Skip to content

Commit 2c780ad

Browse files
author
ojd2
committed
Small Update
1 parent 24d825f commit 2c780ad

File tree

8 files changed

+108
-3
lines changed

8 files changed

+108
-3
lines changed

compiler

0 Bytes
Binary file not shown.

compiler.hs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ data Expr = ExprInt Int
8686
| ExprBool Bool
8787
| ExprAssignment Id Exprs
8888
| ExprRaise Id Exprs
89-
| ExprCacth Exprs Id Id Exprs
89+
| ExprCatch Exprs Id Id Exprs
9090
| ExprOp Exprs Op Exprs
9191
| ExprGroup Exprs
9292
deriving Show
@@ -126,7 +126,13 @@ data Op = OpAdd
126126
--test5 = Program "opAddInts" ( Par ( ParId "OpAdd" ( Struct ( StructExp ( Expression ( ExprOp (Expression (ExprInt 10) ) (OpAdd) (Expression (ExprInt 5) ) ) ) ) ) ) )
127127

128128
-- program opMinusInts : func OpMinus ExprInt 100, OpAdd ExprInt 35
129-
test6 = Program "opMinusInts" ( Par ( ParId "OpMinus" ( Struct ( StructExp ( Expression ( ExprOp (Expression (ExprInt 100) ) (OpMinus) (Expression (ExprInt 35) ) ) ) ) ) ) )
129+
-- test6 = Program "opMinusInts" ( Par ( ParId "OpMinus" ( Struct ( StructExp ( Expression ( ExprOp (Expression (ExprInt 100) ) (OpMinus) (Expression (ExprInt 35) ) ) ) ) ) ) )
130+
131+
-- program opDivideInts : func OpMinus ExprInt 100, OpAdd ExprInt 35
132+
-- test7 = Program "opDivideInts" ( Par ( ParId "OpDivide" ( Struct ( StructExp ( Expression ( ExprOp (Expression (ExprInt 100) ) (OpDivide) (Expression (ExprInt 35) ) ) ) ) ) ) )
133+
134+
-- program opDivideInts : func OpMinus ExprInt 100, OpAdd ExprInt 35
135+
-- test8 = Program "strComp" ( Par ( ParId "StructComp" ( Struct ( StructExp ( Expression ( ExprOp (Expression (ExprInt 20) ) (OpLess) (Expression (ExprInt 80) ) ) ) ) ) ) )
130136

131137

132138

@@ -137,5 +143,5 @@ test6 = Program "opMinusInts" ( Par ( ParId "OpMinus" ( Struct ( StructExp ( Exp
137143

138144

139145
-- Print out test program above using AST declarations
140-
main = print test6
146+
main = print test8
141147

compiler.o

8 Bytes
Binary file not shown.

test6.class

348 Bytes
Binary file not shown.

test6.j

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.class public test6
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 3 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 100 ; load int
24+
ldc 35 ; load int
25+
isub ; subtract int
26+
istore_0 ; store result in variable
27+
iload 0 ; load variable, push to top of stack
28+
; invoke println
29+
invokevirtual java/io/PrintStream/println(I)V ; int print result
30+
; terminate main
31+
return
32+
33+
.end method

test7.class

348 Bytes
Binary file not shown.

test7.j

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.class public test7
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 3 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 100 ; load int
24+
ldc 35 ; load int
25+
idiv ; divide int
26+
istore_0 ; store result in variable
27+
iload 0 ; load variable, push to top of stack
28+
; invoke println
29+
invokevirtual java/io/PrintStream/println(I)V ; int print result
30+
; terminate main
31+
return
32+
33+
.end method

test8.j

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.class public test7
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 3 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 20 ; load int
24+
ldc 80 ; load int
25+
if_icmple ; if less than int
26+
istore_0 ; store result in variable
27+
iload 0 ; load variable, push to top of stack
28+
; invoke println
29+
invokevirtual java/io/PrintStream/println(I)V ; int print result
30+
; terminate main
31+
return
32+
33+
.end method

0 commit comments

Comments
 (0)