Переглянути джерело

- Added static initializers

- Added switch statements
- Started work on increment and decrement operators
- Starting work on Constructor, the build tool
Stan Hebben 6 роки тому
джерело
коміт
7c33560a67
92 змінених файлів з 3007 додано та 198 видалено
  1. 8
    7
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/ExpressionFormatter.java
  2. 6
    0
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/FormattingUtils.java
  3. 11
    4
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/MemberFormatter.java
  4. 32
    0
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/StatementFormatter.java
  5. 11
    0
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/TypeFormatter.java
  6. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java
  7. 10
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/OperatorType.java
  8. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/FunctionDefinition.java
  9. 7
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ZSPackage.java
  10. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionVisitor.java
  11. 36
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/PostCallExpression.java
  12. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/TypeParameter.java
  13. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/MemberVisitor.java
  14. 54
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/StaticInitializerMember.java
  15. 68
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/StringCharIterator.java
  16. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialStaticMemberGroupExpression.java
  17. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/StatementVisitor.java
  18. 23
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/SwitchCase.java
  19. 31
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/SwitchStatement.java
  20. 3
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ArrayTypeID.java
  21. 98
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericMapTypeID.java
  22. 18
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GlobalTypeRegistry.java
  23. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ITypeID.java
  24. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ITypeVisitor.java
  25. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/RangeTypeID.java
  26. 0
    22
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeExpansionRegistry.java
  27. 107
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/BuiltinTypeMembers.java
  28. 24
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/DefinitionMemberGroup.java
  29. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/LocalMemberCache.java
  30. 58
    45
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java
  31. 36
    10
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMembers.java
  32. 22
    0
      Constructor/build.gradle
  33. 9
    0
      Constructor/libraries/stdlib/module.json
  34. 5
    0
      Constructor/libraries/stdlib/src/Chars.zs
  35. 4
    0
      Constructor/libraries/stdlib/src/Exception.zs
  36. 5
    0
      Constructor/libraries/stdlib/src/IllegalArgumentException.zs
  37. 5
    0
      Constructor/libraries/stdlib/src/Integers.zs
  38. 10
    0
      Constructor/libraries/stdlib/src/StringBuilder.zs
  39. 62
    0
      Constructor/libraries/stdlib/src/Strings.zs
  40. 53
    0
      Constructor/src/main/java/org/openzen/zenscript/constructor/Arguments.java
  41. 20
    0
      Constructor/src/main/java/org/openzen/zenscript/constructor/ConstructorException.java
  42. 28
    0
      Constructor/src/main/java/org/openzen/zenscript/constructor/JSONUtils.java
  43. 44
    0
      Constructor/src/main/java/org/openzen/zenscript/constructor/Main.java
  44. 154
    0
      Constructor/src/main/java/org/openzen/zenscript/constructor/Module.java
  45. 56
    0
      Constructor/src/main/java/org/openzen/zenscript/constructor/ModuleLoader.java
  46. 28
    0
      Constructor/src/main/java/org/openzen/zenscript/constructor/Project.java
  47. 91
    0
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleLoader.java
  48. 25
    0
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/FileContents.java
  49. 14
    0
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/ModuleReference.java
  50. 54
    0
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/ModuleSpace.java
  51. 47
    0
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/SemanticModule.java
  52. 2
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java
  53. 5
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaParameterInfo.java
  54. 0
    9
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/TestIsStaticInfo.java
  55. 14
    5
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/CompilerUtils.java
  56. 15
    5
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
  57. 6
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaOptionalTypeClassVisitor.java
  58. 395
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreDecrementVisitor.java
  59. 401
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreIncrementVisitor.java
  60. 5
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java
  61. 5
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaTypeClassVisitor.java
  62. 5
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaTypeVisitor.java
  63. 40
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java
  64. 6
    2
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaDefinitionVisitor.java
  65. 32
    4
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaMemberVisitor.java
  66. 3
    0
      Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenStream.java
  67. 8
    0
      Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenType.java
  68. 5
    1
      Parser/src/main/java/org/openzen/zenscript/parser/ParsedDefinition.java
  69. 13
    0
      Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java
  70. 2
    3
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedExpansion.java
  71. 45
    15
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpression.java
  72. 12
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionMap.java
  73. 42
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionPostCall.java
  74. 79
    29
      Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedDefinitionMember.java
  75. 8
    1
      Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedField.java
  76. 53
    0
      Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedStaticInitializer.java
  77. 32
    0
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatement.java
  78. 109
    0
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementSwitch.java
  79. 37
    0
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedSwitchCase.java
  80. 5
    0
      Parser/src/main/java/org/openzen/zenscript/parser/type/IParsedType.java
  81. 117
    0
      Parser/src/main/java/org/openzen/zenscript/parser/type/ParsedTypeGenericMap.java
  82. 0
    7
      Shared/src/main/java/org/openzen/zenscript/shared/CodePosition.java
  83. 2
    1
      Shared/src/main/java/org/openzen/zenscript/shared/CompileExceptionCode.java
  84. 2
    2
      Shared/src/main/java/org/openzen/zenscript/shared/StringUtils.java
  85. 2
    1
      Validator/src/main/java/org/openzen/zenscript/validator/ValidationLogEntry.java
  86. 36
    0
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionMemberValidator.java
  87. 0
    4
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionValidator.java
  88. 9
    0
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/ExpressionValidator.java
  89. 14
    0
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/StatementValidator.java
  90. 30
    10
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/SupertypeValidator.java
  91. 9
    0
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/TypeValidator.java
  92. 1
    1
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/ValidationUtils.java

+ 8
- 7
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/ExpressionFormatter.java Переглянути файл

@@ -54,6 +54,7 @@ import org.openzen.zenscript.codemodel.expression.MapExpression;
54 54
 import org.openzen.zenscript.codemodel.expression.NewExpression;
55 55
 import org.openzen.zenscript.codemodel.expression.NullExpression;
56 56
 import org.openzen.zenscript.codemodel.expression.OrOrExpression;
57
+import org.openzen.zenscript.codemodel.expression.PostCallExpression;
57 58
 import org.openzen.zenscript.codemodel.expression.RangeExpression;
58 59
 import org.openzen.zenscript.codemodel.expression.SetFieldExpression;
59 60
 import org.openzen.zenscript.codemodel.expression.SetFunctionParameterExpression;
@@ -65,7 +66,6 @@ import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
65 66
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
66 67
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
67 68
 import org.openzen.zenscript.codemodel.member.OperatorMember;
68
-import org.openzen.zenscript.codemodel.type.ITypeID;
69 69
 import org.openzen.zenscript.shared.StringUtils;
70 70
 
71 71
 /**
@@ -209,13 +209,9 @@ public class ExpressionFormatter implements ExpressionVisitor<ExpressionString>
209 209
 					return binary(expression.target, expression.getFirstArgument(), OperatorPriority.XORASSIGN, " &= ");
210 210
 				case XORASSIGN:
211 211
 					return binary(expression.target, expression.getFirstArgument(), OperatorPriority.XORASSIGN, " ^= ");
212
-				case POST_INCREMENT:
213
-					return unaryPostfix(expression.target, OperatorPriority.DECREMENT, "++");
214
-				case POST_DECREMENT:
215
-					return unaryPostfix(expression.target, OperatorPriority.DECREMENT, "--");
216
-				case PRE_INCREMENT:
212
+				case INCREMENT:
217 213
 					return unaryPrefix(expression.target, OperatorPriority.DECREMENT, "++");
218
-				case PRE_DECREMENT:
214
+				case DECREMENT:
219 215
 					return unaryPrefix(expression.target, OperatorPriority.DECREMENT, "--");
220 216
 				case CALL: {
221 217
 					StringBuilder result = new StringBuilder();
@@ -526,6 +522,11 @@ public class ExpressionFormatter implements ExpressionVisitor<ExpressionString>
526 522
 	public ExpressionString visitOrOr(OrOrExpression expression) {
527 523
 		return binary(expression.left, expression.right, OperatorPriority.OROR, " || ");
528 524
 	}
525
+	
526
+	@Override
527
+	public ExpressionString visitPostCall(PostCallExpression expression) {
528
+		return unaryPostfix(expression.target, OperatorPriority.INCREMENT, expression.member.operator == OperatorType.INCREMENT ? "++" : "--");
529
+	}
529 530
 
530 531
 	@Override
531 532
 	public ExpressionString visitRange(RangeExpression expression) {

+ 6
- 0
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/FormattingUtils.java Переглянути файл

@@ -24,6 +24,7 @@ import org.openzen.zenscript.codemodel.statement.LockStatement;
24 24
 import org.openzen.zenscript.codemodel.statement.ReturnStatement;
25 25
 import org.openzen.zenscript.codemodel.statement.Statement;
26 26
 import org.openzen.zenscript.codemodel.statement.StatementVisitor;
27
+import org.openzen.zenscript.codemodel.statement.SwitchStatement;
27 28
 import org.openzen.zenscript.codemodel.statement.ThrowStatement;
28 29
 import org.openzen.zenscript.codemodel.statement.TryCatchStatement;
29 30
 import org.openzen.zenscript.codemodel.statement.VarStatement;
@@ -229,6 +230,11 @@ public class FormattingUtils {
229 230
 			return null;
230 231
 		}
231 232
 
233
+		@Override
234
+		public Void visitSwitch(SwitchStatement statement) {
235
+			return statementFormatter.visitSwitch(statement);
236
+		}
237
+
232 238
 		@Override
233 239
 		public Void visitThrow(ThrowStatement statement) {
234 240
 			return statementFormatter.visitThrow(statement);

+ 11
- 4
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/MemberFormatter.java Переглянути файл

@@ -5,7 +5,6 @@
5 5
  */
6 6
 package org.openzen.zenscript.formatter;
7 7
 
8
-import java.util.List;
9 8
 import org.openzen.zenscript.codemodel.Modifiers;
10 9
 import org.openzen.zenscript.codemodel.member.CallerMember;
11 10
 import org.openzen.zenscript.codemodel.member.CasterMember;
@@ -21,7 +20,7 @@ import org.openzen.zenscript.codemodel.member.MemberVisitor;
21 20
 import org.openzen.zenscript.codemodel.member.MethodMember;
22 21
 import org.openzen.zenscript.codemodel.member.OperatorMember;
23 22
 import org.openzen.zenscript.codemodel.member.SetterMember;
24
-import org.openzen.zenscript.codemodel.statement.ReturnStatement;
23
+import org.openzen.zenscript.codemodel.member.StaticInitializerMember;
25 24
 import org.openzen.zenscript.codemodel.statement.Statement;
26 25
 
27 26
 /**
@@ -153,8 +152,8 @@ public class MemberFormatter implements MemberVisitor<Void> {
153 152
 			case ANDASSIGN: output.append("&="); break;
154 153
 			case XORASSIGN: output.append("^="); break;
155 154
 	
156
-			case POST_INCREMENT: output.append("++"); break;
157
-			case POST_DECREMENT: output.append("--"); break;
155
+			case INCREMENT: output.append("++"); break;
156
+			case DECREMENT: output.append("--"); break;
158 157
 			default:
159 158
 				throw new UnsupportedOperationException("Unknown operator: " + member.operator);
160 159
 		}
@@ -219,4 +218,12 @@ public class MemberFormatter implements MemberVisitor<Void> {
219 218
 	private void formatBody(Statement body) {
220 219
 		FormattingUtils.formatBody(output, settings, indent, typeFormatter, body);
221 220
 	}
221
+
222
+	@Override
223
+	public Void visitStaticInitializer(StaticInitializerMember member) {
224
+		visit(false);
225
+		output.append("static ");
226
+		formatBody(member.body);
227
+		return null;
228
+	}
222 229
 }

+ 32
- 0
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/StatementFormatter.java Переглянути файл

@@ -21,6 +21,8 @@ import org.openzen.zenscript.codemodel.statement.LockStatement;
21 21
 import org.openzen.zenscript.codemodel.statement.ReturnStatement;
22 22
 import org.openzen.zenscript.codemodel.statement.Statement;
23 23
 import org.openzen.zenscript.codemodel.statement.StatementVisitor;
24
+import org.openzen.zenscript.codemodel.statement.SwitchCase;
25
+import org.openzen.zenscript.codemodel.statement.SwitchStatement;
24 26
 import org.openzen.zenscript.codemodel.statement.ThrowStatement;
25 27
 import org.openzen.zenscript.codemodel.statement.TryCatchStatement;
26 28
 import org.openzen.zenscript.codemodel.statement.VarStatement;
@@ -196,6 +198,36 @@ public class StatementFormatter implements StatementVisitor<Void> {
196 198
 		return null;
197 199
 	}
198 200
 
201
+	@Override
202
+	public Void visitSwitch(SwitchStatement statement) {
203
+		WhitespaceInfo whitespace = statement.getTag(WhitespaceInfo.class);
204
+		beginSingleLine(whitespace);
205
+		output.append("switch ");
206
+		if (statement.label != null)
207
+			output.append(':').append(statement.label);
208
+		
209
+		output.append(settings.getBlockSeparator(indent, position));
210
+		
211
+		StatementFormatter innerFormatter = new StatementFormatter(output, indent + settings.indent + settings.indent, settings, expressionFormatter);
212
+		for (SwitchCase switchCase : statement.cases) {
213
+			if (switchCase.value == null) {
214
+				output.append(indent).append(settings.indent).append("default:\n");
215
+			} else {
216
+				output.append(indent)
217
+						.append(settings.indent)
218
+						.append("case ")
219
+						.append(switchCase.value.accept(expressionFormatter))
220
+						.append(":\n");
221
+			}
222
+			for (Statement s : switchCase.statements)
223
+				s.accept(innerFormatter);
224
+		}
225
+		
226
+		output.append("\n").append(indent).append("}");
227
+		endSingleLine(whitespace);
228
+		return null;
229
+	}
230
+
199 231
 	@Override
200 232
 	public Void visitThrow(ThrowStatement statement) {
201 233
 		WhitespaceInfo whitespace = statement.getTag(WhitespaceInfo.class);

+ 11
- 0
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/TypeFormatter.java Переглянути файл

@@ -18,6 +18,7 @@ import org.openzen.zenscript.codemodel.type.BasicTypeID;
18 18
 import org.openzen.zenscript.codemodel.type.ConstTypeID;
19 19
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
20 20
 import org.openzen.zenscript.codemodel.type.FunctionTypeID;
21
+import org.openzen.zenscript.codemodel.type.GenericMapTypeID;
21 22
 import org.openzen.zenscript.codemodel.type.GenericTypeID;
22 23
 import org.openzen.zenscript.codemodel.type.ITypeID;
23 24
 import org.openzen.zenscript.codemodel.type.ITypeVisitor;
@@ -121,4 +122,14 @@ public class TypeFormatter implements ITypeVisitor<String>, GenericParameterBoun
121 122
 	public String visitType(ParameterTypeBound bound) {
122 123
 		return bound.type.accept(this);
123 124
 	}
125
+
126
+	@Override
127
+	public String visitGenericMap(GenericMapTypeID map) {
128
+		StringBuilder result = new StringBuilder();
129
+		result.append(map.value.accept(this));
130
+		result.append("[");
131
+		FormattingUtils.formatTypeParameters(result, map.keys, this);
132
+		result.append("]");
133
+		return result.toString();
134
+	}
124 135
 }

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java Переглянути файл

@@ -40,7 +40,7 @@ public class FunctionHeader {
40 40
 		this.parameters = parameters;
41 41
 	}
42 42
 	
43
-	public FunctionHeader(TypeParameter[] genericParameters, ITypeID returnType, FunctionParameter[] parameters) {
43
+	public FunctionHeader(TypeParameter[] genericParameters, ITypeID returnType, FunctionParameter... parameters) {
44 44
 		this.typeParameters = genericParameters;
45 45
 		this.returnType = returnType;
46 46
 		this.parameters = parameters;

+ 10
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/OperatorType.java Переглянути файл

@@ -24,6 +24,9 @@ public enum OperatorType {
24 24
 	MEMBERGETTER(".", "getMember"),
25 25
 	MEMBERSETTER(".=", "setMember"),
26 26
 	EQUALS("==", "equals"),
27
+	SHL("<<", "shl"),
28
+	SHR(">>", "shr"),
29
+	USHR(">>>", "ushr"),
27 30
 	
28 31
 	ADDASSIGN("+=", "addAssign", ADD),
29 32
 	SUBASSIGN("-=", "subAssign", SUB),
@@ -34,11 +37,14 @@ public enum OperatorType {
34 37
 	ORASSIGN("|=", "orAssign", OR),
35 38
 	ANDASSIGN("&=", "andAssign", AND),
36 39
 	XORASSIGN("^=", "xorAssign", XOR),
40
+	SHLASSIGN("<<=", "shlAssign", SHL),
41
+	SHRASSIGN(">>=", "shrAssign", SHR),
42
+	USHRASSIGN(">>>=", "ushrAssign", USHR),
37 43
 	
38
-	POST_INCREMENT("x++", "postIncrement"),
39
-	POST_DECREMENT("x--", "postDecrement"),
40
-	PRE_INCREMENT("++x", "preIncrement"),
41
-	PRE_DECREMENT("--x", "preDecrement"),
44
+	INCREMENT("++", "increment"),
45
+	DECREMENT("--", "decrement"),
46
+	
47
+	RANGE("..", "rangeTo"),
42 48
 	
43 49
 	CONSTRUCTOR("this", "construct"),
44 50
 	CALL("()", "call"),

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/FunctionDefinition.java Переглянути файл

@@ -24,7 +24,7 @@ public class FunctionDefinition extends HighLevelDefinition {
24 24
 	public FunctionHeader header;
25 25
 	public Statement statement;
26 26
 	public OperatorMember caller;
27
-	public DefinitionMemberGroup callerGroup = new DefinitionMemberGroup();
27
+	public DefinitionMemberGroup callerGroup = new DefinitionMemberGroup(true);
28 28
 	
29 29
 	public FunctionDefinition(CodePosition position, ZSPackage pkg, String name, int modifiers, HighLevelDefinition outerDefinition) {
30 30
 		super(position, pkg, name, modifiers, outerDefinition);

+ 7
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ZSPackage.java Переглянути файл

@@ -34,6 +34,13 @@ public class ZSPackage {
34 34
 	private final Map<String, ZSPackage> subPackages = new HashMap<>();
35 35
 	private final Map<String, HighLevelDefinition> types = new HashMap<>();
36 36
 	
37
+	public void add(String name, ZSPackage subPackage) {
38
+		if (subPackages.containsKey(name))
39
+			throw new RuntimeException("Such package already exists: " + name);
40
+		
41
+		subPackages.put(name, this);
42
+	}
43
+	
37 44
 	public IPartialExpression getMember(CodePosition position, GlobalTypeRegistry registry, GenericName name) {
38 45
 		if (subPackages.containsKey(name.name) && name.arguments.isEmpty())
39 46
 			return new PartialPackageExpression(position, subPackages.get(name.name));

+ 2
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionVisitor.java Переглянути файл

@@ -102,6 +102,8 @@ public interface ExpressionVisitor<T> {
102 102
 	
103 103
 	public T visitOrOr(OrOrExpression expression);
104 104
 	
105
+	public T visitPostCall(PostCallExpression expression);
106
+	
105 107
 	public T visitRange(RangeExpression expression);
106 108
 	
107 109
 	public T visitSetField(SetFieldExpression expression);

+ 36
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/PostCallExpression.java Переглянути файл

@@ -0,0 +1,36 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.FunctionHeader;
9
+import org.openzen.zenscript.codemodel.OperatorType;
10
+import org.openzen.zenscript.codemodel.member.OperatorMember;
11
+import org.openzen.zenscript.shared.CodePosition;
12
+
13
+/**
14
+ * Used for post-increment and post-decrement.
15
+ * 
16
+ * @author Hoofdgebruiker
17
+ */
18
+public class PostCallExpression extends Expression {
19
+	public final Expression target;
20
+	public final OperatorMember member;
21
+	
22
+	public PostCallExpression(CodePosition position, Expression target, OperatorMember member, FunctionHeader instancedHeader) {
23
+		super(position, instancedHeader.returnType);
24
+		
25
+		if (member.operator != OperatorType.DECREMENT && member.operator != OperatorType.INCREMENT)
26
+			throw new IllegalArgumentException("Operator must be increment or decrement");
27
+		
28
+		this.target = target;
29
+		this.member = member;
30
+	}
31
+
32
+	@Override
33
+	public <T> T accept(ExpressionVisitor<T> visitor) {
34
+		return visitor.visitPostCall(this);
35
+	}
36
+}

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/TypeParameter.java Переглянути файл

@@ -55,6 +55,6 @@ public class TypeParameter {
55 55
 	}
56 56
 	
57 57
 	public String toString() {
58
-		return name + "[" + position.toShortString() + "]";
58
+		return name + "@" + position.toShortString();
59 59
 	}
60 60
 }

+ 2
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/MemberVisitor.java Переглянути файл

@@ -33,4 +33,6 @@ public interface MemberVisitor<T> {
33 33
 	public T visitImplementation(ImplementationMember member);
34 34
 	
35 35
 	public T visitInnerDefinition(InnerDefinitionMember member);
36
+	
37
+	public T visitStaticInitializer(StaticInitializerMember member);
36 38
 }

+ 54
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/StaticInitializerMember.java Переглянути файл

@@ -0,0 +1,54 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.codemodel.member;
7
+
8
+import java.util.Map;
9
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
10
+import org.openzen.zenscript.codemodel.statement.Statement;
11
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
12
+import org.openzen.zenscript.codemodel.type.ITypeID;
13
+import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
14
+import org.openzen.zenscript.codemodel.type.member.TypeMembers;
15
+import org.openzen.zenscript.shared.CodePosition;
16
+import org.openzen.zenscript.shared.Taggable;
17
+
18
+/**
19
+ *
20
+ * @author Hoofdgebruiker
21
+ */
22
+public class StaticInitializerMember extends Taggable implements IDefinitionMember {
23
+	private final CodePosition position;
24
+	public Statement body;
25
+	
26
+	public StaticInitializerMember(CodePosition position) {
27
+		this.position = position;
28
+	}
29
+	
30
+	@Override
31
+	public CodePosition getPosition() {
32
+		return position;
33
+	}
34
+
35
+	@Override
36
+	public String describe() {
37
+		return "static initializer";
38
+	}
39
+
40
+	@Override
41
+	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
42
+		
43
+	}
44
+
45
+	@Override
46
+	public IDefinitionMember instance(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> mapping) {
47
+		return this;
48
+	}
49
+
50
+	@Override
51
+	public <T> T accept(MemberVisitor<T> visitor) {
52
+		return visitor.visitStaticInitializer(this);
53
+	}
54
+}

+ 68
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/StringCharIterator.java Переглянути файл

@@ -0,0 +1,68 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.codemodel.member.builtin;
7
+
8
+import java.util.Map;
9
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
10
+import org.openzen.zenscript.codemodel.iterator.ForeachIteratorVisitor;
11
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
12
+import org.openzen.zenscript.codemodel.member.IIteratorMember;
13
+import org.openzen.zenscript.codemodel.member.MemberVisitor;
14
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
15
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
16
+import org.openzen.zenscript.codemodel.type.ITypeID;
17
+import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
18
+import org.openzen.zenscript.codemodel.type.member.TypeMembers;
19
+import org.openzen.zenscript.shared.CodePosition;
20
+import org.openzen.zenscript.shared.Taggable;
21
+
22
+/**
23
+ *
24
+ * @author Hoofdgebruiker
25
+ */
26
+public class StringCharIterator extends Taggable implements IIteratorMember {
27
+	private static final ITypeID[] TYPES = new ITypeID[] { BasicTypeID.CHAR };
28
+
29
+	@Override
30
+	public int getLoopVariableCount() {
31
+		return 1;
32
+	}
33
+
34
+	@Override
35
+	public ITypeID[] getLoopVariableTypes() {
36
+		return TYPES;
37
+	}
38
+
39
+	@Override
40
+	public <T> T acceptForIterator(ForeachIteratorVisitor<T> visitor) {
41
+		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
42
+	}
43
+
44
+	@Override
45
+	public CodePosition getPosition() {
46
+		return CodePosition.BUILTIN;
47
+	}
48
+
49
+	@Override
50
+	public String describe() {
51
+		return "string character iterator";
52
+	}
53
+
54
+	@Override
55
+	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
56
+		type.addIterator(this, priority);
57
+	}
58
+
59
+	@Override
60
+	public IDefinitionMember instance(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> mapping) {
61
+		return this;
62
+	}
63
+
64
+	@Override
65
+	public <T> T accept(MemberVisitor<T> visitor) {
66
+		throw new UnsupportedOperationException("Not a compilable member");
67
+	}
68
+}

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialStaticMemberGroupExpression.java Переглянути файл

@@ -24,7 +24,7 @@ import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
24 24
  */
