소스 검색

Add iterators, statements, more expressions (#3)

stan 6 년 전
부모
커밋
cbbc503504
34개의 변경된 파일964개의 추가작업 그리고 264개의 파일을 삭제
  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. 2
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/Statement.java
  6. 12
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/implementations/IntRange.java
  7. 73
    71
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java
  8. 13
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaLocalVariableInfo.java
  9. 160
    47
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
  10. 85
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaForeachVisitor.java
  11. 96
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java
  12. 92
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaTypeClassVisitor.java
  13. 0
    92
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaTypeSignatureVisitor.java
  14. 23
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java
  15. 2
    2
      Linker/src/main/java/org/openzen/zenscript/linker/BaseScope.java
  16. 2
    2
      Linker/src/main/java/org/openzen/zenscript/linker/BlockScope.java
  17. 3
    2
      Linker/src/main/java/org/openzen/zenscript/linker/DefinitionScope.java
  18. 2
    2
      Linker/src/main/java/org/openzen/zenscript/linker/ExpressionScope.java
  19. 2
    2
      Linker/src/main/java/org/openzen/zenscript/linker/FileScope.java
  20. 2
    2
      Linker/src/main/java/org/openzen/zenscript/linker/ForeachScope.java
  21. 2
    2
      Linker/src/main/java/org/openzen/zenscript/linker/FunctionScope.java
  22. 2
    2
      Linker/src/main/java/org/openzen/zenscript/linker/GenericFunctionScope.java
  23. 2
    2
      Linker/src/main/java/org/openzen/zenscript/linker/GlobalScriptScope.java
  24. 2
    2
      Linker/src/main/java/org/openzen/zenscript/linker/ImplementationScope.java
  25. 2
    2
      Linker/src/main/java/org/openzen/zenscript/linker/LambdaScope.java
  26. 1
    2
      Linker/src/main/java/org/openzen/zenscript/linker/LoopScope.java
  27. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementBreak.java
  28. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementContinue.java
  29. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementDoWhile.java
  30. 83
    4
      ScriptingExample/scripts/moreHellos.zs
  31. 2
    2
      ScriptingExample/scripts/statements.zs
  32. 266
    0
      Shared/out/production/resources/org/openzen/zenscript/shared/characterEntities.properties
  33. 2
    1
      Shared/src/main/java/org/openzen/zenscript/shared/CompileExceptionCode.java
  34. 19
    10
      Shared/src/main/java/org/openzen/zenscript/shared/TagDictionary.java

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/BreakStatement.java 파일 보기

@@ -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 파일 보기

@@ -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 파일 보기

@@ -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 파일 보기

@@ -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);

+ 2
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/Statement.java 파일 보기

@@ -10,12 +10,13 @@ import java.util.stream.Collectors;
10 10
 import org.openzen.zenscript.codemodel.type.ITypeID;
11 11
 import org.openzen.zenscript.shared.CodePosition;
12 12
 import org.openzen.zenscript.codemodel.scope.TypeScope;
13
+import org.openzen.zenscript.shared.Taggable;
13 14
 
14 15
 /**
15 16
  *
16 17
  * @author Hoofdgebruiker
17 18
  */
