Skip to content

Commit

Permalink
Additional tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
kentdlee committed Jan 7, 2014
1 parent b7be0f0 commit 9154d96
Show file tree
Hide file tree
Showing 18 changed files with 331 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/addtwo.casm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Function: main/0
Constants: None, 5, 6
Locals: x, y, z
Globals: print
BEGIN
LOAD_CONST 1
STORE_FAST 0
LOAD_CONST 2
STORE_FAST 1
LOAD_FAST 0
LOAD_FAST 1
BINARY_ADD
STORE_FAST 2
LOAD_GLOBAL 0
LOAD_FAST 2
CALL_FUNCTION 1
POP_TOP
LOAD_CONST 0
RETURN_VALUE
END
9 changes: 9 additions & 0 deletions tests/addtwo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from disassembler import *

def main():
x = 5
y = 6
z = x + y
print(z)

disassemble(main)
56 changes: 56 additions & 0 deletions tests/except.casm
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
Function: main/0
Constants: None, "Enter a number: ", "/", "="
Locals: x, y, z, ex
Globals: float, input, print, Exception
BEGIN
SETUP_EXCEPT label00
LOAD_GLOBAL 0
LOAD_GLOBAL 1
LOAD_CONST 1
CALL_FUNCTION 1
CALL_FUNCTION 1
STORE_FAST 0
LOAD_GLOBAL 0
LOAD_GLOBAL 1
LOAD_CONST 1
CALL_FUNCTION 1
CALL_FUNCTION 1
STORE_FAST 1
LOAD_FAST 0
LOAD_FAST 1
BINARY_TRUE_DIVIDE
STORE_FAST 2
LOAD_GLOBAL 2
LOAD_FAST 0
LOAD_CONST 2
LOAD_FAST 1
LOAD_CONST 3
LOAD_FAST 2
CALL_FUNCTION 5
POP_TOP
POP_BLOCK
JUMP_FORWARD label03
label00: DUP_TOP
LOAD_GLOBAL 3
COMPARE_OP 10
POP_JUMP_IF_FALSE label02
POP_TOP
STORE_FAST 3
POP_TOP
SETUP_FINALLY label01
LOAD_GLOBAL 2
LOAD_FAST 3
CALL_FUNCTION 1
POP_TOP
POP_BLOCK
POP_EXCEPT
LOAD_CONST 0
label01: LOAD_CONST 0
STORE_FAST 3
DELETE_FAST 3
END_FINALLY
JUMP_FORWARD label03
label02: END_FINALLY
label03: LOAD_CONST 0
RETURN_VALUE
END
14 changes: 14 additions & 0 deletions tests/except.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import disassembler

def main():
try:
x = int(input("Enter a number: "))
y = float(input("Enter a number: "))
z = x / y

print(x,"/",y,"=",z)
except Exception as ex:
print(ex)

main()
#disassembler.disassemble(main)
25 changes: 25 additions & 0 deletions tests/ifthen.casm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Function: main/0
Constants: None, 5, 6
Locals: x, y
Globals: print
BEGIN
LOAD_CONST 1
STORE_FAST 0
LOAD_CONST 2
STORE_FAST 1
LOAD_FAST 0
LOAD_FAST 1
COMPARE_OP 4
POP_JUMP_IF_FALSE label00
LOAD_GLOBAL 0
LOAD_FAST 0
CALL_FUNCTION 1
POP_TOP
JUMP_FORWARD label00
label00: LOAD_GLOBAL 0
LOAD_FAST 1
CALL_FUNCTION 1
POP_TOP
LOAD_CONST 0
RETURN_VALUE
END
13 changes: 13 additions & 0 deletions tests/ifthen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import disassembler

def main():
x = 5
y = 6
if x > y:
print(x)

print(y)

#main()

disassembler.disassemble(main)
25 changes: 25 additions & 0 deletions tests/ifthenelse.casm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Function: main/0
Constants: None, 5, 6
Locals: x, y, z
Globals: print
BEGIN
LOAD_CONST 1
STORE_FAST 0
LOAD_CONST 2
STORE_FAST 1
LOAD_FAST 0
LOAD_FAST 1
COMPARE_OP 4
POP_JUMP_IF_FALSE label00
LOAD_FAST 0
STORE_FAST 2
JUMP_FORWARD label01
label00: LOAD_FAST 1
STORE_FAST 2
label01: LOAD_GLOBAL 0
LOAD_FAST 2
CALL_FUNCTION 1
POP_TOP
LOAD_CONST 0
RETURN_VALUE
END
15 changes: 15 additions & 0 deletions tests/ifthenelse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import disassembler

