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

fix issue with arrayClass.s files being overwritten and the error with class being in compid

parent cfe91701
No related branches found
No related tags found
1 merge request!20Master
......@@ -65,6 +65,7 @@ def arrayClassMemory(types):
# TODO: add subtype testing table
methods = ["M_Object_Object_", "M_Object_equals_Object", "M_Object_toString_", "M_Object_hashCode_", "M_Object_clone_", "M_Object_getClass_"]
typeDict = {}
primTypes = ['boolean', 'byte', 'char', 'int', 'short'] # All possible types
for t in types:
# Class memory layout
# Label: "A_type"
......@@ -95,8 +96,10 @@ def arrayClassMemory(types):
p(instruction="mov", arg1="[eax]", arg2="dword "+m, comment="points to method implementation")
code += p(instruction="ret", arg1="")
code += "; End of function to initialize class memory layout\n"
typeDict[t] = code
if t in primTypes:
typeDict[('P', t)] = code # primitive types (for file name)
else:
typeDict[('T', t)] = code # non primitive types
return typeDict
......@@ -179,11 +182,11 @@ def startGen(ASTs, output, arrayClassMemory):
callArrayInit = "; Start of calling each array type's arrayMemoryInitialize\n"
for t, code in arrayClassMemory.items():
label = "H_" + t + "_arrayMemoryInitialize"
label = "H_" + t[1] + "_arrayMemoryInitialize"
callArrayInit += p(instruction="extern", arg1=label) + \
p(instruction="call", arg1=label)
# Creating .s files for each array type to store the class memory layout
fileName = output + "/" + t + "_arrayClass" + ".s"
fileName = output + "/" + t[0] + '_' + t[1] + "_arrayClass" + ".s"
f = open(fileName, "w")
f.write(code)
f.close()
......
......@@ -524,8 +524,6 @@ def scan(input):
for i, t in enumerate(temp):
if i == 0 and t in wrongJavaKeyWordDict:
return (None, "wrong keyword in comp id")
if i is not 0 and (t == 'Class' or t == 'class'):
return (None, "wrong keyword in comp id")
if i is not 0 and t == 'this':
return (None, "this cannot be in the middle of a compid")
......
......@@ -7,7 +7,7 @@ public class Main {
public int j = 5;
public static int test() {
Interface a = new pkg.Class1();
Interface a = new pkg.Class();
Object o = a.clone();
return o.hashCode() + a.k(2);
}
......
// CODE_GENERATION
package pkg;
public class Class1 implements Interface {
public Class1() {}
public class Class implements Interface {
public Class() {}
public Object clone() { return this; }
public int k(int i) {return i + 42;}
}
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