18
-public abstract class Statement {
19
+public abstract class Statement extends Taggable {
19 20
 	public final CodePosition position;
20 21
 	
21 22
 	public Statement(CodePosition position) {

+ 12
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/implementations/IntRange.java 파일 보기

@@ -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
+}

+ 73
- 71
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java 파일 보기

@@ -35,86 +35,88 @@ public class JavaCompiler {
35 35
 		LONG_GET_MIN_VALUE.setTag(JavaFieldInfo.class, new JavaFieldInfo(jLong, "MIN_VALUE", "J"));
36 36
 		LONG_GET_MAX_VALUE.setTag(JavaFieldInfo.class, new JavaFieldInfo(jLong, "MAX_VALUE", "J"));
37 37
 		
38
-		implement(BOOL_NOT, writer -> writer.iNot());
39
-		
40
-		implement(BYTE_NOT, writer -> writer.iNot());
41
-		implement(SBYTE_NOT, writer -> writer.iNot());
42
-		implement(SHORT_NOT, writer -> writer.iNot());
43
-		implement(USHORT_NOT, writer -> writer.iNot());
44
-		implement(INT_NOT, writer -> writer.iNot());
45
-		implement(UINT_NOT, writer -> writer.iNot());
46
-		implement(LONG_NOT, writer -> writer.lNot());
47
-		implement(ULONG_NOT, writer -> writer.lNot());
48
-		
49
-		implement(BYTE_NEG, writer -> writer.iNeg());
50
-		implement(SBYTE_NEG, writer -> writer.iNeg());
51
-		implement(SHORT_NEG, writer -> writer.iNeg());
52
-		implement(USHORT_NEG, writer -> writer.iNeg());
53
-		implement(INT_NEG, writer -> writer.iNeg());
54
-		implement(UINT_NEG, writer -> writer.iNeg());
55
-		implement(LONG_NEG, writer -> writer.lNeg());
56
-		implement(ULONG_NEG, writer -> writer.lNeg());
57
-		implement(FLOAT_NEG, writer -> writer.fNeg());
58
-		implement(DOUBLE_NEG, writer -> writer.dNeg());
59
-		
60
-		implement(BYTE_ADD_BYTE, writer -> writer.iAdd());
61
-		implement(SBYTE_ADD_SBYTE, writer -> writer.iAdd());
62
-		implement(SHORT_ADD_SHORT, writer -> writer.iAdd());
63
-		implement(USHORT_ADD_USHORT, writer -> writer.iAdd());
64
-		implement(INT_ADD_INT, writer -> writer.iAdd());
65
-		implement(UINT_ADD_UINT, writer -> writer.iAdd());
66
-		implement(LONG_ADD_LONG, writer -> writer.lAdd());
67
-		implement(ULONG_ADD_ULONG, writer -> writer.lAdd());
68
-		implement(FLOAT_ADD_FLOAT, writer -> writer.fAdd());
69
-		implement(DOUBLE_ADD_DOUBLE, writer -> writer.dAdd());
38
+		implement(BOOL_NOT, JavaWriter::iNot);
39
+		
40
+		implement(BYTE_NOT, JavaWriter::iNot);
41
+		implement(SBYTE_NOT, JavaWriter::iNot);
42
+		implement(SHORT_NOT, JavaWriter::iNot);
43
+		implement(USHORT_NOT, JavaWriter::iNot);
44
+		implement(INT_NOT, JavaWriter::iNot);
45
+		implement(UINT_NOT, JavaWriter::iNot);
46
+		implement(LONG_NOT, JavaWriter::lNot);
47
+		implement(ULONG_NOT, JavaWriter::lNot);
48
+		
49
+		implement(BYTE_NEG, JavaWriter::iNeg);
50
+		implement(SBYTE_NEG, JavaWriter::iNeg);
51
+		implement(SHORT_NEG, JavaWriter::iNeg);
52
+		implement(USHORT_NEG, JavaWriter::iNeg);
53
+		implement(INT_NEG, JavaWriter::iNeg);
54
+		implement(UINT_NEG, JavaWriter::iNeg);
55
+		implement(LONG_NEG, JavaWriter::lNeg);
56
+		implement(ULONG_NEG, JavaWriter::lNeg);
57
+		implement(FLOAT_NEG, JavaWriter::fNeg);
58
+		implement(DOUBLE_NEG, JavaWriter::dNeg);
59
+		
60
+		implement(BYTE_ADD_BYTE, JavaWriter::iAdd);
61
+		implement(SBYTE_ADD_SBYTE, JavaWriter::iAdd);
62
+		implement(SHORT_ADD_SHORT, JavaWriter::iAdd);
63
+		implement(USHORT_ADD_USHORT, JavaWriter::iAdd);
64
+		implement(INT_ADD_INT, JavaWriter::iAdd);
65
+		implement(UINT_ADD_UINT, JavaWriter::iAdd);
66
+		implement(LONG_ADD_LONG, JavaWriter::lAdd);
67
+		implement(ULONG_ADD_ULONG, JavaWriter::lAdd);
68
+		implement(FLOAT_ADD_FLOAT, JavaWriter::fAdd);
69
+		implement(DOUBLE_ADD_DOUBLE, JavaWriter::dAdd);
70 70
 		// TODO: STRING_ADD_STRING
71
-		
72
-		implement(BYTE_SUB_BYTE, writer -> writer.iSub());
73
-		implement(SBYTE_SUB_SBYTE, writer -> writer.iSub());
74
-		implement(SHORT_SUB_SHORT, writer -> writer.iSub());
75
-		implement(USHORT_SUB_USHORT, writer -> writer.iSub());
76
-		implement(INT_SUB_INT, writer -> writer.iSub());
77
-		implement(UINT_SUB_UINT, writer -> writer.iSub());
78
-		implement(LONG_SUB_LONG, writer -> writer.lSub());
79
-		implement(ULONG_SUB_ULONG, writer -> writer.lSub());
80
-		implement(FLOAT_SUB_FLOAT, writer -> writer.fSub());
81
-		implement(DOUBLE_SUB_DOUBLE, writer -> writer.dSub());
82
-		
83
-		implement(BYTE_MUL_BYTE, writer -> writer.iMul());
84
-		implement(SBYTE_MUL_SBYTE, writer -> writer.iMul());
85
-		implement(SHORT_MUL_SHORT, writer -> writer.iMul());
86
-		implement(USHORT_MUL_USHORT, writer -> writer.iMul());
87
-		implement(INT_MUL_INT, writer -> writer.iMul());
88
-		implement(UINT_MUL_UINT, writer -> writer.iMul());
89
-		implement(LONG_MUL_LONG, writer -> writer.lMul());
90
-		implement(ULONG_MUL_ULONG, writer -> writer.lMul());
91
-		implement(FLOAT_MUL_FLOAT, writer -> writer.fMul());
92
-		implement(DOUBLE_MUL_DOUBLE, writer -> writer.dMul());
93
-		
94
-		implement(INT_DIV_INT, writer -> writer.iDiv());
95
-		implement(INT_MOD_INT, writer -> writer.iRem());
96
-		
97
-		implement(INT_TO_BYTE, writer -> writer.i2b());
98
-		implement(INT_TO_SBYTE, writer -> writer.i2b());
99
-		implement(INT_TO_SHORT, writer -> writer.i2s());
100
-		implement(INT_TO_USHORT, writer -> writer.i2s());
71
+
72
+		implement(STRING_ADD_STRING, JavaWriter::stringAdd);
73
+		
74
+		implement(BYTE_SUB_BYTE, JavaWriter::iSub);
75
+		implement(SBYTE_SUB_SBYTE, JavaWriter::iSub);
76
+		implement(SHORT_SUB_SHORT, JavaWriter::iSub);
77
+		implement(USHORT_SUB_USHORT, JavaWriter::iSub);
78
+		implement(INT_SUB_INT, JavaWriter::iSub);
79
+		implement(UINT_SUB_UINT, JavaWriter::iSub);
80
+		implement(LONG_SUB_LONG, JavaWriter::lSub);
81
+		implement(ULONG_SUB_ULONG, JavaWriter::lSub);
82
+		implement(FLOAT_SUB_FLOAT, JavaWriter::fSub);
83
+		implement(DOUBLE_SUB_DOUBLE, JavaWriter::dSub);
84
+		
85
+		implement(BYTE_MUL_BYTE, JavaWriter::iMul);
86
+		implement(SBYTE_MUL_SBYTE, JavaWriter::iMul);
87
+		implement(SHORT_MUL_SHORT, JavaWriter::iMul);
88
+		implement(USHORT_MUL_USHORT, JavaWriter::iMul);
89
+		implement(INT_MUL_INT, JavaWriter::iMul);
90
+		implement(UINT_MUL_UINT, JavaWriter::iMul);
91
+		implement(LONG_MUL_LONG, JavaWriter::lMul);
92
+		implement(ULONG_MUL_ULONG, JavaWriter::lMul);
93
+		implement(FLOAT_MUL_FLOAT, JavaWriter::fMul);
94
+		implement(DOUBLE_MUL_DOUBLE, JavaWriter::dMul);
95
+		
96
+		implement(INT_DIV_INT, JavaWriter::iDiv);
97
+		implement(INT_MOD_INT, JavaWriter::iRem);
98
+		
99
+		implement(INT_TO_BYTE, JavaWriter::i2b);
100
+		implement(INT_TO_SBYTE, JavaWriter::i2b);
101
+		implement(INT_TO_SHORT, JavaWriter::i2s);
102
+		implement(INT_TO_USHORT, JavaWriter::i2s);
101 103
 		implement(INT_TO_UINT, writer -> {});
102
-		implement(INT_TO_LONG, writer -> writer.i2l());
103
-		implement(INT_TO_ULONG, writer -> writer.i2l());
104
-		implement(INT_TO_FLOAT, writer -> writer.i2f());
105
-		implement(INT_TO_DOUBLE, writer -> writer.i2d());
106
-		implement(INT_TO_CHAR, writer -> writer.i2s());
104
+		implement(INT_TO_LONG, JavaWriter::i2l);
105
+		implement(INT_TO_ULONG, JavaWriter::i2l);
106
+		implement(INT_TO_FLOAT, JavaWriter::i2f);
107
+		implement(INT_TO_DOUBLE, JavaWriter::i2d);
108
+		implement(INT_TO_CHAR, JavaWriter::i2s);
107 109
 		INT_TO_STRING.setTag(JavaMethodInfo.class, new JavaMethodInfo(jInteger, "toString", "(I)Ljava/lang/String;", true));
108 110
 		
109 111
 		implement(LONG_TO_BYTE, writer -> { writer.l2i(); writer.i2b(); });
110 112
 		implement(LONG_TO_SBYTE, writer -> { writer.l2i(); writer.i2b(); });
111 113
 		implement(LONG_TO_SHORT, writer -> { writer.l2i(); writer.i2s(); });
112 114
 		implement(LONG_TO_USHORT, writer -> { writer.l2i(); writer.i2s(); });
113
-		implement(LONG_TO_INT, writer -> writer.l2i());
114
-		implement(LONG_TO_UINT, writer -> writer.l2i());
115
+		implement(LONG_TO_INT, JavaWriter::l2i);
116
+		implement(LONG_TO_UINT, JavaWriter::l2i);
115 117
 		implement(LONG_TO_ULONG, writer -> {});
116
-		implement(LONG_TO_FLOAT, writer -> writer.l2f());
117
-		implement(LONG_TO_DOUBLE, writer -> writer.l2d());
118
+		implement(LONG_TO_FLOAT, JavaWriter::l2f);
119
+		implement(LONG_TO_DOUBLE, JavaWriter::l2d);
118 120
 		implement(LONG_TO_CHAR, writer -> { writer.l2i(); writer.i2s(); });
119 121
 		LONG_TO_STRING.setTag(JavaMethodInfo.class, new JavaMethodInfo(jLong, "toString", "(J)Ljava/lang/String;", true));
120 122
 		

+ 13
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaLocalVariableInfo.java 파일 보기

@@ -0,0 +1,13 @@
1
+package org.openzen.zenscript.javabytecode;
2
+
3
+import org.objectweb.asm.Type;
4
+
5
+public class JavaLocalVariableInfo {
6
+    public final Type type;
7
+    public final int local;
8
+
9
+    public JavaLocalVariableInfo(Type type, int local) {
10
+        this.type = type;
11
+        this.local = local;
12
+    }
13
+}

+ 160
- 47
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java 파일 보기

@@ -1,13 +1,23 @@
1 1
 package org.openzen.zenscript.javabytecode.compiler;
2 2
 
3
+import com.sun.javafx.image.IntPixelGetter;
4
+import org.objectweb.asm.Type;
5
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
3 6
 import org.openzen.zenscript.codemodel.expression.*;
7
+import org.openzen.zenscript.codemodel.member.DefinitionMember;
8
+import org.openzen.zenscript.implementations.IntRange;
4 9
 import org.openzen.zenscript.javabytecode.JavaBytecodeImplementation;
5 10
 import org.openzen.zenscript.javabytecode.JavaFieldInfo;
11
+import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
6 12
 import org.openzen.zenscript.javabytecode.JavaMethodInfo;
13
+import org.openzen.zenscript.shared.CompileException;
14
+import org.openzen.zenscript.shared.CompileExceptionCode;
15
+
16
+import java.util.Map;
7 17
 
8 18
 public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
9 19
 
10
-    private final JavaWriter javaWriter;
20
+    private JavaWriter javaWriter;
11 21
 
12 22
     public JavaExpressionVisitor(final JavaWriter javaWriter) {
13 23
         this.javaWriter = javaWriter;
@@ -20,6 +30,15 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
20 30
 
21 31
     @Override
22 32
     public Void visitArray(ArrayExpression expression) {
33
+        javaWriter.constant(expression.expressions.length);
34
+        Type type = Type.getType(expression.type.accept(JavaTypeClassVisitor.INSTANCE).getComponentType());
35
+        javaWriter.newArray(type);
36
+        for (int i = 0; i < expression.expressions.length; i++) {
37
+            javaWriter.dup();
38
+            javaWriter.constant(i);
39
+            expression.expressions[i].accept(this);
40
+            javaWriter.arrayStore(type);
41
+        }
23 42
         return null;
24 43
     }
25 44
 
@@ -34,29 +53,9 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
34 53
         for (Expression argument : expression.arguments.arguments) {
35 54
             argument.accept(this);
36 55
         }
37
-		
38
-		JavaBytecodeImplementation implementation = expression.member.getTag(JavaBytecodeImplementation.class);
39
-		if (implementation != null) {
40
-			implementation.compile(javaWriter);
41
-			return null;
42
-		}
43
-		
44
-		JavaMethodInfo methodInfo = expression.member.getTag(JavaMethodInfo.class);
45
-		if (methodInfo == null)
46
-			throw new IllegalStateException("Call target has no method info!");
47
-		
48
-		if (methodInfo.isStatic) {
49
-			javaWriter.invokeStatic(
50
-					methodInfo.javaClass.internalClassName,
51
-					methodInfo.name,
52
-					methodInfo.signature);
53
-		} else {
54
-			javaWriter.invokeVirtual(
55
-					methodInfo.javaClass.internalClassName,
56
-					methodInfo.name,
57
-					methodInfo.signature);
58
-		}
59
-		
56
+        if (!checkAndExecuteByteCodeImplementation(expression.member) && !checkAndExecuteMethodInfo(expression.member))
57
+            throw new IllegalStateException("Call target has no method info!");
58
+
60 59
         return null;
61 60
     }
62 61
 
@@ -107,79 +106,79 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
107 106
 
108 107
     @Override
109 108
     public Void visitConstantBool(ConstantBoolExpression expression) {
110
-        javaWriter.constant(expression.value);
109
+        getJavaWriter().constant(expression.value);
111 110
         return null;
112 111
     }
113 112
 
114 113
     @Override
115 114
     public Void visitConstantByte(ConstantByteExpression expression) {
116
-        javaWriter.biPush(expression.value);
115
+        getJavaWriter().biPush(expression.value);
117 116
         return null;
118 117
     }
119 118
 
120 119
     @Override
121 120
     public Void visitConstantChar(ConstantCharExpression expression) {
122
-        javaWriter.constant(expression.value);
121
+        getJavaWriter().constant(expression.value);
123 122
         return null;
124 123
     }
125 124
 
126 125
     @Override
127 126
     public Void visitConstantDouble(ConstantDoubleExpression expression) {
128
-        javaWriter.constant(expression.value);
127
+        getJavaWriter().constant(expression.value);
129 128
         return null;
130 129
     }
131 130
 
132 131
     @Override
133 132
     public Void visitConstantFloat(ConstantFloatExpression expression) {
134
-        javaWriter.constant(expression.value);
133
+        getJavaWriter().constant(expression.value);
135 134
         return null;
136 135
     }
137 136
 
138 137
     @Override
139 138
     public Void visitConstantInt(ConstantIntExpression expression) {
140
-        javaWriter.constant(expression.value);
139
+        getJavaWriter().constant(expression.value);
141 140
         return null;
142 141
     }
143 142
 
144 143
     @Override
145 144
     public Void visitConstantLong(ConstantLongExpression expression) {
146
-        javaWriter.constant(expression.value);
145
+        getJavaWriter().constant(expression.value);
147 146
         return null;
148 147
     }
149 148
 
150 149
     @Override
151 150
     public Void visitConstantSByte(ConstantSByteExpression expression) {
152
-        javaWriter.constant(expression.value);
151
+        getJavaWriter().constant(expression.value);
153 152
         return null;
154 153
     }
155 154
 
156 155
     @Override
157 156
     public Void visitConstantShort(ConstantShortExpression expression) {
158
-        javaWriter.siPush(expression.value);
157
+        getJavaWriter().siPush(expression.value);
159 158
         return null;
160 159
     }
161 160
 
162 161
     @Override
163 162
     public Void visitConstantString(ConstantStringExpression expression) {
164
-        javaWriter.constant(expression.value);
163
+        getJavaWriter().constant(expression.value);
165 164
         return null;
166 165
     }
167 166
 
168 167
     @Override
169 168
     public Void visitConstantUInt(ConstantUIntExpression expression) {
170
-        javaWriter.constant(expression.value);
169
+        getJavaWriter().constant(expression.value);
171 170
         return null;
172 171
     }
173 172
 
174 173
     @Override
175 174
     public Void visitConstantULong(ConstantULongExpression expression) {
176
-        javaWriter.constant(expression.value);
175
+        getJavaWriter().constant(expression.value);
177 176
         return null;
178 177
     }
179 178
 
180 179
     @Override
181 180
     public Void visitConstantUShort(ConstantUShortExpression expression) {
182
-        javaWriter.constant(expression.value);
181
+        getJavaWriter().constant(expression.value);
183 182
         return null;
184 183
     }
185 184
 
@@ -210,6 +209,8 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
210 209
 
211 210
     @Override
212 211
     public Void visitGetField(GetFieldExpression expression) {
212
+        if (!checkAndGetFieldInfo(expression.field, false))
213
+            throw new IllegalStateException("Missing field info on a field member!");
213 214
         return null;
214 215
     }
215 216
 
@@ -220,20 +221,15 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
220 221
 
221 222
     @Override
222 223
     public Void visitGetLocalVariable(GetLocalVariableExpression expression) {
224
+        final JavaLocalVariableInfo tag = expression.variable.getTag(JavaLocalVariableInfo.class);
225
+        javaWriter.load(tag.type, tag.local);
223 226
         return null;
224 227
     }
225 228
 
226 229
     @Override
227 230
     public Void visitGetStaticField(GetStaticFieldExpression expression) {
228
-		JavaFieldInfo fieldInfo = expression.field.getTag(JavaFieldInfo.class);
229
-		if (fieldInfo == null)
230
-			throw new IllegalStateException("Missing field info on a field member!");
231
-		
232
-		javaWriter.getStaticField(
233
-				fieldInfo.javaClass.internalClassName,
234
-				fieldInfo.name,
235
-				fieldInfo.signature);
236
-		
231
+        if (!checkAndGetFieldInfo(expression.field, true))
232
+            throw new IllegalStateException("Missing field info on a field member!");
237 233
         return null;
238 234
     }
239 235
 
@@ -244,36 +240,66 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
244 240
 
245 241
     @Override
246 242
     public Void visitInterfaceCast(InterfaceCastExpression expression) {
243
+        expression.value.accept(this);
244
+        javaWriter.checkCast(expression.type.accept(JavaTypeClassVisitor.INSTANCE));
247 245
         return null;
248 246
     }
249 247
 
250 248
     @Override
251 249
     public Void visitIs(IsExpression expression) {
250
+        expression.value.accept(this);
251
+        javaWriter.instanceOf(Type.getDescriptor(expression.isType.accept(JavaTypeClassVisitor.INSTANCE)));
252 252
         return null;
253 253
     }
254 254
 
255 255
     @Override
256
-    public Void visitMakeConst(MakeConstExpression expression) {
256
+    public Void visitMakeConst(MakeConstExpression expression)
257
+    {
258
+
257 259
         return null;
258 260
     }
259 261
 
260 262
     @Override
261 263
     public Void visitMap(MapExpression expression) {
264
+        javaWriter.newObject(expression.type.accept(JavaTypeClassVisitor.INSTANCE));
265
+        javaWriter.dup();
266
+        javaWriter.invokeSpecial("java/util/Map", "<init>", "()V");
267
+        for (int i = 0; i < expression.keys.length; i++) {
268
+            javaWriter.dup();
269
+            expression.keys[i].accept(this);
270
+            expression.values[i].accept(this);
271
+            javaWriter.invokeInterface(Map.class, "put", Object.class, Object.class, Object.class);
272
+            javaWriter.pop();
273
+        }
262 274
         return null;
263 275
     }
264 276
 
265 277
     @Override
266 278
     public Void visitNew(NewExpression expression) {
279
+        String type = Type.getDescriptor(expression.type.accept(JavaTypeClassVisitor.INSTANCE));
280
+        javaWriter.newObject(type);
281
+        javaWriter.dup();
282
+        StringBuilder signatureBuilder = new StringBuilder("(");
283
+        for (Expression argument : expression.arguments.arguments) {
284
+            argument.accept(this);
285
+            signatureBuilder.append(Type.getDescriptor(argument.type.accept(JavaTypeClassVisitor.INSTANCE)));
286
+        }
287
+        signatureBuilder.append(")V");
288
+        javaWriter.invokeSpecial(type, "<init>", signatureBuilder.toString());
289
+
267 290
         return null;
268 291
     }
269 292
 
270 293
     @Override
271 294
     public Void visitNot(NotExpression expression) {
295
+        expression.value.accept(this);
296
+        javaWriter.iNeg();
272 297
         return null;
273 298
     }
274 299
 
275 300
     @Override
276 301
     public Void visitNull(NullExpression expression) {
302
+        javaWriter.aConstNull();
277 303
         return null;
278 304
     }
279 305
 
@@ -284,11 +310,25 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
284 310
 
285 311
     @Override
286 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
+
287 322
         return null;
288 323
     }
289 324
 
290 325
     @Override
291 326
     public Void visitSetField(SetFieldExpression expression) {
327
+        if (expression.field.isFinal)
328
+            throw new CompileException(expression.position, CompileExceptionCode.CANNOT_SET_FINAL_VARIABLE, "Cannot set a final field!");
329
+        expression.value.accept(this);
330
+        if (!checkAndPutFieldInfo(expression.field, false))
331
+            throw new IllegalStateException("Missing field info on a field member!");
292 332
         return null;
293 333
     }
294 334
 
@@ -299,11 +339,23 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
299 339
 
300 340
     @Override
301 341
     public Void visitSetLocalVariable(SetLocalVariableExpression expression) {
342
+        if (expression.variable.isFinal)
343
+            throw new CompileException(expression.position, CompileExceptionCode.CANNOT_SET_FINAL_VARIABLE, "Cannot set a final variable!");
344
+        expression.value.accept(this);
345
+        final JavaLocalVariableInfo tag = expression.variable.getTag(JavaLocalVariableInfo.class);
346
+
347
+        javaWriter.store(tag.type, tag.local);
348
+
302 349
         return null;
303 350
     }
304 351
 
305 352
     @Override
306 353
     public Void visitSetStaticField(SetStaticFieldExpression expression) {
354
+        if (expression.field.isFinal)
355
+            throw new CompileException(expression.position, CompileExceptionCode.CANNOT_SET_FINAL_VARIABLE, "Cannot set a final field!");
356
+        expression.value.accept(this);
357
+        if (!checkAndPutFieldInfo(expression.field, true))
358
+            throw new IllegalStateException("Missing field info on a field member!");
307 359
         return null;
308 360
     }
309 361
 
@@ -341,4 +393,65 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
341 393
     public Void visitWrapOptional(WrapOptionalExpression expression) {
342 394
         return null;
343 395
     }
396
+
397
+    public JavaWriter getJavaWriter() {
398
+        return javaWriter;
399
+    }
400
+
401
+
402
+    //Will return true if a JavaBytecodeImplementation.class tag exists, and will compile that tag
403
+    private boolean checkAndExecuteByteCodeImplementation(DefinitionMember member) {
404
+        JavaBytecodeImplementation implementation = member.getTag(JavaBytecodeImplementation.class);
405
+        if (implementation != null) {
406
+            implementation.compile(getJavaWriter());
407
+            return true;
408
+        }
409
+        return false;
410
+    }
411
+
412
+    //Will return true if a JavaMethodInfo.class tag exists, and will compile that tag
413
+    private boolean checkAndExecuteMethodInfo(DefinitionMember member) {
414
+        JavaMethodInfo methodInfo = member.getTag(JavaMethodInfo.class);
415
+        if (methodInfo == null)
416
+            return false;
417
+        if (methodInfo.isStatic) {
418
+            getJavaWriter().invokeStatic(
419
+                    methodInfo.javaClass.internalClassName,
420
+                    methodInfo.name,
421
+                    methodInfo.signature);
422
+        } else {
423
+            getJavaWriter().invokeVirtual(
424
+                    methodInfo.javaClass.internalClassName,
425
+                    methodInfo.name,
426
+                    methodInfo.signature);
427
+        }
428
+        return true;
429
+    }
430
+
431
+
432
+    //TODO: Should isStatic go to the fieldInfo or stay here?
433
+    //Will return true if a JavaFieldInfo.class tag exists, and will compile that tag
434
+    private boolean checkAndPutFieldInfo(DefinitionMember field, boolean isStatic) {
435
+        JavaFieldInfo fieldInfo = field.getTag(JavaFieldInfo.class);
436
+        if (fieldInfo == null)
437
+            return false;
438
+        if (isStatic) {
439
+            getJavaWriter().putStaticField(fieldInfo.javaClass.internalClassName, fieldInfo.name, fieldInfo.signature);
440
+        } else {
441
+            getJavaWriter().putField(fieldInfo.javaClass.internalClassName, fieldInfo.name, fieldInfo.signature);
442
+        }
443
+        return true;
444
+    }
445
+
446
+    private boolean checkAndGetFieldInfo(DefinitionMember field, boolean isStatic) {
447
+        JavaFieldInfo fieldInfo = field.getTag(JavaFieldInfo.class);
448
+        if (fieldInfo == null)
449
+            return false;
450
+        if (isStatic) {
451
+            getJavaWriter().getStaticField(fieldInfo.javaClass.internalClassName, fieldInfo.name, fieldInfo.signature);
452
+        } else {
453
+            getJavaWriter().getField(fieldInfo.javaClass.internalClassName, fieldInfo.name, fieldInfo.signature);
454
+        }
455
+        return true;
456
+    }
344 457
 }

+ 85
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaForeachVisitor.java 파일 보기

@@ -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
+}

+ 96
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java 파일 보기

@@ -1,53 +1,118 @@
1 1
 package org.openzen.zenscript.javabytecode.compiler;
2 2
 
3
+import org.objectweb.asm.Label;
4
+import org.objectweb.asm.Type;
3 5
 import org.openzen.zenscript.codemodel.statement.*;
6
+import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
4 7
 
5 8
 public class JavaStatementVisitor implements StatementVisitor<Void> {
6 9
     private final JavaWriter javaWriter;
10
+    private final JavaExpressionVisitor expressionVisitor;
7 11
 
8 12
     public JavaStatementVisitor(final JavaWriter javaWriter) {
9 13
 
10 14
         this.javaWriter = javaWriter;
15
+        this.expressionVisitor = new JavaExpressionVisitor(javaWriter);
11 16
     }
12 17
 
13 18
     @Override
14 19
     public Void visitBlock(BlockStatement statement) {
20
+        for (Statement statement1 : statement.statements) {
21
+            statement1.accept(this);
22
+        }
15 23
         return null;
16 24
     }
17 25
 
18 26
     @Override
19 27
     public Void visitBreak(BreakStatement statement) {
28
+        javaWriter.goTo(javaWriter.getNamedLabel(statement.target.label + "_end"));
20 29
         return null;
21 30
     }
22 31
 
23 32
     @Override
24 33
     public Void visitContinue(ContinueStatement statement) {
34
+        javaWriter.goTo(javaWriter.getNamedLabel(statement.target.label + "_start"));
25 35
         return null;
26 36
     }
27 37
 
28 38
     @Override
29 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);
30 54
         return null;
31 55
     }
