Przeglądaj źródła

Fixed something with iterables (but I forgot what)

Stan Hebben 4 lat temu
rodzic
commit
4d53b6cc85

+ 2
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/BuiltinID.java Wyświetl plik

@@ -527,7 +527,8 @@ public enum BuiltinID {
527 527
 	ITERATOR_ARRAY_KEY_VALUES,
528 528
 	ITERATOR_ASSOC_KEYS,
529 529
 	ITERATOR_ASSOC_KEY_VALUES,
530
-	ITERATOR_STRING_CHARS;
530
+	ITERATOR_STRING_CHARS,
531
+	ITERATOR_ITERABLE;
531 532
 	
532 533
 	private static final BuiltinID[] VALUES = values();
533 534
 	public static BuiltinID get(int ordinal) {

+ 5
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/BaseComponentGroup.java Wyświetl plik

@@ -19,6 +19,11 @@ public abstract class BaseComponentGroup implements DComponent {
19 19
 	
20 20
 	protected abstract DComponent findChild(Predicate<DComponent> predicate);
21 21
 	
22
+	protected void onComponentRemoved(DComponent component) {
23
+		if (hovering == component)
24
+			hovering = null;
25
+	}
26
+	
22 27
 	@Override
23 28
 	public void onMouseEnter(DMouseEvent e) {
24 29
 		DComponent target = getComponent(e.x, e.y);

+ 3
- 1
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedView.java Wyświetl plik

@@ -60,8 +60,10 @@ public class TabbedView extends BaseComponentGroup {
60 60
 		tabs.addListener(new TabListListener());
61 61
 		
62 62
 		currentTab.addListener((oldValue, newValue) -> {
63
-			if (oldValue != null)
63
+			if (oldValue != null) {
64 64
 				oldValue.content.unmount();
65
+				onComponentRemoved(oldValue.content);
66
+			}
65 67
 			if (newValue != null)
66 68
 				newValue.content.mount(context);
67 69
 			

+ 1
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedViewTab.java Wyświetl plik

@@ -165,6 +165,7 @@ public class TabbedViewTab implements DComponent {
165 165
 	public void close() {
166 166
 		titleListener.close();
167 167
 		updatedListener.close();
168
+		currentTabListener.close();
168 169
 		
169 170
 		unmount();
170 171
 	}

+ 3
- 1
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/SourceEditor.java Wyświetl plik

@@ -299,6 +299,7 @@ public class SourceEditor implements DComponent {
299 299
 	
300 300
 	@Override
301 301
 	public void onMouseExit(DMouseEvent e) {
302
+		
302 303
 		context.getUIContext().setCursor(DUIContext.Cursor.NORMAL);
303 304
 	}
304 305
 	
@@ -816,7 +817,8 @@ public class SourceEditor implements DComponent {
816 817
 		@Override
817 818
 		public void onLineChanged(int index) {
818 819
 			if (bounds != null) {
819
-				Destructible.close(drawnTokens.get(index));
820
+				if (index < drawnTokens.size())
821
+					Destructible.close(drawnTokens.get(index));
820 822
 				
821 823
 				TokenLine line = tokens.getLine(index);
822 824
 				drawnTokens.set(index, lineToTokens(line));

+ 14
- 2
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaForeachWriter.java Wyświetl plik

@@ -8,7 +8,6 @@ import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
8 8
 import org.openzen.zenscript.javashared.JavaClass;
9 9
 import org.openzen.zenscript.javashared.JavaMethod;
10 10
 
11
-import java.util.HashMap;
12 11
 import java.util.Map;
13 12
 
14 13
 public class JavaForeachWriter {
@@ -60,6 +59,20 @@ public class JavaForeachWriter {
60 59
 		handleArray(javaWriter.local(int.class), javaWriter.getLocalVariable(variables[0].variable));
61 60
 	}
62 61
 
62
+	public void visitIteratorIterator(Type targetType) {
63
+		javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.ITERABLE, "iterator", "()Ljava/lang/Iterator;", 0));
64
+		javaWriter.label(startLabel);
65
+		javaWriter.dup();
66
+		javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.ITERATOR, "hasNext", "()Z", 0));
67
+		javaWriter.ifEQ(endLabel);
68
+		javaWriter.invokeInterface(JavaMethod.getVirtual(JavaClass.ITERATOR, "next", "()Ljava/lang/Object;", 0));
69
+		javaWriter.checkCast(targetType);
70
+		final JavaLocalVariableInfo variable = javaWriter.getLocalVariable(variables[0].variable);
71
+		javaWriter.store(variable.type, variable.local);
72
+
73
+		content.accept(statementVisitor);
74
+	}
75
+
63 76
 	private void handleArray(final int z, final JavaLocalVariableInfo arrayTypeInfo) {
64 77
 		javaWriter.iConst0();
65 78
 		javaWriter.storeInt(z);
@@ -73,7 +86,6 @@ public class JavaForeachWriter {
73 86
 		javaWriter.ifICmpLE(endLabel);
74 87
 		javaWriter.loadInt(z);
75 88
 
76
-
77 89
 		javaWriter.arrayLoad(arrayTypeInfo.type);
78 90
 		javaWriter.store(arrayTypeInfo.type, arrayTypeInfo.local);
79 91
 		content.accept(statementVisitor);

+ 3
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java Wyświetl plik

@@ -135,6 +135,9 @@ public class JavaStatementVisitor implements StatementVisitor<Boolean> {
135 135
 				case ITERATOR_STRING_CHARS:
136 136
 					iteratorWriter.visitStringCharacterIterator();
137 137
 					break;
138
+				case ITERATOR_ITERABLE:
139
+					iteratorWriter.visitIteratorIterator(context.getType(statement.loopVariables[0].type));
140
+					break;
138 141
 				default:
139 142
 					throw new IllegalArgumentException("Invalid iterator: " + statement.iterator.target.getBuiltin());
140 143
 			}

+ 1
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaClass.java Wyświetl plik

@@ -21,6 +21,7 @@ public class JavaClass implements Comparable<JavaClass> {
21 21
 	public static final JavaClass MAP = new JavaClass("java.util", "Map", JavaClass.Kind.INTERFACE);
22 22
 	public static final JavaClass HASHMAP = new JavaClass("java.util", "HashMap", JavaClass.Kind.CLASS);
23 23
 	public static final JavaClass ITERATOR = new JavaClass("java.util", "Iterator", JavaClass.Kind.INTERFACE);
24
+	public static final JavaClass ITERABLE = new JavaClass("java.lang", "Iterable", Kind.INTERFACE);
24 25
 	public static final JavaClass ARRAYS = new JavaClass("java.util", "Arrays", Kind.CLASS);
25 26
 	
26 27
 	public static final JavaClass BOOLEAN = new JavaClass("java.lang", "Boolean", Kind.CLASS);

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunctionHeader.java Wyświetl plik

@@ -56,7 +56,7 @@ public class ParsedFunctionHeader {
56 56
 				boolean variadic = tokens.optional(T_DOT3) != null;
57 57
 				
58 58
 				IParsedType type = ParsedTypeBasic.UNDETERMINED;
59
-				if (tokens.optional(K_AS) != null) {
59
+				if (tokens.optional(K_AS) != null || tokens.optional(T_COLON) != null) {
60 60
 					type = IParsedType.parse(tokens);
61 61
 				}
62 62
 				ParsedExpression defaultValue = null;

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatement.java Wyświetl plik

@@ -99,7 +99,7 @@ public abstract class ParsedStatement {
99 99
 
100 100
 				IParsedType type = null;
101 101
 				ParsedExpression initializer = null;
102
-				if (parser.optional(K_AS) != null) {
102
+				if (parser.optional(K_AS) != null || parser.optional(T_COLON) != null) {
103 103
 					type = IParsedType.parse(parser);
104 104
 				}
105 105
 				if (parser.optional(T_ASSIGN) != null) {

Ładowanie…
Anuluj
Zapisz