Browse Source

- Fixed ranges, all range types should be supported now

- Cleaned up unused code
- Refactored the JavaMethodInfo class to the shared JavaMethod one
- Use valueOf for boxing instead of the boxed type constructors
Stan Hebben 6 years ago
parent
commit
7b5ada39fa
31 changed files with 518 additions and 652 deletions
  1. 13
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ConstructorMember.java
  2. 0
    12
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/implementations/IntRange.java
  3. 85
    4
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeContext.java
  4. 0
    15
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeImplementation.java
  5. 0
    23
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompileUtils.java
  6. 5
    6
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java
  7. 0
    42
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaMethodInfo.java
  8. 15
    7
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaModule.java
  9. 4
    91
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/CompilerUtils.java
  10. 37
    30
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaBoxingTypeVisitor.java
  11. 144
    163
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
  12. 2
    2
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaForeachVisitor.java
  13. 1
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreDecrementVisitor.java
  14. 1
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreIncrementVisitor.java
  15. 2
    3
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaScriptFile.java
  16. 1
    3
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java
  17. 48
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaSwitchKeyVisitor.java
  18. 27
    102
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java
  19. 62
    89
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaDefinitionVisitor.java
  20. 11
    29
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaMemberVisitor.java
  21. 7
    0
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaClass.java
  22. 4
    3
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaField.java
  23. 29
    0
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaMethod.java
  24. 4
    6
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaParameterInfo.java
  25. 1
    1
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaSynthesizedClassNamer.java
  26. 3
    5
      JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareClassMethodVisitor.java
  27. 3
    5
      JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareDefinitionMemberVisitor.java
  28. 2
    2
      JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareDefinitionVisitor.java
  29. 1
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceFile.java
  30. 1
    0
      ScriptingExample/build.gradle
  31. 5
    6
      ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/GlobalRegistry.java

+ 13
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ConstructorMember.java View File

@@ -6,14 +6,19 @@
6 6
 package org.openzen.zenscript.codemodel.member;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.ConcatMap;
9 10
 import org.openzen.zenscript.codemodel.FunctionHeader;
10 11
 import org.openzen.zenscript.codemodel.GenericMapper;
11 12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
+import org.openzen.zenscript.codemodel.Modifiers;
14
+import org.openzen.zenscript.codemodel.definition.EnumDefinition;
12 15
 import org.openzen.zenscript.codemodel.expression.ConstructorSuperCallExpression;
13 16
 import org.openzen.zenscript.codemodel.expression.ConstructorThisCallExpression;
14 17
 import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
18
+import org.openzen.zenscript.codemodel.scope.TypeScope;
15 19
 import org.openzen.zenscript.codemodel.statement.BlockStatement;
16 20
 import org.openzen.zenscript.codemodel.statement.ExpressionStatement;
21
+import org.openzen.zenscript.codemodel.statement.LoopStatement;
17 22
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
18 23
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
19 24
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
@@ -84,4 +89,12 @@ public class ConstructorMember extends FunctionalMember {
84 89
 	public DefinitionMemberRef getOverrides() {
85 90
 		return null;
86 91
 	}
92
+
93
+	@Override
94
+	public void normalize(TypeScope scope) {
95
+		if (definition instanceof EnumDefinition)
96
+			modifiers |= Modifiers.PRIVATE;
97
+		
98
+		super.normalize(scope);
99
+	}
87 100
 }

+ 0
- 12
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/implementations/IntRange.java View File

@@ -1,12 +0,0 @@
1
-package org.openzen.zenscript.implementations;
2
-
3
-public class IntRange {
4
-	public final int from;
5
-	public final int to;
6
-
7
-
8
-	public IntRange(int from, int to) {
9
-		this.from = from;
10
-		this.to = to;
11
-	}
12
-}

+ 85
- 4
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeContext.java View File

@@ -5,15 +5,24 @@
5 5
  */
6 6
 package org.openzen.zenscript.javabytecode;
7 7
 
8
+import java.io.FileOutputStream;
9
+import java.io.IOException;
10
+import java.util.HashMap;
11
+import java.util.Map;
12
+import org.objectweb.asm.ClassWriter;
13
+import org.objectweb.asm.MethodVisitor;
14
+import org.objectweb.asm.Opcodes;
8 15
 import org.objectweb.asm.Type;
9 16
 import org.openzen.zenscript.codemodel.FunctionHeader;
10
-import org.openzen.zenscript.codemodel.FunctionParameter;
11 17
 import org.openzen.zenscript.codemodel.type.FunctionTypeID;
12 18
 import org.openzen.zenscript.codemodel.type.ITypeID;
13 19
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
14
-import org.openzen.zenscript.javabytecode.compiler.CompilerUtils;
20
+import org.openzen.zenscript.javabytecode.compiler.JavaWriter;
21
+import org.openzen.zenscript.javashared.JavaClass;
15 22
 import org.openzen.zenscript.javashared.JavaContext;
23
+import org.openzen.zenscript.javashared.JavaMethod;
16 24
 import org.openzen.zenscript.javashared.JavaSynthesizedClass;
25
+import org.openzen.zenscript.javashared.JavaSynthesizedClassNamer;
17 26
 import org.openzen.zenscript.javashared.JavaSyntheticClassGenerator;
18 27
 import org.openzen.zenscript.javashared.JavaTypeDescriptorVisitor;
19 28
 import org.openzen.zenscript.javashared.JavaTypeInternalNameVisitor;
@@ -27,6 +36,9 @@ public class JavaBytecodeContext extends JavaContext {
27 36
 	private final TypeGenerator typeGenerator;
28 37
 	private final JavaTypeInternalNameVisitor internalNameVisitor;
29 38
 	private final JavaTypeDescriptorVisitor descriptorVisitor;
39
+	private final Map<String, JavaSynthesizedClass> functions = new HashMap<>();
40
+	private final Map<String, JavaSynthesizedClass> ranges = new HashMap<>();
41
+	private int lambdaCounter = 0;
30 42
 	
31 43
 	public JavaBytecodeContext(JavaModule module) {
32 44
 		this.module = module;
@@ -56,17 +68,86 @@ public class JavaBytecodeContext extends JavaContext {
56 68
 	public void register(String name, byte[] bytecode) {
57 69
 		module.register(name, bytecode);
58 70
 	}
71
+
72
+    private JavaSynthesizedClass getLambdaInterface(FunctionTypeID function) {
73
+		String signature = JavaSynthesizedClassNamer.getFunctionSignature(function);
74
+		if (functions.containsKey(signature))
75
+			return functions.get(signature).withTypeParameters(JavaSynthesizedClassNamer.extractTypeParameters(function));
76
+		
77
+		JavaSynthesizedClass result = JavaSynthesizedClassNamer.createFunctionName(function);
78
+		functions.put(signature, result);
79
+		
80
+        createLambdaInterface(function.header, result.cls);
81
+        return result;
82
+    }
83
+	
84
+	private JavaSynthesizedClass getRangeType(RangeTypeID type) {
85
+		String signature = JavaSynthesizedClassNamer.getRangeSignature(type);
86
+		if (ranges.containsKey(signature))
87
+			return ranges.get(signature).withTypeParameters(JavaSynthesizedClassNamer.extractTypeParameters(type));
88
+		
89
+		JavaSynthesizedClass result = JavaSynthesizedClassNamer.createRangeName(type);
90
+		ranges.put(signature, result);
91
+		
92
+		createRangeClass(type.from, type.to, result.cls);
93
+		return result;
94
+	}
95
+
96
+    private void createLambdaInterface(FunctionHeader header, JavaClass cls) {
97
+        ClassWriter ifaceWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
98
+        ifaceWriter.visitAnnotation("java/lang/FunctionalInterface", true).visitEnd();
99
+        ifaceWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT, cls.internalName, null, "java/lang/Object", null);
100
+
101
+        ifaceWriter
102
+				.visitMethod(
103
+					Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT,
104
+					"accept",
105
+					getMethodDescriptor(header),
106
+					getMethodSignature(header),
107
+					null)
108
+				.visitEnd();
109
+
110
+        register(cls.internalName, ifaceWriter.toByteArray());
111
+    }
112
+	
113
+	private void createRangeClass(ITypeID from, ITypeID to, JavaClass cls) {
114
+		ClassWriter rangeWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
115
+		rangeWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, cls.internalName, null, "java/lang/Object", null);
116
+		rangeWriter.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "from", getDescriptor(from), null, null).visitEnd();
117
+		rangeWriter.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "to", getDescriptor(to), null, null).visitEnd();
118
+		
119
+		JavaMethod method = JavaMethod.getConstructor(cls, "(" + getDescriptor(from) + getDescriptor(to) + ")V", Opcodes.ACC_PUBLIC);
120
+		JavaWriter constructorWriter = new JavaWriter(rangeWriter, method, null, method.descriptor, null);
121
+		constructorWriter.loadObject(0);
122
+		constructorWriter.invokeSpecial("java/lang/Object", "<init>", "()V");
123
+		constructorWriter.loadObject(0);
124
+		constructorWriter.load(getType(from), 1);
125
+		constructorWriter.putField(cls.internalName, "from", getDescriptor(from));
126
+		constructorWriter.loadObject(0);
127
+		constructorWriter.load(getType(to), 2);
128
+		constructorWriter.putField(cls.internalName, "to", getDescriptor(from));
129
+		constructorWriter.ret();
130
+		constructorWriter.end();
131
+		
132
+		rangeWriter.visitEnd();
133
+		
134
+		register(cls.internalName, rangeWriter.toByteArray());
135
+	}
136
+
137
+    public String getLambdaCounter() {
138
+        return "lambda" + ++lambdaCounter;
139
+    }
59 140
 	
60 141
 	private class TypeGenerator implements JavaSyntheticClassGenerator {
61 142
 
62 143
 		@Override
63 144
 		public JavaSynthesizedClass synthesizeFunction(FunctionTypeID type) {
64
-			return CompilerUtils.getLambdaInterface(JavaBytecodeContext.this, type);
145
+			return getLambdaInterface(type);
65 146
 		}
66 147
 
67 148
 		@Override
68 149
 		public JavaSynthesizedClass synthesizeRange(RangeTypeID type) {
69
-			throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
150
+			return getRangeType(type);
70 151
 		}
71 152
 	}
72 153
 }

+ 0
- 15
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeImplementation.java View File

@@ -1,15 +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.javabytecode.compiler.JavaWriter;
9
-
10
-/**
11
- * @author Hoofdgebruiker
12
- */
13
-public interface JavaBytecodeImplementation {
14
-	void compile(JavaWriter writer);
15
-}

+ 0
- 23
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompileUtils.java View File

@@ -1,23 +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.objectweb.asm.Type;
9
-import org.openzen.zenscript.javashared.JavaClass;
10
-
11
-/**
12
- *
13
- * @author Hoofdgebruiker
14
- */
15
-public class JavaCompileUtils {
16
-	private JavaCompileUtils() {}
17
-	
18
-	public static JavaClass get(Class<?> cls) {
19
-		return JavaClass.fromInternalName(
20
-				Type.getInternalName(cls),
21
-				cls.isInterface() ? JavaClass.Kind.INTERFACE : (cls.isEnum() ? JavaClass.Kind.ENUM : JavaClass.Kind.CLASS));
22
-	}
23
-}

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

@@ -7,8 +7,6 @@ package org.openzen.zenscript.javabytecode;
7 7
 
8 8
 import java.io.File;
9 9
 import java.util.ArrayList;
10
-import java.util.HashMap;
11
-import java.util.Map;
12 10
 
13 11
 import org.objectweb.asm.ClassWriter;
14 12
 import org.objectweb.asm.Opcodes;
@@ -28,6 +26,7 @@ import java.util.HashMap;
28 26
 import java.util.List;
29 27
 import java.util.Map;
30 28
 import org.openzen.zenscript.javashared.JavaClass;
29
+import org.openzen.zenscript.javashared.JavaMethod;
31 30
 import org.openzen.zenscript.javashared.prepare.JavaPrepareDefinitionMemberVisitor;
32 31
 import org.openzen.zenscript.javashared.prepare.JavaPrepareDefinitionVisitor;
33 32
 