25 25
 public class PartialStaticMemberGroupExpression implements IPartialExpression {
26 26
 	public static PartialStaticMemberGroupExpression forMethod(CodePosition position, ITypeID target, ICallableMember method) {
27
-		DefinitionMemberGroup group = new DefinitionMemberGroup();
27
+		DefinitionMemberGroup group = new DefinitionMemberGroup(true);
28 28
 		group.addMethod(method, TypeMemberPriority.SPECIFIED);
29 29
 		return new PartialStaticMemberGroupExpression(position, target, group);
30 30
 	}

+ 2
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/StatementVisitor.java Переглянути файл

@@ -30,6 +30,8 @@ public interface StatementVisitor<T> {
30 30
 	
31 31
 	public T visitReturn(ReturnStatement statement);
32 32
 	
33
+	public T visitSwitch(SwitchStatement statement);
34
+	
33 35
 	public T visitThrow(ThrowStatement statement);
34 36
 	
35 37
 	public T visitTryCatch(TryCatchStatement statement);

+ 23
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/SwitchCase.java Переглянути файл

@@ -0,0 +1,23 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.codemodel.statement;
7
+
8
+import java.util.List;
9
+import org.openzen.zenscript.codemodel.expression.Expression;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class SwitchCase {
16
+	public final Expression value;
17
+	public final List<Statement> statements;
18
+	
19
+	public SwitchCase(Expression value, List<Statement> statements) {
20
+		this.value = value;
21
+		this.statements = statements;
22
+	}
23
+}

+ 31
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/SwitchStatement.java Переглянути файл

@@ -0,0 +1,31 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.codemodel.statement;
7
+
8
+import java.util.ArrayList;
9
+import java.util.List;
10
+import org.openzen.zenscript.codemodel.expression.Expression;
11
+import org.openzen.zenscript.shared.CodePosition;
12
+
13
+/**
14
+ *
15
+ * @author Hoofdgebruiker
16
+ */
17
+public class SwitchStatement extends LoopStatement {
18
+	public final Expression value;
19
+	public final List<SwitchCase> cases = new ArrayList<>();
20
+	
21
+	public SwitchStatement(CodePosition position, String label, Expression value) {
22
+		super(position, label);
23
+		
24
+		this.value = value;
25
+	}
26
+
27
+	@Override
28
+	public <T> T accept(StatementVisitor<T> visitor) {
29
+		return visitor.visitSwitch(this);
30
+	}
31
+}

+ 3
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ArrayTypeID.java Переглянути файл

@@ -13,6 +13,9 @@ import org.openzen.zenscript.codemodel.generic.TypeParameter;
13 13
  * @author Hoofdgebruiker
14 14
  */
15 15
 public class ArrayTypeID implements ITypeID {
16
+	public static final ArrayTypeID INT = new ArrayTypeID(BasicTypeID.INT, 1);
17
+	public static final ArrayTypeID CHAR = new ArrayTypeID(BasicTypeID.CHAR, 1);
18
+	
16 19
 	public final ITypeID elementType;
17 20
 	public final int dimension;
18 21
 

+ 98
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericMapTypeID.java Переглянути файл

@@ -0,0 +1,98 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.codemodel.type;
7
+
8
+import java.util.Arrays;
9
+import java.util.Map;
10
+import java.util.Objects;
11
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
+
13
+/**
14
+ *
15
+ * @author Hoofdgebruiker
16
+ */
17
+public class GenericMapTypeID implements ITypeID {
18
+	public final ITypeID value;
19
+	public final TypeParameter[] keys;
20
+	
21
+	public GenericMapTypeID(ITypeID value, TypeParameter[] keys) {
22
+		this.value = value;
23
+		this.keys = keys;
24
+	}
25
+
26
+	@Override
27
+	public ITypeID getUnmodified() {
28
+		return this;
29
+	}
30
+
31
+	@Override
32
+	public <T> T accept(ITypeVisitor<T> visitor) {
33
+		return visitor.visitGenericMap(this);
34
+	}
35
+
36
+	@Override
37
+	public boolean isOptional() {
38
+		return false;
39
+	}
40
+
41
+	@Override
42
+	public boolean isConst() {
43
+		return false;
44
+	}
45
+
46
+	@Override
47
+	public ITypeID withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments) {
48
+		return registry.getGenericMap(value.withGenericArguments(registry, arguments), keys);
49
+	}
50
+
51
+	@Override
52
+	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
53
+		return value.hasInferenceBlockingTypeParameters(parameters);
54
+	}
55
+	
56
+	@Override
57
+	public String toString() {
58
+		StringBuilder result = new StringBuilder();
59
+		result.append(value.toString());
60
+		result.append("[<");
61
+		for (int i = 0; i < keys.length; i++) {
62
+			if (i > 0)
63
+				result.append(", ");
64
+			result.append(keys[i].toString());
65
+		}
66
+		result.append(">]");
67
+		return result.toString();
68
+	}
69
+
70
+	@Override
71
+	public int hashCode() {
72
+		int hash = 5;
73
+		hash = 97 * hash + Objects.hashCode(this.value);
74
+		hash = 97 * hash + Arrays.deepHashCode(this.keys);
75
+		return hash;
76
+	}
77
+
78
+	@Override
79
+	public boolean equals(Object obj) {
80
+		if (this == obj) {
81
+			return true;
82
+		}
83
+		if (obj == null) {
84
+			return false;
85
+		}
86
+		if (getClass() != obj.getClass()) {
87
+			return false;
88
+		}
89
+		final GenericMapTypeID other = (GenericMapTypeID) obj;
90
+		if (!Objects.equals(this.value, other.value)) {
91
+			return false;
92
+		}
93
+		if (!Arrays.deepEquals(this.keys, other.keys)) {
94
+			return false;
95
+		}
96
+		return true;
97
+	}
98
+}

+ 18
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GlobalTypeRegistry.java Переглянути файл

@@ -24,6 +24,7 @@ import static org.openzen.zenscript.codemodel.type.member.TypeMembers.MODIFIER_W
24 24
 public class GlobalTypeRegistry {
25 25
 	private final Map<ArrayTypeID, ArrayTypeID> arrayTypes = new HashMap<>();
26 26
 	private final Map<AssocTypeID, AssocTypeID> assocTypes = new HashMap<>();
27
+	private final Map<GenericMapTypeID, GenericMapTypeID> genericMapTypes = new HashMap<>();
27 28
 	private final Map<IteratorTypeID, IteratorTypeID> iteratorTypes = new HashMap<>();
28 29
 	private final Map<FunctionTypeID, FunctionTypeID> functionTypes = new HashMap<>();
29 30
 	private final Map<RangeTypeID, RangeTypeID> rangeTypes = new HashMap<>();
@@ -33,6 +34,13 @@ public class GlobalTypeRegistry {
33 34
 	private final Map<ITypeID, ConstTypeID> constTypes = new HashMap<>();
34 35
 	private final Map<ITypeID, OptionalTypeID> optionalTypes = new HashMap<>();
35 36
 	
37
+	public GlobalTypeRegistry() {
38
+		arrayTypes.put(ArrayTypeID.INT, ArrayTypeID.INT);
39
+		arrayTypes.put(ArrayTypeID.CHAR, ArrayTypeID.CHAR);
40
+		
41
+		rangeTypes.put(RangeTypeID.INT, RangeTypeID.INT);
42
+	}
43
+	
36 44
 	public ArrayTypeID getArray(ITypeID baseType, int dimension) {
37 45
 		ArrayTypeID id = new ArrayTypeID(baseType, dimension);
38 46
 		if (arrayTypes.containsKey(id)) {
@@ -53,6 +61,16 @@ public class GlobalTypeRegistry {
53 61
 		}
54 62
 	}
55 63
 	
64
+	public GenericMapTypeID getGenericMap(ITypeID valueType, TypeParameter[] keys) {
65
+		GenericMapTypeID id = new GenericMapTypeID(valueType, keys);
66
+		if (genericMapTypes.containsKey(id)) {
67
+			return genericMapTypes.get(id);
68
+		} else {
69
+			genericMapTypes.put(id, id);
70
+			return id;
71
+		}
72
+	}
73
+	
56 74
 	public IteratorTypeID getIterator(ITypeID[] loopTypes) {
57 75
 		IteratorTypeID id = new IteratorTypeID(loopTypes);
58 76
 		if (iteratorTypes.containsKey(id)) {

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ITypeID.java Переглянути файл

@@ -185,5 +185,10 @@ public interface ITypeID {
185 185
 			
186 186
 			return pattern.accept(new MatchingTypeVisitor(type, mapping));
187 187
 		}
188
+
189
+		@Override
190
+		public Boolean visitGenericMap(GenericMapTypeID map) {
191
+			return map == type; // TODO: improve this
192
+		}
188 193
 	}
189 194
 }

+ 2
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ITypeVisitor.java Переглянути файл

@@ -16,6 +16,8 @@ public interface ITypeVisitor<T> {
16 16
 	
17 17
 	public T visitAssoc(AssocTypeID assoc);
18 18
 	
19
+	public T visitGenericMap(GenericMapTypeID map);
20
+	
19 21
 	public T visitIterator(IteratorTypeID iterator);
20 22
 	
21 23
 	public T visitFunction(FunctionTypeID function);

+ 2
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/RangeTypeID.java Переглянути файл

@@ -13,6 +13,8 @@ import org.openzen.zenscript.codemodel.generic.TypeParameter;
13 13
  * @author Hoofdgebruiker
14 14
  */
15 15
 public class RangeTypeID implements ITypeID {
16
+	public static final RangeTypeID INT = new RangeTypeID(BasicTypeID.INT, BasicTypeID.INT);
17
+	
16 18
 	public final ITypeID from;
17 19
 	public final ITypeID to;
18 20
 	

+ 0
- 22
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeExpansionRegistry.java Переглянути файл

@@ -1,22 +0,0 @@
1
-/*
2
- * To change this license header, choose License Headers in Project Properties.
3
- * To change this template file, choose Tools | Templates
4
- * and open the template in the editor.
5
- */
6
-package org.openzen.zenscript.codemodel.type;
7
-
8
-import java.util.ArrayList;
9
-import java.util.List;
10
-import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
11
-
12
-/**
13
- *
14
- * @author Hoofdgebruiker
15
- */
16
-public class TypeExpansionRegistry {
17
-	private final List<ExpansionDefinition> expansions = new ArrayList<>();
18
-	
19
-	public void register(ExpansionDefinition expansion) {
20
-		expansions.add(expansion);
21
-	}
22
-}

+ 107
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/BuiltinTypeMembers.java Переглянути файл

@@ -13,12 +13,16 @@ import org.openzen.zenscript.codemodel.definition.ClassDefinition;
13 13
 import org.openzen.zenscript.codemodel.expression.ConstantIntExpression;
14 14
 import org.openzen.zenscript.codemodel.expression.ConstantLongExpression;
15 15
 import org.openzen.zenscript.codemodel.member.CasterMember;
16
+import org.openzen.zenscript.codemodel.member.ConstructorMember;
16 17
 import org.openzen.zenscript.codemodel.member.GetterMember;
17 18
 import org.openzen.zenscript.codemodel.member.MethodMember;
18 19
 import org.openzen.zenscript.codemodel.member.OperatorMember;
19 20
 import org.openzen.zenscript.codemodel.member.builtin.ConstantGetterMember;
21
+import org.openzen.zenscript.codemodel.type.ArrayTypeID;
22
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
20 23
 import static org.openzen.zenscript.codemodel.type.BasicTypeID.*;
21 24
 import org.openzen.zenscript.codemodel.type.ITypeID;
25
+import org.openzen.zenscript.codemodel.type.RangeTypeID;
22 26
 import org.openzen.zenscript.shared.CodePosition;
23 27
 import static org.openzen.zenscript.shared.CodePosition.BUILTIN;
24 28
 
@@ -67,6 +71,24 @@ public class BuiltinTypeMembers {
67 71
 	public static final OperatorMember FLOAT_NEG = neg(T_FLOAT, FLOAT);
68 72
 	public static final OperatorMember DOUBLE_NEG = neg(T_DOUBLE, DOUBLE);
69 73
 	
74
+	public static final OperatorMember BYTE_INC = inc(T_BYTE, BYTE);
75
+	public static final OperatorMember SBYTE_INC = inc(T_SBYTE, SBYTE);
76
+	public static final OperatorMember SHORT_INC = inc(T_SHORT, SHORT);
77
+	public static final OperatorMember USHORT_INC = inc(T_USHORT, USHORT);
78
+	public static final OperatorMember INT_INC = inc(T_INT, INT);
79
+	public static final OperatorMember UINT_INC = inc(T_UINT, UINT);
80
+	public static final OperatorMember LONG_INC = inc(T_LONG, LONG);
81
+	public static final OperatorMember ULONG_INC = inc(T_ULONG, ULONG);
82
+	
83
+	public static final OperatorMember BYTE_DEC = dec(T_BYTE, BYTE);
84
+	public static final OperatorMember SBYTE_DEC = dec(T_SBYTE, SBYTE);
85
+	public static final OperatorMember SHORT_DEC = dec(T_SHORT, SHORT);
86
+	public static final OperatorMember USHORT_DEC = dec(T_USHORT, USHORT);
87
+	public static final OperatorMember INT_DEC = dec(T_INT, INT);
88
+	public static final OperatorMember UINT_DEC = dec(T_UINT, UINT);
89
+	public static final OperatorMember LONG_DEC = dec(T_LONG, LONG);
90
+	public static final OperatorMember ULONG_DEC = dec(T_ULONG, ULONG);
91
+	
70 92
 	public static final OperatorMember BYTE_ADD_BYTE = add(T_BYTE, BYTE, BYTE);
71 93
 	public static final OperatorMember SBYTE_ADD_SBYTE = add(T_SBYTE, SBYTE, SBYTE);
72 94
 	public static final OperatorMember SHORT_ADD_SHORT = add(T_SHORT, SHORT, SHORT);
@@ -121,6 +143,47 @@ public class BuiltinTypeMembers {
121 143
 	public static final OperatorMember LONG_MOD_LONG = mod(T_LONG, LONG, LONG);
122 144
 	public static final OperatorMember ULONG_MOD_ULONG = mod(T_ULONG, ULONG, ULONG);
123 145
 	
146
+	public static final OperatorMember BYTE_OR_BYTE = or(T_BYTE, BYTE, BYTE);
147
+	public static final OperatorMember SBYTE_OR_SBYTE = or(T_SBYTE, SBYTE, SBYTE);
148
+	public static final OperatorMember SHORT_OR_SHORT = or(T_SHORT, SHORT, SHORT);
149
+	public static final OperatorMember USHORT_OR_USHORT = or(T_USHORT, USHORT, USHORT);
150
+	public static final OperatorMember INT_OR_INT = or(T_INT, INT, INT);
151
+	public static final OperatorMember UINT_OR_UINT = or(T_UINT, UINT, UINT);
152
+	public static final OperatorMember LONG_OR_LONG = or(T_LONG, LONG, LONG);
153
+	public static final OperatorMember ULONG_OR_ULONG = or(T_ULONG, ULONG, ULONG);
154
+	
155
+	public static final OperatorMember BYTE_AND_BYTE = and(T_BYTE, BYTE, BYTE);
156
+	public static final OperatorMember SBYTE_AND_SBYTE = and(T_SBYTE, SBYTE, SBYTE);
157
+	public static final OperatorMember SHORT_AND_SHORT = and(T_SHORT, SHORT, SHORT);
158
+	public static final OperatorMember USHORT_AND_USHORT = and(T_USHORT, USHORT, USHORT);
159
+	public static final OperatorMember INT_AND_INT = and(T_INT, INT, INT);
160
+	public static final OperatorMember UINT_AND_UINT = and(T_UINT, UINT, UINT);
161
+	public static final OperatorMember LONG_AND_LONG = and(T_LONG, LONG, LONG);
162
+	public static final OperatorMember ULONG_AND_ULONG = and(T_ULONG, ULONG, ULONG);
163
+	
164
+	public static final OperatorMember BYTE_XOR_BYTE = xor(T_BYTE, BYTE, BYTE);
165
+	public static final OperatorMember SBYTE_XOR_SBYTE = xor(T_SBYTE, SBYTE, SBYTE);
166
+	public static final OperatorMember SHORT_XOR_SHORT = xor(T_SHORT, SHORT, SHORT);
167
+	public static final OperatorMember USHORT_XOR_USHORT = xor(T_USHORT, USHORT, USHORT);
168
+	public static final OperatorMember INT_XOR_INT = xor(T_INT, INT, INT);
169
+	public static final OperatorMember UINT_XOR_UINT = xor(T_UINT, UINT, UINT);
170
+	public static final OperatorMember LONG_XOR_LONG = xor(T_LONG, LONG, LONG);
171
+	public static final OperatorMember ULONG_XOR_ULONG = xor(T_ULONG, ULONG, ULONG);
172
+	
173
+	public static final OperatorMember INT_SHL = shl(T_INT, UINT, INT);
174
+	public static final OperatorMember INT_SHR = shr(T_INT, UINT, INT);
175
+	public static final OperatorMember INT_USHR = ushr(T_INT, UINT, INT);
176
+	
177
+	public static final OperatorMember UINT_SHL = shl(T_UINT, UINT, UINT);
178
+	public static final OperatorMember UINT_SHR = shr(T_UINT, UINT, UINT);
179
+	
180
+	public static final OperatorMember LONG_SHL = shl(T_LONG, UINT, LONG);
181
+	public static final OperatorMember LONG_SHR = shr(T_LONG, UINT, LONG);
182
+	public static final OperatorMember LONG_USHR = ushr(T_LONG, UINT, LONG);
183
+	
184
+	public static final OperatorMember ULONG_SHL = shl(T_ULONG, UINT, ULONG);
185
+	public static final OperatorMember ULONG_SHR = shr(T_ULONG, UINT, ULONG);
186
+	
124 187
 	public static final CasterMember INT_TO_BYTE = castExplicit(T_BYTE, BYTE);
125 188
 	public static final CasterMember INT_TO_SBYTE = castExplicit(T_SBYTE, SBYTE);
126 189
 	public static final CasterMember INT_TO_SHORT = castExplicit(T_SHORT, SHORT);
@@ -150,6 +213,18 @@ public class BuiltinTypeMembers {
150 213
 	public static final MethodMember FLOAT_FROMBITS = new MethodMember(BUILTIN, T_FLOAT, Modifiers.STATIC, "fromBits", new FunctionHeader(FLOAT, new FunctionParameter(UINT)));
151 214
 	public static final MethodMember DOUBLE_FROMBITS = new MethodMember(BUILTIN, T_FLOAT, Modifiers.STATIC, "fromBits", new FunctionHeader(DOUBLE, new FunctionParameter(ULONG)));
152 215
 	
216
+	public static final ConstructorMember STRING_CONSTRUCTOR_CHARACTERS
217
+			= new ConstructorMember(BUILTIN, T_STRING, Modifiers.EXPORT | Modifiers.EXTERN, new FunctionHeader(VOID, new FunctionParameter(ArrayTypeID.CHAR)));
218
+	public static final ConstructorMember STRING_CONSTRUCTOR_CHARACTER_RANGE
219
+			= new ConstructorMember(BUILTIN, T_STRING, Modifiers.EXPORT | Modifiers.EXTERN, new FunctionHeader(
220
+					VOID,
221
+					new FunctionParameter(ArrayTypeID.CHAR),
222
+					new FunctionParameter(BasicTypeID.INT),
223
+					new FunctionParameter(BasicTypeID.INT)));
224
+	public static final OperatorMember STRING_INDEXGET = new OperatorMember(BUILTIN, T_STRING, Modifiers.EXPORT | Modifiers.EXTERN, OperatorType.INDEXGET, new FunctionHeader(CHAR, new FunctionParameter(INT)));
225
+	public static final OperatorMember STRING_RANGEGET = new OperatorMember(BUILTIN, T_STRING, Modifiers.EXPORT | Modifiers.EXTERN, OperatorType.INDEXGET, new FunctionHeader(STRING, new FunctionParameter(RangeTypeID.INT)));
226
+	public static final GetterMember STRING_LENGTH = new GetterMember(BUILTIN, T_STRING, Modifiers.EXPORT | Modifiers.EXTERN, "length", INT);
227
+	
153 228
 	private static OperatorMember not(ClassDefinition cls, ITypeID result) {
154 229
 		return new OperatorMember(BUILTIN, cls, 0, OperatorType.NOT, new FunctionHeader(result));
155 230
 	}
@@ -158,6 +233,14 @@ public class BuiltinTypeMembers {
158 233
 		return new OperatorMember(BUILTIN, cls, 0, OperatorType.NEG, new FunctionHeader(result));
159 234
 	}
160 235
 	
236
+	private static OperatorMember inc(ClassDefinition cls, ITypeID result) {
237
+		return new OperatorMember(BUILTIN, cls, 0, OperatorType.INCREMENT, new FunctionHeader(result));
238
+	}
239
+	
240
+	private static OperatorMember dec(ClassDefinition cls, ITypeID result) {
241
+		return new OperatorMember(BUILTIN, cls, 0, OperatorType.DECREMENT, new FunctionHeader(result));
242
+	}
243
+	
161 244
 	private static OperatorMember add(ClassDefinition cls, ITypeID operand, ITypeID result) {
162 245
 		return new OperatorMember(BUILTIN, cls, 0, OperatorType.ADD, new FunctionHeader(result, new FunctionParameter(operand)));
163 246
 	}
@@ -178,6 +261,30 @@ public class BuiltinTypeMembers {
178 261
 		return new OperatorMember(BUILTIN, cls, 0, OperatorType.MOD, new FunctionHeader(result, new FunctionParameter(operand)));
179 262
 	}
180 263
 	
264
+	private static OperatorMember shl(ClassDefinition cls, ITypeID operand, ITypeID result) {
265
+		return new OperatorMember(BUILTIN, cls, 0, OperatorType.SHL, new FunctionHeader(result, new FunctionParameter(operand)));
266
+	}
267
+	
268
+	private static OperatorMember shr(ClassDefinition cls, ITypeID operand, ITypeID result) {
269
+		return new OperatorMember(BUILTIN, cls, 0, OperatorType.SHR, new FunctionHeader(result, new FunctionParameter(operand)));
270
+	}
271
+	
272
+	private static OperatorMember ushr(ClassDefinition cls, ITypeID operand, ITypeID result) {
273
+		return new OperatorMember(BUILTIN, cls, 0, OperatorType.USHR, new FunctionHeader(result, new FunctionParameter(operand)));
274
+	}
275
+	
276
+	private static OperatorMember or(ClassDefinition cls, ITypeID operand, ITypeID result) {
277
+		return new OperatorMember(BUILTIN, cls, 0, OperatorType.OR, new FunctionHeader(result, new FunctionParameter(operand)));
278
+	}
279
+	
280
+	private static OperatorMember and(ClassDefinition cls, ITypeID operand, ITypeID result) {
281
+		return new OperatorMember(BUILTIN, cls, 0, OperatorType.AND, new FunctionHeader(result, new FunctionParameter(operand)));
282
+	}
283
+	
284
+	private static OperatorMember xor(ClassDefinition cls, ITypeID operand, ITypeID result) {
285
+		return new OperatorMember(BUILTIN, cls, 0, OperatorType.XOR, new FunctionHeader(result, new FunctionParameter(operand)));
286
+	}
287
+	
181 288
 	private static CasterMember castExplicit(ClassDefinition cls, ITypeID result) {
182 289
 		return new CasterMember(CodePosition.BUILTIN, cls, 0, result);
183 290
 	}

+ 24
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/DefinitionMemberGroup.java Переглянути файл

@@ -25,6 +25,8 @@ import org.openzen.zenscript.codemodel.member.SetterMember;
25 25
 import org.openzen.zenscript.codemodel.type.ITypeID;
26 26
 import org.openzen.zenscript.codemodel.CompareType;
27 27
 import org.openzen.zenscript.codemodel.FunctionHeader;
28
+import org.openzen.zenscript.codemodel.expression.PostCallExpression;
29
+import org.openzen.zenscript.codemodel.member.OperatorMember;
28 30
 import org.openzen.zenscript.shared.CodePosition;
29 31
 import org.openzen.zenscript.shared.CompileException;
30 32
 import org.openzen.zenscript.shared.CompileExceptionCode;
@@ -36,7 +38,7 @@ import org.openzen.zenscript.codemodel.scope.TypeScope;
36 38
  */
37 39
 public class DefinitionMemberGroup {
38 40
 	public static DefinitionMemberGroup forMethod(ICallableMember member) {
39
-		DefinitionMemberGroup instance = new DefinitionMemberGroup();
41
+		DefinitionMemberGroup instance = new DefinitionMemberGroup(member.isStatic());
40 42
 		instance.addMethod(member, TypeMemberPriority.SPECIFIED);
41 43
 		return instance;
42 44
 	}
@@ -45,6 +47,11 @@ public class DefinitionMemberGroup {
45 47
 	private TypeMember<IGettableMember> getter;
46 48
 	private TypeMember<SetterMember> setter;
47 49
 	private final List<TypeMember<ICallableMember>> methods = new ArrayList<>();
50
+	public final boolean isStatic;
51
+	
52
+	public DefinitionMemberGroup(boolean isStatic) {
53
+		this.isStatic = isStatic;
54
+	}
48 55
 	
49 56
 	public void merge(CodePosition position, DefinitionMemberGroup other, TypeMemberPriority priority) {
50 57
 		if (other.field != null)
@@ -70,6 +77,10 @@ public class DefinitionMemberGroup {
70 77
 		return this.setter == null ? null : this.setter.member;
71 78
 	}
72 79
 	
80
+	public boolean hasMethods() {
81
+		return !methods.isEmpty();
82
+	}
83
+	
73 84
 	public List<TypeMember<ICallableMember>> getMethodMembers() {
74 85
 		return this.methods;
75 86
 	}
@@ -233,6 +244,18 @@ public class DefinitionMemberGroup {
233 244
 		return method.call(position, target, instancedHeader, arguments);
234 245
 	}
235 246
 	
247
+	public Expression callPostfix(CodePosition position, TypeScope scope, Expression target) {
248
+		if (methods.isEmpty())
249
+			throw new CompileException(position, CompileExceptionCode.NO_SUCH_MEMBER, "There is no such operator");
250
+		
251
+		ICallableMember method = methods.get(0).member;
252
+		if (!(method instanceof OperatorMember)) {
253
+			throw new CompileException(position, CompileExceptionCode.NO_SUCH_MEMBER, "Member is not an operator");
254
+		}
255
+		OperatorMember operator = (OperatorMember) method;
256
+		return new PostCallExpression(position, target, operator, operator.header);
257
+	}
258
+	
236 259
 	public Expression callWithComparator(
237 260
 			CodePosition position,
238 261
 			TypeScope scope,

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/LocalMemberCache.java Переглянути файл

@@ -16,6 +16,8 @@ import org.openzen.zenscript.codemodel.generic.TypeParameter;
16 16
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
17 17
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
18 18
 import org.openzen.zenscript.codemodel.type.ITypeID;
19
+import org.openzen.zenscript.shared.CompileException;
20
+import org.openzen.zenscript.shared.CompileExceptionCode;
19 21
 
20 22
 /**
21 23
  *
@@ -55,6 +57,9 @@ public class LocalMemberCache {
55 57
 		members.type.accept(new TypeMemberBuilder(members, this));
56 58
 		
57 59
 		for (ExpansionDefinition expansion : expansions) {
60
+			if (expansion.target == null)
61
+				throw new CompileException(expansion.position, CompileExceptionCode.INTERNAL_ERROR, "Missing expansion target");
62
+			
58 63
 			Map<TypeParameter, ITypeID> mapping = matchType(members.type, expansion.target);
59 64
 			if (mapping != null) {
60 65
 				if (mapping.isEmpty()) {

+ 58
- 45
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java Переглянути файл

@@ -38,6 +38,7 @@ import org.openzen.zenscript.codemodel.member.builtin.ArrayIteratorValues;
38 38
 import org.openzen.zenscript.codemodel.member.builtin.ComparatorMember;
39 39
 import org.openzen.zenscript.codemodel.member.builtin.ConstantGetterMember;
40 40
 import org.openzen.zenscript.codemodel.member.builtin.RangeIterator;
41
+import org.openzen.zenscript.codemodel.member.builtin.StringCharIterator;
41 42
 import org.openzen.zenscript.codemodel.type.ArrayTypeID;
42 43
 import org.openzen.zenscript.codemodel.type.AssocTypeID;
43 44
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
@@ -45,6 +46,7 @@ import static org.openzen.zenscript.codemodel.type.BasicTypeID.*;
45 46
 import org.openzen.zenscript.codemodel.type.ConstTypeID;
46 47
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
47 48
 import org.openzen.zenscript.codemodel.type.FunctionTypeID;
49
+import org.openzen.zenscript.codemodel.type.GenericMapTypeID;
48 50
 import org.openzen.zenscript.codemodel.type.GenericTypeID;
49 51
 import org.openzen.zenscript.codemodel.type.ITypeID;
50 52
 import org.openzen.zenscript.codemodel.type.ITypeVisitor;
@@ -107,7 +109,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
107 109
 
108 110
 		FunctionParameter[] indexGetParameters = new FunctionParameter[dimension];
109 111
 		for (int i = 0; i < dimension; i++)
110
-			indexGetParameters[i] = new FunctionParameter(INT, null);
112
+			indexGetParameters[i] = new FunctionParameter(INT);
111 113
 
112 114
 		FunctionHeader indexGetHeader = new FunctionHeader(baseType, indexGetParameters);
113 115
 		members.addOperator(new OperatorMember(BUILTIN, definition, 0, OperatorType.INDEXGET, indexGetHeader), TypeMemberPriority.SPECIFIED);
@@ -121,6 +123,13 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
121 123
 		FunctionHeader sizedConstructorHeader = new FunctionHeader(VOID, indexGetParameters);
122 124
 		members.addConstructor(new ConstructorMember(BUILTIN, definition, 0, sizedConstructorHeader), TypeMemberPriority.SPECIFIED);
123 125
 
126
+		FunctionParameter[] initialValueConstructorParameters = new FunctionParameter[dimension + 1];
127
+		for (int i = 0; i < dimension; i++)
128
+			initialValueConstructorParameters[i] = new FunctionParameter(INT);
129
+		initialValueConstructorParameters[dimension] = new FunctionParameter(baseType);
130
+		FunctionHeader initialValueConstructorHeader = new FunctionHeader(VOID, initialValueConstructorParameters);
131
+		members.addConstructor(new ConstructorMember(BUILTIN, definition, 0, initialValueConstructorHeader));
132
+		
124 133
 		FunctionParameter[] lambdaConstructorParameters = new FunctionParameter[dimension + 1];
125 134
 		for (int i = 0; i < dimension; i++)
126 135
 			lambdaConstructorParameters[i] = new FunctionParameter(INT, null);
@@ -161,22 +170,34 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
161 170
 		
162 171
 		ClassDefinition definition = new ClassDefinition(BUILTIN, null, "", Modifiers.EXPORT);
163 172
 		
164
-		members.addConstructor(new ConstructorMember(BUILTIN, definition, 0, new FunctionHeader(VOID)), TypeMemberPriority.SPECIFIED);
173
+		members.addConstructor(new ConstructorMember(BUILTIN, definition, 0, new FunctionHeader(VOID)));
165 174
 
166 175
 		FunctionHeader indexGetHeader = new FunctionHeader(valueType, new FunctionParameter(keyType, "key"));
167
-		members.addOperator(new OperatorMember(BUILTIN, definition, 0, OperatorType.INDEXGET, indexGetHeader), TypeMemberPriority.SPECIFIED);
176
+		members.addOperator(new OperatorMember(BUILTIN, definition, 0, OperatorType.INDEXGET, indexGetHeader));
168 177
 
169 178
 		FunctionHeader indexSetHeader = new FunctionHeader(VOID, new FunctionParameter(keyType, "key"), new FunctionParameter(valueType, "value"));
170
-		members.addOperator(new OperatorMember(BUILTIN, definition, 0, OperatorType.INDEXSET, indexSetHeader), TypeMemberPriority.SPECIFIED);
179
+		members.addOperator(new OperatorMember(BUILTIN, definition, 0, OperatorType.INDEXSET, indexSetHeader));
171 180
 		
172 181
 		FunctionHeader getOrDefaultHeader = new FunctionHeader(valueType, new FunctionParameter(keyType, "key"), new FunctionParameter(valueType, "defaultValue"));
173
-		members.addMethod(new MethodMember(BUILTIN, definition, 0, "getOrDefault", getOrDefaultHeader), TypeMemberPriority.SPECIFIED);
182
+		members.addMethod(new MethodMember(BUILTIN, definition, 0, "getOrDefault", getOrDefaultHeader));
174 183
 		
175
-		members.addOperator(new OperatorMember(BUILTIN, definition, 0, OperatorType.CONTAINS, new FunctionHeader(BOOL, new FunctionParameter(keyType, "key"))), TypeMemberPriority.SPECIFIED);
184
+		members.addOperator(new OperatorMember(BUILTIN, definition, 0, OperatorType.CONTAINS, new FunctionHeader(BOOL, new FunctionParameter(keyType, "key"))));
176 185
 
177
-		members.addField(new FieldMember(BUILTIN, definition, Modifiers.FINAL, "length", INT), TypeMemberPriority.SPECIFIED);
178
-		members.addGetter(new GetterMember(BUILTIN, definition, 0, "empty", BOOL), TypeMemberPriority.SPECIFIED);
179
-		members.addGetter(new GetterMember(BUILTIN, definition, 0, "keys", cache.getRegistry().getArray(keyType, 1)), TypeMemberPriority.SPECIFIED);
186
+		members.addField(new FieldMember(BUILTIN, definition, Modifiers.FINAL, "size", INT));
187
+		members.addGetter(new GetterMember(BUILTIN, definition, 0, "empty", BOOL));
188
+		members.addGetter(new GetterMember(BUILTIN, definition, 0, "keys", cache.getRegistry().getArray(keyType, 1)));
189
+		return null;
190
+	}
191
+	
192
+	@Override
193
+	public Void visitGenericMap(GenericMapTypeID map) {
194
+		ITypeID valueType = map.value;
195
+		
196
+		ClassDefinition definition = new ClassDefinition(BUILTIN, null, "", Modifiers.EXPORT);
197
+		members.addConstructor(new ConstructorMember(BUILTIN, definition, 0, new FunctionHeader(VOID)));
198
+		members.addMethod(new MethodMember(BUILTIN, definition, 0, "getOptional", new FunctionHeader(map.keys, valueType, new FunctionParameter[0])));
199
+		members.addMethod(new MethodMember(BUILTIN, definition, 0, "put", new FunctionHeader(map.keys, BasicTypeID.VOID, new FunctionParameter(valueType))));
200
+		members.addMethod(new MethodMember(BUILTIN, definition, 0, "contains", new FunctionHeader(map.keys, BasicTypeID.BOOL, new FunctionParameter[0])));
180 201
 		return null;
181 202
 	}
182 203
 	
@@ -238,6 +259,10 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
238 259
 		if (definition instanceof EnumDefinition) {
239 260
 			members.addGetter(new GetterMember(BUILTIN, definition, 0, "name", BasicTypeID.STRING), TypeMemberPriority.SPECIFIED);
240 261
 			members.addGetter(new GetterMember(BUILTIN, definition, 0, "ordinal", BasicTypeID.INT), TypeMemberPriority.SPECIFIED);
262
+			
263
+			if (!members.canCast(BasicTypeID.STRING)) {
264
+				members.addCaster(new CasterMember(BUILTIN, definition, Modifiers.PUBLIC | Modifiers.EXTERN | Modifiers.IMPLICIT, BasicTypeID.STRING));
265
+			}
241 266
 		}
242 267
 		
243 268
 		return null;
@@ -287,10 +312,8 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
287 312
 		members.addOperator(INT_NEG);
288 313
 		members.addOperator(INT_NOT);
289 314
 		
290
-		/*members.addOperator(new OperatorMember(BUILTIN, 0, OperatorType.PRE_INCREMENT, unaryHeader), TypeMemberPriority.SPECIFIED);
291
-		members.addOperator(new OperatorMember(BUILTIN, 0, OperatorType.PRE_DECREMENT, unaryHeader), TypeMemberPriority.SPECIFIED);
292
-		members.addOperator(new OperatorMember(BUILTIN, 0, OperatorType.POST_INCREMENT, unaryHeader), TypeMemberPriority.SPECIFIED);
293
-		members.addOperator(new OperatorMember(BUILTIN, 0, OperatorType.POST_DECREMENT, unaryHeader), TypeMemberPriority.SPECIFIED);*/
315
+		members.addOperator(INT_INC);
316
+		members.addOperator(INT_DEC);
294 317
 
295 318
 		members.addOperator(OperatorType.COMPARE, new ComparatorMember(members.type), TypeMemberPriority.SPECIFIED);
296 319
 		
@@ -317,6 +340,14 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
317 340
 		members.addOperator(INT_MOD_INT);
318 341
 		members.addOperator(mod(T_INT, LONG, LONG, castedTargetCall(LONG_MOD_LONG, INT_TO_LONG)));
319 342
 		
343
+		members.addOperator(INT_OR_INT);
344
+		members.addOperator(INT_AND_INT);
345
+		members.addOperator(INT_XOR_INT);
346
+		
347
+		members.addOperator(INT_SHL);
348
+		members.addOperator(INT_SHR);
349
+		members.addOperator(INT_USHR);
350
+		
320 351
 		members.addGetter(INT_GET_MIN_VALUE);
321 352
 		members.addGetter(INT_GET_MAX_VALUE);
322 353
 		
@@ -334,7 +365,11 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
334 365
 	}
335 366
 
336 367
 	private void visitUInt() {
337
-		registerUnaryOperations(T_UINT);
368
+		members.addOperator(UINT_NOT);
369
+		
370
+		members.addOperator(UINT_INC);
371
+		members.addOperator(UINT_DEC);
372
+		
338 373
 		registerArithmeticOperations(T_UINT, UINT, UINT);
339 374
 		registerArithmeticOperations(T_UINT, ULONG, ULONG);
340 375
 		registerArithmeticOperations(T_UINT, FLOAT, FLOAT);
@@ -412,45 +447,23 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
412 447
 	}
413 448
 
414 449
 	private void visitString() {
415
-		FunctionHeader getIndexHeader = new FunctionHeader(CHAR, new FunctionParameter(INT));
416
-		members.addOperator(new OperatorMember(BUILTIN, T_STRING, 0, OperatorType.INDEXGET, getIndexHeader), TypeMemberPriority.SPECIFIED);
450
+		members.addOperator(STRING_INDEXGET);
451
+		members.addOperator(STRING_RANGEGET);
452
+		members.addGetter(STRING_LENGTH);
417 453
 
418
-		members.addGetter(new GetterMember(BUILTIN, T_STRING, 0, "length", INT), TypeMemberPriority.SPECIFIED);
419
-
420
-		//FunctionHeader substringHeader = new FunctionHeader(STRING, new FunctionParameter(cache.getRegistry().getRange(INT, INT)));
421
-		//members.addOperator(OperatorType.INDEXGET, new SubstringMember(substringHeader), TypeMemberPriority.SPECIFIED);
422
-		
423
-		members.addConstructor(new ConstructorMember(BUILTIN, T_STRING, 0, new FunctionHeader(VOID, new FunctionParameter(cache.getRegistry().getArray(CHAR, 1), "characters"))), TypeMemberPriority.SPECIFIED);
454
+		members.addConstructor(STRING_CONSTRUCTOR_CHARACTERS);
455
+		members.addConstructor(STRING_CONSTRUCTOR_CHARACTER_RANGE);
424 456
 		
425 457
 		members.addOperator(STRING_ADD_STRING);
426
-
427
-		/*registerStringConcat(NULL);
428
-		registerStringConcat(BOOL);
429
-		registerStringConcat(SBYTE);
430
-		registerStringConcat(BYTE);
431
-		registerStringConcat(SHORT);
432
-		registerStringConcat(USHORT);
433
-		registerStringConcat(INT);
434
-		registerStringConcat(UINT);
435
-		registerStringConcat(LONG);
436
-		registerStringConcat(ULONG);
437
-		registerStringConcat(FLOAT);
438
-		registerStringConcat(DOUBLE);
439
-		registerStringConcat(CHAR);
440
-		registerStringConcat(STRING);*/
441
-	}
442
-
443
-	private void registerStringConcat(ITypeID withType) {
444
-		members.addOperator(STRING_ADD_STRING);
458
+		
459
+		members.addIterator(new StringCharIterator(), TypeMemberPriority.SPECIFIED);
445 460
 	}
446 461
 
447 462
 	private void registerUnaryOperations(ClassDefinition definition) {
448 463
 		FunctionHeader unaryHeader = new FunctionHeader(members.type);
449 464
 		members.addOperator(new OperatorMember(BUILTIN, definition, 0, OperatorType.NEG, unaryHeader), TypeMemberPriority.SPECIFIED);
450
-		members.addOperator(new OperatorMember(BUILTIN, definition, 0, OperatorType.PRE_INCREMENT, unaryHeader), TypeMemberPriority.SPECIFIED);
451
-		members.addOperator(new OperatorMember(BUILTIN, definition, 0, OperatorType.PRE_DECREMENT, unaryHeader), TypeMemberPriority.SPECIFIED);
452
-		members.addOperator(new OperatorMember(BUILTIN, definition, 0, OperatorType.POST_INCREMENT, unaryHeader), TypeMemberPriority.SPECIFIED);
453
-		members.addOperator(new OperatorMember(BUILTIN, definition, 0, OperatorType.POST_DECREMENT, unaryHeader), TypeMemberPriority.SPECIFIED);
465
+		members.addOperator(new OperatorMember(BUILTIN, definition, 0, OperatorType.INCREMENT, unaryHeader), TypeMemberPriority.SPECIFIED);
466
+		members.addOperator(new OperatorMember(BUILTIN, definition, 0, OperatorType.DECREMENT, unaryHeader), TypeMemberPriority.SPECIFIED);
454 467
 
455 468
 		members.addOperator(OperatorType.COMPARE, new ComparatorMember(members.type), TypeMemberPriority.SPECIFIED);
456 469
 	}

+ 36
- 10
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMembers.java Переглянути файл

@@ -88,7 +88,7 @@ public final class TypeMembers {
88 88
 		for (Map.Entry<String, EnumConstantMember> entry : enumMembers.entrySet())
89 89
 			other.addEnumMember(entry.getValue(), priority);
90 90
 		for (Map.Entry<String, DefinitionMemberGroup> entry : members.entrySet())
91
-			other.getOrCreateGroup(entry.getKey()).merge(position, entry.getValue(), priority);
91
+			other.getOrCreateGroup(entry.getKey(), entry.getValue().isStatic).merge(position, entry.getValue(), priority);
92 92
 		for (Map.Entry<String, InnerDefinition> entry : innerTypes.entrySet())
93 93
 			other.innerTypes.put(entry.getKey(), entry.getValue());
94 94
 		for (Map.Entry<OperatorType, DefinitionMemberGroup> entry : operators.entrySet())
@@ -111,6 +111,10 @@ public final class TypeMembers {
111 111
 		getOrCreateGroup(OperatorType.CONSTRUCTOR).addMethod(constructor, priority);
112 112
 	}
113 113
 	
114
+	public void addConstructor(ConstructorMember constructor) {
115
+		getOrCreateGroup(OperatorType.CONSTRUCTOR).addMethod(constructor, TypeMemberPriority.SPECIFIED);
116
+	}
117
+	
114 118
 	public void addCaller(CallerMember caller, TypeMemberPriority priority) {
115 119
 		getOrCreateGroup(OperatorType.CALL).addMethod(caller, priority);
116 120
 	}
@@ -135,7 +139,7 @@ public final class TypeMembers {
135 139
 	}
136 140
 	
137 141
 	public void addField(FieldMember member, TypeMemberPriority priority) {
138
-		DefinitionMemberGroup group = getOrCreateGroup(member.name);
142
+		DefinitionMemberGroup group = getOrCreateGroup(member.name, member.isStatic());
139 143
 		group.setField(member, priority);
140 144
 	}
141 145
 	
@@ -144,7 +148,7 @@ public final class TypeMembers {
144 148
 	}
145 149
 	
146 150
 	public void addGetter(IGettableMember member, TypeMemberPriority priority) {
147
-		DefinitionMemberGroup group = getOrCreateGroup(member.getName());
151
+		DefinitionMemberGroup group = getOrCreateGroup(member.getName(), member.isStatic());
148 152
 		group.setGetter(member, priority);
149 153
 	}
150 154
 	
@@ -153,7 +157,7 @@ public final class TypeMembers {
153 157
 	}
154 158
 	
155 159
 	public void addSetter(SetterMember member, TypeMemberPriority priority) {
156
-		DefinitionMemberGroup group = getOrCreateGroup(member.name);
160
+		DefinitionMemberGroup group = getOrCreateGroup(member.name, member.isStatic());
157 161
 		group.setSetter(member, priority);
158 162
 	}
159 163
 	
@@ -162,7 +166,7 @@ public final class TypeMembers {
162 166
 	}
163 167
 	
164 168
 	public void addMethod(MethodMember member, TypeMemberPriority priority) {
165
-		DefinitionMemberGroup group = getOrCreateGroup(member.name);
169
+		DefinitionMemberGroup group = getOrCreateGroup(member.name, member.isStatic());
166 170
 		group.addMethod(member, priority);
167 171
 	}
168 172
 	
@@ -206,16 +210,16 @@ public final class TypeMembers {
206 210
 		innerTypes.put(name, type);
207 211
 	}
208 212
 	
209
-	public DefinitionMemberGroup getOrCreateGroup(String name) {
213
+	public DefinitionMemberGroup getOrCreateGroup(String name, boolean isStatic) {
210 214
 		if (!members.containsKey(name))
211
-			members.put(name, new DefinitionMemberGroup());
215
+			members.put(name, new DefinitionMemberGroup(isStatic));
212 216
 		
213 217
 		return members.get(name);
214 218
 	}
215 219
 	
216 220
 	public DefinitionMemberGroup getOrCreateGroup(OperatorType operator) {
217 221
 		if (!operators.containsKey(operator))
218
-			operators.put(operator, new DefinitionMemberGroup());
222
+			operators.put(operator, new DefinitionMemberGroup(false));
219 223
 		
220 224
 		return operators.get(operator);
221 225
 	}
@@ -307,6 +311,18 @@ public final class TypeMembers {
307 311
 		return false;
308 312
 	}
309 313
 	
314
+	public boolean canCast(ITypeID toType) {
315
+		if (canCastImplicit(toType))
316
+			return true;
317
+		
318
+		for (TypeMember<ICasterMember> caster : casters) {
319
+			if (toType == caster.member.getTargetType())
320
+				return true;
321
+		}
322
+		
323
+		return false;
324
+	}
325
+	
310 326
 	public Expression castImplicit(CodePosition position, Expression value, ITypeID toType, boolean implicit) {
311 327
 		if (toType == type || toType == BasicTypeID.UNDETERMINED)
312 328
 			return value;
@@ -350,8 +366,18 @@ public final class TypeMembers {
350 366
 	}
351 367
 	
352 368
 	public IPartialExpression getMemberExpression(CodePosition position, Expression target, GenericName name, boolean allowStatic) {
353
-		if (members.containsKey(name.name) && name.arguments.isEmpty())
354
-			return new PartialMemberGroupExpression(position, target, members.get(name.name), allowStatic);
369
+		if (members.containsKey(name.name)) {
370
+			DefinitionMemberGroup group = members.get(name.name);
371
+			
372
+			if (!name.arguments.isEmpty()) {
373
+				/* ... */
374
+			}
375
+			
376
+			if (group.isStatic)
377
+				return new PartialStaticMemberGroupExpression(position, type, group);
378
+			else
379
+				return new PartialMemberGroupExpression(position, target, group, allowStatic);
380
+		}
355 381
 		
356 382
 		return null;
357 383
 	}

+ 22
- 0
Constructor/build.gradle Переглянути файл

@@ -0,0 +1,22 @@
1
+// Note: "common.gradle" in the root project contains additional initialization
2
+//   for this project. This initialization is applied in the "build.gradle"
3
+//   of the root project.
4
+
5
+// NetBeans will automatically add "run" and "debug" tasks relying on the
6
+// "mainClass" property. You may however define the property prior executing
7
+// tasks by passing a "-PmainClass=<QUALIFIED_CLASS_NAME>" argument.
8
+//
9
+// Note however, that you may define your own "run" and "debug" task if you
10
+// prefer. In this case NetBeans will not add these tasks but you may rely on
11
+// your own implementation.
12
+if (!hasProperty('mainClass')) {
13
+    ext.mainClass = 'org.openzen.zenscript.constructor.Main'
14
+}
15
+
16
+dependencies {
17
+	compile 'org.json:json:20180130'
18
+	compile project(':CodeModel')
19
+	compile project(':Parser')
20
+	compile project(':Validator')
21
+	compile project(':JavaBytecodeCompiler')
22
+}

+ 9
- 0
Constructor/libraries/stdlib/module.json Переглянути файл

@@ -0,0 +1,9 @@
1
+{
2
+	"package": "stdlib",
3
+	"host": "universal",
4
+	"globals": {
5
+		"Exception": {"type": "Definition", "definition": "Exception"},
6
+		"IllegalArgumentException": {"type": "Definition", "definition": "IllegalArgumentException"},
7
+		"StringBuilder": {"type": "Definition", "definition": "StringBuilder"}
8
+	}
9
+}

+ 5
- 0
Constructor/libraries/stdlib/src/Chars.zs Переглянути файл

@@ -0,0 +1,5 @@
1
+export expand char {
2
+	public times(number as int) as string {
3
+		return new string(new char[](number, this));
4
+	}
5
+}

+ 4
- 0
Constructor/libraries/stdlib/src/Exception.zs Переглянути файл

@@ -0,0 +1,4 @@
1
+export virtual class Exception {
2
+	public this(message as string) {
3
+	}
4
+}

+ 5
- 0
Constructor/libraries/stdlib/src/IllegalArgumentException.zs Переглянути файл

@@ -0,0 +1,5 @@
1
+export class IllegalArgumentException : Exception {
2
+	public this(message as string) {
3
+		super(message);
4
+	}
5
+}

+ 5
- 0
Constructor/libraries/stdlib/src/Integers.zs Переглянути файл

@@ -0,0 +1,5 @@
1
+expand int {
2
+	public extern toHexString() as string;
3
+	public static extern parse(value as string) as int;
4
+	public static extern parse(value as string, radix as int) as int;
5
+}

+ 10
- 0
Constructor/libraries/stdlib/src/StringBuilder.zs Переглянути файл

@@ -0,0 +1,10 @@
1
+export class StringBuilder {
2
+	public extern this();
3
+	public extern this(capacity as int);
4
+	public extern this(value as string);
5
+	
6
+	public extern +=(value as string);
7
+	public extern +=(value as char);
8
+	
9
+	public extern implicit as string;
10
+}

+ 62
- 0
Constructor/libraries/stdlib/src/Strings.zs Переглянути файл

@@ -0,0 +1,62 @@
1
+export expand string {
2
+	public get isEmpty as bool => length == 0;
3
+	
4
+	public const indexOf(c as char) as int {
5
+		for i in 0 .. length {
6
+			if this[i] == c
7
+				return i;
8
+		}
9
+		
10
+		return -1;
11
+	}
12
+	
13
+	public const indexOf(c as char, from as int) as int {
14
+		for i in from .. length {
15
+			if this[i] == c
16
+				return i;
17
+		}
18
+		
19
+		return -1;
20
+	}
21
+	
22
+	public const lastIndexOf(c as char) as int {
23
+		var i = length;
24
+		while i > 0 {
25
+			i--;
26
+			if this[i] == c
27
+				return i;
28
+		}
29
+		
30
+		return -1;
31
+	}
32
+	
33
+	public const lastIndexOf(c as char, until as int) as int {
34
+		var i = until;
35
+		while i > 0 {
36
+			i--;
37
+			if this[i] == c
38
+				return i;
39
+		}
40
+		
41
+		return -1;
42
+	}
43
+	
44
+	public const split(delimiter as char) as string[] {
45
+		val result = [] as string[];
46
+		var start = 0;
47
+		for i in 0 .. this.length {
48
+			if this[i] == delimiter {
49
+				result.add(this[start .. i]);
50
+				start = i + 1;
51
+			}
52
+		}
53
+		result.add(this[start .. $]);
54
+		return result;
55
+	}
56
+	
57
+	public const lpad(length as int, c as char) as string
58
+		=> this.length >= length ? this : c.times(length - this.length) + this;
59
+	
60
+	public const rpad(length as int, c as char) as string
61
+		=> this.length >= length ? this : this + c.times(length - this.length);
62
+}

+ 53
- 0
Constructor/src/main/java/org/openzen/zenscript/constructor/Arguments.java Переглянути файл

@@ -0,0 +1,53 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.constructor;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public class Arguments {
13
+	public static Arguments parse(String[] args) {
14
+		String directory = ".";
15
+		boolean help = false;
16
+		String target = null;
17
+		
18
+		int position = 0;
19
+		outer: for (int i = 0; i < args.length; i++) {
20
+			switch (args[i]) {
21
+				case "-d":
22
+					i++;
23
+					directory = args[0];
24
+					continue outer;
25
+				case "-h":
26
+				case "--help":
27
+					help = true;
28
+					continue outer;
29
+				default:
30
+					if (position == 0) {
31
+						position++;
32
+						target = args[i];
33
+					}
34
+			}
35
+		}
36
+		
37
+		return new Arguments(directory, target, help);
38
+	}
39
+	
40
+	public final String directory;
41
+	public final String target;
42
+	public final boolean help;
43
+	
44
+	public Arguments(String directory, String target) {
45
+		this(directory, target, false);
46
+	}
47
+	
48
+	private Arguments(String directory, String target, boolean help) {
49
+		this.directory = directory;
50
+		this.target = target;
51
+		this.help = help;
52
+	}
53
+}

+ 20
- 0
Constructor/src/main/java/org/openzen/zenscript/constructor/ConstructorException.java Переглянути файл

@@ -0,0 +1,20 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.constructor;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public class ConstructorException extends RuntimeException {
13
+	public ConstructorException(String message) {
14
+		super(message);
15
+	}
16
+	
17
+	public ConstructorException(String message, Throwable cause) {
18
+		super(message, cause);
19
+	}
20
+}

+ 28
- 0
Constructor/src/main/java/org/openzen/zenscript/constructor/JSONUtils.java Переглянути файл

@@ -0,0 +1,28 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.constructor;
7
+
8
+import java.io.BufferedInputStream;
9
+import java.io.File;
10
+import java.io.FileInputStream;
11
+import java.io.IOException;
12
+import org.json.JSONException;
13
+import org.json.JSONObject;
14
+import org.json.JSONTokener;
15
+
16
+/**
17
+ *
18
+ * @author Hoofdgebruiker
19
+ */
20
+public class JSONUtils {
21
+	private JSONUtils() {}
22
+	
23
+	public static JSONObject load(File file) throws IOException, JSONException {
24
+		try (BufferedInputStream input = new BufferedInputStream(new FileInputStream(file))) {
25
+			return new JSONObject(new JSONTokener(input));
26
+		}
27
+	}
28
+}

+ 44
- 0
Constructor/src/main/java/org/openzen/zenscript/constructor/Main.java Переглянути файл

@@ -0,0 +1,44 @@
1
+package org.openzen.zenscript.constructor;
2
+
3
+import java.io.File;
4
+import java.io.IOException;
5
+import org.openzen.zenscript.constructor.module.DirectoryModuleLoader;
6
+
7
+public class Main {
8
+    /**
9
+     * @param args the command line arguments
10
+     */
11
+    public static void main(String[] args) throws IOException {
12
+		//Arguments arguments = Arguments.parse(args);
13
+		Arguments arguments = new Arguments("../../ZenCode", "default");
14
+		if (arguments.help) {
15
+			printHelp();
16
+			return;
17
+		}
18
+		
19
+		File currentDirectory = new File(arguments.directory);
20
+		File projectJson = new File(currentDirectory, "project.json");
21
+		if (!projectJson.exists()) {
22
+			System.out.println("Error: not a valid project (missing project.json)");
23
+			return;
24
+		}
25
+		
26
+		ModuleLoader moduleLoader = new ModuleLoader();
27
+		moduleLoader.register("stdlib", new DirectoryModuleLoader(moduleLoader, "stdlib", new File("libraries/stdlib"), true));
28
+		
29
+		Project project = new Project(projectJson);
30
+		for (String moduleName : project.modules) {
31
+			moduleLoader.register(moduleName, new DirectoryModuleLoader(moduleLoader, moduleName, new File(currentDirectory, moduleName), false));
32
+		}
33
+		
34
+		// TODO: compile targets
35
+		for (String moduleName : project.modules) {
36
+			moduleLoader.getModule(moduleName);
37
+		}
38
+    }
39
+	
40
+	private static void printHelp() {
41
+		System.out.println("Usage:");
42
+		System.out.println("  java -jar Constructor.jar [<target>] [-d directory] [-h|--help]");
43
+	}
44
+}

+ 154
- 0
Constructor/src/main/java/org/openzen/zenscript/constructor/Module.java Переглянути файл

@@ -0,0 +1,154 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.constructor;
7
+
8
+import java.io.BufferedInputStream;
9
+import java.io.File;
10
+import java.io.FileInputStream;
11
+import java.io.IOException;
12
+import java.util.ArrayList;
13
+import java.util.Collections;
14
+import java.util.List;
15
+import java.util.Map;
16
+import org.json.JSONObject;
17
+import org.json.JSONTokener;
18
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
19
+import org.openzen.zenscript.codemodel.PackageDefinitions;
20
+import org.openzen.zenscript.codemodel.ScriptBlock;
21
+import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
22
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
23
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
24
+import org.openzen.zenscript.constructor.module.ModuleSpace;
25
+import org.openzen.zenscript.constructor.module.SemanticModule;
26
+import org.openzen.zenscript.linker.symbol.ISymbol;
27
+import org.openzen.zenscript.parser.ParsedFile;
28
+import org.openzen.zenscript.shared.CompileException;
29
+import org.openzen.zenscript.validator.ValidationLogEntry;
30
+import org.openzen.zenscript.validator.Validator;
31
+
32
+/**
33
+ *
34
+ * @author Hoofdgebruiker
35
+ */
36
+public class Module {
37
+	public final String name;
38
+	public final File sourceDirectory;
39
+	public final String packageName;
40
+	public final String host;
41
+	
42
+	public Module(String name, File directory, File moduleFile) throws IOException {
43
+		this.name = name;
44
+		this.sourceDirectory = new File(directory, "src");
45
+		
46
+		BufferedInputStream input = new BufferedInputStream(new FileInputStream(moduleFile));
47
+		JSONObject json = new JSONObject(new JSONTokener(input));
48
+		packageName = json.getString("package");
49
+		host = json.getString("host");
50
+	}
51
+	
52
+	public ParsedFile[] parse(ZSPackage pkg) throws IOException {
53
+		List<ParsedFile> files = new ArrayList<>();
54
+		parse(files, pkg, sourceDirectory);
55
+		return files.toArray(new ParsedFile[files.size()]);
56
+	}
57
+	
58
+	private void parse(List<ParsedFile> files, ZSPackage pkg, File directory) throws IOException {
59
+		for (File file : directory.listFiles()) {
60
+			if (file.getName().endsWith(".zs")) {
61
+				try {
62
+					files.add(ParsedFile.parse(pkg, file));
63
+				} catch (CompileException ex) {
64
+					System.out.println(ex.getMessage());
65
+				}
66
+			} else if (file.isDirectory()) {
67
+				parse(files, pkg.getOrCreatePackage(file.getName()), file);
68
+			}
69
+		}
70
+	}
71
+	
72
+	public static SemanticModule compileSyntaxToSemantic(ZSPackage pkg, ParsedFile[] files, ModuleSpace registry) {
73
+		// We are considering all these files to be in the same package, so make
74
+		// a single PackageDefinition instance. If these files were in multiple
75
+		// packages, we'd need an instance for every package.
76
+		PackageDefinitions definitions = new PackageDefinitions();
77
+		for (ParsedFile file : files) {
78
+			// listDefinitions will merely register all definitions (classes,
79
+			// interfaces, functions ...) so they can later be available to
80
+			// the other files as well. It doesn't yet compile anything.
81
+			file.listDefinitions(definitions);
82
+		}
83
+		
84
+		ZSPackage rootPackage = registry.collectPackages();
85
+		List<ExpansionDefinition> expansions = registry.collectExpansions();
86
+		definitions.registerExpansionsTo(expansions);
87
+		
88
+		Map<String, ISymbol> globals = registry.collectGlobals();
89
+		boolean failed = false;
90
+		
91
+		GlobalTypeRegistry globalRegistry = new GlobalTypeRegistry();
92
+		for (ParsedFile file : files) {
93
+			// compileMembers will register all definition members to their
94
+			// respective definitions, such as fields, constructors, methods...
95
+			// It doesn't yet compile the method contents.
96
+			try {
97
+				file.compileTypes(rootPackage, definitions, globalRegistry, expansions, globals);
98
+			} catch (CompileException ex) {
99
+				System.out.println(ex.getMessage());
100
+				failed = true;
101
+			}
102
+		}
103
+		
104
+		if (failed)
105
+			return new SemanticModule(false, pkg, definitions, Collections.emptyList());
106
+		
107
+		for (ParsedFile file : files) {
108
+			// compileMembers will register all definition members to their
109
+			// respective definitions, such as fields, constructors, methods...
110
+			// It doesn't yet compile the method contents.
111
+			try {
112
+				file.compileMembers(rootPackage, definitions, globalRegistry, expansions, globals);
113
+			} catch (CompileException ex) {
114
+				System.out.println(ex.getMessage());
115
+				failed = true;
116
+			}
117
+		}
118
+		
119
+		if (failed)
120
+			return new SemanticModule(false, pkg, definitions, Collections.emptyList());
121
+		
122
+		// scripts will store all the script blocks encountered in the files
123
+		List<ScriptBlock> scripts = new ArrayList<>();
124
+		for (ParsedFile file : files) {
125
+			// compileCode will convert the parsed statements and expressions
126
+			// into semantic code. This semantic code can then be compiled
127
+			// to various targets.
128
+			try {
129
+				file.compileCode(rootPackage, definitions, globalRegistry, expansions, scripts, globals);
130
+			} catch (CompileException ex) {
131
+				System.out.println(ex.getMessage());
132
+				failed = true;
133
+			}
134
+		}
135
+		
136
+		if (failed)
137
+			return new SemanticModule(false, pkg, definitions, Collections.emptyList());
138
+		
139
+		Validator validator = new Validator();
140
+		boolean isValid = true;
141
+		for (ScriptBlock script : scripts) {
142
+			isValid &= validator.validate(script);
143
+		}
144
+		for (HighLevelDefinition definition : definitions.getAll()) {
145
+			isValid &= validator.validate(definition);
146
+		}
147
+		
148
+		for (ValidationLogEntry entry : validator.getLog()) {
149
+			System.out.println(entry.kind + " " + entry.position.toString() + ": " + entry.message);
150
+		}
151
+		
152
+		return new SemanticModule(isValid, pkg, definitions, scripts);
153
+	}
154
+}

+ 56
- 0
Constructor/src/main/java/org/openzen/zenscript/constructor/ModuleLoader.java Переглянути файл

@@ -0,0 +1,56 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.constructor;
7
+
8
+import java.util.HashMap;
9
+import java.util.HashSet;
10
+import java.util.Map;
11
+import java.util.Stack;
12
+import org.openzen.zenscript.constructor.module.ModuleReference;
13
+import org.openzen.zenscript.constructor.module.SemanticModule;
14
+
15
+/**
16
+ *
17
+ * @author Hoofdgebruiker
18
+ */
19
+public class ModuleLoader {
20
+	private final Map<String, SemanticModule> moduleCache = new HashMap<>();
21
+	private final Map<String, ModuleReference> modules = new HashMap<>();
22
+	
23
+	private final HashSet<String> compilingModulesSet = new HashSet<>();
24
+	private final Stack<String> compilingModulesStack = new Stack<>();
25
+	
26
+	public SemanticModule getModule(String name) {
27
+		if (moduleCache.containsKey(name))
28
+			return moduleCache.get(name);
29
+		
30
+		if (!modules.containsKey(name))
31
+			throw new ConstructorException("Module not found: " + name);
32
+		
33
+		if (compilingModulesSet.contains(name)) {
34
+			StringBuilder stack = new StringBuilder();
35
+			stack.append("Circular module reference loading ").append(name).append(":");
36
+			for (int i = compilingModulesStack.size() - 1; i >= 0; i--) {
37
+				stack.append("\n\t").append(compilingModulesStack.get(i));
38
+			}
39
+			throw new ConstructorException(stack.toString());
40
+		}
41
+		
42
+		compilingModulesSet.add(name);
43
+		compilingModulesStack.add(name);
44
+		
45
+		SemanticModule module = modules.get(name).load();
46
+		moduleCache.put(name, module);
47
+		
48
+		compilingModulesSet.remove(name);
49
+		compilingModulesStack.pop();
50
+		return module;
51
+	}
52
+	
53
+	public void register(String name, ModuleReference module) {
54
+		modules.put(name, module);
55
+	}
56
+}

+ 28
- 0
Constructor/src/main/java/org/openzen/zenscript/constructor/Project.java Переглянути файл

@@ -0,0 +1,28 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.constructor;
7
+
8
+import java.io.File;
9
+import java.io.IOException;
10
+import org.json.JSONArray;
11
+import org.json.JSONObject;
12
+
13
+/**
14
+ *
15
+ * @author Hoofdgebruiker
16
+ */
17
+public class Project {
18
+	public final String[] modules;
19
+	
20
+	public Project(File projectFile) throws IOException {
21
+		JSONObject json = JSONUtils.load(projectFile);
22
+		
23
+		JSONArray jsonModules = json.getJSONArray("modules");
24
+		modules = new String[jsonModules.length()];
25
+		for (int i = 0; i < jsonModules.length(); i++)
26
+			modules[i] = jsonModules.getString(i);
27
+	}
28
+}

+ 91
- 0
Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleLoader.java Переглянути файл

@@ -0,0 +1,91 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.constructor.module;
7
+
8
+import java.io.File;
9
+import java.io.IOException;
10
+import java.util.ArrayList;
11
+import java.util.List;
12
+import org.json.JSONArray;
13
+import org.json.JSONObject;
14
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
15
+import org.openzen.zenscript.constructor.ConstructorException;
16
+import org.openzen.zenscript.constructor.JSONUtils;
17
+import org.openzen.zenscript.constructor.Module;
18
+import org.openzen.zenscript.constructor.ModuleLoader;
19
+import org.openzen.zenscript.linker.symbol.TypeSymbol;
20
+import org.openzen.zenscript.parser.ParsedFile;
21
+
22
+/**
23
+ *
24
+ * @author Hoofdgebruiker
25
+ */
26
+public class DirectoryModuleLoader implements ModuleReference {
27
+	private final ModuleLoader loader;
28
+	private final String moduleName;
29
+	private final File directory;
30
+	private final boolean isStdlib;
31
+	
32
+	public DirectoryModuleLoader(ModuleLoader loader, String moduleName, File directory, boolean isStdlib) {
33
+		this.loader = loader;
34
+		this.moduleName = moduleName;
35
+		this.directory = directory;
36
+		this.isStdlib = isStdlib;
37
+	}
38
+
39
+	@Override
40
+	public SemanticModule load() {
41
+		if (!directory.exists())
42
+			throw new ConstructorException("Error: module directory not found: " + directory);
43
+		
44
+		File jsonFile = new File(directory, "module.json");
45
+		if (!jsonFile.exists())
46
+			throw new ConstructorException("Error: module.json file not found in module " + moduleName);
47
+		
48
+		try {
49
+			JSONObject json = JSONUtils.load(jsonFile);
50
+
51
+			List<String> dependencyNames = new ArrayList<>();
52
+			if (!isStdlib)
53
+				dependencyNames.add("stdlib");
54
+
55
+			JSONArray jsonDependencies = json.optJSONArray("dependencies");
56
+			if (jsonDependencies != null) {
57
+				for (int i = 0; i < jsonDependencies.length(); i++) {
58
+					dependencyNames.add(jsonDependencies.getString(i));
59
+				}
60
+			}
61
+
62
+			ModuleSpace space = new ModuleSpace();
63
+			for (String dependencyName : dependencyNames)
64
+				space.addModule(dependencyName, loader.getModule(dependencyName));
65
+
66
+			Module module = new Module(moduleName, directory, jsonFile);
67
+			ZSPackage pkg = new ZSPackage(module.packageName);
68
+
69
+			ParsedFile[] parsedFiles = module.parse(pkg);
70
+			SemanticModule result = Module.compileSyntaxToSemantic(pkg, parsedFiles, space);
71
+			
72
+			JSONObject globals = json.optJSONObject("globals");
73
+			if (globals != null) {
74
+				for (String key : globals.keySet()) {
75
+					JSONObject global = globals.getJSONObject(key);
76
+					switch (global.getString("type")) {
77
+						case "Definition":
78
+							result.globals.put(key, new TypeSymbol(result.definitions.getDefinition(global.getString("definition"))));
79
+							break;
80
+						default:
81
+							throw new ConstructorException("Invalid global type: " + global.getString("type"));
82
+					}
83
+				}
84
+			}
85
+			
86
+			return result;
87
+		} catch (IOException ex) {
88
+			throw new ConstructorException("Loading module files failed: " + ex.getMessage(), ex);
89
+		}
90
+	}
91
+}

+ 25
- 0
Constructor/src/main/java/org/openzen/zenscript/constructor/module/FileContents.java Переглянути файл

@@ -0,0 +1,25 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.constructor.module;
7
+
8
+import java.util.ArrayList;
9
+import java.util.List;
10
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
+import org.openzen.zenscript.codemodel.ScriptBlock;
12
+
13
+/**
14
+ *
15
+ * @author Hoofdgebruiker
16
+ */
17
+public class FileContents {
18
+	public final String filename;
19
+	public ScriptBlock script;
20
+	public final List<HighLevelDefinition> definitions = new ArrayList<>();
21
+	
22
+	public FileContents(String filename) {
23
+		this.filename = filename;
24
+	}
25
+}

+ 14
- 0
Constructor/src/main/java/org/openzen/zenscript/constructor/module/ModuleReference.java Переглянути файл

@@ -0,0 +1,14 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.constructor.module;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public interface ModuleReference {
13
+	public SemanticModule load();
14
+}

+ 54
- 0
Constructor/src/main/java/org/openzen/zenscript/constructor/module/ModuleSpace.java Переглянути файл

@@ -0,0 +1,54 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.constructor.module;
7
+
8
+import java.util.ArrayList;
9
+import java.util.HashMap;
10
+import java.util.List;
11
+import java.util.Map;
12
+import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
13
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
14
+import org.openzen.zenscript.constructor.ConstructorException;
15
+import org.openzen.zenscript.linker.symbol.ISymbol;
16
+
17
+/**
18
+ *
19
+ * @author Hoofdgebruiker
20
+ */
21
+public class ModuleSpace {
22
+	public final ZSPackage globalsPackage = new ZSPackage("");
23
+	private final ZSPackage rootPackage = new ZSPackage("");
24
+	private final List<ExpansionDefinition> expansions = new ArrayList<>();
25
+	private final Map<String, ISymbol> globals = new HashMap<>();
26
+	
27
+	public ModuleSpace() {
28
+		
29
+	}
30
+	
31
+	public void addModule(String name, SemanticModule dependency) {
32
+		rootPackage.add(name, dependency.pkg);
33
+		dependency.definitions.registerExpansionsTo(expansions);
34
+		
35
+		for (Map.Entry<String, ISymbol> globalEntry : dependency.globals.entrySet()) {
36
+			if (globals.containsKey(globalEntry.getKey()))
37
+				throw new ConstructorException("Duplicate global: " + globalEntry.getKey());
38
+			
39
+			globals.put(globalEntry.getKey(), globalEntry.getValue());
40
+		}
41
+	}
42
+	
43
+	public ZSPackage collectPackages() {
44
+		return rootPackage;
45
+	}
46
+	
47
+	public List<ExpansionDefinition> collectExpansions() {
48
+		return expansions;
49
+	}
50
+	
51
+	public Map<String, ISymbol> collectGlobals() {
52
+		return globals;
53
+	}
54
+}

+ 47
- 0
Constructor/src/main/java/org/openzen/zenscript/constructor/module/SemanticModule.java Переглянути файл

@@ -0,0 +1,47 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.constructor.module;
7
+
8
+import java.util.HashMap;
9
+import java.util.List;
10
+import java.util.Map;
11
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
+import org.openzen.zenscript.codemodel.PackageDefinitions;
13
+import org.openzen.zenscript.codemodel.ScriptBlock;
14
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
15
+import org.openzen.zenscript.javabytecode.JavaCompiler;
16
+import org.openzen.zenscript.javabytecode.JavaModule;
17
+import org.openzen.zenscript.linker.symbol.ISymbol;
18
+
19
+/**
20
+ *
21
+ * @author Hoofdgebruiker
22
+ */
23
+public class SemanticModule {
24
+	public final boolean isValid;
25
+	public final ZSPackage pkg;
26
+	public final PackageDefinitions definitions;
27
+	public final List<ScriptBlock> scripts;
28
+	public final Map<String, ISymbol> globals = new HashMap<>();
29
+	
30
+	public SemanticModule(boolean isValid, ZSPackage pkg, PackageDefinitions definitions, List<ScriptBlock> scripts) {
31
+		this.isValid = isValid;
32
+		this.pkg = pkg;
33
+		this.definitions = definitions;
34
+		this.scripts = scripts;
35
+	}
36
+	
37
+	public JavaModule compileToJava() {
38
+		JavaCompiler compiler = new JavaCompiler(false);
39
+		for (HighLevelDefinition definition : definitions.getAll()) {
40
+			compiler.addDefinition(definition);
41
+		}
42
+		for (ScriptBlock script : scripts) {
43
+			compiler.addScriptBlock(script);
44
+		}
45
+		return compiler.finish();
46
+	}
47
+}

+ 2
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java Переглянути файл

@@ -58,6 +58,8 @@ public class JavaCompiler {
58 58
 		implement(FLOAT_NEG, JavaWriter::fNeg);
59 59
 		implement(DOUBLE_NEG, JavaWriter::dNeg);
60 60
 		
61
+		
62
+		
61 63
 		implement(BYTE_ADD_BYTE, JavaWriter::iAdd);
62 64
 		implement(SBYTE_ADD_SBYTE, JavaWriter::iAdd);
63 65
 		implement(SHORT_ADD_SHORT, JavaWriter::iAdd);

+ 5
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaParameterInfo.java Переглянути файл

@@ -5,14 +5,18 @@
5 5
  */
6 6
 package org.openzen.zenscript.javabytecode;
7 7
 
8
+import org.objectweb.asm.Type;
9
+
8 10
 /**
9 11
  *
10 12
  * @author Hoofdgebruiker
11 13
  */
12 14
 public class JavaParameterInfo {
13 15
 	public final int index;
16
+	public final Type type;
14 17
 	
15
-	public JavaParameterInfo(int index) {
18
+	public JavaParameterInfo(int index, Type type) {
16 19
 		this.index = index;
20
+		this.type = type;
17 21
 	}
18 22
 }

+ 0
- 9
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/TestIsStaticInfo.java Переглянути файл

@@ -1,9 +0,0 @@
1
-package org.openzen.zenscript.javabytecode;
2
-
3
-public class TestIsStaticInfo {
4
-    public final boolean isStatic;
5
-
6
-    public TestIsStaticInfo(boolean isStatic) {
7
-        this.isStatic = isStatic;
8
-    }
9
-}

+ 14
- 5
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/CompilerUtils.java Переглянути файл

@@ -78,22 +78,31 @@ public class CompilerUtils {
78 78
     }
79 79
 	
80 80
 	public static void tagMethodParameters(FunctionHeader header, boolean isStatic) {
81
+		JavaTypeVisitor typeVisitor = new JavaTypeVisitor();
81 82
 		for (int i = 0; i < header.parameters.length; i++) {
82
-			header.parameters[i].setTag(JavaParameterInfo.class, new JavaParameterInfo(isStatic ? i : i + 1));
83
+			FunctionParameter parameter = header.parameters[i];
84
+			Type parameterType = parameter.type.accept(typeVisitor);
85
+			parameter.setTag(JavaParameterInfo.class, new JavaParameterInfo(isStatic ? i : i + 1, parameterType));
83 86
 		}
84 87
 	}
85 88
 	
86 89
 	public static void tagConstructorParameters(FunctionHeader header, boolean isEnum) {
90
+		JavaTypeVisitor typeVisitor = new JavaTypeVisitor();
87 91
 		for (int i = 0; i < header.parameters.length; i++) {
88
-			header.parameters[i].setTag(JavaParameterInfo.class, new JavaParameterInfo(isEnum ? i + 3 : i + 1));
92
+			FunctionParameter parameter = header.parameters[i];
93
+			Type parameterType = parameter.type.accept(typeVisitor);
94
+			parameter.setTag(JavaParameterInfo.class, new JavaParameterInfo(isEnum ? i + 3 : i + 1, parameterType));
89 95
 		}
90 96
 	}
91 97
 	
92
-	public static void writeDefaultFieldInitializers(JavaWriter constructorWriter, HighLevelDefinition definition) {
98
+	public static void writeDefaultFieldInitializers(JavaWriter constructorWriter, HighLevelDefinition definition, boolean staticFields) {
93 99
 		JavaExpressionVisitor expressionVisitor = new JavaExpressionVisitor(constructorWriter);
94 100
 		for (final IDefinitionMember definitionMember : definition.members) {
95
-			if (definitionMember instanceof FieldMember && ((FieldMember) definitionMember).initializer != null) {
96
-				final FieldMember field = (FieldMember) definitionMember;
101
+			if (!(definitionMember instanceof FieldMember))
102
+				continue;
103
+			
104
+			FieldMember field = (FieldMember) definitionMember;
105
+			if (field.isStatic() == staticFields && field.initializer != null) {
97 106
 				constructorWriter.loadObject(0);
98 107
 				field.initializer.accept(expressionVisitor);
99 108
 				constructorWriter.putField(definition.name, field.name, Type.getDescriptor(field.type.accept(JavaTypeClassVisitor.INSTANCE)));

+ 15
- 5
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java Переглянути файл

@@ -300,7 +300,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
300 300
         //No super calls in enums possible, and that's already handled in the enum constructor itself.
301 301
         javaWriter.invokeSpecial(expression.objectType.accept(JavaTypeClassVisitor.INSTANCE), "<init>", CompilerUtils.calcDesc(expression.constructor.header, false));
302 302
 		
303
-		CompilerUtils.writeDefaultFieldInitializers(javaWriter, javaWriter.forDefinition);
303
+		CompilerUtils.writeDefaultFieldInitializers(javaWriter, javaWriter.forDefinition, false);
304 304
         return null;
305 305
     }
306 306
 
@@ -324,7 +324,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
324 324
 
325 325
     @Override
326 326
     public Void visitGetField(GetFieldExpression expression) {
327
-        javaWriter.loadObject(0);
327
+		expression.accept(this);
328 328
         if (!checkAndGetFieldInfo(expression.field, false))
329 329
             throw new IllegalStateException("Missing field info on a field member!");
330 330
         return null;
@@ -455,6 +455,16 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
455 455
 
456 456
         return null;
457 457
     }
458
+	
459
+	@Override
460
+	public Void visitPostCall(PostCallExpression expression) {
461
+		expression.target.accept(this);
462
+		javaWriter.dup(expression.type.accept(new JavaTypeVisitor()));
463
+        if (!checkAndExecuteByteCodeImplementation(expression.member) && !checkAndExecuteMethodInfo(expression.member))
464
+            throw new IllegalStateException("Call target has no method info!");
465
+		
466
+		return null;
467
+	}
458 468
 
459 469
     @Override
460 470
     public Void visitRange(RangeExpression expression) {
@@ -472,7 +482,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
472 482
 
473 483
     @Override
474 484
     public Void visitSetField(SetFieldExpression expression) {
475
-        javaWriter.loadObject(0);
485
+        expression.target.accept(this);
476 486
         expression.value.accept(this);
477 487
         if (!checkAndPutFieldInfo(expression.field, false))
478 488
             throw new IllegalStateException("Missing field info on a field member!");
@@ -568,7 +578,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
568 578
 
569 579
 
570 580
     //Will return true if a JavaFieldInfo.class tag exists, and will compile that tag
571
-    private boolean checkAndPutFieldInfo(DefinitionMember field, boolean isStatic) {
581
+    public boolean checkAndPutFieldInfo(DefinitionMember field, boolean isStatic) {
572 582
         JavaFieldInfo fieldInfo = field.getTag(JavaFieldInfo.class);
573 583
         if (fieldInfo == null)
574 584
             return false;
@@ -581,7 +591,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
581 591
         return true;
582 592
     }
583 593
 
584
-    private boolean checkAndGetFieldInfo(DefinitionMember field, boolean isStatic) {
594
+    public boolean checkAndGetFieldInfo(DefinitionMember field, boolean isStatic) {
585 595
         JavaFieldInfo fieldInfo = field.getTag(JavaFieldInfo.class);
586 596
         if (fieldInfo == null)
587 597
             return false;

+ 6
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaOptionalTypeClassVisitor.java Переглянути файл

@@ -11,6 +11,7 @@ import org.openzen.zenscript.codemodel.type.BasicTypeID;
11 11
 import org.openzen.zenscript.codemodel.type.ConstTypeID;
12 12
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
13 13
 import org.openzen.zenscript.codemodel.type.FunctionTypeID;
14
+import org.openzen.zenscript.codemodel.type.GenericMapTypeID;
14 15
 import org.openzen.zenscript.codemodel.type.GenericTypeID;
15 16
 import org.openzen.zenscript.codemodel.type.ITypeVisitor;
16 17
 import org.openzen.zenscript.codemodel.type.IteratorTypeID;
@@ -108,4 +109,9 @@ public class JavaOptionalTypeClassVisitor implements ITypeVisitor<Class> {
108 109
 	public Class visitOptional(OptionalTypeID optional) {
109 110
 		return base.visitOptional(optional);
110 111
 	}
112
+
113
+	@Override
114
+	public Class visitGenericMap(GenericMapTypeID map) {
115
+		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
116
+	}
111 117
 }

+ 395
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreDecrementVisitor.java Переглянути файл

@@ -0,0 +1,395 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.javabytecode.compiler;
7
+
8
+import org.objectweb.asm.Type;
9
+import org.openzen.zenscript.codemodel.expression.AndAndExpression;
10
+import org.openzen.zenscript.codemodel.expression.ArrayExpression;
11
+import org.openzen.zenscript.codemodel.expression.BasicCompareExpression;
12
+import org.openzen.zenscript.codemodel.expression.CallExpression;
13
+import org.openzen.zenscript.codemodel.expression.CallStaticExpression;
14
+import org.openzen.zenscript.codemodel.expression.CapturedClosureExpression;
15
+import org.openzen.zenscript.codemodel.expression.CapturedDirectExpression;
16
+import org.openzen.zenscript.codemodel.expression.CapturedLocalVariableExpression;
17
+import org.openzen.zenscript.codemodel.expression.CapturedParameterExpression;
18
+import org.openzen.zenscript.codemodel.expression.CapturedThisExpression;
19
+import org.openzen.zenscript.codemodel.expression.CastExpression;
20
+import org.openzen.zenscript.codemodel.expression.CheckNullExpression;
21
+import org.openzen.zenscript.codemodel.expression.CoalesceExpression;
22
+import org.openzen.zenscript.codemodel.expression.ConditionalExpression;
23
+import org.openzen.zenscript.codemodel.expression.ConstantBoolExpression;
24
+import org.openzen.zenscript.codemodel.expression.ConstantByteExpression;
25
+import org.openzen.zenscript.codemodel.expression.ConstantCharExpression;
26
+import org.openzen.zenscript.codemodel.expression.ConstantDoubleExpression;
27
+import org.openzen.zenscript.codemodel.expression.ConstantFloatExpression;
28
+import org.openzen.zenscript.codemodel.expression.ConstantIntExpression;
29
+import org.openzen.zenscript.codemodel.expression.ConstantLongExpression;
30
+import org.openzen.zenscript.codemodel.expression.ConstantSByteExpression;
31
+import org.openzen.zenscript.codemodel.expression.ConstantShortExpression;
32
+import org.openzen.zenscript.codemodel.expression.ConstantStringExpression;
33
+import org.openzen.zenscript.codemodel.expression.ConstantUIntExpression;
34
+import org.openzen.zenscript.codemodel.expression.ConstantULongExpression;
35
+import org.openzen.zenscript.codemodel.expression.ConstantUShortExpression;
36
+import org.openzen.zenscript.codemodel.expression.ConstructorSuperCallExpression;
37
+import org.openzen.zenscript.codemodel.expression.ConstructorThisCallExpression;
38
+import org.openzen.zenscript.codemodel.expression.EnumConstantExpression;
39
+import org.openzen.zenscript.codemodel.expression.ExpressionVisitor;
40
+import org.openzen.zenscript.codemodel.expression.FunctionExpression;
41
+import org.openzen.zenscript.codemodel.expression.GenericCompareExpression;
42
+import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
43
+import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
44
+import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
45
+import org.openzen.zenscript.codemodel.expression.GetStaticFieldExpression;
46
+import org.openzen.zenscript.codemodel.expression.GetterExpression;
47
+import org.openzen.zenscript.codemodel.expression.GlobalCallExpression;
48
+import org.openzen.zenscript.codemodel.expression.GlobalExpression;
49
+import org.openzen.zenscript.codemodel.expression.InterfaceCastExpression;
50
+import org.openzen.zenscript.codemodel.expression.IsExpression;
51
+import org.openzen.zenscript.codemodel.expression.MakeConstExpression;
52
+import org.openzen.zenscript.codemodel.expression.MapExpression;
53
+import org.openzen.zenscript.codemodel.expression.NewExpression;
54
+import org.openzen.zenscript.codemodel.expression.NullExpression;
55
+import org.openzen.zenscript.codemodel.expression.OrOrExpression;
56
+import org.openzen.zenscript.codemodel.expression.PostCallExpression;
57
+import org.openzen.zenscript.codemodel.expression.RangeExpression;
58
+import org.openzen.zenscript.codemodel.expression.SetFieldExpression;
59
+import org.openzen.zenscript.codemodel.expression.SetFunctionParameterExpression;
60
+import org.openzen.zenscript.codemodel.expression.SetLocalVariableExpression;
61
+import org.openzen.zenscript.codemodel.expression.SetStaticFieldExpression;
62
+import org.openzen.zenscript.codemodel.expression.SetterExpression;
63
+import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
64
+import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
65
+import org.openzen.zenscript.codemodel.expression.ThisExpression;
66
+import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
67
+import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
68
+import org.openzen.zenscript.javabytecode.JavaParameterInfo;
69
+
70
+/**
71
+ *
72
+ * @author Hoofdgebruiker
73
+ */
74
+public class JavaPreDecrementVisitor implements ExpressionVisitor<Void> {
75
+	private final JavaExpressionVisitor expressionCompiler;
76
+	private final JavaWriter javaWriter;
77
+	
78
+	public JavaPreDecrementVisitor(JavaExpressionVisitor expressionCompiler) {
79
+		this.expressionCompiler = expressionCompiler;
80
+		javaWriter = expressionCompiler.getJavaWriter();
81
+	}
82
+
83
+	@Override
84
+	public Void visitAndAnd(AndAndExpression expression) {
85
+		throw new UnsupportedOperationException("Invalid increment target");
86
+	}
87
+
88
+	@Override
89
+	public Void visitArray(ArrayExpression expression) {
90
+		throw new UnsupportedOperationException("Invalid increment target");
91
+	}
92
+
93
+	@Override
94
+	public Void visitCompare(BasicCompareExpression expression) {
95
+		throw new UnsupportedOperationException("Invalid increment target");
96
+	}
97
+
98
+	@Override
99
+	public Void visitCall(CallExpression expression) {
100
+		throw new UnsupportedOperationException("Invalid increment target");
101
+	}
102
+
103
+	@Override
104
+	public Void visitCallStatic(CallStaticExpression expression) {
105
+		throw new UnsupportedOperationException("Invalid increment target");
106
+	}
107
+
108
+	@Override
109
+	public Void visitCapturedClosure(CapturedClosureExpression expression) {
110
+		throw new UnsupportedOperationException("Invalid increment target");
111
+	}
112
+
113
+	@Override
114
+	public Void visitCapturedDirect(CapturedDirectExpression expression) {
115
+		throw new UnsupportedOperationException("Invalid increment target");
116
+	}
117
+
118
+	@Override
119
+	public Void visitCapturedLocalVariable(CapturedLocalVariableExpression expression) {
120
+		throw new UnsupportedOperationException("Invalid increment target");
121
+	}
122
+
123
+	@Override
124
+	public Void visitCapturedParameter(CapturedParameterExpression expression) {
125
+		throw new UnsupportedOperationException("Invalid increment target");
126
+	}
127
+
128
+	@Override
129
+	public Void visitCapturedThis(CapturedThisExpression expression) {
130
+		throw new UnsupportedOperationException("Invalid increment target");
131
+	}
132
+
133
+	@Override
134
+	public Void visitCast(CastExpression expression) {
135
+		throw new UnsupportedOperationException("Invalid increment target");
136
+	}
137
+
138
+	@Override
139
+	public Void visitCheckNull(CheckNullExpression expression) {
140
+		throw new UnsupportedOperationException("Invalid increment target");
141
+	}
142
+
143
+	@Override
144
+	public Void visitCoalesce(CoalesceExpression expression) {
145
+		throw new UnsupportedOperationException("Invalid increment target");
146
+	}
147
+
148
+	@Override
149
+	public Void visitConditional(ConditionalExpression expression) {
150
+		throw new UnsupportedOperationException("Invalid increment target");
151
+	}
152
+
153
+	@Override
154
+	public Void visitConstantBool(ConstantBoolExpression expression) {
155
+		throw new UnsupportedOperationException("Invalid increment target");
156
+	}
157
+
158
+	@Override
159
+	public Void visitConstantByte(ConstantByteExpression expression) {
160
+		throw new UnsupportedOperationException("Invalid increment target");
161
+	}
162
+
163
+	@Override
164
+	public Void visitConstantChar(ConstantCharExpression expression) {
165
+		throw new UnsupportedOperationException("Invalid increment target");
166
+	}
167
+
168
+	@Override
169
+	public Void visitConstantDouble(ConstantDoubleExpression expression) {
170
+		throw new UnsupportedOperationException("Invalid increment target");
171
+	}
172
+
173
+	@Override
174
+	public Void visitConstantFloat(ConstantFloatExpression expression) {
175
+		throw new UnsupportedOperationException("Invalid increment target");
176
+	}
177
+
178
+	@Override
179
+	public Void visitConstantInt(ConstantIntExpression expression) {
180
+		throw new UnsupportedOperationException("Invalid increment target");
181
+	}
182
+
183
+	@Override
184
+	public Void visitConstantLong(ConstantLongExpression expression) {
185
+		throw new UnsupportedOperationException("Invalid increment target");
186
+	}
187
+
188
+	@Override
189
+	public Void visitConstantSByte(ConstantSByteExpression expression) {
190
+		throw new UnsupportedOperationException("Invalid increment target");
191
+	}
192
+
193
+	@Override
194
+	public Void visitConstantShort(ConstantShortExpression expression) {
195
+		throw new UnsupportedOperationException("Invalid increment target");
196
+	}
197
+
198
+	@Override
199
+	public Void visitConstantString(ConstantStringExpression expression) {
200
+		throw new UnsupportedOperationException("Invalid increment target");
201
+	}
202
+
203
+	@Override
204
+	public Void visitConstantUInt(ConstantUIntExpression expression) {
205
+		throw new UnsupportedOperationException("Invalid increment target");
206
+	}
207
+
208
+	@Override
209
+	public Void visitConstantULong(ConstantULongExpression expression) {
210
+		throw new UnsupportedOperationException("Invalid increment target");
211
+	}
212
+
213
+	@Override
214
+	public Void visitConstantUShort(ConstantUShortExpression expression) {
215
+		throw new UnsupportedOperationException("Invalid increment target");
216
+	}
217
+
218
+	@Override
219
+	public Void visitConstructorThisCall(ConstructorThisCallExpression expression) {
220
+		throw new UnsupportedOperationException("Invalid increment target");
221
+	}
222
+
223
+	@Override
224
+	public Void visitConstructorSuperCall(ConstructorSuperCallExpression expression) {
225
+		throw new UnsupportedOperationException("Invalid increment target");
226
+	}
227
+
228
+	@Override
229
+	public Void visitEnumConstant(EnumConstantExpression expression) {
230
+		throw new UnsupportedOperationException("Invalid increment target");
231
+	}
232
+
233
+	@Override
234
+	public Void visitFunction(FunctionExpression expression) {
235
+		throw new UnsupportedOperationException("Invalid increment target");
236
+	}
237
+
238
+	@Override
239
+	public Void visitGenericCompare(GenericCompareExpression expression) {
240
+		throw new UnsupportedOperationException("Invalid increment target");
241
+	}
242
+
243
+	@Override
244
+	public Void visitGetField(GetFieldExpression expression) {
245
+		Type objectType = expression.target.type.accept(new JavaTypeVisitor());
246
+		
247
+		int local = javaWriter.local(objectType);
248
+		expression.target.accept(expressionCompiler);
249
+		javaWriter.dup();
250
+		javaWriter.store(objectType, local);
251
+		
252
+        if (!expressionCompiler.checkAndGetFieldInfo(expression.field, false))
253
+            throw new IllegalStateException("Missing field info on a field member!");
254
+		
255
+		javaWriter.iConst1();
256
+		javaWriter.iSub();
257
+		
258
+		javaWriter.load(objectType, local);
259
+        if (!expressionCompiler.checkAndPutFieldInfo(expression.field, false))
260
+            throw new IllegalStateException("Missing field info on a field member!");
261
+		
262
+		return null;
263
+	}
264
+
265
+	@Override
266
+	public Void visitGetFunctionParameter(GetFunctionParameterExpression expression) {
267
+		javaWriter.idec(expression.parameter.getTag(JavaParameterInfo.class).index);
268
+		return null;
269
+	}
270
+
271
+	@Override
272
+	public Void visitGetLocalVariable(GetLocalVariableExpression expression) {
273
+		javaWriter.idec(expression.variable.getTag(JavaLocalVariableInfo.class).local);
274
+		return null;
275
+	}
276
+
277
+	@Override
278
+	public Void visitGetStaticField(GetStaticFieldExpression expression) {
279
+		if (!expressionCompiler.checkAndGetFieldInfo(expression.field, false))
280
+            throw new IllegalStateException("Missing field info on a field member!");
281
+		
282
+		javaWriter.iConst1();
283
+		javaWriter.iAdd();
284
+		
285
+		if (!expressionCompiler.checkAndPutFieldInfo(expression.field, false))
286
+            throw new IllegalStateException("Missing field info on a field member!");
287
+		
288
+		return null;
289
+	}
290
+
291
+	@Override
292
+	public Void visitGetter(GetterExpression expression) {
293
+		throw new UnsupportedOperationException("Not yet supported");
294
+	}
295
+
296
+	@Override
297
+	public Void visitGlobal(GlobalExpression expression) {
298
+		throw new UnsupportedOperationException("Invalid increment target");
299
+	}
300
+
301
+	@Override
302
+	public Void visitGlobalCall(GlobalCallExpression expression) {
303
+		throw new UnsupportedOperationException("Invalid increment target");
304
+	}
305
+
306
+	@Override
307
+	public Void visitInterfaceCast(InterfaceCastExpression expression) {
308
+		throw new UnsupportedOperationException("Invalid increment target");
309
+	}
310
+
311
+	@Override
312
+	public Void visitIs(IsExpression expression) {
313
+		throw new UnsupportedOperationException("Invalid increment target");
314
+	}
315
+
316
+	@Override
317
+	public Void visitMakeConst(MakeConstExpression expression) {
318
+		throw new UnsupportedOperationException("Invalid increment target");
319
+	}
320
+
321
+	@Override
322
+	public Void visitMap(MapExpression expression) {
323
+		throw new UnsupportedOperationException("Invalid increment target");
324
+	}
325
+
326
+	@Override
327
+	public Void visitNew(NewExpression expression) {
328
+		throw new UnsupportedOperationException("Invalid increment target");
329
+	}
330
+
331
+	@Override
332
+	public Void visitNull(NullExpression expression) {
333
+		throw new UnsupportedOperationException("Invalid increment target");
334
+	}
335
+
336
+	@Override
337
+	public Void visitOrOr(OrOrExpression expression) {
338
+		throw new UnsupportedOperationException("Invalid increment target");
339
+	}
340
+
341
+	@Override
342
+	public Void visitPostCall(PostCallExpression expression) {
343
+		throw new UnsupportedOperationException("Invalid increment target");
344
+	}
345
+
346
+	@Override
347
+	public Void visitRange(RangeExpression expression) {
348
+		throw new UnsupportedOperationException("Invalid increment target");
349
+	}
350
+
351
+	@Override
352
+	public Void visitSetField(SetFieldExpression expression) {
353
+		throw new UnsupportedOperationException("Invalid increment target");
354
+	}
355
+
356
+	@Override
357
+	public Void visitSetFunctionParameter(SetFunctionParameterExpression expression) {
358
+		throw new UnsupportedOperationException("Invalid increment target");
359
+	}
360
+
361
+	@Override
362
+	public Void visitSetLocalVariable(SetLocalVariableExpression expression) {
363
+		throw new UnsupportedOperationException("Invalid increment target");
364
+	}
365
+
366
+	@Override
367
+	public Void visitSetStaticField(SetStaticFieldExpression expression) {
368
+		throw new UnsupportedOperationException("Invalid increment target");
369
+	}
370
+
371
+	@Override
372
+	public Void visitSetter(SetterExpression expression) {
373
+		throw new UnsupportedOperationException("Invalid increment target");
374
+	}
375
+
376
+	@Override
377
+	public Void visitStaticGetter(StaticGetterExpression expression) {
378
+		throw new UnsupportedOperationException("Invalid increment target");
379
+	}
380
+
381
+	@Override
382
+	public Void visitStaticSetter(StaticSetterExpression expression) {
383
+		throw new UnsupportedOperationException("Invalid increment target");
384
+	}
385
+
386
+	@Override
387
+	public Void visitThis(ThisExpression expression) {
388
+		throw new UnsupportedOperationException("Invalid increment target");
389
+	}
390
+
391
+	@Override
392
+	public Void visitWrapOptional(WrapOptionalExpression expression) {
393
+		throw new UnsupportedOperationException("Invalid increment target");
394
+	}
395
+}

+ 401
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreIncrementVisitor.java Переглянути файл

@@ -0,0 +1,401 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.javabytecode.compiler;
7
+
8
+import org.objectweb.asm.Type;
9
+import org.openzen.zenscript.codemodel.expression.AndAndExpression;
10
+import org.openzen.zenscript.codemodel.expression.ArrayExpression;
11
+import org.openzen.zenscript.codemodel.expression.BasicCompareExpression;
12
+import org.openzen.zenscript.codemodel.expression.CallExpression;
13
+import org.openzen.zenscript.codemodel.expression.CallStaticExpression;
14
+import org.openzen.zenscript.codemodel.expression.CapturedClosureExpression;
15
+import org.openzen.zenscript.codemodel.expression.CapturedDirectExpression;
16
+import org.openzen.zenscript.codemodel.expression.CapturedLocalVariableExpression;
17
+import org.openzen.zenscript.codemodel.expression.CapturedParameterExpression;
18
+import org.openzen.zenscript.codemodel.expression.CapturedThisExpression;
19
+import org.openzen.zenscript.codemodel.expression.CastExpression;
20
+import org.openzen.zenscript.codemodel.expression.CheckNullExpression;
21
+import org.openzen.zenscript.codemodel.expression.CoalesceExpression;
22
+import org.openzen.zenscript.codemodel.expression.ConditionalExpression;
23
+import org.openzen.zenscript.codemodel.expression.ConstantBoolExpression;
24
+import org.openzen.zenscript.codemodel.expression.ConstantByteExpression;
25
+import org.openzen.zenscript.codemodel.expression.ConstantCharExpression;
26
+import org.openzen.zenscript.codemodel.expression.ConstantDoubleExpression;
27
+import org.openzen.zenscript.codemodel.expression.ConstantFloatExpression;
28
+import org.openzen.zenscript.codemodel.expression.ConstantIntExpression;
29
+import org.openzen.zenscript.codemodel.expression.ConstantLongExpression;
30
+import org.openzen.zenscript.codemodel.expression.ConstantSByteExpression;
31
+import org.openzen.zenscript.codemodel.expression.ConstantShortExpression;
32
+import org.openzen.zenscript.codemodel.expression.ConstantStringExpression;
33
+import org.openzen.zenscript.codemodel.expression.ConstantUIntExpression;
34
+import org.openzen.zenscript.codemodel.expression.ConstantULongExpression;
35
+import org.openzen.zenscript.codemodel.expression.ConstantUShortExpression;
36
+import org.openzen.zenscript.codemodel.expression.ConstructorSuperCallExpression;
37
+import org.openzen.zenscript.codemodel.expression.ConstructorThisCallExpression;
38
+import org.openzen.zenscript.codemodel.expression.EnumConstantExpression;
39
+import org.openzen.zenscript.codemodel.expression.ExpressionVisitor;
40
+import org.openzen.zenscript.codemodel.expression.FunctionExpression;
41
+import org.openzen.zenscript.codemodel.expression.GenericCompareExpression;
42
+import org.openzen.zenscript.codemodel.expression.GetFieldExpression;
43
+import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
44
+import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
45
+import org.openzen.zenscript.codemodel.expression.GetStaticFieldExpression;
46
+import org.openzen.zenscript.codemodel.expression.GetterExpression;
47
+import org.openzen.zenscript.codemodel.expression.GlobalCallExpression;
48
+import org.openzen.zenscript.codemodel.expression.GlobalExpression;
49
+import org.openzen.zenscript.codemodel.expression.InterfaceCastExpression;
50
+import org.openzen.zenscript.codemodel.expression.IsExpression;
51
+import org.openzen.zenscript.codemodel.expression.MakeConstExpression;
52
+import org.openzen.zenscript.codemodel.expression.MapExpression;
53
+import org.openzen.zenscript.codemodel.expression.NewExpression;
54
+import org.openzen.zenscript.codemodel.expression.NullExpression;
55
+import org.openzen.zenscript.codemodel.expression.OrOrExpression;
56
+import org.openzen.zenscript.codemodel.expression.PostCallExpression;
57
+import org.openzen.zenscript.codemodel.expression.RangeExpression;
58
+import org.openzen.zenscript.codemodel.expression.SetFieldExpression;
59
+import org.openzen.zenscript.codemodel.expression.SetFunctionParameterExpression;
60
+import org.openzen.zenscript.codemodel.expression.SetLocalVariableExpression;
61
+import org.openzen.zenscript.codemodel.expression.SetStaticFieldExpression;
62
+import org.openzen.zenscript.codemodel.expression.SetterExpression;
63
+import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
64
+import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
65
+import org.openzen.zenscript.codemodel.expression.ThisExpression;
66
+import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
67
+import org.openzen.zenscript.javabytecode.JavaLocalVariableInfo;
68
+import org.openzen.zenscript.javabytecode.JavaParameterInfo;
69
+
70
+/**
71
+ *
72
+ * @author Hoofdgebruiker
73
+ */
74
+public class JavaPreIncrementVisitor implements ExpressionVisitor<Void> {
75
+	private final JavaExpressionVisitor expressionCompiler;
76
+	private final JavaWriter javaWriter;
77
+	
78
+	public JavaPreIncrementVisitor(JavaExpressionVisitor expressionCompiler) {
79
+		this.expressionCompiler = expressionCompiler;
80
+		javaWriter = expressionCompiler.getJavaWriter();
81
+	}
82
+
83
+	@Override
84
+	public Void visitAndAnd(AndAndExpression expression) {
85
+		throw new UnsupportedOperationException("Invalid increment target");
86
+	}
87
+
88
+	@Override
89
+	public Void visitArray(ArrayExpression expression) {
90
+		throw new UnsupportedOperationException("Invalid increment target");
91
+	}
92
+
93
+	@Override
94
+	public Void visitCompare(BasicCompareExpression expression) {
95
+		throw new UnsupportedOperationException("Invalid increment target");
96
+	}
97
+
98
+	@Override
99
+	public Void visitCall(CallExpression expression) {
100
+		throw new UnsupportedOperationException("Invalid increment target");
101
+	}
102
+
103
+	@Override
104
+	public Void visitCallStatic(CallStaticExpression expression) {
105
+		throw new UnsupportedOperationException("Invalid increment target");
106
+	}
107
+
108
+	@Override
109
+	public Void visitCapturedClosure(CapturedClosureExpression expression) {
110
+		throw new UnsupportedOperationException("Invalid increment target");
111
+	}
112
+
113
+	@Override
114
+	public Void visitCapturedDirect(CapturedDirectExpression expression) {
115
+		throw new UnsupportedOperationException("Invalid increment target");
116
+	}
117
+
118
+	@Override
119
+	public Void visitCapturedLocalVariable(CapturedLocalVariableExpression expression) {
120
+		throw new UnsupportedOperationException("Invalid increment target");
121
+	}
122
+
123
+	@Override
124
+	public Void visitCapturedParameter(CapturedParameterExpression expression) {
125
+		throw new UnsupportedOperationException("Invalid increment target");
126
+	}
127
+
128
+	@Override
129
+	public Void visitCapturedThis(CapturedThisExpression expression) {
130
+		throw new UnsupportedOperationException("Invalid increment target");
131
+	}
132
+
133
+	@Override
134
+	public Void visitCast(CastExpression expression) {
135
+		throw new UnsupportedOperationException("Invalid increment target");
136
+	}
137
+
138
+	@Override
139
+	public Void visitCheckNull(CheckNullExpression expression) {
140
+		throw new UnsupportedOperationException("Invalid increment target");
141
+	}
142
+
143
+	@Override
144
+	public Void visitCoalesce(CoalesceExpression expression) {
145
+		throw new UnsupportedOperationException("Invalid increment target");
146
+	}
147
+
148
+	@Override
149
+	public Void visitConditional(ConditionalExpression expression) {
150
+		throw new UnsupportedOperationException("Invalid increment target");
151
+	}
152
+
153
+	@Override
154
+	public Void visitConstantBool(ConstantBoolExpression expression) {
155
+		throw new UnsupportedOperationException("Invalid increment target");
156
+	}
157
+
158
+	@Override
159
+	public Void visitConstantByte(ConstantByteExpression expression) {
160
+		throw new UnsupportedOperationException("Invalid increment target");
161
+	}
162
+
163
+	@Override
164
+	public Void visitConstantChar(ConstantCharExpression expression) {
165
+		throw new UnsupportedOperationException("Invalid increment target");
166
+	}
167
+
168
+	@Override
169
+	public Void visitConstantDouble(ConstantDoubleExpression expression) {
170
+		throw new UnsupportedOperationException("Invalid increment target");
171
+	}
172
+
173
+	@Override
174
+	public Void visitConstantFloat(ConstantFloatExpression expression) {
175
+		throw new UnsupportedOperationException("Invalid increment target");
176
+	}
177
+
178
+	@Override
179
+	public Void visitConstantInt(ConstantIntExpression expression) {
180
+		throw new UnsupportedOperationException("Invalid increment target");
181
+	}
182
+
183
+	@Override
184
+	public Void visitConstantLong(ConstantLongExpression expression) {
185
+		throw new UnsupportedOperationException("Invalid increment target");
186
+	}
187
+
188
+	@Override
189
+	public Void visitConstantSByte(ConstantSByteExpression expression) {
190
+		throw new UnsupportedOperationException("Invalid increment target");
191
+	}
192
+
193
+	@Override
194
+	public Void visitConstantShort(ConstantShortExpression expression) {
195
+		throw new UnsupportedOperationException("Invalid increment target");
196
+	}
197
+
198
+	@Override
199
+	public Void visitConstantString(ConstantStringExpression expression) {
200
+		throw new UnsupportedOperationException("Invalid increment target");
201
+	}
202
+
203
+	@Override
204
+	public Void visitConstantUInt(ConstantUIntExpression expression) {
205
+		throw new UnsupportedOperationException("Invalid increment target");
206
+	}
207
+
208
+	@Override
209
+	public Void visitConstantULong(ConstantULongExpression expression) {
210
+		throw new UnsupportedOperationException("Invalid increment target");
211
+	}
212
+
213
+	@Override
214
+	public Void visitConstantUShort(ConstantUShortExpression expression) {
215
+		throw new UnsupportedOperationException("Invalid increment target");
216
+	}
217
+
218
+	@Override
219
+	public Void visitConstructorThisCall(ConstructorThisCallExpression expression) {
220
+		throw new UnsupportedOperationException("Invalid increment target");
221
+	}
222
+
223
+	@Override
224
+	public Void visitConstructorSuperCall(ConstructorSuperCallExpression expression) {
225
+		throw new UnsupportedOperationException("Invalid increment target");
226
+	}
227
+
228
+	@Override
229
+	public Void visitEnumConstant(EnumConstantExpression expression) {
230
+		throw new UnsupportedOperationException("Invalid increment target");
231
+	}
232
+
233
+	@Override
234
+	public Void visitFunction(FunctionExpression expression) {
235
+		throw new UnsupportedOperationException("Invalid increment target");
236
+	}
237
+
238
+	@Override
239
+	public Void visitGenericCompare(GenericCompareExpression expression) {
240
+		throw new UnsupportedOperationException("Invalid increment target");
241
+	}
242
+
243
+	@Override
244
+	public Void visitGetField(GetFieldExpression expression) {
245
+		Type objectType = expression.target.type.accept(new JavaTypeVisitor());
246
+		
247
+		int local = javaWriter.local(objectType);
248
+		expression.target.accept(expressionCompiler);
249
+		javaWriter.dup();
250
+		javaWriter.store(objectType, local);
251
+		
252
+        if (!expressionCompiler.checkAndGetFieldInfo(expression.field, false))
253
+            throw new IllegalStateException("Missing field info on a field member!");
254
+		
255
+		javaWriter.iConst1();
256
+		javaWriter.iAdd();
257
+		
258
+		javaWriter.load(objectType, local);
259
+		javaWriter.dupX1();
260
+        if (!expressionCompiler.checkAndPutFieldInfo(expression.field, false))
261
+            throw new IllegalStateException("Missing field info on a field member!");
262
+		
263
+		return null;
264
+	}
265
+
266
+	@Override
267
+	public Void visitGetFunctionParameter(GetFunctionParameterExpression expression) {
268
+		JavaParameterInfo parameter = expression.parameter.getTag(JavaParameterInfo.class);
269
+		javaWriter.iinc(parameter.index);
270
+		javaWriter.load(parameter);
271
+		return null;
272
+	}
273
+
274
+	@Override
275
+	public Void visitGetLocalVariable(GetLocalVariableExpression expression) {
276
+		JavaLocalVariableInfo localVariable = expression.variable.getTag(JavaLocalVariableInfo.class);
277
+		javaWriter.iinc(localVariable.local);
278
+		javaWriter.load(localVariable);
279
+		return null;
280
+	}
281
+
282
+	@Override
283
+	public Void visitGetStaticField(GetStaticFieldExpression expression) {
284
+		if (!expressionCompiler.checkAndGetFieldInfo(expression.field, false))
285
+            throw new IllegalStateException("Missing field info on a field member!");
286
+		
287
+		javaWriter.iConst1();
288
+		javaWriter.iAdd();
289
+		javaWriter.dup();
290
+		
291
+		if (!expressionCompiler.checkAndPutFieldInfo(expression.field, false))
292
+            throw new IllegalStateException("Missing field info on a field member!");
293
+		
294
+		return null;
295
+	}
296
+
297
+	@Override
298
+	public Void visitGetter(GetterExpression expression) {
299
+		throw new UnsupportedOperationException("Not yet supported");
300
+	}
301
+
302
+	@Override
303
+	public Void visitGlobal(GlobalExpression expression) {
304
+		throw new UnsupportedOperationException("Invalid increment target");
305
+	}
306
+
307
+	@Override
308
+	public Void visitGlobalCall(GlobalCallExpression expression) {
309
+		throw new UnsupportedOperationException("Invalid increment target");
310
+	}
311
+
312
+	@Override
313
+	public Void visitInterfaceCast(InterfaceCastExpression expression) {
314
+		throw new UnsupportedOperationException("Invalid increment target");
315
+	}
316
+
317
+	@Override
318
+	public Void visitIs(IsExpression expression) {
319
+		throw new UnsupportedOperationException("Invalid increment target");
320
+	}
321
+
322
+	@Override
323
+	public Void visitMakeConst(MakeConstExpression expression) {
324
+		throw new UnsupportedOperationException("Invalid increment target");
325
+	}
326
+
327
+	@Override
328
+	public Void visitMap(MapExpression expression) {
329
+		throw new UnsupportedOperationException("Invalid increment target");
330
+	}
331
+
332
+	@Override
333
+	public Void visitNew(NewExpression expression) {
334
+		throw new UnsupportedOperationException("Invalid increment target");
335
+	}
336
+
337
+	@Override
338
+	public Void visitNull(NullExpression expression) {
339
+		throw new UnsupportedOperationException("Invalid increment target");
340
+	}
341
+
342
+	@Override
343
+	public Void visitOrOr(OrOrExpression expression) {
344
+		throw new UnsupportedOperationException("Invalid increment target");
345
+	}
346
+
347
+	@Override
348
+	public Void visitPostCall(PostCallExpression expression) {
349
+		throw new UnsupportedOperationException("Invalid increment target");
350
+	}
351
+
352
+	@Override
353
+	public Void visitRange(RangeExpression expression) {
354
+		throw new UnsupportedOperationException("Invalid increment target");
355
+	}
356
+
357
+	@Override
358
+	public Void visitSetField(SetFieldExpression expression) {
359
+		throw new UnsupportedOperationException("Invalid increment target");
360
+	}
361
+
362
+	@Override
363
+	public Void visitSetFunctionParameter(SetFunctionParameterExpression expression) {
364
+		throw new UnsupportedOperationException("Invalid increment target");
365
+	}
366
+
367
+	@Override
368
+	public Void visitSetLocalVariable(SetLocalVariableExpression expression) {
369
+		throw new UnsupportedOperationException("Invalid increment target");
370
+	}
371
+
372
+	@Override
373
+	public Void visitSetStaticField(SetStaticFieldExpression expression) {
374
+		throw new UnsupportedOperationException("Invalid increment target");
375
+	}
376
+
377
+	@Override
378
+	public Void visitSetter(SetterExpression expression) {
379
+		throw new UnsupportedOperationException("Invalid increment target");
380
+	}
381
+
382
+	@Override
383
+	public Void visitStaticGetter(StaticGetterExpression expression) {
384
+		throw new UnsupportedOperationException("Invalid increment target");
385
+	}
386
+
387
+	@Override
388
+	public Void visitStaticSetter(StaticSetterExpression expression) {
389
+		throw new UnsupportedOperationException("Invalid increment target");
390
+	}
391
+
392
+	@Override
393
+	public Void visitThis(ThisExpression expression) {
394
+		throw new UnsupportedOperationException("Invalid increment target");
395
+	}
396
+
397
+	@Override
398
+	public Void visitWrapOptional(WrapOptionalExpression expression) {
399
+		throw new UnsupportedOperationException("Invalid increment target");
400
+	}
401
+}

+ 5
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java Переглянути файл

@@ -134,6 +134,11 @@ public class JavaStatementVisitor implements StatementVisitor<Boolean> {
134 134
         javaWriter.returnType(Type.getType(statement.value.type.accept(JavaTypeClassVisitor.INSTANCE)));
135 135
         return true;
136 136
     }
137
+	
138
+	@Override
139
+	public Boolean visitSwitch(SwitchStatement statement) {
140
+		throw new UnsupportedOperationException("Not yet implemented!");
141
+	}
137 142
 
138 143
     @Override
139 144
     public Boolean visitThrow(ThrowStatement statement) {

+ 5
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaTypeClassVisitor.java Переглянути файл

@@ -90,4 +90,9 @@ public class JavaTypeClassVisitor implements ITypeVisitor<Class> {
90 90
     public Class visitOptional(OptionalTypeID optional) {
91 91
         return optional.baseType.accept(this.optional);
92 92
     }
93
+
94
+	@Override
95
+	public Class visitGenericMap(GenericMapTypeID map) {
96
+		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
97
+	}
93 98
 }

+ 5
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaTypeVisitor.java Переглянути файл

@@ -55,4 +55,9 @@ public class JavaTypeVisitor implements ITypeVisitor<Type> {
55 55
     public Type visitOptional(OptionalTypeID optional) {
56 56
         return Type.getType(optional.accept(JavaTypeClassVisitor.INSTANCE));
57 57
     }
58
+
59
+	@Override
60
+	public Type visitGenericMap(GenericMapTypeID map) {
61
+		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
62
+	}
58 63
 }

+ 40
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java Переглянути файл

@@ -15,6 +15,7 @@ import static org.objectweb.asm.Opcodes.*;
15 15
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
16 16
 import org.openzen.zenscript.javabytecode.JavaClassInfo;
17 17
 import org.openzen.zenscript.javabytecode.JavaMethodInfo;
18
+import org.openzen.zenscript.javabytecode.JavaParameterInfo;
18 19
 
19 20
 public class JavaWriter {
20 21
 	private static final JavaClassInfo T_STRING = new JavaClassInfo("java/lang/String");
@@ -173,6 +174,13 @@ public class JavaWriter {
173 174
 
174 175
         visitor.visitInsn(DUP);
175 176
     }
177
+	
178
+	public void dup(Type type) {
179
+        if (debug)
180
+            System.out.println("dup");
181
+		
182
+		visitor.visitInsn(type.getSize() == 2 ? DUP2 : DUP);
183
+	}
176 184
 
177 185
     public void dup(boolean large) {
178 186
         if (debug)
@@ -229,6 +237,34 @@ public class JavaWriter {
229 237
 
230 238
         visitor.visitVarInsn(type.getOpcode(ILOAD), local);
231 239
     }
240
+	
241
+	public void load(JavaParameterInfo parameter) {
242
+        if (debug)
243
+            System.out.println("load " + parameter.index);
244
+
245
+        visitor.visitVarInsn(parameter.type.getOpcode(ILOAD), parameter.index);
246
+	}
247
+	
248
+	public void load(JavaLocalVariableInfo localVariable) {
249
+        if (debug)
250
+            System.out.println("load " + localVariable.local);
251
+
252
+        visitor.visitVarInsn(localVariable.type.getOpcode(ILOAD), localVariable.local);
253
+	}
254
+	
255
+	public void store(JavaParameterInfo parameter) {
256
+        if (debug)
257
+            System.out.println("store " + parameter.index);
258
+
259
+        visitor.visitVarInsn(parameter.type.getOpcode(ISTORE), parameter.index);
260
+	}
261
+	
262
+	public void store(JavaLocalVariableInfo localVariable) {
263
+        if (debug)
264
+            System.out.println("store " + localVariable.local);
265
+
266
+        visitor.visitVarInsn(localVariable.type.getOpcode(ISTORE), localVariable.local);
267
+	}
232 268
 
233 269
     public void storeInt(int local) {
234 270
         if (debug)
@@ -605,6 +641,10 @@ public class JavaWriter {
605 641
     public void iinc(int local) {
606 642
         iinc(local, 1);
607 643
     }
644
+	
645
+	public void idec(int local) {
646
+		iinc(local, -1);
647
+	}
608 648
 
609 649
     public void iinc(int local, int increment) {
610 650
         if (debug)

+ 6
- 2
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaDefinitionVisitor.java Переглянути файл

@@ -56,9 +56,11 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
56 56
 
57 57
 
58 58
         writer.visit(Opcodes.V1_8, definition.modifiers, definition.name, signature, superType.getInternalName(), null);
59
+		JavaMemberVisitor memberVisitor = new JavaMemberVisitor(writer, toClass, definition); 
59 60
         for (IDefinitionMember member : definition.members) {
60
-            member.accept(new JavaMemberVisitor(writer, toClass, definition));
61
+            member.accept(memberVisitor);
61 62
         }
63
+		memberVisitor.end();
62 64
         writer.visitEnd();
63 65
         return writer.toByteArray();
64 66
     }
@@ -72,9 +74,11 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
72 74
         //TODO: Extending Interfaces?
73 75
         String signature = null;
74 76
         writer.visit(Opcodes.V1_8, definition.modifiers | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT, definition.name, signature, Type.getInternalName(Object.class), null);
77
+		JavaMemberVisitor memberVisitor = new JavaMemberVisitor(writer, toClass, definition);
75 78
         for (IDefinitionMember member : definition.members) {
76
-            member.accept(new JavaMemberVisitor(writer, toClass, definition));
79
+            member.accept(memberVisitor);
77 80
         }
81
+		memberVisitor.end();
78 82
         writer.visitEnd();
79 83
         return writer.toByteArray();
80 84
     }

+ 32
- 4
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaMemberVisitor.java Переглянути файл

@@ -1,5 +1,7 @@
1 1
 package org.openzen.zenscript.javabytecode.compiler.definitions;
2 2
 
3
+import java.util.ArrayList;
4
+import java.util.List;
3 5
 import org.objectweb.asm.ClassWriter;
4 6
 import org.objectweb.asm.Label;
5 7
 import org.objectweb.asm.Opcodes;
@@ -20,6 +22,7 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
20 22
     private final ClassWriter writer;
21 23
 	private final JavaClassInfo toClass;
22 24
 	private final HighLevelDefinition definition;
25
+	private final List<StaticInitializerMember> staticInitializers = new ArrayList<>();
23 26
 
24 27
     public JavaMemberVisitor(ClassWriter writer, JavaClassInfo toClass, HighLevelDefinition definition) {
25 28
         this.writer = writer;
@@ -40,9 +43,7 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
40 43
 
41 44
     @Override
42 45
     public Void visitConstructor(ConstructorMember member) {
43
-		System.out.println("Compiling constructor " + member.header.toString());
44
-		
45
-        final boolean isEnum = definition instanceof EnumDefinition;
46
+		final boolean isEnum = definition instanceof EnumDefinition;
46 47
 		String descriptor = CompilerUtils.calcDesc(member.header, isEnum);
47 48
 		final JavaMethodInfo method = new JavaMethodInfo(toClass, "<init>", descriptor, isEnum ? Opcodes.ACC_PRIVATE : CompilerUtils.calcAccess(member.modifiers));
48 49
 		
@@ -78,7 +79,7 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
78 79
 				constructorWriter.invokeSpecial(Type.getInternalName(Object.class), "<init>", "()V");
79 80
 			}
80 81
 			
81
-			CompilerUtils.writeDefaultFieldInitializers(constructorWriter, definition);
82
+			CompilerUtils.writeDefaultFieldInitializers(constructorWriter, definition, false);
82 83
 		}
83 84
 		
84 85
         member.body.accept(statementVisitor);
@@ -168,4 +169,31 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
168 169
     public Void visitInnerDefinition(InnerDefinitionMember member) {
169 170
         return null;
170 171
     }
172
+
173
+	@Override
174
+	public Void visitStaticInitializer(StaticInitializerMember member) {
175
+		staticInitializers.add(member);
176
+		return null;
177
+	}
178
+	
179
+	public void end() {
180
+		final JavaMethodInfo method = new JavaMethodInfo(toClass, "<clinit>", "()V", 0);
181
+		
182
+        final Label constructorStart = new Label();
183
+        final Label constructorEnd = new Label();
184
+        final JavaWriter constructorWriter = new JavaWriter(writer, method, definition, null, null);
185
+        constructorWriter.label(constructorStart);
186
+		
187
+        final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(constructorWriter);
188
+        statementVisitor.start();
189
+		
190
+		CompilerUtils.writeDefaultFieldInitializers(constructorWriter, definition, true);
191
+		
192
+		for (StaticInitializerMember member : staticInitializers) {
193
+	        member.body.accept(statementVisitor);
194
+		}
195
+		
196
+        constructorWriter.label(constructorEnd);
197
+        statementVisitor.end();
198
+	}
171 199
 }

+ 3
- 0
Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenStream.java Переглянути файл

@@ -83,6 +83,9 @@ public class ZSTokenStream extends TokenStream<ZSToken, ZSTokenType> {
83 83
 		KEYWORDS.put("return", K_RETURN);
84 84
 		KEYWORDS.put("break", K_BREAK);
85 85
 		KEYWORDS.put("continue", K_CONTINUE);
86
+		KEYWORDS.put("switch", K_SWITCH);
87
+		KEYWORDS.put("case", K_CASE);
88
+		KEYWORDS.put("default", K_DEFAULT);
86 89
 		
87 90
 		KEYWORDS.put("in", K_IN);
88 91
 		KEYWORDS.put("is", K_IS);

+ 8
- 0
Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenType.java Переглянути файл

@@ -56,9 +56,14 @@ public enum ZSTokenType implements TokenType {
56 56
 	T_BRCLOSE("\\)"),
57 57
 	T_SEMICOLON(";"),
58 58
 	T_LESSEQ("<="),
59
+	T_SHLASSIGN("<<="),
59 60
 	T_SHL("<<"),
60 61
 	T_LESS("<"),
61 62
 	T_GREATEREQ(">="),
63
+	T_USHR(">>>"),
64
+	T_USHRASSIGN(">>>="),
65
+	T_SHRASSIGN(">>="),
66
+	T_SHR(">>"),
62 67
 	T_GREATER(">"),
63 68
 	T_LAMBDA("=>"),
64 69
 	T_EQUAL3("==="),
@@ -128,6 +133,9 @@ public enum ZSTokenType implements TokenType {
128 133
 	K_RETURN,
129 134
 	K_BREAK,
130 135
 	K_CONTINUE,
136
+	K_SWITCH,
137
+	K_CASE,
138
+	K_DEFAULT,
131 139
 	
132 140
 	K_IN,
133 141
 	K_IS,

+ 5
- 1
Parser/src/main/java/org/openzen/zenscript/parser/ParsedDefinition.java Переглянути файл

@@ -38,7 +38,7 @@ public abstract class ParsedDefinition {
38 38
 		} else if (tokens.optional(K_ENUM) != null) {
39 39
 			return ParsedEnum.parseEnum(pkg, position, modifiers, tokens, outerDefinition);
40 40
 		} else if (tokens.optional(K_STRUCT) != null) {
41
-			return ParsedStruct.parse(pkg, position, modifiers, tokens, outerDefinition);
41
+			return ParsedStruct.parseStruct(pkg, position, modifiers, tokens, outerDefinition);
42 42
 		} else if (tokens.optional(K_ALIAS) != null) {
43 43
 			return ParsedAlias.parseAlias(pkg, position, modifiers, tokens, outerDefinition);
44 44
 		} else if (tokens.optional(K_FUNCTION) != null) {
@@ -71,6 +71,10 @@ public abstract class ParsedDefinition {
71 71
 	
72 72
 	public abstract void linkInnerTypes();
73 73
 	
74
+	public void compileTypes(BaseScope scope) {
75
+		
76
+	}
77
+	
74 78
 	public abstract void compileMembers(BaseScope scope);
75 79
 	
76 80
 	public abstract void compileCode(BaseScope scope);

+ 13
- 0
Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java Переглянути файл

@@ -145,6 +145,19 @@ public class ParsedFile {
145 145
 		}
146 146
 	}
147 147
 	
148
+	public void compileTypes(
149
+			ZSPackage rootPackage,
150
+			PackageDefinitions packageDefinitions,
151
+			GlobalTypeRegistry globalRegistry,
152
+			List<ExpansionDefinition> expansions,
153
+			Map<String, ISymbol> globalSymbols) {
154
+		FileScope scope = new FileScope(access, rootPackage, packageDefinitions, globalRegistry, expansions, globalSymbols);
155
+		loadImports(scope, rootPackage);
156
+		for (ParsedDefinition definition : this.definitions) {
157
+			definition.compileTypes(scope);
158
+		}
159
+	}
160
+	
148 161
 	public void compileMembers(
149 162
 			ZSPackage rootPackage,
150 163
 			PackageDefinitions packageDefinitions,

+ 2
- 3
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedExpansion.java Переглянути файл

@@ -12,6 +12,7 @@ import org.openzen.zenscript.codemodel.definition.ZSPackage;
12 12
 import org.openzen.zenscript.lexer.ZSTokenStream;
13 13
 import org.openzen.zenscript.lexer.ZSTokenType;
14 14
 import org.openzen.zenscript.linker.BaseScope;
15
+import org.openzen.zenscript.linker.DefinitionScope;
15 16
 import org.openzen.zenscript.linker.GenericFunctionScope;
16 17
 import org.openzen.zenscript.parser.member.ParsedDefinitionMember;
17 18
 import org.openzen.zenscript.parser.type.IParsedType;
@@ -54,10 +55,8 @@ public class ParsedExpansion extends BaseParsedDefinition {
54 55
 	}
55 56
 
56 57
 	@Override
57
-	public void compileMembers(BaseScope scope) {
58
+	public void compileTypes(BaseScope scope) {
58 59
 		ParsedGenericParameter.compile(scope, compiled.genericParameters, this.parameters);
59 60
 		compiled.target = target.compile(new GenericFunctionScope(scope, compiled.genericParameters));
60
-		
61
-		super.compileMembers(scope);
62 61
 	}
63 62
 }

+ 45
- 15
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpression.java Переглянути файл

@@ -75,6 +75,15 @@ public abstract class ParsedExpression {
75 75
 			case T_XORASSIGN:
76 76
 				parser.next();
77 77
 				return new ParsedExpressionOpAssign(position, left, readAssignExpression(parser), OperatorType.XORASSIGN);
78
+			case T_SHLASSIGN:
79
+				parser.next();
80
+				return new ParsedExpressionOpAssign(position, left, readAssignExpression(parser), OperatorType.SHLASSIGN);
81
+			case T_SHRASSIGN:
82
+				parser.next();
83
+				return new ParsedExpressionOpAssign(position, left, readAssignExpression(parser), OperatorType.SHRASSIGN);
84
+			case T_USHRASSIGN:
85
+				parser.next();
86
+				return new ParsedExpressionOpAssign(position, left, readAssignExpression(parser), OperatorType.USHRASSIGN);
78 87
 		}
79 88
 
80 89
 		return left;
@@ -150,52 +159,52 @@ public abstract class ParsedExpression {
150 159
 	}
151 160
 
152 161
 	private static ParsedExpression readCompareExpression(CodePosition position, ZSTokenStream parser) {
153
-		ParsedExpression left = readAddExpression(position, parser);
162
+		ParsedExpression left = readShiftExpression(position, parser);
154 163
 
155 164
 		switch (parser.peek().getType()) {
156 165
 			case T_EQUAL2: {
157 166
 				parser.next();
158
-				ParsedExpression right = readAddExpression(parser.peek().position, parser);
167
+				ParsedExpression right = readShiftExpression(parser.peek().position, parser);
159 168
 				return new ParsedExpressionCompare(position, left, right, CompareType.EQ);
160 169
 			}
161 170
 			case T_EQUAL3: {
162 171
 				parser.next();
163
-				ParsedExpression right = readAddExpression(parser.peek().position, parser);
172
+				ParsedExpression right = readShiftExpression(parser.peek().position, parser);
164 173
 				return new ParsedExpressionCompare(position, left, right, CompareType.SAME);
165 174
 			}
166 175
 			case T_NOTEQUAL: {
167 176
 				parser.next();
168
-				ParsedExpression right = readAddExpression(parser.peek().position, parser);
177
+				ParsedExpression right = readShiftExpression(parser.peek().position, parser);
169 178
 				return new ParsedExpressionCompare(position, left, right, CompareType.NE);
170 179
 			}
171 180
 			case T_NOTEQUAL2: {
172 181
 				parser.next();
173
-				ParsedExpression right = readAddExpression(parser.peek().position, parser);
182
+				ParsedExpression right = readShiftExpression(parser.peek().position, parser);
174 183
 				return new ParsedExpressionCompare(position, left, right, CompareType.NOTSAME);
175 184
 			}
176 185
 			case T_LESS: {
177 186
 				parser.next();
178
-				ParsedExpression right = readAddExpression(parser.peek().position, parser);
187
+				ParsedExpression right = readShiftExpression(parser.peek().position, parser);
179 188
 				return new ParsedExpressionCompare(position, left, right, CompareType.LT);
180 189
 			}
181 190
 			case T_LESSEQ: {
182 191
 				parser.next();
183
-				ParsedExpression right = readAddExpression(parser.peek().position, parser);
192
+				ParsedExpression right = readShiftExpression(parser.peek().position, parser);
184 193
 				return new ParsedExpressionCompare(position, left, right, CompareType.LE);
185 194
 			}
186 195
 			case T_GREATER: {
187 196
 				parser.next();
188
-				ParsedExpression right = readAddExpression(parser.peek().position, parser);
197
+				ParsedExpression right = readShiftExpression(parser.peek().position, parser);
189 198
 				return new ParsedExpressionCompare(position, left, right, CompareType.GT);
190 199
 			}
191 200
 			case T_GREATEREQ: {
192 201
 				parser.next();
193
-				ParsedExpression right = readAddExpression(parser.peek().position, parser);
202
+				ParsedExpression right = readShiftExpression(parser.peek().position, parser);
194 203
 				return new ParsedExpressionCompare(position, left, right, CompareType.GE);
195 204
 			}
196 205
 			case K_IN: {
197 206
 				parser.next();
198
-				ParsedExpression right = readAddExpression(parser.peek().position, parser);
207
+				ParsedExpression right = readShiftExpression(parser.peek().position, parser);
199 208
 				return new ParsedExpressionBinary(position, right, left, OperatorType.CONTAINS);
200 209
 			}
201 210
 			case K_IS: {
@@ -206,7 +215,7 @@ public abstract class ParsedExpression {
206 215
 			case T_NOT: {
207 216
 				parser.next();
208 217
 				if (parser.optional(K_IN) != null) {
209
-					ParsedExpression right = readAddExpression(parser.peek().position, parser);
218
+					ParsedExpression right = readShiftExpression(parser.peek().position, parser);
210 219
 					return new ParsedExpressionUnary(position, new ParsedExpressionBinary(position, right, left, OperatorType.CONTAINS), OperatorType.NOT);
211 220
 				} else if (parser.optional(K_IS) != null) {
212 221
 					IParsedType type = IParsedType.parse(parser);
@@ -219,6 +228,27 @@ public abstract class ParsedExpression {
219 228
 
220 229
 		return left;
221 230
 	}
231
+	
232
+	private static ParsedExpression readShiftExpression(CodePosition position, ZSTokenStream parser) {
233
+		ParsedExpression left = readAddExpression(position, parser);
234
+		
235
+		while (true) {
236
+			if (parser.optional(T_SHL) != null) {
237
+				ParsedExpression right = readAddExpression(parser.peek().position, parser);
238
+				left = new ParsedExpressionBinary(position, left, right, OperatorType.SHL);
239
+			} else if (parser.optional(T_SHR) != null) {
240
+				ParsedExpression right = readAddExpression(parser.peek().position, parser);
241
+				left = new ParsedExpressionBinary(position, left, right, OperatorType.SHR);
242
+			} else if (parser.optional(T_USHR) != null) {
243
+				ParsedExpression right = readAddExpression(parser.peek().position, parser);
244
+				left = new ParsedExpressionBinary(position, left, right, OperatorType.USHR);
245
+			} else {
246
+				break;
247
+			}
248
+		}
249
+		
250
+		return left;
251
+	}
222 252
 
223 253
 	private static ParsedExpression readAddExpression(CodePosition position, ZSTokenStream parser) {
224 254
 		ParsedExpression left = readMulExpression(position, parser);
@@ -286,13 +316,13 @@ public abstract class ParsedExpression {
286 316
 				return new ParsedExpressionUnary(
287 317
 						position,
288 318
 						readUnaryExpression(parser.peek().position, parser),
289
-						OperatorType.PRE_INCREMENT);
319
+						OperatorType.INCREMENT);
290 320
 			case T_DECREMENT:
291 321
 				parser.next();
292 322
 				return new ParsedExpressionUnary(
293 323
 						position,
294 324
 						readUnaryExpression(parser.peek().position, parser),
295
-						OperatorType.PRE_DECREMENT);
325
+						OperatorType.DECREMENT);
296 326
 			default:
297 327
 				return readPostfixExpression(position, parser);
298 328
 		}
@@ -338,9 +368,9 @@ public abstract class ParsedExpression {
338 368
 				IParsedType type = IParsedType.parse(parser);
339 369
 				base = new ParsedExpressionCast(position, base, type, optional);
340 370
 			} else if (parser.optional(T_INCREMENT) != null) {
341
-				base = new ParsedExpressionUnary(position, base, OperatorType.POST_INCREMENT);
371
+				base = new ParsedExpressionPostCall(position, base, OperatorType.INCREMENT);
342 372
 			} else if (parser.optional(T_DECREMENT) != null) {
343
-				base = new ParsedExpressionUnary(position, base, OperatorType.POST_DECREMENT);
373
+				base = new ParsedExpressionPostCall(position, base, OperatorType.DECREMENT);
344 374
 			} else if (parser.optional(T_LAMBDA) != null) {
345 375
 				ParsedFunctionBody body = ParsedStatement.parseLambdaBody(parser, true);
346 376
 				base = new ParsedExpressionFunction(position, base.toLambdaHeader(), body);

+ 12
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionMap.java Переглянути файл

@@ -8,11 +8,17 @@ package org.openzen.zenscript.parser.expression;
8 8
 
9 9
 import java.util.ArrayList;
10 10
 import java.util.List;
11
+import org.openzen.zenscript.codemodel.OperatorType;
12
+import org.openzen.zenscript.codemodel.expression.CallArguments;
11 13
 import org.openzen.zenscript.codemodel.expression.Expression;
12 14
 import org.openzen.zenscript.codemodel.expression.MapExpression;
15
+import org.openzen.zenscript.codemodel.expression.NewExpression;
16
+import org.openzen.zenscript.codemodel.member.ConstructorMember;
17
+import org.openzen.zenscript.codemodel.member.ICallableMember;
13 18
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14 19
 import org.openzen.zenscript.codemodel.type.AssocTypeID;
15 20
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
21
+import org.openzen.zenscript.codemodel.type.GenericMapTypeID;
16 22
 import org.openzen.zenscript.codemodel.type.ITypeID;
17 23
 import org.openzen.zenscript.linker.ExpressionScope;
18 24
 import org.openzen.zenscript.shared.CodePosition;
@@ -52,6 +58,12 @@ public class ParsedExpressionMap extends ParsedExpression {
52 58
 					valueHints.add(assocHint.valueType);
53 59
 				
54 60
 				hasAssocHint = true;
61
+			} else if (hint instanceof GenericMapTypeID) {
62
+				ICallableMember constructor = scope
63
+						.getTypeMembers(hint)
64
+						.getOrCreateGroup(OperatorType.CONSTRUCTOR)
65
+						.selectMethod(position, scope, CallArguments.EMPTY, true, true);
66
+				return new NewExpression(position, hint, (ConstructorMember) constructor, CallArguments.EMPTY);
55 67
 			}
56 68
 		}
57 69
 		

+ 42
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionPostCall.java Переглянути файл

@@ -0,0 +1,42 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+
7
+package org.openzen.zenscript.parser.expression;
8
+
9
+import org.openzen.zenscript.codemodel.OperatorType;
10
+import org.openzen.zenscript.codemodel.expression.CallArguments;
11
+import org.openzen.zenscript.codemodel.expression.CallExpression;
12
+import org.openzen.zenscript.codemodel.expression.Expression;
13
+import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14
+import org.openzen.zenscript.linker.ExpressionScope;
15
+import org.openzen.zenscript.shared.CodePosition;
16
+
17
+/**
18
+ *
19
+ * @author Stanneke
20
+ */
21
+public class ParsedExpressionPostCall extends ParsedExpression {
22
+	private final ParsedExpression value;
23
+	private final OperatorType operator;
24
+
25
+	public ParsedExpressionPostCall(CodePosition position, ParsedExpression value, OperatorType operator) {
26
+		super(position);
27
+
28
+		this.value = value;
29
+		this.operator = operator;
30
+	}
31
+
32
+	@Override
33
+	public IPartialExpression compile(ExpressionScope scope) {
34
+		Expression cValue = value.compile(scope).eval();
35
+		return scope.getTypeMembers(cValue.getType()).getOrCreateGroup(operator).callPostfix(position, scope, cValue);
36
+	}
37
+
38
+	@Override
39
+	public boolean hasStrongType() {
40
+		return value.hasStrongType();
41
+	}
42
+}

+ 79
- 29
Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedDefinitionMember.java Переглянути файл

@@ -16,12 +16,14 @@ import org.openzen.zenscript.codemodel.HighLevelDefinition;
16 16
 import org.openzen.zenscript.codemodel.Modifiers;
17 17
 import org.openzen.zenscript.codemodel.OperatorType;
18 18
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
19
+import org.openzen.zenscript.codemodel.member.StaticInitializerMember;
19 20
 import org.openzen.zenscript.lexer.ZSToken;
20 21
 import org.openzen.zenscript.lexer.ZSTokenStream;
21 22
 import org.openzen.zenscript.lexer.ZSTokenType;
22 23
 import org.openzen.zenscript.linker.BaseScope;
23 24
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
24 25
 import org.openzen.zenscript.parser.statements.ParsedStatement;
26
+import org.openzen.zenscript.parser.statements.ParsedStatementBlock;
25 27
 import org.openzen.zenscript.parser.type.IParsedType;
26 28
 import org.openzen.zenscript.parser.type.ParsedTypeBasic;
27 29
 import org.openzen.zenscript.shared.CodePosition;
@@ -34,31 +36,54 @@ public abstract class ParsedDefinitionMember {
34 36
 	public static ParsedDefinitionMember parse(ZSTokenStream tokens, HighLevelDefinition forDefinition) {
35 37
 		CodePosition start = tokens.getPosition();
36 38
 		int modifiers = 0;
37
-		while (true) {
38
-			if (tokens.optional(ZSTokenType.K_EXPORT) != null) {
39
-				modifiers |= Modifiers.EXPORT;
40
-			} else if (tokens.optional(ZSTokenType.K_PUBLIC) != null) {
41
-				modifiers |= Modifiers.PUBLIC;
42
-			} else if (tokens.optional(ZSTokenType.K_PRIVATE) != null) {
43
-				modifiers |= Modifiers.PRIVATE;
44
-			} else if (tokens.optional(ZSTokenType.K_CONST) != null) {
45
-				if (tokens.optional(ZSTokenType.T_QUEST) != null) {
46
-					modifiers |= Modifiers.CONST_OPTIONAL;
47
-				} else {
48
-					modifiers |= Modifiers.CONST;
49
-				}
50
-			} else if (tokens.optional(ZSTokenType.K_ABSTRACT) != null) {
51
-				modifiers |= Modifiers.ABSTRACT;
52
-			} else if (tokens.optional(ZSTokenType.K_FINAL) != null) {
53
-				modifiers |= Modifiers.FINAL;
54
-			} else if (tokens.optional(ZSTokenType.K_STATIC) != null) {
55
-				modifiers |= Modifiers.STATIC;
56
-			} else if (tokens.optional(ZSTokenType.K_PROTECTED) != null) {
57
-				modifiers |= Modifiers.PROTECTED;
58
-			} else if (tokens.optional(ZSTokenType.K_IMPLICIT) != null) {
59
-				modifiers |= Modifiers.IMPLICIT;
60
-			} else {
61
-				break;
39
+		outer: while (true) {
40
+			switch (tokens.peek().type) {
41
+				case K_EXPORT:
42
+					tokens.next();
43
+					modifiers |= Modifiers.EXPORT;
44
+					break;
45
+				case K_PUBLIC:
46
+					tokens.next();
47
+					modifiers |= Modifiers.PUBLIC;
48
+					break;
49
+				case K_PRIVATE:
50
+					tokens.next();
51
+					modifiers |= Modifiers.PRIVATE;
52
+					break;
53
+				case K_CONST:
54
+					tokens.next();
55
+					if (tokens.optional(ZSTokenType.T_QUEST) != null) {
56
+						modifiers |= Modifiers.CONST_OPTIONAL;
57
+					} else {
58
+						modifiers |= Modifiers.CONST;
59
+					}
60
+					break;
61
+				case K_ABSTRACT:
62
+					tokens.next();
63
+					modifiers |= Modifiers.ABSTRACT;
64
+					break;
65
+				case K_FINAL:
66
+					tokens.next();
67
+					modifiers |= Modifiers.FINAL;
68
+					break;
69
+				case K_STATIC:
70
+					tokens.next();
71
+					modifiers |= Modifiers.STATIC;
72
+					break;
73
+				case K_PROTECTED:
74
+					tokens.next();
75
+					modifiers |= Modifiers.PROTECTED;
76
+					break;
77
+				case K_IMPLICIT:
78
+					tokens.next();
79
+					modifiers |= Modifiers.IMPLICIT;
80
+					break;
81
+				case K_EXTERN:
82
+					tokens.next();
83
+					modifiers |= Modifiers.EXTERN;
84
+					break;
85
+				default:
86
+					break outer;
62 87
 			}
63 88
 		}
64 89
 		
@@ -72,11 +97,30 @@ public abstract class ParsedDefinitionMember {
72 97
 					type = IParsedType.parse(tokens);
73 98
 				}
74 99
 				ParsedExpression initializer = null;
100
+				int autoGetter = 0;
101
+				int autoSetter = 0;
102
+				if (tokens.optional(ZSTokenType.T_COLON) != null) {
103
+					do {
104
+						int accessor = Modifiers.PUBLIC;
105
+						if (tokens.optional(ZSTokenType.K_PUBLIC) != null) {
106
+							accessor = Modifiers.PUBLIC;
107
+						} else if (tokens.optional(ZSTokenType.K_PROTECTED) != null) {
108
+							accessor = Modifiers.PROTECTED;
109
+						}
110
+
111
+						if (tokens.optional(ZSTokenType.K_GET) != null) {
112
+							autoGetter = accessor;
113
+						} else {
114
+							tokens.required(ZSTokenType.K_SET, "get or set expected");
115
+							autoSetter = accessor;
116
+						}
117
+					} while (tokens.optional(ZSTokenType.T_COMMA) != null);
118
+				}
75 119
 				if (tokens.optional(ZSTokenType.T_ASSIGN) != null) {
76 120
 					initializer = ParsedExpression.parse(tokens);
77 121
 				}
78 122
 				tokens.required(ZSTokenType.T_SEMICOLON, "; expected");
79
-				return new ParsedField(start, forDefinition, modifiers, name, type, initializer, t.type == ZSTokenType.K_VAL);
123
+				return new ParsedField(start, forDefinition, modifiers, name, type, initializer, t.type == ZSTokenType.K_VAL, autoGetter, autoSetter);
80 124
 			}
81 125
 			case K_THIS: {
82 126
 				tokens.next();
@@ -160,7 +204,8 @@ public abstract class ParsedDefinitionMember {
160 204
 			case T_ORASSIGN:
161 205
 			case T_XORASSIGN:
162 206
 			case T_INCREMENT:
163
-			case T_DECREMENT: {
207
+			case T_DECREMENT:
208
+			case T_DOT2: {
164 209
 				ZSToken token = tokens.next();
165 210
 				ParsedFunctionHeader header = ParsedFunctionHeader.parse(tokens);
166 211
 				ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
@@ -197,6 +242,10 @@ public abstract class ParsedDefinitionMember {
197 242
 				return new ParsedIterator(start, forDefinition, modifiers, header, body);
198 243
 			}
199 244
 			default:
245
+				if (modifiers == Modifiers.STATIC && tokens.peek().type == ZSTokenType.T_AOPEN) {
246
+					ParsedStatementBlock body = ParsedStatementBlock.parseBlock(tokens, true);
247
+					return new ParsedStaticInitializer(forDefinition, tokens.peek().position, body);
248
+				}
200 249
 				throw new CompileException(tokens.peek().position, CompileExceptionCode.UNEXPECTED_TOKEN, "Unexpected token: " + tokens.peek().content);
201 250
 		}
202 251
 	}
@@ -222,8 +271,9 @@ public abstract class ParsedDefinitionMember {
222 271
 			case T_ANDASSIGN: return OperatorType.ANDASSIGN;
223 272
 			case T_ORASSIGN: return OperatorType.ORASSIGN;
224 273
 			case T_XORASSIGN: return OperatorType.XORASSIGN;
225
-			case T_INCREMENT: return OperatorType.POST_INCREMENT;
226
-			case T_DECREMENT: return OperatorType.POST_DECREMENT;
274
+			case T_INCREMENT: return OperatorType.INCREMENT;
275
+			case T_DECREMENT: return OperatorType.DECREMENT;
276
+			case T_DOT2: return OperatorType.RANGE;
227 277
 			default:
228 278
 				throw new AssertionError("Missing switch case in getOperator");
229 279
 		}

+ 8
- 1
Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedField.java Переглянути файл

@@ -27,6 +27,9 @@ public class ParsedField extends ParsedDefinitionMember {
27 27
 	private final ParsedExpression expression;
28 28
 	private final boolean isFinal;
29 29
 	
30
+	private final int autoGetter;
31
+	private final int autoSetter;
32
+	
30 33
 	private FieldMember compiled;
31 34
 	
32 35
 	public ParsedField(
@@ -36,7 +39,9 @@ public class ParsedField extends ParsedDefinitionMember {
36 39
 			String name,
37 40
 			IParsedType type,
38 41
 			ParsedExpression expression,
39
-			boolean isFinal)
42
+			boolean isFinal,
43
+			int autoGetter,
44
+			int autoSetter)
40 45
 	{
41 46
 		super(definition);
42 47
 		
@@ -46,6 +51,8 @@ public class ParsedField extends ParsedDefinitionMember {
46 51
 		this.type = type;
47 52
 		this.expression = expression;
48 53
 		this.isFinal = isFinal;
54
+		this.autoGetter = autoGetter;
55
+		this.autoSetter = autoSetter;
49 56
 	}
50 57
 	
51 58
 	@Override

+ 53
- 0
Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedStaticInitializer.java Переглянути файл

@@ -0,0 +1,53 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.parser.member;
7
+
8
+import org.openzen.zenscript.codemodel.FunctionHeader;
9
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
11
+import org.openzen.zenscript.codemodel.member.StaticInitializerMember;
12
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
13
+import org.openzen.zenscript.linker.BaseScope;
14
+import org.openzen.zenscript.linker.FunctionScope;
15
+import org.openzen.zenscript.parser.statements.ParsedStatement;
16
+import org.openzen.zenscript.shared.CodePosition;
17
+
18
+/**
19
+ *
20
+ * @author Hoofdgebruiker
21
+ */
22
+public class ParsedStaticInitializer extends ParsedDefinitionMember {
23
+	private final ParsedStatement body;
24
+	
25
+	private final StaticInitializerMember compiled;
26
+	
27
+	public ParsedStaticInitializer(HighLevelDefinition definition, CodePosition position, ParsedStatement body) {
28
+		super(definition);
29
+		
30
+		this.body = body;
31
+		compiled = new StaticInitializerMember(position);
32
+	}
33
+
34
+	@Override
35
+	public void linkInnerTypes() {
36
+		
37
+	}
38
+
39
+	@Override
40
+	public void linkTypes(BaseScope scope) {
41
+		
42
+	}
43
+
44
+	@Override
45
+	public IDefinitionMember getCompiled() {
46
+		return compiled;
47
+	}
48
+
49
+	@Override
50
+	public void compile(BaseScope scope) {
51
+		compiled.body = body.compile(new FunctionScope(scope, new FunctionHeader(BasicTypeID.VOID)));
52
+	}
53
+}

+ 32
- 0
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatement.java Переглянути файл

@@ -14,6 +14,8 @@ import org.openzen.zenscript.parser.expression.ParsedExpression;
14 14
 import org.openzen.zenscript.parser.type.IParsedType;
15 15
 import org.openzen.zenscript.parser.type.ParsedTypeBasic;
16 16
 import org.openzen.zenscript.shared.CodePosition;
17
+import org.openzen.zenscript.shared.CompileException;
18
+import org.openzen.zenscript.shared.CompileExceptionCode;
17 19
 
18 20
 public abstract class ParsedStatement {
19 21
 	public static ParsedFunctionBody parseLambdaBody(ZSTokenStream tokens, boolean inExpression) {
@@ -236,6 +238,36 @@ public abstract class ParsedStatement {
236 238
 				WhitespaceInfo whitespace = parser.collectWhitespaceInfo(ws, isFirst);
237 239
 				return new ParsedStatementBreak(t.position, whitespace, name);
238 240
 			}
241
+			case K_SWITCH: {
242
+				ZSToken t = parser.next();
243
+				String name = null;
244
+				if (parser.optional(T_COLON) != null)
245
+					name = parser.next().content;
246
+				
247
+				ParsedExpression value = ParsedExpression.parse(parser);
248
+				ParsedSwitchCase currentCase = null;
249
+				List<ParsedSwitchCase> cases = new ArrayList<>();
250
+				
251
+				parser.required(T_AOPEN, "{ expected");
252
+				while (parser.optional(T_ACLOSE) == null) {
253
+					if (parser.optional(K_CASE) != null) {
254
+						currentCase = new ParsedSwitchCase(ParsedExpression.parse(parser));
255
+						cases.add(currentCase);
256
+						parser.required(T_COLON, ": expected");
257
+					} else if (parser.optional(K_DEFAULT) != null) {
258
+						currentCase = new ParsedSwitchCase(null);
259
+						cases.add(currentCase);
260
+						parser.required(T_COLON, ": expected");
261
+					} else if (currentCase == null) {
262
+						throw new CompileException(parser.getPosition(), CompileExceptionCode.STATEMENT_OUTSIDE_SWITCH_CASE, "Statement in switch outside case");
263
+					} else {
264
+						currentCase.statements.add(ParsedStatement.parse(parser));
265
+					}
266
+				}
267
+				
268
+				WhitespaceInfo whitespace = parser.collectWhitespaceInfo(ws, isFirst);
269
+				return new ParsedStatementSwitch(t.position, whitespace, name, value, cases);
270
+			}
239 271
 		}
240 272
 
241 273
 		CodePosition position = parser.peek().getPosition();

+ 109
- 0
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementSwitch.java Переглянути файл

@@ -0,0 +1,109 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.parser.statements;
7
+
8
+import java.util.List;
9
+import java.util.function.Function;
10
+import org.openzen.zenscript.codemodel.FunctionHeader;
11
+import org.openzen.zenscript.codemodel.WhitespaceInfo;
12
+import org.openzen.zenscript.codemodel.expression.Expression;
13
+import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
14
+import org.openzen.zenscript.codemodel.partial.IPartialExpression;
15
+import org.openzen.zenscript.codemodel.statement.LoopStatement;
16
+import org.openzen.zenscript.codemodel.statement.Statement;
17
+import org.openzen.zenscript.codemodel.statement.SwitchStatement;
18
+import org.openzen.zenscript.codemodel.type.GenericName;
19
+import org.openzen.zenscript.codemodel.type.ITypeID;
20
+import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
21
+import org.openzen.zenscript.linker.ExpressionScope;
22
+import org.openzen.zenscript.linker.StatementScope;
23
+import org.openzen.zenscript.parser.expression.ParsedExpression;
24
+import org.openzen.zenscript.shared.CodePosition;
25
+
26
+/**
27
+ *
28
+ * @author Hoofdgebruiker
29
+ */
30
+public class ParsedStatementSwitch extends ParsedStatement {
31
+	private final String name;
32
+	private final ParsedExpression value;
33
+	private final List<ParsedSwitchCase> cases;
34
+	
35
+	public ParsedStatementSwitch(CodePosition position, WhitespaceInfo whitespace, String name, ParsedExpression value, List<ParsedSwitchCase> cases) {
36
+		super(position, whitespace);
37
+		
38
+		this.name = name;
39
+		this.value = value;
40
+		this.cases = cases;
41
+	}
42
+
43
+	@Override
44
+	public Statement compile(StatementScope scope) {
45
+		SwitchStatement result = new SwitchStatement(position, name, value.compile(new ExpressionScope(scope)).eval());
46
+		SwitchScope innerScope = new SwitchScope(scope, result);
47
+		
48
+		for (ParsedSwitchCase switchCase : cases) {
49
+			result.cases.add(switchCase.compile(innerScope));
50
+		}
51
+		
52
+		return result;
53
+	}
54
+	
55
+	private class SwitchScope extends StatementScope {
56
+		private final StatementScope outer;
57
+		private final SwitchStatement target;
58
+		
59
+		public SwitchScope(StatementScope outer, SwitchStatement target) {
60
+			this.outer = outer;
61
+			this.target = target;
62
+		}
63
+	
64
+		@Override
65
+		public IPartialExpression get(CodePosition position, GenericName name) {
66
+			IPartialExpression result = super.get(position, name);
67
+			if (result == null) {
68
+				return outer.get(position, name);
69
+			} else {
70
+				return result;
71
+			}
72
+		}
73
+
74
+		@Override
75
+		public LocalMemberCache getMemberCache() {
76
+			return outer.getMemberCache();
77
+		}
78
+
79
+		@Override
80
+		public ITypeID getType(CodePosition position, List<GenericName> name) {
81
+			return outer.getType(position, name);
82
+		}
83
+
84
+		@Override
85
+		public LoopStatement getLoop(String name) {
86
+			return name == null || name.equals(target.label) ? target : outer.getLoop(name);
87
+		}
88
+
89
+		@Override
90
+		public FunctionHeader getFunctionHeader() {
91
+			return outer.getFunctionHeader();
92
+		}
93
+
94
+		@Override
95
+		public ITypeID getThisType() {
96
+			return outer.getThisType();
97
+		}
98
+
99
+		@Override
100
+		public Function<CodePosition, Expression> getDollar() {
101
+			return outer.getDollar();
102
+		}
103
+
104
+		@Override
105
+		public IPartialExpression getOuterInstance(CodePosition position) {
106
+			return outer.getOuterInstance(position);
107
+		}
108
+	}
109
+}

+ 37
- 0
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedSwitchCase.java Переглянути файл

@@ -0,0 +1,37 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.parser.statements;
7
+
8
+import java.util.ArrayList;
9
+import java.util.List;
10
+import org.openzen.zenscript.codemodel.expression.Expression;
11
+import org.openzen.zenscript.codemodel.statement.Statement;
12
+import org.openzen.zenscript.codemodel.statement.SwitchCase;
13
+import org.openzen.zenscript.linker.ExpressionScope;
14
+import org.openzen.zenscript.linker.StatementScope;
15
+import org.openzen.zenscript.parser.expression.ParsedExpression;
16
+
17
+/**
18
+ *
19
+ * @author Hoofdgebruiker
20
+ */
21
+public class ParsedSwitchCase {
22
+	public final ParsedExpression value; // null for default
23
+	public final List<ParsedStatement> statements = new ArrayList<>();
24
+	
25
+	public ParsedSwitchCase(ParsedExpression value) {
26
+		this.value = value;
27
+	}
28
+	
29
+	public SwitchCase compile(StatementScope scope) {
30
+		Expression cValue = value == null ? null : value.compile(new ExpressionScope(scope)).eval();
31
+		List<Statement> cStatements = new ArrayList<>();
32
+		for (ParsedStatement statement : statements) {
33
+			cStatements.add(statement.compile(scope));
34
+		}
35
+		return new SwitchCase(cValue, cStatements);
36
+	}
37
+}

+ 5
- 0
Parser/src/main/java/org/openzen/zenscript/parser/type/IParsedType.java Переглянути файл

@@ -18,6 +18,7 @@ import static org.openzen.zenscript.lexer.ZSTokenType.T_LESS;
18 18
 import org.openzen.zenscript.linker.BaseScope;
19 19
 import org.openzen.zenscript.parser.ParseException;
20 20
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
21
+import org.openzen.zenscript.parser.definitions.ParsedGenericParameter;
21 22
 import org.openzen.zenscript.shared.CodePosition;
22 23
 
23 24
 /**
@@ -147,6 +148,10 @@ public interface IParsedType {
147 148
 					
148 149
 					if (tokens.optional(ZSTokenType.T_SQCLOSE) != null) {
149 150
 						result = new ParsedTypeArray(result, dimension);
151
+					} else if (tokens.isNext(T_LESS)) {
152
+						List<ParsedGenericParameter> parameters = ParsedGenericParameter.parseAll(tokens);
153
+						result = new ParsedTypeGenericMap(parameters, result, modifiers);
154
+						tokens.required(ZSTokenType.T_SQCLOSE, "] expected");
150 155
 					} else {
151 156
 						IParsedType keyType = parse(tokens);
152 157
 						result = new ParsedTypeAssociative(keyType, result);

+ 117
- 0
Parser/src/main/java/org/openzen/zenscript/parser/type/ParsedTypeGenericMap.java Переглянути файл

@@ -0,0 +1,117 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.parser.type;
7
+
8
+import java.util.HashMap;
9
+import java.util.List;
10
+import java.util.Map;
11
+import java.util.function.Function;
12
+import org.openzen.zenscript.codemodel.FunctionHeader;
13
+import org.openzen.zenscript.codemodel.expression.Expression;
14
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
15
+import org.openzen.zenscript.codemodel.partial.IPartialExpression;
16
+import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
17
+import org.openzen.zenscript.codemodel.statement.LoopStatement;
18
+import org.openzen.zenscript.codemodel.type.GenericName;
19
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
20
+import org.openzen.zenscript.codemodel.type.ITypeID;
21
+import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
22
+import org.openzen.zenscript.codemodel.type.member.TypeMembers;
23
+import org.openzen.zenscript.linker.BaseScope;
24
+import org.openzen.zenscript.parser.definitions.ParsedGenericParameter;
25
+import org.openzen.zenscript.shared.CodePosition;
26
+
27
+/**
28
+ *
29
+ * @author Hoofdgebruiker
30
+ */
31
+public class ParsedTypeGenericMap implements IParsedType {
32
+	private final List<ParsedGenericParameter> keys;
33
+	private final IParsedType value;
34
+	private final int modifiers;
35
+	
36
+	public ParsedTypeGenericMap(List<ParsedGenericParameter> keys, IParsedType value, int modifiers) {
37
+		this.keys = keys;
38
+		this.value = value;
39
+		this.modifiers = modifiers;
40
+	}
41
+
42
+	@Override
43
+	public IParsedType withOptional() {
44
+		return new ParsedTypeGenericMap(keys, value, modifiers | TypeMembers.MODIFIER_OPTIONAL);
45
+	}
46
+
47
+	@Override
48
+	public IParsedType withModifiers(int modifiers) {
49
+		return new ParsedTypeGenericMap(keys, value, modifiers | this.modifiers);
50
+	}
51
+
52
+	@Override
53
+	public ITypeID compile(BaseScope scope) {
54
+		TypeParameter[] cKeys = ParsedGenericParameter.getCompiled(keys);
55
+		ITypeID valueType = this.value.compile(new GenericMapScope(scope, cKeys));
56
+		
57
+		GlobalTypeRegistry registry = scope.getTypeRegistry();
58
+		return registry.getModified(modifiers, registry.getGenericMap(valueType, cKeys));
59
+	}
60
+	
61
+	private class GenericMapScope extends BaseScope {
62
+		private final BaseScope outer;
63
+		private final Map<String, TypeParameter> typeParameters = new HashMap<>();
64
+		
65
+		public GenericMapScope(BaseScope outer, TypeParameter[] parameters) {
66
+			this.outer = outer;
67
+			for (TypeParameter parameter : parameters)
68
+				typeParameters.put(parameter.name, parameter);
69
+		}
70
+
71
+		@Override
72
+		public LocalMemberCache getMemberCache() {
73
+			return outer.getMemberCache();
74
+		}
75
+
76
+		@Override
77
+		public IPartialExpression get(CodePosition position, GenericName name) {
78
+			if (typeParameters.containsKey(name.name) && name.arguments.isEmpty())
79
+				return new PartialTypeExpression(position, getTypeRegistry().getGeneric(typeParameters.get(name.name)));
80
+			
81
+			return outer.get(position, name);
82
+		}
83
+
84
+		@Override
85
+		public ITypeID getType(CodePosition position, List<GenericName> name) {
86
+			if (typeParameters.containsKey(name.get(0).name) && name.size() == 1 && name.get(0).arguments.isEmpty())
87
+				return getTypeRegistry().getGeneric(typeParameters.get(name.get(0).name));
88
+			
89
+			return outer.getType(position, name);
90
+		}
91
+
92
+		@Override
93
+		public LoopStatement getLoop(String name) {
94
+			return outer.getLoop(name);
95
+		}
96
+
97
+		@Override
98
+		public FunctionHeader getFunctionHeader() {
99
+			return outer.getFunctionHeader();
100
+		}
101
+
102
+		@Override
103
+		public ITypeID getThisType() {
104
+			return outer.getThisType();
105
+		}
106
+
107
+		@Override
108
+		public Function<CodePosition, Expression> getDollar() {
109
+			return outer.getDollar();
110
+		}
111
+
112
+		@Override
113
+		public IPartialExpression getOuterInstance(CodePosition position) {
114
+			return outer.getOuterInstance(position);
115
+		}
116
+	}
117
+}

+ 0
- 7
Shared/src/main/java/org/openzen/zenscript/shared/CodePosition.java Переглянути файл

@@ -58,11 +58,4 @@ public class CodePosition
58 58
 		
59 59
 		return shortFilename + ":" + fromLine + ":" + fromLineOffset;
60 60
 	}
61
-	
62
-	private static int compareLinePosition(int leftLine, int leftLineOffset, int rightLine, int rightLineOffset) {
63
-		if (leftLine == rightLine)
64
-			return leftLineOffset - rightLineOffset;
65
-		else
66
-			return leftLine - rightLine;
67
-	}
68 61
 }

+ 2
- 1
Shared/src/main/java/org/openzen/zenscript/shared/CompileExceptionCode.java Переглянути файл

@@ -57,5 +57,6 @@ public enum CompileExceptionCode {
57 57
 	INVALID_CONDITION,
58 58
 	INTERNAL_ERROR,
59 59
 	CANNOT_SET_FINAL_VARIABLE,
60
-	MISSING_PARAMETER
60
+	MISSING_PARAMETER,
61
+	STATEMENT_OUTSIDE_SWITCH_CASE
61 62
 }

+ 2
- 2
Shared/src/main/java/org/openzen/zenscript/shared/StringUtils.java Переглянути файл

@@ -15,7 +15,6 @@ import java.util.Map;
15 15
 import java.util.Properties;
16 16
 import java.util.logging.Level;
17 17
 import java.util.logging.Logger;
18
-import java.util.regex.Pattern;
19 18
 
20 19
 /**
21 20
  *
@@ -23,7 +22,8 @@ import java.util.regex.Pattern;
23 22
  */
24 23
 public class StringUtils {
25 24
 	private static final Map<String, CharacterEntity> NAMED_CHARACTER_ENTITIES;
26
-	private static final Pattern MATCH_ACCENTS = Pattern.compile("\\p{M}");
25
+	
26
+	private StringUtils() {}
27 27
 	
28 28
 	static
29 29
 	{

+ 2
- 1
Validator/src/main/java/org/openzen/zenscript/validator/ValidationLogEntry.java Переглянути файл

@@ -60,6 +60,7 @@ public class ValidationLogEntry {
60 60
 		LOCAL_VARIABLE_NOT_YET_INITIALIZED,
61 61
 		INVALID_SOURCE_TYPE,
62 62
 		SETTING_FINAL_FIELD,
63
-		SETTING_FINAL_VARIABLE
63
+		SETTING_FINAL_VARIABLE,
64
+		INVALID_SUPERTYPE
64 65
 	}
65 66
 }

+ 36
- 0
Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionMemberValidator.java Переглянути файл

@@ -25,7 +25,9 @@ import org.openzen.zenscript.codemodel.member.MemberVisitor;
25 25
 import org.openzen.zenscript.codemodel.member.MethodMember;
26 26
 import org.openzen.zenscript.codemodel.member.OperatorMember;
27 27
 import org.openzen.zenscript.codemodel.member.SetterMember;
28
+import org.openzen.zenscript.codemodel.member.StaticInitializerMember;
28 29
 import org.openzen.zenscript.codemodel.statement.VarStatement;
30
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
29 31
 import org.openzen.zenscript.codemodel.type.ITypeID;
30 32
 import org.openzen.zenscript.validator.ValidationLogEntry;
31 33
 import org.openzen.zenscript.validator.Validator;
@@ -235,6 +237,11 @@ public class DefinitionMemberValidator implements MemberVisitor<Boolean> {
235 237
 		isValid &= innerDefinition.innerDefinition.accept(new DefinitionValidator(validator));
236 238
 		return isValid;
237 239
 	}
240
+
241
+	@Override
242
+	public Boolean visitStaticInitializer(StaticInitializerMember member) {
243
+		return member.body.accept(new StatementValidator(validator, new StaticInitializerScope()));
244
+	}
238 245
 	
239 246
 	private class FieldInitializerScope implements ExpressionScope {
240 247
 		private final FieldMember field;
@@ -322,6 +329,35 @@ public class DefinitionMemberValidator implements MemberVisitor<Boolean> {
322 329
 		}
323 330
 	}
324 331
 	
332
+	private class StaticInitializerScope implements StatementScope {
333
+		private final FunctionHeader header = new FunctionHeader(BasicTypeID.VOID);
334
+		
335
+		@Override
336
+		public boolean isConstructor() {
337
+			return false;
338
+		}
339
+
340
+		@Override
341
+		public boolean isStatic() {
342
+			return true;
343
+		}
344
+
345
+		@Override
346
+		public FunctionHeader getFunctionHeader() {
347
+			return header;
348
+		}
349
+
350
+		@Override
351
+		public boolean isStaticInitializer() {
352
+			return true;
353
+		}
354
+
355
+		@Override
356
+		public HighLevelDefinition getDefinition() {
357
+			return definition;
358
+		}
359
+	}
360
+	
325 361
 	private class EnumConstantInitializerScope implements ExpressionScope {
326 362
 
327 363
 		@Override

+ 0
- 4
Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionValidator.java Переглянути файл

@@ -134,10 +134,6 @@ public class DefinitionValidator implements DefinitionVisitor<Boolean> {
134 134
 				PUBLIC | EXPORT | PROTECTED | PRIVATE,
135 135
 				definition.position,
136 136
 				"Invalid expansion modifier");
137
-		isValid &= ValidationUtils.validateIdentifier(
138
-				validator,
139
-				definition.position,
140
-				definition.name);
141 137
 		
142 138
 		isValid &= definition.target.accept(new TypeValidator(validator, definition.position));
143 139
 		isValid &= validateMembers(definition);

+ 9
- 0
Validator/src/main/java/org/openzen/zenscript/validator/visitors/ExpressionValidator.java Переглянути файл

@@ -56,6 +56,7 @@ import org.openzen.zenscript.codemodel.expression.MapExpression;
56 56
 import org.openzen.zenscript.codemodel.expression.NewExpression;
57 57
 import org.openzen.zenscript.codemodel.expression.NullExpression;
58 58
 import org.openzen.zenscript.codemodel.expression.OrOrExpression;
59
+import org.openzen.zenscript.codemodel.expression.PostCallExpression;
59 60
 import org.openzen.zenscript.codemodel.expression.RangeExpression;
60 61
 import org.openzen.zenscript.codemodel.expression.SetFieldExpression;
61 62
 import org.openzen.zenscript.codemodel.expression.SetFunctionParameterExpression;
@@ -467,6 +468,14 @@ public class ExpressionValidator implements ExpressionVisitor<Boolean> {
467 468
 		}
468 469
 		return isValid;
469 470
 	}
471
+	
472
+	@Override
473
+	public Boolean visitPostCall(PostCallExpression expression) {
474
+		boolean isValid = true;
475
+		expression.target.accept(this);
476
+		// TODO: is target a valid increment target?
477
+		return isValid;
478
+	}
470 479
 
471 480
 	@Override
472 481
 	public Boolean visitRange(RangeExpression expression) {

+ 14
- 0
Validator/src/main/java/org/openzen/zenscript/validator/visitors/StatementValidator.java Переглянути файл

@@ -24,6 +24,8 @@ import org.openzen.zenscript.codemodel.statement.LockStatement;
24 24
 import org.openzen.zenscript.codemodel.statement.ReturnStatement;
25 25
 import org.openzen.zenscript.codemodel.statement.Statement;
26 26
 import org.openzen.zenscript.codemodel.statement.StatementVisitor;
27
+import org.openzen.zenscript.codemodel.statement.SwitchCase;
28
+import org.openzen.zenscript.codemodel.statement.SwitchStatement;
27 29
 import org.openzen.zenscript.codemodel.statement.ThrowStatement;
28 30
 import org.openzen.zenscript.codemodel.statement.TryCatchStatement;
29 31
 import org.openzen.zenscript.codemodel.statement.VarStatement;
@@ -174,6 +176,18 @@ public class StatementValidator implements StatementVisitor<Boolean> {
174 176
 		return isValid;
175 177
 	}
176 178
 
179
+	@Override
180
+	public Boolean visitSwitch(SwitchStatement statement) {
181
+		boolean isValid = true;
182
+		isValid &= statement.value.accept(new ExpressionValidator(validator, new StatementExpressionScope()));
183
+		
184
+		for (SwitchCase switchCase : statement.cases) {
185
+			// TODO: finish this
186
+		}
187
+		
188
+		return isValid;
189
+	}
190
+
177 191
 	@Override
178 192
 	public Boolean visitThrow(ThrowStatement statement) {
179 193
 		boolean isValid = statement.value.accept(new ExpressionValidator(validator, new StatementExpressionScope()));

+ 30
- 10
Validator/src/main/java/org/openzen/zenscript/validator/visitors/SupertypeValidator.java Переглянути файл

@@ -5,12 +5,14 @@
5 5
  */
6 6
 package org.openzen.zenscript.validator.visitors;
7 7
 
8
+import org.openzen.zenscript.codemodel.Modifiers;
8 9
 import org.openzen.zenscript.codemodel.type.ArrayTypeID;
9 10
 import org.openzen.zenscript.codemodel.type.AssocTypeID;
10 11
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
11 12
 import org.openzen.zenscript.codemodel.type.ConstTypeID;
12 13
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
13 14
 import org.openzen.zenscript.codemodel.type.FunctionTypeID;
15
+import org.openzen.zenscript.codemodel.type.GenericMapTypeID;
14 16
 import org.openzen.zenscript.codemodel.type.GenericTypeID;
15 17
 import org.openzen.zenscript.codemodel.type.ITypeVisitor;
16 18
 import org.openzen.zenscript.codemodel.type.IteratorTypeID;
@@ -44,47 +46,65 @@ public class SupertypeValidator implements ITypeVisitor<Boolean> {
44 46
 
45 47
 	@Override
46 48
 	public Boolean visitArray(ArrayTypeID array) {
47
-		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
49
+		validator.logError(ValidationLogEntry.Code.SUPERCLASS_NOT_A_CLASS, position, "Superclass cannot be an array");
50
+		return false;
48 51
 	}
49 52
 
50 53
 	@Override
51 54
 	public Boolean visitAssoc(AssocTypeID assoc) {
52
-		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
55
+		validator.logError(ValidationLogEntry.Code.SUPERCLASS_NOT_A_CLASS, position, "Superclass cannot be an associative array");
56
+		return false;
53 57
 	}
54 58
 
55 59
 	@Override
56 60
 	public Boolean visitIterator(IteratorTypeID iterator) {
57
-		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
61
+		validator.logError(ValidationLogEntry.Code.SUPERCLASS_NOT_A_CLASS, position, "Superclass cannot be an iterator");
62
+		return false;
58 63
 	}
59 64
 
60 65
 	@Override
61 66
 	public Boolean visitFunction(FunctionTypeID function) {
62
-		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
67
+		validator.logError(ValidationLogEntry.Code.SUPERCLASS_NOT_A_CLASS, position, "Superclass cannot be a function");
68
+		return false;
63 69
 	}
64 70
 
65 71
 	@Override
66 72
 	public Boolean visitDefinition(DefinitionTypeID definition) {
67
-		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
73
+		boolean isValid = true;
74
+		if (!Modifiers.isVirtual(definition.definition.modifiers)) {
75
+			validator.logError(ValidationLogEntry.Code.INVALID_SUPERTYPE, position, "Supertype must be virtual");
76
+			isValid = false;
77
+		}
78
+		return isValid;
68 79
 	}
69 80
 
70 81
 	@Override
71 82
 	public Boolean visitGeneric(GenericTypeID generic) {
72
-		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
83
+		validator.logError(ValidationLogEntry.Code.SUPERCLASS_NOT_A_CLASS, position, "Superclass cannot be a type parameter");
84
+		return false;
73 85
 	}
74 86
 
75 87
 	@Override
76 88
 	public Boolean visitRange(RangeTypeID range) {
77
-		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
89
+		validator.logError(ValidationLogEntry.Code.SUPERCLASS_NOT_A_CLASS, position, "Superclass cannot be a range");
90
+		return false;
78 91
 	}
79 92
 
80 93
 	@Override
81 94
 	public Boolean visitConst(ConstTypeID type) {
82
-		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
95
+		validator.logError(ValidationLogEntry.Code.SUPERCLASS_NOT_A_CLASS, position, "Superclass cannot be a const type");
96
+		return false;
83 97
 	}
84 98
 
85 99
 	@Override
86 100
 	public Boolean visitOptional(OptionalTypeID optional) {
87
-		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
101
+		validator.logError(ValidationLogEntry.Code.SUPERCLASS_NOT_A_CLASS, position, "Superclass cannot be an optional type");
102
+		return false;
103
+	}
104
+
105
+	@Override
106
+	public Boolean visitGenericMap(GenericMapTypeID map) {
107
+		validator.logError(ValidationLogEntry.Code.SUPERCLASS_NOT_A_CLASS, position, "Superclass cannot be a generic map");
108
+		return false;
88 109
 	}
89
-	
90 110
 }

+ 9
- 0
Validator/src/main/java/org/openzen/zenscript/validator/visitors/TypeValidator.java Переглянути файл

@@ -16,6 +16,7 @@ import org.openzen.zenscript.codemodel.type.BasicTypeID;
16 16
 import org.openzen.zenscript.codemodel.type.ConstTypeID;
17 17
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
18 18
 import org.openzen.zenscript.codemodel.type.FunctionTypeID;
19
+import org.openzen.zenscript.codemodel.type.GenericMapTypeID;
19 20
 import org.openzen.zenscript.codemodel.type.GenericTypeID;
20 21
 import org.openzen.zenscript.codemodel.type.ITypeID;
21 22
 import org.openzen.zenscript.codemodel.type.ITypeVisitor;
@@ -111,4 +112,12 @@ public class TypeValidator implements ITypeVisitor<Boolean> {
111 112
 		// TODO: detect duplicate optional
112 113
 		return optional.baseType.accept(this);
113 114
 	}
115
+
116
+	@Override
117
+	public Boolean visitGenericMap(GenericMapTypeID map) {
118
+		boolean isValid = true;
119
+		isValid &= map.value.accept(this);
120
+		
121
+		return isValid;
122
+	}
114 123
 }

+ 1
- 1
Validator/src/main/java/org/openzen/zenscript/validator/visitors/ValidationUtils.java Переглянути файл

@@ -38,7 +38,7 @@ public class ValidationUtils {
38 38
 	private ValidationUtils() {}
39 39
 	
40 40
 	public static boolean validateIdentifier(Validator target, CodePosition position, String identifier) { 
41
-		if (!IDENTIFIER_PATTERN.matcher(identifier).matches()) {
41
+		if (identifier == null || !IDENTIFIER_PATTERN.matcher(identifier).matches()) {
42 42
 			target.logError(INVALID_IDENTIFIER, position, "Invalid identifier: " + identifier);
43 43
 			return false;
44 44
 		}

Завантаження…
Відмінити
Зберегти