Skip to content

Commit 2f1c5f1

Browse files
author
ojd2
committed
Various updates and added additional expression test8.j
1 parent 2c780ad commit 2f1c5f1

12 files changed

+44
-24
lines changed

compiler

128 Bytes
Binary file not shown.

compiler.hi

12 Bytes
Binary file not shown.

compiler.hs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ data Par = ParId Id Structs
4444
-- <struct> [";" <structs>] (Statements)
4545
-- Structs type is defined = takes the following expressions "Struct" and "StructAlt"
4646
data Structs = Struct Struct
47-
| StructAlt Struct Structs
47+
| StructSeperator Struct Structs
4848
deriving Show
4949

5050

@@ -67,7 +67,7 @@ data Struct = StructExp Exprs
6767
-- Exprs type is defined = takes the following expressions "Expr"
6868
-- Alternative options are "ExprAlt"
6969
data Exprs = Expression Expr
70-
| ExprAlt Expr Exprs
70+
| ExprSeperator Expr Exprs
7171
deriving Show
7272

7373

@@ -108,7 +108,7 @@ data Op = OpAdd
108108

109109

110110

111-
111+
-- Abstract syntax tree expressions:
112112

113113
-- program printInt : string "int" and ExprInt of '42' int
114114
-- test = Program "printInt" ( Par ( ParId "Int" ( Struct ( StructExp ( Expression ( ExprInt 42 ) ) ) ) ) )
@@ -131,8 +131,12 @@ data Op = OpAdd
131131
-- program opDivideInts : func OpMinus ExprInt 100, OpAdd ExprInt 35
132132
-- test7 = Program "opDivideInts" ( Par ( ParId "OpDivide" ( Struct ( StructExp ( Expression ( ExprOp (Expression (ExprInt 100) ) (OpDivide) (Expression (ExprInt 35) ) ) ) ) ) ) )
133133

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) ) ) ) ) ) ) )
134+
-- program printStringInts : func String "Hello World!".
135+
-- test8 = Program "printStringInts" ( Par ( ParId "ExprSeperator" ( Struct ( StructExp ( ExprSeperator ( ( ExprString "Hello World!" ) ) ( Expression ( ExprInt 42 ) ) ) ) ) ) )
136+
137+
138+
139+
136140

137141

138142

compiler.o

252 Bytes
Binary file not shown.
File renamed without changes.

test.j

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
.method public static main([Ljava/lang/String;)V
1414

15-
; allocate stack big enough to hold 2 items
15+
; allocate stack big enough to hold 1 items
1616
.limit stack 2
1717
.limit locals 2
1818

test3.j

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
; push java.lang.System.out (type PrintStream)
2020
getstatic java/lang/System/out Ljava/io/PrintStream;
2121
; push int to be printed
22-
; 0 = f, 1 = t
22+
; 0 = false, 1 = true
2323
ldc 1
2424
; invoke println
2525
invokevirtual java/io/PrintStream/println(Z)V ; bool print (Z)

test4.j

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
; push java.lang.System.out (type PrintStream)
2020
getstatic java/lang/System/out Ljava/io/PrintStream;
2121
; push int to be printed
22-
; 0 = f, 1 = t
22+
; 0 = false, 1 = true
2323
ldc 0
2424
; invoke println
2525
invokevirtual java/io/PrintStream/println(Z)V ; bool print (Z)

test5.j

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
ldc 10 ; load int
2424
ldc 5 ; load int
25-
iadd ; add int
25+
iadd ; add ints
2626
istore_0 ; store result in variable
2727
iload 0 ; load variable, push to top of stack
2828
; invoke println

test6.j

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
.method public static main([Ljava/lang/String;)V
1414

15-
; allocate stack big enough to hold 3 items
15+
; allocate stack big enough to hold 2 items
1616
.limit stack 3
1717
.limit locals 2 ; should be fine with 2
1818

test8.class

405 Bytes
Binary file not shown.

test8.j

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,48 @@
1-
.class public test7
1+
.class public test8
22
.super java/lang/Object
33

44
; standard initializer
55
; default constructor
66

77
.method public <init>()V
8-
aload_0 ; push this
9-
invokespecial java/lang/Object/<init>()V ; call super
8+
aload_0
9+
invokespecial java/lang/Object/<init>()V
1010
return
1111
.end method
1212

1313
.method public static main([Ljava/lang/String;)V
1414

15-
; allocate stack big enough to hold 3 items
16-
.limit stack 3
17-
.limit locals 2 ; should be fine with 2
18-
15+
; allocate stack big enough to hold 2 items
16+
.limit stack 3
17+
.limit locals 2
18+
19+
; push string to be printed
20+
ldc "Hello World!"
21+
astore 0 ; astore for strings
22+
ldc 42
23+
istore 1 ; istore for ints
24+
25+
; push java.lang.System.out (type PrintStream)
26+
; getstatic modifies the stack. Be aware.
27+
getstatic java/lang/System/out Ljava/io/PrintStream;
28+
29+
aload 0 ; 0 top of stack
30+
31+
; invoke println
32+
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V ; string print
33+
1934
; push java.lang.System.out (type PrintStream)
35+
getstatic modifies the stack. Be aware.
2036
getstatic java/lang/System/out Ljava/io/PrintStream;
21-
; push ints to be printed
2237

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
38+
iload 1 ; 1 bottom of stack but at top after print
39+
2840
; invoke println
29-
invokevirtual java/io/PrintStream/println(I)V ; int print result
41+
invokevirtual java/io/PrintStream/println(I)V ; int print
42+
43+
44+
45+
3046
; terminate main
3147
return
3248

0 commit comments

Comments
 (0)