Browse Source

WIP on new tags, refactoring & tag preparation system.

Stan Hebben 6 years ago
parent
commit
62d5db3fc0
35 changed files with 1018 additions and 715 deletions
  1. 3
    0
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleReference.java
  2. 6
    5
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java
  3. 100
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaContext.java
  4. 0
    24
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaFieldInfo.java
  5. 2
    2
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaModule.java
  6. 39
    60
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/CompilerUtils.java
  7. 168
    198
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
  8. 0
    109
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaOptionalTypeClassVisitor.java
  9. 5
    2
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreDecrementVisitor.java
  10. 5
    2
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreIncrementVisitor.java
  11. 11
    7
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java
  12. 0
    98
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaTypeClassVisitor.java
  13. 0
    60
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaTypeVisitor.java
  14. 25
    25
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java
  15. 14
    13
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaDefinitionVisitor.java
  16. 25
    22
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaMemberVisitor.java
  17. 12
    0
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaClass.java
  18. 5
    5
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaField.java
  19. 1
    2
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaSynthesizedClass.java
  20. 50
    0
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaSynthesizedClassNamer.java
  21. 19
    0
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaSyntheticClassGenerator.java
  22. 2
    2
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaSyntheticTypeSignatureConverter.java
  23. 119
    0
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeDescriptorVisitor.java
  24. 115
    0
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeInternalNameVisitor.java
  25. 5
    2
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceCompiler.java
  26. 25
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceContext.java
  27. 3
    3
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceExpressionFormatter.java
  28. 16
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceFile.java
  29. 54
    32
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceSyntheticTypeGenerator.java
  30. 2
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceTypeVisitor.java
  31. 13
    9
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareClassMethodVisitor.java
  32. 154
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareDefinitionMemberVisitor.java
  33. 11
    25
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareDefinitionVisitor.java
  34. 7
    4
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareExpansionMethodVisitor.java
  35. 2
    2
      ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/GlobalRegistry.java

+ 3
- 0
Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleReference.java View File

@@ -115,6 +115,9 @@ public class DirectoryModuleReference implements ModuleReference {
115 115
 	}
116 116
 	