32 56
 
33 57
     @Override
34 58
     public Void visitEmpty(EmptyStatement statement) {
59
+        //No-Op
35 60
         return null;
36 61
     }
37 62
 
38 63
     @Override
39 64
     public Void visitExpression(ExpressionStatement statement) {
40
-        statement.expression.accept(new JavaExpressionVisitor(javaWriter));
65
+        statement.expression.accept(expressionVisitor);
41 66
         return null;
42 67
     }
43 68
 
44 69
     @Override
45 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);
46 94
         return null;
47 95
     }
48 96
 
49 97
     @Override
50 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);
51 116
         return null;
52 117
     }
53 118
 
@@ -58,11 +123,15 @@ public class JavaStatementVisitor implements StatementVisitor<Void> {
58 123
 
59 124
     @Override
60 125
     public Void visitReturn(ReturnStatement statement) {
126
+        statement.value.accept(expressionVisitor);
127
+        javaWriter.returnType(Type.getType(statement.value.type.accept(JavaTypeClassVisitor.INSTANCE)));
61 128
         return null;
62 129
     }
63 130
 
64 131
     @Override
65 132
     public Void visitThrow(ThrowStatement statement) {
133
+        statement.value.accept(expressionVisitor);
134
+        javaWriter.aThrow();
66 135
         return null;
67 136
     }
68 137
 
@@ -73,11 +142,33 @@ public class JavaStatementVisitor implements StatementVisitor<Void> {
73 142
 
74 143
     @Override
75 144
     public Void visitVar(VarStatement statement) {
145
+        Type type = Type.getType(statement.type.accept(JavaTypeClassVisitor.INSTANCE));
146
+        int local = javaWriter.local(type);
147
+        if (statement.initializer != null) {
148
+            statement.initializer.accept(expressionVisitor);
149
+            javaWriter.store(type, local);
150
+        }
151
+        statement.setTag(JavaLocalVariableInfo.class, new JavaLocalVariableInfo(type, local));
76 152
         return null;
77 153
     }
78 154
 
79 155
     @Override
80 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);
81 172
         return null;
82 173
     }
