Browse Source

More java stuff

- If/Else
- While do and do While
- For
kindlich 6 years ago
parent
commit
599bc9ac36
No known key found for this signature in database
27 changed files with 319 additions and 50 deletions
  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 View File

12
  * @author Hoofdgebruiker
12
  * @author Hoofdgebruiker
13
  */
13
  */
14
 public class BreakStatement extends Statement {
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
 		super(position);
18
 		super(position);
19
 		
19
 		
20
 		this.target = target;
20
 		this.target = target;

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ContinueStatement.java View File

12
  * @author Hoofdgebruiker
12
  * @author Hoofdgebruiker
13
  */
13
  */
14
 public class ContinueStatement extends Statement {
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
 		super(position);
18
 		super(position);
19
 		
19
 		
20
 		this.target = target;
20
 		this.target = target;

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ForeachStatement.java View File

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/LoopStatement.java View File

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

+ 12
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/implementations/IntRange.java View File

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 View File

1
 package org.openzen.zenscript.javabytecode.compiler;
1
 package org.openzen.zenscript.javabytecode.compiler;
2
 
2
 
3
+import com.sun.javafx.image.IntPixelGetter;
3
 import org.objectweb.asm.Type;
4
 import org.objectweb.asm.Type;
4
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
5
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
5
 import org.openzen.zenscript.codemodel.expression.*;
6
 import org.openzen.zenscript.codemodel.expression.*;
6
 import org.openzen.zenscript.codemodel.member.DefinitionMember;
7
 import org.openzen.zenscript.codemodel.member.DefinitionMember;
8
+import org.openzen.zenscript.implementations.IntRange;
7
 import org.openzen.zenscript.javabytecode.JavaBytecodeImplementation;
9
 import org.openzen.zenscript.javabytecode.JavaBytecodeImplementation;
8
 import org.openzen.zenscript.javabytecode.JavaFieldInfo;
10
 import org.openzen.zenscript.javabytecode.JavaFieldInfo;
9
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
11
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
308
 
310
 
309
     @Override
311
     @Override
310
     public Void visitRange(RangeExpression expression) {
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
         return null;
322
         return null;
312
     }
323
     }
313
 
324
 

+ 85
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaForeachVisitor.java View File

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 View File

1
 package org.openzen.zenscript.javabytecode.compiler;
1
 package org.openzen.zenscript.javabytecode.compiler;
2
 
2
 
3
+import org.objectweb.asm.Label;
3
 import org.objectweb.asm.Type;
4
 import org.objectweb.asm.Type;
4
 import org.openzen.zenscript.codemodel.statement.*;
5
 import org.openzen.zenscript.codemodel.statement.*;
5
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
6
 import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
11
     public JavaStatementVisitor(final JavaWriter javaWriter) {
12
     public JavaStatementVisitor(final JavaWriter javaWriter) {
12
 
13
 
13
         this.javaWriter = javaWriter;
14
         this.javaWriter = javaWriter;
14
-        this.expressionVisitor = new JavaExpressionVisitor( javaWriter);
15
+        this.expressionVisitor = new JavaExpressionVisitor(javaWriter);
15
     }
16
     }
16
 
17
 
17
     @Override
18
     @Override
24
 
25
 
25
     @Override
26
     @Override
26
     public Void visitBreak(BreakStatement statement) {
27
     public Void visitBreak(BreakStatement statement) {
28
+        javaWriter.goTo(javaWriter.getNamedLabel(statement.target.label + "_end"));
27
         return null;
29
         return null;
28
     }
30
     }
29
 
31
 
30
     @Override
32
     @Override
31
     public Void visitContinue(ContinueStatement statement) {
33
     public Void visitContinue(ContinueStatement statement) {
34
+        javaWriter.goTo(javaWriter.getNamedLabel(statement.target.label + "_start"));
32
         return null;
35
         return null;
33
     }
36
     }
34
 
37
 
35
     @Override
38
     @Override
36
     public Void visitDoWhile(DoWhileStatement statement) {
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
         return null;
54
         return null;
38
     }
55
     }
39
 
56
 
40
     @Override
57
     @Override
