Skip to content

Commit 4d53b6c

Browse files
committed
Fixed something with iterables (but I forgot what)
1 parent 84d5a1d commit 4d53b6c

File tree

10 files changed

+34
-7
lines changed

10 files changed

+34
-7
lines changed

CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/BuiltinID.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,8 @@ public enum BuiltinID {
527527
ITERATOR_ARRAY_KEY_VALUES,
528528
ITERATOR_ASSOC_KEYS,
529529
ITERATOR_ASSOC_KEY_VALUES,
530-
ITERATOR_STRING_CHARS;
530+
ITERATOR_STRING_CHARS,
531+
ITERATOR_ITERABLE;
531532

532533
private static final BuiltinID[] VALUES = values();
533534
public static BuiltinID get(int ordinal) {

DrawableGui/src/main/java/org/openzen/drawablegui/BaseComponentGroup.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public abstract class BaseComponentGroup implements DComponent {
1919

2020
protected abstract DComponent findChild(Predicate<DComponent> predicate);
2121

22+
protected void onComponentRemoved(DComponent component) {
23+
if (hovering == component)
24+
hovering = null;
25+
}
26+
2227
@Override
2328
public void onMouseEnter(DMouseEvent e) {
2429
DComponent target = getComponent(e.x, e.y);

IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedView.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ public TabbedView(DStyleClass styleClass) {
6060
tabs.addListener(new TabListListener());
6161

6262
currentTab.addListener((oldValue, newValue) -> {
63-
if (oldValue != null)
63+
if (oldValue != null) {
6464
oldValue.content.unmount();
65+
onComponentRemoved(oldValue.content);
66+
}
6567
if (newValue != null)
6668
newValue.content.mount(context);
6769

IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedViewTab.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public void setBounds(DIRectangle bounds) {
165165
public void close() {
166166
titleListener.close();
167167
updatedListener.close();
168+
currentTabListener.close();
168169

169170
unmount();
170171
}

IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/SourceEditor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ public void onMouseEnter(DMouseEvent e) {
299299

300300
@Override
301301
public void onMouseExit(DMouseEvent e) {
302+
302303
context.getUIContext().setCursor(DUIContext.Cursor.NORMAL);
303304
}
304305

@@ -816,7 +817,8 @@ public void onLineInserted(int index) {
816817
@Override
817818
public void onLineChanged(int index) {
818819
if (bounds != null) {
819-
Destructible.close(drawnTokens.get(index));
820+
if (index < drawnTokens.size())
821+
Destructible.close(drawnTokens.get(index));
820822

821823
TokenLine line = tokens.getLine(index);
822824
drawnTokens.set(index, lineToTokens(line));

JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaForeachWriter.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import org.openzen.zenscript.javashared.JavaClass;
99
import org.openzen.zenscript.javashared.JavaMethod;
1010

11-
import java.util.HashMap;
1211
import java.util.Map;
1312

1413
public class JavaForeachWriter {
@@ -60,6 +59,20 @@ public void visitStringCharacterIterator() {
6059
handleArray(javaWriter.local(int.class), javaWriter.getLocalVariable(variables[0].variable));
6160
}
6261

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+
6376
private void handleArray(final int z, final JavaLocalVariableInfo arrayTypeInfo) {
6477
javaWriter.iConst0();
6578
javaWriter.storeInt(z);
@@ -73,7 +86,6 @@ private void handleArray(final int z, final JavaLocalVariableInfo arrayTypeInfo)
7386
javaWriter.ifICmpLE(endLabel);
7487
javaWriter.loadInt(z);
7588

76-
7789
javaWriter.arrayLoad(arrayTypeInfo.type);
7890
javaWriter.store(arrayTypeInfo.type, arrayTypeInfo.local);
7991
content.accept(statementVisitor);

JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ public Boolean visitForeach(ForeachStatement statement) {
135135
case ITERATOR_STRING_CHARS:
136136
iteratorWriter.visitStringCharacterIterator();
137137
break;
138+
case ITERATOR_ITERABLE:
139+
iteratorWriter.visitIteratorIterator(context.getType(statement.loopVariables[0].type));
140+
break;
138141
default:
139142
throw new IllegalArgumentException("Invalid iterator: " + statement.iterator.target.getBuiltin());
140143
}

JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaClass.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class JavaClass implements Comparable<JavaClass> {
2121
public static final JavaClass MAP = new JavaClass("java.util", "Map", JavaClass.Kind.INTERFACE);
2222
public static final JavaClass HASHMAP = new JavaClass("java.util", "HashMap", JavaClass.Kind.CLASS);
2323
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);
2425
public static final JavaClass ARRAYS = new JavaClass("java.util", "Arrays", Kind.CLASS);
2526

2627
public static final JavaClass BOOLEAN = new JavaClass("java.lang", "Boolean", Kind.CLASS);

Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunctionHeader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static ParsedFunctionHeader parse(ZSTokenParser tokens) throws ParseExcep
5656
boolean variadic = tokens.optional(T_DOT3) != null;
5757

5858
IParsedType type = ParsedTypeBasic.UNDETERMINED;
59-
if (tokens.optional(K_AS) != null) {
59+
if (tokens.optional(K_AS) != null || tokens.optional(T_COLON) != null) {
6060
type = IParsedType.parse(tokens);
6161
}
6262
ParsedExpression defaultValue = null;

Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public static ParsedStatement parse(ZSTokenParser parser, ParsedAnnotation[] ann
9999

100100
IParsedType type = null;
101101
ParsedExpression initializer = null;
102-
if (parser.optional(K_AS) != null) {
102+
if (parser.optional(K_AS) != null || parser.optional(T_COLON) != null) {
103103
type = IParsedType.parse(parser);
104104
}
105105
if (parser.optional(T_ASSIGN) != null) {

0 commit comments

Comments
 (0)