83 174
 
@@ -89,4 +180,8 @@ public class JavaStatementVisitor implements StatementVisitor<Void> {
89 180
         javaWriter.ret();
90 181
         javaWriter.end();
91 182
     }
183
+
184
+    public JavaWriter getJavaWriter() {
185
+        return javaWriter;
186
+    }
92 187
 }

+ 92
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaTypeClassVisitor.java 파일 보기

@@ -0,0 +1,92 @@
1
+package org.openzen.zenscript.javabytecode.compiler;
2
+
3
+import org.openzen.zenscript.codemodel.type.*;
4
+
5
+import java.lang.reflect.Array;
6
+import java.util.Iterator;
7
+import java.util.Map;
8
+
9
+public class JavaTypeClassVisitor implements ITypeVisitor<Class> {
10
+
11
+    public static final JavaTypeClassVisitor INSTANCE = new JavaTypeClassVisitor();
12
+
13
+    @Override
14
+    public Class visitBasic(BasicTypeID basic) {
15
+        switch (basic) {
16
+            case VOID:
17
+                return void.class;
18
+            case ANY:
19
+            case NULL:
20
+            case UNDETERMINED:
21
+                return Object.class;
22
+            case BOOL:
23
+                return boolean.class;
24
+            case BYTE:
25
+            case SBYTE:
26
+                return byte.class;
27
+            case SHORT:
28
+            case USHORT:
29
+                return short.class;
30
+            case INT:
31
+            case UINT:
32
+                return int.class;
33
+            case LONG:
34
+            case ULONG:
35
+                return long.class;
36
+            case FLOAT:
37
+                return float.class;
38
+            case DOUBLE:
39
+                return double.class;
40
+            case CHAR:
41
+                return char.class;
42
+            case STRING:
43
+                return String.class;
44
+        }
45
+        return Object.class;
46
+    }
47
+
48
+    @Override
49
+    public Class visitArray(ArrayTypeID array) {
50
+        return Array.newInstance(array.elementType.accept(this), 0).getClass();
51
+    }
52
+
53
+    @Override
54
+    public Class visitAssoc(AssocTypeID assoc) {
55
+        return Map.class;
56
+    }
57
+
58
+    @Override
59
+    public Class visitIterator(IteratorTypeID iterator) {
60
+        return Iterator.class;
61
+    }
62
+
63
+    @Override
64
+    public Class visitFunction(FunctionTypeID function) {
65
+        return null;
66
+    }
67
+
68
+    @Override
69
+    public Class visitDefinition(DefinitionTypeID definition) {
70
+        return null;
71
+    }
72
+
73
+    @Override
74
+    public Class visitGeneric(GenericTypeID generic) {
75
+        return null;
76
+    }
77
+
78
+    @Override
79
+    public Class visitRange(RangeTypeID range) {
80
+        return null;
81
+    }
82
+
83
+    @Override
84
+    public Class visitConst(ConstTypeID type) {
85
+        return type.baseType.accept(this);
86
+    }
87
+
88
+    @Override
89
+    public Class visitOptional(OptionalTypeID optional) {
90
+        return null;
91
+    }
92
+}