117 117
 	private SourcePackage loadPackage(String name, File directory) {
118
+		if (!directory.exists())
119
+			throw new IllegalArgumentException("Directory does not exist: " + directory.getAbsolutePath());
120
+		
118 121
 		SourcePackage pkg = new SourcePackage(directory, name);
119 122
 		
120 123
 		for (File file : directory.listFiles()) {

+ 6
- 5
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java View File

@@ -35,8 +35,8 @@ public class JavaCompiler implements ZenCodeCompiler {
35 35
 	private final JavaClassWriter scriptsClassWriter;
36 36
 	private int generatedScriptBlockCounter = 0;
37 37
 	private boolean finished = false;
38
-	private JavaModule compiled = null;
39 38
 	private final File jarFile;
39
+	private final JavaContext context;
40 40
 	
41 41
 	public JavaCompiler(File jarFile) {
42 42
 		this(false, jarFile);
@@ -45,6 +45,7 @@ public class JavaCompiler implements ZenCodeCompiler {
45 45
 	public JavaCompiler(boolean debug, File jarFile) {
46 46
 		target = new JavaModule();
47 47
 		this.jarFile = jarFile;
48
+		this.context = new JavaContext(target);
48 49
 		
49 50
 		scriptsClassWriter = new JavaClassWriter(ClassWriter.COMPUTE_FRAMES);
50 51
 		scriptsClassWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, "Scripts", null, "java/lang/Object", null);
@@ -54,7 +55,7 @@ public class JavaCompiler implements ZenCodeCompiler {
54 55
 	public void addDefinition(HighLevelDefinition definition, SemanticModule module) {
55 56
 		String className = getClassName(definition.position.getFilename());
56 57
 		JavaScriptFile scriptFile = getScriptFile(className);
57
-		target.register(definition.name, definition.accept(new JavaDefinitionVisitor(scriptFile.classWriter)));
58
+		target.register(definition.name, definition.accept(new JavaDefinitionVisitor(context, scriptFile.classWriter)));
58 59
 	}
59 60
 	
60 61
 	@Override
@@ -71,7 +72,7 @@ public class JavaCompiler implements ZenCodeCompiler {
71 72
 		JavaMethodInfo method = new JavaMethodInfo(new JavaClass(script.pkg.fullName, className, JavaClass.Kind.CLASS), methodName, "()V", Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);
72 73
 		scriptFile.scriptMethods.add(method);
73 74
 		
74
-		final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(new JavaWriter(visitor, method, null, null, null));
75
+		final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, new JavaWriter(visitor, method, null, null, null));
75 76
 		statementVisitor.start();
76 77
 		for (Statement statement : script.statements) {
77 78
 			statement.accept(statementVisitor);
@@ -111,7 +112,7 @@ public class JavaCompiler implements ZenCodeCompiler {
111 112
 	
112 113
 	@Override
113 114
 	public void run() {
114
-		if (compiled == null)
115
+		if (!finished)
115 116
 			throw new IllegalStateException("Not yet built!");
116 117
 		
117 118
 		// TODO: execute this
@@ -120,6 +121,7 @@ public class JavaCompiler implements ZenCodeCompiler {
120 121
 	public JavaModule finishAndGetModule() {
121 122
 		if (finished)
122 123
 			throw new IllegalStateException("Already finished!");
124
+		
123 125
 		finished = true;
124 126
 		
125 127
 		JavaMethodInfo runMethod = new JavaMethodInfo(new JavaClass("script", "Scripts", JavaClass.Kind.CLASS), "run", "()V", Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);
@@ -136,7 +138,6 @@ public class JavaCompiler implements ZenCodeCompiler {
136 138
 		runWriter.end();
137 139
 		
138 140
 		target.register("Scripts", scriptsClassWriter.toByteArray());
139
-		
140 141
 		return target;
141 142
 	}
142 143
 }

+ 100
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaContext.java View File

@@ -0,0 +1,100 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.javabytecode;
7
+
8
+import org.objectweb.asm.Type;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
+import org.openzen.zenscript.codemodel.FunctionParameter;
11
+import org.openzen.zenscript.codemodel.type.FunctionTypeID;
12
+import org.openzen.zenscript.codemodel.type.ITypeID;
13
+import org.openzen.zenscript.codemodel.type.RangeTypeID;
14
+import org.openzen.zenscript.javabytecode.compiler.CompilerUtils;
15
+import org.openzen.zenscript.javashared.JavaSynthesizedClass;
16
+import org.openzen.zenscript.javashared.JavaSyntheticClassGenerator;
17
+import org.openzen.zenscript.javashared.JavaTypeDescriptorVisitor;
18
+import org.openzen.zenscript.javashared.JavaTypeInternalNameVisitor;
19
+
20
+/**
21
+ *
22
+ * @author Hoofdgebruiker
23
+ */
24
+public class JavaContext {
25
+	private final JavaModule module;
26
+	private final TypeGenerator typeGenerator;
27
+	private final JavaTypeInternalNameVisitor internalNameVisitor;
28
+	private final JavaTypeDescriptorVisitor descriptorVisitor;
29
+	
30
+	public JavaContext(JavaModule module) {
31
+		this.module = module;
32
+		
33
+		typeGenerator = new TypeGenerator();
34
+		internalNameVisitor = new JavaTypeInternalNameVisitor(typeGenerator);
35
+		descriptorVisitor = new JavaTypeDescriptorVisitor(typeGenerator);
36
+	}
37
+	
38
+	public JavaSyntheticClassGenerator getTypeGenerator() {
39
+		return typeGenerator;
40
+	}
41
+	
42
+	public String getDescriptor(ITypeID type) {
43
+		return type.accept(descriptorVisitor);
44
+	}
45
+	
46
+	public String getInternalName(ITypeID type) {
47
+		return type.accept(internalNameVisitor);
48
+	}
49
+	
50
+	public Type getType(ITypeID type) {
51
+		return Type.getType(getDescriptor(type));
52
+	}
53
+	
54
+	public String getMethodDescriptor(FunctionHeader header) {
55
+		return getMethodDescriptor(header, false);
56
+	}
57
+	
58
+    public String getMethodSignature(FunctionHeader header) {
59
+        StringBuilder signatureBuilder = new StringBuilder("(");
60
+        for (FunctionParameter parameter : header.parameters) {
61
+            signatureBuilder.append(getDescriptor(parameter.type));
62
+        }
63
+        signatureBuilder.append(")").append(getDescriptor(header.returnType));
64
+        return signatureBuilder.toString();
65
+    }
66
+	
67
+	public String getEnumConstructorDescriptor(FunctionHeader header) {
68
+		return getMethodDescriptor(header, true);
69
+	}
70
+	
71
+	private String getMethodDescriptor(FunctionHeader header, boolean isEnumConstructor) {
72
+        StringBuilder descBuilder = new StringBuilder("(");
73
+        if (isEnumConstructor)
74
+            descBuilder.append("Ljava/lang/String;I");
75
+		
76
+        for (FunctionParameter parameter : header.parameters) {
77
+			descBuilder.append(getDescriptor(parameter.type));
78
+        }
79
+        descBuilder.append(")");
80
+        descBuilder.append(getDescriptor(header.returnType));
81
+        return descBuilder.toString();
82
+    }
83
+	
84
+	public void register(String name, byte[] bytecode) {
85
+		module.register(name, bytecode);
86
+	}
87
+	
88
+	private class TypeGenerator implements JavaSyntheticClassGenerator {
89
+
90
+		@Override
91
+		public JavaSynthesizedClass synthesizeFunction(FunctionTypeID type) {
92
+			return CompilerUtils.getLambdaInterface(JavaContext.this, type);
93
+		}
94
+
95
+		@Override
96
+		public JavaSynthesizedClass synthesizeRange(RangeTypeID type) {
97
+			throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
98
+		}
99
+	}
100
+}

+ 0
- 24
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaFieldInfo.java View File

@@ -1,24 +0,0 @@
1
-/*
2
- * To change this license header, choose License Headers in Project Properties.
3
- * To change this template file, choose Tools | Templates
4
- * and open the template in the editor.
5
- */
6
-package org.openzen.zenscript.javabytecode;
7
-
8
-import org.openzen.zenscript.javashared.JavaClass;
9
-
10
-/**
11
- *
12
- * @author Hoofdgebruiker
13
- */
14
-public class JavaFieldInfo {
15
-	public final JavaClass javaClass;
16
-	public final String name;
17
-	public final String signature;
18
-	
19
-	public JavaFieldInfo(JavaClass javaClass, String name, String signature) {
20
-		this.javaClass = javaClass;
21
-		this.name = name;
22
-		this.signature = signature;
23
-	}
24
-}

+ 2
- 2
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaModule.java View File

@@ -48,9 +48,9 @@ public class JavaModule {
48 48
 
49 49
 		@Override
50 50
 		public Class<?> loadClass(String name) throws ClassNotFoundException {
51
-			if(customClasses.containsKey(name))
51
+			if (customClasses.containsKey(name))
52 52
 				return customClasses.get(name);
53
-			if(classes.containsKey(name)) {
53
+			if (classes.containsKey(name)) {
54 54
 				final byte[] bytes = classes.get(name);
55 55
 				customClasses.put(name, defineClass(name, bytes, 0, bytes.length, null));
56 56
 				return customClasses.get(name);

+ 39
- 60
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/CompilerUtils.java View File

@@ -19,37 +19,20 @@ import org.openzen.zenscript.codemodel.member.FieldMember;
19 19
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
20 20
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
21 21
 import org.openzen.zenscript.codemodel.type.ITypeID;
22
-import org.openzen.zenscript.javabytecode.JavaModule;
23 22
 import org.openzen.zenscript.javabytecode.JavaParameterInfo;
24 23
 
25
-import java.io.FileNotFoundException;
26 24
 import java.io.FileOutputStream;
27 25
 import java.io.IOException;
28 26
 import java.util.HashMap;
29 27
 import java.util.Map;
28
+import org.openzen.zenscript.codemodel.type.FunctionTypeID;
29
+import org.openzen.zenscript.javabytecode.JavaContext;
30
+import org.openzen.zenscript.javashared.JavaClass;
31
+import org.openzen.zenscript.javashared.JavaSynthesizedClass;
32
+import org.openzen.zenscript.javashared.JavaSynthesizedClassNamer;
30 33
 
31 34
 public class CompilerUtils {
32
-    public static String calcDesc(FunctionHeader header, boolean isEnum) {
33
-        StringBuilder descBuilder = new StringBuilder("(");
34
-        if (isEnum)
35
-            descBuilder.append("Ljava/lang/String;I");
36
-        for (FunctionParameter parameter : header.parameters) {
37
-            //descBuilder.append(Type.getDescriptor(parameter.type.accept(JavaTypeClassVisitor.INSTANCE)));
38
-            descBuilder.append(parameter.type.accept(JavaTypeVisitor.INSTANCE).getDescriptor());
39
-        }
40
-        descBuilder.append(")");
41
-        descBuilder.append(header.returnType.accept(JavaTypeVisitor.INSTANCE).getDescriptor());
42
-        return descBuilder.toString();
43
-    }
44
-
45
-    public static String calcSign(FunctionHeader header, boolean isEnum) {
46
-        StringBuilder signatureBuilder = new StringBuilder("(");
47
-        for (FunctionParameter parameter : header.parameters) {
48
-            signatureBuilder.append(parameter.type.accept(JavaTypeVisitor.INSTANCE).getDescriptor());
49
-        }
50
-        signatureBuilder.append(")").append(header.returnType.accept(JavaTypeVisitor.INSTANCE).getDescriptor());
51
-        return signatureBuilder.toString();
52
-    }
35
+	private CompilerUtils() {}
53 36
 
54 37
     public static boolean isPrimitive(ITypeID id) {
55 38
         if (id instanceof BasicTypeID) {
@@ -93,26 +76,24 @@ public class CompilerUtils {
93 76
         return position.getFilename().substring(0, position.getFilename().lastIndexOf('.')).replace("/", "_");
94 77
     }
95 78
 
96
-    public static void tagMethodParameters(FunctionHeader header, boolean isStatic) {
97
-        JavaTypeVisitor typeVisitor = new JavaTypeVisitor();
79
+    public static void tagMethodParameters(JavaContext context, FunctionHeader header, boolean isStatic) {
98 80
         for (int i = 0; i < header.parameters.length; i++) {
99 81
             FunctionParameter parameter = header.parameters[i];
100
-            Type parameterType = parameter.type.accept(typeVisitor);
82
+            Type parameterType = context.getType(parameter.type);
101 83
             parameter.setTag(JavaParameterInfo.class, new JavaParameterInfo(isStatic ? i : i + 1, parameterType));
102 84
         }
103 85
     }
104 86
 
105
-    public static void tagConstructorParameters(FunctionHeader header, boolean isEnum) {
106
-        JavaTypeVisitor typeVisitor = new JavaTypeVisitor();
87
+    public static void tagConstructorParameters(JavaContext context, FunctionHeader header, boolean isEnum) {
107 88
         for (int i = 0; i < header.parameters.length; i++) {
108 89
             FunctionParameter parameter = header.parameters[i];
109
-            Type parameterType = parameter.type.accept(typeVisitor);
90
+            Type parameterType = context.getType(parameter.type);
110 91
             parameter.setTag(JavaParameterInfo.class, new JavaParameterInfo(isEnum ? i + 3 : i + 1, parameterType));
111 92
         }
112 93
     }
113 94
 
114
-    public static void writeDefaultFieldInitializers(JavaWriter constructorWriter, HighLevelDefinition definition, boolean staticFields) {
115
-        JavaExpressionVisitor expressionVisitor = new JavaExpressionVisitor(constructorWriter);
95
+    public static void writeDefaultFieldInitializers(JavaContext context, JavaWriter constructorWriter, HighLevelDefinition definition, boolean staticFields) {
96
+        JavaExpressionVisitor expressionVisitor = new JavaExpressionVisitor(context, constructorWriter);
116 97
         for (final IDefinitionMember definitionMember : definition.members) {
117 98
             if (!(definitionMember instanceof FieldMember))
118 99
                 continue;
@@ -123,57 +104,55 @@ public class CompilerUtils {
123 104
                     constructorWriter.loadObject(0);
124 105
                 field.initializer.accept(expressionVisitor);
125 106
                 if (staticFields)
126
-                    constructorWriter.putStaticField(definition.name, field.name, Type.getDescriptor(field.type.accept(JavaTypeClassVisitor.INSTANCE)));
107
+                    constructorWriter.putStaticField(definition.name, field.name, context.getDescriptor(field.type));
127 108
                 else
128
-                    constructorWriter.putField(definition.name, field.name, Type.getDescriptor(field.type.accept(JavaTypeClassVisitor.INSTANCE)));
109
+                    constructorWriter.putField(definition.name, field.name, context.getDescriptor(field.type));
129 110
             }
130 111
         }
131 112
     }
132 113
 
133
-    private static final Map<String, String> lambdas = new HashMap<>();
134
-    private static int lambdaCounter = 0;
135
-    private static int lambdaICounter = 0;
136
-    public static String getLambdaInterface(final FunctionHeader header) {
137
-        StringBuilder builder = new StringBuilder("(");
138
-        for (FunctionParameter parameter : header.parameters) {
139
-            builder.append(parameter.type.accept(JavaTypeVisitor.INSTANCE).getDescriptor());
140
-        }
141
-
142
-        //final String identifier = header.toString();
143
-        final String identifier = builder.append(")").append(header.returnType.accept(JavaTypeVisitor.INSTANCE).getDescriptor()).toString();
144
-        if(!lambdas.containsKey(identifier)) {
145
-            final String name = "lambdaInterface" + ++lambdaICounter;
146
-            lambdas.put(identifier, name);
147
-            createLambdaInterface(header, name);
148
-        }
149
-        return lambdas.get(identifier);
114
+	private static final Map<String, JavaSynthesizedClass> functions = new HashMap<>();
115
+	
116
+    public static JavaSynthesizedClass getLambdaInterface(JavaContext context, FunctionTypeID function) {
117
+		String signature = JavaSynthesizedClassNamer.getFunctionSignature(function);
118
+		if (functions.containsKey(signature))
119
+			return functions.get(signature).withTypeParameters(JavaSynthesizedClassNamer.extractTypeParameters(function));
120
+		
121
+		JavaSynthesizedClass result = JavaSynthesizedClassNamer.createFunctionName(function);
122
+		functions.put(signature, result);
123
+		
124
+        createLambdaInterface(context, function.header, result.cls);
125
+        return result;
150 126
     }
151 127
 
152
-    private static void createLambdaInterface(FunctionHeader header, String name) {
128
+    private static void createLambdaInterface(JavaContext context, FunctionHeader header, JavaClass cls) {
153 129
         ClassWriter ifaceWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
154 130
         ifaceWriter.visitAnnotation("java/lang/FunctionalInterface", true).visitEnd();
155
-        ifaceWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT, name, null, "java/lang/Object", null);
156
-
157
-        ifaceWriter.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, "accept", calcDesc(header, false), calcSign(header, false), null).visitEnd();
131
+        ifaceWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT, cls.getClassName(), null, "java/lang/Object", null);
158 132
 
159
-        ifaceWriter.visitEnd();
133
+        ifaceWriter
134
+				.visitMethod(
135
+					Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT,
136
+					"accept",
137
+					context.getMethodDescriptor(header),
138
+					context.getMethodSignature(header),
139
+					null)
140
+				.visitEnd();
160 141
 
161
-        JavaModule.classes.putIfAbsent(name, ifaceWriter.toByteArray());
142
+        context.register(cls.internalName, ifaceWriter.toByteArray());
162 143
 
163
-        try (FileOutputStream out = new FileOutputStream(name + ".class")){
144
+        try (FileOutputStream out = new FileOutputStream(cls.getClassName() + ".class")){
164 145
             out.write(ifaceWriter.toByteArray());
165 146
         } catch (IOException e) {
166 147
             e.printStackTrace();
167 148
         }
168 149
     }
169 150
 
170
-
151
+	private static int lambdaCounter = 0;
171 152
     public static String getLambdaCounter() {
172 153
         return "lambda" + ++lambdaCounter;
173 154
     }
174 155
 
175
-
176
-
177 156
     public static int getKeyForSwitch(SwitchValue expression) {
178 157
 		return expression.accept(new SwitchKeyVisitor());
179 158
     }

+ 168
- 198
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java View File

@@ -1,9 +1,7 @@
1 1
 package org.openzen.zenscript.javabytecode.compiler;
2 2
 
3 3
 import java.util.Arrays;
4
-import java.util.Collection;
5 4
 import java.util.Comparator;
6
-import java.util.Map;
7 5
 import java.util.StringJoiner;
8 6
 import org.objectweb.asm.ClassWriter;
9 7
 import org.objectweb.asm.Label;
@@ -25,152 +23,136 @@ import org.openzen.zenscript.javabytecode.*;
25 23
 import java.io.FileOutputStream;
26 24
 import java.io.IOException;
27 25
 import org.openzen.zenscript.javashared.JavaClass;
26
+import org.openzen.zenscript.javashared.JavaField;
27
+import org.openzen.zenscript.javashared.JavaSynthesizedClassNamer;
28 28
 
29 29
 public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
30 30
 	private static final int PUBLIC = Opcodes.ACC_PUBLIC;
31 31
 	private static final int STATIC = Opcodes.ACC_STATIC;
32 32
 	private static final int PUBLIC_STATIC = PUBLIC | STATIC;
33 33
 
34
-	private static final JavaClass BOOLEAN = JavaCompileUtils.get(Boolean.class);
35
-	private static final JavaMethodInfo BOOLEAN_PARSE = new JavaMethodInfo(BOOLEAN, "parseBoolean", "(Ljava/lang/String;)Z", PUBLIC_STATIC);
36
-	private static final JavaMethodInfo BOOLEAN_TO_STRING = new JavaMethodInfo(BOOLEAN, "toString", "(Z)Ljava/lang/String;", PUBLIC_STATIC);
37
-	private static final JavaClass BYTE = JavaCompileUtils.get(Byte.class);
38
-	private static final JavaMethodInfo BYTE_PARSE = new JavaMethodInfo(BYTE, "parseByte", "(Ljava/lang/String;)B", PUBLIC_STATIC);
39
-	private static final JavaMethodInfo BYTE_PARSE_WITH_BASE = new JavaMethodInfo(BYTE, "parseByte", "(Ljava/lang/String;I)B", PUBLIC_STATIC);
40
-	private static final JavaFieldInfo BYTE_MIN_VALUE = new JavaFieldInfo(BYTE, "MIN_VALUE", "B");
41
-	private static final JavaFieldInfo BYTE_MAX_VALUE = new JavaFieldInfo(BYTE, "MAX_VALUE", "B");
42
-	private static final JavaMethodInfo BYTE_TO_STRING = new JavaMethodInfo(BYTE, "toString", "(B)Ljava/lang/String;", PUBLIC_STATIC);
43
-	private static final JavaClass SHORT = JavaCompileUtils.get(Short.class);
44
-	private static final JavaMethodInfo SHORT_PARSE = new JavaMethodInfo(SHORT, "parseShort", "(Ljava/lang/String;)S", PUBLIC_STATIC);
45
-	private static final JavaMethodInfo SHORT_PARSE_WITH_BASE = new JavaMethodInfo(SHORT, "parseShort", "(Ljava/lang/String;I)S", PUBLIC_STATIC);
46
-	private static final JavaFieldInfo SHORT_MIN_VALUE = new JavaFieldInfo(SHORT, "MIN_VALUE", "S");
47
-	private static final JavaFieldInfo SHORT_MAX_VALUE = new JavaFieldInfo(SHORT, "MAX_VALUE", "S");
48
-	private static final JavaMethodInfo SHORT_TO_STRING = new JavaMethodInfo(SHORT, "toString", "(S)Ljava/lang/String;", PUBLIC_STATIC);
49
-	private static final JavaClass INTEGER = JavaCompileUtils.get(Integer.class);
50
-	private static final JavaMethodInfo INTEGER_COMPARE_UNSIGNED = new JavaMethodInfo(INTEGER, "compareUnsigned", "(II)I", PUBLIC_STATIC);
51
-	private static final JavaMethodInfo INTEGER_DIVIDE_UNSIGNED = new JavaMethodInfo(INTEGER, "divideUnsigned", "(II)I", PUBLIC_STATIC);
52
-	private static final JavaMethodInfo INTEGER_REMAINDER_UNSIGNED = new JavaMethodInfo(INTEGER, "remainderUnsigned", "(II)I", PUBLIC_STATIC);
53
-	private static final JavaMethodInfo INTEGER_NUMBER_OF_TRAILING_ZEROS = new JavaMethodInfo(INTEGER, "numberOfTrailingZeros", "(I)I", PUBLIC_STATIC);
54
-	private static final JavaMethodInfo INTEGER_NUMBER_OF_LEADING_ZEROS = new JavaMethodInfo(INTEGER, "numberOfLeadingZeros", "(I)I", PUBLIC_STATIC);
55
-	private static final JavaMethodInfo INTEGER_PARSE = new JavaMethodInfo(INTEGER, "parseInt", "(Ljava/lang/String;)I", PUBLIC_STATIC);
56
-	private static final JavaMethodInfo INTEGER_PARSE_WITH_BASE = new JavaMethodInfo(INTEGER, "parseInt", "(Ljava/lang/String;I)I", PUBLIC_STATIC);
57
-	private static final JavaMethodInfo INTEGER_PARSE_UNSIGNED = new JavaMethodInfo(INTEGER, "parseUnsignedInt", "(Ljava/lang/String;)I", PUBLIC_STATIC);
58
-	private static final JavaMethodInfo INTEGER_PARSE_UNSIGNED_WITH_BASE = new JavaMethodInfo(INTEGER, "parseUnsignedInt", "(Ljava/lang/String;I)I", PUBLIC_STATIC);
59
-	private static final JavaMethodInfo INTEGER_HIGHEST_ONE_BIT = new JavaMethodInfo(INTEGER, "highestOneBit", "(I)I", PUBLIC_STATIC);
60
-	private static final JavaMethodInfo INTEGER_LOWEST_ONE_BIT = new JavaMethodInfo(INTEGER, "lowestOneBit", "(I)I", PUBLIC_STATIC);
61
-	private static final JavaMethodInfo INTEGER_BIT_COUNT = new JavaMethodInfo(INTEGER, "bitCount", "(I)I", PUBLIC_STATIC);
62
-	private static final JavaFieldInfo INTEGER_MIN_VALUE = new JavaFieldInfo(INTEGER, "MIN_VALUE", "I");
63
-	private static final JavaFieldInfo INTEGER_MAX_VALUE = new JavaFieldInfo(INTEGER, "MAX_VALUE", "I");
64
-	private static final JavaMethodInfo INTEGER_TO_STRING = new JavaMethodInfo(INTEGER, "toString", "(I)Ljava/lang/String;", PUBLIC_STATIC);
65
-	private static final JavaMethodInfo INTEGER_TO_UNSIGNED_STRING = new JavaMethodInfo(INTEGER, "toUnsignedString", "(I)Ljava/lang/String;", PUBLIC_STATIC);
66
-	private static final JavaClass LONG = JavaCompileUtils.get(Long.class);
67
-	private static final JavaMethodInfo LONG_COMPARE = new JavaMethodInfo(LONG, "compare", "(JJ)I", PUBLIC_STATIC);
68
-	private static final JavaMethodInfo LONG_COMPARE_UNSIGNED = new JavaMethodInfo(LONG, "compareUnsigned", "(JJ)I", PUBLIC_STATIC);
69
-	private static final JavaMethodInfo LONG_DIVIDE_UNSIGNED = new JavaMethodInfo(LONG, "divideUnsigned", "(JJ)J", PUBLIC_STATIC);
70
-	private static final JavaMethodInfo LONG_REMAINDER_UNSIGNED = new JavaMethodInfo(LONG, "remainderUnsigned", "(JJ)J", PUBLIC_STATIC);
71
-	private static final JavaMethodInfo LONG_NUMBER_OF_TRAILING_ZEROS = new JavaMethodInfo(LONG, "numberOfTrailingZeros", "(J)I", PUBLIC_STATIC);
72
-	private static final JavaMethodInfo LONG_NUMBER_OF_LEADING_ZEROS = new JavaMethodInfo(LONG, "numberOfLeadingZeros", "(J)I", PUBLIC_STATIC);
73
-	private static final JavaMethodInfo LONG_PARSE = new JavaMethodInfo(LONG, "parseLong", "(Ljava/lang/String;)J", PUBLIC_STATIC);
74
-	private static final JavaMethodInfo LONG_PARSE_WITH_BASE = new JavaMethodInfo(LONG, "parseLong", "(Ljava/lang/String;I)J", PUBLIC_STATIC);
75
-	private static final JavaMethodInfo LONG_PARSE_UNSIGNED = new JavaMethodInfo(LONG, "parseUnsignedLong", "(Ljava/lang/String;)J", PUBLIC_STATIC);
76
-	private static final JavaMethodInfo LONG_PARSE_UNSIGNED_WITH_BASE = new JavaMethodInfo(LONG, "parseUnsignedLong", "(Ljava/lang/String;I)J", PUBLIC_STATIC);
77
-	private static final JavaMethodInfo LONG_HIGHEST_ONE_BIT = new JavaMethodInfo(LONG, "highestOneBit", "(J)J", PUBLIC_STATIC);
78
-	private static final JavaMethodInfo LONG_LOWEST_ONE_BIT = new JavaMethodInfo(LONG, "lowestOneBit", "(J)J", PUBLIC_STATIC);
79
-	private static final JavaMethodInfo LONG_BIT_COUNT = new JavaMethodInfo(LONG, "bitCount", "(J)I", PUBLIC_STATIC);
80
-	private static final JavaFieldInfo LONG_MIN_VALUE = new JavaFieldInfo(LONG, "MIN_VALUE", "J");
81
-	private static final JavaFieldInfo LONG_MAX_VALUE = new JavaFieldInfo(LONG, "MAX_VALUE", "J");
82
-	private static final JavaMethodInfo LONG_TO_STRING = new JavaMethodInfo(LONG, "toString", "(J)Ljava/lang/String;", PUBLIC_STATIC);
83
-	private static final JavaMethodInfo LONG_TO_UNSIGNED_STRING = new JavaMethodInfo(LONG, "toUnsignedString", "(J)Ljava/lang/String;", PUBLIC_STATIC);
84
-	private static final JavaClass FLOAT = JavaCompileUtils.get(Float.class);
85
-	private static final JavaMethodInfo FLOAT_COMPARE = new JavaMethodInfo(FLOAT, "compare", "(FF)I", PUBLIC_STATIC);
86
-	private static final JavaMethodInfo FLOAT_PARSE = new JavaMethodInfo(FLOAT, "parseFloat", "(Ljava/lang/String;)F", PUBLIC_STATIC);
87
-	private static final JavaMethodInfo FLOAT_FROM_BITS = new JavaMethodInfo(FLOAT, "intBitsToFloat", "(I)F", PUBLIC_STATIC);
88
-	private static final JavaMethodInfo FLOAT_BITS = new JavaMethodInfo(FLOAT, "floatToRawIntBits", "(F)I", PUBLIC_STATIC);
89
-	private static final JavaFieldInfo FLOAT_MIN_VALUE = new JavaFieldInfo(FLOAT, "MIN_VALUE", "F");
90
-	private static final JavaFieldInfo FLOAT_MAX_VALUE = new JavaFieldInfo(FLOAT, "MAX_VALUE", "F");
91
-	private static final JavaMethodInfo FLOAT_TO_STRING = new JavaMethodInfo(FLOAT, "toString", "(F)Ljava/lang/String;", PUBLIC_STATIC);
92
-	private static final JavaClass DOUBLE = JavaCompileUtils.get(Double.class);
93
-	private static final JavaMethodInfo DOUBLE_COMPARE = new JavaMethodInfo(DOUBLE, "compare", "(DD)I", PUBLIC_STATIC);
94
-	private static final JavaMethodInfo DOUBLE_PARSE = new JavaMethodInfo(DOUBLE, "parseDouble", "(Ljava/lang/String;)D", PUBLIC_STATIC);
95
-	private static final JavaMethodInfo DOUBLE_FROM_BITS = new JavaMethodInfo(DOUBLE, "longBitsToDouble", "(J)D", PUBLIC_STATIC);
96
-	private static final JavaMethodInfo DOUBLE_BITS = new JavaMethodInfo(DOUBLE, "doubleToRawLongBits", "(D)J", PUBLIC_STATIC);
97
-	private static final JavaFieldInfo DOUBLE_MIN_VALUE = new JavaFieldInfo(DOUBLE, "MIN_VALUE", "D");
98
-	private static final JavaFieldInfo DOUBLE_MAX_VALUE = new JavaFieldInfo(DOUBLE, "MAX_VALUE", "D");
99
-	private static final JavaMethodInfo DOUBLE_TO_STRING = new JavaMethodInfo(DOUBLE, "toString", "(D)Ljava/lang/String;", PUBLIC_STATIC);
100
-	private static final JavaClass CHARACTER = JavaCompileUtils.get(Character.class);
101
-	private static final JavaMethodInfo CHARACTER_TO_LOWER_CASE = new JavaMethodInfo(CHARACTER, "toLowerCase", "()C", PUBLIC);
102
-	private static final JavaMethodInfo CHARACTER_TO_UPPER_CASE = new JavaMethodInfo(CHARACTER, "toUpperCase", "()C", PUBLIC);
103
-	private static final JavaFieldInfo CHARACTER_MIN_VALUE = new JavaFieldInfo(CHARACTER, "MIN_VALUE", "C");
104
-	private static final JavaFieldInfo CHARACTER_MAX_VALUE = new JavaFieldInfo(CHARACTER, "MAX_VALUE", "C");
105
-	private static final JavaMethodInfo CHARACTER_TO_STRING = new JavaMethodInfo(CHARACTER, "toString", "(C)Ljava/lang/String;", PUBLIC_STATIC);
106
-	private static final JavaClass STRING = JavaCompileUtils.get(String.class);
107
-	private static final JavaMethodInfo STRING_COMPARETO = new JavaMethodInfo(STRING, "compareTo", "(Ljava/lang/String;)I", PUBLIC);
108
-	private static final JavaMethodInfo STRING_CONCAT = new JavaMethodInfo(STRING, "concat", "(Ljava/lang/String;)Ljava/lang/String;", PUBLIC);
109
-	private static final JavaMethodInfo STRING_CHAR_AT = new JavaMethodInfo(STRING, "charAt", "(I)C", PUBLIC);
110
-	private static final JavaMethodInfo STRING_SUBSTRING = new JavaMethodInfo(STRING, "substring", "(II)Ljava/lang/String;", PUBLIC);
111
-	private static final JavaMethodInfo STRING_TRIM = new JavaMethodInfo(STRING, "trim", "()Ljava/lang/String;", PUBLIC);
112
-	private static final JavaMethodInfo STRING_TO_LOWER_CASE = new JavaMethodInfo(STRING, "toLowerCase", "()Ljava/lang/String;", PUBLIC);
113
-	private static final JavaMethodInfo STRING_TO_UPPER_CASE = new JavaMethodInfo(STRING, "toUpperCase", "()Ljava/lang/String;", PUBLIC);
114
-	private static final JavaMethodInfo STRING_LENGTH = new JavaMethodInfo(STRING, "length", "()I", PUBLIC);
115
-	private static final JavaMethodInfo STRING_CHARACTERS = new JavaMethodInfo(STRING, "toCharArray", "()[C", PUBLIC);
116
-	private static final JavaMethodInfo STRING_ISEMPTY = new JavaMethodInfo(STRING, "isEmpty", "()Z", PUBLIC);
117
-	private static final JavaClass ENUM = JavaCompileUtils.get(Enum.class);
118
-	private static final JavaMethodInfo ENUM_COMPARETO = new JavaMethodInfo(STRING, "compareTo", "(Ljava/lang/Enum;)I", PUBLIC);
119
-	private static final JavaMethodInfo ENUM_NAME = new JavaMethodInfo(STRING, "name", "()Ljava/lang/String;", PUBLIC);
120
-	private static final JavaMethodInfo ENUM_ORDINAL = new JavaMethodInfo(STRING, "ordinal", "()I", PUBLIC);
121
-	private static final JavaClass MAP = JavaCompileUtils.get(Map.class);
122
-	private static final JavaMethodInfo MAP_GET = new JavaMethodInfo(MAP, "get", "(Ljava/lang/Object;)Ljava/lang/Object;", PUBLIC);
123
-	private static final JavaMethodInfo MAP_PUT = new JavaMethodInfo(MAP, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", PUBLIC);
124
-	private static final JavaMethodInfo MAP_CONTAINS_KEY = new JavaMethodInfo(MAP, "containsKey", "(Ljava/lang/Object;)Z", PUBLIC);
125
-	private static final JavaMethodInfo MAP_SIZE = new JavaMethodInfo(MAP, "size", "()I", PUBLIC);
126
-	private static final JavaMethodInfo MAP_ISEMPTY = new JavaMethodInfo(MAP, "isEmpty", "()Z", PUBLIC);
127
-	private static final JavaMethodInfo MAP_KEYS = new JavaMethodInfo(MAP, "keys", "()Ljava/lang/Object;", PUBLIC);
128
-	private static final JavaMethodInfo MAP_VALUES = new JavaMethodInfo(MAP, "values", "()Ljava/lang/Object;", PUBLIC);
129
-	private static final JavaClass ARRAYS = JavaCompileUtils.get(Arrays.class);
130
-	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_OBJECTS = new JavaMethodInfo(ARRAYS, "copyOfRange", "([Ljava/lang/Object;II)[Ljava/lang/Object;", PUBLIC_STATIC);
131
-	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_BOOLS = new JavaMethodInfo(ARRAYS, "copyOfRange", "([ZII)[Z", PUBLIC_STATIC);
132
-	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_BYTES = new JavaMethodInfo(ARRAYS, "copyOfRange", "([BII)[B", PUBLIC_STATIC);
133
-	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_SHORTS = new JavaMethodInfo(ARRAYS, "copyOfRange", "([SII)[S", PUBLIC_STATIC);
134
-	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_INTS = new JavaMethodInfo(ARRAYS, "copyOfRange", "([III)[I", PUBLIC_STATIC);
135
-	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_LONGS = new JavaMethodInfo(ARRAYS, "copyOfRange", "([JII)[J", PUBLIC_STATIC);
136
-	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_FLOATS = new JavaMethodInfo(ARRAYS, "copyOfRange", "([FII)[F", PUBLIC_STATIC);
137
-	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_DOUBLES = new JavaMethodInfo(ARRAYS, "copyOfRange", "([DII)[D", PUBLIC_STATIC);
138
-	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_CHARS = new JavaMethodInfo(ARRAYS, "copyOfRange", "([CII)[C", PUBLIC_STATIC);
139
-	private static final JavaMethodInfo ARRAYS_EQUALS_OBJECTS = new JavaMethodInfo(ARRAYS, "equals", "([Ljava/lang/Object[Ljava/lang/Object)Z", PUBLIC_STATIC);
140
-	private static final JavaMethodInfo ARRAYS_EQUALS_BOOLS = new JavaMethodInfo(ARRAYS, "equals", "([Z[Z)Z", PUBLIC_STATIC);
141
-	private static final JavaMethodInfo ARRAYS_EQUALS_BYTES = new JavaMethodInfo(ARRAYS, "equals", "([B[B)Z", PUBLIC_STATIC);
142
-	private static final JavaMethodInfo ARRAYS_EQUALS_SHORTS = new JavaMethodInfo(ARRAYS, "equals", "([S[S)Z", PUBLIC_STATIC);
143
-	private static final JavaMethodInfo ARRAYS_EQUALS_INTS = new JavaMethodInfo(ARRAYS, "equals", "([I[I)Z", PUBLIC_STATIC);
144
-	private static final JavaMethodInfo ARRAYS_EQUALS_LONGS = new JavaMethodInfo(ARRAYS, "equals", "([L[L)Z", PUBLIC_STATIC);
145
-	private static final JavaMethodInfo ARRAYS_EQUALS_FLOATS = new JavaMethodInfo(ARRAYS, "equals", "([F[F)Z", PUBLIC_STATIC);
146
-	private static final JavaMethodInfo ARRAYS_EQUALS_DOUBLES = new JavaMethodInfo(ARRAYS, "equals", "([D[D)Z", PUBLIC_STATIC);
147
-	private static final JavaMethodInfo ARRAYS_EQUALS_CHARS = new JavaMethodInfo(ARRAYS, "equals", "([C[C)Z", PUBLIC_STATIC);
148
-	private static final JavaMethodInfo ARRAYS_DEEPHASHCODE = new JavaMethodInfo(ARRAYS, "deepHashCode", "([Ljava/lang/Object;)", PUBLIC_STATIC);
149
-	private static final JavaMethodInfo ARRAYS_HASHCODE_BOOLS = new JavaMethodInfo(ARRAYS, "hashCode", "([Z)I", PUBLIC_STATIC);
150
-	private static final JavaMethodInfo ARRAYS_HASHCODE_BYTES = new JavaMethodInfo(ARRAYS, "hashCode", "([B)I", PUBLIC_STATIC);
151
-	private static final JavaMethodInfo ARRAYS_HASHCODE_SHORTS = new JavaMethodInfo(ARRAYS, "hashCode", "([S)I", PUBLIC_STATIC);
152
-	private static final JavaMethodInfo ARRAYS_HASHCODE_INTS = new JavaMethodInfo(ARRAYS, "hashCode", "([I)I", PUBLIC_STATIC);
153
-	private static final JavaMethodInfo ARRAYS_HASHCODE_LONGS = new JavaMethodInfo(ARRAYS, "hashCode", "([L)I", PUBLIC_STATIC);
154
-	private static final JavaMethodInfo ARRAYS_HASHCODE_FLOATS = new JavaMethodInfo(ARRAYS, "hashCode", "([F)I", PUBLIC_STATIC);
155
-	private static final JavaMethodInfo ARRAYS_HASHCODE_DOUBLES = new JavaMethodInfo(ARRAYS, "hashCode", "([D)I", PUBLIC_STATIC);
156
-	private static final JavaMethodInfo ARRAYS_HASHCODE_CHARS = new JavaMethodInfo(ARRAYS, "hashCode", "([C)I", PUBLIC_STATIC);
157
-	private static final JavaClass OBJECT = JavaCompileUtils.get(Object.class);
158
-	private static final JavaMethodInfo OBJECT_HASHCODE = new JavaMethodInfo(OBJECT, "hashCode", "()I", PUBLIC);
159
-	private static final JavaClass COLLECTION = JavaCompileUtils.get(Collection.class);
160
-	private static final JavaMethodInfo COLLECTION_SIZE = new JavaMethodInfo(COLLECTION, "size", "()I", PUBLIC);
161
-	private static final JavaMethodInfo COLLECTION_TOARRAY = new JavaMethodInfo(COLLECTION, "toArray", "([Ljava/lang/Object;)[Ljava/lang/Object;", PUBLIC);
34
+	private static final JavaMethodInfo BOOLEAN_PARSE = new JavaMethodInfo(JavaClass.BOOLEAN, "parseBoolean", "(Ljava/lang/String;)Z", PUBLIC_STATIC);
35
+	private static final JavaMethodInfo BOOLEAN_TO_STRING = new JavaMethodInfo(JavaClass.BOOLEAN, "toString", "(Z)Ljava/lang/String;", PUBLIC_STATIC);
36
+	private static final JavaMethodInfo BYTE_PARSE = new JavaMethodInfo(JavaClass.BYTE, "parseByte", "(Ljava/lang/String;)B", PUBLIC_STATIC);
37
+	private static final JavaMethodInfo BYTE_PARSE_WITH_BASE = new JavaMethodInfo(JavaClass.BYTE, "parseByte", "(Ljava/lang/String;I)B", PUBLIC_STATIC);
38
+	private static final JavaField BYTE_MIN_VALUE = new JavaField(JavaClass.BYTE, "MIN_VALUE", "B");
39
+	private static final JavaField BYTE_MAX_VALUE = new JavaField(JavaClass.BYTE, "MAX_VALUE", "B");
40
+	private static final JavaMethodInfo BYTE_TO_STRING = new JavaMethodInfo(JavaClass.BYTE, "toString", "(B)Ljava/lang/String;", PUBLIC_STATIC);
41
+	private static final JavaMethodInfo SHORT_PARSE = new JavaMethodInfo(JavaClass.SHORT, "parseShort", "(Ljava/lang/String;)S", PUBLIC_STATIC);
42
+	private static final JavaMethodInfo SHORT_PARSE_WITH_BASE = new JavaMethodInfo(JavaClass.SHORT, "parseShort", "(Ljava/lang/String;I)S", PUBLIC_STATIC);
43
+	private static final JavaField SHORT_MIN_VALUE = new JavaField(JavaClass.SHORT, "MIN_VALUE", "S");
44
+	private static final JavaField SHORT_MAX_VALUE = new JavaField(JavaClass.SHORT, "MAX_VALUE", "S");
45
+	private static final JavaMethodInfo SHORT_TO_STRING = new JavaMethodInfo(JavaClass.SHORT, "toString", "(S)Ljava/lang/String;", PUBLIC_STATIC);
46
+	private static final JavaMethodInfo INTEGER_COMPARE_UNSIGNED = new JavaMethodInfo(JavaClass.INTEGER, "compareUnsigned", "(II)I", PUBLIC_STATIC);
47
+	private static final JavaMethodInfo INTEGER_DIVIDE_UNSIGNED = new JavaMethodInfo(JavaClass.INTEGER, "divideUnsigned", "(II)I", PUBLIC_STATIC);
48
+	private static final JavaMethodInfo INTEGER_REMAINDER_UNSIGNED = new JavaMethodInfo(JavaClass.INTEGER, "remainderUnsigned", "(II)I", PUBLIC_STATIC);
49
+	private static final JavaMethodInfo INTEGER_NUMBER_OF_TRAILING_ZEROS = new JavaMethodInfo(JavaClass.INTEGER, "numberOfTrailingZeros", "(I)I", PUBLIC_STATIC);
50
+	private static final JavaMethodInfo INTEGER_NUMBER_OF_LEADING_ZEROS = new JavaMethodInfo(JavaClass.INTEGER, "numberOfLeadingZeros", "(I)I", PUBLIC_STATIC);
51
+	private static final JavaMethodInfo INTEGER_PARSE = new JavaMethodInfo(JavaClass.INTEGER, "parseInt", "(Ljava/lang/String;)I", PUBLIC_STATIC);
52
+	private static final JavaMethodInfo INTEGER_PARSE_WITH_BASE = new JavaMethodInfo(JavaClass.INTEGER, "parseInt", "(Ljava/lang/String;I)I", PUBLIC_STATIC);
53
+	private static final JavaMethodInfo INTEGER_PARSE_UNSIGNED = new JavaMethodInfo(JavaClass.INTEGER, "parseUnsignedInt", "(Ljava/lang/String;)I", PUBLIC_STATIC);
54
+	private static final JavaMethodInfo INTEGER_PARSE_UNSIGNED_WITH_BASE = new JavaMethodInfo(JavaClass.INTEGER, "parseUnsignedInt", "(Ljava/lang/String;I)I", PUBLIC_STATIC);
55
+	private static final JavaMethodInfo INTEGER_HIGHEST_ONE_BIT = new JavaMethodInfo(JavaClass.INTEGER, "highestOneBit", "(I)I", PUBLIC_STATIC);
56
+	private static final JavaMethodInfo INTEGER_LOWEST_ONE_BIT = new JavaMethodInfo(JavaClass.INTEGER, "lowestOneBit", "(I)I", PUBLIC_STATIC);
57
+	private static final JavaMethodInfo INTEGER_BIT_COUNT = new JavaMethodInfo(JavaClass.INTEGER, "bitCount", "(I)I", PUBLIC_STATIC);
58
+	private static final JavaField INTEGER_MIN_VALUE = new JavaField(JavaClass.INTEGER, "MIN_VALUE", "I");
59
+	private static final JavaField INTEGER_MAX_VALUE = new JavaField(JavaClass.INTEGER, "MAX_VALUE", "I");
60
+	private static final JavaMethodInfo INTEGER_TO_STRING = new JavaMethodInfo(JavaClass.INTEGER, "toString", "(I)Ljava/lang/String;", PUBLIC_STATIC);
61
+	private static final JavaMethodInfo INTEGER_TO_UNSIGNED_STRING = new JavaMethodInfo(JavaClass.INTEGER, "toUnsignedString", "(I)Ljava/lang/String;", PUBLIC_STATIC);
62
+	private static final JavaMethodInfo LONG_COMPARE = new JavaMethodInfo(JavaClass.LONG, "compare", "(JJ)I", PUBLIC_STATIC);
63
+	private static final JavaMethodInfo LONG_COMPARE_UNSIGNED = new JavaMethodInfo(JavaClass.LONG, "compareUnsigned", "(JJ)I", PUBLIC_STATIC);
64
+	private static final JavaMethodInfo LONG_DIVIDE_UNSIGNED = new JavaMethodInfo(JavaClass.LONG, "divideUnsigned", "(JJ)J", PUBLIC_STATIC);
65
+	private static final JavaMethodInfo LONG_REMAINDER_UNSIGNED = new JavaMethodInfo(JavaClass.LONG, "remainderUnsigned", "(JJ)J", PUBLIC_STATIC);
66
+	private static final JavaMethodInfo LONG_NUMBER_OF_TRAILING_ZEROS = new JavaMethodInfo(JavaClass.LONG, "numberOfTrailingZeros", "(J)I", PUBLIC_STATIC);
67
+	private static final JavaMethodInfo LONG_NUMBER_OF_LEADING_ZEROS = new JavaMethodInfo(JavaClass.LONG, "numberOfLeadingZeros", "(J)I", PUBLIC_STATIC);
68
+	private static final JavaMethodInfo LONG_PARSE = new JavaMethodInfo(JavaClass.LONG, "parseLong", "(Ljava/lang/String;)J", PUBLIC_STATIC);
69
+	private static final JavaMethodInfo LONG_PARSE_WITH_BASE = new JavaMethodInfo(JavaClass.LONG, "parseLong", "(Ljava/lang/String;I)J", PUBLIC_STATIC);
70
+	private static final JavaMethodInfo LONG_PARSE_UNSIGNED = new JavaMethodInfo(JavaClass.LONG, "parseUnsignedLong", "(Ljava/lang/String;)J", PUBLIC_STATIC);
71
+	private static final JavaMethodInfo LONG_PARSE_UNSIGNED_WITH_BASE = new JavaMethodInfo(JavaClass.LONG, "parseUnsignedLong", "(Ljava/lang/String;I)J", PUBLIC_STATIC);
72
+	private static final JavaMethodInfo LONG_HIGHEST_ONE_BIT = new JavaMethodInfo(JavaClass.LONG, "highestOneBit", "(J)J", PUBLIC_STATIC);
73
+	private static final JavaMethodInfo LONG_LOWEST_ONE_BIT = new JavaMethodInfo(JavaClass.LONG, "lowestOneBit", "(J)J", PUBLIC_STATIC);
74
+	private static final JavaMethodInfo LONG_BIT_COUNT = new JavaMethodInfo(JavaClass.LONG, "bitCount", "(J)I", PUBLIC_STATIC);
75
+	private static final JavaField LONG_MIN_VALUE = new JavaField(JavaClass.LONG, "MIN_VALUE", "J");
76
+	private static final JavaField LONG_MAX_VALUE = new JavaField(JavaClass.LONG, "MAX_VALUE", "J");
77
+	private static final JavaMethodInfo LONG_TO_STRING = new JavaMethodInfo(JavaClass.LONG, "toString", "(J)Ljava/lang/String;", PUBLIC_STATIC);
78
+	private static final JavaMethodInfo LONG_TO_UNSIGNED_STRING = new JavaMethodInfo(JavaClass.LONG, "toUnsignedString", "(J)Ljava/lang/String;", PUBLIC_STATIC);
79
+	private static final JavaMethodInfo FLOAT_COMPARE = new JavaMethodInfo(JavaClass.FLOAT, "compare", "(FF)I", PUBLIC_STATIC);
80
+	private static final JavaMethodInfo FLOAT_PARSE = new JavaMethodInfo(JavaClass.FLOAT, "parseFloat", "(Ljava/lang/String;)F", PUBLIC_STATIC);
81
+	private static final JavaMethodInfo FLOAT_FROM_BITS = new JavaMethodInfo(JavaClass.FLOAT, "intBitsToFloat", "(I)F", PUBLIC_STATIC);
82
+	private static final JavaMethodInfo FLOAT_BITS = new JavaMethodInfo(JavaClass.FLOAT, "floatToRawIntBits", "(F)I", PUBLIC_STATIC);
83
+	private static final JavaField FLOAT_MIN_VALUE = new JavaField(JavaClass.FLOAT, "MIN_VALUE", "F");
84
+	private static final JavaField FLOAT_MAX_VALUE = new JavaField(JavaClass.FLOAT, "MAX_VALUE", "F");
85
+	private static final JavaMethodInfo FLOAT_TO_STRING = new JavaMethodInfo(JavaClass.FLOAT, "toString", "(F)Ljava/lang/String;", PUBLIC_STATIC);
86
+	private static final JavaMethodInfo DOUBLE_COMPARE = new JavaMethodInfo(JavaClass.DOUBLE, "compare", "(DD)I", PUBLIC_STATIC);
87
+	private static final JavaMethodInfo DOUBLE_PARSE = new JavaMethodInfo(JavaClass.DOUBLE, "parseDouble", "(Ljava/lang/String;)D", PUBLIC_STATIC);
88
+	private static final JavaMethodInfo DOUBLE_FROM_BITS = new JavaMethodInfo(JavaClass.DOUBLE, "longBitsToDouble", "(J)D", PUBLIC_STATIC);
89
+	private static final JavaMethodInfo DOUBLE_BITS = new JavaMethodInfo(JavaClass.DOUBLE, "doubleToRawLongBits", "(D)J", PUBLIC_STATIC);
90
+	private static final JavaField DOUBLE_MIN_VALUE = new JavaField(JavaClass.DOUBLE, "MIN_VALUE", "D");
91
+	private static final JavaField DOUBLE_MAX_VALUE = new JavaField(JavaClass.DOUBLE, "MAX_VALUE", "D");
92
+	private static final JavaMethodInfo DOUBLE_TO_STRING = new JavaMethodInfo(JavaClass.DOUBLE, "toString", "(D)Ljava/lang/String;", PUBLIC_STATIC);
93
+	private static final JavaMethodInfo CHARACTER_TO_LOWER_CASE = new JavaMethodInfo(JavaClass.CHARACTER, "toLowerCase", "()C", PUBLIC);
94
+	private static final JavaMethodInfo CHARACTER_TO_UPPER_CASE = new JavaMethodInfo(JavaClass.CHARACTER, "toUpperCase", "()C", PUBLIC);
95
+	private static final JavaField CHARACTER_MIN_VALUE = new JavaField(JavaClass.CHARACTER, "MIN_VALUE", "C");
96
+	private static final JavaField CHARACTER_MAX_VALUE = new JavaField(JavaClass.CHARACTER, "MAX_VALUE", "C");
97
+	private static final JavaMethodInfo CHARACTER_TO_STRING = new JavaMethodInfo(JavaClass.CHARACTER, "toString", "(C)Ljava/lang/String;", PUBLIC_STATIC);
98
+	private static final JavaMethodInfo STRING_COMPARETO = new JavaMethodInfo(JavaClass.STRING, "compareTo", "(Ljava/lang/String;)I", PUBLIC);
99
+	private static final JavaMethodInfo STRING_CONCAT = new JavaMethodInfo(JavaClass.STRING, "concat", "(Ljava/lang/String;)Ljava/lang/String;", PUBLIC);
100
+	private static final JavaMethodInfo STRING_CHAR_AT = new JavaMethodInfo(JavaClass.STRING, "charAt", "(I)C", PUBLIC);
101
+	private static final JavaMethodInfo STRING_SUBSTRING = new JavaMethodInfo(JavaClass.STRING, "substring", "(II)Ljava/lang/String;", PUBLIC);
102
+	private static final JavaMethodInfo STRING_TRIM = new JavaMethodInfo(JavaClass.STRING, "trim", "()Ljava/lang/String;", PUBLIC);
103
+	private static final JavaMethodInfo STRING_TO_LOWER_CASE = new JavaMethodInfo(JavaClass.STRING, "toLowerCase", "()Ljava/lang/String;", PUBLIC);
104
+	private static final JavaMethodInfo STRING_TO_UPPER_CASE = new JavaMethodInfo(JavaClass.STRING, "toUpperCase", "()Ljava/lang/String;", PUBLIC);
105
+	private static final JavaMethodInfo STRING_LENGTH = new JavaMethodInfo(JavaClass.STRING, "length", "()I", PUBLIC);
106
+	private static final JavaMethodInfo STRING_CHARACTERS = new JavaMethodInfo(JavaClass.STRING, "toCharArray", "()[C", PUBLIC);
107
+	private static final JavaMethodInfo STRING_ISEMPTY = new JavaMethodInfo(JavaClass.STRING, "isEmpty", "()Z", PUBLIC);
108
+	private static final JavaMethodInfo ENUM_COMPARETO = new JavaMethodInfo(JavaClass.ENUM, "compareTo", "(Ljava/lang/Enum;)I", PUBLIC);
109
+	private static final JavaMethodInfo ENUM_NAME = new JavaMethodInfo(JavaClass.ENUM, "name", "()Ljava/lang/String;", PUBLIC);
110
+	private static final JavaMethodInfo ENUM_ORDINAL = new JavaMethodInfo(JavaClass.ENUM, "ordinal", "()I", PUBLIC);
111
+	private static final JavaMethodInfo MAP_GET = new JavaMethodInfo(JavaClass.MAP, "get", "(Ljava/lang/Object;)Ljava/lang/Object;", PUBLIC);
112
+	private static final JavaMethodInfo MAP_PUT = new JavaMethodInfo(JavaClass.MAP, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", PUBLIC);
113
+	private static final JavaMethodInfo MAP_CONTAINS_KEY = new JavaMethodInfo(JavaClass.MAP, "containsKey", "(Ljava/lang/Object;)Z", PUBLIC);
114
+	private static final JavaMethodInfo MAP_SIZE = new JavaMethodInfo(JavaClass.MAP, "size", "()I", PUBLIC);
115
+	private static final JavaMethodInfo MAP_ISEMPTY = new JavaMethodInfo(JavaClass.MAP, "isEmpty", "()Z", PUBLIC);
116
+	private static final JavaMethodInfo MAP_KEYS = new JavaMethodInfo(JavaClass.MAP, "keys", "()Ljava/lang/Object;", PUBLIC);
117
+	private static final JavaMethodInfo MAP_VALUES = new JavaMethodInfo(JavaClass.MAP, "values", "()Ljava/lang/Object;", PUBLIC);
118
+	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_OBJECTS = new JavaMethodInfo(JavaClass.ARRAYS, "copyOfRange", "([Ljava/lang/Object;II)[Ljava/lang/Object;", PUBLIC_STATIC);
119
+	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_BOOLS = new JavaMethodInfo(JavaClass.ARRAYS, "copyOfRange", "([ZII)[Z", PUBLIC_STATIC);
120
+	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_BYTES = new JavaMethodInfo(JavaClass.ARRAYS, "copyOfRange", "([BII)[B", PUBLIC_STATIC);
121
+	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_SHORTS = new JavaMethodInfo(JavaClass.ARRAYS, "copyOfRange", "([SII)[S", PUBLIC_STATIC);
122
+	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_INTS = new JavaMethodInfo(JavaClass.ARRAYS, "copyOfRange", "([III)[I", PUBLIC_STATIC);
123
+	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_LONGS = new JavaMethodInfo(JavaClass.ARRAYS, "copyOfRange", "([JII)[J", PUBLIC_STATIC);
124
+	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_FLOATS = new JavaMethodInfo(JavaClass.ARRAYS, "copyOfRange", "([FII)[F", PUBLIC_STATIC);
125
+	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_DOUBLES = new JavaMethodInfo(JavaClass.ARRAYS, "copyOfRange", "([DII)[D", PUBLIC_STATIC);
126
+	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_CHARS = new JavaMethodInfo(JavaClass.ARRAYS, "copyOfRange", "([CII)[C", PUBLIC_STATIC);
127
+	private static final JavaMethodInfo ARRAYS_EQUALS_OBJECTS = new JavaMethodInfo(JavaClass.ARRAYS, "equals", "([Ljava/lang/Object[Ljava/lang/Object)Z", PUBLIC_STATIC);
128
+	private static final JavaMethodInfo ARRAYS_EQUALS_BOOLS = new JavaMethodInfo(JavaClass.ARRAYS, "equals", "([Z[Z)Z", PUBLIC_STATIC);
129
+	private static final JavaMethodInfo ARRAYS_EQUALS_BYTES = new JavaMethodInfo(JavaClass.ARRAYS, "equals", "([B[B)Z", PUBLIC_STATIC);
130
+	private static final JavaMethodInfo ARRAYS_EQUALS_SHORTS = new JavaMethodInfo(JavaClass.ARRAYS, "equals", "([S[S)Z", PUBLIC_STATIC);
131
+	private static final JavaMethodInfo ARRAYS_EQUALS_INTS = new JavaMethodInfo(JavaClass.ARRAYS, "equals", "([I[I)Z", PUBLIC_STATIC);
132
+	private static final JavaMethodInfo ARRAYS_EQUALS_LONGS = new JavaMethodInfo(JavaClass.ARRAYS, "equals", "([L[L)Z", PUBLIC_STATIC);
133
+	private static final JavaMethodInfo ARRAYS_EQUALS_FLOATS = new JavaMethodInfo(JavaClass.ARRAYS, "equals", "([F[F)Z", PUBLIC_STATIC);
134
+	private static final JavaMethodInfo ARRAYS_EQUALS_DOUBLES = new JavaMethodInfo(JavaClass.ARRAYS, "equals", "([D[D)Z", PUBLIC_STATIC);
135
+	private static final JavaMethodInfo ARRAYS_EQUALS_CHARS = new JavaMethodInfo(JavaClass.ARRAYS, "equals", "([C[C)Z", PUBLIC_STATIC);
136
+	private static final JavaMethodInfo ARRAYS_DEEPHASHCODE = new JavaMethodInfo(JavaClass.ARRAYS, "deepHashCode", "([Ljava/lang/Object;)", PUBLIC_STATIC);
137
+	private static final JavaMethodInfo ARRAYS_HASHCODE_BOOLS = new JavaMethodInfo(JavaClass.ARRAYS, "hashCode", "([Z)I", PUBLIC_STATIC);
138
+	private static final JavaMethodInfo ARRAYS_HASHCODE_BYTES = new JavaMethodInfo(JavaClass.ARRAYS, "hashCode", "([B)I", PUBLIC_STATIC);
139
+	private static final JavaMethodInfo ARRAYS_HASHCODE_SHORTS = new JavaMethodInfo(JavaClass.ARRAYS, "hashCode", "([S)I", PUBLIC_STATIC);
140
+	private static final JavaMethodInfo ARRAYS_HASHCODE_INTS = new JavaMethodInfo(JavaClass.ARRAYS, "hashCode", "([I)I", PUBLIC_STATIC);
141
+	private static final JavaMethodInfo ARRAYS_HASHCODE_LONGS = new JavaMethodInfo(JavaClass.ARRAYS, "hashCode", "([L)I", PUBLIC_STATIC);
142
+	private static final JavaMethodInfo ARRAYS_HASHCODE_FLOATS = new JavaMethodInfo(JavaClass.ARRAYS, "hashCode", "([F)I", PUBLIC_STATIC);
143
+	private static final JavaMethodInfo ARRAYS_HASHCODE_DOUBLES = new JavaMethodInfo(JavaClass.ARRAYS, "hashCode", "([D)I", PUBLIC_STATIC);
144
+	private static final JavaMethodInfo ARRAYS_HASHCODE_CHARS = new JavaMethodInfo(JavaClass.ARRAYS, "hashCode", "([C)I", PUBLIC_STATIC);
145
+	private static final JavaMethodInfo OBJECT_HASHCODE = new JavaMethodInfo(JavaClass.OBJECT, "hashCode", "()I", PUBLIC);
146
+	private static final JavaMethodInfo COLLECTION_SIZE = new JavaMethodInfo(JavaClass.COLLECTION, "size", "()I", PUBLIC);
147
+	private static final JavaMethodInfo COLLECTION_TOARRAY = new JavaMethodInfo(JavaClass.COLLECTION, "toArray", "([Ljava/lang/Object;)[Ljava/lang/Object;", PUBLIC);
162 148
 
163 149
     private final JavaWriter javaWriter;
164 150
     private final JavaCapturedExpressionVisitor capturedExpressionVisitor = new JavaCapturedExpressionVisitor(this);
151
+	private final JavaContext context;
165 152
 
166
-    public JavaExpressionVisitor(JavaWriter javaWriter) {
153
+    public JavaExpressionVisitor(JavaContext context, JavaWriter javaWriter) {
167 154
         this.javaWriter = javaWriter;
168
-    }
169
-
170
-    private static Class<?> getForEquals(ITypeID id) {
171
-        if (CompilerUtils.isPrimitive(id))
172
-            return id.accept(JavaTypeClassVisitor.INSTANCE);
173
-        return Object.class;
155
+		this.context = context;
174 156
     }
175 157
 
176 158
     @Override
@@ -201,7 +183,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
201 183
     @Override
202 184
     public Void visitArray(ArrayExpression expression) {
203 185
         javaWriter.constant(expression.expressions.length);
204
-        Type type = Type.getType(expression.type.accept(JavaTypeClassVisitor.INSTANCE).getComponentType());
186
+        Type type = context.getType(((ArrayTypeID)expression.type).elementType);
205 187
         javaWriter.newArray(type);
206 188
         for (int i = 0; i < expression.expressions.length; i++) {
207 189
             javaWriter.dup();
@@ -659,8 +641,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
659 641
 				javaWriter.invokeVirtual(MAP_GET);
660 642
 
661 643
 				AssocTypeID type = (AssocTypeID) expression.target.type;
662
-				Type cls = type.valueType.accept(JavaTypeVisitor.INSTANCE);
663
-				javaWriter.checkCast(cls.getInternalName());
644
+				javaWriter.checkCast(context.getInternalName(type.valueType));
664 645
 				break;
665 646
 			}
666 647
 			case ASSOC_INDEXSET:
@@ -716,12 +697,12 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
716 697
 				throw new UnsupportedOperationException("Not yet supported!");
717 698
 			case ARRAY_INDEXGET: {
718 699
 				ArrayTypeID type = (ArrayTypeID) expression.target.type;
719
-				javaWriter.arrayLoad(type.elementType.accept(JavaTypeVisitor.INSTANCE));
700
+				javaWriter.arrayLoad(context.getType(type.elementType));
720 701
 				break;
721 702
 			}
722 703
 			case ARRAY_INDEXSET: {
723 704
 				ArrayTypeID type = (ArrayTypeID) expression.target.type;
724
-				javaWriter.arrayStore(type.elementType.accept(JavaTypeVisitor.INSTANCE));
705
+				javaWriter.arrayStore(context.getType(type.elementType));
725 706
 				break;
726 707
 			}
727 708
 			case ARRAY_INDEXGETRANGE: {
@@ -782,7 +763,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
782 763
 					}
783 764
 				} else {
784 765
 					javaWriter.invokeStatic(ARRAYS_COPY_OF_RANGE_OBJECTS);
785
-					javaWriter.checkCast("[" + type.elementType.accept(JavaTypeVisitor.INSTANCE).getDescriptor());
766
+					javaWriter.checkCast(context.getDescriptor(type));
786 767
 				}
787 768
 				break;
788 769
 			}
@@ -840,9 +821,9 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
840 821
 			case FUNCTION_CALL:
841 822
 				javaWriter.invokeInterface(
842 823
 						new JavaMethodInfo(
843
-								JavaClass.fromInternalName(expression.target.type.accept(JavaTypeVisitor.INSTANCE).getInternalName(), JavaClass.Kind.INTERFACE),
824
+								JavaClass.fromInternalName(context.getInternalName(expression.target.type), JavaClass.Kind.INTERFACE),
844 825
 								"accept",
845
-								CompilerUtils.calcSign(expression.instancedHeader, false),
826
+								context.getMethodSignature(expression.instancedHeader),
846 827
 								Opcodes.ACC_PUBLIC));
847 828
 				break;
848 829
 			case AUTOOP_NOTEQUALS:
@@ -1313,7 +1294,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1313 1294
         javaWriter.pop();
1314 1295
         javaWriter.newObject(NullPointerException.class);
1315 1296
         javaWriter.dup();
1316
-        javaWriter.constant("Tried to convert a null value to nonnull type " + expression.type.accept(JavaTypeClassVisitor.INSTANCE).getSimpleName());
1297
+        javaWriter.constant("Tried to convert a null value to nonnull type " + context.getType(expression.type).getClassName());
1317 1298
         javaWriter.invokeSpecial(NullPointerException.class, "<init>", "(Ljava/lang/String;)V");
1318 1299
         javaWriter.aThrow();
1319 1300
         javaWriter.label(end);
@@ -1520,13 +1501,6 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1520 1501
 
1521 1502
     @Override
1522 1503
     public Void visitConstructorThisCall(ConstructorThisCallExpression expression) {
1523
-        Type type = expression.objectType.accept(JavaTypeVisitor.INSTANCE);
1524
-		try {
1525
-			type.getInternalName();
1526
-		} catch (NullPointerException ex) {
1527
-			ex.printStackTrace();
1528
-		}
1529
-
1530 1504
         javaWriter.loadObject(0);
1531 1505
         if (javaWriter.method.javaClass.isEnum()) {
1532 1506
             javaWriter.loadObject(1);
@@ -1536,8 +1510,10 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1536 1510
         for (Expression argument : expression.arguments.arguments) {
1537 1511
             argument.accept(this);
1538 1512
         }
1539
-		String internalName = type.getInternalName();
1540
-        javaWriter.invokeSpecial(internalName, "<init>", CompilerUtils.calcDesc(expression.constructor.getHeader(), javaWriter.method.javaClass.isEnum()));
1513
+		String internalName = context.getInternalName(expression.objectType);
1514
+        javaWriter.invokeSpecial(internalName, "<init>", javaWriter.method.javaClass.isEnum()
1515
+				? context.getEnumConstructorDescriptor(expression.constructor.getHeader())
1516
+				: context.getMethodDescriptor(expression.constructor.getHeader()));
1541 1517
         return null;
1542 1518
     }
1543 1519
 
@@ -1548,38 +1524,37 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1548 1524
             argument.accept(this);
1549 1525
         }
1550 1526
         //No super calls in enums possible, and that's already handled in the enum constructor itself.
1551
-        javaWriter.invokeSpecial(expression.objectType.accept(JavaTypeClassVisitor.INSTANCE), "<init>", CompilerUtils.calcDesc(expression.constructor.getHeader(), false));
1552
-
1553
-        CompilerUtils.writeDefaultFieldInitializers(javaWriter, javaWriter.forDefinition, false);
1527
+        javaWriter.invokeSpecial(
1528
+				context.getInternalName(expression.objectType),
1529
+				"<init>",
1530
+				context.getMethodDescriptor(expression.constructor.getHeader()));
1531
+			
1532
+        CompilerUtils.writeDefaultFieldInitializers(context, javaWriter, javaWriter.forDefinition, false);
1554 1533
         return null;
1555 1534
     }
1556 1535
 
1557 1536
     @Override
1558 1537
     public Void visitEnumConstant(EnumConstantExpression expression) {
1559
-        final Type type = expression.type.accept(JavaTypeVisitor.INSTANCE);
1560
-        javaWriter.getStaticField(type.getInternalName(), expression.value.name, type.getDescriptor());
1538
+        javaWriter.getStaticField(context.getInternalName(expression.type), expression.value.name, context.getDescriptor(expression.type));
1561 1539
         return null;
1562 1540
     }
1563 1541
 
1564 1542
     @Override
1565 1543
     public Void visitFunction(FunctionExpression expression) {
1566
-		CompilerUtils.tagMethodParameters(expression.header, false);
1544
+		CompilerUtils.tagMethodParameters(context, expression.header, false);
1567 1545
 
1568 1546
         if (expression.header.parameters.length == 0 && expression.body instanceof ReturnStatement && expression.body.hasTag(MatchExpression.class) && expression.closure.captures.isEmpty()) {
1569 1547
             ((ReturnStatement) expression.body).value.accept(this);
1570 1548
             return null;
1571 1549
         }
1572
-        final String signature = CompilerUtils.calcSign(expression.header, false);
1573
-        //final String name = CompilerUtils.getLambdaInterface(expression.header);
1550
+        final String signature = context.getMethodSignature(expression.header);
1574 1551
 		final String name = CompilerUtils.getLambdaCounter();
1575 1552
 
1576 1553
         final JavaMethodInfo methodInfo = new JavaMethodInfo(javaWriter.method.javaClass, "accept", signature, Opcodes.ACC_PUBLIC);
1577 1554
 		final ClassWriter lambdaCW = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
1578
-		lambdaCW.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, name, null, "java/lang/Object", new String[]{CompilerUtils.getLambdaInterface(expression.header)});
1555
+		lambdaCW.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, name, null, "java/lang/Object", new String[]{JavaSynthesizedClassNamer.createFunctionName(new FunctionTypeID(null, expression.header)).cls.internalName});
1579 1556
 		final JavaWriter functionWriter = new JavaWriter(lambdaCW, methodInfo, null, signature, null, "java/lang/Override");
1580
-
1581
-
1582
-
1557
+		
1583 1558
 		javaWriter.newObject(name);
1584 1559
 		javaWriter.dup();
1585 1560
 
@@ -1595,9 +1570,9 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1595 1570
 		int i = 0;
1596 1571
 		for (CapturedExpression capture : expression.closure.captures) {
1597 1572
 			constructorWriter.dup();
1598
-			final Type type = capture.type.accept(JavaTypeVisitor.INSTANCE);
1573
+			Type type = context.getType(capture.type);
1599 1574
 			lambdaCW.visitField(Opcodes.ACC_FINAL | Opcodes.ACC_PRIVATE, "captured" + ++i, type.getDescriptor(), null, null).visitEnd();
1600
-
1575
+			
1601 1576
 			capture.accept(this);
1602 1577
 
1603 1578
 			constructorWriter.load(type, i);
@@ -1612,30 +1587,24 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1612 1587
 		constructorWriter.end();
1613 1588
 
1614 1589
 
1615
-
1616 1590
         functionWriter.start();
1617 1591
 
1618 1592
 
1619
-		final JavaStatementVisitor CSV = new JavaStatementVisitor(new JavaExpressionVisitor(functionWriter) {
1620
-			//@Override
1593
+		final JavaStatementVisitor CSV = new JavaStatementVisitor(context, new JavaExpressionVisitor(context, functionWriter) {
1594
+			@Override
1621 1595
 			public Void visitGetLocalVariable(GetLocalVariableExpression varExpression) {
1622 1596
 				final int position = calculateMemberPosition(varExpression, expression) ;
1623 1597
 				if (position < 0)
1624 1598
 					throw new CompileException(varExpression.position, CompileExceptionCode.INTERNAL_ERROR, "Captured Statement error");
1625 1599
 				functionWriter.loadObject(0);
1626
-				functionWriter.getField(name, "captured" + position, varExpression.variable.type.accept(JavaTypeVisitor.INSTANCE).getDescriptor());
1600
+				functionWriter.getField(name, "captured" + position, context.getDescriptor(varExpression.variable.type));
1627 1601
 				return null;
1628 1602
 			}
1629 1603
 		});
1630
-
1631
-
1604
+		
1632 1605
 		expression.body.accept(CSV);
1633
-
1634
-
1606
+		
1635 1607
         functionWriter.ret();
1636
-
1637
-
1638
-
1639 1608
 		functionWriter.end();
1640 1609
         lambdaCW.visitEnd();
1641 1610
 
@@ -1665,9 +1634,8 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1665 1634
 
1666 1635
     private String calcFunctionSignature(LambdaClosure closure) {
1667 1636
         StringJoiner joiner = new StringJoiner("", "(", ")V");
1668
-
1669 1637
         for (CapturedExpression capture : closure.captures) {
1670
-            String descriptor = capture.type.accept(JavaTypeVisitor.INSTANCE).getDescriptor();
1638
+            String descriptor = context.getDescriptor(capture.type);
1671 1639
             joiner.add(descriptor);
1672 1640
         }
1673 1641
         return joiner.toString();
@@ -1691,7 +1659,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1691 1659
 			parameter = new JavaParameterInfo(1, Type.INT_TYPE);
1692 1660
 		}
1693 1661
 
1694
-        javaWriter.load(expression.parameter.type.accept(JavaTypeVisitor.INSTANCE), parameter.index);
1662
+        javaWriter.load(context.getType(expression.parameter.type), parameter.index);
1695 1663
         return null;
1696 1664
     }
1697 1665
 
@@ -1798,7 +1766,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1798 1766
 			case ASSOC_KEYS: {
1799 1767
 				AssocTypeID type = (AssocTypeID) expression.target.type;
1800 1768
 				ArrayTypeID result = new ArrayTypeID(null, type.keyType, 1);
1801
-				Type resultType = result.accept(JavaTypeVisitor.INSTANCE);
1769
+				Type resultType = context.getType(result);
1802 1770
 
1803 1771
 				javaWriter.invokeVirtual(MAP_KEYS);
1804 1772
 				javaWriter.dup();
@@ -1811,7 +1779,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1811 1779
 			case ASSOC_VALUES: {
1812 1780
 				AssocTypeID type = (AssocTypeID) expression.target.type;
1813 1781
 				ArrayTypeID result = new ArrayTypeID(null, type.valueType, 1);
1814
-				Type resultType = result.accept(JavaTypeVisitor.INSTANCE);
1782
+				Type resultType = context.getType(result);
1815 1783
 
1816 1784
 				javaWriter.invokeVirtual(MAP_VALUES);
1817 1785
 				javaWriter.dup();
@@ -1922,14 +1890,14 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1922 1890
     @Override
1923 1891
     public Void visitInterfaceCast(InterfaceCastExpression expression) {
1924 1892
         expression.value.accept(this);
1925
-        javaWriter.checkCast(expression.type.accept(JavaTypeVisitor.INSTANCE));
1893
+        javaWriter.checkCast(context.getDescriptor(expression.type));
1926 1894
         return null;
1927 1895
     }
1928 1896
 
1929 1897
     @Override
1930 1898
     public Void visitIs(IsExpression expression) {
1931 1899
         expression.value.accept(this);
1932
-        javaWriter.instanceOf(expression.isType.accept(JavaTypeVisitor.INSTANCE));
1900
+        javaWriter.instanceOf(context.getDescriptor(expression.isType));
1933 1901
         return null;
1934 1902
     }
1935 1903
 
@@ -1940,9 +1908,9 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1940 1908
 
1941 1909
     @Override
1942 1910
     public Void visitMap(MapExpression expression) {
1943
-        javaWriter.newObject(expression.type.accept(JavaTypeClassVisitor.INSTANCE));
1911
+        javaWriter.newObject("java/util/HashMap");
1944 1912
         javaWriter.dup();
1945
-        javaWriter.invokeSpecial("java/util/Map", "<init>", "()V");
1913
+        javaWriter.invokeSpecial("java/util/HashMap", "<init>", "()V");
1946 1914
         for (int i = 0; i < expression.keys.length; i++) {
1947 1915
             javaWriter.dup();
1948 1916
             expression.keys[i].accept(this);
@@ -1963,7 +1931,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1963 1931
         javaWriter.label(start);
1964 1932
         expression.value.accept(this);
1965 1933
         if (expression.value.type == BasicTypeID.STRING)
1966
-            javaWriter.invokeVirtual(new JavaMethodInfo(OBJECT, "hashCode", "()I", 0));
1934
+            javaWriter.invokeVirtual(new JavaMethodInfo(JavaClass.OBJECT, "hashCode", "()I", 0));
1967 1935
 
1968 1936
         final boolean hasNoDefault = hasNoDefault(expression);
1969 1937
 
@@ -2014,18 +1982,20 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2014 1982
 
2015 1983
     @Override
2016 1984
     public Void visitNew(NewExpression expression) {
1985
+		// TODO: this code is incorrect!
1986
+		
2017 1987
         final String type;
2018 1988
         if (expression.type instanceof DefinitionTypeID)
2019 1989
             type = ((DefinitionTypeID) expression.type).definition.name;
2020 1990
         else
2021
-            type = Type.getDescriptor(expression.type.accept(JavaTypeClassVisitor.INSTANCE));
1991
+            type = context.getDescriptor(expression.type);
2022 1992
 
2023 1993
         javaWriter.newObject(type);
2024 1994
         javaWriter.dup();
2025 1995
         StringBuilder signatureBuilder = new StringBuilder("(");
2026 1996
         for (Expression argument : expression.arguments.arguments) {
2027 1997
             argument.accept(this);
2028
-            signatureBuilder.append(Type.getDescriptor(argument.type.accept(JavaTypeClassVisitor.INSTANCE)));
1998
+            signatureBuilder.append(context.getDescriptor(argument.type));
2029 1999
         }
2030 2000
         signatureBuilder.append(")V");
2031 2001
         javaWriter.invokeSpecial(type, "<init>", signatureBuilder.toString());
@@ -2073,7 +2043,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2073 2043
 	@Override
2074 2044
 	public Void visitPostCall(PostCallExpression expression) {
2075 2045
 		expression.target.accept(this);
2076
-		javaWriter.dup(expression.type.accept(new JavaTypeVisitor()));
2046
+		javaWriter.dup(context.getType(expression.type));
2077 2047
         if (!checkAndExecuteByteCodeImplementation(expression.member) && !checkAndExecuteMethodInfo(expression.member))
2078 2048
             throw new IllegalStateException("Call target has no method info!");
2079 2049
 
@@ -2083,7 +2053,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2083 2053
     @Override
2084 2054
     public Void visitRange(RangeExpression expression) {
2085 2055
         // TODO: there are other kinds of ranges also; there should be a Range<T, T> type with creation of synthetic types
2086
-        if (expression.from.type.accept(JavaTypeClassVisitor.INSTANCE) != int.class)
2056
+        if (!context.getDescriptor(expression.from.type).equals("I"))
2087 2057
             throw new CompileException(expression.position, CompileExceptionCode.INTERNAL_ERROR, "Only integer ranges supported");
2088 2058
 
2089 2059
         javaWriter.newObject(IntRange.class);
@@ -2131,7 +2101,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2131 2101
     public Void visitSetFunctionParameter(SetFunctionParameterExpression expression) {
2132 2102
         expression.value.accept(this);
2133 2103
         JavaParameterInfo parameter = expression.parameter.getTag(JavaParameterInfo.class);
2134
-        javaWriter.store(expression.type.accept(JavaTypeVisitor.INSTANCE), parameter.index);
2104
+        javaWriter.store(context.getType(expression.type), parameter.index);
2135 2105
         return null;
2136 2106
     }
2137 2107
 
@@ -2337,7 +2307,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2337 2307
 
2338 2308
     //Will return true if a JavaFieldInfo.class tag exists, and will compile that tag
2339 2309
     public boolean checkAndPutFieldInfo(FieldMemberRef field, boolean isStatic) {
2340
-		JavaFieldInfo fieldInfo = field.getTag(JavaFieldInfo.class);
2310
+		JavaField fieldInfo = field.getTag(JavaField.class);
2341 2311
         if (fieldInfo == null)
2342 2312
             return false;
2343 2313
         //TODO Remove isStatic
@@ -2350,7 +2320,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2350 2320
     }
2351 2321
 
2352 2322
     public boolean checkAndGetFieldInfo(ConstMemberRef field, boolean isStatic) {
2353
-        JavaFieldInfo fieldInfo = field.getTag(JavaFieldInfo.class);
2323
+        JavaField fieldInfo = field.getTag(JavaField.class);
2354 2324
         if (fieldInfo == null)
2355 2325
             return false;
2356 2326
 
@@ -2359,7 +2329,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2359 2329
     }
2360 2330
 
2361 2331
     public boolean checkAndGetFieldInfo(FieldMemberRef field, boolean isStatic) {
2362
-        JavaFieldInfo fieldInfo = field.getTag(JavaFieldInfo.class);
2332
+        JavaField fieldInfo = field.getTag(JavaField.class);
2363 2333
         if (fieldInfo == null)
2364 2334
             return false;
2365 2335
 

+ 0
- 109
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaOptionalTypeClassVisitor.java View File

@@ -1,109 +0,0 @@
1
-/*
2
- * To change this license header, choose License Headers in Project Properties.
3
- * To change this template file, choose Tools | Templates
4
- * and open the template in the editor.
5
- */
6
-package org.openzen.zenscript.javabytecode.compiler;
7
-
8
-import org.openzen.zenscript.codemodel.type.ArrayTypeID;
9
-import org.openzen.zenscript.codemodel.type.AssocTypeID;
10
-import org.openzen.zenscript.codemodel.type.BasicTypeID;
11
-import org.openzen.zenscript.codemodel.type.ModifiedTypeID;
12
-import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
13
-import org.openzen.zenscript.codemodel.type.FunctionTypeID;
14
-import org.openzen.zenscript.codemodel.type.GenericMapTypeID;
15
-import org.openzen.zenscript.codemodel.type.GenericTypeID;
16
-import org.openzen.zenscript.codemodel.type.ITypeVisitor;
17
-import org.openzen.zenscript.codemodel.type.IteratorTypeID;
18
-import org.openzen.zenscript.codemodel.type.RangeTypeID;
19
-
20
-/**
21
- *
22
- * @author Hoofdgebruiker
23
- */
24
-public class JavaOptionalTypeClassVisitor implements ITypeVisitor<Class> {
25
-	private final JavaTypeClassVisitor base;
26
-	
27
-	public JavaOptionalTypeClassVisitor(JavaTypeClassVisitor base) {
28
-		this.base = base;
29
-	}
30
-
31
-	@Override
32
-	public Class visitBasic(BasicTypeID basic) {
33
-		switch (basic) {
34
-			case VOID:
35
-				return void.class;
36
-			case NULL:
37
-				return Object.class;
38
-			case BOOL:
39
-				return Boolean.class;
40
-			case BYTE:
41
-			case SBYTE:
42
-				return Byte.class;
43
-			case SHORT:
44
-			case USHORT:
45
-				return Short.class;
46
-			case INT:
47
-			case UINT:
48
-				return Integer.class;
49
-			case LONG:
50
-			case ULONG:
51
-				return Long.class;
52
-			case FLOAT:
53
-				return Float.class;
54
-			case DOUBLE:
55
-				return Double.class;
56
-			case CHAR:
57
-				return Character.class;
58
-			case STRING:
59
-				return String.class;
60
-			default:
61
-				throw new IllegalArgumentException("Invalid type: " + basic);
62
-		}
63
-	}
64
-
65
-	@Override
66
-	public Class visitArray(ArrayTypeID array) {
67
-		return base.visitArray(array);
68
-	}
69
-
70
-	@Override
71
-	public Class visitAssoc(AssocTypeID assoc) {
72
-		return base.visitAssoc(assoc);
73
-	}
74
-
75
-	@Override
76
-	public Class visitIterator(IteratorTypeID iterator) {
77
-		return base.visitIterator(iterator);
78
-	}
79
-
80
-	@Override
81
-	public Class visitFunction(FunctionTypeID function) {
82
-		return base.visitFunction(function);
83
-	}
84
-
85
-	@Override
86
-	public Class visitDefinition(DefinitionTypeID definition) {
87
-		return base.visitDefinition(definition);
88
-	}
89
-
90
-	@Override
91
-	public Class visitGeneric(GenericTypeID generic) {
92
-		return base.visitGeneric(generic);
93
-	}
94
-
95
-	@Override
96
-	public Class visitRange(RangeTypeID range) {
97
-		return base.visitRange(range);
98
-	}
99
-
100
-	@Override
101
-	public Class visitModified(ModifiedTypeID type) {
102
-		return base.visitModified(type);
103
-	}
104
-
105
-	@Override
106
-	public Class visitGenericMap(GenericMapTypeID map) {
107
-		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
108
-	}
109
-}

+ 5
- 2
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreDecrementVisitor.java View File

@@ -74,6 +74,7 @@ import org.openzen.zenscript.codemodel.expression.TryRethrowAsExceptionExpressio
74 74
 import org.openzen.zenscript.codemodel.expression.TryRethrowAsResultExpression;
75 75
 import org.openzen.zenscript.codemodel.expression.VariantValueExpression;
76 76
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
77
+import org.openzen.zenscript.javabytecode.JavaContext;
77 78
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
78 79
 import org.openzen.zenscript.javabytecode.JavaParameterInfo;
79 80
 
@@ -84,9 +85,11 @@ import org.openzen.zenscript.javabytecode.JavaParameterInfo;
84 85
 public class JavaPreDecrementVisitor implements ExpressionVisitor<Void> {
85 86
 	private final JavaExpressionVisitor expressionCompiler;
86 87
 	private final JavaWriter javaWriter;
88
+	private final JavaContext context;
87 89
 	
88
-	public JavaPreDecrementVisitor(JavaExpressionVisitor expressionCompiler) {
90
+	public JavaPreDecrementVisitor(JavaContext context, JavaExpressionVisitor expressionCompiler) {
89 91
 		this.expressionCompiler = expressionCompiler;
92
+		this.context = context;
90 93
 		javaWriter = expressionCompiler.getJavaWriter();
91 94
 	}
92 95
 
@@ -252,7 +255,7 @@ public class JavaPreDecrementVisitor implements ExpressionVisitor<Void> {
252 255
 
253 256
 	@Override
254 257
 	public Void visitGetField(GetFieldExpression expression) {
255
-		Type objectType = expression.target.type.accept(new JavaTypeVisitor());
258
+		Type objectType = context.getType(expression.target.type);
256 259
 		
257 260
 		int local = javaWriter.local(objectType);
258 261
 		expression.target.accept(expressionCompiler);

+ 5
- 2
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreIncrementVisitor.java View File

@@ -74,6 +74,7 @@ import org.openzen.zenscript.codemodel.expression.TryRethrowAsExceptionExpressio
74 74
 import org.openzen.zenscript.codemodel.expression.TryRethrowAsResultExpression;
75 75
 import org.openzen.zenscript.codemodel.expression.VariantValueExpression;
76 76
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
77
+import org.openzen.zenscript.javabytecode.JavaContext;
77 78
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
78 79
 import org.openzen.zenscript.javabytecode.JavaParameterInfo;
79 80
 
@@ -83,10 +84,12 @@ import org.openzen.zenscript.javabytecode.JavaParameterInfo;
83 84
  */
84 85
 public class JavaPreIncrementVisitor implements ExpressionVisitor<Void> {
85 86
 	private final JavaExpressionVisitor expressionCompiler;
87
+	private final JavaContext context;
86 88
 	private final JavaWriter javaWriter;
87 89
 	
88
-	public JavaPreIncrementVisitor(JavaExpressionVisitor expressionCompiler) {
90
+	public JavaPreIncrementVisitor(JavaContext context, JavaExpressionVisitor expressionCompiler) {
89 91
 		this.expressionCompiler = expressionCompiler;
92
+		this.context = context;
90 93
 		javaWriter = expressionCompiler.getJavaWriter();
91 94
 	}
92 95
 
@@ -252,7 +255,7 @@ public class JavaPreIncrementVisitor implements ExpressionVisitor<Void> {
252 255
 
253 256
 	@Override
254 257
 	public Void visitGetField(GetFieldExpression expression) {
255
-		Type objectType = expression.target.type.accept(new JavaTypeVisitor());
258
+		Type objectType = context.getType(expression.target.type);
256 259
 		
257 260
 		int local = javaWriter.local(objectType);
258 261
 		expression.target.accept(expressionCompiler);

+ 11
- 7
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java View File

@@ -9,22 +9,26 @@ import org.openzen.zenscript.javabytecode.JavaMethodInfo;
9 9
 
10 10
 import java.util.Arrays;
11 11
 import java.util.List;
12
+import org.openzen.zenscript.javabytecode.JavaContext;
12 13
 import org.openzen.zenscript.javashared.JavaClass;
13 14
 
14 15
 public class JavaStatementVisitor implements StatementVisitor<Boolean> {
15 16
     private final JavaWriter javaWriter;
17
+	private final JavaContext context;
16 18
     public JavaExpressionVisitor expressionVisitor;
17 19
 
18 20
     /**
19 21
      * @param javaWriter the method writer that compiles the statement
20 22
      */
21
-    public JavaStatementVisitor(JavaWriter javaWriter) {
23
+    public JavaStatementVisitor(JavaContext context, JavaWriter javaWriter) {
22 24
         this.javaWriter = javaWriter;
23
-        this.expressionVisitor = new JavaExpressionVisitor(javaWriter);
25
+		this.context = context;
26
+        this.expressionVisitor = new JavaExpressionVisitor(context, javaWriter);
24 27
     }
25 28
 
26
-    public JavaStatementVisitor(JavaExpressionVisitor expressionVisitor) {
29
+    public JavaStatementVisitor(JavaContext context, JavaExpressionVisitor expressionVisitor) {
27 30
         this.javaWriter = expressionVisitor.getJavaWriter();
31
+		this.context = context;
28 32
         this.expressionVisitor = expressionVisitor;
29 33
     }
30 34
 
@@ -97,7 +101,7 @@ public class JavaStatementVisitor implements StatementVisitor<Boolean> {
97 101
 
98 102
         //Create local variables
99 103
         for (VarStatement variable : statement.loopVariables) {
100
-            final Type type = Type.getType(variable.type.accept(JavaTypeClassVisitor.INSTANCE));
104
+            final Type type = context.getType(variable.type);
101 105
             final Label variableStart = new Label();
102 106
             final JavaLocalVariableInfo info = new JavaLocalVariableInfo(type, javaWriter.local(type), variableStart, variable.name);
103 107
             info.end = end;
@@ -142,7 +146,7 @@ public class JavaStatementVisitor implements StatementVisitor<Boolean> {
142 146
     @Override
143 147
     public Boolean visitReturn(ReturnStatement statement) {
144 148
         statement.value.accept(expressionVisitor);
145
-        javaWriter.returnType(Type.getType(statement.value.type.accept(JavaTypeClassVisitor.INSTANCE)));
149
+        javaWriter.returnType(context.getType(statement.value.type));
146 150
         return true;
147 151
     }
148 152
 
@@ -238,7 +242,7 @@ public class JavaStatementVisitor implements StatementVisitor<Boolean> {
238 242
             javaWriter.label(catchStart);
239 243
 
240 244
             //final Type exceptionType = Type.getType(RuntimeException.class);
241
-            final Type exceptionType = Type.getType(catchClause.exceptionVariable.type.accept(JavaTypeClassVisitor.INSTANCE));
245
+            final Type exceptionType = context.getType(catchClause.exceptionVariable.type);
242 246
             final int local = javaWriter.local(exceptionType);
243 247
             javaWriter.store(exceptionType, local);
244 248
 
@@ -276,7 +280,7 @@ public class JavaStatementVisitor implements StatementVisitor<Boolean> {
276 280
             statement.initializer.accept(expressionVisitor);
277 281
         }
278 282
 
279
-        Type type = statement.type.accept(JavaTypeVisitor.INSTANCE);
283
+        Type type = context.getType(statement.type);
280 284
         int local = javaWriter.local(type);
281 285
         if (statement.initializer != null)
282 286
             javaWriter.store(type, local);

+ 0
- 98
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaTypeClassVisitor.java View File

@@ -1,98 +0,0 @@
1
-package org.openzen.zenscript.javabytecode.compiler;
2
-
3
-import org.openzen.zenscript.codemodel.type.*;
4
-import org.openzen.zenscript.javabytecode.JavaModule;
5
-
6
-import java.lang.reflect.Array;
7
-import java.util.Iterator;
8
-import java.util.Map;
9
-
10
-public class JavaTypeClassVisitor implements ITypeVisitor<Class> {
11
-
12
-    public static final JavaTypeClassVisitor INSTANCE = new JavaTypeClassVisitor();
13
-	private final JavaOptionalTypeClassVisitor optional = new JavaOptionalTypeClassVisitor(this);
14
-
15
-    @Override
16
-    public Class visitBasic(BasicTypeID basic) {
17
-        switch (basic) {
18
-            case VOID:
19
-                return void.class;
20
-            case NULL:
21
-            case UNDETERMINED:
22
-                return Object.class;
23
-            case BOOL:
24
-                return boolean.class;
25
-            case BYTE:
26
-            case SBYTE:
27
-                return byte.class;
28
-            case SHORT:
29
-            case USHORT:
30
-                return short.class;
31
-            case INT:
32
-            case UINT:
33
-                return int.class;
34
-            case LONG:
35
-            case ULONG:
36
-                return long.class;
37
-            case FLOAT:
38
-                return float.class;
39
-            case DOUBLE:
40
-                return double.class;
41
-            case CHAR:
42
-                return char.class;
43
-            case STRING:
44
-                return String.class;
45
-        }
46
-        return Object.class;
47
-    }
48
-
49
-    @Override
50
-    public Class visitArray(ArrayTypeID array) {
51
-        return Array.newInstance(array.elementType.accept(this), 0).getClass();
52
-    }
53
-
54
-    @Override
55
-    public Class visitAssoc(AssocTypeID assoc) {
56
-        return Map.class;
57
-    }
58
-
59
-    @Override
60
-    public Class visitIterator(IteratorTypeID iterator) {
61
-        return Iterator.class;
62
-    }
63
-
64
-    @Override
65
-    public Class visitFunction(FunctionTypeID function) {
66
-        try {
67
-            return new JavaModule().new ScriptClassLoader().loadClass(CompilerUtils.getLambdaInterface(function.header));
68
-        } catch (ClassNotFoundException e) {
69
-            return null;
70
-        }
71
-        //return function.header.returnType.accept(this);
72
-    }
73
-
74
-    @Override
75
-    public Class visitDefinition(DefinitionTypeID definition) {
76
-        return null;
77
-    }
78
-
79
-    @Override
80
-    public Class visitGeneric(GenericTypeID generic) {
81
-        return null;
82
-    }
83
-
84
-    @Override
85
-    public Class visitRange(RangeTypeID range) {
86
-        return null;
87
-    }
88
-
89
-    @Override
90
-    public Class visitModified(ModifiedTypeID modified) {
91
-        return modified.baseType.accept(this.optional);
92
-    }
93
-
94
-	@Override
95
-	public Class visitGenericMap(GenericMapTypeID map) {
96
-		return Map.class;
97
-	}
98
-}

+ 0
- 60
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaTypeVisitor.java View File

@@ -1,60 +0,0 @@
1
-package org.openzen.zenscript.javabytecode.compiler;
2
-
3
-import java.util.Map;
4
-import org.objectweb.asm.Type;
5
-import org.openzen.zenscript.codemodel.type.*;
6
-
7
-public class JavaTypeVisitor implements ITypeVisitor<Type> {
8
-    public static final JavaTypeVisitor INSTANCE = new JavaTypeVisitor();
9
-
10
-    @Override
11
-    public Type visitBasic(BasicTypeID basic) {
12
-        return Type.getType(basic.accept(JavaTypeClassVisitor.INSTANCE));
13
-    }
14
-
15
-    @Override
16
-    public Type visitArray(ArrayTypeID array) {
17
-        return Type.getType(array.accept(JavaTypeClassVisitor.INSTANCE));
18
-    }
19
-
20
-    @Override
21
-    public Type visitAssoc(AssocTypeID assoc) {
22
-        return Type.getType(assoc.accept(JavaTypeClassVisitor.INSTANCE));
23
-    }
24
-
25
-    @Override
26
-    public Type visitIterator(IteratorTypeID iterator) {
27
-        return Type.getType(iterator.accept(JavaTypeClassVisitor.INSTANCE));
28
-    }
29
-
30
-    @Override
31
-    public Type visitFunction(FunctionTypeID function) {
32
-        Class clazz = function.accept(JavaTypeClassVisitor.INSTANCE);
33
-        return clazz != null ? Type.getType(clazz) : Type.getType("L" + CompilerUtils.getLambdaInterface(function.header) + ";");
34
-    }
35
-
36
-    @Override
37
-    public Type visitDefinition(DefinitionTypeID definition) {
38
-        return Type.getType("L" + definition + ";");
39
-    }
40
-
41
-    @Override
42
-    public Type visitGeneric(GenericTypeID generic) {
43
-        return Type.getType(generic.accept(JavaTypeClassVisitor.INSTANCE));
44
-    }
45
-
46
-    @Override
47
-    public Type visitRange(RangeTypeID range) {
48
-        return Type.getType(range.accept(JavaTypeClassVisitor.INSTANCE));
49
-    }
50
-
51
-    @Override
52
-    public Type visitModified(ModifiedTypeID optional) {
53
-        return Type.getType(optional.accept(JavaTypeClassVisitor.INSTANCE));
54
-    }
55
-
56
-	@Override
57
-	public Type visitGenericMap(GenericMapTypeID map) {
58
-		return Type.getType(Map.class);
59
-	}
60
-}

+ 25
- 25
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java View File

@@ -11,11 +11,11 @@ import static org.objectweb.asm.Opcodes.*;
11 11
 import org.objectweb.asm.commons.LocalVariablesSorter;
12 12
 import org.openzen.zencode.shared.CodePosition;
13 13
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
14
-import org.openzen.zenscript.javabytecode.JavaFieldInfo;
15 14
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
16 15
 import org.openzen.zenscript.javabytecode.JavaMethodInfo;
17 16
 import org.openzen.zenscript.javabytecode.JavaParameterInfo;
18 17
 import org.openzen.zenscript.javashared.JavaClass;
18
+import org.openzen.zenscript.javashared.JavaField;
19 19
 
20 20
 public class JavaWriter {
21 21
     private static final JavaMethodInfo STRING_CONCAT = new JavaMethodInfo(
@@ -372,11 +372,11 @@ public class JavaWriter {
372 372
         visitor.visitTypeInsn(CHECKCAST, signature(newClass));
373 373
     }
374 374
 
375
-    public void checkCast(String newClass) {
375
+    public void checkCast(String descriptor) {
376 376
         if (debug)
377
-            System.out.println("checkCast " + newClass);
377
+            System.out.println("checkCast " + descriptor);
378 378
 
379
-        visitor.visitTypeInsn(CHECKCAST, newClass);
379
+        visitor.visitTypeInsn(CHECKCAST, descriptor);
380 380
     }
381 381
 
382 382
     public void checkCast(Type type) {
@@ -796,11 +796,11 @@ public class JavaWriter {
796 796
         visitor.visitInsn(DCMPL);
797 797
     }
798 798
 
799
-    public void instanceOf(String clsName) {
799
+    public void instanceOf(String descriptor) {
800 800
         if (debug)
801
-            System.out.println("instanceOf " + clsName);
801
+            System.out.println("instanceOf " + descriptor);
802 802
 
803
-        visitor.visitTypeInsn(INSTANCEOF, clsName);
803
+        visitor.visitTypeInsn(INSTANCEOF, descriptor);
804 804
     }
805 805
 
806 806
     public void instanceOf(Type type) {
@@ -819,11 +819,11 @@ public class JavaWriter {
819 819
 				false);
820 820
 	}
821 821
 
822
-    public void invokeSpecial(String owner, String name, String descriptor) {
822
+    public void invokeSpecial(String ownerInternalName, String name, String descriptor) {
823 823
         if (debug)
824
-            System.out.println("invokeSpecial " + owner + '.' + name + descriptor);
824
+            System.out.println("invokeSpecial " + ownerInternalName + '.' + name + descriptor);
825 825
 
826
-        visitor.visitMethodInsn(INVOKESPECIAL, owner, name, descriptor, false);
826
+        visitor.visitMethodInsn(INVOKESPECIAL, ownerInternalName, name, descriptor, false);
827 827
     }
828 828
 
829 829
     public void invokeSpecial(Class owner, String name, String descriptor) {
@@ -851,11 +851,11 @@ public class JavaWriter {
851 851
         visitor.visitTypeInsn(NEW, internal(type));
852 852
     }
853 853
 
854
-    public void newObject(String type) {
854
+    public void newObject(String internalName) {
855 855
         if (debug)
856
-            System.out.println("newObject " + type);
856
+            System.out.println("newObject " + internalName);
857 857
 
858
-        visitor.visitTypeInsn(NEW, type);
858
+        visitor.visitTypeInsn(NEW, internalName);
859 859
     }
860 860
 
861 861
     public void construct(Class type, Class... arguments) {
@@ -1052,11 +1052,11 @@ public class JavaWriter {
1052 1052
         visitor.visitFieldInsn(GETFIELD, internal(owner), name, signature(descriptor));
1053 1053
     }
1054 1054
 	
1055
-	public void getField(JavaFieldInfo field) {
1055
+	public void getField(JavaField field) {
1056 1056
         if (debug)
1057
-            System.out.println("getField " + field.javaClass.internalName + '.' + field.name + ":" + field.signature);
1057
+            System.out.println("getField " + field.cls.internalName + '.' + field.name + ":" + field.signature);
1058 1058
 		
1059
-		visitor.visitFieldInsn(GETFIELD, field.javaClass.internalName, field.name, field.signature);
1059
+		visitor.visitFieldInsn(GETFIELD, field.cls.internalName, field.name, field.signature);
1060 1060
 	}
1061 1061
 
1062 1062
     public void putField(String owner, String name, String descriptor) {
@@ -1073,11 +1073,11 @@ public class JavaWriter {
1073 1073
         visitor.visitFieldInsn(PUTFIELD, internal(owner), name, signature(descriptor));
1074 1074
     }
1075 1075
 	
1076
-	public void putField(JavaFieldInfo field) {
1076
+	public void putField(JavaField field) {
1077 1077
         if (debug)
1078
-            System.out.println("putField " + field.javaClass.internalName + '.' + field.name + ":" + field.signature);
1078
+            System.out.println("putField " + field.cls.internalName + '.' + field.name + ":" + field.signature);
1079 1079
 		
1080
-		visitor.visitFieldInsn(PUTFIELD, field.javaClass.internalName, field.name, field.signature);
1080
+		visitor.visitFieldInsn(PUTFIELD, field.cls.internalName, field.name, field.signature);
1081 1081
 	}
1082 1082
 
1083 1083
     public void getStaticField(String owner, String name, String descriptor) {
@@ -1087,11 +1087,11 @@ public class JavaWriter {
1087 1087
         visitor.visitFieldInsn(GETSTATIC, owner, name, descriptor);
1088 1088
     }
1089 1089
 	
1090
-	public void getStaticField(JavaFieldInfo field) {
1090
+	public void getStaticField(JavaField field) {
1091 1091
         if (debug)
1092
-            System.out.println("getStaticField " + field.javaClass.internalName + '.' + field.name + ":" + field.signature);
1092
+            System.out.println("getStaticField " + field.cls.internalName + '.' + field.name + ":" + field.signature);
1093 1093
 		
1094
-		visitor.visitFieldInsn(GETSTATIC, field.javaClass.internalName, field.name, field.signature);
1094
+		visitor.visitFieldInsn(GETSTATIC, field.cls.internalName, field.name, field.signature);
1095 1095
 	}
1096 1096
 
1097 1097
     public void putStaticField(String owner, String name, String descriptor) {
@@ -1108,11 +1108,11 @@ public class JavaWriter {
1108 1108
         visitor.visitFieldInsn(PUTSTATIC, internal(owner), field.getName(), signature(field.getType()));
1109 1109
     }
1110 1110
 	
1111
-	public void putStaticField(JavaFieldInfo field) {
1111
+	public void putStaticField(JavaField field) {
1112 1112
         if (debug)
1113
-            System.out.println("putStaticField " + field.javaClass.internalName + '.' + field.name + ":" + field.signature);
1113
+            System.out.println("putStaticField " + field.cls.internalName + '.' + field.name + ":" + field.signature);
1114 1114
 		
1115
-		visitor.visitFieldInsn(PUTSTATIC, field.javaClass.internalName, field.name, field.signature);
1115
+		visitor.visitFieldInsn(PUTSTATIC, field.cls.internalName, field.name, field.signature);
1116 1116
 	}
1117 1117
 
1118 1118
     public void aThrow() {

+ 14
- 13
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaDefinitionVisitor.java View File

@@ -7,12 +7,12 @@ import org.openzen.zenscript.codemodel.definition.*;
7 7
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
8 8
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
9 9
 import org.openzen.zenscript.codemodel.type.ITypeID;
10
+import org.openzen.zenscript.javabytecode.JavaContext;
10 11
 import org.openzen.zenscript.javabytecode.JavaMethodInfo;
11 12
 import org.openzen.zenscript.javabytecode.JavaModule;
12 13
 import org.openzen.zenscript.javabytecode.compiler.*;
13 14
 import org.openzen.zenscript.javashared.JavaClass;
14 15
 
15
-
16 16
 public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
17 17
 	private static final JavaMethodInfo CLASS_FORNAME = new JavaMethodInfo(
18 18
 			JavaClass.CLASS,
@@ -27,9 +27,10 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
27 27
 			Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC);
28 28
 
29 29
     private final JavaClassWriter outerWriter;
30
+	private final JavaContext context;
30 31
 
31
-    public JavaDefinitionVisitor(JavaClassWriter outerWriter) {
32
-
32
+    public JavaDefinitionVisitor(JavaContext context, JavaClassWriter outerWriter) {
33
+		this.context = context;
33 34
         this.outerWriter = outerWriter;
34 35
     }
35 36
 
@@ -41,7 +42,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
41 42
         if (definition.getSuperType() == null)
42 43
             superType = Type.getType(Object.class);
43 44
         else
44
-            superType = Type.getType(definition.getSuperType().accept(JavaTypeClassVisitor.INSTANCE));
45
+            superType = context.getType(definition.getSuperType());
45 46
 
46 47
 		JavaClass toClass = new JavaClass(definition.pkg.fullName, definition.name, JavaClass.Kind.CLASS);
47 48
         JavaClassWriter writer = new JavaClassWriter(ClassWriter.COMPUTE_FRAMES);
@@ -51,7 +52,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
51 52
         String signature = null;
52 53
 		
53 54
         writer.visit(Opcodes.V1_8, definition.modifiers, definition.name, signature, superType.getInternalName(), null);
54
-		JavaMemberVisitor memberVisitor = new JavaMemberVisitor(writer, toClass, definition); 
55
+		JavaMemberVisitor memberVisitor = new JavaMemberVisitor(context, writer, toClass, definition); 
55 56
         for (IDefinitionMember member : definition.members) {
56 57
             member.accept(memberVisitor);
57 58
         }
@@ -69,7 +70,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
69 70
         //TODO: Extending Interfaces?
70 71
         String signature = null;
71 72
         writer.visit(Opcodes.V1_8, definition.modifiers | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT, definition.name, signature, Type.getInternalName(Object.class), null);
72
-		JavaMemberVisitor memberVisitor = new JavaMemberVisitor(writer, toClass, definition);
73
+		JavaMemberVisitor memberVisitor = new JavaMemberVisitor(context, writer, toClass, definition);
73 74
         for (IDefinitionMember member : definition.members) {
74 75
             member.accept(memberVisitor);
75 76
         }
@@ -86,7 +87,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
86 87
         if (definition.getSuperType() == null)
87 88
             superType = Type.getType(Object.class);
88 89
         else
89
-            superType = Type.getType(definition.getSuperType().accept(JavaTypeClassVisitor.INSTANCE));
90
+            superType = context.getType(definition.getSuperType());
90 91
 
91 92
         ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
92 93
 
@@ -97,7 +98,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
97 98
         //Enum Stuff(required!)
98 99
         writer.visitField(Opcodes.ACC_STATIC | Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL | Opcodes.ACC_SYNTHETIC, "$VALUES", "[L" + definition.name + ";", null, null).visitEnd();
99 100
 
100
-        final JavaMemberVisitor visitor = new JavaMemberVisitor(writer, toClass, definition);
101
+        final JavaMemberVisitor visitor = new JavaMemberVisitor(context, writer, toClass, definition);
101 102
         for (IDefinitionMember member : definition.members) {
102 103
             member.accept(visitor);
103 104
         }
@@ -136,15 +137,15 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
136 137
 
137 138
     @Override
138 139
     public byte[] visitFunction(FunctionDefinition definition) {
139
-		CompilerUtils.tagMethodParameters(definition.header, true);
140
+		CompilerUtils.tagMethodParameters(context, definition.header, true);
140 141
 		
141
-        final String signature = CompilerUtils.calcSign(definition.header, false);
142
+        final String signature = context.getMethodSignature(definition.header);
142 143
 		
143 144
 		final JavaClass toClass = new JavaClass(definition.pkg.fullName, CompilerUtils.calcClasName(definition.position), JavaClass.Kind.CLASS);
144
-		final JavaMethodInfo methodInfo = new JavaMethodInfo(toClass, definition.name, CompilerUtils.calcDesc(definition.header, false), CompilerUtils.calcAccess(definition.modifiers) | Opcodes.ACC_STATIC);
145
+		final JavaMethodInfo methodInfo = new JavaMethodInfo(toClass, definition.name, context.getMethodDescriptor(definition.header), CompilerUtils.calcAccess(definition.modifiers) | Opcodes.ACC_STATIC);
145 146
 
146 147
 		final JavaWriter writer = new JavaWriter(outerWriter, true, methodInfo, definition, signature, null);
147
-        final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(writer);
148
+        final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, writer);
148 149
         statementVisitor.start();
149 150
 		boolean returns = definition.statement.accept(statementVisitor);
150 151
 		if (!returns) {
@@ -153,7 +154,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
153 154
 				writer.iConst0();
154 155
 			else if (type != BasicTypeID.VOID)
155 156
 				writer.aConstNull();
156
-			writer.returnType(type.accept(JavaTypeVisitor.INSTANCE));
157
+			writer.returnType(context.getType(type));
157 158
         }
158 159
 
159 160
         statementVisitor.end();

+ 25
- 22
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaMemberVisitor.java View File

@@ -10,39 +10,42 @@ import org.openzen.zenscript.codemodel.Modifiers;
10 10
 import org.openzen.zenscript.codemodel.definition.EnumDefinition;
11 11
 import org.openzen.zenscript.codemodel.expression.Expression;
12 12
 import org.openzen.zenscript.codemodel.member.*;
13
-import org.openzen.zenscript.javabytecode.JavaFieldInfo;
14 13
 import org.openzen.zenscript.javabytecode.JavaMethodInfo;
15 14
 import org.openzen.zenscript.javabytecode.JavaParameterInfo;
16 15
 import org.openzen.zenscript.javabytecode.compiler.*;
17 16
 
18 17
 import java.util.List;
18
+import org.openzen.zenscript.javabytecode.JavaContext;
19 19
 import org.openzen.zenscript.javashared.JavaClass;
20
+import org.openzen.zenscript.javashared.JavaField;
20 21
 
21 22
 public class JavaMemberVisitor implements MemberVisitor<Void> {
22 23
     private final ClassWriter writer;
24
+	private final JavaContext context;
23 25
     private final JavaClass toClass;
24 26
     private final HighLevelDefinition definition;
25 27
     private final JavaStatementVisitor clinitStatementVisitor;
26 28
     private EnumDefinition enumDefinition = null;
27 29
 
28
-    public JavaMemberVisitor(ClassWriter writer, JavaClass toClass, HighLevelDefinition definition) {
30
+    public JavaMemberVisitor(JavaContext context, ClassWriter writer, JavaClass toClass, HighLevelDefinition definition) {
29 31
         this.writer = writer;
30 32
         this.toClass = toClass;
31 33
         this.definition = definition;
34
+		this.context = context;
32 35
 
33 36
         final JavaWriter javaWriter = new JavaWriter(writer, new JavaMethodInfo(toClass, "<clinit>", "()V", 0), definition, null, null);
34
-        this.clinitStatementVisitor = new JavaStatementVisitor(javaWriter);
37
+        this.clinitStatementVisitor = new JavaStatementVisitor(context, javaWriter);
35 38
         this.clinitStatementVisitor.start();
36
-        CompilerUtils.writeDefaultFieldInitializers(javaWriter, definition, true);
39
+        CompilerUtils.writeDefaultFieldInitializers(context, javaWriter, definition, true);
37 40
     }
38 41
 	
39 42
 	@Override
40 43
 	public Void visitConst(ConstMember member) {
41 44
         //TODO calc signature
42 45
         String signature = null;
43
-        final String descriptor = Type.getDescriptor(member.type.accept(JavaTypeClassVisitor.INSTANCE));
46
+        final String descriptor = context.getDescriptor(member.type);
44 47
         writer.visitField(CompilerUtils.calcAccess(member.modifiers), member.name, descriptor, signature, null).visitEnd();
45
-        member.setTag(JavaFieldInfo.class, new JavaFieldInfo(toClass, member.name, descriptor));
48
+        member.setTag(JavaField.class, new JavaField(toClass, member.name, descriptor));
46 49
         return null;
47 50
 	}
48 51
 
@@ -51,33 +54,33 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
51 54
 
52 55
         //TODO calc signature
53 56
         String signature = null;
54
-        final String descriptor = Type.getDescriptor(member.type.accept(JavaTypeClassVisitor.INSTANCE));
57
+        final String descriptor = context.getDescriptor(member.type);
55 58
         writer.visitField(CompilerUtils.calcAccess(member.modifiers), member.name, descriptor, signature, null).visitEnd();
56
-        member.setTag(JavaFieldInfo.class, new JavaFieldInfo(toClass, member.name, descriptor));
59
+        member.setTag(JavaField.class, new JavaField(toClass, member.name, descriptor));
57 60
         return null;
58 61
     }
59 62
 
60 63
     @Override
61 64
     public Void visitConstructor(ConstructorMember member) {
62 65
         final boolean isEnum = definition instanceof EnumDefinition;
63
-        String descriptor = CompilerUtils.calcDesc(member.header, isEnum);
66
+        String descriptor = isEnum ? context.getEnumConstructorDescriptor(member.header) : context.getMethodDescriptor(member.header);
64 67
         final JavaMethodInfo method = new JavaMethodInfo(toClass, "<init>", descriptor, isEnum ? Opcodes.ACC_PRIVATE : CompilerUtils.calcAccess(member.modifiers));
65 68
 
66 69
         final Label constructorStart = new Label();
67 70
         final Label constructorEnd = new Label();
68
-        final JavaWriter constructorWriter = new JavaWriter(writer, method, definition, CompilerUtils.calcSign(member.header, isEnum), null);
71
+        final JavaWriter constructorWriter = new JavaWriter(writer, method, definition, context.getMethodSignature(member.header), null);
69 72
         constructorWriter.label(constructorStart);
70
-        CompilerUtils.tagConstructorParameters(member.header, isEnum);
73
+        CompilerUtils.tagConstructorParameters(context, member.header, isEnum);
71 74
         for (FunctionParameter parameter : member.header.parameters) {
72 75
             constructorWriter.nameVariable(
73 76
                     parameter.getTag(JavaParameterInfo.class).index,
74 77
                     parameter.name,
75 78
                     constructorStart,
76 79
                     constructorEnd,
77
-                    Type.getType(parameter.type.accept(JavaTypeClassVisitor.INSTANCE)));
80
+                    context.getType(parameter.type));
78 81
         }
79 82
 
80
-        final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(constructorWriter);
83
+        final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, constructorWriter);
81 84
         statementVisitor.start();
82 85
 
83 86
         if (!member.isConstructorForwarded()) {
@@ -95,7 +98,7 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
95 98
                 constructorWriter.invokeSpecial(Type.getInternalName(Object.class), "<init>", "()V");
96 99
             }
97 100
 
98
-            CompilerUtils.writeDefaultFieldInitializers(constructorWriter, definition, false);
101
+            CompilerUtils.writeDefaultFieldInitializers(context, constructorWriter, definition, false);
99 102
         }
100 103
 
101 104
         member.body.accept(statementVisitor);
@@ -113,7 +116,7 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
113 116
         final JavaWriter destructorWriter = new JavaWriter(writer, method, definition, null, null);
114 117
         destructorWriter.label(constructorStart);
115 118
 
116
-        final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(destructorWriter);
119
+        final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, destructorWriter);
117 120
         statementVisitor.start();
118 121
 		// TODO: destruction of members (to be done when memory tags are implemented)
119 122
         member.body.accept(statementVisitor);
@@ -124,7 +127,7 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
124 127
 
125 128
     @Override
126 129
     public Void visitMethod(MethodMember member) {
127
-        CompilerUtils.tagMethodParameters(member.header, member.isStatic());
130
+        CompilerUtils.tagMethodParameters(context, member.header, member.isStatic());
128 131
 
129 132
         final boolean isAbstract = member.body == null || Modifiers.isAbstract(member.modifiers);
130 133
         int modifiers = (isAbstract ? Opcodes.ACC_ABSTRACT : 0)
@@ -133,20 +136,20 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
133 136
         final JavaMethodInfo method = new JavaMethodInfo(
134 137
                 toClass,
135 138
                 member.name,
136
-                CompilerUtils.calcSign(member.header, false),
139
+                context.getMethodSignature(member.header),
137 140
                 modifiers);
138 141
 
139 142
         final Label methodStart = new Label();
140 143
         final Label methodEnd = new Label();
141
-        final JavaWriter methodWriter = new JavaWriter(writer, method, definition, CompilerUtils.calcSign(member.header, false), null);
144
+        final JavaWriter methodWriter = new JavaWriter(writer, method, definition, context.getMethodSignature(member.header), null);
142 145
         methodWriter.label(methodStart);
143 146
         for (final FunctionParameter parameter : member.header.parameters) {
144 147
             methodWriter.nameParameter(0, parameter.name);
145 148
             if (!isAbstract)
146
-                methodWriter.nameVariable(parameter.getTag(JavaParameterInfo.class).index, parameter.name, methodStart, methodEnd, Type.getType(parameter.type.accept(JavaTypeClassVisitor.INSTANCE)));
149
+                methodWriter.nameVariable(parameter.getTag(JavaParameterInfo.class).index, parameter.name, methodStart, methodEnd, context.getType(parameter.type));
147 150
         }
148 151
 
149
-        final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(methodWriter);
152
+        final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, methodWriter);
150 153
 
151 154
         if (!isAbstract) {
152 155
             statementVisitor.start();
@@ -210,7 +213,7 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
210 213
         if (enumDefinition != null) {
211 214
 			for (EnumConstantMember constant : enumDefinition.enumConstants) {
212 215
 				writer.visitField(Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_ENUM, constant.name, "L" + definition.name + ";", null, null).visitEnd();
213
-				final String internalName = constant.constructor.type.accept(JavaTypeVisitor.INSTANCE).getInternalName();
216
+				final String internalName = context.getInternalName(constant.constructor.type);
214 217
 				final JavaWriter clinitWriter = clinitStatementVisitor.getJavaWriter();
215 218
 				clinitWriter.newObject(internalName);
216 219
 				clinitWriter.dup();
@@ -220,7 +223,7 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
220 223
 					argument.accept(clinitStatementVisitor.expressionVisitor);
221 224
 				}
222 225
 
223
-				clinitWriter.invokeSpecial(internalName, "<init>", CompilerUtils.calcDesc(constant.constructor.constructor.getHeader(), true));
226
+				clinitWriter.invokeSpecial(internalName, "<init>", context.getEnumConstructorDescriptor(constant.constructor.constructor.getHeader()));
224 227
 				clinitWriter.putStaticField(internalName, constant.name, "L" + internalName + ";");
225 228
 				
226 229
 				enumDefinition = (EnumDefinition) constant.definition;

+ 12
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaClass.java View File

@@ -21,6 +21,17 @@ public class JavaClass implements Comparable<JavaClass> {
21 21
 	public static final JavaClass MAP = new JavaClass("java.util", "Map", JavaClass.Kind.INTERFACE);
22 22
 	public static final JavaClass HASHMAP = new JavaClass("java.util", "HashMap", JavaClass.Kind.CLASS);
23 23
 	public static final JavaClass ITERATOR = new JavaClass("java.util", "Iterator", JavaClass.Kind.INTERFACE);
24
+	public static final JavaClass ARRAYS = new JavaClass("java.util", "Arrays", Kind.CLASS);
25
+	
26
+	public static final JavaClass BOOLEAN = new JavaClass("java.lang", "Boolean", Kind.CLASS);
27
+	public static final JavaClass BYTE = new JavaClass("java.lang", "Byte", Kind.CLASS);
28
+	public static final JavaClass SHORT = new JavaClass("java.lang", "Short", Kind.CLASS);
29
+	public static final JavaClass INTEGER = new JavaClass("java.lang", "Integer", Kind.CLASS);
30
+	public static final JavaClass LONG = new JavaClass("java.lang", "Long", Kind.CLASS);
31
+	public static final JavaClass FLOAT = new JavaClass("java.lang", "Float", Kind.CLASS);
32
+	public static final JavaClass DOUBLE = new JavaClass("java.lang", "Double", Kind.CLASS);
33
+	public static final JavaClass CHARACTER = new JavaClass("java.lang", "Character", Kind.CLASS);
34
+	public static final JavaClass COLLECTION = new JavaClass("java.util", "Collection", Kind.INTERFACE);
24 35
 	
25 36
 	public static JavaClass fromInternalName(String internalName, Kind kind) {
26 37
 		if (kind == Kind.ARRAY)
@@ -45,6 +56,7 @@ public class JavaClass implements Comparable<JavaClass> {
45 56
 	
46 57
 	public boolean empty = false;
47 58
 	public boolean destructible = false;
59
+	public boolean membersPrepared = false;
48 60
 	
49 61
 	private final String[] classNameParts;
50 62
 	

JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/tags/JavaSourceField.java → JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaField.java View File

@@ -3,20 +3,20 @@
3 3
  * To change this template file, choose Tools | Templates
4 4
  * and open the template in the editor.
5 5
  */
6
-package org.openzen.zenscript.javasource.tags;
7
-
8
-import org.openzen.zenscript.javashared.JavaClass;
6
+package org.openzen.zenscript.javashared;
9 7
 
10 8
 /**
11 9
  *
12 10
  * @author Hoofdgebruiker
13 11
  */
14
-public class JavaSourceField {
12
+public class JavaField {
15 13
 	public final JavaClass cls;
16 14
 	public final String name;
15
+	public final String signature;
17 16
 	
18
-	public JavaSourceField(JavaClass cls, String name) {
17
+	public JavaField(JavaClass cls, String name, String signature) {
19 18
 		this.cls = cls;
20 19
 		this.name = name;
20
+		this.signature = signature;
21 21
 	}
22 22
 }

JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSynthesizedClass.java → JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaSynthesizedClass.java View File

@@ -3,10 +3,9 @@
3 3
  * To change this template file, choose Tools | Templates
4 4
  * and open the template in the editor.
5 5
  */
6
-package org.openzen.zenscript.javasource;
6
+package org.openzen.zenscript.javashared;
7 7
 
8 8
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
9
-import org.openzen.zenscript.javashared.JavaClass;
10 9
 
11 10
 /**
12 11
  *

+ 50
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaSynthesizedClassNamer.java View File

@@ -0,0 +1,50 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.javashared;
7
+
8
+import java.util.ArrayList;
9
+import java.util.List;
10
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
11
+import org.openzen.zenscript.codemodel.type.FunctionTypeID;
12
+import org.openzen.zenscript.codemodel.type.ITypeID;
13
+import org.openzen.zenscript.codemodel.type.RangeTypeID;
14
+
15
+/**
16
+ *
17
+ * @author Hoofdgebruiker
18
+ */
19
+public class JavaSynthesizedClassNamer {
20
+	private JavaSynthesizedClassNamer() {}
21
+	
22
+	public static JavaSynthesizedClass createFunctionName(FunctionTypeID function) {
23
+		String signature = getFunctionSignature(function);
24
+		
25
+		String className = "Function" + signature;
26
+		JavaClass cls = new JavaClass("zsynthetic", className, JavaClass.Kind.INTERFACE);
27
+		return new JavaSynthesizedClass(cls, extractTypeParameters(function));
28
+	}
29
+	
30
+	public static JavaSynthesizedClass createRangeName(RangeTypeID range) {
31
+		String signature = getRangeSignature(range);
32
+		String className = signature + "Range";
33
+		JavaClass cls = new JavaClass("zsynthetic", className, JavaClass.Kind.CLASS);
34
+		return new JavaSynthesizedClass(cls, extractTypeParameters(range));
35
+	}
36
+	
37
+	public static TypeParameter[] extractTypeParameters(ITypeID type) {
38
+		List<TypeParameter> result = new ArrayList<>();
39
+		type.extractTypeParameters(result);
40
+		return result.toArray(new TypeParameter[result.size()]);
41
+	}
42
+	
43
+	public static String getFunctionSignature(FunctionTypeID type) {
44
+		return new JavaSyntheticTypeSignatureConverter().visitFunction(type);
45
+	}
46
+	
47
+	public static String getRangeSignature(RangeTypeID type) {
48
+		return new JavaSyntheticTypeSignatureConverter().visitRange(type);
49
+	}
50
+}

+ 19
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaSyntheticClassGenerator.java View File

@@ -0,0 +1,19 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.javashared;
7
+
8
+import org.openzen.zenscript.codemodel.type.FunctionTypeID;
9
+import org.openzen.zenscript.codemodel.type.RangeTypeID;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public interface JavaSyntheticClassGenerator {
16
+	JavaSynthesizedClass synthesizeFunction(FunctionTypeID type);
17
+	
18
+	JavaSynthesizedClass synthesizeRange(RangeTypeID type);
19
+}

JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSyntheticTypeSignatureConverter.java → JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaSyntheticTypeSignatureConverter.java View File

@@ -3,7 +3,7 @@
3 3
  * To change this template file, choose Tools | Templates
4 4
  * and open the template in the editor.
5 5
  */
6
-package org.openzen.zenscript.javasource;
6
+package org.openzen.zenscript.javashared;
7 7
 
8 8
 import java.util.ArrayList;
9 9
 import java.util.HashMap;
@@ -32,7 +32,7 @@ public class JavaSyntheticTypeSignatureConverter implements ITypeVisitor<String>
32 32
 	private static final String[] typeParameterNames = {"T", "U", "V", "W", "X", "Y", "Z"}; // if we have more than this, make it Tx with x the number
33 33
 	private final Map<TypeParameter, String> typeParameters = new HashMap<>();
34 34
 	public final List<TypeParameter> typeParameterList = new ArrayList<>();
35
-
35
+	
36 36
 	@Override
37 37
 	public String visitBasic(BasicTypeID basic) {
38 38
 		switch (basic) {

+ 119
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeDescriptorVisitor.java View File

@@ -0,0 +1,119 @@
1
+package org.openzen.zenscript.javashared;
2
+
3
+import org.openzen.zenscript.codemodel.generic.GenericParameterBound;
4
+import org.openzen.zenscript.codemodel.generic.ParameterTypeBound;
5
+import org.openzen.zenscript.codemodel.type.*;
6
+
7
+public class JavaTypeDescriptorVisitor implements ITypeVisitor<String> {
8
+	private final JavaTypeDescriptorVisitor forOptional;
9
+	private final boolean optional;
10
+	
11
+	public JavaTypeDescriptorVisitor(JavaSyntheticClassGenerator generator) {
12
+		this(generator, false);
13
+	}
14
+	
15
+	private JavaTypeDescriptorVisitor(JavaSyntheticClassGenerator generator, boolean optional) {
16
+		this.optional = optional;
17
+		forOptional = optional ? this : new JavaTypeDescriptorVisitor(generator, true);
18
+	}
19
+	
20
+    @Override
21
+    public String visitBasic(BasicTypeID basic) {
22
+		if (optional) {
23
+			switch (basic) {
24
+				case BOOL: return "Ljava/lang/Boolean;";
25
+				case CHAR: return "Ljava/lang/Character;";
26
+				case BYTE: return "Ljava/lang/Integer;";
27
+				case SBYTE: return "Ljava/lang/Byte;";
28
+				case SHORT: return "Ljava/lang/Short;";
29
+				case USHORT: return "Ljava/lang/Integer;";
30
+				case INT: return "Ljava/lang/Integer;";
31
+				case UINT: return "Ljava/lang/Integer;";
32
+				case LONG: return "Ljava/lang/Long;";
33
+				case ULONG: return "Ljava/lang/Long;";
34
+				case FLOAT: return "Ljava/lang/Float;";
35
+				case DOUBLE: return "Ljava/lang/Double;";
36
+				case STRING: return "Ljava/lang/String;";
37
+				default:
38
+					throw new IllegalArgumentException("Not a valid type: " + basic);
39
+			}
40
+		} else {
41
+			switch (basic) {
42
+				case VOID: return "V";
43
+				case BOOL: return "Z";
44
+				case CHAR: return "C";
45
+				case BYTE: return "I";
46
+				case SBYTE: return "B";
47
+				case SHORT: return "S";
48
+				case USHORT: return "I";
49
+				case INT: return "I";
50
+				case UINT: return "I";
51
+				case LONG: return "J";
52
+				case ULONG: return "J";
53
+				case FLOAT: return "F";
54
+				case DOUBLE: return "D";
55
+				case STRING: return "Ljava/lang/String;";
56
+				default:
57
+					throw new IllegalArgumentException("Not a valid type: " + basic);
58
+			}
59
+		}
60
+    }
61
+
62
+    @Override
63
+    public String visitArray(ArrayTypeID array) {
64
+		return "[" + array.elementType.accept(this);
65
+    }
66
+
67
+    @Override
68
+    public String visitAssoc(AssocTypeID assoc) {
69
+		return "Ljava/util/Map;";
70
+    }
71
+
72
+    @Override
73
+    public String visitIterator(IteratorTypeID iterator) {
74
+		return "Ljava/lang/Iterator;";
75
+    }
76
+
77
+    @Override
78
+    public String visitFunction(FunctionTypeID function) {
79
+        return "L" + JavaSynthesizedClassNamer.createFunctionName(function).cls.internalName + ";";
80
+    }
81
+
82
+    @Override
83
+    public String visitDefinition(DefinitionTypeID definition) {
84
+		JavaClass cls = definition.definition.getTag(JavaClass.class);
85
+		if (cls == null)
86
+			throw new IllegalStateException("Class not yet initialized: " + definition.definition.name);
87
+		
88
+		return "L" + cls.internalName + ";";
89
+    }
90
+
91
+    @Override
92
+    public String visitGeneric(GenericTypeID generic) {
93
+		for (GenericParameterBound bound : generic.parameter.bounds) {
94
+			if (bound instanceof ParameterTypeBound) {
95
+				return ((ParameterTypeBound) bound).type.accept(this);
96
+			}
97
+		}
98
+		
99
+		return "Ljava/lang/Object;";
100
+    }
101
+
102
+    @Override
103
+    public String visitRange(RangeTypeID range) {
104
+		return "L" + JavaSynthesizedClassNamer.createRangeName(range).cls.internalName + ";";
105
+    }
106
+
107
+    @Override
108
+    public String visitModified(ModifiedTypeID modified) {
109
+		if (modified.isOptional())
110
+			return modified.withoutOptional().accept(forOptional);
111
+		
112
+		return modified.baseType.accept(this);
113
+    }
114
+
115
+	@Override
116
+	public String visitGenericMap(GenericMapTypeID map) {
117
+		return "Ljava/util/Map;";
118
+	}
119
+}

+ 115
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaTypeInternalNameVisitor.java View File

@@ -0,0 +1,115 @@
1
+package org.openzen.zenscript.javashared;
2
+
3
+import org.openzen.zenscript.codemodel.generic.GenericParameterBound;
4
+import org.openzen.zenscript.codemodel.generic.ParameterTypeBound;
5
+import org.openzen.zenscript.codemodel.type.*;
6
+
7
+public class JavaTypeInternalNameVisitor implements ITypeVisitor<String> {
8
+	private final JavaTypeInternalNameVisitor forOptional;
9
+	private final boolean optional;
10
+	
11
+	public JavaTypeInternalNameVisitor(JavaSyntheticClassGenerator generator) {
12
+		this(generator, false);
13
+	}
14
+	
15
+	private JavaTypeInternalNameVisitor(JavaSyntheticClassGenerator generator, boolean optional) {
16
+		this.optional = optional;
17
+		forOptional = optional ? this : new JavaTypeInternalNameVisitor(generator, true);
18
+	}
19
+	
20
+    @Override
21
+    public String visitBasic(BasicTypeID basic) {
22
+		if (optional) {
23
+			switch (basic) {
24
+				case BOOL: return "java/lang/Boolean";
25
+				case CHAR: return "java/lang/Character";
26
+				case BYTE: return "java/lang/Integer";
27
+				case SBYTE: return "java/lang/Byte";
28
+				case SHORT: return "java/lang/Short";
29
+				case USHORT: return "java/lang/Integer";
30
+				case INT: return "java/lang/Integer";
31
+				case UINT: return "java/lang/Integer";
32
+				case LONG: return "java/lang/Long";
33
+				case ULONG: return "java/lang/Long";
34
+				case FLOAT: return "java/lang/Float";
35
+				case DOUBLE: return "java/lang/Double";
36
+				case STRING: return "java/lang/String";
37
+				default:
38
+					throw new IllegalArgumentException("Not a valid type: " + basic);
39
+			}
40
+		} else {
41
+			switch (basic) {
42
+				case VOID: return "V";
43
+				case BOOL: return "Z";
44
+				case CHAR: return "C";
45
+				case BYTE: return "I";
46
+				case SBYTE: return "B";
47
+				case SHORT: return "S";
48
+				case USHORT: return "I";
49
+				case INT: return "I";
50
+				case UINT: return "I";
51
+				case LONG: return "J";
52
+				case ULONG: return "J";
53
+				case FLOAT: return "F";
54
+				case DOUBLE: return "D";
55
+				case STRING: return "java/lang/String";
56
+				default:
57
+					throw new IllegalArgumentException("Not a valid type: " + basic);
58
+			}
59
+		}
60
+    }
61
+
62
+    @Override
63
+    public String visitArray(ArrayTypeID array) {
64
+		return "[" + array.elementType.accept(this);
65
+    }
66
+
67
+    @Override
68
+    public String visitAssoc(AssocTypeID assoc) {
69
+		return "java/util/Map;";
70
+    }
71
+
72
+    @Override
73
+    public String visitIterator(IteratorTypeID iterator) {
74
+		return "java/lang/Iterator;";
75
+    }
76
+
77
+    @Override
78
+    public String visitFunction(FunctionTypeID function) {
79
+        return JavaSynthesizedClassNamer.createFunctionName(function).cls.internalName;
80
+    }
81
+
82
+    @Override
83
+    public String visitDefinition(DefinitionTypeID definition) {
84
+		return definition.definition.getTag(JavaClass.class).internalName;
85
+    }
86
+
87
+    @Override
88
+    public String visitGeneric(GenericTypeID generic) {
89
+		for (GenericParameterBound bound : generic.parameter.bounds) {
90
+			if (bound instanceof ParameterTypeBound) {
91
+				return ((ParameterTypeBound) bound).type.accept(this);
92
+			}
93
+		}
94
+		
95
+		return "java/lang/Object";
96
+    }
97
+
98
+    @Override
99
+    public String visitRange(RangeTypeID range) {
100
+		return JavaSynthesizedClassNamer.createRangeName(range).cls.internalName;
101
+    }
102
+
103
+    @Override
104
+    public String visitModified(ModifiedTypeID modified) {
105
+		if (modified.isOptional())
106
+			return modified.withoutOptional().accept(forOptional);
107
+		
108
+		return modified.baseType.accept(this);
109
+    }
110
+
111
+	@Override
112
+	public String visitGenericMap(GenericMapTypeID map) {
113
+		return "java/util/Map";
114
+	}
115
+}

+ 5
- 2
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceCompiler.java View File

@@ -48,8 +48,6 @@ public class JavaSourceCompiler implements ZenCodeCompiler {
48 48
 		String filename = getFilename(definition);
49 49
 		JavaSourcePrepareDefinitionVisitor prepare = new JavaSourcePrepareDefinitionVisitor(filename, null);
50 50
 		JavaClass cls = definition.accept(prepare);
51
-		if (cls.empty)
52
-			return;
53 51
 		
54 52
 		File file = new File(getDirectory(definition.pkg), cls.getName() + ".java");
55 53
 		System.out.println("Compiling " + definition.name + " as " + cls.fullName);
@@ -67,6 +65,11 @@ public class JavaSourceCompiler implements ZenCodeCompiler {
67 65
 	
68 66
 	@Override
69 67
 	public void finish() {
68
+		JavaSourceContext context = new JavaSourceContext(typeGenerator);
69
+		for (JavaSourceFile sourceFile : sourceFiles.values()) {
70
+			sourceFile.prepare(context);
71
+		}
72
+		
70 73
 		for (JavaSourceFile sourceFile : sourceFiles.values())
71 74
 			sourceFile.write();
72 75
 		

+ 25
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceContext.java View File

@@ -0,0 +1,25 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.javasource;
7
+
8
+import org.openzen.zenscript.codemodel.type.ITypeID;
9
+import org.openzen.zenscript.javashared.JavaTypeDescriptorVisitor;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class JavaSourceContext {
16
+	private final JavaTypeDescriptorVisitor typeDescriptorVisitor;
17
+	
18
+	public JavaSourceContext(JavaSourceSyntheticTypeGenerator generator) {
19
+		typeDescriptorVisitor = new JavaTypeDescriptorVisitor(generator);
20
+	}
21
+	
22
+	public String getDescriptor(ITypeID type) {
23
+		return type.accept(typeDescriptorVisitor);
24
+	}
25
+}

+ 3
- 3
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceExpressionFormatter.java View File

@@ -94,7 +94,7 @@ import org.openzen.zenscript.formattershared.ExpressionString;
94 94
 import org.openzen.zenscript.formattershared.StatementFormattingTarget;
95 95
 import org.openzen.zenscript.javasource.scope.JavaSourceStatementScope;
96 96
 import org.openzen.zenscript.javashared.JavaClass;
97
-import org.openzen.zenscript.javasource.tags.JavaSourceField;
97
+import org.openzen.zenscript.javashared.JavaField;
98 98
 import org.openzen.zenscript.javasource.tags.JavaSourceMethod;
99 99
 import org.openzen.zenscript.javasource.tags.JavaSourceVariantOption;
100 100
 
@@ -429,7 +429,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
429 429
 
430 430
 	@Override
431 431
 	public ExpressionString visitGetStaticField(GetStaticFieldExpression expression) {
432
-		JavaSourceField field = expression.field.getTag(JavaSourceField.class);
432
+		JavaField field = expression.field.getTag(JavaField.class);
433 433
 		if (field == null)
434 434
 			throw new CompileException(expression.position, CompileExceptionCode.INTERNAL_ERROR, "Missing field tag");
435 435
 		
@@ -596,7 +596,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
596 596
 
597 597
 	@Override
598 598
 	public ExpressionString visitSetStaticField(SetStaticFieldExpression expression) {
599
-		JavaSourceField field = expression.field.getTag(JavaSourceField.class);
599
+		JavaField field = expression.field.getTag(JavaField.class);
600 600
 		if (field == null)
601 601
 			throw new CompileException(expression.position, CompileExceptionCode.INTERNAL_ERROR, "Missing field tag");
602 602
 		if (field.cls.fullName.equals(scope.fileScope.cls.fullName) && !scope.hasLocalVariable(field.name)) {

+ 16
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceFile.java View File

@@ -23,6 +23,7 @@ import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
23 23
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
24 24
 import org.openzen.zenscript.compiler.SemanticModule;
25 25
 import org.openzen.zenscript.javashared.JavaClass;
26
+import org.openzen.zenscript.javasource.prepare.JavaSourcePrepareDefinitionMemberVisitor;
26 27
 
27 28
 /**
28 29
  *
@@ -67,11 +68,25 @@ public class JavaSourceFile {
67 68
 		modules.put(definition, module);
68 69
 	}
69 70
 	
71
+	public void prepare(JavaSourceContext context) {
72
+		JavaSourcePrepareDefinitionMemberVisitor visitor = new JavaSourcePrepareDefinitionMemberVisitor(context, file.getName());
73
+		
74
+		if (mainDefinition != null)
75
+			mainDefinition.accept(visitor);
76
+		
77
+		for (ExpansionDefinition expansion : expansions)
78
+			expansion.accept(visitor);
79
+	}
80
+	
70 81
 	public void write() {
71 82
 		System.out.println("Calling write on " + file.getName());
72 83
 		
73
-		if (mainDefinition == null)
84
+		if (mainDefinition == null || mainDefinition.getTag(JavaClass.class).empty) {
85
+			if (expansions.isEmpty())
86
+				return;
87
+			
74 88
 			mainDefinition = expansions.remove(0);
89
+		}
75 90
 		
76 91
 		HighLevelDefinition definition = mainDefinition;
77 92
 		JavaDefinitionVisitor visitor = new JavaDefinitionVisitor(

+ 54
- 32
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceSyntheticTypeGenerator.java View File

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.javasource;
7 7
 
8
+import org.openzen.zenscript.javashared.JavaSynthesizedClass;
8 9
 import java.io.BufferedOutputStream;
9 10
 import java.io.File;
10 11
 import java.io.FileOutputStream;
@@ -12,22 +13,22 @@ import java.io.IOException;
12 13
 import java.io.OutputStreamWriter;
13 14
 import java.io.Writer;
14 15
 import java.nio.charset.StandardCharsets;
15
-import java.util.ArrayList;
16 16
 import java.util.HashMap;
17
-import java.util.List;
18 17
 import java.util.Map;
19 18
 import org.openzen.zenscript.codemodel.FunctionParameter;
20
-import org.openzen.zenscript.codemodel.generic.TypeParameter;
21 19
 import org.openzen.zenscript.codemodel.type.FunctionTypeID;
22
-import org.openzen.zenscript.codemodel.type.ITypeID;
20
+import org.openzen.zenscript.codemodel.type.RangeTypeID;
23 21
 import org.openzen.zenscript.javashared.JavaClass;
22
+import org.openzen.zenscript.javashared.JavaSynthesizedClassNamer;
23
+import org.openzen.zenscript.javashared.JavaSyntheticClassGenerator;
24 24
 
25 25
 /**
26 26
  *
27 27
  * @author Hoofdgebruiker
28 28
  */
29
-public class JavaSourceSyntheticTypeGenerator {
29
+public class JavaSourceSyntheticTypeGenerator implements JavaSyntheticClassGenerator {
30 30
 	private final Map<String, JavaSynthesizedClass> functions = new HashMap<>();
31
+	private final Map<String, JavaSynthesizedClass> ranges = new HashMap<>();
31 32
 	private final File directory;
32 33
 	private final JavaSourceFormattingSettings settings;
33 34
 	
@@ -36,24 +37,23 @@ public class JavaSourceSyntheticTypeGenerator {
36 37
 		this.settings = settings;
37 38
 	}
38 39
 	
39
-	public JavaSynthesizedClass createFunction(JavaSourceTypeVisitor typeFormatter, FunctionTypeID function) {
40
-		String signature = getFunctionSignature(function);
40
+	@Override
41
+	public JavaSynthesizedClass synthesizeFunction(FunctionTypeID function) {
42
+		String signature = JavaSynthesizedClassNamer.getFunctionSignature(function);
41 43
 		if (functions.containsKey(signature))
42
-			return functions.get(signature).withTypeParameters(extractTypeParameters(function));
44
+			return functions.get(signature).withTypeParameters(JavaSynthesizedClassNamer.extractTypeParameters(function));
43 45
 		
44
-		String className = "Function" + signature;
45
-		JavaClass cls = new JavaClass("zsynthetic", className, JavaClass.Kind.INTERFACE);
46
-		JavaSynthesizedClass result = new JavaSynthesizedClass(cls, extractTypeParameters(function));
46
+		JavaSynthesizedClass result = JavaSynthesizedClassNamer.createFunctionName(function);
47 47
 		functions.put(signature, result);
48 48
 		
49
-		JavaSourceImporter importer = new JavaSourceImporter(cls);
49
+		JavaSourceImporter importer = new JavaSourceImporter(result.cls);
50 50
 		JavaSourceTypeVisitor typeVisitor = new JavaSourceTypeVisitor(importer, this);
51 51
 		
52 52
 		StringBuilder contents = new StringBuilder();
53 53
 		contents.append("@FunctionalInterface\n");
54 54
 		contents.append("public interface ");
55
-		contents.append(className);
56
-		JavaSourceUtils.formatTypeParameters(typeFormatter, contents, result.typeParameters, false);
55
+		contents.append(result.cls.getName());
56
+		JavaSourceUtils.formatTypeParameters(typeVisitor, contents, result.typeParameters, false);
57 57
 		contents.append(" {\n");
58 58
 		contents.append(settings.indent);
59 59
 		if (function.header.getNumberOfTypeParameters() > 0) {
@@ -82,10 +82,49 @@ public class JavaSourceSyntheticTypeGenerator {
82 82
 		contents.append(");\n");
83 83
 		contents.append("}\n");
84 84
 		
85
+		writeFile(result, importer, contents);
86
+		return result;
87
+	}
88
+	
89
+	@Override
90
+	public JavaSynthesizedClass synthesizeRange(RangeTypeID type) {
91
+		String signature = JavaSynthesizedClassNamer.getRangeSignature(type);
92
+		if (ranges.containsKey(signature))
93
+			return ranges.get(signature).withTypeParameters(JavaSynthesizedClassNamer.extractTypeParameters(type));
94
+		
95
+		JavaSynthesizedClass result = JavaSynthesizedClassNamer.createRangeName(type);
96
+		functions.put(signature, result);
97
+		
98
+		JavaSourceImporter importer = new JavaSourceImporter(result.cls);
99
+		JavaSourceTypeVisitor typeVisitor = new JavaSourceTypeVisitor(importer, this);
100
+		
101
+		StringBuilder contents = new StringBuilder();
102
+		contents.append("public final class ").append(result.cls.getName()).append(" {\n");
103
+		contents.append(settings.indent).append("public final ").append(type.from.accept(typeVisitor)).append(" from;\n");
104
+		contents.append(settings.indent).append("public final ").append(type.to.accept(typeVisitor)).append(" to;\n");
105
+		contents.append(settings.indent).append("\n");
106
+		contents.append(settings.indent)
107
+				.append("public ")
108
+				.append(result.cls.getName())
109
+				.append("(")
110
+				.append(type.from.accept(typeVisitor))
111
+				.append(", ")
112
+				.append(type.to.accept(typeVisitor))
113
+				.append(") {\n");
114
+		contents.append(settings.indent).append(settings.indent).append("this.from = from;\n");
115
+		contents.append(settings.indent).append(settings.indent).append("this.to = top;\n");
116
+		contents.append(settings.indent).append("}\n");
117
+		contents.append("}\n");
118
+		
119
+		writeFile(result, importer, contents);
120
+		return result;
121
+	}
122
+	
123
+	private void writeFile(JavaSynthesizedClass result, JavaSourceImporter importer, StringBuilder contents) {
85 124
 		if (!directory.exists())
86 125
 			directory.mkdirs();
87 126
 		
88
-		File file = new File(directory, className + ".java");
127
+		File file = new File(directory, result.cls.getName() + ".java");
89 128
 		try (Writer writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file)), StandardCharsets.UTF_8)) {
90 129
 			writer.write("package zsynthetic;\n");
91 130
 			
@@ -108,22 +147,5 @@ public class JavaSourceSyntheticTypeGenerator {
108 147
 		} catch (IOException ex) {
109 148
 			ex.printStackTrace();
110 149
 		}
111
-		return result;
112
-	}
113
-	
114
-	private TypeParameter[] extractTypeParameters(ITypeID type) {
115
-		List<TypeParameter> result = new ArrayList<>();
116
-		type.extractTypeParameters(result);
117
-		return result.toArray(new TypeParameter[result.size()]);
118
-	}
119
-	
120
-	private static String getFunctionSignature(FunctionTypeID type) {
121
-		return new JavaSyntheticTypeSignatureConverter().visitFunction(type);
122
-	}
123
-	
124
-	private TypeParameter[] getFunctionTypeParameters(FunctionTypeID type) {
125
-		JavaSyntheticTypeSignatureConverter converter = new JavaSyntheticTypeSignatureConverter();
126
-		converter.visitFunction(type);
127
-		return converter.typeParameterList.toArray(new TypeParameter[converter.typeParameterList.size()]);
128 150
 	}
129 151
 }

+ 2
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceTypeVisitor.java View File

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.javasource;
7 7
 
8
+import org.openzen.zenscript.javashared.JavaSynthesizedClass;
8 9
 import org.openzen.zenscript.codemodel.generic.GenericParameterBoundVisitor;
9 10
 import org.openzen.zenscript.codemodel.generic.ParameterSuperBound;
10 11
 import org.openzen.zenscript.codemodel.generic.ParameterTypeBound;
@@ -101,7 +102,7 @@ public class JavaSourceTypeVisitor implements ITypeVisitor<String>, GenericParam
101 102
 
102 103
 	@Override
103 104
 	public String visitFunction(FunctionTypeID function) {
104
-		JavaSynthesizedClass synthetic = typeGenerator.createFunction(this, function);
105
+		JavaSynthesizedClass synthetic = typeGenerator.synthesizeFunction(function);
105 106
 		StringBuilder result = new StringBuilder();
106 107
 		result.append(importer.importType(synthetic.cls));
107 108
 		if (synthetic.typeParameters.length > 0) {

+ 13
- 9
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareClassMethodVisitor.java View File

@@ -28,7 +28,8 @@ import org.openzen.zenscript.codemodel.member.StaticInitializerMember;
28 28
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
29 29
 import org.openzen.zenscript.javasource.JavaSourceTypeNameVisitor;
30 30
 import org.openzen.zenscript.javashared.JavaClass;
31
-import org.openzen.zenscript.javasource.tags.JavaSourceField;
31
+import org.openzen.zenscript.javashared.JavaField;
32
+import org.openzen.zenscript.javasource.JavaSourceContext;
32 33
 import org.openzen.zenscript.javasource.tags.JavaSourceImplementation;
33 34
 import org.openzen.zenscript.javasource.tags.JavaSourceMethod;
34 35
 
@@ -39,21 +40,24 @@ import org.openzen.zenscript.javasource.tags.JavaSourceMethod;
39 40
 public class JavaSourcePrepareClassMethodVisitor implements MemberVisitor<Void> {
40 41
 	private static final boolean DEBUG_EMPTY = true;
41 42
 	
42
-	private final JavaSourcePrepareDefinitionVisitor definitionPreparer;
43
+	private final JavaSourceContext context;
43 44
 	private final String filename;
44 45
 	private final JavaClass cls;
45 46
 	private final JavaNativeClass nativeClass;
47
+	private final JavaSourcePrepareDefinitionMemberVisitor memberPreparer;
46 48
 	
47 49
 	public JavaSourcePrepareClassMethodVisitor(
48
-			JavaSourcePrepareDefinitionVisitor definitionPreparer,
50
+			JavaSourceContext context,
49 51
 			String filename,
50 52
 			JavaClass cls,
51 53
 			JavaNativeClass nativeClass,
54
+			JavaSourcePrepareDefinitionMemberVisitor memberPreparer,
52 55
 			boolean startsEmpty) {
53
-		this.definitionPreparer = definitionPreparer;
56
+		this.context = context;
54 57
 		this.filename = filename;
55 58
 		this.cls = cls;
56 59
 		this.nativeClass = nativeClass;
60
+		this.memberPreparer = memberPreparer;
57 61
 		
58 62
 		cls.empty = startsEmpty;
59 63
 	}
@@ -64,13 +68,13 @@ public class JavaSourcePrepareClassMethodVisitor implements MemberVisitor<Void>
64 68
 			System.out.println("Class " + cls.fullName + " not empty because of const " + member.name);
65 69
 		
66 70
 		cls.empty = false;
67
-		member.setTag(JavaSourceField.class, new JavaSourceField(cls, member.name));
71
+		member.setTag(JavaField.class, new JavaField(cls, member.name, context.getDescriptor(member.type)));
68 72
 		return null;
69 73
 	}
70 74
 	
71 75
 	@Override
72 76
 	public Void visitField(FieldMember member) {
73
-		member.setTag(JavaSourceField.class, new JavaSourceField(cls, member.name));
77
+		member.setTag(JavaField.class, new JavaField(cls, member.name, context.getDescriptor(member.type)));
74 78
 		if (member.hasAutoGetter())
75 79
 			visitGetter(member.autoGetter);
76 80
 		if (member.hasAutoSetter())
@@ -138,7 +142,7 @@ public class JavaSourcePrepareClassMethodVisitor implements MemberVisitor<Void>
138 142
 
139 143
 	@Override
140 144
 	public Void visitImplementation(ImplementationMember member) {
141
-		definitionPreparer.prepare(member.type);
145
+		memberPreparer.prepare(member.type);
142 146
 		
143 147
 		if (canMergeImplementation(member)) {
144 148
 			member.setTag(JavaSourceImplementation.class, new JavaSourceImplementation(true, cls));
@@ -153,7 +157,7 @@ public class JavaSourcePrepareClassMethodVisitor implements MemberVisitor<Void>
153 157
 			JavaClass implementationClass = new JavaClass(cls, member.type.accept(new JavaSourceTypeNameVisitor()) + "Implementation", JavaClass.Kind.CLASS);
154 158
 			member.setTag(JavaSourceImplementation.class, new JavaSourceImplementation(false, implementationClass));
155 159
 			
156
-			JavaSourcePrepareClassMethodVisitor visitor = new JavaSourcePrepareClassMethodVisitor(definitionPreparer, filename, implementationClass, null, true);
160
+			JavaSourcePrepareClassMethodVisitor visitor = new JavaSourcePrepareClassMethodVisitor(context, filename, implementationClass, null, memberPreparer, true);
157 161
 			for (IDefinitionMember m : member.members)
158 162
 				m.accept(visitor);
159 163
 		}
@@ -166,7 +170,7 @@ public class JavaSourcePrepareClassMethodVisitor implements MemberVisitor<Void>
166 170
 
167 171
 	@Override
168 172
 	public Void visitInnerDefinition(InnerDefinitionMember member) {
169
-		JavaSourcePrepareDefinitionVisitor innerDefinitionPrepare = new JavaSourcePrepareDefinitionVisitor(filename, cls);
173
+		JavaSourcePrepareDefinitionMemberVisitor innerDefinitionPrepare = new JavaSourcePrepareDefinitionMemberVisitor(context, filename);
170 174
 		member.innerDefinition.accept(innerDefinitionPrepare);
171 175
 		
172 176
 		if (DEBUG_EMPTY && cls.empty)

+ 154
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareDefinitionMemberVisitor.java View File

@@ -0,0 +1,154 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.javasource.prepare;
7
+
8
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
9
+import org.openzen.zenscript.codemodel.definition.AliasDefinition;
10
+import org.openzen.zenscript.codemodel.definition.ClassDefinition;
11
+import org.openzen.zenscript.codemodel.definition.DefinitionVisitor;
12
+import org.openzen.zenscript.codemodel.definition.EnumDefinition;
13
+import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
14
+import org.openzen.zenscript.codemodel.definition.FunctionDefinition;
15
+import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
16
+import org.openzen.zenscript.codemodel.definition.StructDefinition;
17
+import org.openzen.zenscript.codemodel.definition.VariantDefinition;
18
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
19
+import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
20
+import org.openzen.zenscript.codemodel.type.ITypeID;
21
+import org.openzen.zenscript.javashared.JavaClass;
22
+import org.openzen.zenscript.javasource.JavaSourceContext;
23
+import org.openzen.zenscript.javasource.tags.JavaSourceMethod;
24
+
25
+/**
26
+ *
27
+ * @author Hoofdgebruiker
28
+ */
29
+public class JavaSourcePrepareDefinitionMemberVisitor implements DefinitionVisitor<JavaClass> {
30
+	private final JavaSourceContext context;
31
+	private final String filename;
32
+	
33
+	public JavaSourcePrepareDefinitionMemberVisitor(JavaSourceContext context, String filename) {
34
+		this.context = context;
35
+		this.filename = filename;
36
+	}
37
+	
38
+	private boolean isPrepared(HighLevelDefinition definition) {
39
+		return definition.getTag(JavaClass.class).membersPrepared;
40
+	}
41
+	
42
+	public void prepare(ITypeID type) {
43
+		if (!(type instanceof DefinitionTypeID))
44
+			return;
45
+			
46
+		HighLevelDefinition definition = ((DefinitionTypeID)type).definition;
47
+		definition.accept(this);
48
+	}
49
+	
50
+	@Override
51
+	public JavaClass visitClass(ClassDefinition definition) {
52
+		if (isPrepared(definition))
53
+			return definition.getTag(JavaClass.class);
54
+		
55
+		return visitClassCompiled(definition, true, JavaClass.Kind.CLASS);
56
+	}
57
+
58
+	@Override
59
+	public JavaClass visitInterface(InterfaceDefinition definition) {
60
+		if (isPrepared(definition))
61
+			return definition.getTag(JavaClass.class);
62
+		
63
+		for (ITypeID baseType : definition.baseInterfaces)
64
+			prepare(baseType);
65
+		
66
+		return visitClassCompiled(definition, true, JavaClass.Kind.INTERFACE);
67
+	}
68
+
69
+	@Override
70
+	public JavaClass visitEnum(EnumDefinition definition) {
71
+		if (isPrepared(definition))
72
+			return definition.getTag(JavaClass.class);
73
+		
74
+		return visitClassCompiled(definition, false, JavaClass.Kind.ENUM);
75
+	}
76
+
77
+	@Override
78
+	public JavaClass visitStruct(StructDefinition definition) {
79
+		if (isPrepared(definition))
80
+			return definition.getTag(JavaClass.class);
81
+		
82
+		return visitClassCompiled(definition, true, JavaClass.Kind.CLASS);
83
+	}
84
+
85
+	@Override
86
+	public JavaClass visitFunction(FunctionDefinition definition) {
87
+		if (isPrepared(definition))
88
+			return definition.getTag(JavaClass.class);
89
+		
90
+		JavaClass cls = definition.getTag(JavaClass.class);
91
+		JavaSourceMethod method = new JavaSourceMethod(cls, JavaSourceMethod.Kind.STATIC, definition.name, true);
92
+		definition.caller.setTag(JavaSourceMethod.class, method);
93
+		return cls;
94
+	}
95
+
96
+	@Override
97
+	public JavaClass visitExpansion(ExpansionDefinition definition) {
98
+		if (isPrepared(definition))
99
+			return definition.getTag(JavaClass.class);
100
+		
101
+		JavaNativeClass nativeClass = definition.getTag(JavaNativeClass.class);
102
+		JavaClass cls = definition.getTag(JavaClass.class);
103
+		visitExpansionMembers(definition, cls, nativeClass);
104
+		return cls;
105
+	}
106
+
107
+	@Override
108
+	public JavaClass visitAlias(AliasDefinition definition) {
109
+		// nothing to do
110
+		return null;
111
+	}
112
+
113
+	@Override
114
+	public JavaClass visitVariant(VariantDefinition variant) {
115
+		if (isPrepared(variant))
116
+			return variant.getTag(JavaClass.class);
117
+		
118
+		JavaClass cls = variant.getTag(JavaClass.class);
119
+		visitClassMembers(variant, cls, null, false);
120
+		return cls;
121
+	}
122
+	
123
+	private JavaClass visitClassCompiled(HighLevelDefinition definition, boolean startsEmpty, JavaClass.Kind kind) {
124
+		if (definition.getSuperType() != null)
125
+			prepare(definition.getSuperType());
126
+		
127
+		JavaNativeClass nativeClass = definition.getTag(JavaNativeClass.class);
128
+		JavaClass cls = definition.getTag(JavaClass.class);
129
+		if (nativeClass == null) {
130
+			visitClassMembers(definition, cls, null, startsEmpty);
131
+		} else {
132
+			visitExpansionMembers(definition, cls, nativeClass);
133
+		}
134
+		return cls;
135
+	}
136
+	
137
+	private void visitClassMembers(HighLevelDefinition definition, JavaClass cls, JavaNativeClass nativeClass, boolean startsEmpty) {
138
+		System.out.println("Preparing " + cls.internalName);
139
+		JavaSourcePrepareClassMethodVisitor methodVisitor = new JavaSourcePrepareClassMethodVisitor(context, filename, cls, nativeClass, this, startsEmpty);
140
+		for (IDefinitionMember member : definition.members) {
141
+			member.accept(methodVisitor);
142
+		}
143
+		cls.membersPrepared = true;
144
+	}
145
+	
146
+	private void visitExpansionMembers(HighLevelDefinition definition, JavaClass cls, JavaNativeClass nativeClass) {
147
+		System.out.println("Preparing " + cls.internalName);
148
+		JavaSourcePrepareExpansionMethodVisitor methodVisitor = new JavaSourcePrepareExpansionMethodVisitor(context, cls, nativeClass);
149
+		for (IDefinitionMember member : definition.members) {
150
+			member.accept(methodVisitor);
151
+		}
152
+		cls.membersPrepared = true;
153
+	}
154
+}

+ 11
- 25
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareDefinitionVisitor.java View File

@@ -22,6 +22,7 @@ import org.openzen.zenscript.codemodel.expression.CallExpression;
22 22
 import org.openzen.zenscript.codemodel.expression.CastExpression;
23 23
 import org.openzen.zenscript.codemodel.expression.Expression;
24 24
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
25
+import org.openzen.zenscript.codemodel.member.InnerDefinitionMember;
25 26
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
26 27
 import org.openzen.zenscript.codemodel.type.ITypeID;
27 28
 import org.openzen.zenscript.formattershared.ExpressionString;
@@ -272,8 +273,6 @@ public class JavaSourcePrepareDefinitionVisitor implements DefinitionVisitor<Jav
272 273
 		
273 274
 		JavaClass cls = new JavaClass(definition.pkg.fullName, filename, JavaClass.Kind.CLASS);
274 275
 		definition.setTag(JavaClass.class, cls);
275
-		JavaSourceMethod method = new JavaSourceMethod(cls, JavaSourceMethod.Kind.STATIC, definition.name, true);
276
-		definition.caller.setTag(JavaSourceMethod.class, method);
277 276
 		return cls;
278 277
 	}
279 278
 
@@ -283,14 +282,12 @@ public class JavaSourcePrepareDefinitionVisitor implements DefinitionVisitor<Jav
283 282
 			return definition.getTag(JavaClass.class);
284 283
 		
285 284
 		NativeTag nativeTag = definition.getTag(NativeTag.class);
286
-		JavaNativeClass nativeClass = null;
287 285
 		if (nativeTag != null) {
288
-			nativeClass = nativeClasses.get(nativeTag.value);
286
+			definition.setTag(JavaNativeClass.class, nativeClasses.get(nativeTag.value));
289 287
 		}
290 288
 		
291 289
 		JavaClass cls = new JavaClass(definition.pkg.fullName, filename, JavaClass.Kind.CLASS);
292 290
 		definition.setTag(JavaClass.class, cls);
293
-		visitExpansionMembers(definition, cls, nativeClass);
294 291
 		return cls;
295 292
 	}
296 293
 
@@ -313,7 +310,6 @@ public class JavaSourcePrepareDefinitionVisitor implements DefinitionVisitor<Jav
313 310
 			option.setTag(JavaSourceVariantOption.class, new JavaSourceVariantOption(cls, variantCls));
314 311
 		}
315 312
 		
316
-		visitClassMembers(variant, cls, null, false);
317 313
 		return cls;
318 314
 	}
319 315
 	
@@ -323,36 +319,26 @@ public class JavaSourcePrepareDefinitionVisitor implements DefinitionVisitor<Jav
323 319
 		
324 320
 		NativeTag nativeTag = definition.getTag(NativeTag.class);
325 321
 		JavaNativeClass nativeClass = nativeTag == null ? null : nativeClasses.get(nativeTag.value);
322
+		JavaClass cls;
326 323
 		if (nativeClass == null) {
327
-			JavaClass cls = outerClass == null ? new JavaClass(definition.pkg.fullName, definition.name, kind) : new JavaClass(outerClass, definition.name, kind);
324
+			cls = outerClass == null ? new JavaClass(definition.pkg.fullName, definition.name, kind) : new JavaClass(outerClass, definition.name, kind);
328 325
 			cls.destructible = definition.isDestructible();
329 326
 			definition.setTag(JavaClass.class, cls);
330
-			visitClassMembers(definition, cls, null, startsEmpty);
331
-			return cls;
332 327
 		} else {
333
-			JavaClass cls = outerClass == null ? new JavaClass(definition.pkg.fullName, filename, kind) : new JavaClass(outerClass, filename, kind);
328
+			cls = outerClass == null ? new JavaClass(definition.pkg.fullName, filename, kind) : new JavaClass(outerClass, filename, kind);
334 329
 			definition.setTag(JavaClass.class, nativeClass.cls);
335 330
 			definition.setTag(JavaNativeClass.class, nativeClass);
336
-			visitExpansionMembers(definition, cls, nativeClass);
337 331
 			
338 332
 			if (nativeClass.nonDestructible)
339 333
 				cls.destructible = false;
340
-			
341
-			return cls;
342
-		}
343
-	}
344
-	
345
-	private void visitClassMembers(HighLevelDefinition definition, JavaClass cls, JavaNativeClass nativeClass, boolean startsEmpty) {
346
-		JavaSourcePrepareClassMethodVisitor methodVisitor = new JavaSourcePrepareClassMethodVisitor(this, filename, cls, nativeClass, startsEmpty);
347
-		for (IDefinitionMember member : definition.members) {
348
-			member.accept(methodVisitor);
349 334
 		}
350
-	}
351
-	
352
-	private void visitExpansionMembers(HighLevelDefinition definition, JavaClass cls, JavaNativeClass nativeClass) {
353
-		JavaSourcePrepareExpansionMethodVisitor methodVisitor = new JavaSourcePrepareExpansionMethodVisitor(cls, nativeClass);
335
+		
354 336
 		for (IDefinitionMember member : definition.members) {
355
-			member.accept(methodVisitor);
337
+			if (member instanceof InnerDefinitionMember) {
338
+				((InnerDefinitionMember) member).innerDefinition.accept(new JavaSourcePrepareDefinitionVisitor(filename, cls));
339
+			}
356 340
 		}
341
+		
342
+		return cls;
357 343
 	}
358 344
 }

+ 7
- 4
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareExpansionMethodVisitor.java View File

@@ -27,7 +27,8 @@ import org.openzen.zenscript.codemodel.member.SetterMember;
27 27
 import org.openzen.zenscript.codemodel.member.StaticInitializerMember;
28 28
 import org.openzen.zenscript.javasource.JavaSourceTypeNameVisitor;
29 29
 import org.openzen.zenscript.javashared.JavaClass;
30
-import org.openzen.zenscript.javasource.tags.JavaSourceField;
30
+import org.openzen.zenscript.javashared.JavaField;
31
+import org.openzen.zenscript.javasource.JavaSourceContext;
31 32
 import org.openzen.zenscript.javasource.tags.JavaSourceImplementation;
32 33
 import org.openzen.zenscript.javasource.tags.JavaSourceMethod;
33 34
 
@@ -38,18 +39,20 @@ import org.openzen.zenscript.javasource.tags.JavaSourceMethod;
38 39
 public class JavaSourcePrepareExpansionMethodVisitor implements MemberVisitor<Void> {
39 40
 	private static final boolean DEBUG_EMPTY = true;
40 41
 	
42
+	private final JavaSourceContext context;
41 43
 	private final JavaClass cls;
42 44
 	private final JavaNativeClass nativeClass;
43 45
 	
44
-	public JavaSourcePrepareExpansionMethodVisitor(JavaClass cls, JavaNativeClass nativeClass) {
46
+	public JavaSourcePrepareExpansionMethodVisitor(JavaSourceContext context, JavaClass cls, JavaNativeClass nativeClass) {
45 47
 		this.cls = cls;
46 48
 		this.nativeClass = nativeClass;
49
+		this.context = context;
47 50
 		cls.empty = true;
48 51
 	}
49 52
 	
50 53
 	@Override
51 54
 	public Void visitConst(ConstMember member) {
52
-		member.setTag(JavaSourceField.class, new JavaSourceField(cls, member.name));
55
+		member.setTag(JavaField.class, new JavaField(cls, member.name, context.getDescriptor(member.type)));
53 56
 		
54 57
 		if (DEBUG_EMPTY && cls.empty)
55 58
 			System.out.println("Class " + cls.fullName + " not empty because of const");
@@ -61,7 +64,7 @@ public class JavaSourcePrepareExpansionMethodVisitor implements MemberVisitor<Vo
61 64
 	@Override
62 65
 	public Void visitField(FieldMember member) {
63 66
 		// TODO: expansion fields
64
-		member.setTag(JavaSourceField.class, new JavaSourceField(cls, member.name));
67
+		member.setTag(JavaField.class, new JavaField(cls, member.name, context.getDescriptor(member.type)));
65 68
 		if (member.hasAutoGetter() || member.hasAutoSetter())
66 69
 			cls.empty = false;
67 70
 		return null;

+ 2
- 2
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/GlobalRegistry.java View File

@@ -29,10 +29,10 @@ import org.openzen.zenscript.codemodel.scope.BaseScope;
29 29
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
30 30
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
31 31
 import org.openzen.zenscript.codemodel.type.ITypeID;
32
-import org.openzen.zenscript.javabytecode.JavaFieldInfo;
33 32
 import org.openzen.zenscript.javabytecode.JavaMethodInfo;
34 33
 import org.openzen.zenscript.codemodel.type.ISymbol;
35 34
 import org.openzen.zenscript.javashared.JavaClass;
35
+import org.openzen.zenscript.javashared.JavaField;
36 36
 
37 37
 /**
38 38
  *
@@ -50,7 +50,7 @@ public class GlobalRegistry {
50 50
 		PRINTSTREAM_PRINTLN.setTag(JavaMethodInfo.class, printstreamPrintln);
51 51
 		
52 52
 		JavaClass jSystem = new JavaClass("java.lang", "System", JavaClass.Kind.CLASS);
53
-		SYSTEM_OUT.setTag(JavaFieldInfo.class, new JavaFieldInfo(jSystem, "out", "Ljava/io/PrintStream;"));
53
+		SYSTEM_OUT.setTag(JavaField.class, new JavaField(jSystem, "out", "Ljava/io/PrintStream;"));
54 54
 	}
55 55
 	
56 56
 	public ZSPackage collectPackages() {

Loading…
Cancel
Save