41
     public Void visitEmpty(EmptyStatement statement) {
58
     public Void visitEmpty(EmptyStatement statement) {
59
+        //No-Op
42
         return null;
60
         return null;
43
     }
61
     }
44
 
62
 
50
 
68
 
51
     @Override
69
     @Override
52
     public Void visitForeach(ForeachStatement statement) {
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
         return null;
94
         return null;
54
     }
95
     }
55
 
96
 
56
     @Override
97
     @Override
57
     public Void visitIf(IfStatement statement) {
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
         return null;
116
         return null;
59
     }
117
     }
60
 
118
 
65
 
123
 
66
     @Override
124
     @Override
67
     public Void visitReturn(ReturnStatement statement) {
125
     public Void visitReturn(ReturnStatement statement) {
126
+        statement.value.accept(expressionVisitor);
127
+        javaWriter.returnType(Type.getType(statement.value.type.accept(JavaTypeClassVisitor.INSTANCE)));
68
         return null;
128
         return null;
69
     }
129
     }
70
 
130
 
71
     @Override
131
     @Override
72
     public Void visitThrow(ThrowStatement statement) {
132
     public Void visitThrow(ThrowStatement statement) {
133
+        statement.value.accept(expressionVisitor);
134
+        javaWriter.aThrow();
73
         return null;
135
         return null;
74
     }
136
     }
75
 
137
 
80
 
142
 
81
     @Override
143
     @Override
82
     public Void visitVar(VarStatement statement) {
144
     public Void visitVar(VarStatement statement) {
83
-        if(statement.initializer != null)
84
-            statement.initializer.accept(expressionVisitor);
85
         Type type = Type.getType(statement.type.accept(JavaTypeClassVisitor.INSTANCE));
145
         Type type = Type.getType(statement.type.accept(JavaTypeClassVisitor.INSTANCE));
86
         int local = javaWriter.local(type);
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
         statement.setTag(JavaLocalVariableInfo.class, new JavaLocalVariableInfo(type, local));
151
         statement.setTag(JavaLocalVariableInfo.class, new JavaLocalVariableInfo(type, local));
89
         return null;
152
         return null;
90
     }
153
     }
91
 
154
 
92
     @Override
155
     @Override
93
     public Void visitWhile(WhileStatement statement) {
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
         return null;
172
         return null;
95
     }
173
     }
96
 
174
 

+ 2
- 7
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaTypeClassVisitor.java View File

1
 package org.openzen.zenscript.javabytecode.compiler;
1
 package org.openzen.zenscript.javabytecode.compiler;
2
 
2
 
3
-import org.objectweb.asm.Type;
4
 import org.openzen.zenscript.codemodel.type.*;
3
 import org.openzen.zenscript.codemodel.type.*;
5
 
4
 
5
+import java.lang.reflect.Array;
6
 import java.util.Iterator;
6
 import java.util.Iterator;
7
 import java.util.Map;
7
 import java.util.Map;
8
 
8
 
47
 
47
 
48
     @Override
48
     @Override