+ 0
- 92
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaTypeSignatureVisitor.java 파일 보기

@@ -1,92 +0,0 @@
1
-package org.openzen.zenscript.javabytecode.compiler;
2
-
3
-import org.openzen.zenscript.codemodel.type.*;
4
-import org.openzen.zenscript.javabytecode.JavaClassInfo;
5
-import org.openzen.zenscript.shared.CompileException;
6
-
7
-public class JavaTypeSignatureVisitor implements ITypeVisitor<String> {
8
-    @Override
9
-    public String visitBasic(BasicTypeID basic) {
10
-        switch (basic) {
11
-            case VOID:
12
-                return "V";
13
-            case NULL:
14
-            case ANY:
15
-            case UNDETERMINED:
16
-                return "Ljava/lang/Object;";
17
-            case BOOL:
18
-                return "Z";
19
-            case BYTE:
20
-            case SBYTE:
21
-                return "B";
22
-            case SHORT:
23
-            case USHORT:
24
-                return "S";
25
-            case INT:
26
-            case UINT:
27
-                return "I";
28
-            case LONG:
29
-            case ULONG:
30
-                return "J";
31
-            case FLOAT:
32
-                return "F";
33
-            case DOUBLE:
34
-                return "D";
35
-            case CHAR:
36
-                return "C";
37
-            case STRING:
38
-                return "Ljava/lang/String;";
39
-        }
40
-        return "";
41
-    }
42
-
43
-    @Override
44
-    public String visitArray(ArrayTypeID array) {
45
-        return "[" + array.elementType.accept(this);
46
-    }
47
-
48
-    @Override
49
-    public String visitAssoc(AssocTypeID assoc) {
50
-        return "Ljava/util/Map;";
51
-    }
52
-
53
-    @Override
54
-    public String visitIterator(IteratorTypeID iterator) {
55
-        return "java/lang/Iterable";
56
-    }
57
-
58
-    @Override
59
-    public String visitFunction(FunctionTypeID function) {
60
-        return null;
61
-    }
62
-
63
-    @Override
64
-    public String visitDefinition(DefinitionTypeID definition) {
65
-		JavaClassInfo classInfo = definition.definition.getTag(JavaClassInfo.class);
66
-		if (classInfo == null)
67
-			throw CompileException.internalError("Definition is missing java class tag!");
68
-		
69
-        return "L" + classInfo.internalClassName + ";";
70
-    }
71
-
72
-    @Override
73
-    public String visitGeneric(GenericTypeID generic) {
74
-		// TODO: type erasure
75
-        return null;
76
-    }
77
-
78
-    @Override
79
-    public String visitRange(RangeTypeID range) {
80
-        return null;
81
-    }
82
-
83
-    @Override
84
-    public String visitConst(ConstTypeID type) {
85
-		return type.baseType.accept(this);
86
-    }
87
-
88
-    @Override
89
-    public String visitOptional(OptionalTypeID optional) {
90
-        return null;
91
-    }
92
-}

