Skip to content
Snippets Groups Projects
Commit ee1fed25 authored by pycsham's avatar pycsham
Browse files

Changed methodInvoke and methodNode so that object is pushed on stack after...

Changed methodInvoke and methodNode so that object is pushed on stack after parameters. Fixed a minor issue
parent f1eb114d
No related branches found
No related tags found
3 merge requests!19Namenode,!18Sit,!17Sit
...@@ -894,7 +894,10 @@ class MethodInvNode(ASTNode): ...@@ -894,7 +894,10 @@ class MethodInvNode(ASTNode):
(pro, epi) = genMethodInvoke(self.method.name + "_" + self.method.paramTypes) (pro, epi) = genMethodInvoke(self.method.name + "_" + self.method.paramTypes)
self.code += pro self.code += pro
# 2. Evaluating o, the object # 2. Evaluate arguments and pushing them on the stack (handled by the args node)
self.evalArgs()
# 3. Evaluating o, the object
if self.primary: if self.primary:
if not hasattr(self.primary, "code"): if not hasattr(self.primary, "code"):
self.primary.codeGen() self.primary.codeGen()
...@@ -904,22 +907,19 @@ class MethodInvNode(ASTNode): ...@@ -904,22 +907,19 @@ class MethodInvNode(ASTNode):
self.ID.codeGen() self.ID.codeGen()
self.code += self.ID.code self.code += self.ID.code
# 3. Null check # 4. Null check
# At this point, eax stores the address of the object # 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")
# 4. Pushing the object pointer on the stack # 5. Pushing the object pointer on the stack
self.code += p(instruction="push", arg1="eax", comment="pushing object pointer to the stack") self.code += p(instruction="push", arg1="eax", comment="pushing object pointer to the stack")
# 5. Evaluate arguments and pushing them on the stack (handled by the args node)
self.evalArgs()
# 6. Fetch vtable # 6. Fetch vtable
toPop = 0 toPop = 0
if self.args: if self.args:
toPop = len(self.args.exprs)*4 toPop = len(self.args.exprs)*4
self.code += p(instruction="mov", arg1="eax", arg2="[esp+"+str(toPop)+"]", comment="get address of object") + \ self.code += p(instruction="mov", arg1="eax", arg2="[eax]", comment="get vtable")
p(instruction="mov", arg1="eax", arg2="[eax]", comment="get vtable")
# 7. Fetching the address of m's implementation # 7. Fetching the address of m's implementation
......
...@@ -225,7 +225,7 @@ class MethodNode(ASTNode): ...@@ -225,7 +225,7 @@ class MethodNode(ASTNode):
# params # params
for i, param in enumerate(self.params): for i, param in enumerate(self.params):
param.offset = i * 4 + 8 param.offset = i * 4 + 12 # 12 since the stack is now of the order: ebp, eip, o, params
if self.body: if self.body:
...@@ -259,7 +259,7 @@ class MethodNode(ASTNode): ...@@ -259,7 +259,7 @@ class MethodNode(ASTNode):
self.label = "M_" + self.typeName + "_" + self.name + "_" + self.paramTypes self.label = "M_" + self.typeName + "_" + self.name + "_" + self.paramTypes
self.code = pLabel(self.typeName + "_" + self.name + "_" + self.paramTypes, "method") # label self.code = pLabel(self.typeName + "_" + self.name + "_" + self.paramTypes, "method") # label
thisLoc = len(self.params) * 4 + 8 thisLoc = 8 # Right after ebp, eip
bodyCode = "" bodyCode = ""
if self.body: if self.body:
...@@ -269,7 +269,7 @@ class MethodNode(ASTNode): ...@@ -269,7 +269,7 @@ class MethodNode(ASTNode):
vars[i].offset = i * 4 + 16 vars[i].offset = i * 4 + 16
bodyCode += p("push", 0) bodyCode += p("push", 0)
# call parent constructor # call parent constructor(zero argument)
if myClass.superClass: if myClass.superClass:
suLabel = "M_" + myClass.superClass.name + "_" + myClass.superClass.name + "_" suLabel = "M_" + myClass.superClass.name + "_" + myClass.superClass.name + "_"
bodyCode += importHelper(myClass.superClass.name, self.typeName, suLabel) bodyCode += importHelper(myClass.superClass.name, self.typeName, suLabel)
......
...@@ -349,7 +349,7 @@ class ClassNode(ClassInterNode): ...@@ -349,7 +349,7 @@ class ClassNode(ClassInterNode):
for method in self.constructors: for method in self.constructors:
lastMethodOffset += 4 lastMethodOffset += 4
self.methodOffset[(method.name, method.paramTypes)] = lastMethodOffset self.methodOffset[(method.name, method.paramTypes)] = lastMethodOffset
method.offset = lastMethodOffset method.methodOffset = lastMethodOffset
self.data += pLabel(name=self.name + "_" + method.name + "_" + method.paramTypes, type="vtable") 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 self.data += p(instruction="dd", arg1=64) # just declaring a memory segment with a random number
......
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