diff --git a/ExprPrimaryNodes.py b/ExprPrimaryNodes.py index 3aec6f27e57b82a8e79812c5395b8071d0c2b33b..ed367083caf9120d2cbc2a21aabb91f8f5fa8cdd 100644 --- a/ExprPrimaryNodes.py +++ b/ExprPrimaryNodes.py @@ -253,7 +253,7 @@ class AssignNode(ASTNode): if self.left.__class__.__name__ == "NameNode": if self.left.prefixLink.__class__.__name__ == "VarDclNode": # move init result to var location - self.code += p("mov", "[ebp + " + str(self.left.prefixLink.offset) + "]", "eax") + self.code += p("mov", "[ebp - " + str(self.left.prefixLink.offset) + "]", "eax") ################################################################################## diff --git a/LineNodes.py b/LineNodes.py index fc9edff10acca6c9a44bbef88f65be15e19d8d87..e4e46f2628a7d280b44b1f527836a430745bccb8 100644 --- a/LineNodes.py +++ b/LineNodes.py @@ -173,11 +173,11 @@ class VarDclNode(ASTNode): self.variableInit.codeGen() self.code += self.variableInit.code # move init result to var location - self.code += p("mov", "[ebp + " + str(self.offset) + "]", "eax") + self.code += p("mov", "[ebp - " + str(self.offset) + "]", "eax") def addr(self): result = p("mov", "eax", "ebp") - result += p("add", "eax", str(self.offset)) + result += p("sub", "eax", str(self.offset)) return result diff --git a/MemberNodes.py b/MemberNodes.py index 84330c5eabea0ad864cac3d7a089bbb58e1fbdff..0c9cb8868b10da4f3226f3c639f36fc9de95f4cd 100644 --- a/MemberNodes.py +++ b/MemberNodes.py @@ -270,6 +270,7 @@ class MethodNode(ASTNode): bodyCode += p("mov", "eax", "[ebp - " + str(thisLoc) + "]") bodyCode += p("push", "eax", None, "# Pass THIS as argument to superClass.") bodyCode += p("call", suLabel) + bodyCode += p("add", "esp", "4") # pop object off stack # init fields @@ -278,7 +279,7 @@ class MethodNode(ASTNode): if not 'static' in f.mods and f.variableDcl.variableInit: f.variableDcl.variableInit.codeGen() bodyCode += f.variableDcl.variableInit.code - bodyCode += p("mov", "ebx", "[ebp - " + str(thisLoc) + "]") # THIS + bodyCode += p("mov", "ebx", "[ebp + " + str(thisLoc) + "]") # THIS bodyCode += p("mov", "[ebx + " + str(f.offset) + " ]", "eax") # body code diff --git a/NameNode.py b/NameNode.py index b413c6963c3b98675a692a52eba2647672c9abb2..55033f041430270356258dcbe7554d41c1b985d1 100644 --- a/NameNode.py +++ b/NameNode.py @@ -257,7 +257,8 @@ class NameNode(ASTNode): def codeGen(self): self.code = "" if self.prefixLink.__class__.__name__ == "VarDclNode": - self.code = p("mov", "eax", "[ebp + " + str(self.prefixLink.offset) + "]", "access local var" + self.name) + self.code = p("mov", "eax", "[ebp - " + str(self.prefixLink.offset) + "]", "access local var" + self.name) + # helper def checkProtected(dcl, usage): # get curType's class it was declared in diff --git a/Tests/A5/J1_01_ObjCreate.java b/Tests/A5/J1_01_ObjCreate.java new file mode 100644 index 0000000000000000000000000000000000000000..67019b9be76ff2405354a12b1bc866cda676998e --- /dev/null +++ b/Tests/A5/J1_01_ObjCreate.java @@ -0,0 +1,13 @@ +// Need to delete lines that involves java.long.Object from the .s for the code to work +public class J1_01_ObjCreate { + + public J1_01_ObjCreate() { + } + public int i = 4; + public int j; + + public static int test() { + J1_01_ObjCreate k = new J1_01_ObjCreate(); + return k.i; + } +}