+ 23
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java 파일 보기

@@ -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
 
@@ -1064,4 +1064,26 @@ public class JavaWriter {
1064 1064
 
1065 1065
         return labelNames.get(lbl);
1066 1066
     }
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
+
1078
+    public void stringAdd() {
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!");
1088
+    }
1067 1089
 }

+ 2
- 2
Linker/src/main/java/org/openzen/zenscript/linker/BaseScope.java 파일 보기

@@ -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 파일 보기

@@ -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 파일 보기

@@ -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 파일 보기

@@ -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 파일 보기

@@ -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 파일 보기

@@ -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 파일 보기

@@ -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 파일 보기

@@ -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 파일 보기

@@ -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 파일 보기

@@ -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 파일 보기

@@ -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 파일 보기

@@ -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 파일 보기

@@ -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 파일 보기

@@ -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 파일 보기

@@ -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()

+ 83
- 4
ScriptingExample/scripts/moreHellos.zs 파일 보기

@@ -1,5 +1,84 @@
1 1
 println("Hello world!");
2
-println("Hello world!");
3
-println("Hello world!");
4
-println("Hello world!");
5
-println("Hello world!");
2
+println(1 as string);
3
+
4
+
5
+var test = "test";
6
+println(test);
7
+
8
+
9
+test = "testMore";
10
+println(test);
11
+
12
+test = 13;
13
+println(test);
14
+
15
+val test2 = 14;
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 파일 보기

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

