Skip to content

Commit

Permalink
Merge branch 'code_gen'
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandraGrass committed Jul 28, 2019
2 parents 9df09fd + 1f8c529 commit b5d32c6
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 2 deletions.
1 change: 0 additions & 1 deletion code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ def code_gen_for_fun(children):
else: #the actual execution of the function
varsUsed = getVarsUsed(children) #all variables used inside the function definition
freeVars = list(set(varsUsed) - set(funArgVars) - set(varsCreatedInsideFunction)) #variables that are not formal parameters
freeVars = ['c']
varsUsedInFun = [] #reset the global variables

for var in freeVars: #first generate code for free-vars
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# usage: main.py [-h] [-i INPUT] [-o OUTPUT]
# example: python3 main.py -i input/slide_102.ml -o output/slide_102.txt

with open(args.input) as i_f, open(args.output, 'w') as o_f:
with open(args.input) as i_f, open(args.output, 'w+') as o_f:

# read input and remove whitespace
expr = i_f.read()
Expand Down
41 changes: 41 additions & 0 deletions output/slide_102.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Output:
0 alloc 1
1 pushloc 0
2 mkvec 1
2 mkfunval A
2 jump B
A:
0 targ 1
0 pushloc 0
1 getbasic
1 loadc 1
2 le
1 jumpz C
1 loadc 1
2 mkbasic
2 jump D
C:
2 pushloc 2
3 getbasic
3 mark E
6 pushloc 6
7 getbasic
7 loadc 1
8 sub
7 mkbasic
7 pushglob 0
8 apply
E:
4 mul
3 mkbasic
D:
3 return 1
B:
2 rewrite 1
1 mark F
4 loadc 7
5 mkbasic
5 pushloc 4
6 apply
F:
2 slide 1
29 changes: 29 additions & 0 deletions output/slide_114.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Output:
0 loadc 5
1 mkbasic
1 pushloc 0
2 mkvec 1
2 mkfunval A
2 jump B
A:
0 targ 1
0 pushloc 0
1 getbasic
1 pushloc 1
2 getbasic
2 mul
1 mkbasic
1 pushloc 0
2 getbasic
2 pushglob 0
3 getbasic
3 add
2 mkbasic
2 return 1
B:
2 mark C
5 pushloc 4
6 pushloc 4
7 apply
C:
3 slide 3
16 changes: 16 additions & 0 deletions output/slide_131.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Output:
0 loadc 19
1 mkbasic
1 pushloc 0
2 getbasic
2 pushloc 1
3 getbasic
3 mul
2 mkbasic
2 pushloc 1
3 getbasic
3 pushloc 1
4 getbasic
4 add
3 mkbasic
3 slide 2
24 changes: 24 additions & 0 deletions output/slide_140.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Output:
0 loadc 17
1 mkbasic
1 pushloc 0
2 mkvec 1
2 mkfunval A
2 jump B
A:
0 targ 1
0 pushglob 0
1 getbasic
1 pushloc 1
2 getbasic
2 add
1 mkbasic
1 return 1
B:
2 mark C
5 loadc 42
6 mkbasic
6 pushloc 4
7 apply
C:
3 slide 2
42 changes: 42 additions & 0 deletions output/slide_159.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Output:
0 alloc 1
1 pushloc 0
2 mkvec 1
2 mkfunval A
2 jump B
A:
0 targ 2
0 pushloc 1
1 getbasic
1 loadc 1
2 le
1 jumpz C
1 pushloc 1
2 jump D
C:
2 mark E
5 pushloc 6
6 getbasic
6 loadc 1
7 sub
6 mkbasic
6 pushloc 6
7 getbasic
7 pushloc 8
8 getbasic
8 mul
7 mkbasic
7 pushglob 0
8 apply
E:
D:
3 return 2
B:
2 rewrite 1
1 mark F
4 loadc 1
5 mkbasic
5 pushloc 4
6 apply
F:
2 slide 1

0 comments on commit b5d32c6

Please sign in to comment.