Browse Source

Made the JavaClass#Iterator a supplier, fixes multiple engine runs

Jared 5 years ago
parent
commit
b10277cda2
No account linked to committer's email address

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

9
 import org.openzen.zenscript.javashared.JavaMethod;
9
 import org.openzen.zenscript.javashared.JavaMethod;
10
 import org.openzen.zenscript.javashared.JavaModifiers;
10
 import org.openzen.zenscript.javashared.JavaModifiers;
11
 
11
 
12
-import java.util.HashMap;
13
 import java.util.Map;
12
 import java.util.Map;
14
 @SuppressWarnings("Duplicates")
13
 @SuppressWarnings("Duplicates")
15
 public class JavaForeachWriter {
14
 public class JavaForeachWriter {
92
         
91
         
93
         javaWriter.label(startLabel);
92
         javaWriter.label(startLabel);
94
         javaWriter.dup();
93
         javaWriter.dup();
95
-        javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.ITERATOR, "hasNext", "()Z", 0));
94
+        javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.ITERATOR.get(), "hasNext", "()Z", 0));
96
         javaWriter.ifEQ(endLabel);
95
         javaWriter.ifEQ(endLabel);
97
         javaWriter.dup();
96
         javaWriter.dup();
98
-        javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.ITERATOR, "next", "()Ljava/lang/Object;", 0));
97
+        javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.ITERATOR.get(), "next", "()Ljava/lang/Object;", 0));
99
         
98
         
100
         final JavaLocalVariableInfo keyVariable = javaWriter.getLocalVariable(variables[0].variable);
99
         final JavaLocalVariableInfo keyVariable = javaWriter.getLocalVariable(variables[0].variable);
101
         this.downCast(0, keyVariable.type);
100
         this.downCast(0, keyVariable.type);
110
 
109
 
111
 		javaWriter.label(startLabel);
110
 		javaWriter.label(startLabel);
112
 		javaWriter.dup();
111
 		javaWriter.dup();
113
-		javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.ITERATOR, "hasNext", "()Z", 0));
112
+		javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.ITERATOR.get(), "hasNext", "()Z", 0));
114
 		javaWriter.ifEQ(endLabel);
113
 		javaWriter.ifEQ(endLabel);
115
 		javaWriter.dup();
114
 		javaWriter.dup();
116
-		javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.ITERATOR, "next", "()Ljava/lang/Object;", 0));
115
+		javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.ITERATOR.get(), "next", "()Ljava/lang/Object;", 0));
117
 		javaWriter.checkCast(Type.getType(Map.Entry.class));
116
 		javaWriter.checkCast(Type.getType(Map.Entry.class));
118
 		javaWriter.dup(false);
117
 		javaWriter.dup(false);
119
 
118
 

+ 4
- 2
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaClass.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.javashared;
6
 package org.openzen.zenscript.javashared;
7
 
7
 
8
-import java.util.Arrays;
9
 import stdlib.Strings;
8
 import stdlib.Strings;
10
 
9
 
10
+import java.util.Arrays;
11
+import java.util.function.Supplier;
12
+
11
 /**
13
 /**
12
  *
14
  *
13
  * @author Hoofdgebruiker
15
  * @author Hoofdgebruiker
20
 	public static final JavaClass CLOSEABLE = new JavaClass("java.lang", "AutoCloseable", Kind.INTERFACE);
22
 	public static final JavaClass CLOSEABLE = new JavaClass("java.lang", "AutoCloseable", Kind.INTERFACE);
21
 	public static final JavaClass MAP = new JavaClass("java.util", "Map", JavaClass.Kind.INTERFACE);
23
 	public static final JavaClass MAP = new JavaClass("java.util", "Map", JavaClass.Kind.INTERFACE);
22
 	public static final JavaClass HASHMAP = new JavaClass("java.util", "HashMap", JavaClass.Kind.CLASS);
24
 	public static final JavaClass HASHMAP = new JavaClass("java.util", "HashMap", JavaClass.Kind.CLASS);
23
-	public static final JavaClass ITERATOR = new JavaClass("java.util", "Iterator", JavaClass.Kind.INTERFACE);
25
+	public static final Supplier<JavaClass> ITERATOR = () -> new JavaClass("java.util", "Iterator", JavaClass.Kind.INTERFACE);
24
 	public static final JavaClass ARRAYS = new JavaClass("java.util", "Arrays", Kind.CLASS);
26
 	public static final JavaClass ARRAYS = new JavaClass("java.util", "Arrays", Kind.CLASS);
25
 	
27
 	
26
 	public static final JavaClass BOOLEAN = new JavaClass("java.lang", "Boolean", Kind.CLASS);
28
 	public static final JavaClass BOOLEAN = new JavaClass("java.lang", "Boolean", Kind.CLASS);

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

95
 		}
95
 		}
96
 		
96
 		
97
 		{
97
 		{
98
-			JavaNativeClass iterator = new JavaNativeClass(JavaClass.ITERATOR);
98
+			JavaNativeClass iterator = new JavaNativeClass(JavaClass.ITERATOR.get());
99
 			iterator.addMethod("empty", new JavaMethod(JavaClass.COLLECTIONS, JavaMethod.Kind.STATIC, "emptyIterator", false, "()Ljava/lang/Iterator;", JavaModifiers.STATIC | JavaModifiers.PUBLIC, false));
99
 			iterator.addMethod("empty", new JavaMethod(JavaClass.COLLECTIONS, JavaMethod.Kind.STATIC, "emptyIterator", false, "()Ljava/lang/Iterator;", JavaModifiers.STATIC | JavaModifiers.PUBLIC, false));
100
 			iterator.addInstanceMethod("hasNext", "hasNext", "()Z");
100
 			iterator.addInstanceMethod("hasNext", "hasNext", "()Z");
101
 			iterator.addInstanceMethod("next", "next", "()Ljava/lang/Object;");
101
 			iterator.addInstanceMethod("next", "next", "()Ljava/lang/Object;");

Loading…
Cancel
Save