@@ -116,7 +115,7 @@ public class JavaCompiler implements ZenCodeCompiler {
116 115
 		finished = true;
117 116
 		
118 117
 		for (HighLevelDefinition definition : definitions) {
119
-			JavaPrepareDefinitionMemberVisitor memberPreparer = new JavaPrepareDefinitionMemberVisitor(context, definition.position.getFilename());
118
+			JavaPrepareDefinitionMemberVisitor memberPreparer = new JavaPrepareDefinitionMemberVisitor(context);
120 119
 			definition.accept(memberPreparer);
121 120
 		}
122 121
 		
@@ -137,7 +136,7 @@ public class JavaCompiler implements ZenCodeCompiler {
137 136
 			// convert scripts into methods (add them to a Scripts class?)
138 137
 			// (TODO: can we break very long scripts into smaller methods? for the extreme scripts)
139 138
 			final JavaClassWriter visitor = scriptFile.classWriter;
140
-			JavaMethodInfo method = new JavaMethodInfo(new JavaClass(script.pkg.fullName, className, JavaClass.Kind.CLASS), methodName, "()V", Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);
139
+			JavaMethod method = new JavaMethod(new JavaClass(script.pkg.fullName, className, JavaClass.Kind.CLASS), JavaMethod.Kind.STATIC, methodName, true, "()V", Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);
141 140
 			scriptFile.scriptMethods.add(method);
142 141
 
143 142
 			final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, new JavaWriter(visitor, method, null, null, null));
@@ -148,11 +147,11 @@ public class JavaCompiler implements ZenCodeCompiler {
148 147
 			statementVisitor.end();
149 148
 		}
150 149
 		
151
-		JavaMethodInfo runMethod = new JavaMethodInfo(new JavaClass("script", "Scripts", JavaClass.Kind.CLASS), "run", "()V", Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);
150
+		JavaMethod runMethod = new JavaMethod(new JavaClass("script", "Scripts", JavaClass.Kind.CLASS), JavaMethod.Kind.STATIC, "run", true, "()V", Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);
152 151
 		final JavaWriter runWriter = new JavaWriter(scriptsClassWriter, runMethod, null, null, null);
153 152
 		runWriter.start();
154 153
 		for (Map.Entry<String, JavaScriptFile> entry : scriptBlocks.entrySet()) {
155
-			for (JavaMethodInfo method : entry.getValue().scriptMethods)
154
+			for (JavaMethod method : entry.getValue().scriptMethods)
156 155
 				runWriter.invokeStatic(method);
157 156
 
158 157
 			entry.getValue().classWriter.visitEnd();

+ 0
- 42
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaMethodInfo.java View File

@@ -1,42 +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.objectweb.asm.Opcodes;
9
-import org.objectweb.asm.Type;
10
-import org.openzen.zenscript.javashared.JavaClass;
11
-
12
-/**
13
- * @author Hoofdgebruiker
14
- */
15
-public class JavaMethodInfo {
16
-	public static JavaMethodInfo get(int modifiers, Class owner, String name, Class result, Class... arguments) {
17
-		StringBuilder descriptor = new StringBuilder();
18
-		descriptor.append('(');
19
-		for (Class argument : arguments) {
20
-			descriptor.append(Type.getDescriptor(argument));
21
-		}
22
-		descriptor.append(')');
23
-		descriptor.append(result == null ? 'V' : Type.getDescriptor(result));
24
-		return new JavaMethodInfo(JavaCompileUtils.get(owner), name, descriptor.toString(), modifiers);
25
-	}
26
-
27
-	public final JavaClass javaClass;
28
-	public final String name;
29
-	public final String descriptor;
30
-	public final int modifiers;
31
-
32
-	public JavaMethodInfo(JavaClass javaClass, String name, String signature, int modifiers) {
33
-		this.javaClass = javaClass;
34
-		this.name = name;
35
-		this.descriptor = signature;
36
-		this.modifiers = modifiers;
37
-	}
38
-
39
-	public boolean isStatic() {
40
-		return (modifiers & Opcodes.ACC_STATIC) > 0;
41
-	}
42
-}

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

@@ -19,21 +19,29 @@ import java.util.logging.Logger;
19 19
  */
20 20
 public class JavaModule {
21 21
 	private final Map<String, byte[]> classes = new HashMap<>();
22
-
22
+	private final File debugOutput;
23
+	
23 24
 	public JavaModule() {
24
-
25
+		debugOutput = null;
25 26
 	}
26
-
27
+	
28
+	public JavaModule(File debugOutput) {
29
+		this.debugOutput = debugOutput;
30
+	}
31
+	
27 32
 	public void register(String classname, byte[] bytecode) {
28 33
 		if (bytecode == null)
29 34
 			return;
30 35
 		
36
+		classname = classname.replace('/', '.');
31 37
 		classes.put(classname, bytecode);
32 38
 		
33
-		try (FileOutputStream writer = new FileOutputStream(new File(classname.replace('/', '_') + ".class"))) {
34
-			writer.write(bytecode);
35
-		} catch (IOException e) {
36
-			e.printStackTrace();
39
+		if (debugOutput != null) {
40
+			try (FileOutputStream writer = new FileOutputStream(new File(debugOutput, classname + ".class"))) {
41
+				writer.write(bytecode);
42
+			} catch (IOException e) {
43
+				e.printStackTrace();
44
+			}
37 45
 		}
38 46
 	}
39 47
 

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

@@ -1,9 +1,6 @@
1 1
 package org.openzen.zenscript.javabytecode.compiler;
2 2
 
3
-import org.objectweb.asm.ClassWriter;
4 3
 import org.objectweb.asm.Opcodes;
5
-import org.objectweb.asm.Type;
6
-import org.openzen.zencode.shared.CodePosition;
7 4
 import org.openzen.zenscript.codemodel.FunctionHeader;
8 5
 import org.openzen.zenscript.codemodel.FunctionParameter;
9 6
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
@@ -13,17 +10,9 @@ import org.openzen.zenscript.codemodel.member.FieldMember;
13 10
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
14 11
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
15 12
 import org.openzen.zenscript.codemodel.type.ITypeID;
16
-import org.openzen.zenscript.javabytecode.JavaParameterInfo;
13
+import org.openzen.zenscript.javashared.JavaParameterInfo;
17 14
 
18
-import java.io.FileOutputStream;
19
-import java.io.IOException;
20
-import java.util.HashMap;
21
-import java.util.Map;
22
-import org.openzen.zenscript.codemodel.type.FunctionTypeID;
23 15
 import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
24
-import org.openzen.zenscript.javashared.JavaClass;
25
-import org.openzen.zenscript.javashared.JavaSynthesizedClass;
26
-import org.openzen.zenscript.javashared.JavaSynthesizedClassNamer;
27 16
 
28 17
 public class CompilerUtils {
29 18
 	private CompilerUtils() {}
@@ -66,14 +55,10 @@ public class CompilerUtils {
66 55
 		return out;
67 56
 	}
68 57
 
69
-	public static String calcClasName(CodePosition position) {
70
-		return position.getFilename().substring(0, position.getFilename().lastIndexOf('.')).replace("/", "_");
71
-	}
72
-
73 58
     public static void tagMethodParameters(JavaBytecodeContext context, FunctionHeader header, boolean isStatic) {
74 59
         for (int i = 0; i < header.parameters.length; i++) {
75 60
             FunctionParameter parameter = header.parameters[i];
76
-            Type parameterType = context.getType(parameter.type);
61
+            String parameterType = context.getDescriptor(parameter.type);
77 62
             parameter.setTag(JavaParameterInfo.class, new JavaParameterInfo(isStatic ? i : i + 1, parameterType));
78 63
         }
79 64
     }
@@ -81,7 +66,7 @@ public class CompilerUtils {
81 66
     public static void tagConstructorParameters(JavaBytecodeContext context, FunctionHeader header, boolean isEnum) {
82 67
         for (int i = 0; i < header.parameters.length; i++) {
83 68
             FunctionParameter parameter = header.parameters[i];
84
-            Type parameterType = context.getType(parameter.type);
69
+            String parameterType = context.getDescriptor(parameter.type);
85 70
             parameter.setTag(JavaParameterInfo.class, new JavaParameterInfo(isEnum ? i + 3 : i + 1, parameterType));
86 71
         }
87 72
     }
@@ -105,79 +90,7 @@ public class CompilerUtils {
105 90
         }
106 91
     }
107 92
 
108
-	private static final Map<String, JavaSynthesizedClass> functions = new HashMap<>();
109
-	
110
-    public static JavaSynthesizedClass getLambdaInterface(JavaBytecodeContext context, FunctionTypeID function) {
111
-		String signature = JavaSynthesizedClassNamer.getFunctionSignature(function);
112
-		if (functions.containsKey(signature))
113
-			return functions.get(signature).withTypeParameters(JavaSynthesizedClassNamer.extractTypeParameters(function));
114
-		
115
-		System.out.println("Generating function " + signature);
116
-		
117
-		JavaSynthesizedClass result = JavaSynthesizedClassNamer.createFunctionName(function);
118
-		functions.put(signature, result);
119
-		
120
-        createLambdaInterface(context, function.header, result.cls);
121
-        return result;
122
-    }
123
-
124
-    private static void createLambdaInterface(JavaBytecodeContext context, FunctionHeader header, JavaClass cls) {
125
-        ClassWriter ifaceWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
126
-        ifaceWriter.visitAnnotation("java/lang/FunctionalInterface", true).visitEnd();
127
-        ifaceWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT, cls.internalName, null, "java/lang/Object", null);
128
-
129
-        ifaceWriter
130
-				.visitMethod(
131
-					Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT,
132
-					"accept",
133
-					context.getMethodDescriptor(header),
134
-					context.getMethodSignature(header),
135
-					null)
136
-				.visitEnd();
137
-
138
-        context.register(cls.internalName.replace('/', '.'), ifaceWriter.toByteArray());
139
-
140
-        try (FileOutputStream out = new FileOutputStream(cls.getClassName() + ".class")){
141
-            out.write(ifaceWriter.toByteArray());
142
-        } catch (IOException e) {
143
-            e.printStackTrace();
144
-        }
145
-    }
146
-
147
-	private static int lambdaCounter = 0;
148
-    public static String getLambdaCounter() {
149
-        return "lambda" + ++lambdaCounter;
150
-    }
151
-
152 93
 	public static int getKeyForSwitch(SwitchValue expression) {
153
-		return expression.accept(new SwitchKeyVisitor());
154
-	}
155
-
156
-	private static class SwitchKeyVisitor implements SwitchValueVisitor<Integer> {
157
-
158
-		@Override
159
-		public Integer acceptInt(IntSwitchValue value) {
160
-			return value.value;
161
-		}
162
-
163
-		@Override
164
-		public Integer acceptChar(CharSwitchValue value) {
165
-			return (int) value.value;
166
-		}
167
-
168
-		@Override
169
-		public Integer acceptString(StringSwitchValue value) {
170
-			return value.value.hashCode();
171
-		}
172
-
173
-		@Override
174
-		public Integer acceptEnumConstant(EnumConstantSwitchValue value) {
175
-			return value.constant.ordinal;
176
-		}
177
-
178
-		@Override
179
-		public Integer acceptVariantOption(VariantOptionSwitchValue value) {
180
-			return value.option.getOrdinal();
181
-		}
94
+		return expression.accept(JavaSwitchKeyVisitor.INSTANCE);
182 95
 	}
183 96
 }

+ 37
- 30
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaBoxingTypeVisitor.java View File

@@ -1,10 +1,18 @@
1 1
 package org.openzen.zenscript.javabytecode.compiler;
2 2
 
3 3
 import org.openzen.zenscript.codemodel.type.*;
4
-import org.openzen.zenscript.javabytecode.JavaMethodInfo;
5 4
 import org.openzen.zenscript.javashared.JavaClass;
5
+import org.openzen.zenscript.javashared.JavaMethod;
6 6
 
7
-public class JavaBoxingTypeVisitor implements ITypeVisitor<JavaMethodInfo> {
7
+public class JavaBoxingTypeVisitor implements ITypeVisitor<Void> {
8
+	private static final JavaMethod BOOLEAN_VALUEOF = JavaMethod.getNativeStatic(JavaClass.BOOLEAN, "valueOf", "(Z)Ljava/lang/Boolean;");
9
+	private static final JavaMethod BYTE_VALUEOF = JavaMethod.getNativeStatic(JavaClass.BYTE, "valueOf", "(B)Ljava/lang/Byte;");
10
+	private static final JavaMethod SHORT_VALUEOF = JavaMethod.getNativeStatic(JavaClass.SHORT, "valueOf", "(S)Ljava/lang/Short;");
11
+	private static final JavaMethod INTEGER_VALUEOF = JavaMethod.getNativeStatic(JavaClass.INTEGER, "valueOf", "(I)Ljava/lang/Integer;");
12
+	private static final JavaMethod LONG_VALUEOF = JavaMethod.getNativeStatic(JavaClass.LONG, "valueOf", "(J)Ljava/lang/Long;");
13
+	private static final JavaMethod FLOAT_VALUEOF = JavaMethod.getNativeStatic(JavaClass.FLOAT, "valueOf", "(F)Ljava/lang/Float;");
14
+	private static final JavaMethod DOUBLE_VALUEOF = JavaMethod.getNativeStatic(JavaClass.DOUBLE, "valueOf", "(D)Ljava/lang/Double;");
15
+	private static final JavaMethod CHARACTER_VALUEOF = JavaMethod.getNativeStatic(JavaClass.CHARACTER, "valueOf", "(C)Ljava/lang/Character;");
8 16
 
9 17
 	private final JavaWriter writer;
10 18
 
@@ -13,102 +21,101 @@ public class JavaBoxingTypeVisitor implements ITypeVisitor<JavaMethodInfo> {
13 21
 	}
14 22
 
15 23
 	@Override
16
-	public JavaMethodInfo visitBasic(BasicTypeID basic) {
17
-		final JavaMethodInfo info;
24
+	public Void visitBasic(BasicTypeID basic) {
25
+		final JavaMethod method;
18 26
 		switch (basic) {
19 27
 			case BOOL:
20
-				writer.newObject(Boolean.class);
21
-				info = new JavaMethodInfo(new JavaClass("java.lang", "Boolean", JavaClass.Kind.CLASS), "<init>", "(Z)V", -1);
28
+				method = BOOLEAN_VALUEOF;
22 29
 				break;
23 30
 			case BYTE:
31
+				method = INTEGER_VALUEOF;
32
+				break;
24 33
 			case SBYTE:
25
-				writer.newObject(Byte.class);
26
-				info = new JavaMethodInfo(new JavaClass("java.lang", "Byte", JavaClass.Kind.CLASS), "<init>", "(B)V", -1);
34
+				method = BYTE_VALUEOF;
27 35
 				break;
28 36
 			case SHORT:
37
+				method = SHORT_VALUEOF;
38
+				break;
29 39
 			case USHORT:
30
-				writer.newObject(Short.class);
31
-				info = new JavaMethodInfo(new JavaClass("java.lang", "Short", JavaClass.Kind.CLASS), "<init>", "(S)V", -1);
40
+				method = INTEGER_VALUEOF;
32 41
 				break;
33 42
 			case INT:
34 43
 			case UINT:
35
-				writer.newObject(Byte.class);
36
-				info = new JavaMethodInfo(new JavaClass("java.lang", "Byte", JavaClass.Kind.CLASS), "<init>", "(B)V", -1);
44
+				method = INTEGER_VALUEOF;
37 45
 				break;
38 46
 			case LONG:
39 47
 			case ULONG:
40
-				writer.newObject(Long.class);
41
-				info = new JavaMethodInfo(new JavaClass("java.lang", "Long", JavaClass.Kind.CLASS), "<init>", "(S)V", -1);
48
+				method = LONG_VALUEOF;
42 49
 				break;
43 50
 			case FLOAT:
44
-				writer.newObject(Float.class);
45
-				info = new JavaMethodInfo(new JavaClass("java.lang", "Float", JavaClass.Kind.CLASS), "<init>", "(F)V", -1);
51
+				method = FLOAT_VALUEOF;
46 52
 				break;
47 53
 			case DOUBLE:
48
-				writer.newObject(Double.class);
49
-				info = new JavaMethodInfo(new JavaClass("java.lang", "Double", JavaClass.Kind.CLASS), "<init>", "(D)V", -1);
54
+				method = DOUBLE_VALUEOF;
50 55
 				break;
51 56
 			case CHAR:
52
-				writer.newObject(Character.class);
53
-				info = new JavaMethodInfo(new JavaClass("java.lang", "Character", JavaClass.Kind.CLASS), "<init>", "(C)V", -1);
57
+				method = CHARACTER_VALUEOF;
54 58
 				break;
55 59
 			default:
56 60
 				return null;
57 61
 		}
58 62
 		writer.dup();
59
-		return info;
63
+		
64
+		if (method != null)
65
+			writer.invokeStatic(method);
66
+		return null;
60 67
 	}
61 68
 
62 69
 	@Override
63
-	public JavaMethodInfo visitArray(ArrayTypeID array) {
70
+	public Void visitArray(ArrayTypeID array) {
64 71
 		//NO-OP
65 72
 		return null;
66 73
 	}
67 74
 
68 75
 	@Override
69
-	public JavaMethodInfo visitAssoc(AssocTypeID assoc) {
76
+	public Void visitAssoc(AssocTypeID assoc) {
70 77
 		//NO-OP
71 78
 		return null;
72 79
 	}
73 80
 
74 81
 	@Override
75
-	public JavaMethodInfo visitGenericMap(GenericMapTypeID map) {
82
+	public Void visitGenericMap(GenericMapTypeID map) {
76 83
 		//NO-OP
77 84
 		return null;
78 85
 	}
79 86
 
80 87
 	@Override
81
-	public JavaMethodInfo visitIterator(IteratorTypeID iterator) {
88
+	public Void visitIterator(IteratorTypeID iterator) {
82 89
 		//NO-OP
83 90
 		return null;
84 91
 	}
85 92
 
86 93
 	@Override
87
-	public JavaMethodInfo visitFunction(FunctionTypeID function) {
94
+	public Void visitFunction(FunctionTypeID function) {
88 95
 		//NO-OP
89 96
 		return null;
90 97
 	}
91 98
 
92 99
 	@Override
93
-	public JavaMethodInfo visitDefinition(DefinitionTypeID definition) {
100
+	public Void visitDefinition(DefinitionTypeID definition) {
94 101
 		//NO-OP
95 102
 		return null;
96 103
 	}
97 104
 
98 105
 	@Override
99
-	public JavaMethodInfo visitGeneric(GenericTypeID generic) {
106
+	public Void visitGeneric(GenericTypeID generic) {
100 107
 		//NO-OP
101 108
 		return null;
102 109
 	}
103 110
 
104 111
 	@Override
105
-	public JavaMethodInfo visitRange(RangeTypeID range) {
112
+	public Void visitRange(RangeTypeID range) {
106 113
 		//NO-OP
107 114
 		return null;
108 115
 	}
109 116
 
110 117
 	@Override
111
-	public JavaMethodInfo visitModified(ModifiedTypeID type) {
118
+	public Void visitModified(ModifiedTypeID type) {
112 119
 		//NO-OP
113 120
 		return null;
114 121
 	}

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

@@ -1,5 +1,6 @@
1 1
 package org.openzen.zenscript.javabytecode.compiler;
2 2
 
3
+import org.openzen.zenscript.javashared.JavaParameterInfo;
3 4
 import java.util.Arrays;
4 5
 import java.util.Comparator;
5 6
 import java.util.StringJoiner;
@@ -18,134 +19,136 @@ import org.openzen.zenscript.codemodel.member.ref.FieldMemberRef;
18 19
 import org.openzen.zenscript.codemodel.statement.ReturnStatement;
19 20
 import org.openzen.zenscript.codemodel.type.*;
20 21
 import org.openzen.zenscript.codemodel.type.member.BuiltinID;
21
-import org.openzen.zenscript.implementations.IntRange;
22 22
 import org.openzen.zenscript.javabytecode.*;
23 23
 
24 24
 import java.io.FileOutputStream;
25 25
 import java.io.IOException;
26 26
 import org.openzen.zenscript.javashared.JavaClass;
27 27
 import org.openzen.zenscript.javashared.JavaField;
28
+import org.openzen.zenscript.javashared.JavaMethod;
29
+import org.openzen.zenscript.javashared.JavaSynthesizedClass;
28 30
 import org.openzen.zenscript.javashared.JavaSynthesizedClassNamer;
31
+import org.openzen.zenscript.javashared.JavaVariantOption;
29 32
 
30 33
 public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
31 34
 	private static final int PUBLIC = Opcodes.ACC_PUBLIC;
32 35
 	private static final int STATIC = Opcodes.ACC_STATIC;
33 36
 	private static final int PUBLIC_STATIC = PUBLIC | STATIC;
34 37
 
35
-	private static final JavaMethodInfo BOOLEAN_PARSE = new JavaMethodInfo(JavaClass.BOOLEAN, "parseBoolean", "(Ljava/lang/String;)Z", PUBLIC_STATIC);
36
-	private static final JavaMethodInfo BOOLEAN_TO_STRING = new JavaMethodInfo(JavaClass.BOOLEAN, "toString", "(Z)Ljava/lang/String;", PUBLIC_STATIC);
37
-	private static final JavaMethodInfo BYTE_PARSE = new JavaMethodInfo(JavaClass.BYTE, "parseByte", "(Ljava/lang/String;)B", PUBLIC_STATIC);
38
-	private static final JavaMethodInfo BYTE_PARSE_WITH_BASE = new JavaMethodInfo(JavaClass.BYTE, "parseByte", "(Ljava/lang/String;I)B", PUBLIC_STATIC);
38
+	private static final JavaMethod BOOLEAN_PARSE = JavaMethod.getNativeStatic(JavaClass.BOOLEAN, "parseBoolean", "(Ljava/lang/String;)Z");
39
+	private static final JavaMethod BOOLEAN_TO_STRING = JavaMethod.getNativeStatic(JavaClass.BOOLEAN, "toString", "(Z)Ljava/lang/String;");
40
+	private static final JavaMethod BYTE_PARSE = JavaMethod.getNativeStatic(JavaClass.BYTE, "parseByte", "(Ljava/lang/String;)B");
41
+	private static final JavaMethod BYTE_PARSE_WITH_BASE = JavaMethod.getNativeStatic(JavaClass.BYTE, "parseByte", "(Ljava/lang/String;I)B");
39 42
 	private static final JavaField BYTE_MIN_VALUE = new JavaField(JavaClass.BYTE, "MIN_VALUE", "B");
40 43
 	private static final JavaField BYTE_MAX_VALUE = new JavaField(JavaClass.BYTE, "MAX_VALUE", "B");
41
-	private static final JavaMethodInfo BYTE_TO_STRING = new JavaMethodInfo(JavaClass.BYTE, "toString", "(B)Ljava/lang/String;", PUBLIC_STATIC);
42
-	private static final JavaMethodInfo SHORT_PARSE = new JavaMethodInfo(JavaClass.SHORT, "parseShort", "(Ljava/lang/String;)S", PUBLIC_STATIC);
43
-	private static final JavaMethodInfo SHORT_PARSE_WITH_BASE = new JavaMethodInfo(JavaClass.SHORT, "parseShort", "(Ljava/lang/String;I)S", PUBLIC_STATIC);
44
+	private static final JavaMethod BYTE_TO_STRING = JavaMethod.getNativeStatic(JavaClass.BYTE, "toString", "(B)Ljava/lang/String;");
45
+	private static final JavaMethod SHORT_PARSE = JavaMethod.getNativeStatic(JavaClass.SHORT, "parseShort", "(Ljava/lang/String;)S");
46
+	private static final JavaMethod SHORT_PARSE_WITH_BASE = JavaMethod.getNativeStatic(JavaClass.SHORT, "parseShort", "(Ljava/lang/String;I)S");
44 47
 	private static final JavaField SHORT_MIN_VALUE = new JavaField(JavaClass.SHORT, "MIN_VALUE", "S");
45 48
 	private static final JavaField SHORT_MAX_VALUE = new JavaField(JavaClass.SHORT, "MAX_VALUE", "S");
46
-	private static final JavaMethodInfo SHORT_TO_STRING = new JavaMethodInfo(JavaClass.SHORT, "toString", "(S)Ljava/lang/String;", PUBLIC_STATIC);
47
-	private static final JavaMethodInfo INTEGER_COMPARE_UNSIGNED = new JavaMethodInfo(JavaClass.INTEGER, "compareUnsigned", "(II)I", PUBLIC_STATIC);
48
-	private static final JavaMethodInfo INTEGER_DIVIDE_UNSIGNED = new JavaMethodInfo(JavaClass.INTEGER, "divideUnsigned", "(II)I", PUBLIC_STATIC);
49
-	private static final JavaMethodInfo INTEGER_REMAINDER_UNSIGNED = new JavaMethodInfo(JavaClass.INTEGER, "remainderUnsigned", "(II)I", PUBLIC_STATIC);
50
-	private static final JavaMethodInfo INTEGER_NUMBER_OF_TRAILING_ZEROS = new JavaMethodInfo(JavaClass.INTEGER, "numberOfTrailingZeros", "(I)I", PUBLIC_STATIC);
51
-	private static final JavaMethodInfo INTEGER_NUMBER_OF_LEADING_ZEROS = new JavaMethodInfo(JavaClass.INTEGER, "numberOfLeadingZeros", "(I)I", PUBLIC_STATIC);
52
-	private static final JavaMethodInfo INTEGER_PARSE = new JavaMethodInfo(JavaClass.INTEGER, "parseInt", "(Ljava/lang/String;)I", PUBLIC_STATIC);
53
-	private static final JavaMethodInfo INTEGER_PARSE_WITH_BASE = new JavaMethodInfo(JavaClass.INTEGER, "parseInt", "(Ljava/lang/String;I)I", PUBLIC_STATIC);
54
-	private static final JavaMethodInfo INTEGER_PARSE_UNSIGNED = new JavaMethodInfo(JavaClass.INTEGER, "parseUnsignedInt", "(Ljava/lang/String;)I", PUBLIC_STATIC);
55
-	private static final JavaMethodInfo INTEGER_PARSE_UNSIGNED_WITH_BASE = new JavaMethodInfo(JavaClass.INTEGER, "parseUnsignedInt", "(Ljava/lang/String;I)I", PUBLIC_STATIC);
56
-	private static final JavaMethodInfo INTEGER_HIGHEST_ONE_BIT = new JavaMethodInfo(JavaClass.INTEGER, "highestOneBit", "(I)I", PUBLIC_STATIC);
57
-	private static final JavaMethodInfo INTEGER_LOWEST_ONE_BIT = new JavaMethodInfo(JavaClass.INTEGER, "lowestOneBit", "(I)I", PUBLIC_STATIC);
58
-	private static final JavaMethodInfo INTEGER_BIT_COUNT = new JavaMethodInfo(JavaClass.INTEGER, "bitCount", "(I)I", PUBLIC_STATIC);
49
+	private static final JavaMethod SHORT_TO_STRING = JavaMethod.getNativeStatic(JavaClass.SHORT, "toString", "(S)Ljava/lang/String;");
50
+	private static final JavaMethod INTEGER_COMPARE_UNSIGNED = JavaMethod.getNativeStatic(JavaClass.INTEGER, "compareUnsigned", "(II)I");
51
+	private static final JavaMethod INTEGER_DIVIDE_UNSIGNED = JavaMethod.getNativeStatic(JavaClass.INTEGER, "divideUnsigned", "(II)I");
52
+	private static final JavaMethod INTEGER_REMAINDER_UNSIGNED = JavaMethod.getNativeStatic(JavaClass.INTEGER, "remainderUnsigned", "(II)I");
53
+	private static final JavaMethod INTEGER_NUMBER_OF_TRAILING_ZEROS = JavaMethod.getNativeStatic(JavaClass.INTEGER, "numberOfTrailingZeros", "(I)I");
54
+	private static final JavaMethod INTEGER_NUMBER_OF_LEADING_ZEROS = JavaMethod.getNativeStatic(JavaClass.INTEGER, "numberOfLeadingZeros", "(I)I");
55
+	private static final JavaMethod INTEGER_PARSE = JavaMethod.getNativeStatic(JavaClass.INTEGER, "parseInt", "(Ljava/lang/String;)I");
56
+	private static final JavaMethod INTEGER_PARSE_WITH_BASE = JavaMethod.getNativeStatic(JavaClass.INTEGER, "parseInt", "(Ljava/lang/String;I)I");
57
+	private static final JavaMethod INTEGER_PARSE_UNSIGNED = JavaMethod.getNativeStatic(JavaClass.INTEGER, "parseUnsignedInt", "(Ljava/lang/String;)I");
58
+	private static final JavaMethod INTEGER_PARSE_UNSIGNED_WITH_BASE = JavaMethod.getNativeStatic(JavaClass.INTEGER, "parseUnsignedInt", "(Ljava/lang/String;I)I");
59
+	private static final JavaMethod INTEGER_HIGHEST_ONE_BIT = JavaMethod.getNativeStatic(JavaClass.INTEGER, "highestOneBit", "(I)I");
60
+	private static final JavaMethod INTEGER_LOWEST_ONE_BIT = JavaMethod.getNativeStatic(JavaClass.INTEGER, "lowestOneBit", "(I)I");
61
+	private static final JavaMethod INTEGER_BIT_COUNT = JavaMethod.getNativeStatic(JavaClass.INTEGER, "bitCount", "(I)I");
59 62
 	private static final JavaField INTEGER_MIN_VALUE = new JavaField(JavaClass.INTEGER, "MIN_VALUE", "I");
60 63
 	private static final JavaField INTEGER_MAX_VALUE = new JavaField(JavaClass.INTEGER, "MAX_VALUE", "I");
61
-	private static final JavaMethodInfo INTEGER_TO_STRING = new JavaMethodInfo(JavaClass.INTEGER, "toString", "(I)Ljava/lang/String;", PUBLIC_STATIC);
62
-	private static final JavaMethodInfo INTEGER_TO_UNSIGNED_STRING = new JavaMethodInfo(JavaClass.INTEGER, "toUnsignedString", "(I)Ljava/lang/String;", PUBLIC_STATIC);
63
-	private static final JavaMethodInfo LONG_COMPARE = new JavaMethodInfo(JavaClass.LONG, "compare", "(JJ)I", PUBLIC_STATIC);
64
-	private static final JavaMethodInfo LONG_COMPARE_UNSIGNED = new JavaMethodInfo(JavaClass.LONG, "compareUnsigned", "(JJ)I", PUBLIC_STATIC);
65
-	private static final JavaMethodInfo LONG_DIVIDE_UNSIGNED = new JavaMethodInfo(JavaClass.LONG, "divideUnsigned", "(JJ)J", PUBLIC_STATIC);
66
-	private static final JavaMethodInfo LONG_REMAINDER_UNSIGNED = new JavaMethodInfo(JavaClass.LONG, "remainderUnsigned", "(JJ)J", PUBLIC_STATIC);
67
-	private static final JavaMethodInfo LONG_NUMBER_OF_TRAILING_ZEROS = new JavaMethodInfo(JavaClass.LONG, "numberOfTrailingZeros", "(J)I", PUBLIC_STATIC);
68
-	private static final JavaMethodInfo LONG_NUMBER_OF_LEADING_ZEROS = new JavaMethodInfo(JavaClass.LONG, "numberOfLeadingZeros", "(J)I", PUBLIC_STATIC);
69
-	private static final JavaMethodInfo LONG_PARSE = new JavaMethodInfo(JavaClass.LONG, "parseLong", "(Ljava/lang/String;)J", PUBLIC_STATIC);
70
-	private static final JavaMethodInfo LONG_PARSE_WITH_BASE = new JavaMethodInfo(JavaClass.LONG, "parseLong", "(Ljava/lang/String;I)J", PUBLIC_STATIC);
71
-	private static final JavaMethodInfo LONG_PARSE_UNSIGNED = new JavaMethodInfo(JavaClass.LONG, "parseUnsignedLong", "(Ljava/lang/String;)J", PUBLIC_STATIC);
72
-	private static final JavaMethodInfo LONG_PARSE_UNSIGNED_WITH_BASE = new JavaMethodInfo(JavaClass.LONG, "parseUnsignedLong", "(Ljava/lang/String;I)J", PUBLIC_STATIC);
73
-	private static final JavaMethodInfo LONG_HIGHEST_ONE_BIT = new JavaMethodInfo(JavaClass.LONG, "highestOneBit", "(J)J", PUBLIC_STATIC);
74
-	private static final JavaMethodInfo LONG_LOWEST_ONE_BIT = new JavaMethodInfo(JavaClass.LONG, "lowestOneBit", "(J)J", PUBLIC_STATIC);
75
-	private static final JavaMethodInfo LONG_BIT_COUNT = new JavaMethodInfo(JavaClass.LONG, "bitCount", "(J)I", PUBLIC_STATIC);
64
+	private static final JavaMethod INTEGER_TO_STRING = JavaMethod.getNativeStatic(JavaClass.INTEGER, "toString", "(I)Ljava/lang/String;");
65
+	private static final JavaMethod INTEGER_TO_UNSIGNED_STRING = JavaMethod.getNativeStatic(JavaClass.INTEGER, "toUnsignedString", "(I)Ljava/lang/String;");
66
+	private static final JavaMethod LONG_COMPARE = JavaMethod.getNativeStatic(JavaClass.LONG, "compare", "(JJ)I");
67
+	private static final JavaMethod LONG_COMPARE_UNSIGNED = JavaMethod.getNativeStatic(JavaClass.LONG, "compareUnsigned", "(JJ)I");
68
+	private static final JavaMethod LONG_DIVIDE_UNSIGNED = JavaMethod.getNativeStatic(JavaClass.LONG, "divideUnsigned", "(JJ)J");
69
+	private static final JavaMethod LONG_REMAINDER_UNSIGNED = JavaMethod.getNativeStatic(JavaClass.LONG, "remainderUnsigned", "(JJ)J");
70
+	private static final JavaMethod LONG_NUMBER_OF_TRAILING_ZEROS = JavaMethod.getNativeStatic(JavaClass.LONG, "numberOfTrailingZeros", "(J)I");
71
+	private static final JavaMethod LONG_NUMBER_OF_LEADING_ZEROS = JavaMethod.getNativeStatic(JavaClass.LONG, "numberOfLeadingZeros", "(J)I");
72
+	private static final JavaMethod LONG_PARSE = JavaMethod.getNativeStatic(JavaClass.LONG, "parseLong", "(Ljava/lang/String;)J");
73
+	private static final JavaMethod LONG_PARSE_WITH_BASE = JavaMethod.getNativeStatic(JavaClass.LONG, "parseLong", "(Ljava/lang/String;I)J");
74
+	private static final JavaMethod LONG_PARSE_UNSIGNED = JavaMethod.getNativeStatic(JavaClass.LONG, "parseUnsignedLong", "(Ljava/lang/String;)J");
75
+	private static final JavaMethod LONG_PARSE_UNSIGNED_WITH_BASE = JavaMethod.getNativeStatic(JavaClass.LONG, "parseUnsignedLong", "(Ljava/lang/String;I)J");
76
+	private static final JavaMethod LONG_HIGHEST_ONE_BIT = JavaMethod.getNativeStatic(JavaClass.LONG, "highestOneBit", "(J)J");
77
+	private static final JavaMethod LONG_LOWEST_ONE_BIT = JavaMethod.getNativeStatic(JavaClass.LONG, "lowestOneBit", "(J)J");
78
+	private static final JavaMethod LONG_BIT_COUNT = JavaMethod.getNativeStatic(JavaClass.LONG, "bitCount", "(J)I");
76 79
 	private static final JavaField LONG_MIN_VALUE = new JavaField(JavaClass.LONG, "MIN_VALUE", "J");
77 80
 	private static final JavaField LONG_MAX_VALUE = new JavaField(JavaClass.LONG, "MAX_VALUE", "J");
78
-	private static final JavaMethodInfo LONG_TO_STRING = new JavaMethodInfo(JavaClass.LONG, "toString", "(J)Ljava/lang/String;", PUBLIC_STATIC);
79
-	private static final JavaMethodInfo LONG_TO_UNSIGNED_STRING = new JavaMethodInfo(JavaClass.LONG, "toUnsignedString", "(J)Ljava/lang/String;", PUBLIC_STATIC);
80
-	private static final JavaMethodInfo FLOAT_COMPARE = new JavaMethodInfo(JavaClass.FLOAT, "compare", "(FF)I", PUBLIC_STATIC);
81
-	private static final JavaMethodInfo FLOAT_PARSE = new JavaMethodInfo(JavaClass.FLOAT, "parseFloat", "(Ljava/lang/String;)F", PUBLIC_STATIC);
82
-	private static final JavaMethodInfo FLOAT_FROM_BITS = new JavaMethodInfo(JavaClass.FLOAT, "intBitsToFloat", "(I)F", PUBLIC_STATIC);
83
-	private static final JavaMethodInfo FLOAT_BITS = new JavaMethodInfo(JavaClass.FLOAT, "floatToRawIntBits", "(F)I", PUBLIC_STATIC);
81
+	private static final JavaMethod LONG_TO_STRING = JavaMethod.getNativeStatic(JavaClass.LONG, "toString", "(J)Ljava/lang/String;");
82
+	private static final JavaMethod LONG_TO_UNSIGNED_STRING = JavaMethod.getNativeStatic(JavaClass.LONG, "toUnsignedString", "(J)Ljava/lang/String;");
83
+	private static final JavaMethod FLOAT_COMPARE = JavaMethod.getNativeStatic(JavaClass.FLOAT, "compare", "(FF)I");
84
+	private static final JavaMethod FLOAT_PARSE = JavaMethod.getNativeStatic(JavaClass.FLOAT, "parseFloat", "(Ljava/lang/String;)F");
85
+	private static final JavaMethod FLOAT_FROM_BITS = JavaMethod.getNativeStatic(JavaClass.FLOAT, "intBitsToFloat", "(I)F");
86
+	private static final JavaMethod FLOAT_BITS = JavaMethod.getNativeStatic(JavaClass.FLOAT, "floatToRawIntBits", "(F)I");
84 87
 	private static final JavaField FLOAT_MIN_VALUE = new JavaField(JavaClass.FLOAT, "MIN_VALUE", "F");
85 88
 	private static final JavaField FLOAT_MAX_VALUE = new JavaField(JavaClass.FLOAT, "MAX_VALUE", "F");
86
-	private static final JavaMethodInfo FLOAT_TO_STRING = new JavaMethodInfo(JavaClass.FLOAT, "toString", "(F)Ljava/lang/String;", PUBLIC_STATIC);
87
-	private static final JavaMethodInfo DOUBLE_COMPARE = new JavaMethodInfo(JavaClass.DOUBLE, "compare", "(DD)I", PUBLIC_STATIC);
88
-	private static final JavaMethodInfo DOUBLE_PARSE = new JavaMethodInfo(JavaClass.DOUBLE, "parseDouble", "(Ljava/lang/String;)D", PUBLIC_STATIC);
89
-	private static final JavaMethodInfo DOUBLE_FROM_BITS = new JavaMethodInfo(JavaClass.DOUBLE, "longBitsToDouble", "(J)D", PUBLIC_STATIC);
90
-	private static final JavaMethodInfo DOUBLE_BITS = new JavaMethodInfo(JavaClass.DOUBLE, "doubleToRawLongBits", "(D)J", PUBLIC_STATIC);
89
+	private static final JavaMethod FLOAT_TO_STRING = JavaMethod.getNativeStatic(JavaClass.FLOAT, "toString", "(F)Ljava/lang/String;");
90
+	private static final JavaMethod DOUBLE_COMPARE = JavaMethod.getNativeStatic(JavaClass.DOUBLE, "compare", "(DD)I");
91
+	private static final JavaMethod DOUBLE_PARSE = JavaMethod.getNativeStatic(JavaClass.DOUBLE, "parseDouble", "(Ljava/lang/String;)D");
92
+	private static final JavaMethod DOUBLE_FROM_BITS = JavaMethod.getNativeStatic(JavaClass.DOUBLE, "longBitsToDouble", "(J)D");
93
+	private static final JavaMethod DOUBLE_BITS = JavaMethod.getNativeStatic(JavaClass.DOUBLE, "doubleToRawLongBits", "(D)J");
91 94
 	private static final JavaField DOUBLE_MIN_VALUE = new JavaField(JavaClass.DOUBLE, "MIN_VALUE", "D");
92 95
 	private static final JavaField DOUBLE_MAX_VALUE = new JavaField(JavaClass.DOUBLE, "MAX_VALUE", "D");
93
-	private static final JavaMethodInfo DOUBLE_TO_STRING = new JavaMethodInfo(JavaClass.DOUBLE, "toString", "(D)Ljava/lang/String;", PUBLIC_STATIC);
94
-	private static final JavaMethodInfo CHARACTER_TO_LOWER_CASE = new JavaMethodInfo(JavaClass.CHARACTER, "toLowerCase", "()C", PUBLIC);
95
-	private static final JavaMethodInfo CHARACTER_TO_UPPER_CASE = new JavaMethodInfo(JavaClass.CHARACTER, "toUpperCase", "()C", PUBLIC);
96
+	private static final JavaMethod DOUBLE_TO_STRING = JavaMethod.getNativeStatic(JavaClass.DOUBLE, "toString", "(D)Ljava/lang/String;");
97
+	private static final JavaMethod CHARACTER_TO_LOWER_CASE = JavaMethod.getNativeVirtual(JavaClass.CHARACTER, "toLowerCase", "()C");
98
+	private static final JavaMethod CHARACTER_TO_UPPER_CASE = JavaMethod.getNativeVirtual(JavaClass.CHARACTER, "toUpperCase", "()C");
96 99
 	private static final JavaField CHARACTER_MIN_VALUE = new JavaField(JavaClass.CHARACTER, "MIN_VALUE", "C");
97 100
 	private static final JavaField CHARACTER_MAX_VALUE = new JavaField(JavaClass.CHARACTER, "MAX_VALUE", "C");
98
-	private static final JavaMethodInfo CHARACTER_TO_STRING = new JavaMethodInfo(JavaClass.CHARACTER, "toString", "(C)Ljava/lang/String;", PUBLIC_STATIC);
99
-	private static final JavaMethodInfo STRING_COMPARETO = new JavaMethodInfo(JavaClass.STRING, "compareTo", "(Ljava/lang/String;)I", PUBLIC);
100
-	private static final JavaMethodInfo STRING_CONCAT = new JavaMethodInfo(JavaClass.STRING, "concat", "(Ljava/lang/String;)Ljava/lang/String;", PUBLIC);
101
-	private static final JavaMethodInfo STRING_CHAR_AT = new JavaMethodInfo(JavaClass.STRING, "charAt", "(I)C", PUBLIC);
102
-	private static final JavaMethodInfo STRING_SUBSTRING = new JavaMethodInfo(JavaClass.STRING, "substring", "(II)Ljava/lang/String;", PUBLIC);
103
-	private static final JavaMethodInfo STRING_TRIM = new JavaMethodInfo(JavaClass.STRING, "trim", "()Ljava/lang/String;", PUBLIC);
104
-	private static final JavaMethodInfo STRING_TO_LOWER_CASE = new JavaMethodInfo(JavaClass.STRING, "toLowerCase", "()Ljava/lang/String;", PUBLIC);
105
-	private static final JavaMethodInfo STRING_TO_UPPER_CASE = new JavaMethodInfo(JavaClass.STRING, "toUpperCase", "()Ljava/lang/String;", PUBLIC);
106
-	private static final JavaMethodInfo STRING_LENGTH = new JavaMethodInfo(JavaClass.STRING, "length", "()I", PUBLIC);
107
-	private static final JavaMethodInfo STRING_CHARACTERS = new JavaMethodInfo(JavaClass.STRING, "toCharArray", "()[C", PUBLIC);
108
-	private static final JavaMethodInfo STRING_ISEMPTY = new JavaMethodInfo(JavaClass.STRING, "isEmpty", "()Z", PUBLIC);
109
-	private static final JavaMethodInfo ENUM_COMPARETO = new JavaMethodInfo(JavaClass.ENUM, "compareTo", "(Ljava/lang/Enum;)I", PUBLIC);
110
-	private static final JavaMethodInfo ENUM_NAME = new JavaMethodInfo(JavaClass.ENUM, "name", "()Ljava/lang/String;", PUBLIC);
111
-	private static final JavaMethodInfo ENUM_ORDINAL = new JavaMethodInfo(JavaClass.ENUM, "ordinal", "()I", PUBLIC);
112
-	private static final JavaMethodInfo MAP_GET = new JavaMethodInfo(JavaClass.MAP, "get", "(Ljava/lang/Object;)Ljava/lang/Object;", PUBLIC);
113
-	private static final JavaMethodInfo MAP_PUT = new JavaMethodInfo(JavaClass.MAP, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", PUBLIC);
114
-	private static final JavaMethodInfo MAP_CONTAINS_KEY = new JavaMethodInfo(JavaClass.MAP, "containsKey", "(Ljava/lang/Object;)Z", PUBLIC);
115
-	private static final JavaMethodInfo MAP_SIZE = new JavaMethodInfo(JavaClass.MAP, "size", "()I", PUBLIC);
116
-	private static final JavaMethodInfo MAP_ISEMPTY = new JavaMethodInfo(JavaClass.MAP, "isEmpty", "()Z", PUBLIC);
117
-	private static final JavaMethodInfo MAP_KEYS = new JavaMethodInfo(JavaClass.MAP, "keys", "()Ljava/lang/Object;", PUBLIC);
118
-	private static final JavaMethodInfo MAP_VALUES = new JavaMethodInfo(JavaClass.MAP, "values", "()Ljava/lang/Object;", PUBLIC);
119
-	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_OBJECTS = new JavaMethodInfo(JavaClass.ARRAYS, "copyOfRange", "([Ljava/lang/Object;II)[Ljava/lang/Object;", PUBLIC_STATIC);
120
-	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_BOOLS = new JavaMethodInfo(JavaClass.ARRAYS, "copyOfRange", "([ZII)[Z", PUBLIC_STATIC);
121
-	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_BYTES = new JavaMethodInfo(JavaClass.ARRAYS, "copyOfRange", "([BII)[B", PUBLIC_STATIC);
122
-	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_SHORTS = new JavaMethodInfo(JavaClass.ARRAYS, "copyOfRange", "([SII)[S", PUBLIC_STATIC);
123
-	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_INTS = new JavaMethodInfo(JavaClass.ARRAYS, "copyOfRange", "([III)[I", PUBLIC_STATIC);
124
-	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_LONGS = new JavaMethodInfo(JavaClass.ARRAYS, "copyOfRange", "([JII)[J", PUBLIC_STATIC);
125
-	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_FLOATS = new JavaMethodInfo(JavaClass.ARRAYS, "copyOfRange", "([FII)[F", PUBLIC_STATIC);
126
-	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_DOUBLES = new JavaMethodInfo(JavaClass.ARRAYS, "copyOfRange", "([DII)[D", PUBLIC_STATIC);
127
-	private static final JavaMethodInfo ARRAYS_COPY_OF_RANGE_CHARS = new JavaMethodInfo(JavaClass.ARRAYS, "copyOfRange", "([CII)[C", PUBLIC_STATIC);
128
-	private static final JavaMethodInfo ARRAYS_EQUALS_OBJECTS = new JavaMethodInfo(JavaClass.ARRAYS, "equals", "([Ljava/lang/Object[Ljava/lang/Object)Z", PUBLIC_STATIC);
129
-	private static final JavaMethodInfo ARRAYS_EQUALS_BOOLS = new JavaMethodInfo(JavaClass.ARRAYS, "equals", "([Z[Z)Z", PUBLIC_STATIC);
130
-	private static final JavaMethodInfo ARRAYS_EQUALS_BYTES = new JavaMethodInfo(JavaClass.ARRAYS, "equals", "([B[B)Z", PUBLIC_STATIC);
131
-	private static final JavaMethodInfo ARRAYS_EQUALS_SHORTS = new JavaMethodInfo(JavaClass.ARRAYS, "equals", "([S[S)Z", PUBLIC_STATIC);
132
-	private static final JavaMethodInfo ARRAYS_EQUALS_INTS = new JavaMethodInfo(JavaClass.ARRAYS, "equals", "([I[I)Z", PUBLIC_STATIC);
133
-	private static final JavaMethodInfo ARRAYS_EQUALS_LONGS = new JavaMethodInfo(JavaClass.ARRAYS, "equals", "([L[L)Z", PUBLIC_STATIC);
134
-	private static final JavaMethodInfo ARRAYS_EQUALS_FLOATS = new JavaMethodInfo(JavaClass.ARRAYS, "equals", "([F[F)Z", PUBLIC_STATIC);
135
-	private static final JavaMethodInfo ARRAYS_EQUALS_DOUBLES = new JavaMethodInfo(JavaClass.ARRAYS, "equals", "([D[D)Z", PUBLIC_STATIC);
136
-	private static final JavaMethodInfo ARRAYS_EQUALS_CHARS = new JavaMethodInfo(JavaClass.ARRAYS, "equals", "([C[C)Z", PUBLIC_STATIC);
137
-	private static final JavaMethodInfo ARRAYS_DEEPHASHCODE = new JavaMethodInfo(JavaClass.ARRAYS, "deepHashCode", "([Ljava/lang/Object;)", PUBLIC_STATIC);
138
-	private static final JavaMethodInfo ARRAYS_HASHCODE_BOOLS = new JavaMethodInfo(JavaClass.ARRAYS, "hashCode", "([Z)I", PUBLIC_STATIC);
139
-	private static final JavaMethodInfo ARRAYS_HASHCODE_BYTES = new JavaMethodInfo(JavaClass.ARRAYS, "hashCode", "([B)I", PUBLIC_STATIC);
140
-	private static final JavaMethodInfo ARRAYS_HASHCODE_SHORTS = new JavaMethodInfo(JavaClass.ARRAYS, "hashCode", "([S)I", PUBLIC_STATIC);
141
-	private static final JavaMethodInfo ARRAYS_HASHCODE_INTS = new JavaMethodInfo(JavaClass.ARRAYS, "hashCode", "([I)I", PUBLIC_STATIC);
142
-	private static final JavaMethodInfo ARRAYS_HASHCODE_LONGS = new JavaMethodInfo(JavaClass.ARRAYS, "hashCode", "([L)I", PUBLIC_STATIC);
143
-	private static final JavaMethodInfo ARRAYS_HASHCODE_FLOATS = new JavaMethodInfo(JavaClass.ARRAYS, "hashCode", "([F)I", PUBLIC_STATIC);
144
-	private static final JavaMethodInfo ARRAYS_HASHCODE_DOUBLES = new JavaMethodInfo(JavaClass.ARRAYS, "hashCode", "([D)I", PUBLIC_STATIC);
145
-	private static final JavaMethodInfo ARRAYS_HASHCODE_CHARS = new JavaMethodInfo(JavaClass.ARRAYS, "hashCode", "([C)I", PUBLIC_STATIC);
146
-	private static final JavaMethodInfo OBJECT_HASHCODE = new JavaMethodInfo(JavaClass.OBJECT, "hashCode", "()I", PUBLIC);
147
-	private static final JavaMethodInfo COLLECTION_SIZE = new JavaMethodInfo(JavaClass.COLLECTION, "size", "()I", PUBLIC);
148
-	private static final JavaMethodInfo COLLECTION_TOARRAY = new JavaMethodInfo(JavaClass.COLLECTION, "toArray", "([Ljava/lang/Object;)[Ljava/lang/Object;", PUBLIC);
101
+	private static final JavaMethod CHARACTER_TO_STRING = JavaMethod.getNativeStatic(JavaClass.CHARACTER, "toString", "(C)Ljava/lang/String;");
102
+	private static final JavaMethod STRING_COMPARETO = JavaMethod.getNativeVirtual(JavaClass.STRING, "compareTo", "(Ljava/lang/String;)I");
103
+	private static final JavaMethod STRING_CONCAT = JavaMethod.getNativeVirtual(JavaClass.STRING, "concat", "(Ljava/lang/String;)Ljava/lang/String;");
104
+	private static final JavaMethod STRING_CHAR_AT = JavaMethod.getNativeVirtual(JavaClass.STRING, "charAt", "(I)C");
105
+	private static final JavaMethod STRING_SUBSTRING = JavaMethod.getNativeVirtual(JavaClass.STRING, "substring", "(II)Ljava/lang/String;");
106
+	private static final JavaMethod STRING_TRIM = JavaMethod.getNativeVirtual(JavaClass.STRING, "trim", "()Ljava/lang/String;");
107
+	private static final JavaMethod STRING_TO_LOWER_CASE = JavaMethod.getNativeVirtual(JavaClass.STRING, "toLowerCase", "()Ljava/lang/String;");
108
+	private static final JavaMethod STRING_TO_UPPER_CASE = JavaMethod.getNativeVirtual(JavaClass.STRING, "toUpperCase", "()Ljava/lang/String;");
109
+	private static final JavaMethod STRING_LENGTH = JavaMethod.getNativeVirtual(JavaClass.STRING, "length", "()I");
110
+	private static final JavaMethod STRING_CHARACTERS = JavaMethod.getNativeVirtual(JavaClass.STRING, "toCharArray", "()[C");
111
+	private static final JavaMethod STRING_ISEMPTY = JavaMethod.getNativeVirtual(JavaClass.STRING, "isEmpty", "()Z");
112
+	private static final JavaMethod ENUM_COMPARETO = JavaMethod.getNativeVirtual(JavaClass.ENUM, "compareTo", "(Ljava/lang/Enum;)I");
113
+	private static final JavaMethod ENUM_NAME = JavaMethod.getNativeVirtual(JavaClass.ENUM, "name", "()Ljava/lang/String;");
114
+	private static final JavaMethod ENUM_ORDINAL = JavaMethod.getNativeVirtual(JavaClass.ENUM, "ordinal", "()I");
115
+	private static final JavaMethod MAP_GET = JavaMethod.getNativeVirtual(JavaClass.MAP, "get", "(Ljava/lang/Object;)Ljava/lang/Object;");
116
+	private static final JavaMethod MAP_PUT = JavaMethod.getNativeVirtual(JavaClass.MAP, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
117
+	private static final JavaMethod MAP_CONTAINS_KEY = JavaMethod.getNativeVirtual(JavaClass.MAP, "containsKey", "(Ljava/lang/Object;)Z");
118
+	private static final JavaMethod MAP_SIZE = JavaMethod.getNativeVirtual(JavaClass.MAP, "size", "()I");
119
+	private static final JavaMethod MAP_ISEMPTY = JavaMethod.getNativeVirtual(JavaClass.MAP, "isEmpty", "()Z");
120
+	private static final JavaMethod MAP_KEYS = JavaMethod.getNativeVirtual(JavaClass.MAP, "keys", "()Ljava/lang/Object;");
121
+	private static final JavaMethod MAP_VALUES = JavaMethod.getNativeVirtual(JavaClass.MAP, "values", "()Ljava/lang/Object;");
122
+	private static final JavaMethod ARRAYS_COPY_OF_RANGE_OBJECTS = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "copyOfRange", "([Ljava/lang/Object;II)[Ljava/lang/Object;");
123
+	private static final JavaMethod ARRAYS_COPY_OF_RANGE_BOOLS = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "copyOfRange", "([ZII)[Z");
124
+	private static final JavaMethod ARRAYS_COPY_OF_RANGE_BYTES = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "copyOfRange", "([BII)[B");
125
+	private static final JavaMethod ARRAYS_COPY_OF_RANGE_SHORTS = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "copyOfRange", "([SII)[S");
126
+	private static final JavaMethod ARRAYS_COPY_OF_RANGE_INTS = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "copyOfRange", "([III)[I");
127
+	private static final JavaMethod ARRAYS_COPY_OF_RANGE_LONGS = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "copyOfRange", "([JII)[J");
128
+	private static final JavaMethod ARRAYS_COPY_OF_RANGE_FLOATS = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "copyOfRange", "([FII)[F");
129
+	private static final JavaMethod ARRAYS_COPY_OF_RANGE_DOUBLES = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "copyOfRange", "([DII)[D");
130
+	private static final JavaMethod ARRAYS_COPY_OF_RANGE_CHARS = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "copyOfRange", "([CII)[C");
131
+	private static final JavaMethod ARRAYS_EQUALS_OBJECTS = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "equals", "([Ljava/lang/Object[Ljava/lang/Object)Z");
132
+	private static final JavaMethod ARRAYS_EQUALS_BOOLS = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "equals", "([Z[Z)Z");
133
+	private static final JavaMethod ARRAYS_EQUALS_BYTES = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "equals", "([B[B)Z");
134
+	private static final JavaMethod ARRAYS_EQUALS_SHORTS = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "equals", "([S[S)Z");
135
+	private static final JavaMethod ARRAYS_EQUALS_INTS = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "equals", "([I[I)Z");
136
+	private static final JavaMethod ARRAYS_EQUALS_LONGS = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "equals", "([L[L)Z");
137
+	private static final JavaMethod ARRAYS_EQUALS_FLOATS = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "equals", "([F[F)Z");
138
+	private static final JavaMethod ARRAYS_EQUALS_DOUBLES = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "equals", "([D[D)Z");
139
+	private static final JavaMethod ARRAYS_EQUALS_CHARS = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "equals", "([C[C)Z");
140
+	private static final JavaMethod ARRAYS_DEEPHASHCODE = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "deepHashCode", "([Ljava/lang/Object;)");
141
+	private static final JavaMethod ARRAYS_HASHCODE_BOOLS = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "hashCode", "([Z)I");
142
+	private static final JavaMethod ARRAYS_HASHCODE_BYTES = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "hashCode", "([B)I");
143
+	private static final JavaMethod ARRAYS_HASHCODE_SHORTS = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "hashCode", "([S)I");
144
+	private static final JavaMethod ARRAYS_HASHCODE_INTS = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "hashCode", "([I)I");
145
+	private static final JavaMethod ARRAYS_HASHCODE_LONGS = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "hashCode", "([L)I");
146
+	private static final JavaMethod ARRAYS_HASHCODE_FLOATS = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "hashCode", "([F)I");
147
+	private static final JavaMethod ARRAYS_HASHCODE_DOUBLES = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "hashCode", "([D)I");
148
+	private static final JavaMethod ARRAYS_HASHCODE_CHARS = JavaMethod.getNativeStatic(JavaClass.ARRAYS, "hashCode", "([C)I");
149
+	public static final JavaMethod OBJECT_HASHCODE = JavaMethod.getNativeVirtual(JavaClass.OBJECT, "hashCode", "()I");
150
+	private static final JavaMethod COLLECTION_SIZE = JavaMethod.getNativeVirtual(JavaClass.COLLECTION, "size", "()I");
151
+	private static final JavaMethod COLLECTION_TOARRAY = JavaMethod.getNativeVirtual(JavaClass.COLLECTION, "toArray", "([Ljava/lang/Object;)[Ljava/lang/Object;");
149 152
 