def main():
x = 5
y = 6
if x > y:
z = x
else:
z = y

print(z)

#main()

disassembler.disassemble(main)
10 changes: 10 additions & 0 deletions tests/ifthenelseexp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import disassembler

def main():
x = 5
y = 6
print(x if x > y else y)

#main()

disassembler.disassemble(main)
27 changes: 27 additions & 0 deletions tests/inputoutput.casm
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Function: main/0
Constants: None, "Please enter an integer: ", "Please enter a number: ", "The product is"
Locals: x, y
Globals: int, input, float, print
BEGIN
LOAD_GLOBAL 0
LOAD_GLOBAL 1
LOAD_CONST 1
CALL_FUNCTION 1
CALL_FUNCTION 1
STORE_FAST 0
LOAD_GLOBAL 2
LOAD_GLOBAL 1
LOAD_CONST 2
CALL_FUNCTION 1
CALL_FUNCTION 1
STORE_FAST 1
LOAD_GLOBAL 3
LOAD_CONST 3
LOAD_FAST 0
LOAD_FAST 1
BINARY_MULTIPLY
CALL_FUNCTION 2
POP_TOP
LOAD_CONST 0
RETURN_VALUE
END
10 changes: 10 additions & 0 deletions tests/inputoutput.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import disassembler

def main():
x = int(input("Please enter an integer: "))
y = float(input("Please enter a number: "))
print("The product is", x*y)

#main()

disassembler.disassemble(main)
11 changes: 11 additions & 0 deletions tests/iotest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import disassembler

def main():

name = input("Enter your name: ")
age = int(input("Enter your age: "))
print(name + ", a year from now you will be", age+1, "years old.")

#main()

disassembler.disassemble(main)
16 changes: 16 additions & 0 deletions tests/listconstant.casm
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Function: main/0
Constants: None, "hello", "world"
Locals: lst
Globals: print
BEGIN
LOAD_CONST 1
LOAD_CONST 2
BUILD_LIST 2
STORE_FAST 0
LOAD_GLOBAL 0
LOAD_FAST 0
CALL_FUNCTION 1
POP_TOP
LOAD_CONST 0
RETURN_VALUE
END
8 changes: 8 additions & 0 deletions tests/listconstant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import disassembler

def main():
lst = ["hello","world"]
print(lst)

#main()
disassembler.disassemble(main)
20 changes: 20 additions & 0 deletions tests/split.casm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Function: main/0
Constants: None, "Enter a list of integers:"
Locals: s, lst
Globals: input, split, print
BEGIN
LOAD_GLOBAL 0
LOAD_CONST 1
CALL_FUNCTION 1
STORE_FAST 0
LOAD_FAST 0
LOAD_ATTR 1
CALL_FUNCTION 0
STORE_FAST 1
LOAD_GLOBAL 2
LOAD_FAST 1
CALL_FUNCTION 1
POP_TOP
LOAD_CONST 0
RETURN_VALUE
END
10 changes: 10 additions & 0 deletions tests/split.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import disassembler

def main():
s = input("Enter a list of integers:")
lst = s.split()

print(lst)

#main()
disassembler.disassemble(main)
25 changes: 25 additions & 0 deletions tests/test.casm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Function: main/0
Constants: None, 7, 6
Locals: x, y
Globals: print
BEGIN
SETUP_LOOP label01
LOAD_CONST 1
STORE_FAST 0
LOAD_CONST 2
STORE_FAST 1
LOAD_FAST 0
LOAD_FAST 1
COMPARE_OP 1
POP_JUMP_IF_TRUE label00
BREAK_LOOP
LOAD_GLOBAL 0
LOAD_FAST 0
CALL_FUNCTION 1
POP_TOP
label00: POP_BLOCK
label01: LOAD_GLOBAL 0
LOAD_FAST 1
CALL_FUNCTION 1
RETURN_VALUE
END
17 changes: 17 additions & 0 deletions tests/while.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import disassembler

def main():
f = 8
i = 1
j = 1
n = 1
while n < f:
n = n + 1
tmp = j
j = j + i
i = tmp

print("Fibonacci("+str(n)+") is",i)

#main()
disassembler.disassemble(main)

0 comments on commit 9154d96

Please sign in to comment.