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

array assign check, fix subtype count

parent 2b8b7207
No related branches found
No related tags found
2 merge requests!26Array subtype,!20Master
......@@ -112,7 +112,7 @@ def arrayClassMemory(types):
p(instruction="mov", arg1="[eax]", arg2="dword "+m, comment="points to method implementation")
if tt.__class__.__name__ == "ClassNode":
code += p("extern", "A_subT" + tt.name)
code += p("extern", "A_subT_" + tt.name)
code += p("mov", "eax", "I_subT_spot_" + t)
code += p("mov", "[eax]", "dword A_subT_" + tt.name)
......@@ -135,21 +135,23 @@ def codeGenPrep(ASTs):
interM = []
types = ['boolean', 'byte', 'char', 'int', 'short'] # All possible types
classNodes = []
j = 0
for t in ASTs:
classInterNode = t[1].typeDcl
if classInterNode.__class__.__name__ == "ClassNode":
types.append(classInterNode)
classNodes.append(classInterNode)
else: # interfaceNode, get their methods to prep for SIT
interM += classInterNode.methods
classInterNode.subTypeOffset = j * 4 # assign each type a position in the subtype testing table
j += 1
# store SIT and subtype table size
for i in range(len(classNodes)):
classNodes[i].SITsize = len(interM)
classNodes[i].subTypeSize = len(types) - 5 # no primitive types in subtype table
classNodes[i].subTypeOffset = i * 4 # assign each type a position in the subtype testing table
for c in classNodes:
c.SITsize = len(interM)
c.subTypeSize = j # no primitive types in subtype table
# prep SIT
for i in range(len(interM)):
......
......@@ -327,6 +327,21 @@ class AssignNode(ASTNode):
self.code = self.right.code
self.code += p("push", "eax")
# array assign check
if self.left.__class__.__name__ == "ArrayAccessNode" and (not self.left.myType.isPrimitive):
self.code += "; array assign subtype check\n"
self.left.array.codeGen()
self.code += self.left.array.code
offset = self.right.myType.typePointer.subTypeOffset
self.code += p("mov", "ebx", "[eax]", "start subtype test") # access class tag of left object
self.code += p("mov", "ebx", "[ebx + 4]") # access subtype testing column
self.code += p("mov", "ebx", "[ebx + " + str(offset) + "]") # ebx has isSubtype
# exception if not subtype, else do nothing (object is already in eax)
self.code += p("cmp", "[G__Zero]", "ebx")
self.code += p("je", "H__Throw_Exception")
self.code +=("; Evaluate left of assignment\n")
self.code += self.left.addr()
......
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