diff --git a/MemberNodes.py b/MemberNodes.py index 075604174100ef3f2e8617ef20362c9a3e1ac0ec..576e0e2cf6cf1fe430441e5238a809e196a4b91d 100644 --- a/MemberNodes.py +++ b/MemberNodes.py @@ -264,14 +264,14 @@ class MethodNode(ASTNode): vars[i].offset = i * 4 + 16 bodyCode += p("push", 0) - # call parent constructor - if myClass.superClass: - suLabel = "M_" + myClass.superClass.name + "_" - bodyCode += importHelper(myClass.superClass.name, self.typeName, suLabel) - 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 + # # call parent constructor + # if myClass.superClass: + # suLabel = "M_" + myClass.superClass.name + "_" + # bodyCode += importHelper(myClass.superClass.name, self.typeName, suLabel) + # 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 diff --git a/TypeNodes.py b/TypeNodes.py index 14b6f8f9047e26a87a0592430e81025961c18762..b2d7282b0b13e15c4d0106b430233c56a58c50b1 100644 --- a/TypeNodes.py +++ b/TypeNodes.py @@ -305,7 +305,7 @@ class ClassNode(ClassInterNode): return - self.code = "" # For read-only section + self.code = "" # For read-only section self.data = "" # For writeable data section # print("This is the super class: {}".format(self.superClass)) @@ -355,8 +355,8 @@ class ClassNode(ClassInterNode): self.methodOffset[(method.name, method.paramTypes)] = lastMethodOffset self.data += pLabel(name=self.name + "_" + method.name + "_" + method.paramTypes, type="vtable") self.data += p(instruction="dd", arg1=64) # just declaring a memory segment with a random number - - # Adding inherited method to the methodDict + + # Adding inherited method to the methodDict for i in self.inherits: if isinstance(i, MethodNode): key = (i.name, i.paramTypes) @@ -381,10 +381,13 @@ class ClassNode(ClassInterNode): mLabel = "M_" + className + "_" + key[0] + "_" + key[1] # method implementation # First need to import method implementation labels - if className != self.name: - self.code += p(instruction="extern", arg1=mLabel, comment="importing method implementation label") - self.code += p(instruction="mov", arg1="eax", arg2=vLabel, comment="Filling in class memory segment for method " + mLabel) - self.code += p(instruction="mov", arg1="[eax]", arg2="dword " + mLabel) + # if className != self.name: + # self.code += p(instruction="extern", arg1=mLabel, comment="importing method implementation label") + # self.code += p(instruction="mov", arg1="eax", arg2=vLabel, comment="Filling in class memory segment for method " + mLabel) + # self.code += p(instruction="mov", arg1="[eax]", arg2="dword " + mLabel) + if className == self.name: + self.code += p(instruction="mov", arg1="eax", arg2=vLabel, comment="Filling in class memory segment for method " + mLabel) + self.code += p(instruction="mov", arg1="[eax]", arg2="dword " + mLabel) self.code += p(instruction="ret", arg1="") self.code += "; End of function for filling in class memory layout\n" @@ -395,22 +398,22 @@ class ClassNode(ClassInterNode): ########################################################### - # Generating a function that allocates and initializes all static fields - # Note: 1. saving and restoring ebx, a callee-save register + # Generating a function that allocates and initializes all static fields + # Note: 1. saving and restoring ebx, a callee-save register # 2. static fields are intialized in the order of declaration within the class and has to be intialized # before the test() method is being called self.code += "; Function for filling allocating space and initializing static fields for class " + self.name + "\n" self.code += pLabel(name=self.name + "_" + "staticFieldMemoryInit", type="helper") - self.code += p(instruction="push", arg1="ebx", comment="saving ebx") + self.code += p(instruction="push", arg1="ebx", comment="saving ebx") for field in self.fields: if not hasattr(field, "code"): field.codeGen() self.code += field.code self.data += field.data - self.code += p(instruction="pop", arg1="ebx", comment="restoring ebx") + self.code += p(instruction="pop", arg1="ebx", comment="restoring ebx") self.code += p(instruction="ret", arg1="") self.code += "; End of function for filling allocating space and initializing static fields for class " + self.name + "\n" - + # Generating a function that calls both the class memory init and static field init functions self.code += "; Function that calls staticFieldMemoryInit and classMemoryInit \n" self.code += pLabel(name=self.name + "_" + "classAndStaticFieldInit", type="helper")