49
     public Class visitArray(ArrayTypeID array) {
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
     @Override
53
     @Override

+ 20
- 2
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java View File

12
 
12
 
13
 public class JavaWriter {
13
 public class JavaWriter {
14
     final LocalVariablesSorter visitor;
14
     final LocalVariablesSorter visitor;
15
-    private boolean debug = false;
15
+    private boolean debug = true;
16
     private int labelIndex = 1;
16
     private int labelIndex = 1;
17
     private Map<Label, String> labelNames = new HashMap<>();
17
     private Map<Label, String> labelNames = new HashMap<>();
18
 
18
 
1065
         return labelNames.get(lbl);
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
     public void stringAdd() {
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 View File

11
 import org.openzen.zenscript.codemodel.expression.Expression;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13
 import org.openzen.zenscript.codemodel.scope.TypeScope;
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
 import org.openzen.zenscript.codemodel.type.GenericName;
15
 import org.openzen.zenscript.codemodel.type.GenericName;
16
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
16
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
17
 import org.openzen.zenscript.codemodel.type.ITypeID;
17
 import org.openzen.zenscript.codemodel.type.ITypeID;
30
 	
30
 	
31
 	public abstract ITypeID getType(CodePosition position, List<GenericName> name);
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
 	public abstract FunctionHeader getFunctionHeader();
35
 	public abstract FunctionHeader getFunctionHeader();
36
 	
36
 	

+ 2
- 2
Linker/src/main/java/org/openzen/zenscript/linker/BlockScope.java View File

10
 import org.openzen.zenscript.codemodel.FunctionHeader;
10
 import org.openzen.zenscript.codemodel.FunctionHeader;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
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
 import org.openzen.zenscript.codemodel.type.GenericName;
14
 import org.openzen.zenscript.codemodel.type.GenericName;
15
 import org.openzen.zenscript.codemodel.type.ITypeID;
15
 import org.openzen.zenscript.codemodel.type.ITypeID;
16
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
16
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
42
 	}
42
 	}
43
 
43
 
44
 	@Override
44
 	@Override
45
-	public Statement getLoop(String name) {
45
+	public LoopStatement getLoop(String name) {
46
 		return parent.getLoop(name);
46
 		return parent.getLoop(name);
47
 	}
47
 	}
48
 
48
 

+ 3
- 2
Linker/src/main/java/org/openzen/zenscript/linker/DefinitionScope.java View File

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

+ 2
- 2
Linker/src/main/java/org/openzen/zenscript/linker/ExpressionScope.java View File

14
 import org.openzen.zenscript.codemodel.expression.Expression;
14
 import org.openzen.zenscript.codemodel.expression.Expression;
15
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
15
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
16
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
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
 import org.openzen.zenscript.codemodel.type.GenericName;
18
 import org.openzen.zenscript.codemodel.type.GenericName;
19
 import org.openzen.zenscript.codemodel.type.ITypeID;
19
 import org.openzen.zenscript.codemodel.type.ITypeID;
20
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
20
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
106
 	}
106
 	}
107
 	
107
 	
108
 	@Override
108
 	@Override
109
-	public Statement getLoop(String name) {
109
+	public LoopStatement getLoop(String name) {
110
 		return outer.getLoop(name);
110
 		return outer.getLoop(name);
111
 	}
111
 	}
112
 	
112
 	

+ 2
- 2
Linker/src/main/java/org/openzen/zenscript/linker/FileScope.java View File

18
 import org.openzen.zenscript.codemodel.expression.Expression;
18
 import org.openzen.zenscript.codemodel.expression.Expression;
19
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
19
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
20
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
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
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
22
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
23
 import org.openzen.zenscript.codemodel.type.GenericName;
23
 import org.openzen.zenscript.codemodel.type.GenericName;
24
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
24
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
121
 	}
121
 	}
122
 
122
 
123
 	@Override
123
 	@Override
124
-	public Statement getLoop(String name) {
124
+	public LoopStatement getLoop(String name) {
125
 		return null;
125
 		return null;
126
 	}
126
 	}
127
 
127
 

+ 2
- 2
Linker/src/main/java/org/openzen/zenscript/linker/ForeachScope.java View File

12
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
12
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14
 import org.openzen.zenscript.codemodel.statement.ForeachStatement;
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
 import org.openzen.zenscript.codemodel.statement.VarStatement;
16
 import org.openzen.zenscript.codemodel.statement.VarStatement;
17
 import org.openzen.zenscript.codemodel.type.GenericName;
17
 import org.openzen.zenscript.codemodel.type.GenericName;
18
 import org.openzen.zenscript.codemodel.type.ITypeID;
18
 import org.openzen.zenscript.codemodel.type.ITypeID;
59
 	}
59
 	}
60
 
60
 
61
 	@Override
61
 	@Override
62
-	public Statement getLoop(String name) {
62
+	public LoopStatement getLoop(String name) {
63
 		if (name == null)
63
 		if (name == null)
64
 			return statement;
64
 			return statement;
65
 		
65
 		

+ 2
- 2
Linker/src/main/java/org/openzen/zenscript/linker/FunctionScope.java View File

14
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
14
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
16
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
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
 import org.openzen.zenscript.codemodel.type.GenericName;
18
 import org.openzen.zenscript.codemodel.type.GenericName;
19
 import org.openzen.zenscript.codemodel.type.ITypeID;
19
 import org.openzen.zenscript.codemodel.type.ITypeID;
20
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
20
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
39
 	}
39
 	}
