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

array cast instance of

parent 031c4751
No related branches found
No related tags found
2 merge requests!26Array subtype,!20Master
......@@ -387,8 +387,9 @@ class CastNode(ASTNode):
self.code += self.right.code
# subtype test:
if not self.left.myType.isPrimitive:
# only test if right is not primitive (primitive types would be correctly static tested already)
if (not self.left.myType.isPrimitive) and self.right.myType.isArray == self.left.myType.isArray:
# only test if not primitive, both are array or both non array
# cast would've exception if array is casting to non-array and not Object
offset = self.left.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
......@@ -578,8 +579,8 @@ class ExprNode(ASTNode):
self.left.codeGen()
self.code += self.left.code
# only test if non-primitive
if not self.right.myType.isPrimitive:
# only test if non-primitive, both arrays or both non arrays
if (not self.right.myType.isPrimitive) and self.right.myType.isArray == self.left.myType.isArray:
offset = self.right.myType.typePointer.subTypeOffset
self.code += p("mov", "eax", "[eax]") # access class tag of left object
self.code += p("mov", "eax", "[eax + 4]") # access subtype testing column
......
......@@ -19,8 +19,7 @@ class ClassInterNode(ASTNode):
self.SITsize = 0
self.subTypeSize = 0
self.subTypeOffset = 0
self.arrayTypeOffset = 0 # only array assignable classes will have this field set
# sets
self.inherits = []
self.super = []
......@@ -308,13 +307,6 @@ class ClassNode(ClassInterNode):
# Calculating the size of objects of this class
self.size += (len(self.fieldOffset))*4
assignable = dict({"java.lang.Object" : 4,
"java.lang.Cloneable" : 8,
"java.io.Serializable" : 12
}) # fix offsets for array assignable classes, 0 row is reserve for all the non assignable ones
if self.canonName in assignable.keys():
self.arrayTypeOffset = assignable[self.canonName]
# Populating method offset and creating class memory layout
def populateMethodOffset(self):
if hasattr(self, "data"):
......@@ -392,7 +384,7 @@ class ClassNode(ClassInterNode):
self.data += p("dd", "42")
# Layout subtype testing column
self.data += pLabel("subT_" + self.name, "inter")
self.data += pLabel("subT_" + self.name, "array")
for i in range(self.subTypeSize):
self.data += pLabel("subT_" + str(i), "inter")
self.data += p("dd", "0") # 0 for False, 1 for True
......@@ -451,7 +443,7 @@ class ClassNode(ClassInterNode):
# fill in subtype testing column
self.code += "\n; Filling in subtype testing\n"
self.code += p("mov", "eax", "I_subT_spot_" + self.name)
self.code += p("mov", "[eax]", "dword I_subT_" + self.name)
self.code += p("mov", "[eax]", "dword A_subT_" + self.name)
for t in getSupers(self): # getSupers includes self
dlabel = "I_subT_" + str(t.subTypeOffset // 4)
......
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