Przeglądaj źródła

More java stuff

- If/Else
- While do and do While
- For
kindlich 6 lat temu
rodzic
commit
599bc9ac36
Nie znaleziono w bazie danych klucza dla tego podpisu
27 zmienionych plików z 319 dodań i 50 usunięć
  1. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/BreakStatement.java
  2. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ContinueStatement.java
  3. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ForeachStatement.java
  4. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/LoopStatement.java
  5. 12
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/implementations/IntRange.java
  6. 11
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
  7. 85
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaForeachVisitor.java
  8. 82
    4
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java
  9. 2
    7
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaTypeClassVisitor.java
  10. 20
    2
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java
  11. 2
    2
      Linker/src/main/java/org/openzen/zenscript/linker/BaseScope.java
  12. 2
    2
      Linker/src/main/java/org/openzen/zenscript/linker/BlockScope.java
  13. 3
    2
      Linker/src/main/java/org/openzen/zenscript/linker/DefinitionScope.java
  14. 2
    2
      Linker/src/main/java/org/openzen/zenscript/linker/ExpressionScope.java
  15. 2
    2
      Linker/src/main/java/org/openzen/zenscript/linker/FileScope.java
  16. 2
    2
      Linker/src/main/java/org/openzen/zenscript/linker/ForeachScope.java
  17. 2
    2
      Linker/src/main/java/org/openzen/zenscript/linker/FunctionScope.java
  18. 2
    2
      Linker/src/main/java/org/openzen/zenscript/linker/GenericFunctionScope.java
  19. 2
    2
      Linker/src/main/java/org/openzen/zenscript/linker/GlobalScriptScope.java
  20. 2
    2
      Linker/src/main/java/org/openzen/zenscript/linker/ImplementationScope.java
  21. 2
    2
      Linker/src/main/java/org/openzen/zenscript/linker/LambdaScope.java
  22. 1
    2
      Linker/src/main/java/org/openzen/zenscript/linker/LoopScope.java
  23. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementBreak.java
  24. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementContinue.java
  25. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementDoWhile.java
  26. 69
    1
      ScriptingExample/scripts/moreHellos.zs
  27. 2
    2
      ScriptingExample/scripts/statements.zs

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/BreakStatement.java Wyświetl plik

@@ -12,9 +12,9 @@ import org.openzen.zenscript.shared.CodePosition;
12 12
  * @author Hoofdgebruiker
13 13
  */