40
 
40
 
41
 	@Override
41
 	@Override
42
-	public Statement getLoop(String name) {
42
+	public LoopStatement getLoop(String name) {
43
 		return null; // not in a loop
43
 		return null; // not in a loop
44
 	}
44
 	}
45
 
45
 

+ 2
- 2
Linker/src/main/java/org/openzen/zenscript/linker/GenericFunctionScope.java View File

14
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
14
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
16
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
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
 import org.openzen.zenscript.codemodel.type.GenericName;
18
 import org.openzen.zenscript.codemodel.type.GenericName;
19
 import org.openzen.zenscript.codemodel.type.ITypeID;
19
 import org.openzen.zenscript.codemodel.type.ITypeID;
20
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
20
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
57
 	}
57
 	}
58
 
58
 
59
 	@Override
59
 	@Override
60
-	public Statement getLoop(String name) {
60
+	public LoopStatement getLoop(String name) {
61
 		return outer.getLoop(name);
61
 		return outer.getLoop(name);
62
 	}
62
 	}
63
 
63
 

+ 2
- 2
Linker/src/main/java/org/openzen/zenscript/linker/GlobalScriptScope.java View File

10
 import org.openzen.zenscript.codemodel.FunctionHeader;
10
 import org.openzen.zenscript.codemodel.FunctionHeader;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
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
 import org.openzen.zenscript.codemodel.type.GenericName;
14
 import org.openzen.zenscript.codemodel.type.GenericName;
15
 import org.openzen.zenscript.codemodel.type.ITypeID;
15
 import org.openzen.zenscript.codemodel.type.ITypeID;
16
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
16
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
47
 	}
47
 	}
48
 
48
 
49
 	@Override
49
 	@Override
50
-	public Statement getLoop(String name) {
50
+	public LoopStatement getLoop(String name) {
51
 		return null;
51
 		return null;
52
 	}
52
 	}
53
 
53
 

+ 2
- 2
Linker/src/main/java/org/openzen/zenscript/linker/ImplementationScope.java View File

14
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
14
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
16
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
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
 import org.openzen.zenscript.codemodel.type.GenericName;
18
 import org.openzen.zenscript.codemodel.type.GenericName;
19
 import org.openzen.zenscript.codemodel.type.ITypeID;
19
 import org.openzen.zenscript.codemodel.type.ITypeID;
20
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
20
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
73
 	}
73
 	}
74
 
74
 
75
 	@Override
75
 	@Override
76
-	public Statement getLoop(String name) {
76
+	public LoopStatement getLoop(String name) {
77
 		return null;
77
 		return null;
78
 	}
78
 	}
79
 
79
 

+ 2
- 2
Linker/src/main/java/org/openzen/zenscript/linker/LambdaScope.java View File

13
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
13
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
14
 import org.openzen.zenscript.codemodel.expression.LambdaClosure;
14
 import org.openzen.zenscript.codemodel.expression.LambdaClosure;
15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
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
 import org.openzen.zenscript.codemodel.type.GenericName;
17
 import org.openzen.zenscript.codemodel.type.GenericName;
18
 import org.openzen.zenscript.codemodel.type.ITypeID;
18
 import org.openzen.zenscript.codemodel.type.ITypeID;
19
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
19
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
57
 	}
57
 	}
58
 
58
 
59
 	@Override
59
 	@Override
60
-	public Statement getLoop(String name) {
60
+	public LoopStatement getLoop(String name) {
61
 		return null;
61
 		return null;
62
 	}
62
 	}
63
 
63
 

+ 1
- 2
Linker/src/main/java/org/openzen/zenscript/linker/LoopScope.java View File

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

+ 2
- 1
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementBreak.java View File

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

+ 2
- 1
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementContinue.java View File

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

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementDoWhile.java View File

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

+ 69
- 1
ScriptingExample/scripts/moreHellos.zs View File

13
 println(test);
13
 println(test);
14
 
14
 
15
 val test2 = 14;
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 View File

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

Loading…
Cancel
Save