+ 266
- 0
Shared/out/production/resources/org/openzen/zenscript/shared/characterEntities.properties 파일 보기

@@ -0,0 +1,266 @@
1
+quot=34
2
+amp=38
3
+apos=39
4
+lt=60
5
+gt=62
6
+
7
+nbsp=160
8
+iexcl=161
9
+cent=162
10
+pound=163
11
+curren=164
12
+yen=165
13
+brvbar=166
14
+sect=167
15
+uml=168
16
+copy=169
17
+ordf=170
18
+laquo=171
19
+not=172
20
+shy=173
21
+reg=174
22
+macr=175
23
+deg=176
24
+plusmn=177
25
+sup2=178
26
+sup3=179
27
+acute=180
28
+micro=181
29
+para=182
30
+middot=183
31
+cedil=184
32
+sup1=185
33
+ordm=186
34
+raquo=187
35
+frac14=188
36
+frac12=189
37
+frac34=190
38
+iquest=191
39
+
40
+Agrave=192
41
+Aacute=193
42
+Acirc=194
43
+Atilde=195
44
+Auml=196
45
+Aring=197
46
+AElig=198
47
+Ccedil=199
48
+Egrave=200
49
+Eacute=201
50
+Ecirc=202
51
+Euml=203
52
+lgrave=204
53
+lacute=205
54
+lcirc=206
55
+luml=207
56
+ETH=208
57
+Ntilde=209
58
+Ograve=210
59
+Oacute=211
60
+Ocirc=212
61
+Otilde=213
62
+Ouml=214
63
+times=215
64
+Oslash=216
65
+Ugrave=217
66
+Uacute=218
67
+Ucirc=219
68
+Uuml=220
69
+Yacute=221
70
+THORN=222
71
+szlig=223
72
+agrave=224
73
+aacute=225
74
+acirc=226
75
+atilde=227
76
+auml=228
77
+aring=229
78
+aelig=230
79
+ccedil=231
80
+egrave=232
81
+eacute=233
82
+ecirc=234
83
+euml=235
84
+igrave=236
85
+iacute=237
86
+icirc=238
87
+iuml=239
88
+eth=240
89
+ntilde=241
90
+ograve=242
91
+oacute=243
92
+ocirc=244
93
+otilde=245
94
+ouml=246
95
+divide=247
96
+oslash=248
97
+ugrave=249
98
+uacute=250
99
+ucirc=251
100
+uuml=252
101
+yacute=253
102
+thorn=254
103
+yuml=255
104
+
105
+OElig=338
106
+oelig=339
107
+Scaron=352
108
+scaron=353
109
+Yuml=376
110
+
111
+fnof=402
112
+
113
+circ=710
114
+tilde=732
115
+
116
+Alpha=913
117
+Beta=914
118
+Gamma=915
119
+Delta=916
120
+Epsilon=917
121
+Zeta=918
122
+Eta=919
123
+Theta=920
124
+Iota=921
125
+Kappa=922
126
+Lambda=923
127
+Mu=924
128
+Nu=925
129
+Xi=926
130
+Omicron=927
131
+Pi=928
132
+Rho=929
133
+Sigma=931
134
+Tau=932
135
+Upsilon=933
136
+Phi=934
137
+Chi=935
138
+Psi=936
139
+Omega=937
140
+
141
+alpha=945
142
+beta=946
143
+gamma=947
144
+delta=948
145
+epsilon=949
146
+zeta=950
147
+eta=951
148
+theta=952
149
+iota=953
150
+kappa=954
151
+lambda=955
152
+mu=956
153
+nu=957
154
+xi=958
155
+omicron=959
156
+pi=960
157
+rho=961
158
+sigmaf=962
159
+sigma=963
160
+tau=964
161
+upsilon=965
162
+phi=966
163
+chi=967
164
+psi=968
165
+omega=969
166
+thetasym=977
167
+upsih=978
168
+piv=982
169
+
170
+ensp=8194
171
+emsp=8195
172
+thinsp=8201
173
+zwnj=8204
174
+zwj=8205
175
+lrm=8206
176
+rlm=8207
177
+ndash=8211
178
+mdash=8212
179
+lsquo=8216
180
+rsquo=8217
181
+sbquo=8218
182
+ldquo=8220
183
+rdquo=8221
184
+bdquo=8222
185
+dagger=8224
186
+Dagger=8225
187
+bull=8226
188
+hellip=8230
189
+permil=8240
190
+prime=8242
191
+Prime=8243
192
+lsaquo=8249
193
+rsaquo=8250
194
+oline=8254
195
+frasl=8260
196
+
197
+euro=8364
198
+
199
+image=8465
200
+weierp=8472
201
+real=8476
202
+trade=8482
203
+alefsym=8501
204
+
205
+larr=8592
206
+uarr=8593
207
+rarr=8594
208
+darr=8595
209
+harr=8596
210
+crarr=8629
211
+lArr=8656
212
+uArr=8657
213
+rArr=8658
214
+dArr=8659
215
+hArr=8660
216
+
217
+forall=8704
218
+part=8706
219
+exist=8707
220
+empty=8709
221
+nabla=8711
222
+isin=8712
223
+notin=8713
224
+ni=8715
225
+prod=8719
226
+sum=8721
227
+minus=8722
228
+lowast=8727
229
+radic=8730
230
+prop=8733
231
+infin=8734
232
+ang=8736
233
+and=8743
234
+or=8744
235
+cap=8745
236
+cup=8746
237
+int=8747
238
+there4=8756
239
+sim=8764
240
+cong=8773
241
+asymp=8776
242
+ne=8800
243
+equiv=8801
244
+le=8804
245
+ge=8805
246
+sub=8834
247
+sup=8835
248
+nsub=8836
249
+sube=8838
250
+supe=8839
251
+oplus=8853
252
+otimes=8855
253
+perp=8869
254
+sdot=8901
255
+
256
+lceil=8968
257
+rceil=8969
258
+lfloor=8970
259
+rfloor=8971
260
+lang=9001
261
+rang=9002
262
+loz=9674
263
+spades=9824
264
+clubs=8927
265
+hearts=9829
266
+diams=9830

