Skip to content

Commit

Permalink
Code generated for function application example on slide 140
Browse files Browse the repository at this point in the history
  • Loading branch information
raypinto committed Jul 21, 2019
1 parent bb0e23c commit f5a72f5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 14 additions & 1 deletion code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,17 @@ def getVarsUsed(): #TODO

#code generation for function application
def code_gen_for_application(children):
print(children)
global sd
preAppSD = sd
print(str(sd) + " mark C")
sd=sd+3
for i in range((len(children)-1),-1, -1):
if(children[i].tag == "basic"):
code_gen_for_basic_val(children[i].value)
elif(children[i].tag == "add"):
code_gen_for_op(children[i].children,"add")
elif(children[i].tag == "fvar"):
code_gen_for_var(children[i].var,False)
print(str(sd) + " apply")
print("C:")
sd = preAppSD + 1
4 changes: 3 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,7 @@
#parse_syntaxTree(result)
#result = parse_tree("if 1 then 3 else 4")
#parse_syntaxTree(result)
result = parse_tree("let a = 17 in let f = fun b -> a + b in f (39 + 2)")
#result = parse_tree("let a = 17 in let f = fun b -> a + b in f (39 + 2)")
#parse_syntaxTree(result)
result = parse_tree("let a = 17 in let f = fun b -> a + b in f 42") # 140
parse_syntaxTree(result)

0 comments on commit f5a72f5

Please sign in to comment.