150 153
 	protected final JavaWriter javaWriter;
151 154
 	private final JavaCapturedExpressionVisitor capturedExpressionVisitor = new JavaCapturedExpressionVisitor(this);
@@ -846,11 +849,10 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
846 849
 			}
847 850
 			case FUNCTION_CALL:
848 851
 				javaWriter.invokeInterface(
849
-						new JavaMethodInfo(
852
+						JavaMethod.getNativeVirtual(
850 853
 								JavaClass.fromInternalName(context.getInternalName(expression.target.type), JavaClass.Kind.INTERFACE),
851 854
 								"accept",
852
-								context.getMethodSignature(expression.instancedHeader),
853
-								Opcodes.ACC_PUBLIC));
855
+								context.getMethodSignature(expression.instancedHeader)));
854 856
 				break;
855 857
 			case AUTOOP_NOTEQUALS:
856 858
 				throw new UnsupportedOperationException("Not yet supported!");
@@ -975,7 +977,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
975 977
 
976 978
 		BuiltinID builtin = expression.member.member.builtin;
977 979
 		if (builtin == null) {
978
-			if (!checkAndExecuteByteCodeImplementation(expression.member) && !checkAndExecuteMethodInfo(expression.member))
980
+			if (!checkAndExecuteMethodInfo(expression.member))
979 981
 				throw new IllegalStateException("Call target has no method info!");
980 982
 
981 983
 			return null;
@@ -1318,7 +1320,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1318 1320
         javaWriter.dup();
1319 1321
         javaWriter.ifNonNull(end);
1320 1322
         javaWriter.pop();
1321
-        javaWriter.newObject(NullPointerException.class);
1323
+        javaWriter.newObject("java/lang/NullPointerException");
1322 1324
         javaWriter.dup();
1323 1325
         javaWriter.constant("Tried to convert a null value to nonnull type " + context.getType(expression.type).getClassName());
1324 1326
         javaWriter.invokeSpecial(NullPointerException.class, "<init>", "(Ljava/lang/String;)V");
@@ -1434,7 +1436,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1434 1436
 			case ENUM_VALUES: {
1435 1437
 				DefinitionTypeID type = (DefinitionTypeID) expression.type;
1436 1438
 				JavaClass cls = type.definition.getTag(JavaClass.class);
1437
-				javaWriter.invokeStatic(new JavaMethodInfo(cls, "values", "()[L" + cls.internalName + ";", PUBLIC_STATIC));
1439
+				javaWriter.invokeStatic(JavaMethod.getNativeStatic(cls, "values", "()[L" + cls.internalName + ";"));
1438 1440
 				break;
1439 1441
 			}
1440 1442
 			default:
@@ -1528,7 +1530,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1528 1530
     @Override
1529 1531
     public Void visitConstructorThisCall(ConstructorThisCallExpression expression) {
1530 1532
 		javaWriter.loadObject(0);
1531
-		if (javaWriter.method.javaClass.isEnum()) {
1533
+		if (javaWriter.method.cls.isEnum()) {
1532 1534
 			javaWriter.loadObject(1);
1533 1535
 			javaWriter.loadInt(2);
1534 1536
 		}
@@ -1537,7 +1539,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1537 1539
 			argument.accept(this);
1538 1540
 		}
1539 1541
 		String internalName = context.getInternalName(expression.objectType);
1540
-        javaWriter.invokeSpecial(internalName, "<init>", javaWriter.method.javaClass.isEnum()
1542
+        javaWriter.invokeSpecial(internalName, "<init>", javaWriter.method.cls.isEnum()
1541 1543
 				? context.getEnumConstructorDescriptor(expression.constructor.getHeader())
1542 1544
 				: context.getMethodDescriptor(expression.constructor.getHeader()));
1543 1545
         return null;
@@ -1574,9 +1576,9 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1574 1576
             return null;
1575 1577
         }
1576 1578
         final String signature = context.getMethodSignature(expression.header);
1577
-		final String name = CompilerUtils.getLambdaCounter();
1579
+		final String name = context.getLambdaCounter();
1578 1580
 
1579
-		final JavaMethodInfo methodInfo = new JavaMethodInfo(javaWriter.method.javaClass, "accept", signature, Opcodes.ACC_PUBLIC);
1581
+		final JavaMethod methodInfo = JavaMethod.getNativeVirtual(javaWriter.method.cls, "accept", signature);
1580 1582
 		final ClassWriter lambdaCW = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
1581 1583
 		lambdaCW.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, name, null, "java/lang/Object", new String[]{JavaSynthesizedClassNamer.createFunctionName(new FunctionTypeID(null, expression.header)).cls.internalName});
1582 1584
 		final JavaWriter functionWriter = new JavaWriter(lambdaCW, methodInfo, null, signature, null, "java/lang/Override");
@@ -1587,7 +1589,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1587 1589
 		final String constructorDesc = calcFunctionSignature(expression.closure);
1588 1590
 
1589 1591
 
1590
-		final JavaWriter constructorWriter = new JavaWriter(lambdaCW, new JavaMethodInfo(javaWriter.method.javaClass, "<init>", constructorDesc, Opcodes.ACC_PUBLIC), null, null, null);
1592
+		final JavaWriter constructorWriter = new JavaWriter(lambdaCW, JavaMethod.getConstructor(javaWriter.method.cls, constructorDesc, Opcodes.ACC_PUBLIC), null, null, null);
1591 1593
 		constructorWriter.start();
1592 1594
 		constructorWriter.loadObject(0);
1593 1595
 		constructorWriter.dup();
@@ -1718,10 +1720,9 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1718 1720
 		javaWriter.loadObject(0);
1719 1721
 		final ITypeID type = expression.value.option.getParameterType(expression.index);
1720 1722
 		final JavaClass tag = expression.value.option.getTag(JavaClass.class);
1721
-		javaWriter.checkCast(tag.internalName);
1722
-		javaWriter.getField(new JavaField(tag, "Field" + expression.index, context.getDescriptor(type)));
1723
+		javaWriter.checkCast("L" + tag.internalName + ";");
1724
+		javaWriter.getField(new JavaField(tag, "field" + expression.index, context.getDescriptor(type)));
1723 1725
 		return null;
1724
-		//throw new UnsupportedOperationException(); // TODO
1725 1726
 	}
