Skip to content
Snippets Groups Projects
Commit 7b75fe21 authored by Xun Yang's avatar Xun Yang
Browse files

minor fixes to constructor and iffalse

parent 5043df70
No related branches found
No related tags found
No related merge requests found
......@@ -86,9 +86,15 @@ def genMethodInvoke(method):
return (pro, epi)
# generates shorter code for constant value conditionals and comparison conditionals
# cond is either literalNode or ExprNode
# cond is either literalNode or ExprNode or NameNode
def iffalse(cond, label):
result = ""
if cond.__class__.__name__ == "NameNode":
cond.codeGen()
result += cond.code
result += p("jz", label)
return result
val = cond.getConstant()
if val != None:
if val == True:
......@@ -102,7 +108,7 @@ def iffalse(cond, label):
return result
# Generates generic (not specific to class) helper functions
# Generates generic (not specific to class) helper functions
def genericHelperFunctions():
code = ""
......@@ -137,9 +143,9 @@ def globalImport(genGlobalFunction=False):
if not genGlobalFunction:
code += p(instruction="extern", arg1="G__Zero") + \
p(instruction="extern", arg1="H__Throw_Exception") + \
p(instruction="extern", arg1="H__Null_Check")
p(instruction="extern", arg1="H__Null_Check")
code += "; End of importing helper functions and constants\n"
code += "; End of importing helper functions and constants\n"
return code
# Helper function for importation of label (only import if it's not already inside the same .s file)
......
......@@ -105,6 +105,7 @@ class MethodNode(ASTNode):
self.typeName = typeName
self.order = order
self.myType = None
# self.SIToffset for methods that implements interface method
# get method name
nameNodes = getParseTreeNodes(['ID'], parseTree, ['params', 'type', 'methodBody'])
......@@ -241,7 +242,7 @@ class MethodNode(ASTNode):
self.code += genProcedure(bodyCode, "method definition for " + self.name)
else:
self.code += ("mov", "eax", "0")
self.code += p("mov", "eax", "0")
self.code += p("ret", "")
# This method is called instead of codeGen if this is a constructor
......@@ -292,7 +293,7 @@ class MethodNode(ASTNode):
for i in range(len(vars)):
bodyCode += p("pop", "edx")
else:
bodyCode += ("mov", "eax", "0")
bodyCode += p("mov", "eax", "0")
self.code += genProcedure(bodyCode, "Constructor definition for " + self.name + " " + self.paramTypes)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment