|
@@ -7,7 +7,6 @@ import org.openzen.zenscript.codemodel.FunctionParameter;
|
7
|
7
|
import org.openzen.zenscript.codemodel.definition.*;
|
8
|
8
|
import org.openzen.zenscript.codemodel.expression.Expression;
|
9
|
9
|
import org.openzen.zenscript.codemodel.expression.ExpressionVisitor;
|
10
|
|
-import org.openzen.zenscript.codemodel.generic.TypeParameter;
|
11
|
10
|
import org.openzen.zenscript.codemodel.member.ConstructorMember;
|
12
|
11
|
import org.openzen.zenscript.codemodel.member.EnumConstantMember;
|
13
|
12
|
import org.openzen.zenscript.codemodel.member.FieldMember;
|
|
@@ -20,7 +19,6 @@ import org.openzen.zenscript.codemodel.type.ITypeID;
|
20
|
19
|
import org.openzen.zenscript.javabytecode.JavaClassInfo;
|
21
|
20
|
import org.openzen.zenscript.javabytecode.JavaEnumInfo;
|
22
|
21
|
import org.openzen.zenscript.javabytecode.JavaMethodInfo;
|
23
|
|
-import org.openzen.zenscript.javabytecode.TestIsStaticInfo;
|
24
|
22
|
import org.openzen.zenscript.javabytecode.compiler.*;
|
25
|
23
|
|
26
|
24
|
import java.util.Iterator;
|
|
@@ -45,6 +43,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
|
45
|
43
|
else
|
46
|
44
|
superType = Type.getType(definition.superType.accept(JavaTypeClassVisitor.INSTANCE));
|
47
|
45
|
|
|
46
|
+ JavaClassInfo toClass = new JavaClassInfo(definition.name);
|
48
|
47
|
JavaClassWriter writer = new JavaClassWriter(ClassWriter.COMPUTE_FRAMES);
|
49
|
48
|
|
50
|
49
|
//TODO: Calculate signature from generic parameters
|
|
@@ -56,8 +55,6 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
|
56
|
55
|
for (IDefinitionMember member : definition.members) {
|
57
|
56
|
if (member instanceof ConstructorMember) {
|
58
|
57
|
final ConstructorMember constructorMember = (ConstructorMember) member;
|
59
|
|
-
|
60
|
|
-
|
61
|
58
|
constructorMember.body.add(0, new ExpressionStatement(constructorMember.position, new Expression(constructorMember.position, BasicTypeID.VOID) {
|
62
|
59
|
@Override
|
63
|
60
|
public <T> T accept(ExpressionVisitor<T> visitor) {
|
|
@@ -79,9 +76,8 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
|
79
|
76
|
}
|
80
|
77
|
}));
|
81
|
78
|
}
|
82
|
|
- member.accept(new JavaMemberVisitor(writer, definition.name));
|
83
|
|
-
|
84
|
|
-
|
|
79
|
+
|
|
80
|
+ member.accept(new JavaMemberVisitor(writer, toClass));
|
85
|
81
|
}
|
86
|
82
|
writer.visitEnd();
|
87
|
83
|
return writer.toByteArray();
|
|
@@ -89,6 +85,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
|
89
|
85
|
|
90
|
86
|
@Override
|
91
|
87
|
public byte[] visitInterface(InterfaceDefinition definition) {
|
|
88
|
+ JavaClassInfo toClass = new JavaClassInfo(definition.name);
|
92
|
89
|
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
|
93
|
90
|
|
94
|
91
|
//TODO: Calculate signature from generic parameters
|
|
@@ -96,7 +93,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
|
96
|
93
|
String signature = null;
|
97
|
94
|
writer.visit(Opcodes.V1_8, definition.modifiers | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT, definition.name, signature, Type.getInternalName(Object.class), null);
|
98
|
95
|
for (IDefinitionMember member : definition.members) {
|
99
|
|
- member.accept(new JavaMemberVisitor(writer, definition.name));
|
|
96
|
+ member.accept(new JavaMemberVisitor(writer, toClass));
|
100
|
97
|
}
|
101
|
98
|
writer.visitEnd();
|
102
|
99
|
return writer.toByteArray();
|
|
@@ -123,8 +120,10 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
|
123
|
120
|
}
|
124
|
121
|
}
|
125
|
122
|
|
126
|
|
- final JavaWriter clinitWriter = new JavaWriter(writer, true, Opcodes.ACC_STATIC, "<clinit>", "()V", null, null);
|
127
|
|
- final JavaStatementVisitor clinitVisitor = new JavaStatementVisitor(clinitWriter, true);
|
|
123
|
+ JavaClassInfo toClass = new JavaClassInfo(definition.name);
|
|
124
|
+ JavaMethodInfo clinitInfo = new JavaMethodInfo(toClass, "<clinit>", "()V", Opcodes.ACC_STATIC);
|
|
125
|
+ final JavaWriter clinitWriter = new JavaWriter(writer, clinitInfo, null, null);
|
|
126
|
+ final JavaStatementVisitor clinitVisitor = new JavaStatementVisitor(clinitWriter);
|
128
|
127
|
clinitVisitor.start();
|
129
|
128
|
int constantCount = 0;
|
130
|
129
|
for (IDefinitionMember member : definition.members) {
|
|
@@ -151,7 +150,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
|
151
|
150
|
++constantCount;
|
152
|
151
|
member.setTag(JavaEnumInfo.class, new JavaEnumInfo(clinitVisitor));
|
153
|
152
|
}
|
154
|
|
- member.accept(new JavaMemberVisitor(writer, definition.name));
|
|
153
|
+ member.accept(new JavaMemberVisitor(writer, toClass));
|
155
|
154
|
}
|
156
|
155
|
|
157
|
156
|
clinitWriter.constant(constantCount);
|
|
@@ -171,7 +170,8 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
|
171
|
170
|
//Enum Stuff(required!)
|
172
|
171
|
writer.visitField(Opcodes.ACC_STATIC | Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL | Opcodes.ACC_SYNTHETIC, "$VALUES", "[L" + definition.name + ";", null, null).visitEnd();
|
173
|
172
|
|
174
|
|
- JavaWriter valuesWriter = new JavaWriter(writer, true, Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC, "values", "()[L" + definition.name + ";", null, null);
|
|
173
|
+ JavaMethodInfo valuesMethodInfo = new JavaMethodInfo(toClass, "values", "()[L" + definition.name + ";", Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC);
|
|
174
|
+ JavaWriter valuesWriter = new JavaWriter(writer, true, valuesMethodInfo, null, null);
|
175
|
175
|
valuesWriter.start();
|
176
|
176
|
valuesWriter.getStaticField(definition.name, "$VALUES", "[L" + definition.name + ";");
|
177
|
177
|
valuesWriter.invokeVirtual("[L" + definition.name + ";", "clone", "()Ljava/lang/Object;");
|
|
@@ -179,8 +179,8 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
|
179
|
179
|
valuesWriter.returnObject();
|
180
|
180
|
valuesWriter.end();
|
181
|
181
|
|
182
|
|
-
|
183
|
|
- JavaWriter valueOfWriter = new JavaWriter(writer, true, Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC, "valueOf", "(Ljava/lang/String;)L" + definition.name + ";", null, null);
|
|
182
|
+ JavaMethodInfo valueOfMethodInfo = new JavaMethodInfo(toClass, "valueOf", "(Ljava/lang/String;)L" + definition.name + ";", Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC);
|
|
183
|
+ JavaWriter valueOfWriter = new JavaWriter(writer, true, valueOfMethodInfo, null, null);
|
184
|
184
|
valueOfWriter.start();
|
185
|
185
|
valueOfWriter.invokeStatic("java/lang/Class", "forName", "(Ljava/lang/String;)Ljava/lang/Class;");
|
186
|
186
|
valueOfWriter.loadObject(0);
|
|
@@ -202,7 +202,11 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
|
202
|
202
|
@Override
|
203
|
203
|
public byte[] visitFunction(FunctionDefinition definition) {
|
204
|
204
|
final String signature = CompilerUtils.calcSign(definition.header, false);
|
205
|
|
- final JavaWriter writer = new JavaWriter(outerWriter, true, CompilerUtils.calcAccess(definition.modifiers) | Opcodes.ACC_STATIC, definition.name, CompilerUtils.calcDesc(definition.header, false), signature, null);
|
|
205
|
+
|
|
206
|
+ final JavaClassInfo toClass = new JavaClassInfo(CompilerUtils.calcClasName(definition.position));
|
|
207
|
+ final JavaMethodInfo methodInfo = new JavaMethodInfo(toClass, definition.name, CompilerUtils.calcDesc(definition.header, false), CompilerUtils.calcAccess(definition.modifiers) | Opcodes.ACC_STATIC);
|
|
208
|
+
|
|
209
|
+ final JavaWriter writer = new JavaWriter(outerWriter, true, methodInfo, signature, null);
|
206
|
210
|
final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(writer);
|
207
|
211
|
statementVisitor.start();
|
208
|
212
|
final Iterator<Statement> statementIterator = definition.statements.iterator();
|
|
@@ -222,13 +226,10 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
|
222
|
226
|
writer.aConstNull();
|
223
|
227
|
writer.returnType(type.accept(JavaTypeVisitor.INSTANCE));
|
224
|
228
|
}
|
225
|
|
-
|
226
|
229
|
}
|
227
|
230
|
|
228
|
231
|
statementVisitor.end();
|
229
|
|
-
|
230
|
|
- final JavaMethodInfo methodInfo = new JavaMethodInfo(new JavaClassInfo(CompilerUtils.calcClasName(definition.position)), definition.name, signature, true);
|
231
|
|
-
|
|
232
|
+
|
232
|
233
|
definition.setTag(JavaMethodInfo.class, methodInfo);
|
233
|
234
|
definition.caller.setTag(JavaMethodInfo.class, methodInfo);
|
234
|
235
|
return null;
|