1726 1727
 
1727 1728
 	@Override
@@ -1910,13 +1911,16 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1910 1911
 			case OBJECT_HASHCODE:
1911 1912
 				javaWriter.invokeVirtual(OBJECT_HASHCODE);
1912 1913
 				break;
1913
-			case RANGE_FROM:
1914
-				// TODO: range types
1915
-				javaWriter.getField(IntRange.class, "from", int.class);
1914
+			case RANGE_FROM: {
1915
+				RangeTypeID type = (RangeTypeID)expression.target.type;
1916
+				JavaClass cls = context.getTypeGenerator().synthesizeRange(type).cls;
1917
+				javaWriter.getField(cls.internalName, "from", context.getDescriptor(type.from));
1916 1918
 				break;
1919
+			}
1917 1920
 			case RANGE_TO:
1918
-				// TODO: range types
1919
-				javaWriter.getField(IntRange.class, "to", int.class);
1921
+				RangeTypeID type = (RangeTypeID)expression.target.type;
1922
+				JavaClass cls = context.getTypeGenerator().synthesizeRange(type).cls;
1923
+				javaWriter.getField(cls.internalName, "to", context.getDescriptor(type.to));
1920 1924
 				break;
1921 1925
 		}
1922 1926
 
@@ -1969,30 +1973,26 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1969 1973
 