+ 2
- 1
Shared/src/main/java/org/openzen/zenscript/shared/CompileExceptionCode.java 파일 보기

@@ -55,5 +55,6 @@ public enum CompileExceptionCode {
55 55
 	RETURN_VALUE_REQUIRED,
56 56
 	RETURN_VALUE_VOID,
57 57
 	INVALID_CONDITION,
58
-	INTERNAL_ERROR
58
+	INTERNAL_ERROR,
59
+	CANNOT_SET_FINAL_VARIABLE
59 60
 }

+ 19
- 10
Shared/src/main/java/org/openzen/zenscript/shared/TagDictionary.java 파일 보기

@@ -5,21 +5,30 @@
5 5
  */
6 6
 package org.openzen.zenscript.shared;
7 7
 
8
+import java.util.Collections;
8 9
 import java.util.HashMap;
9 10
 import java.util.Map;
10 11
 
11 12
 /**
12
- *
13 13
  * @author Hoofdgebruiker
14 14
  */
15
+@SuppressWarnings("unchecked")
15 16
 public class TagDictionary {
16
-	private final Map<Class<?>, Object> tags = new HashMap<>();
17
-	
18
-	public <T> void put(Class<T> cls, T tag) {
19
-		tags.put(cls, tag);
20
-	}
21
-	
22
-	public <T> T get(Class<T> cls) {
23
-		return (T) tags.get(cls);
24
-	}
17
+    private Map<Class<?>, Object> tags = Collections.EMPTY_MAP;
18
+
19
+    public <T> void put(Class<T> cls, T tag) {
20
+        if (tags == Collections.EMPTY_MAP) {
21
+            tags = Collections.singletonMap(cls, tag);
22
+        } else if (tags.size() == 1) {
23
+            Map<Class<?>, Object> newTags = new HashMap<>(tags);
24
+            newTags.put(cls, tag);
25
+            this.tags = newTags;
26
+        } else {
27
+            tags.put(cls, tag);
28
+        }
29
+    }
30
+
31
+    public <T> T get(Class<T> cls) {
32
+        return (T) tags.get(cls);
33
+    }
25 34
 }

Loading…
취소
저장