Skip to content

Commit 4e393d8

Browse files
author
ojd2
committed
Added more additional testing
1 parent 2f1c5f1 commit 4e393d8

File tree

8 files changed

+82
-4
lines changed

8 files changed

+82
-4
lines changed

compiler

-24 Bytes
Binary file not shown.

compiler.hs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,20 @@ data Op = OpAdd
125125
-- program opAddInts : func OpAdd ExprInt 10, OpAdd ExprInt 10
126126
--test5 = Program "opAddInts" ( Par ( ParId "OpAdd" ( Struct ( StructExp ( Expression ( ExprOp (Expression (ExprInt 10) ) (OpAdd) (Expression (ExprInt 5) ) ) ) ) ) ) )
127127

128-
-- program opMinusInts : func OpMinus ExprInt 100, OpAdd ExprInt 35
128+
-- program opMinusInts : func OpMinus ExprInt 100, OpMinus ExprInt 35
129129
-- test6 = Program "opMinusInts" ( Par ( ParId "OpMinus" ( Struct ( StructExp ( Expression ( ExprOp (Expression (ExprInt 100) ) (OpMinus) (Expression (ExprInt 35) ) ) ) ) ) ) )
130130

131-
-- program opDivideInts : func OpMinus ExprInt 100, OpAdd ExprInt 35
131+
-- program opDivideInts : func OpMinus ExprInt 100, OpDivide ExprInt 35
132132
-- test7 = Program "opDivideInts" ( Par ( ParId "OpDivide" ( Struct ( StructExp ( Expression ( ExprOp (Expression (ExprInt 100) ) (OpDivide) (Expression (ExprInt 35) ) ) ) ) ) ) )
133133

134-
-- program printStringInts : func String "Hello World!".
134+
-- program printStringInts : func String "Hello World!" func Int 42. return
135135
-- test8 = Program "printStringInts" ( Par ( ParId "ExprSeperator" ( Struct ( StructExp ( ExprSeperator ( ( ExprString "Hello World!" ) ) ( Expression ( ExprInt 42 ) ) ) ) ) ) )
136136

137+
-- program printStringBool : func String "Hello World!" func Int 42. return
138+
-- test9 = Program "printStringBool" ( Par ( ParId "ExprSeperator" ( Struct ( StructExp ( ExprSeperator ( ( ExprString "Hello World!" ) ) ( Expression ( ExprBool True ) ) ) ) ) ) )
137139

140+
-- program printStringBool : func String "Hello World!" func Int 42. return
141+
test10 = Program "opMultiplyInts" ( Par ( ParId "OpMultiply" ( Struct ( StructExp ( Expression ( ExprOp (Expression (ExprInt 235) ) (OpMultiply) (Expression (ExprInt 19) ) ) ) ) ) ) )
138142

139143

140144

@@ -147,5 +151,5 @@ data Op = OpAdd
147151

148152

149153
-- Print out test program above using AST declarations
150-
main = print test8
154+
main = print test10
151155

compiler.o

-144 Bytes
Binary file not shown.

test10.class

350 Bytes
Binary file not shown.

test10.j

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.class public test10
2+
.super java/lang/Object
3+
4+
; standard initializer
5+
; default constructor
6+
7+
.method public <init>()V
8+
aload_0 ; push this
9+
invokespecial java/lang/Object/<init>()V ; call super
10+
return
11+
.end method
12+
13+
.method public static main([Ljava/lang/String;)V
14+
15+
; allocate stack big enough to hold 2 items
16+
.limit stack 3
17+
.limit locals 2 ; should be fine with 2
18+
19+
; push java.lang.System.out (type PrintStream)
20+
getstatic java/lang/System/out Ljava/io/PrintStream;
21+
; push ints to be printed
22+
23+
ldc 235 ; load int
24+
ldc 19 ; load int
25+
imul ; multiply ints
26+
27+
istore_0 ; store result in variable
28+
iload 0 ; load variable, push to top of stack
29+
30+
; invoke println
31+
invokevirtual java/io/PrintStream/println(I)V ; int print result
32+
; terminate main
33+
return
34+
35+
.end method

test6.class

1 Byte
Binary file not shown.

test9.class

397 Bytes
Binary file not shown.

test9.j

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
.class public test9
2+
.super java/lang/Object
3+
4+
; standard initializer
5+
; default constructor
6+
7+
.method public <init>()V
8+
aload_0
9+
invokespecial java/lang/Object/<init>()V
10+
return
11+
.end method
12+
13+
.method public static main([Ljava/lang/String;)V
14+
15+
; allocate stack big enough to hold 2 items
16+
.limit stack 3
17+
.limit locals 2
18+
19+
; push java.lang.System.out (type PrintStream)
20+
; getstatic modifies the stack. Be aware.
21+
getstatic java/lang/System/out Ljava/io/PrintStream;
22+
; push string to be printed
23+
ldc "Hello World!"
24+
25+
; invoke println
26+
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V ; string print
27+
28+
; push java.lang.System.out (type PrintStream)
29+
getstatic java/lang/System/out Ljava/io/PrintStream;
30+
; push int to be printed
31+
; 0 = false, 1 = true
32+
ldc 1
33+
; invoke println
34+
invokevirtual java/io/PrintStream/println(Z)V ; bool print (Z)
35+
36+
; terminate main
37+
return
38+
39+
.end method

0 commit comments

Comments
 (0)