diff --git a/ExprPrimaryNodes.py b/ExprPrimaryNodes.py index 1c2ecb1e35b5a964839b63af4871d3b10b98d24c..37aedd4eb1b030800e8a1341781232c9a68a7e39 100644 --- a/ExprPrimaryNodes.py +++ b/ExprPrimaryNodes.py @@ -368,16 +368,6 @@ class ClassCreateNode(ASTNode): self.code += importHelper(classDef.name, self.typeName, "C_"+classDef.name) self.code += p(instruction="mov", arg1="[eax]", arg2="[C_"+classDef.name+"]", comment="first item is vtable pointer") - # 3. Filling up the object memory layout with pointers to fields - # Note: the key of the offset table is of the form (className, fieldName) - self.code += "; Filling in object memory layout with pointers to fields\n" - for key,value in sorted(fieldOffset.items(), key=lambda item: item[1]): - label = "F_"+key[0]+"_"+key[1] - self.code += importHelper(key[0], self.typeName, label) - self.code += p(instruction="call", arg1=label, comment="calling function to allocate space on heap") + \ - p(instruction="mov", arg1="[eax"+str(value)+"]", arg2="ecx", comment="filling in field on object memory for "+label) - self.code += "; End of filling in object memory layout\n" - # 4. Calling constructor self.code += "; Calling constructor for object\n" self.code += p(instruction="push", arg1="eax", comment="pushing object as first argument") @@ -692,13 +682,12 @@ class FieldAccessNode(ASTNode): # NOTE: this is always called by codeGen, so self.code is already intialized to "" def addr(self): fieldNode = self.ID.prefixLink - label = fieldNode.typeName + "_" + fieldNode.name if "static" in fieldNode.mods: - + label = fieldNode.typeName + "_" + fieldNode.name self.code += "; Start of calculating address for static field: " + label + "\n" + \ importHelper(fieldNode.typeName, self.typeName, "S_"+label) + \ - p(instruction="mov", arg1="eax", arg2="[S_"+label+"]", comment="getting address to static field") + \ + p(instruction="mov", arg1="eax", arg2="S_"+label, comment="getting address to static field") + \ "; End of field access\n" else: @@ -707,10 +696,9 @@ class FieldAccessNode(ASTNode): self.code += self.primary.code # Null check # At this point, eax stores the address of the object - self.code += p(instruction="call", arg1="H__Null_Check", comment="calling null check function") + self.code += p(instruction="call", arg1="H__Null_Check", comment="calling null check function") # Make eax store the address to the field we're accessing - self.code += p(instruction="add", arg1="eax", arg2=self.ID.prefixLink.offset, comment="calculating pointer to a pointer to the field") + \ - p(instruction="mov", arg1="eax", arg2="[eax]", comment="storing pointer to the field") + self.code += p(instruction="add", arg1="eax", arg2=self.ID.prefixLink.offset, comment="calculating pointer to the field") self.code += "; End of calculating address for non-static field\n"