1970 1974
 	@Override
1971 1975
 	public Void visitMatch(MatchExpression expression) {
1972
-
1973 1976
 		final Label start = new Label();
1974 1977
 		final Label end = new Label();
1975 1978
 
1976
-
1977 1979
 		javaWriter.label(start);
1978 1980
 		expression.value.accept(this);
1979 1981
 
1980
-
1981 1982
 		//TODO replace beforeSwitch visitor or similar
1982 1983
 		if (expression.value.type == BasicTypeID.STRING)
1983
-			javaWriter.invokeVirtual(new JavaMethodInfo(JavaClass.OBJECT, "hashCode", "()I", 0));
1984
+			javaWriter.invokeVirtual(OBJECT_HASHCODE);
1984 1985
 
1985 1986
 		//TODO replace with beforeSwitch visitor or similar
1986 1987
 		for (MatchExpression.Case aCase : expression.cases) {
1987 1988
 			if (aCase.key instanceof VariantOptionSwitchValue) {
1988 1989
 				VariantOptionSwitchValue variantOptionSwitchValue = (VariantOptionSwitchValue) aCase.key;
1989
-				final String className = variantOptionSwitchValue.option.getTag(JavaClass.class).internalName;
1990
-				javaWriter.invokeVirtual(new JavaMethodInfo(new JavaClass("", className.substring(0, className.lastIndexOf('$')), JavaClass.Kind.CLASS), "getDenominator", "()I", 0));
1990
+				JavaVariantOption option = variantOptionSwitchValue.option.getTag(JavaVariantOption.class);
1991
+				javaWriter.invokeVirtual(JavaMethod.getNativeVirtual(option.variantClass, "getDenominator", "()I"));
1991 1992
 				break;
1992 1993
 			}
1993 1994
 		}
1994 1995
 
1995
-
1996 1996
 		final boolean hasNoDefault = hasNoDefault(expression);
1997 1997
 
1998 1998
 		final MatchExpression.Case[] cases = expression.cases;
@@ -2044,6 +2044,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2044 2044
     @Override
2045 2045
     public Void visitNew(NewExpression expression) {
2046 2046
 		// TODO: this code is incorrect!
2047
+		JavaMethod method = expression.constructor.getTag(JavaMethod.class);
2047 2048
 		
2048 2049
         final String type;
2049 2050
         if (expression.type instanceof DefinitionTypeID)
@@ -2053,15 +2054,12 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2053 2054
 
2054 2055
         javaWriter.newObject(type);
2055 2056
         javaWriter.dup();
2056
-        StringBuilder signatureBuilder = new StringBuilder("(");
2057
-        for (Expression argument : expression.arguments.arguments) {
2058
-            argument.accept(this);
2059
-            signatureBuilder.append(context.getDescriptor(argument.type));
2060
-        }
2061
-        signatureBuilder.append(")V");
2062
-        javaWriter.invokeSpecial(type, "<init>", signatureBuilder.toString());
2063
-
2064
-		//throw new UnsupportedOperationException("Not yet implemented!");
2057
+		
2058
+		for (Expression argument : expression.arguments.arguments) {
2059
+			argument.accept(this);
2060
+		}
2061
+		
2062
+        javaWriter.invokeSpecial(method);
2065 2063
 		return null;
2066 2064
 	}
2067 2065
 
@@ -2098,7 +2096,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2098 2096
 
2099 2097
 	@Override
2100 2098
 	public Void visitPanic(PanicExpression expression) {
2101
-		javaWriter.newObject(AssertionError.class);
2099
+		javaWriter.newObject("java/lang/AssertionError");
2102 2100
 		javaWriter.dup();
2103 2101
 		expression.value.accept(this);
2104 2102
 		javaWriter.invokeSpecial(AssertionError.class, "<init>", "(Ljava/lang/String;)V");
@@ -2110,7 +2108,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2110 2108
 	public Void visitPostCall(PostCallExpression expression) {
2111 2109
 		expression.target.accept(this);
2112 2110
 		javaWriter.dup(context.getType(expression.type));
2113
-		if (!checkAndExecuteByteCodeImplementation(expression.member) && !checkAndExecuteMethodInfo(expression.member))
2111
+		if (!checkAndExecuteMethodInfo(expression.member))
2114 2112
 			throw new IllegalStateException("Call target has no method info!");
2115 2113
 
2116 2114
 		return null;
@@ -2118,15 +2116,13 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2118 2116
 
2119 2117
     @Override
2120 2118
     public Void visitRange(RangeExpression expression) {
2121
-        // TODO: there are other kinds of ranges also; there should be a Range<T, T> type with creation of synthetic types
2122
-        if (!context.getDescriptor(expression.from.type).equals("I"))
2123
-            throw new CompileException(expression.position, CompileExceptionCode.INTERNAL_ERROR, "Only integer ranges supported");
2124
-
2125
-		javaWriter.newObject(IntRange.class);
2119
+		RangeTypeID type = (RangeTypeID)expression.type;
2120
+		JavaSynthesizedClass cls = context.getTypeGenerator().synthesizeRange(type);
2121
+		javaWriter.newObject(cls.cls.internalName);
2126 2122
 		javaWriter.dup();
2127 2123
 		expression.from.accept(this);
2128 2124
 		expression.to.accept(this);
2129
-		javaWriter.invokeSpecial("org/openzen/zenscript/implementations/IntRange", "<init>", "(II)V");
2125
+		javaWriter.invokeSpecial(cls.cls.internalName, "<init>", "(" + context.getDescriptor(type.from) + context.getDescriptor(type.to) + ")V");
2130 2126
 
2131 2127
 		return null;
2132 2128
 	}
@@ -2279,7 +2275,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2279 2275
 			case ENUM_VALUES: {
2280 2276
 				DefinitionTypeID type = (DefinitionTypeID) expression.type;
2281 2277
 				JavaClass cls = type.definition.getTag(JavaClass.class);
2282
-				javaWriter.invokeStatic(new JavaMethodInfo(cls, "values", "()[L" + cls.internalName + ";", PUBLIC_STATIC));
2278
+				javaWriter.invokeStatic(JavaMethod.getNativeStatic(cls, "values", "()[L" + cls.internalName + ";"));
2283 2279
 				break;
2284 2280
 			}
2285 2281
 			default:
@@ -2351,12 +2347,8 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2351 2347
 	@Override
2352 2348
 	public Void visitWrapOptional(WrapOptionalExpression expression) {
2353 2349
 		//Does nothing if not required to be wrapped
2354
-		final JavaMethodInfo info = expression.value.type.accept(new JavaBoxingTypeVisitor(javaWriter));
2355 2350
 		expression.value.accept(this);
2356
-
2357
-		//i.e. if it was a primitive
2358
-		if (info != null)
2359
-			javaWriter.invokeSpecial(info);
2351
+		expression.value.type.accept(new JavaBoxingTypeVisitor(javaWriter));
2360 2352
 		return null;
2361 2353
 	}
2362 2354
 
@@ -2364,24 +2356,13 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
2364 2356
         return javaWriter;
2365 2357
     }
2366 2358
 
2367
-
2368
-    //Will return true if a JavaBytecodeImplementation.class tag exists, and will compile that tag
2369
-    private boolean checkAndExecuteByteCodeImplementation(DefinitionMemberRef member) {
2370
-        JavaBytecodeImplementation implementation = member.getTag(JavaBytecodeImplementation.class);
2371
-        if (implementation != null) {
2372
-            implementation.compile(getJavaWriter());
2373
-            return true;
2374
-        }
2375
-        return false;
2376
-    }
2377
-
2378 2359
     //Will return true if a JavaMethodInfo.class tag exists, and will compile that tag
2379 2360
     private boolean checkAndExecuteMethodInfo(DefinitionMemberRef member) {
2380
-        JavaMethodInfo methodInfo = member.getTag(JavaMethodInfo.class);
2361
+        JavaMethod methodInfo = member.getTag(JavaMethod.class);
2381 2362
         if (methodInfo == null)
2382 2363
             return false;
2383 2364
 
2384
-        if (methodInfo.isStatic()) {
2365
+        if (methodInfo.kind == JavaMethod.Kind.STATIC) {
2385 2366
             getJavaWriter().invokeStatic(methodInfo);
2386 2367
         } else {
2387 2368
             getJavaWriter().invokeVirtual(methodInfo);

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

@@ -27,9 +27,9 @@ public class JavaForeachVisitor implements ForeachIteratorVisitor<Void> {
27 27
 	@Override
28 28
 	public Void visitIntRange() {
29 29
 		javaWriter.dup();
30
-		javaWriter.getField("org/openzen/zenscript/implementations/IntRange", "to", "I");
30
+		javaWriter.getField("zsynthetic/IntRange", "to", "I");
31 31
 		javaWriter.swap();
32
-		javaWriter.getField("org/openzen/zenscript/implementations/IntRange", "from", "I");
32
+		javaWriter.getField("zsynthetic/IntRange", "from", "I");
33 33
 
34 34
 		final int z = variables[0].getTag(JavaLocalVariableInfo.class).local;
35 35
 		javaWriter.storeInt(z);

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

@@ -76,7 +76,7 @@ import org.openzen.zenscript.codemodel.expression.VariantValueExpression;
76 76
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
77 77
 import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
78 78
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
79
-import org.openzen.zenscript.javabytecode.JavaParameterInfo;
79
+import org.openzen.zenscript.javashared.JavaParameterInfo;
80 80
 
81 81
 /**
82 82
  *

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

@@ -76,7 +76,7 @@ import org.openzen.zenscript.codemodel.expression.VariantValueExpression;
76 76
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
77 77
 import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
78 78
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
79
-import org.openzen.zenscript.javabytecode.JavaParameterInfo;
79
+import org.openzen.zenscript.javashared.JavaParameterInfo;
80 80
 
81 81
 /**
82 82
  *

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

@@ -5,17 +5,16 @@
5 5
  */
6 6
 package org.openzen.zenscript.javabytecode.compiler;
7 7
 
8
-import org.openzen.zenscript.javabytecode.JavaMethodInfo;
9
-
10 8
 import java.util.ArrayList;
11 9
 import java.util.List;
10
+import org.openzen.zenscript.javashared.JavaMethod;
12 11
 
13 12
 /**
14 13
  * @author Hoofdgebruiker
15 14
  */
16 15
 public class JavaScriptFile {
17 16
 	public final JavaClassWriter classWriter;
18
-	public final List<JavaMethodInfo> scriptMethods;
17
+	public final List<JavaMethod> scriptMethods;
19 18
 
20 19
 	public JavaScriptFile(JavaClassWriter classWriter) {
21 20
 		this.classWriter = classWriter;

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

@@ -5,12 +5,10 @@ import org.objectweb.asm.Type;
5 5
 import org.openzen.zenscript.codemodel.statement.*;
6 6
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
7 7
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
8
-import org.openzen.zenscript.javabytecode.JavaMethodInfo;
9 8
 
10 9
 import java.util.Arrays;
11 10
 import java.util.List;
12 11
 import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
13
-import org.openzen.zenscript.javashared.JavaClass;
14 12
 
15 13
 public class JavaStatementVisitor implements StatementVisitor<Boolean> {
16 14
     private final JavaWriter javaWriter;
@@ -166,7 +164,7 @@ public class JavaStatementVisitor implements StatementVisitor<Boolean> {
166 164
 		javaWriter.label(start);
167 165
 		statement.value.accept(expressionVisitor);
168 166
 		if (statement.value.type == BasicTypeID.STRING)
169
-			javaWriter.invokeVirtual(new JavaMethodInfo(JavaClass.OBJECT, "hashCode", "()I", 0));
167
+			javaWriter.invokeVirtual(JavaExpressionVisitor.OBJECT_HASHCODE);
170 168
 		boolean out = false;
171 169
 
172 170
 		final boolean hasNoDefault = hasNoDefault(statement);

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

@@ -0,0 +1,48 @@
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.expression.switchvalue.CharSwitchValue;
9
+import org.openzen.zenscript.codemodel.expression.switchvalue.EnumConstantSwitchValue;
10
+import org.openzen.zenscript.codemodel.expression.switchvalue.IntSwitchValue;
11
+import org.openzen.zenscript.codemodel.expression.switchvalue.StringSwitchValue;
12
+import org.openzen.zenscript.codemodel.expression.switchvalue.SwitchValueVisitor;
13
+import org.openzen.zenscript.codemodel.expression.switchvalue.VariantOptionSwitchValue;
14
+
15
+/**
16
+ *
17
+ * @author Hoofdgebruiker
18
+ */
19
+public class JavaSwitchKeyVisitor implements SwitchValueVisitor<Integer> {
20
+	public static final JavaSwitchKeyVisitor INSTANCE = new JavaSwitchKeyVisitor();
21
+	
22
+	private JavaSwitchKeyVisitor() {}
23
+	
24
+	@Override
25
+	public Integer acceptInt(IntSwitchValue value) {
26
+		return value.value;
27
+	}
28
+
29
+	@Override
30
+	public Integer acceptChar(CharSwitchValue value) {
31
+		return (int) value.value;
32
+	}
33
+
34
+	@Override
35
+	public Integer acceptString(StringSwitchValue value) {
36
+		return value.value.hashCode();
37
+	}
38
+
39
+	@Override
40
+	public Integer acceptEnumConstant(EnumConstantSwitchValue value) {
41
+		return value.constant.ordinal;
42
+	}
43
+
44
+	@Override
45
+	public Integer acceptVariantOption(VariantOptionSwitchValue value) {
46
+		return value.option.getOrdinal();
47
+	}
48
+}

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

@@ -12,19 +12,18 @@ import org.objectweb.asm.commons.LocalVariablesSorter;
12 12
 import org.openzen.zencode.shared.CodePosition;
13 13
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
14 14
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
15
-import org.openzen.zenscript.javabytecode.JavaMethodInfo;
16
-import org.openzen.zenscript.javabytecode.JavaParameterInfo;
15
+import org.openzen.zenscript.javashared.JavaParameterInfo;
17 16
 import org.openzen.zenscript.javashared.JavaClass;
18 17
 import org.openzen.zenscript.javashared.JavaField;
18
+import org.openzen.zenscript.javashared.JavaMethod;
19 19
 
20 20
 public class JavaWriter {
21
-    private static final JavaMethodInfo STRING_CONCAT = new JavaMethodInfo(
21
+    private static final JavaMethod STRING_CONCAT = JavaMethod.getNativeStatic(
22 22
             JavaClass.STRING,
23 23
             "concat",
24
-            "(Ljava/lang/String;)Ljava/lang/String;",
25
-            Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);
24
+            "(Ljava/lang/String;)Ljava/lang/String;");
26 25
 
27
-    public final JavaMethodInfo method;
26
+    public final JavaMethod method;
28 27
     public final HighLevelDefinition forDefinition;
29 28
 
30 29
     private final LocalVariablesSorter visitor;
@@ -38,7 +37,7 @@ public class JavaWriter {
38 37
     public JavaWriter(
39 38
             ClassVisitor visitor,
40 39
             boolean nameVariables,
41
-            JavaMethodInfo method,
40
+            JavaMethod method,
42 41
             HighLevelDefinition forDefinition,
43 42
             String signature,
44 43
             String[] exceptions,
@@ -57,14 +56,10 @@ public class JavaWriter {
57 56
         this.nameVariables = nameVariables;
58 57
     }
59 58
 
60
-    public JavaWriter(ClassVisitor visitor, JavaMethodInfo method, HighLevelDefinition forDefinition, String signature, String[] exceptions, String... annotations) {
59
+    public JavaWriter(ClassVisitor visitor, JavaMethod method, HighLevelDefinition forDefinition, String signature, String[] exceptions, String... annotations) {
61 60
         this(visitor, true, method, forDefinition, signature, exceptions, annotations);
62 61
     }
63 62
 
64
-    private static String signature(Class aClass) {
65
-        return Type.getDescriptor(aClass);
66
-    }
67
-
68 63
     private static String internal(Class aClass) {
69 64
         return Type.getInternalName(aClass);
70 65
     }
@@ -245,7 +240,7 @@ public class JavaWriter {
245 240
         if (debug)
246 241
             System.out.println("load " + parameter.index);
247 242
 
248
-        visitor.visitVarInsn(parameter.type.getOpcode(ILOAD), parameter.index);
243
+        visitor.visitVarInsn(Type.getType(parameter.typeDescriptor).getOpcode(ILOAD), parameter.index);
249 244
     }
250 245
 
251 246
     public void load(JavaLocalVariableInfo localVariable) {
@@ -259,7 +254,7 @@ public class JavaWriter {
259 254
         if (debug)
260 255
             System.out.println("store " + parameter.index);
261 256
 
262
-        visitor.visitVarInsn(parameter.type.getOpcode(ISTORE), parameter.index);
257
+        visitor.visitVarInsn(Type.getType(parameter.typeDescriptor).getOpcode(ISTORE), parameter.index);
263 258
     }
264 259
 
265 260
     public void store(JavaLocalVariableInfo localVariable) {
@@ -358,20 +353,6 @@ public class JavaWriter {
358 353
         }
359 354
     }
360 355
 
361
-    public void newArray(Class componentType) {
362
-        if (debug)
363
-            System.out.println("newArray " + componentType.getName());
364
-
365
-        visitor.visitTypeInsn(NEWARRAY, internal(componentType));
366
-    }
367
-
368
-    public void checkCast(Class newClass) {
369
-        if (debug)
370
-            System.out.println("checkCast " + newClass.getName());
371
-
372
-        visitor.visitTypeInsn(CHECKCAST, signature(newClass));
373
-    }
374
-
375 356
     public void checkCast(String descriptor) {
376 357
         if (debug)
377 358
             System.out.println("checkCast " + descriptor);
@@ -810,10 +791,10 @@ public class JavaWriter {
810 791
         visitor.visitTypeInsn(INSTANCEOF, type.getDescriptor());
811 792
     }
812 793
 	
813
-	public void invokeStatic(JavaMethodInfo method) {
794
+	public void invokeStatic(JavaMethod method) {
814 795
 		visitor.visitMethodInsn(
815 796
 				INVOKESTATIC,
816
-				method.javaClass.internalName,
797
+				method.cls.internalName,
817 798
 				method.name,
818 799
 				method.descriptor,
819 800
 				false);
@@ -830,29 +811,22 @@ public class JavaWriter {
830 811
         invokeSpecial(Type.getInternalName(owner), name, descriptor);
831 812
     }
832 813
 
833
-	public void invokeSpecial (JavaMethodInfo method) {
834
-		invokeSpecial(method.javaClass.internalName, method.name, method.descriptor);
814
+	public void invokeSpecial(JavaMethod method) {
815
+		invokeSpecial(method.cls.internalName, method.name, method.descriptor);
835 816
 	}
836 817
 
837
-    public void invokeVirtual(JavaMethodInfo method) {
818
+    public void invokeVirtual(JavaMethod method) {
838 819
         if (debug)
839
-            System.out.println("invokeVirtual " + method.javaClass.internalName + '.' + method.name + method.descriptor);
820
+            System.out.println("invokeVirtual " + method.cls.internalName + '.' + method.name + method.descriptor);
840 821
 
841
-        visitor.visitMethodInsn(INVOKEVIRTUAL, method.javaClass.internalName, method.name, method.descriptor, false);
822
+        visitor.visitMethodInsn(INVOKEVIRTUAL, method.cls.internalName, method.name, method.descriptor, false);
842 823
     }
843 824
 
844
-    public void invokeInterface(JavaMethodInfo method) {
825
+    public void invokeInterface(JavaMethod method) {
845 826
         if (debug)
846
-            System.out.println("invokeInterface " + method.javaClass.internalName + '.' + method.name + method.descriptor);
827
+            System.out.println("invokeInterface " + method.cls.internalName + '.' + method.name + method.descriptor);
847 828
 
848
-        visitor.visitMethodInsn(INVOKEINTERFACE, method.javaClass.internalName, method.name, method.descriptor, true);
849
-    }
850
-
851
-    public void newObject(Class type) {
852
-        if (debug)
853
-            System.out.println("newObject " + type.getName());
854
-
855
-        visitor.visitTypeInsn(NEW, internal(type));
829
+        visitor.visitMethodInsn(INVOKEINTERFACE, method.cls.internalName, method.name, method.descriptor, true);
856 830
     }
857 831
 
858 832
     public void newObject(String internalName) {
@@ -862,34 +836,6 @@ public class JavaWriter {
862 836
         visitor.visitTypeInsn(NEW, internalName);
863 837
     }
864 838
 
865
-    public void construct(Class type, Class... arguments) {
866
-        StringBuilder descriptor = new StringBuilder();
867
-        descriptor.append('(');
868
-        for (Class argument : arguments) {
869
-            descriptor.append(signature(argument));
870
-        }
871
-        descriptor.append(")V");
872
-
873
-        if (debug)
874
-            System.out.println("invokeSpecial " + internal(type) + ".<init>" + descriptor);
875
-
876
-        visitor.visitMethodInsn(INVOKESPECIAL, internal(type), "<init>", descriptor.toString(), false);
877
-    }
878
-
879
-    public void construct(String type, String... arguments) {
880
-        StringBuilder descriptor = new StringBuilder();
881
-        descriptor.append('(');
882
-        for (String argument : arguments) {
883
-            descriptor.append(argument);
884
-        }
885
-        descriptor.append(")V");
886
-
887
-        if (debug)
888
-            System.out.println("invokeSpecial " + type + ".<init>" + descriptor);
889
-
890
-        visitor.visitMethodInsn(INVOKESPECIAL, type, "<init>", descriptor.toString(), false);
891
-    }
892
-
893 839
     public void goTo(Label lbl) {
894 840
         if (debug)
895 841
             System.out.println("goTo " + getLabelName(lbl));
@@ -1048,19 +994,12 @@ public class JavaWriter {
1048 994
 
1049 995
         visitor.visitFieldInsn(GETFIELD, owner, name, descriptor);
1050 996
     }
1051
-
1052
-    public void getField(Class owner, String name, Class descriptor) {
1053
-        if (debug)
1054
-            System.out.println("getField " + owner.getName() + '.' + name + ":" + descriptor.getName());
1055
-
1056
-        visitor.visitFieldInsn(GETFIELD, internal(owner), name, signature(descriptor));
1057
-    }
1058 997
 	
1059 998
 	public void getField(JavaField field) {
1060 999
         if (debug)
1061
-            System.out.println("getField " + field.cls.internalName + '.' + field.name + ":" + field.signature);
1000
+            System.out.println("getField " + field.cls.internalName + '.' + field.name + ":" + field.descriptor);
1062 1001
 		
1063
-		visitor.visitFieldInsn(GETFIELD, field.cls.internalName, field.name, field.signature);
1002
+		visitor.visitFieldInsn(GETFIELD, field.cls.internalName, field.name, field.descriptor);
1064 1003
 	}
1065 1004
 
1066 1005
     public void putField(String owner, String name, String descriptor) {
@@ -1069,19 +1008,12 @@ public class JavaWriter {
1069 1008
 
1070 1009
         visitor.visitFieldInsn(PUTFIELD, owner, name, descriptor);
1071 1010
     }
1072
-
1073
-    public void putField(Class owner, String name, Class descriptor) {
1074
-        if (debug)
1075
-            System.out.println("putField " + owner.getName() + '.' + name + ":" + descriptor.getName());
1076
-
1077
-        visitor.visitFieldInsn(PUTFIELD, internal(owner), name, signature(descriptor));
1078
-    }
1079 1011
 	
1080 1012
 	public void putField(JavaField field) {
1081 1013
         if (debug)
1082
-            System.out.println("putField " + field.cls.internalName + '.' + field.name + ":" + field.signature);
1014
+            System.out.println("putField " + field.cls.internalName + '.' + field.name + ":" + field.descriptor);
1083 1015
 		
1084
-		visitor.visitFieldInsn(PUTFIELD, field.cls.internalName, field.name, field.signature);
1016
+		visitor.visitFieldInsn(PUTFIELD, field.cls.internalName, field.name, field.descriptor);
1085 1017
 	}
1086 1018
 
1087 1019
     public void getStaticField(String owner, String name, String descriptor) {
@@ -1093,9 +1025,9 @@ public class JavaWriter {
1093 1025
 	
1094 1026
 	public void getStaticField(JavaField field) {
1095 1027
         if (debug)
1096
-            System.out.println("getStaticField " + field.cls.internalName + '.' + field.name + ":" + field.signature);
1028
+            System.out.println("getStaticField " + field.cls.internalName + '.' + field.name + ":" + field.descriptor);
1097 1029
 		
1098
-		visitor.visitFieldInsn(GETSTATIC, field.cls.internalName, field.name, field.signature);
1030
+		visitor.visitFieldInsn(GETSTATIC, field.cls.internalName, field.name, field.descriptor);
1099 1031
 	}
1100 1032
 
1101 1033
     public void putStaticField(String owner, String name, String descriptor) {
@@ -1104,19 +1036,12 @@ public class JavaWriter {
1104 1036
 
1105 1037
         visitor.visitFieldInsn(PUTSTATIC, owner, name, descriptor);
1106 1038
     }
1107
-
1108
-    public void putStaticField(Class owner, Field field) {
1109
-        if (debug)
1110
-            System.out.println("putStatic " + owner.getName() + '.' + field.getName() + ":" + signature(field.getType()));
1111
-
1112
-        visitor.visitFieldInsn(PUTSTATIC, internal(owner), field.getName(), signature(field.getType()));
1113
-    }
1114 1039
 	
1115 1040
 	public void putStaticField(JavaField field) {
1116 1041
         if (debug)
1117
-            System.out.println("putStaticField " + field.cls.internalName + '.' + field.name + ":" + field.signature);
1042
+            System.out.println("putStaticField " + field.cls.internalName + '.' + field.name + ":" + field.descriptor);
1118 1043
 		
1119
-		visitor.visitFieldInsn(PUTSTATIC, field.cls.internalName, field.name, field.signature);
1044
+		visitor.visitFieldInsn(PUTSTATIC, field.cls.internalName, field.name, field.descriptor);
1120 1045
 	}
1121 1046
 
1122 1047
     public void aThrow() {

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

@@ -2,37 +2,32 @@ package org.openzen.zenscript.javabytecode.compiler.definitions;
2 2
 
3 3
 import org.objectweb.asm.ClassWriter;
4 4
 import org.objectweb.asm.Opcodes;
5
-import org.objectweb.asm.Type;
6
-import org.openzen.zenscript.codemodel.Modifiers;
7 5
 import org.openzen.zenscript.codemodel.definition.*;
8 6
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
9 7
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
10 8
 import org.openzen.zenscript.codemodel.type.ITypeID;
11 9
 import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
12
-import org.openzen.zenscript.javabytecode.JavaMethodInfo;
13
-import org.openzen.zenscript.javabytecode.JavaModule;
14 10
 import org.openzen.zenscript.javabytecode.compiler.*;
15 11
 import org.openzen.zenscript.javashared.JavaClass;
16 12
 
17 13
 import java.io.FileOutputStream;
18 14
 import java.io.IOException;
15
+import java.util.ArrayList;
19 16
 import java.util.List;
17
+import org.openzen.zenscript.codemodel.member.ImplementationMember;
18
+import org.openzen.zenscript.javashared.JavaMethod;
19
+import org.openzen.zenscript.javashared.JavaModifiers;
20
+import org.openzen.zenscript.javashared.JavaVariantOption;
20 21
 
21 22
 
22 23
 public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
23
-	private static final JavaMethodInfo CLASS_FORNAME = new JavaMethodInfo(
24
-			JavaClass.CLASS,
25
-			"forName",
26
-			"(Ljava/lang/String;)Ljava/lang/Class;",
27
-			Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC);
28
-
29
-
30
-	private static final JavaMethodInfo ENUM_VALUEOF = new JavaMethodInfo(
31
-			JavaClass.ENUM,
32
-			"valueOf",
33
-			"(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;",
34
-			Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC);
35
-
24
+	private static final JavaMethod CLASS_FORNAME
25
+			= JavaMethod.getNativeStatic(JavaClass.CLASS, "forName", "(Ljava/lang/String;)Ljava/lang/Class;");
26
+	private static final JavaMethod ENUM_VALUEOF
27
+			= JavaMethod.getNativeStatic(JavaClass.CLASS, "valueOf", "(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;");
28
+	private static final JavaMethod ARRAY_CLONE
29
+			= JavaMethod.getNativeVirtual(JavaClass.ARRAYS, "clone", "()Ljava/lang/Object;");
30
+	
36 31
 	private final JavaClassWriter outerWriter;
37 32
 	private final JavaBytecodeContext context;
38 33
 
@@ -43,22 +38,20 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
43 38
 
44 39
 	@Override
45 40
 	public byte[] visitClass(ClassDefinition definition) {
46
-		//Classes will always be created in a new File/Class
47
-
48
-        final Type superType;
49
-        if (definition.getSuperType() == null)
50
-            superType = Type.getType(Object.class);
51
-        else
52
-            superType = context.getType(definition.getSuperType());
41
+        final String superTypeInternalName = definition.getSuperType() == null ? "java/lang/Object" : context.getInternalName(definition.getSuperType());
53 42
 
54
-		JavaClass toClass = new JavaClass(definition.pkg.fullName, definition.name, JavaClass.Kind.CLASS);
43
+		JavaClass toClass = definition.getTag(JavaClass.class);
55 44
 		JavaClassWriter writer = new JavaClassWriter(ClassWriter.COMPUTE_FRAMES);
56 45
 
57 46
         //TODO: Calculate signature from generic parameters
58
-        //TODO: Interfaces?
47
+		List<String> interfaces = new ArrayList<>();
48
+		for (IDefinitionMember member : definition.members) {
49
+			if (member instanceof ImplementationMember)
50
+				interfaces.add(context.getInternalName(((ImplementationMember) member).type));
51
+		}
59 52
         String signature = null;
60 53
 		
61
-        writer.visit(Opcodes.V1_8, definition.modifiers, definition.name, signature, superType.getInternalName(), null);
54
+        writer.visit(Opcodes.V1_8, definition.modifiers, toClass.internalName, signature, superTypeInternalName, interfaces.toArray(new String[interfaces.size()]));
62 55
 		JavaMemberVisitor memberVisitor = new JavaMemberVisitor(context, writer, toClass, definition); 
63 56
         for (IDefinitionMember member : definition.members) {
64 57
             member.accept(memberVisitor);
@@ -70,13 +63,16 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
70 63
 
71 64
 	@Override
72 65
 	public byte[] visitInterface(InterfaceDefinition definition) {
73
-		JavaClass toClass = new JavaClass(definition.pkg.fullName, definition.name, JavaClass.Kind.INTERFACE);
66
+		JavaClass toClass = definition.getTag(JavaClass.class);
74 67
 		ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
75 68
 
76 69
 		//TODO: Calculate signature from generic parameters
77
-		//TODO: Extending Interfaces?
78 70
 		String signature = null;
79
-		writer.visit(Opcodes.V1_8, definition.modifiers | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT, definition.name, signature, Type.getInternalName(Object.class), null);
71
+		String[] baseInterfaces = new String[definition.baseInterfaces.size()];
72
+		for (int i = 0; i < baseInterfaces.length; i++)
73
+			baseInterfaces[i] = context.getInternalName(definition.baseInterfaces.get(i));
74
+		
75
+		writer.visit(Opcodes.V1_8, definition.modifiers | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT, toClass.internalName, signature, "java/lang/Object", baseInterfaces);
80 76
 		JavaMemberVisitor memberVisitor = new JavaMemberVisitor(context, writer, toClass, definition);
81 77
 		for (IDefinitionMember member : definition.members) {
82 78
 			member.accept(memberVisitor);
@@ -90,49 +86,40 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
90 86
 	public byte[] visitEnum(EnumDefinition definition) {
91 87
 		System.out.println("Compiling enum " + definition.name + " in " + definition.position.getFilename());
92 88
 		
93
-        final Type superType;
94
-        if (definition.getSuperType() == null)
95
-            superType = Type.getType(Object.class);
96
-        else
97
-            superType = context.getType(definition.getSuperType());
89
+		String superTypeInternalName = definition.getSuperType() == null ? "java/lang/Object" : context.getInternalName(definition.getSuperType());
98 90
 
99 91
 		ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
100 92
 
101
-		writer.visit(Opcodes.V1_8, Opcodes.ACC_ENUM | Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER | Opcodes.ACC_FINAL, definition.name, "Ljava/lang/Enum<L" + definition.name + ";>;", superType.getInternalName(), null);
102
-
103
-		JavaClass toClass = new JavaClass(definition.pkg.fullName, definition.name, JavaClass.Kind.ENUM);
93
+		JavaClass toClass = definition.getTag(JavaClass.class);
94
+		writer.visit(Opcodes.V1_8, Opcodes.ACC_ENUM | Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER | Opcodes.ACC_FINAL, toClass.internalName, "Ljava/lang/Enum<L" + toClass.internalName + ";>;", superTypeInternalName, null);
104 95
 
105 96
 		//Enum Stuff(required!)
106
-		writer.visitField(Opcodes.ACC_STATIC | Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL | Opcodes.ACC_SYNTHETIC, "$VALUES", "[L" + definition.name + ";", null, null).visitEnd();
97
+		writer.visitField(Opcodes.ACC_STATIC | Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL | Opcodes.ACC_SYNTHETIC, "$VALUES", "[L" + toClass.internalName + ";", null, null).visitEnd();
107 98
 
108 99
         final JavaMemberVisitor visitor = new JavaMemberVisitor(context, writer, toClass, definition);
109 100
         for (IDefinitionMember member : definition.members) {
110 101
             member.accept(visitor);
111 102
         }
112 103
 		
113
-		JavaClass arrayClass = JavaClass.fromInternalName("[L" + definition.name + ";", JavaClass.Kind.ARRAY);
114
-		JavaMethodInfo arrayClone = new JavaMethodInfo(arrayClass, "clone", "()Ljava/lang/Object;", Opcodes.ACC_PUBLIC);
115
-
116
-		JavaMethodInfo valuesMethodInfo = new JavaMethodInfo(toClass, "values", "()[L" + definition.name + ";", Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC);
117
-		JavaWriter valuesWriter = new JavaWriter(writer, true, valuesMethodInfo, definition, null, null);
104
+		JavaMethod valuesMethod = new JavaMethod(toClass, JavaMethod.Kind.STATIC, "values", true, "()[L" + toClass.internalName + ";", Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC);
105
+		JavaWriter valuesWriter = new JavaWriter(writer, true, valuesMethod, definition, null, null);
118 106
 		valuesWriter.start();
119
-		valuesWriter.getStaticField(definition.name, "$VALUES", "[L" + definition.name + ";");
120
-		valuesWriter.invokeVirtual(arrayClone);
121
-		valuesWriter.checkCast("[L" + definition.name + ";");
107
+		valuesWriter.getStaticField(toClass.internalName, "$VALUES", "[L" + toClass.internalName + ";");
108
+		valuesWriter.invokeVirtual(ARRAY_CLONE);
109
+		valuesWriter.checkCast("[L" + toClass.internalName + ";");
122 110
 		valuesWriter.returnObject();
123 111
 		valuesWriter.end();
124 112
 
125
-		JavaMethodInfo valueOfMethodInfo = new JavaMethodInfo(toClass, "valueOf", "(Ljava/lang/String;)L" + definition.name + ";", Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC);
126
-		JavaWriter valueOfWriter = new JavaWriter(writer, true, valueOfMethodInfo, definition, null, null);
113
+		JavaMethod valueOfMethod = new JavaMethod(toClass, JavaMethod.Kind.STATIC, "valueOf", true, "(Ljava/lang/String;)L" + toClass.internalName + ";", Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC);
114
+		JavaWriter valueOfWriter = new JavaWriter(writer, true, valueOfMethod, definition, null, null);
127 115
 		valueOfWriter.start();
128 116
 		valueOfWriter.invokeStatic(CLASS_FORNAME);
129 117
 		valueOfWriter.loadObject(0);
130 118
 		valueOfWriter.invokeStatic(ENUM_VALUEOF);
131
-		valueOfWriter.checkCast("L" + definition.name + ";");
119
+		valueOfWriter.checkCast("L" + toClass.internalName + ";");
132 120
 		valueOfWriter.returnObject();
133 121
 		valueOfWriter.end();
134
-
135
-
122
+		
136 123
 		writer.visitEnd();
137 124
 		return writer.toByteArray();
138 125
 	}
@@ -148,10 +135,9 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
148 135
 		
149 136
         final String signature = context.getMethodSignature(definition.header);
150 137
 		
151
-		final JavaClass toClass = new JavaClass(definition.pkg.fullName, CompilerUtils.calcClasName(definition.position), JavaClass.Kind.CLASS);
152
-		final JavaMethodInfo methodInfo = new JavaMethodInfo(toClass, definition.name, context.getMethodDescriptor(definition.header), CompilerUtils.calcAccess(definition.modifiers) | Opcodes.ACC_STATIC);
138
+		final JavaMethod method = definition.caller.getTag(JavaMethod.class);
153 139
 
154
-		final JavaWriter writer = new JavaWriter(outerWriter, true, methodInfo, definition, signature, null);
140
+		final JavaWriter writer = new JavaWriter(outerWriter, true, method, definition, signature, null);
155 141
         final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, writer);
156 142
         statementVisitor.start();
157 143
 		boolean returns = definition.statement.accept(statementVisitor);
@@ -165,9 +151,6 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
165 151
 		}
166 152
 
167 153
 		statementVisitor.end();
168
-
169
-		definition.setTag(JavaMethodInfo.class, methodInfo);
170
-		definition.caller.setTag(JavaMethodInfo.class, methodInfo);
171 154
 		return null;
172 155
 	}
173 156
 
@@ -183,29 +166,21 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
183 166
 
184 167
 	@Override
185 168
 	public byte[] visitVariant(VariantDefinition variant) {
186
-
187
-		final String variantName = variant.name;
188
-		final JavaClass toClass = new JavaClass("", variantName, JavaClass.Kind.CLASS);
169
+		final JavaClass toClass = variant.getTag(JavaClass.class);
189 170
 		final JavaClassWriter writer = new JavaClassWriter(ClassWriter.COMPUTE_FRAMES);
190 171
 
191
-		writer.visit(Opcodes.V1_8, Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC, variantName, null, "java/lang/Object", null);
172
+		writer.visit(Opcodes.V1_8, Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC, toClass.internalName, null, "java/lang/Object", null);
192 173
 		writer.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, "getDenominator", "()I", null, null).visitEnd();
193 174
 
194
-
195 175
 		final JavaMemberVisitor visitor = new JavaMemberVisitor(context, writer, toClass, variant);
196 176
 
197 177
 		final List<VariantDefinition.Option> options = variant.options;
198 178
 		//Each option is one of the possible child classes
199 179
 		for (final VariantDefinition.Option option : options) {
200
-			final String optionClassName = variantName + "$" + option.name;
201
-			final JavaClass optionClass = new JavaClass("", optionClassName, JavaClass.Kind.CLASS);
180
+			JavaVariantOption optionTag = option.getTag(JavaVariantOption.class);
202 181
 			final JavaClassWriter optionWriter = new JavaClassWriter(ClassWriter.COMPUTE_FRAMES);
203 182
 
204
-			writer.visitInnerClass(optionClassName, variantName, option.name, Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL);
205
-
206
-
207
-			option.setTag(JavaClass.class, optionClass);
208
-
183
+			writer.visitInnerClass(optionTag.variantOptionClass.internalName, optionTag.variantClass.internalName, option.name, Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL);
209 184
 
210 185
 			//Generic option signature
211 186
 			final String signature;
@@ -216,57 +191,55 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
216 191
 					builder.append(context.getDescriptor(option.types[i]));
217 192
 				}
218 193
 				builder.append(">");
219
-				builder.append("L").append(variantName).append(";");
220
-
221
-
194
+				builder.append("L").append(toClass.internalName).append(";");
195
+				
222 196
 				signature = builder.toString();
223 197
 			}
224 198
 
225
-			optionWriter.visit(Opcodes.V1_8, Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC, optionClassName, signature, variantName, null);
226
-			final JavaMemberVisitor optionVisitor = new JavaMemberVisitor(context, optionWriter, optionClass, variant);
199
+			optionWriter.visit(Opcodes.V1_8, Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC, optionTag.variantOptionClass.internalName, signature, optionTag.variantClass.internalName, null);
200
+			final JavaMemberVisitor optionVisitor = new JavaMemberVisitor(context, optionWriter, optionTag.variantOptionClass, variant);
227 201
 			final StringBuilder optionInitDescBuilder = new StringBuilder("(");
228 202
 
229 203
 			ITypeID[] types = option.types;
230 204
 			for (int i = 0; i < types.length; ++i) {
231 205
 				final String internalName = context.getInternalName(types[i]);
232 206
 				optionInitDescBuilder.append(internalName);
233
-				optionWriter.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "Field" + i, internalName, "TT" + i + ";", null).visitEnd();
207
+				optionWriter.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "field" + i, internalName, "TT" + i + ";", null).visitEnd();
234 208
 			}
235 209
 			optionInitDescBuilder.append(")V");
236
-
237
-
238
-			final JavaWriter initWriter = new JavaWriter(optionWriter, new JavaMethodInfo(optionClass, "<init>", optionInitDescBuilder.toString(), Opcodes.ACC_PUBLIC), variant, optionInitDescBuilder.toString(), null);
210
+			
211
+			JavaMethod constructorMethod = new JavaMethod(optionTag.variantOptionClass, JavaMethod.Kind.CONSTRUCTOR, "<init>", true, optionInitDescBuilder.toString(), JavaModifiers.PUBLIC);
212
+			final JavaWriter initWriter = new JavaWriter(optionWriter, constructorMethod, variant, optionInitDescBuilder.toString(), null);
239 213
 			initWriter.start();
240 214
 			initWriter.loadObject(0);
241 215
 			initWriter.dup();
242
-			initWriter.invokeSpecial(variantName, "<init>", "()V");
216
+			initWriter.invokeSpecial(toClass.internalName, "<init>", "()V");
243 217
 			for (int i = 0; i < types.length; ++i) {
244 218
 				initWriter.dup();
245 219
 				initWriter.loadObject(i + 1);
246 220
 
247 221
 				final String descriptor = context.getDescriptor(types[i]);
248
-				initWriter.putField(optionClassName, "Field" + i, descriptor);
222
+				initWriter.putField(optionTag.variantOptionClass.internalName, "field" + i, descriptor);
249 223
 			}
250 224
 			initWriter.pop();
251 225
 			initWriter.ret();
252 226
 			initWriter.end();
253
-
254
-
227
+			
255 228
 			//Denominator for switch-cases
256
-			final JavaWriter getDenominator = new JavaWriter(optionWriter, new JavaMethodInfo(optionClass, "getDenominator", "()I", Modifiers.PUBLIC), null, null, null, "java/lang/Override");
229
+			JavaMethod denominator = new JavaMethod(optionTag.variantOptionClass, JavaMethod.Kind.INSTANCE, "getDenominator", true, "()I", JavaModifiers.PUBLIC);
230
+			final JavaWriter getDenominator = new JavaWriter(optionWriter, denominator, null, null, null, "java/lang/Override");
257 231
 			getDenominator.start();
258 232
 			getDenominator.constant(option.ordinal);
259 233
 			getDenominator.returnInt();
260 234
 			getDenominator.end();
261
-
262
-
235
+			
263 236
 			optionVisitor.end();
264 237
 			optionWriter.visitEnd();
265 238
 			final byte[] byteArray = optionWriter.toByteArray();
266
-			context.register(optionClassName, byteArray);
239
+			context.register(optionTag.variantOptionClass.internalName, byteArray);
267 240
 
268 241
 			//Print the option files, won't be in production
269
-			try (FileOutputStream out = new FileOutputStream(optionClassName + ".class")) {
242
+			try (FileOutputStream out = new FileOutputStream(optionTag.variantOptionClass.internalName.replace('/', '_') + ".class")) {
270 243
 				out.write(byteArray);
271 244
 			} catch (IOException e) {
272 245
 				e.printStackTrace();
@@ -278,7 +251,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
278 251
 			member.accept(visitor);
279 252
 		}
280 253
 
281
-		final JavaWriter superInitWriter = new JavaWriter(writer, new JavaMethodInfo(toClass, "<init>", "()V", Opcodes.ACC_PUBLIC), variant, "()V", null);
254
+		final JavaWriter superInitWriter = new JavaWriter(writer, new JavaMethod(toClass, JavaMethod.Kind.CONSTRUCTOR, "<init>", true, "()V", Opcodes.ACC_PUBLIC), variant, "()V", null);
282 255
 		superInitWriter.start();
283 256
 		superInitWriter.loadObject(0);
284 257
 		superInitWriter.invokeSpecial("java/lang/Object", "<init>", "()V");

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

@@ -10,14 +10,14 @@ 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.JavaMethodInfo;
14
-import org.openzen.zenscript.javabytecode.JavaParameterInfo;
13
+import org.openzen.zenscript.javashared.JavaParameterInfo;
15 14
 import org.openzen.zenscript.javabytecode.compiler.*;
16 15
 
17 16
 import java.util.List;
18 17
 import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
19 18
 import org.openzen.zenscript.javashared.JavaClass;
20 19
 import org.openzen.zenscript.javashared.JavaField;
20
+import org.openzen.zenscript.javashared.JavaMethod;
21 21
 
22 22
 public class JavaMemberVisitor implements MemberVisitor<Void> {
23 23
     private final ClassWriter writer;
@@ -33,7 +33,7 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
33 33
         this.definition = definition;
34 34
 		this.context = context;
35 35
 
36
-        final JavaWriter javaWriter = new JavaWriter(writer, new JavaMethodInfo(toClass, "<clinit>", "()V", 0), definition, null, null);
36
+        final JavaWriter javaWriter = new JavaWriter(writer, new JavaMethod(toClass, JavaMethod.Kind.STATICINIT, "<clinit>", true, "()V", 0), definition, null, null);
37 37
         this.clinitStatementVisitor = new JavaStatementVisitor(context, javaWriter);
38 38
         this.clinitStatementVisitor.start();
39 39
         CompilerUtils.writeDefaultFieldInitializers(context, javaWriter, definition, true);
@@ -41,30 +41,22 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
41 41
 	
42 42
 	@Override
43 43
 	public Void visitConst(ConstMember member) {
44
-        //TODO calc signature
45
-        String signature = null;
46
-        final String descriptor = context.getDescriptor(member.type);
47
-        writer.visitField(CompilerUtils.calcAccess(member.modifiers), member.name, descriptor, signature, null).visitEnd();
48
-        member.setTag(JavaField.class, new JavaField(toClass, member.name, descriptor));
44
+		JavaField field = member.getTag(JavaField.class);
45
+        writer.visitField(CompilerUtils.calcAccess(member.modifiers), field.name, field.descriptor, field.signature, null).visitEnd();
49 46
         return null;
50 47
 	}
51 48
 
52 49
 	@Override
53 50
 	public Void visitField(FieldMember member) {
54
-
55
-        //TODO calc signature
56
-        String signature = null;
57
-        final String descriptor = context.getDescriptor(member.type);
58
-        writer.visitField(CompilerUtils.calcAccess(member.modifiers), member.name, descriptor, signature, null).visitEnd();
59
-        member.setTag(JavaField.class, new JavaField(toClass, member.name, descriptor));
51
+		JavaField field = member.getTag(JavaField.class);
52
+        writer.visitField(CompilerUtils.calcAccess(member.modifiers), field.name, field.descriptor, field.signature, null).visitEnd();
60 53
         return null;
61 54
     }
62 55
 
63 56
     @Override
64 57
     public Void visitConstructor(ConstructorMember member) {
65 58
         final boolean isEnum = definition instanceof EnumDefinition;
66
-        String descriptor = isEnum ? context.getEnumConstructorDescriptor(member.header) : context.getMethodDescriptor(member.header);
67
-        final JavaMethodInfo method = new JavaMethodInfo(toClass, "<init>", descriptor, isEnum ? Opcodes.ACC_PRIVATE : CompilerUtils.calcAccess(member.modifiers));
59
+        final JavaMethod method = member.getTag(JavaMethod.class);
68 60
 
69 61
         final Label constructorStart = new Label();
70 62
         final Label constructorEnd = new Label();
@@ -94,10 +86,9 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
94 86
 				constructorWriter.invokeSpecial(Type.getInternalName(Enum.class), "<init>", "(Ljava/lang/String;I)V");
95 87
 			} else if (definition.getSuperType() == null) {
96 88
 				System.out.println("Writing regular constructor");
97
-				constructorWriter.load(Type.getType(Object.class), 0);
89
+				constructorWriter.loadObject(0);
98 90
 				constructorWriter.invokeSpecial(Type.getInternalName(Object.class), "<init>", "()V");
99 91
 			}
100
-
101 92
         }
102 93
 
103 94
 		member.body.accept(statementVisitor);
@@ -108,7 +99,7 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
108 99
 
109 100
 	@Override
110 101
 	public Void visitDestructor(DestructorMember member) {
111
-		final JavaMethodInfo method = new JavaMethodInfo(toClass, "close", "()V", Opcodes.ACC_PUBLIC);
102
+		final JavaMethod method = new JavaMethod(toClass, JavaMethod.Kind.INSTANCE, "close", true, "()V", Opcodes.ACC_PUBLIC);
112 103
 
113 104
 		final Label constructorStart = new Label();
114 105
 		final Label constructorEnd = new Label();
@@ -129,14 +120,7 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
129 120
         CompilerUtils.tagMethodParameters(context, member.header, member.isStatic());
130 121
 
131 122
         final boolean isAbstract = member.body == null || Modifiers.isAbstract(member.modifiers);
132
-        int modifiers = (isAbstract ? Opcodes.ACC_ABSTRACT : 0)
133
-                | (member.isStatic() ? Opcodes.ACC_STATIC : 0)
134
-                | CompilerUtils.calcAccess(member.modifiers);
135
-        final JavaMethodInfo method = new JavaMethodInfo(
136
-                toClass,
137
-                member.name,
138
-                context.getMethodSignature(member.header),
139
-                modifiers);
123
+        final JavaMethod method = member.getTag(JavaMethod.class);
140 124
 
141 125
         final Label methodStart = new Label();
142 126
         final Label methodEnd = new Label();
@@ -156,8 +140,6 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
156 140
 			methodWriter.label(methodEnd);
157 141
 			statementVisitor.end();
158 142
 		}
159
-
160
-		member.setTag(JavaMethodInfo.class, method);
161 143
 		return null;
162 144
 	}
163 145
 

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

@@ -47,6 +47,13 @@ public class JavaClass implements Comparable<JavaClass> {
47 47
 		return new JavaClass(pkg, internalName, kind, nameParts);
48 48
 	}
49 49
 	
50
+	public static String getNameFromFile(String filename) {
51
+		if (filename.indexOf('.') > 0)
52
+			return filename.substring(0, filename.indexOf('.'));
53
+		else
54
+			return filename;
55
+	}
56
+	
50 57
 	public final JavaClass outer;
51 58
 	
52 59
 	public final String pkg;

+ 4
- 3
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaField.java View File

@@ -12,11 +12,12 @@ package org.openzen.zenscript.javashared;
12 12
 public class JavaField {
13 13
 	public final JavaClass cls;
14 14
 	public final String name;
15
-	public final String signature;
15
+	public final String descriptor;
16
+	public final String signature = null; // TODO: calculate signature too
16 17
 	
17
-	public JavaField(JavaClass cls, String name, String signature) {
18
+	public JavaField(JavaClass cls, String name, String descriptor) {
18 19
 		this.cls = cls;
19 20
 		this.name = name;
20
-		this.signature = signature;
21
+		this.descriptor = descriptor;
21 22
 	}
22 23
 }

+ 29
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaMethod.java View File

@@ -10,6 +10,34 @@ package org.openzen.zenscript.javashared;
10 10
  * @author Hoofdgebruiker
11 11
  */
12 12
 public class JavaMethod {
13
+	public static JavaMethod getConstructor(JavaClass cls, String descriptor, int modifiers) {
14
+		return new JavaMethod(cls, Kind.CONSTRUCTOR, "<init>", true, descriptor, modifiers);
15
+	}
16
+	
17
+	public static JavaMethod getNativeConstructor(JavaClass cls, String descriptor) {
18
+		return new JavaMethod(cls, Kind.CONSTRUCTOR, "<init>", false, descriptor, JavaModifiers.PUBLIC);
19
+	}
20
+	
21
+	public static JavaMethod getDestructor(JavaClass cls, int modifiers) {
22
+		return new JavaMethod(cls, Kind.INSTANCE, "close", true, "()V", modifiers);
23
+	}
24
+	
25
+	public static JavaMethod getStatic(JavaClass cls, String name, String descriptor, int modifiers) {
26
+		return new JavaMethod(cls, Kind.STATIC, name, true, descriptor, modifiers | JavaModifiers.STATIC);
27
+	}
28
+	
29
+	public static JavaMethod getNativeStatic(JavaClass cls, String name, String descriptor) {
30
+		return new JavaMethod(cls, Kind.STATIC, name, false, descriptor, JavaModifiers.STATIC | JavaModifiers.PUBLIC);
31
+	}
32
+	
33
+	public static JavaMethod getVirtual(JavaClass cls, String name, String descriptor, int modifiers) {
34
+		return new JavaMethod(cls, Kind.INSTANCE, name, true, descriptor, modifiers);
35
+	}
36
+	
37
+	public static JavaMethod getNativeVirtual(JavaClass cls, String name, String descriptor) {
38
+		return new JavaMethod(cls, Kind.INSTANCE, name, false, descriptor, JavaModifiers.PUBLIC);
39
+	}
40
+	
13 41
 	public final JavaClass cls;
14 42
 	public final Kind kind;
15 43
 	public final String name;
@@ -42,6 +70,7 @@ public class JavaMethod {
42 70
 	
43 71
 	public enum Kind {
44 72
 		STATIC,
73
+		STATICINIT,
45 74
 		INSTANCE,
46 75
 		EXPANSION,
47 76
 		CONSTRUCTOR,

JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaParameterInfo.java → JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaParameterInfo.java View File

@@ -3,19 +3,17 @@
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.javabytecode;
7
-
8
-import org.objectweb.asm.Type;
6
+package org.openzen.zenscript.javashared;
9 7
 
10 8
 /**
11 9
  * @author Hoofdgebruiker
12 10
  */
13 11
 public class JavaParameterInfo {
14 12
 	public final int index;
15
-	public final Type type;
13
+	public final String typeDescriptor;
16 14
 
17
-	public JavaParameterInfo(int index, Type type) {
15
+	public JavaParameterInfo(int index, String typeDescriptor) {
18 16
 		this.index = index;
19
-		this.type = type;
17
+		this.typeDescriptor = typeDescriptor;
20 18
 	}
21 19
 }

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

@@ -29,7 +29,7 @@ public class JavaSynthesizedClassNamer {
29 29
 	
30 30
 	public static JavaSynthesizedClass createRangeName(RangeTypeID range) {
31 31
 		String signature = getRangeSignature(range);
32
-		String className = signature + "Range";
32
+		String className = signature;
33 33
 		JavaClass cls = new JavaClass("zsynthetic", className, JavaClass.Kind.CLASS);
34 34
 		return new JavaSynthesizedClass(cls, extractTypeParameters(range));
35 35
 	}

+ 3
- 5
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareClassMethodVisitor.java View File

@@ -7,6 +7,7 @@ package org.openzen.zenscript.javashared.prepare;
7 7
 
8 8
 import org.openzen.zenscript.javashared.JavaNativeClass;
9 9
 import org.openzen.zencode.shared.StringExpansion;
10
+import org.openzen.zenscript.codemodel.Modifiers;
10 11
 import org.openzen.zenscript.codemodel.OperatorType;
11 12
 import org.openzen.zenscript.codemodel.annotations.NativeTag;
12 13
 import org.openzen.zenscript.codemodel.member.CallerMember;
@@ -44,20 +45,17 @@ public class JavaPrepareClassMethodVisitor implements MemberVisitor<Void> {
44 45
 	private static final boolean DEBUG_EMPTY = true;
45 46
 	
46 47
 	private final JavaContext context;
47
-	private final String filename;
48 48
 	private final JavaClass cls;
49 49
 	private final JavaNativeClass nativeClass;
50 50
 	private final JavaPrepareDefinitionMemberVisitor memberPreparer;
51 51
 	
52 52
 	public JavaPrepareClassMethodVisitor(
53 53
 			JavaContext context,
54
-			String filename,
55 54
 			JavaClass cls,
56 55
 			JavaNativeClass nativeClass,
57 56
 			JavaPrepareDefinitionMemberVisitor memberPreparer,
58 57
 			boolean startsEmpty) {
59 58
 		this.context = context;
60
-		this.filename = filename;
61 59
 		this.cls = cls;
62 60
 		this.nativeClass = nativeClass;
63 61
 		this.memberPreparer = memberPreparer;
@@ -160,7 +158,7 @@ public class JavaPrepareClassMethodVisitor implements MemberVisitor<Void> {
160 158
 			JavaClass implementationClass = new JavaClass(cls, member.type.accept(new JavaTypeNameVisitor()) + "Implementation", JavaClass.Kind.CLASS);
161 159
 			member.setTag(JavaImplementation.class, new JavaImplementation(false, implementationClass));
162 160
 			
163
-			JavaPrepareClassMethodVisitor visitor = new JavaPrepareClassMethodVisitor(context, filename, implementationClass, null, memberPreparer, true);
161
+			JavaPrepareClassMethodVisitor visitor = new JavaPrepareClassMethodVisitor(context, implementationClass, null, memberPreparer, true);
164 162
 			for (IDefinitionMember m : member.members)
165 163
 				m.accept(visitor);
166 164
 		}
@@ -173,7 +171,7 @@ public class JavaPrepareClassMethodVisitor implements MemberVisitor<Void> {
173 171
 
174 172
 	@Override
175 173
 	public Void visitInnerDefinition(InnerDefinitionMember member) {
176
-		JavaPrepareDefinitionMemberVisitor innerDefinitionPrepare = new JavaPrepareDefinitionMemberVisitor(context, filename);
174
+		JavaPrepareDefinitionMemberVisitor innerDefinitionPrepare = new JavaPrepareDefinitionMemberVisitor(context);
177 175
 		member.innerDefinition.accept(innerDefinitionPrepare);
178 176
 		
179 177
 		if (DEBUG_EMPTY && cls.empty)

+ 3
- 5
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareDefinitionMemberVisitor.java View File

@@ -30,11 +30,9 @@ import org.openzen.zenscript.javashared.JavaModifiers;
30 30
  */
31 31
 public class JavaPrepareDefinitionMemberVisitor implements DefinitionVisitor<JavaClass> {
32 32
 	private final JavaContext context;
33
-	private final String filename;
34 33
 	
35
-	public JavaPrepareDefinitionMemberVisitor(JavaContext context, String filename) {
34
+	public JavaPrepareDefinitionMemberVisitor(JavaContext context) {
36 35
 		this.context = context;
37
-		this.filename = filename;
38 36
 	}
39 37
 	
40 38
 	private boolean isPrepared(HighLevelDefinition definition) {
@@ -90,7 +88,7 @@ public class JavaPrepareDefinitionMemberVisitor implements DefinitionVisitor<Jav
90 88
 			return definition.getTag(JavaClass.class);
91 89
 		
92 90
 		JavaClass cls = definition.getTag(JavaClass.class);
93
-		JavaMethod method = new JavaMethod(cls, JavaMethod.Kind.STATIC, definition.name, true, context.getMethodDescriptor(definition.header), JavaModifiers.getJavaModifiers(definition.modifiers));
91
+		JavaMethod method = JavaMethod.getStatic(cls, definition.name, context.getMethodDescriptor(definition.header), JavaModifiers.getJavaModifiers(definition.modifiers));
94 92
 		definition.caller.setTag(JavaMethod.class, method);
95 93
 		return cls;
96 94
 	}
@@ -138,7 +136,7 @@ public class JavaPrepareDefinitionMemberVisitor implements DefinitionVisitor<Jav
138 136
 	
139 137
 	private void visitClassMembers(HighLevelDefinition definition, JavaClass cls, JavaNativeClass nativeClass, boolean startsEmpty) {
140 138
 		System.out.println("Preparing " + cls.internalName);
141
-		JavaPrepareClassMethodVisitor methodVisitor = new JavaPrepareClassMethodVisitor(context, filename, cls, nativeClass, this, startsEmpty);
139
+		JavaPrepareClassMethodVisitor methodVisitor = new JavaPrepareClassMethodVisitor(context, cls, nativeClass, this, startsEmpty);
142 140
 		for (IDefinitionMember member : definition.members) {
143 141
 			member.accept(methodVisitor);
144 142
 		}

+ 2
- 2
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareDefinitionVisitor.java View File

@@ -251,7 +251,7 @@ public class JavaPrepareDefinitionVisitor implements DefinitionVisitor<JavaClass
251 251
 		if (isPrepared(definition))
252 252
 			return definition.getTag(JavaClass.class);
253 253
 		
254
-		JavaClass cls = new JavaClass(definition.pkg.fullName, filename, JavaClass.Kind.CLASS);
254
+		JavaClass cls = new JavaClass(definition.pkg.fullName, JavaClass.getNameFromFile(filename), JavaClass.Kind.CLASS);
255 255
 		definition.setTag(JavaClass.class, cls);
256 256
 		return cls;
257 257
 	}
@@ -266,7 +266,7 @@ public class JavaPrepareDefinitionVisitor implements DefinitionVisitor<JavaClass
266 266
 			definition.setTag(JavaNativeClass.class, nativeClasses.get(nativeTag.value));
267 267
 		}
268 268
 		
269
-		JavaClass cls = new JavaClass(definition.pkg.fullName, filename, JavaClass.Kind.CLASS);
269
+		JavaClass cls = new JavaClass(definition.pkg.fullName, JavaClass.getNameFromFile(filename), JavaClass.Kind.CLASS);
270 270
 		definition.setTag(JavaClass.class, cls);
271 271
 		return cls;
272 272
 	}

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

@@ -70,7 +70,7 @@ public class JavaSourceFile {
70 70
 	}
71 71
 	
72 72
 	public void prepare(JavaContext context) {
73
-		JavaPrepareDefinitionMemberVisitor visitor = new JavaPrepareDefinitionMemberVisitor(context, file.getName());
73
+		JavaPrepareDefinitionMemberVisitor visitor = new JavaPrepareDefinitionMemberVisitor(context);
74 74
 		
75 75
 		if (mainDefinition != null)
76 76
 			mainDefinition.accept(visitor);

+ 1
- 0
ScriptingExample/build.gradle View File

@@ -16,6 +16,7 @@ if (!hasProperty('mainClass')) {
16 16
 dependencies {
17 17
 	compile project(':Parser')
18 18
 	compile project(':JavaBytecodeCompiler')
19
+	compile project(':JavaShared')
19 20
 	compile project(':CodeFormatter')
20 21
 	compile project(':Validator')
21 22
 	compile project(':Constructor')

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

@@ -9,7 +9,6 @@ import java.util.ArrayList;
9 9
 import java.util.HashMap;
10 10
 import java.util.List;
11 11
 import java.util.Map;
12
-import org.objectweb.asm.Opcodes;
13 12
 import org.openzen.zencode.shared.CodePosition;
14 13
 import org.openzen.zenscript.codemodel.FunctionHeader;
15 14
 import org.openzen.zenscript.codemodel.FunctionParameter;
@@ -29,10 +28,10 @@ import org.openzen.zenscript.codemodel.scope.BaseScope;
29 28
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
30 29
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
31 30
 import org.openzen.zenscript.codemodel.type.ITypeID;
32
-import org.openzen.zenscript.javabytecode.JavaMethodInfo;
33 31
 import org.openzen.zenscript.codemodel.type.ISymbol;
34 32
 import org.openzen.zenscript.javashared.JavaClass;
35 33
 import org.openzen.zenscript.javashared.JavaField;
34
+import org.openzen.zenscript.javashared.JavaMethod;
36 35
 
37 36
 /**
38 37
  *
@@ -46,8 +45,8 @@ public class GlobalRegistry {
46 45
 	
47 46
 	public GlobalRegistry(ZSPackage globals) {
48 47
 		JavaClass jPrintStream = new JavaClass("java.io", "PrintStream", JavaClass.Kind.CLASS);
49
-		JavaMethodInfo printstreamPrintln = new JavaMethodInfo(jPrintStream, "println", "(Ljava/lang/String;)V", Opcodes.ACC_PUBLIC);
50
-		PRINTSTREAM_PRINTLN.setTag(JavaMethodInfo.class, printstreamPrintln);
48
+		JavaMethod printstreamPrintln = JavaMethod.getNativeVirtual(jPrintStream, "println", "(Ljava/lang/String;)V");
49
+		PRINTSTREAM_PRINTLN.setTag(JavaMethod.class, printstreamPrintln);
51 50
 		
52 51
 		JavaClass jSystem = new JavaClass("java.lang", "System", JavaClass.Kind.CLASS);
53 52
 		SYSTEM_OUT.setTag(JavaField.class, new JavaField(jSystem, "out", "Ljava/io/PrintStream;"));
@@ -59,12 +58,12 @@ public class GlobalRegistry {
59 58
 		{
60 59
 			// eg. package my.package with a class MyClass with a single native method test() returning a string
61 60
 			// the visitors can then during compilation check if a method is an instance of NativeMethodMember and treat it accordingly
62
-			ZSPackage packageMyPackage = rootPackage.getOrCreatePackage("my").getOrCreatePackage("package");
61
+			ZSPackage packageMyPackage = rootPackage.getOrCreatePackage("my").getOrCreatePackage("test");
63 62
 			ClassDefinition myClassDefinition = new ClassDefinition(CodePosition.NATIVE, packageMyPackage, "MyClass", Modifiers.PUBLIC, null);
64 63
 			JavaClass myClassInfo = new JavaClass("my.test", "MyClass", JavaClass.Kind.CLASS);
65 64
 			
66 65
 			MethodMember member = new MethodMember(CodePosition.NATIVE, myClassDefinition, Modifiers.PUBLIC, "test", new FunctionHeader(BasicTypeID.STRING), null);
67
-			member.setTag(JavaMethodInfo.class, new JavaMethodInfo(myClassInfo, "test", "()Ljava/lang/String;", Opcodes.ACC_PUBLIC));
66
+			member.setTag(JavaMethod.class, JavaMethod.getNativeVirtual(myClassInfo, "test", "()Ljava/lang/String;"));
68 67
 			myClassDefinition.addMember(member);
69 68
 			
70 69
 			packageMyPackage.register(myClassDefinition);

Loading…
Cancel
Save