14 14
 public class BreakStatement extends Statement {
15
-	public final Statement target;
15
+	public final LoopStatement target;
16 16
 	
17
-	public BreakStatement(CodePosition position, Statement target) {
17
+	public BreakStatement(CodePosition position, LoopStatement target) {
18 18
 		super(position);
19 19
 		
20 20
 		this.target = target;

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ContinueStatement.java Wyświetl plik

@@ -12,9 +12,9 @@ import org.openzen.zenscript.shared.CodePosition;
12 12
  * @author Hoofdgebruiker
13 13
  */
14 14
 public class ContinueStatement extends Statement {
15
-	public final Statement target;
15
+	public final LoopStatement target;
16 16
 	
17
-	public ContinueStatement(CodePosition position, Statement target) {
17
+	public ContinueStatement(CodePosition position, LoopStatement target) {
18 18
 		super(position);
19 19
 		
20 20
 		this.target = target;

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ForeachStatement.java Wyświetl plik

@@ -13,14 +13,14 @@ import org.openzen.zenscript.shared.CodePosition;
13 13
  *
14 14
  * @author Hoofdgebruiker
15 15
  */
16
-public class ForeachStatement extends Statement {
16
+public class ForeachStatement extends LoopStatement {
17 17
 	public final VarStatement[] loopVariables;
18 18
 	public final Expression list;
19 19
 	public final IIteratorMember iterator;
20 20
 	public Statement content;
21 21
 	
22 22
 	public ForeachStatement(CodePosition position, VarStatement[] loopVariables, IIteratorMember iterator, Expression list) {
23
-		super(position);
23
+		super(position, loopVariables[0].name);
24 24
 		
25 25
 		this.loopVariables = loopVariables;
26 26
 		this.list = list;

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/LoopStatement.java Wyświetl plik

@@ -12,7 +12,7 @@ import org.openzen.zenscript.shared.CodePosition;
12 12
  * @author Hoofdgebruiker
13 13
  */
14 14
 public abstract class LoopStatement extends Statement {
15
-	public final String label;
15
+	public String label;
16 16
 	
17 17
 	public LoopStatement(CodePosition position, String label) {
18 18
 		super(position);

+ 12
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/implementations/IntRange.java Wyświetl plik

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

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

@@ -1,9 +1,11 @@
1 1
 package org.openzen.zenscript.javabytecode.compiler;
2 2
 
3
+import com.sun.javafx.image.IntPixelGetter;
3 4
 import org.objectweb.asm.Type;
4 5
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
5 6
 import org.openzen.zenscript.codemodel.expression.*;
6 7
 import org.openzen.zenscript.codemodel.member.DefinitionMember;
8
+import org.openzen.zenscript.implementations.IntRange;
7 9
 import org.openzen.zenscript.javabytecode.JavaBytecodeImplementation;
8 10
 import org.openzen.zenscript.javabytecode.JavaFieldInfo;
9 11
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
@@ -308,6 +310,15 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
308 310
 
309 311
     @Override
310 312
     public Void visitRange(RangeExpression expression) {
313
+        if(expression.from.type.accept(JavaTypeClassVisitor.INSTANCE) != int.class)
314
+            throw new CompileException(expression.position, CompileExceptionCode.INTERNAL_ERROR, "Only integer ranges supported");
315
+        javaWriter.newObject(IntRange.class);
316
+        javaWriter.dup();
317
+        expression.from.accept(this);
318
+        expression.to.accept(this);
319
+        System.out.println(IntRange.class.getName());
320
+        javaWriter.invokeSpecial("org/openzen/zenscript/implementations/IntRange", "<init>", "(II)V");
321
+
311 322
         return null;
312 323
     }
313 324
 

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

@@ -0,0 +1,85 @@
1
+package org.openzen.zenscript.javabytecode.compiler;
2
+
3
+import org.objectweb.asm.Label;
4
+import org.openzen.zenscript.codemodel.iterator.ForeachIteratorVisitor;
5
+import org.openzen.zenscript.codemodel.member.CustomIteratorMember;
6
+import org.openzen.zenscript.codemodel.statement.Statement;
7
+import org.openzen.zenscript.codemodel.statement.VarStatement;
8
+import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
9
+
10
+public class JavaForeachVisitor implements ForeachIteratorVisitor<Void> {
11
+
12
+    private final JavaWriter javaWriter;
13
+    private final VarStatement[] variables;
14
+    private final Statement content;
15
+    private final Label startLabel;
16
+    private final Label endLabel;
17
+    private final JavaStatementVisitor statementVisitor;
18
+
19
+    public JavaForeachVisitor(JavaStatementVisitor statementVisitor, VarStatement[] variables, Statement content, Label start, Label end) {
20
+        this.statementVisitor = statementVisitor;
21
+        this.javaWriter = statementVisitor.getJavaWriter();
22
+        this.variables = variables;
23
+        this.content = content;
24
+        this.startLabel = start;
25
+        this.endLabel = end;
26
+    }
27
+
28
+    @Override
29
+    public Void visitIntRange() {
30
+        javaWriter.dup();
31
+        javaWriter.getField("org/openzen/zenscript/implementations/IntRange", "max", "I");
32
+        javaWriter.swap();
33
+        javaWriter.getField("org/openzen/zenscript/implementations/IntRange", "min", "I");
34
+
35
+        final int z = variables[0].getTag(JavaLocalVariableInfo.class).local;
36
+        javaWriter.storeInt(z);
37
+        javaWriter.label(startLabel);
38
+        javaWriter.dup();
39
+        javaWriter.loadInt(z);
40
+        javaWriter.ifICmpLE(endLabel);
41
+
42
+        content.accept(statementVisitor);
43
+        javaWriter.iinc(z);
44
+
45
+
46
+        return null;
47
+    }
48
+
49
+    @Override
50
+    public Void visitArrayValueIterator() {
51
+        handleArray(javaWriter.local(int.class), variables[0].getTag(JavaLocalVariableInfo.class));
52
+        return null;
53
+    }
54
+
55
+    @Override
56
+    public Void visitArrayKeyValueIterator() {
57
+        handleArray(variables[0].getTag(JavaLocalVariableInfo.class).local, variables[1].getTag(JavaLocalVariableInfo.class));
58
+        return null;
59
+    }
60
+
61
+    private void handleArray(final int z, final JavaLocalVariableInfo arrayTypeInfo) {
62
+        javaWriter.iConst0();
63
+        javaWriter.storeInt(z);
64
+
65
+        javaWriter.label(startLabel);
66
+        javaWriter.dup();
67
+        javaWriter.dup();
68
+        javaWriter.arrayLength();
69
+        javaWriter.loadInt(z);
70
+
71
+        javaWriter.ifICmpLE(endLabel);
72
+        javaWriter.loadInt(z);
73
+
74
+
75
+        javaWriter.arrayLoad(arrayTypeInfo.type);
76
+        javaWriter.store(arrayTypeInfo.type, arrayTypeInfo.local);
77
+        content.accept(statementVisitor);
78
+        javaWriter.iinc(z);
79
+    }
80
+
81
+    @Override
82
+    public Void visitCustomIterator() {
83
+        return null;
84
+    }
85
+}

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

@@ -1,5 +1,6 @@
1 1
 package org.openzen.zenscript.javabytecode.compiler;
2 2
 
3
+import org.objectweb.asm.Label;
3 4
 import org.objectweb.asm.Type;
4 5
 import org.openzen.zenscript.codemodel.statement.*;
5 6
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
@@ -11,7 +12,7 @@ public class JavaStatementVisitor implements StatementVisitor<Void> {
11 12
     public JavaStatementVisitor(final JavaWriter javaWriter) {
12 13
 
13 14
         this.javaWriter = javaWriter;
14
-        this.expressionVisitor = new JavaExpressionVisitor( javaWriter);
15
+        this.expressionVisitor = new JavaExpressionVisitor(javaWriter);
15 16
     }
16 17
 
17 18
     @Override
@@ -24,21 +25,38 @@ public class JavaStatementVisitor implements StatementVisitor<Void> {
24 25
 
25 26
     @Override
26 27
     public Void visitBreak(BreakStatement statement) {
28
+        javaWriter.goTo(javaWriter.getNamedLabel(statement.target.label + "_end"));
27 29
         return null;
28 30
     }
29 31
 
30 32
     @Override
31 33
     public Void visitContinue(ContinueStatement statement) {
34
+        javaWriter.goTo(javaWriter.getNamedLabel(statement.target.label + "_start"));
32 35
         return null;
33 36
     }
34 37
 
35 38
     @Override
36 39
     public Void visitDoWhile(DoWhileStatement statement) {
40
+        Label start = new Label();
41
+        Label end = new Label();
42
+        if (statement.label == null)
43
+            statement.label = javaWriter.createLabelName() + "DoWhile";
44
+        javaWriter.putNamedLabel(start, statement.label + "_start");
45
+        javaWriter.putNamedLabel(end, statement.label + "_end");
46
+        javaWriter.label(start);
47
+        statement.content.accept(this);
48
+
49
+        statement.condition.accept(expressionVisitor);
50
+        javaWriter.ifNE(start);
51
+
52
+        //Only needed for break statements, should be nop if not used
53
+        javaWriter.label(end);
37 54
         return null;
38 55
     }
39 56
 
40 57
     @Override
41 58
     public Void visitEmpty(EmptyStatement statement) {
59
+        //No-Op
42 60
         return null;
43 61
     }
44 62
 
@@ -50,11 +68,51 @@ public class JavaStatementVisitor implements StatementVisitor<Void> {
50 68
 
51 69
     @Override
52 70
     public Void visitForeach(ForeachStatement statement) {
71
+        //Create Labels
72
+        Label start = new Label();
73
+        Label end = new Label();
74
+        if (statement.label == null) {
75
+            statement.label = javaWriter.createLabelName() + "ForEach";
76
+        }
77
+        javaWriter.putNamedLabel(start, statement.label + "_start");
78
+        javaWriter.putNamedLabel(end, statement.label + "_end");
79
+
80
+
81
+        //Compile Array/Collection
82
+        statement.list.accept(expressionVisitor);
83
+
84
+        //Create local variables
85
+        for (VarStatement variable : statement.loopVariables) {
86
+            final Type type = Type.getType(variable.type.accept(JavaTypeClassVisitor.INSTANCE));
87
+            variable.setTag(JavaLocalVariableInfo.class, new JavaLocalVariableInfo(type, javaWriter.local(type)));
88
+        }
89
+
90
+        //javaWriter.label(min);
91
+        statement.iterator.acceptForIterator(new JavaForeachVisitor(this, statement.loopVariables, statement.content, start, end));
92
+        javaWriter.goTo(start);
93
+        javaWriter.label(end);
53 94
         return null;
54 95
     }
55 96
 
56 97
     @Override
57 98
     public Void visitIf(IfStatement statement) {
99
+        statement.condition.accept(expressionVisitor);
100
+        Label onElse = null;
101
+        Label end = new Label();
102
+        final boolean hasElse = statement.onElse != null;
103
+        if (hasElse) {
104
+            onElse = new Label();
105
+            javaWriter.ifEQ(onElse);
106
+        } else {
107
+            javaWriter.ifEQ(end);
108
+        }
109
+        statement.onThen.accept(this);
110
+        if (hasElse) {
111
+            javaWriter.goTo(end);
112
+            javaWriter.label(onElse);
113
+            statement.onElse.accept(this);
114
+        }
115
+        javaWriter.label(end);
58 116
         return null;
59 117
     }
60 118
 
@@ -65,11 +123,15 @@ public class JavaStatementVisitor implements StatementVisitor<Void> {
65 123
 
66 124
     @Override
67 125
     public Void visitReturn(ReturnStatement statement) {
126
+        statement.value.accept(expressionVisitor);
127
+        javaWriter.returnType(Type.getType(statement.value.type.accept(JavaTypeClassVisitor.INSTANCE)));
68 128
         return null;
69 129
     }
70 130
 
71 131
     @Override
72 132
     public Void visitThrow(ThrowStatement statement) {
133
+        statement.value.accept(expressionVisitor);
134
+        javaWriter.aThrow();
73 135
         return null;
74 136
     }
75 137
 
@@ -80,17 +142,33 @@ public class JavaStatementVisitor implements StatementVisitor<Void> {
80 142
 
81 143
     @Override
82 144
     public Void visitVar(VarStatement statement) {
83
-        if(statement.initializer != null)
84
-            statement.initializer.accept(expressionVisitor);
85 145
         Type type = Type.getType(statement.type.accept(JavaTypeClassVisitor.INSTANCE));
86 146
         int local = javaWriter.local(type);
87
-        javaWriter.store(type, local);
147
+        if (statement.initializer != null) {
148
+            statement.initializer.accept(expressionVisitor);
149
+            javaWriter.store(type, local);
150
+        }
88 151
         statement.setTag(JavaLocalVariableInfo.class, new JavaLocalVariableInfo(type, local));
89 152
         return null;
90 153
     }
91 154
 
92 155
     @Override
93 156
     public Void visitWhile(WhileStatement statement) {
157
+        Label start = new Label();
158
+        Label end = new Label();
159
+
160
+        if (statement.label == null) {
161
+            statement.label = javaWriter.createLabelName() + "WhileDo";
162
+        }
163
+        javaWriter.putNamedLabel(start, statement.label + "_start");
164
+        javaWriter.putNamedLabel(end, statement.label + "_end");
165
+
166
+        javaWriter.label(start);
167
+        statement.condition.accept(expressionVisitor);
168
+        javaWriter.ifEQ(end);
169
+        statement.content.accept(this);
170
+        javaWriter.goTo(start);
171
+        javaWriter.label(end);
94 172
         return null;
95 173
     }
96 174
 

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

@@ -1,8 +1,8 @@
1 1
 package org.openzen.zenscript.javabytecode.compiler;
2 2
 
3
-import org.objectweb.asm.Type;
4 3
 import org.openzen.zenscript.codemodel.type.*;
5 4
 
5
+import java.lang.reflect.Array;
6 6
 import java.util.Iterator;
7 7
 import java.util.Map;
8 8
 
@@ -47,12 +47,7 @@ public class JavaTypeClassVisitor implements ITypeVisitor<Class> {
47 47
 
48 48
     @Override
49 49
     public Class visitArray(ArrayTypeID array) {
50
-        try {
51
-            return Class.forName("[" + Type.getInternalName(array.elementType.accept(this)));
52
-        } catch (ClassNotFoundException e) {
53
-            e.printStackTrace();
54
-            return Object[].class;
55
-        }
50
+        return Array.newInstance(array.elementType.accept(this), 0).getClass();
56 51
     }
57 52
 
58 53
     @Override

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

@@ -12,7 +12,7 @@ import static org.objectweb.asm.Opcodes.*;
12 12
 
13 13
 public class JavaWriter {
14 14
     final LocalVariablesSorter visitor;
15
-    private boolean debug = false;
15
+    private boolean debug = true;
16 16
     private int labelIndex = 1;
17 17
     private Map<Label, String> labelNames = new HashMap<>();
18 18
 
@@ -1065,7 +1065,25 @@ public class JavaWriter {
1065 1065
         return labelNames.get(lbl);
1066 1066
     }
1067 1067
 
1068
+    public String createLabelName() {
1069
+        return "L" + labelIndex++;
1070
+    }
1071
+
1072
+    public void putNamedLabel(Label lbl, String name) {
1073
+        if(labelNames == null)
1074
+            labelNames = new HashMap<>();
1075
+        labelNames.put(lbl, name);
1076
+    }
1077
+
1068 1078
     public void stringAdd() {
1069
-        invokeVirtual(String.class, "concat", String.class, String.class);
1079
+        invokeVirtual("java/lang/String", "concat", "(Ljava/lang/String;)Ljava/lang/String;");
1080
+    }
1081
+
1082
+    public Label getNamedLabel(String label) {
1083
+        for (Map.Entry<Label, String> entry : labelNames.entrySet()) {
1084
+            if(entry.getValue().matches(label))
1085
+                return entry.getKey();
1086
+        }
1087
+        throw new RuntimeException("Label " + label + " not found!");
1070 1088
     }
1071 1089
 }

+ 2
- 2
Linker/src/main/java/org/openzen/zenscript/linker/BaseScope.java Wyświetl plik

@@ -11,7 +11,7 @@ import org.openzen.zenscript.codemodel.FunctionHeader;
11 11
 import org.openzen.zenscript.codemodel.expression.Expression;
12 12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13 13
 import org.openzen.zenscript.codemodel.scope.TypeScope;
14
-import org.openzen.zenscript.codemodel.statement.Statement;
14
+import org.openzen.zenscript.codemodel.statement.LoopStatement;
15 15
 import org.openzen.zenscript.codemodel.type.GenericName;
16 16
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
17 17
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -30,7 +30,7 @@ public abstract class BaseScope implements TypeScope {
30 30
 	
31 31
 	public abstract ITypeID getType(CodePosition position, List<GenericName> name);
32 32
 	
33
-	public abstract Statement getLoop(String name);
33
+	public abstract LoopStatement getLoop(String name);
34 34
 	
35 35
 	public abstract FunctionHeader getFunctionHeader();
36 36
 	

+ 2
- 2
Linker/src/main/java/org/openzen/zenscript/linker/BlockScope.java Wyświetl plik

@@ -10,7 +10,7 @@ import java.util.function.Function;
10 10
 import org.openzen.zenscript.codemodel.FunctionHeader;
11 11
 import org.openzen.zenscript.codemodel.expression.Expression;
12 12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13
-import org.openzen.zenscript.codemodel.statement.Statement;
13
+import org.openzen.zenscript.codemodel.statement.LoopStatement;
14 14
 import org.openzen.zenscript.codemodel.type.GenericName;
15 15
 import org.openzen.zenscript.codemodel.type.ITypeID;
16 16
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
@@ -42,7 +42,7 @@ public class BlockScope extends StatementScope {
42 42
 	}
43 43
 
44 44
 	@Override
45
-	public Statement getLoop(String name) {
45
+	public LoopStatement getLoop(String name) {
46 46
 		return parent.getLoop(name);
47 47
 	}
48 48
 

+ 3
- 2
Linker/src/main/java/org/openzen/zenscript/linker/DefinitionScope.java Wyświetl plik

@@ -10,6 +10,8 @@ import java.util.HashMap;
10 10
 import java.util.List;
11 11
 import java.util.Map;
12 12
 import java.util.function.Function;
13
+
14
+import org.openzen.zenscript.codemodel.statement.LoopStatement;
13 15
 import org.openzen.zenscript.shared.CompileException;
14 16
 import org.openzen.zenscript.shared.CompileExceptionCode;
15 17
 import org.openzen.zenscript.codemodel.FunctionHeader;
@@ -20,7 +22,6 @@ import org.openzen.zenscript.codemodel.expression.ThisExpression;
20 22
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
21 23
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
22 24
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
23
-import org.openzen.zenscript.codemodel.statement.Statement;
24 25
 import org.openzen.zenscript.codemodel.type.GenericName;
25 26
 import org.openzen.zenscript.codemodel.type.ITypeID;
26 27
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
@@ -90,7 +91,7 @@ public class DefinitionScope extends BaseScope {
90 91
 	}
91 92
 
92 93
 	@Override
93
-	public Statement getLoop(String name) {
94
+	public LoopStatement getLoop(String name) {
94 95
 		return null;
95 96
 	}
96 97
 

+ 2
- 2
Linker/src/main/java/org/openzen/zenscript/linker/ExpressionScope.java Wyświetl plik

@@ -14,7 +14,7 @@ import org.openzen.zenscript.codemodel.FunctionHeader;
14 14
 import org.openzen.zenscript.codemodel.expression.Expression;
15 15
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
16 16
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
17
-import org.openzen.zenscript.codemodel.statement.Statement;
17
+import org.openzen.zenscript.codemodel.statement.LoopStatement;
18 18
 import org.openzen.zenscript.codemodel.type.GenericName;
19 19
 import org.openzen.zenscript.codemodel.type.ITypeID;
20 20
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
@@ -106,7 +106,7 @@ public class ExpressionScope extends BaseScope {
106 106
 	}
107 107
 	
108 108
 	@Override
109
-	public Statement getLoop(String name) {
109
+	public LoopStatement getLoop(String name) {
110 110
 		return outer.getLoop(name);
111 111
 	}
112 112
 	

+ 2
- 2
Linker/src/main/java/org/openzen/zenscript/linker/FileScope.java Wyświetl plik

@@ -18,7 +18,7 @@ import org.openzen.zenscript.codemodel.definition.ZSPackage;
18 18
 import org.openzen.zenscript.codemodel.expression.Expression;
19 19
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
20 20
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
21
-import org.openzen.zenscript.codemodel.statement.Statement;
21
+import org.openzen.zenscript.codemodel.statement.LoopStatement;
22 22
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
23 23
 import org.openzen.zenscript.codemodel.type.GenericName;
24 24
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
@@ -121,7 +121,7 @@ public class FileScope extends BaseScope {
121 121
 	}
122 122
 
123 123
 	@Override
124
-	public Statement getLoop(String name) {
124
+	public LoopStatement getLoop(String name) {
125 125
 		return null;
126 126
 	}
127 127
 

+ 2
- 2
Linker/src/main/java/org/openzen/zenscript/linker/ForeachScope.java Wyświetl plik

@@ -12,7 +12,7 @@ import org.openzen.zenscript.codemodel.expression.Expression;
12 12
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
13 13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14 14
 import org.openzen.zenscript.codemodel.statement.ForeachStatement;
15
-import org.openzen.zenscript.codemodel.statement.Statement;
15
+import org.openzen.zenscript.codemodel.statement.LoopStatement;
16 16
 import org.openzen.zenscript.codemodel.statement.VarStatement;
17 17
 import org.openzen.zenscript.codemodel.type.GenericName;
18 18
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -59,7 +59,7 @@ public class ForeachScope extends StatementScope {
59 59
 	}
60 60
 
61 61
 	@Override
62
-	public Statement getLoop(String name) {
62
+	public LoopStatement getLoop(String name) {
63 63
 		if (name == null)
64 64
 			return statement;
65 65
 		

+ 2
- 2
Linker/src/main/java/org/openzen/zenscript/linker/FunctionScope.java Wyświetl plik

@@ -14,7 +14,7 @@ import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression
14 14
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
15 15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
16 16
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
17
-import org.openzen.zenscript.codemodel.statement.Statement;
17
+import org.openzen.zenscript.codemodel.statement.LoopStatement;
18 18
 import org.openzen.zenscript.codemodel.type.GenericName;
19 19
 import org.openzen.zenscript.codemodel.type.ITypeID;
20 20
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
@@ -39,7 +39,7 @@ public class FunctionScope extends StatementScope {
39 39
 	}
40 40
 
41 41
 	@Override
42
-	public Statement getLoop(String name) {
42
+	public LoopStatement getLoop(String name) {
43 43
 		return null; // not in a loop
44 44
 	}
45 45
 

+ 2
- 2
Linker/src/main/java/org/openzen/zenscript/linker/GenericFunctionScope.java Wyświetl plik

@@ -14,7 +14,7 @@ import org.openzen.zenscript.codemodel.expression.Expression;
14 14
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
15 15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
16 16
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
17
-import org.openzen.zenscript.codemodel.statement.Statement;
17
+import org.openzen.zenscript.codemodel.statement.LoopStatement;
18 18
 import org.openzen.zenscript.codemodel.type.GenericName;
19 19
 import org.openzen.zenscript.codemodel.type.ITypeID;
20 20
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
@@ -57,7 +57,7 @@ public class GenericFunctionScope extends BaseScope {
57 57
 	}
58 58
 
59 59
 	@Override
60
-	public Statement getLoop(String name) {
60
+	public LoopStatement getLoop(String name) {
61 61
 		return outer.getLoop(name);
62 62
 	}
63 63
 

+ 2
- 2
Linker/src/main/java/org/openzen/zenscript/linker/GlobalScriptScope.java Wyświetl plik

@@ -10,7 +10,7 @@ import java.util.function.Function;
10 10
 import org.openzen.zenscript.codemodel.FunctionHeader;
11 11
 import org.openzen.zenscript.codemodel.expression.Expression;
12 12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13
-import org.openzen.zenscript.codemodel.statement.Statement;
13
+import org.openzen.zenscript.codemodel.statement.LoopStatement;
14 14
 import org.openzen.zenscript.codemodel.type.GenericName;
15 15
 import org.openzen.zenscript.codemodel.type.ITypeID;
16 16
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
@@ -47,7 +47,7 @@ public class GlobalScriptScope extends StatementScope {
47 47
 	}
48 48
 
49 49
 	@Override
50
-	public Statement getLoop(String name) {
50
+	public LoopStatement getLoop(String name) {
51 51
 		return null;
52 52
 	}
53 53
 

+ 2
- 2
Linker/src/main/java/org/openzen/zenscript/linker/ImplementationScope.java Wyświetl plik

@@ -14,7 +14,7 @@ import org.openzen.zenscript.codemodel.member.IDefinitionMember;
14 14
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
15 15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
16 16
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
17
-import org.openzen.zenscript.codemodel.statement.Statement;
17
+import org.openzen.zenscript.codemodel.statement.LoopStatement;
18 18
 import org.openzen.zenscript.codemodel.type.GenericName;
19 19
 import org.openzen.zenscript.codemodel.type.ITypeID;
20 20
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
@@ -73,7 +73,7 @@ public class ImplementationScope extends BaseScope {
73 73
 	}
74 74
 
75 75
 	@Override
76
-	public Statement getLoop(String name) {
76
+	public LoopStatement getLoop(String name) {
77 77
 		return null;
78 78
 	}
79 79
 

+ 2
- 2
Linker/src/main/java/org/openzen/zenscript/linker/LambdaScope.java Wyświetl plik

@@ -13,7 +13,7 @@ import org.openzen.zenscript.codemodel.expression.Expression;
13 13
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
14 14
 import org.openzen.zenscript.codemodel.expression.LambdaClosure;
15 15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
16
-import org.openzen.zenscript.codemodel.statement.Statement;
16
+import org.openzen.zenscript.codemodel.statement.LoopStatement;
17 17
 import org.openzen.zenscript.codemodel.type.GenericName;
18 18
 import org.openzen.zenscript.codemodel.type.ITypeID;
19 19
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
@@ -57,7 +57,7 @@ public class LambdaScope extends StatementScope {
57 57
 	}
58 58
 
59 59
 	@Override
60
-	public Statement getLoop(String name) {
60
+	public LoopStatement getLoop(String name) {
61 61
 		return null;
62 62
 	}
63 63
 

+ 1
- 2
Linker/src/main/java/org/openzen/zenscript/linker/LoopScope.java Wyświetl plik

@@ -11,7 +11,6 @@ import org.openzen.zenscript.codemodel.FunctionHeader;
11 11
 import org.openzen.zenscript.codemodel.expression.Expression;
12 12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13 13
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
14
-import org.openzen.zenscript.codemodel.statement.Statement;
15 14
 import org.openzen.zenscript.codemodel.type.GenericName;
16 15
 import org.openzen.zenscript.codemodel.type.ITypeID;
17 16
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
@@ -50,7 +49,7 @@ public class LoopScope extends StatementScope {
50 49
 	}
51 50
 
52 51
 	@Override
53
-	public Statement getLoop(String name) {
52
+	public LoopStatement getLoop(String name) {
54 53
 		if (name == null)
55 54
 			return statement;
56 55
 		

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

@@ -6,6 +6,7 @@
6 6
 package org.openzen.zenscript.parser.statements;
7 7
 
8 8
 import org.openzen.zenscript.codemodel.statement.BreakStatement;
9
+import org.openzen.zenscript.codemodel.statement.LoopStatement;
9 10
 import org.openzen.zenscript.codemodel.statement.Statement;
10 11
 import org.openzen.zenscript.linker.StatementScope;
11 12
 import org.openzen.zenscript.shared.CodePosition;
@@ -27,7 +28,7 @@ public class ParsedStatementBreak extends ParsedStatement {
27 28
 
28 29
 	@Override
29 30
 	public Statement compile(StatementScope scope) {
30
-		Statement target = scope.getLoop(name);
31
+		LoopStatement target = scope.getLoop(name);
31 32
 		if (target == null)
32 33
 			throw new CompileException(position, CompileExceptionCode.BREAK_OUTSIDE_LOOP, name == null ? "Not in a loop" : "No such loop: " + name);
33 34
 		return new BreakStatement(position, target);

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

@@ -6,6 +6,7 @@
6 6
 package org.openzen.zenscript.parser.statements;
7 7
 
8 8
 import org.openzen.zenscript.codemodel.statement.ContinueStatement;
9
+import org.openzen.zenscript.codemodel.statement.LoopStatement;
9 10
 import org.openzen.zenscript.codemodel.statement.Statement;
10 11
 import org.openzen.zenscript.linker.StatementScope;
11 12
 import org.openzen.zenscript.shared.CodePosition;
@@ -27,7 +28,7 @@ public class ParsedStatementContinue extends ParsedStatement {
27 28
 
28 29
 	@Override
29 30
 	public Statement compile(StatementScope scope) {
30
-		Statement target = scope.getLoop(name);
31
+		LoopStatement target = scope.getLoop(name);
31 32
 		if (target == null)
32 33
 			throw new CompileException(position, CompileExceptionCode.CONTINUE_OUTSIDE_LOOP, name == null ? "Not in a loop" : "No such loop: " + name);
33 34
 		return new ContinueStatement(position, target);

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

@@ -34,7 +34,7 @@ public class ParsedStatementDoWhile extends ParsedStatement {
34 34
 
35 35
 	@Override
36 36
 	public Statement compile(StatementScope scope) {
37
-		Statement content = this.content.compile(scope);
37
+		//Statement content = this.content.compile(scope);
38 38
 		Expression condition = this.condition
39 39
 				.compile(new ExpressionScope(scope, BasicTypeID.HINT_BOOL))
40 40
 				.eval()

+ 69
- 1
ScriptingExample/scripts/moreHellos.zs Wyświetl plik

@@ -13,4 +13,72 @@ test = 13;
13 13
 println(test);
14 14
 
15 15
 val test2 = 14;
16
-println(test2);
16
+println(test2);
17
+
18
+
19
+if true 
20
+    println("ifTest");
21
+else
22
+    println("elseTest");
23
+
24
+
25
+if false 
26
+    println("testIf");
27
+else
28
+    println("testElse");
29
+
30
+
31
+if (true) {
32
+
33
+    while :testLable true {
34
+        println("trueee");
35
+        if true
36
+            break testLable;
37
+        else
38
+            println("nobreak");
39
+    }
40
+    
41
+    
42
+    do {
43
+        println("tru"); 
44
+        if(false){
45
+        	println("brea");
46
+            continue;
47
+        }
48
+        else{
49
+            println("");
50
+            break;
51
+        }
52
+    } while true;
53
+}
54
+
55
+var test = ["1", "2", "3"];
56
+
57
+for item in test {
58
+	println("test");
59
+	println(item);
60
+}
61
+
62
+println("");
63
+
64
+var test2 = [1, 2, 3];
65
+
66
+for item in test2 {
67
+	println(item);
68
+}
69
+
70
+for i, item in ["5", "ttt"] {
71
+	println(item + i);
72
+}
73
+
74
+for i, item in [1, 5, 7] {
75
+	println(item + i);
76
+}
77
+
78
+for i in 10 .. 20 {
79
+	println(i);
80
+}
81
+
82
+var lateInit as string;
83
+lateInit = "initialized later";
84
+println(lateInit);

+ 2
- 2
ScriptingExample/scripts/statements.zs Wyświetl plik

@@ -1,2 +1,2 @@
1
-while true
2
-	println("Hello!");
1
+//while true
2
+//	println("Hello!");

Ładowanie…
Anuluj
Zapisz