Explorar el Código

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

Jared hace 5 años
padre
commit
b10277cda2
No account linked to committer's email address

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

@@ -9,7 +9,6 @@ import org.openzen.zenscript.javashared.JavaClass;
9 9
 import org.openzen.zenscript.javashared.JavaMethod;
10 10
 import org.openzen.zenscript.javashared.JavaModifiers;
11 11
 
12
-import java.util.HashMap;
13 12
 import java.util.Map;
14 13
 @SuppressWarnings("Duplicates")
15 14
 public class JavaForeachWriter {
@@ -92,10 +91,10 @@ public class JavaForeachWriter {
92 91
         
93 92
         javaWriter.label(startLabel);
94 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 95
         javaWriter.ifEQ(endLabel);
97 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 99
         final JavaLocalVariableInfo keyVariable = javaWriter.getLocalVariable(variables[0].variable);
101 100
         this.downCast(0, keyVariable.type);
@@ -110,10 +109,10 @@ public class JavaForeachWriter {
110 109
 
111 110
 		javaWriter.label(startLabel);
112 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 113
 		javaWriter.ifEQ(endLabel);
115 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 116
 		javaWriter.checkCast(Type.getType(Map.Entry.class));
118 117
 		javaWriter.dup(false);
119 118
 

+ 4
- 2
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaClass.java Ver fichero

@@ -5,9 +5,11 @@
5 5
  */
6 6
 package org.openzen.zenscript.javashared;
7 7
 
8
-import java.util.Arrays;
9 8
 import stdlib.Strings;
10 9
 
10
+import java.util.Arrays;
11
+import java.util.function.Supplier;
12
+
11 13
 /**
12 14
  *
13 15
  * @author Hoofdgebruiker
@@ -20,7 +22,7 @@ public class JavaClass implements Comparable<JavaClass> {
20 22
 	public static final JavaClass CLOSEABLE = new JavaClass("java.lang", "AutoCloseable", Kind.INTERFACE);
21 23
 	public static final JavaClass MAP = new JavaClass("java.util", "Map", JavaClass.Kind.INTERFACE);
22 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 26
 	public static final JavaClass ARRAYS = new JavaClass("java.util", "Arrays", Kind.CLASS);
25 27
 	
26 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 Ver fichero

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

Loading…
Cancelar
Guardar