Browse Source

- Added annotation support

- Removed some redundant types
- Moved scopes to CodeModel and removed Linker
- Added const members and expression support for them
- Added statement transformation (can be used by annotations)
Stan Hebben 6 years ago
parent
commit
2e44dec4d7
100 changed files with 1834 additions and 395 deletions
  1. 11
    1
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/ExpressionFormatter.java
  2. 16
    2
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/MemberFormatter.java
  3. 0
    1
      CodeFormatterShared/build.gradle
  4. 8
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionParameter.java
  5. 2
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/HighLevelDefinition.java
  6. 16
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/ModuleProcessor.java
  7. 9
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/ScriptBlock.java
  8. 16
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/Annotation.java
  9. 44
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/AnnotationDefinition.java
  10. 219
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/AnnotationProcessor.java
  11. 21
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/DefinitionAnnotation.java
  12. 22
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/MemberAnnotation.java
  13. 88
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/NativeAnnotationDefinition.java
  14. 31
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/NativeDefinitionAnnotation.java
  15. 32
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/NativeMemberAnnotation.java
  16. 18
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/NativeTag.java
  17. 107
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/PreconditionAnnotationDefinition.java
  18. 67
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/PreconditionForMethod.java
  19. 19
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/StatementAnnotation.java
  20. 13
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallExpression.java
  21. 44
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstExpression.java
  22. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantByteExpression.java
  23. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantStringExpression.java
  24. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantUShortExpression.java
  25. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/EnumConstantExpression.java
  26. 40
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/Expression.java
  27. 72
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionBuilder.java
  28. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionVisitor.java
  29. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/FunctionExpression.java
  30. 3
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/VariantValueExpression.java
  31. 2
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CasterMember.java
  32. 61
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ConstMember.java
  33. 0
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ConstructorMember.java
  34. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/DefinitionMember.java
  35. 5
    10
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FunctionalMember.java
  36. 2
    14
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/GetterMember.java
  37. 0
    32
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ICallableMember.java
  38. 0
    22
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ICasterMember.java
  39. 0
    26
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/IGettableMember.java
  40. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/MemberVisitor.java
  41. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/StaticInitializerMember.java
  42. 0
    94
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/ConstantGetterMember.java
  43. 4
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialMemberGroupExpression.java
  44. 4
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialStaticMemberGroupExpression.java
  45. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialTypeExpression.java
  46. 19
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/processor/InterfaceProcessor.java
  47. 1
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/BaseScope.java
  48. 7
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/BlockScope.java
  49. 7
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/DefinitionScope.java
  50. 25
    6
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ExpressionScope.java
  51. 15
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FileScope.java
  52. 7
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ForeachScope.java
  53. 7
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FunctionScope.java
  54. 7
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/GenericFunctionScope.java
  55. 9
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/GlobalScriptScope.java
  56. 7
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ImplementationScope.java
  57. 7
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LambdaScope.java
  58. 7
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LoopScope.java
  59. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/StatementScope.java
  60. 3
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/TypeScope.java
  61. 21
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/BlockStatement.java
  62. 11
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/BreakStatement.java
  63. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/CatchClause.java
  64. 11
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ContinueStatement.java
  65. 23
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/DoWhileStatement.java
  66. 11
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/EmptyStatement.java
  67. 13
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ExpressionStatement.java
  68. 23
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ForeachStatement.java
  69. 20
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/IfStatement.java
  70. 14
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/LockStatement.java
  71. 12
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ReturnStatement.java
  72. 11
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/Statement.java
  73. 14
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/StatementTransformer.java
  74. 8
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/SwitchCase.java
  75. 21
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/SwitchStatement.java
  76. 12
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ThrowStatement.java
  77. 22
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/TryCatchStatement.java
  78. 12
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/VarStatement.java
  79. 25
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/WhileStatement.java
  80. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ISymbol.java
  81. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ITypeID.java
  82. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeSymbol.java
  83. 48
    33
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/DefinitionMemberGroup.java
  84. 50
    29
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java
  85. 24
    17
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMembers.java
  86. 1
    1
      CompilerShared/build.gradle
  87. 14
    1
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/CompileScope.java
  88. 79
    8
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java
  89. 0
    1
      Constructor/build.gradle
  90. 2
    1
      Constructor/libraries/stdlib/module.json
  91. 7
    26
      Constructor/src/main/java/org/openzen/zenscript/constructor/Module.java
  92. 2
    2
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleLoader.java
  93. 18
    3
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/ModuleSpace.java
  94. 27
    4
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalTarget.java
  95. 0
    3
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/WindowView.java
  96. 92
    2
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
  97. 6
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreDecrementVisitor.java
  98. 6
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreIncrementVisitor.java
  99. 10
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaMemberVisitor.java
  100. 0
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/ExpressionHoistingChecker.java

+ 11
- 1
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/ExpressionFormatter.java View File

@@ -21,6 +21,7 @@ import org.openzen.zenscript.codemodel.expression.CastExpression;
21 21
 import org.openzen.zenscript.codemodel.expression.CheckNullExpression;
22 22
 import org.openzen.zenscript.codemodel.expression.CoalesceExpression;
23 23
 import org.openzen.zenscript.codemodel.expression.ConditionalExpression;
24
+import org.openzen.zenscript.codemodel.expression.ConstExpression;
24 25
 import org.openzen.zenscript.codemodel.expression.ConstantBoolExpression;
25 26
 import org.openzen.zenscript.codemodel.expression.ConstantByteExpression;
26 27
 import org.openzen.zenscript.codemodel.expression.ConstantCharExpression;
@@ -323,6 +324,15 @@ public class ExpressionFormatter implements ExpressionVisitor<ExpressionString>
323 324
 		result.append(expression.ifElse.accept(this));
324 325
 		return new ExpressionString(result.toString(), ZenScriptOperator.TERNARY);
325 326
 	}
327
+	
328
+	@Override
329
+	public ExpressionString visitConst(ConstExpression expression) {
330
+		StringBuilder result = new StringBuilder();
331
+		result.append(expression.type.accept(typeFormatter));
332
+		result.append('.');
333
+		result.append(expression.constant.name);
334
+		return new ExpressionString(result.toString(), ZenScriptOperator.MEMBER);
335
+	}
326 336
 
327 337
 	@Override
328 338
 	public ExpressionString visitConstantBool(ConstantBoolExpression expression) {
@@ -331,7 +341,7 @@ public class ExpressionFormatter implements ExpressionVisitor<ExpressionString>
331 341
 
332 342
 	@Override
333 343
 	public ExpressionString visitConstantByte(ConstantByteExpression expression) {
334
-		return new ExpressionString(Byte.toString(expression.value) + " as byte", ZenScriptOperator.CAST);
344
+		return new ExpressionString(Integer.toString(expression.value) + " as byte", ZenScriptOperator.CAST);
335 345
 	}
336 346
 
337 347
 	@Override

+ 16
- 2
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/MemberFormatter.java View File

@@ -8,10 +8,10 @@ package org.openzen.zenscript.formatter;
8 8
 import org.openzen.zenscript.codemodel.Modifiers;
9 9
 import org.openzen.zenscript.codemodel.member.CallerMember;
10 10
 import org.openzen.zenscript.codemodel.member.CasterMember;
11
+import org.openzen.zenscript.codemodel.member.ConstMember;
11 12
 import org.openzen.zenscript.codemodel.member.ConstructorMember;
12 13
 import org.openzen.zenscript.codemodel.member.CustomIteratorMember;
13 14
 import org.openzen.zenscript.codemodel.member.DestructorMember;
14
-import org.openzen.zenscript.codemodel.member.EnumConstantMember;
15 15
 import org.openzen.zenscript.codemodel.member.FieldMember;
16 16
 import org.openzen.zenscript.codemodel.member.GetterMember;
17 17
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
@@ -54,6 +54,20 @@ public class MemberFormatter implements MemberVisitor<Void> {
54 54
 		
55 55
 		wasField = field;
56 56
 	}
57
+	
58
+	@Override
59
+	public Void visitConst(ConstMember member) {
60
+		visit(true);
61
+		FormattingUtils.formatModifiers(output, member.modifiers & ~Modifiers.FINAL);
62
+		output.append("const")
63
+				.append(member.name)
64
+				.append(" as ")
65
+				.append(member.type.accept(typeFormatter))
66
+				.append(" = ")
67
+				.append(member.value.accept(new ExpressionFormatter(settings, typeFormatter)))
68
+				.append(";\n");
69
+		return null;
70
+	}
57 71
 
58 72
 	@Override
59 73
 	public Void visitField(FieldMember member) {
@@ -68,7 +82,7 @@ public class MemberFormatter implements MemberVisitor<Void> {
68 82
 			output.append(" = ")
69 83
 					.append(member.initializer.accept(new ExpressionFormatter(settings, typeFormatter)));
70 84
 		}
71
-		output.append(";").append("\n");
85
+		output.append(";\n");
72 86
 		return null;
73 87
 	}
74 88
 

Linker/build.gradle → CodeFormatterShared/build.gradle View File

@@ -14,6 +14,5 @@ if (!hasProperty('mainClass')) {
14 14
 }
15 15
 
16 16
 dependencies {
17
-	compile project(':Shared')
18 17
 	compile project(':CodeModel')
19 18
 }

+ 8
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionParameter.java View File

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel;
7 7
 
8
+import org.openzen.zenscript.codemodel.annotations.Annotation;
8 9
 import java.util.Map;
9 10
 import java.util.Objects;
10 11
 import org.openzen.zenscript.codemodel.expression.Expression;
@@ -20,12 +21,14 @@ import org.openzen.zenscript.shared.Taggable;
20 21
 public class FunctionParameter extends Taggable {
21 22
 	public static final FunctionParameter[] NONE = new FunctionParameter[0];
22 23
 	
24
+	public Annotation[] annotations;
23 25
 	public final ITypeID type;
24 26
 	public final String name;
25 27
 	public final Expression defaultValue;
26 28
 	public final boolean variadic;
27 29
 	
28 30
 	public FunctionParameter(ITypeID type) {
31
+		this.annotations = Annotation.NONE;
29 32
 		this.type = type;
30 33
 		this.name = "";
31 34
 		this.defaultValue = null;
@@ -33,6 +36,7 @@ public class FunctionParameter extends Taggable {
33 36
 	}
34 37
 	
35 38
 	public FunctionParameter(ITypeID type, String name) {
39
+		this.annotations = Annotation.NONE;
36 40
 		this.type = type;
37 41
 		this.name = name;
38 42
 		this.defaultValue = null;
@@ -40,6 +44,7 @@ public class FunctionParameter extends Taggable {
40 44
 	}
41 45
 	
42 46
 	public FunctionParameter(ITypeID type, String name, Expression defaultValue, boolean variadic) {
47
+		this.annotations = Annotation.NONE;
43 48
 		this.type = type;
44 49
 		this.name = name;
45 50
 		this.defaultValue = defaultValue;
@@ -47,7 +52,9 @@ public class FunctionParameter extends Taggable {
47 52
 	}
48 53
 	
49 54
 	public FunctionParameter withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments) {
50
-		return new FunctionParameter(type.withGenericArguments(registry, arguments), name, defaultValue, variadic);
55
+		FunctionParameter result = new FunctionParameter(type.withGenericArguments(registry, arguments), name, defaultValue, variadic);
56
+		result.annotations = annotations;
57
+		return result;
51 58
 	}
52 59
 	
53 60
 	@Override

+ 2
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/HighLevelDefinition.java View File

@@ -7,11 +7,11 @@ package org.openzen.zenscript.codemodel;
7 7
 
8 8
 import java.util.ArrayList;
9 9
 import java.util.List;
10
+import org.openzen.zenscript.codemodel.annotations.DefinitionAnnotation;
10 11
 import org.openzen.zenscript.codemodel.definition.DefinitionVisitor;
11 12
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
12 13
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
13 14
 import org.openzen.zenscript.codemodel.member.ConstructorMember;
14
-import org.openzen.zenscript.codemodel.member.EnumConstantMember;
15 15
 import org.openzen.zenscript.codemodel.member.FieldMember;
16 16
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
17 17
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -30,6 +30,7 @@ public abstract class HighLevelDefinition extends Taggable {
30 30
 	public final List<IDefinitionMember> members = new ArrayList<>();
31 31
 	public final AccessScope access = new AccessScope();
32 32
 	public TypeParameter[] genericParameters = null;
33
+	public DefinitionAnnotation[] annotations = DefinitionAnnotation.NONE;
33 34
 	
34 35
 	public HighLevelDefinition outerDefinition;
35 36
 	public ITypeID superType;

+ 16
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/ModuleProcessor.java View File

@@ -0,0 +1,16 @@
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;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public interface ModuleProcessor {
13
+	public ScriptBlock process(ScriptBlock block);
14
+	
15
+	public void process(HighLevelDefinition definition);
16
+}

+ 9
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/ScriptBlock.java View File

@@ -14,9 +14,17 @@ import org.openzen.zenscript.shared.Taggable;
14 14
  * @author Hoofdgebruiker
15 15
  */
16 16
 public class ScriptBlock extends Taggable {
17
+	public final AccessScope access;
17 18
 	public final List<Statement> statements;
18 19
 	
19
-	public ScriptBlock(List<Statement> statements) {
20
+	public ScriptBlock(AccessScope access, List<Statement> statements) {
21
+		this.access = access;
20 22
 		this.statements = statements;
21 23
 	}
24
+	
25
+	public ScriptBlock withStatements(List<Statement> newStatements) {
26
+		ScriptBlock result = new ScriptBlock(access, newStatements);
27
+		result.addAllTagsFrom(this);
28
+		return result;
29
+	}
22 30
 }

+ 16
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/Annotation.java View File

@@ -0,0 +1,16 @@
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.annotations;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public interface Annotation {
13
+	public static final Annotation[] NONE = new Annotation[0];
14
+	
15
+	public void apply();
16
+}

+ 44
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/AnnotationDefinition.java View File

@@ -0,0 +1,44 @@
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.annotations;
7
+
8
+import java.util.List;
9
+import org.openzen.zenscript.codemodel.FunctionHeader;
10
+import org.openzen.zenscript.codemodel.FunctionParameter;
11
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
+import org.openzen.zenscript.codemodel.expression.CallArguments;
13
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
14
+import org.openzen.zenscript.codemodel.scope.BaseScope;
15
+import org.openzen.zenscript.codemodel.scope.ExpressionScope;
16
+import org.openzen.zenscript.codemodel.scope.StatementScope;
17
+import org.openzen.zenscript.codemodel.statement.Statement;
18
+import org.openzen.zenscript.shared.CodePosition;
19
+
20
+/**
21
+ *
22
+ * @author Hoofdgebruiker
23
+ */
24
+public interface AnnotationDefinition {
25
+	public String getAnnotationName();
26
+	
27
+	public List<FunctionHeader> getInitializers(BaseScope scope);
28
+	
29
+	public ExpressionScope getScopeForMember(IDefinitionMember member, BaseScope scope);
30
+	
31
+	public ExpressionScope getScopeForType(HighLevelDefinition definition, BaseScope scope);
32
+	
33
+	public ExpressionScope getScopeForStatement(Statement statement, StatementScope scope);
34
+	
35
+	public ExpressionScope getScopeForParameter(FunctionHeader header, FunctionParameter parameter, BaseScope scope);
36
+	
37
+	public MemberAnnotation createForMember(CodePosition position, CallArguments arguments);
38
+	
39
+	public DefinitionAnnotation createForDefinition(CodePosition position, CallArguments arguments);
40
+	
41
+	public StatementAnnotation createForStatement(CodePosition position, CallArguments arguments);
42
+	
43
+	public Annotation createForParameter(CodePosition position, CallArguments arguments);
44
+}

+ 219
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/AnnotationProcessor.java View File

@@ -0,0 +1,219 @@
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.annotations;
7
+
8
+import java.util.ArrayList;
9
+import java.util.HashMap;
10
+import java.util.List;
11
+import org.openzen.zenscript.codemodel.FunctionHeader;
12
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
+import org.openzen.zenscript.codemodel.ModuleProcessor;
14
+import org.openzen.zenscript.codemodel.PackageDefinitions;
15
+import org.openzen.zenscript.codemodel.ScriptBlock;
16
+import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
17
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
18
+import org.openzen.zenscript.codemodel.member.CallerMember;
19
+import org.openzen.zenscript.codemodel.member.CasterMember;
20
+import org.openzen.zenscript.codemodel.member.ConstMember;
21
+import org.openzen.zenscript.codemodel.member.ConstructorMember;
22
+import org.openzen.zenscript.codemodel.member.CustomIteratorMember;
23
+import org.openzen.zenscript.codemodel.member.DestructorMember;
24
+import org.openzen.zenscript.codemodel.member.FieldMember;
25
+import org.openzen.zenscript.codemodel.member.FunctionalMember;
26
+import org.openzen.zenscript.codemodel.member.GetterMember;
27
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
28
+import org.openzen.zenscript.codemodel.member.ImplementationMember;
29
+import org.openzen.zenscript.codemodel.member.InnerDefinitionMember;
30
+import org.openzen.zenscript.codemodel.member.MemberVisitor;
31
+import org.openzen.zenscript.codemodel.member.MethodMember;
32
+import org.openzen.zenscript.codemodel.member.OperatorMember;
33
+import org.openzen.zenscript.codemodel.member.SetterMember;
34
+import org.openzen.zenscript.codemodel.member.StaticInitializerMember;
35
+import org.openzen.zenscript.codemodel.scope.DefinitionScope;
36
+import org.openzen.zenscript.codemodel.scope.FileScope;
37
+import org.openzen.zenscript.codemodel.scope.FunctionScope;
38
+import org.openzen.zenscript.codemodel.scope.GlobalScriptScope;
39
+import org.openzen.zenscript.codemodel.scope.StatementScope;
40
+import org.openzen.zenscript.codemodel.statement.Statement;
41
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
42
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
43
+
44
+/**
45
+ *
46
+ * @author Hoofdgebruiker
47
+ */
48
+public class AnnotationProcessor implements ModuleProcessor {
49
+	private final ZSPackage rootPackage;
50
+	private final PackageDefinitions packageDefinitions;
51
+	private final GlobalTypeRegistry globalRegistry;
52
+	private final List<ExpansionDefinition> expansions;
53
+	private final List<AnnotationDefinition> annotations;
54
+	
55
+	public AnnotationProcessor(
56
+			ZSPackage rootPackage,
57
+			PackageDefinitions packageDefinitions,
58
+			GlobalTypeRegistry globalRegistry,
59
+			List<ExpansionDefinition> expansions,
60
+			List<AnnotationDefinition> annotations) {
61
+		this.rootPackage = rootPackage;
62
+		this.packageDefinitions = packageDefinitions;
63
+		this.globalRegistry = globalRegistry;
64
+		this.expansions = expansions;
65
+		this.annotations = annotations;
66
+	}
67
+	
68
+	@Override
69
+	public ScriptBlock process(ScriptBlock block) {
70
+		FileScope fileScope = new FileScope(block.access, rootPackage, packageDefinitions, globalRegistry, expansions, new HashMap<>(), annotations);
71
+		StatementScope scope = new GlobalScriptScope(fileScope);
72
+		List<Statement> transformed = new ArrayList<>();
73
+		boolean unchanged = true;
74
+		for (Statement statement : block.statements) {
75
+			Statement newStatement = process(statement, scope);
76
+			transformed.add(newStatement);
77
+			unchanged &= statement == newStatement;
78
+		}
79
+		return unchanged ? block : block.withStatements(transformed);
80
+	}
81
+	
82
+	@Override
83
+	public void process(HighLevelDefinition definition) {
84
+		FileScope fileScope = new FileScope(definition.access, rootPackage, packageDefinitions, globalRegistry, expansions, new HashMap<>(), annotations);
85
+		DefinitionScope scope = new DefinitionScope(fileScope, definition);
86
+		for (DefinitionAnnotation annotation : definition.annotations) {
87
+			annotation.apply(definition, scope);
88
+		}
89
+		
90
+		MemberAnnotationVisitor visitor = new MemberAnnotationVisitor(scope);
91
+		for (IDefinitionMember member : definition.members) {
92
+			member.accept(visitor);
93
+		}
94
+	}
95
+	
96
+	private Statement process(Statement statement, StatementScope scope) {
97
+		return statement.transform(s -> {
98
+			for (StatementAnnotation annotation : s.annotations) {
99
+				s = annotation.apply(s, scope);
100
+			}
101
+			return s;
102
+		});
103
+	}
104
+	
105
+	private class MemberAnnotationVisitor implements MemberVisitor<Void> {
106
+		private final DefinitionScope scope;
107
+		
108
+		public MemberAnnotationVisitor(DefinitionScope scope) {
109
+			this.scope = scope;
110
+		}
111
+		
112
+		@Override
113
+		public Void visitConst(ConstMember member) {
114
+			for (MemberAnnotation annotation : member.annotations)
115
+				annotation.apply(member, scope);
116
+			
117
+			return null;
118
+		}
119
+
120
+		@Override
121
+		public Void visitField(FieldMember member) {
122
+			for (MemberAnnotation annotation : member.annotations)
123
+				annotation.apply(member, scope);
124
+			
125
+			return null;
126
+		}
127
+
128
+		@Override
129
+		public Void visitConstructor(ConstructorMember member) {
130
+			return functional(member);
131
+		}
132
+
133
+		@Override
134
+		public Void visitDestructor(DestructorMember member) {
135
+			return functional(member);
136
+		}
137
+
138
+		@Override
139
+		public Void visitMethod(MethodMember member) {
140
+			return functional(member);
141
+		}
142
+
143
+		@Override
144
+		public Void visitGetter(GetterMember member) {
145
+			return functional(member);
146
+		}
147
+
148
+		@Override
149
+		public Void visitSetter(SetterMember member) {
150
+			return functional(member);
151
+		}
152
+
153
+		@Override
154
+		public Void visitOperator(OperatorMember member) {
155
+			return functional(member);
156
+		}
157
+
158
+		@Override
159
+		public Void visitCaster(CasterMember member) {
160
+			return functional(member);
161
+		}
162
+
163
+		@Override
164
+		public Void visitCustomIterator(CustomIteratorMember member) {
165
+			throw new UnsupportedOperationException("Not supported yet!");
166
+		}
167
+
168
+		@Override
169
+		public Void visitCaller(CallerMember member) {
170
+			return functional(member);
171
+		}
172
+
173
+		@Override
174
+		public Void visitImplementation(ImplementationMember implementation) {
175
+			for (IDefinitionMember member : implementation.members) {
176
+				member.accept(this);
177
+			}
178
+			return null;
179
+		}
180
+
181
+		@Override
182
+		public Void visitInnerDefinition(InnerDefinitionMember member) {
183
+			process(member.innerDefinition);
184
+			return null;
185
+		}
186
+
187
+		@Override
188
+		public Void visitStaticInitializer(StaticInitializerMember member) {
189
+			StatementScope scope = new FunctionScope(this.scope, new FunctionHeader(BasicTypeID.VOID));
190
+			member.body = process(member.body, scope);
191
+			return null;
192
+		}
193
+		
194
+		private Void functional(FunctionalMember member) {
195
+			for (MemberAnnotation annotation : member.annotations)
196
+				annotation.apply(member, scope);
197
+			
198
+			if (member.overrides != null) {
199
+				functional(member, member.overrides);
200
+			}
201
+			
202
+			if (member.body == null)
203
+				return null;
204
+			
205
+			StatementScope scope = new FunctionScope(this.scope, member.header);
206
+			member.body = process(member.body, scope);
207
+			return null;
208
+		}
209
+		
210
+		private void functional(FunctionalMember member, FunctionalMember overrides) {
211
+			for (MemberAnnotation annotation : overrides.annotations)
212
+				annotation.applyOnOverridingMethod(member, scope);
213
+			
214
+			if (overrides.overrides != null) {
215
+				functional(member, overrides.overrides);
216
+			}
217
+		}
218
+	}
219
+}

+ 21
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/DefinitionAnnotation.java View File

@@ -0,0 +1,21 @@
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.annotations;
7
+
8
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
9
+import org.openzen.zenscript.codemodel.scope.BaseScope;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public interface DefinitionAnnotation {
16
+	public static final DefinitionAnnotation[] NONE = new DefinitionAnnotation[0];
17
+	
18
+	public void apply(HighLevelDefinition definition, BaseScope scope);
19
+	
20
+	public void applyOnSubtype(HighLevelDefinition definition, BaseScope scope);
21
+}

+ 22
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/MemberAnnotation.java View File

@@ -0,0 +1,22 @@
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.annotations;
7
+
8
+import org.openzen.zenscript.codemodel.member.FunctionalMember;
9
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
10
+import org.openzen.zenscript.codemodel.scope.BaseScope;
11
+
12
+/**
13
+ *
14
+ * @author Hoofdgebruiker
15
+ */
16
+public interface MemberAnnotation {
17
+	public static final MemberAnnotation[] NONE = new MemberAnnotation[0];
18
+	
19
+	public void apply(IDefinitionMember member, BaseScope scope);
20
+	
21
+	public void applyOnOverridingMethod(FunctionalMember member, BaseScope scope);
22
+}

+ 88
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/NativeAnnotationDefinition.java View File

@@ -0,0 +1,88 @@
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.annotations;
7
+
8
+import java.util.Collections;
9
+import java.util.List;
10
+import org.openzen.zenscript.codemodel.FunctionHeader;
11
+import org.openzen.zenscript.codemodel.FunctionParameter;
12
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
+import org.openzen.zenscript.codemodel.expression.CallArguments;
14
+import org.openzen.zenscript.codemodel.expression.Expression;
15
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
16
+import org.openzen.zenscript.codemodel.scope.BaseScope;
17
+import org.openzen.zenscript.codemodel.scope.ExpressionScope;
18
+import org.openzen.zenscript.codemodel.scope.StatementScope;
19
+import org.openzen.zenscript.codemodel.statement.Statement;
20
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
21
+import org.openzen.zenscript.shared.CodePosition;
22
+
23
+/**
24
+ *
25
+ * @author Hoofdgebruiker
26
+ */
27
+public class NativeAnnotationDefinition implements AnnotationDefinition {
28
+	public static final NativeAnnotationDefinition INSTANCE = new NativeAnnotationDefinition();
29
+	
30
+	private static final List<FunctionHeader> INITIALIZERS = Collections.singletonList(
31
+			new FunctionHeader(BasicTypeID.VOID, BasicTypeID.STRING));
32
+	
33
+	private NativeAnnotationDefinition() {}
34
+
35
+	@Override
36
+	public String getAnnotationName() {
37
+		return "Native";
38
+	}
39
+
40
+	@Override
41
+	public List<FunctionHeader> getInitializers(BaseScope scope) {
42
+		return INITIALIZERS;
43
+	}
44
+
45
+	@Override
46
+	public ExpressionScope getScopeForMember(IDefinitionMember member, BaseScope scope) {
47
+		return new ExpressionScope(scope);
48
+	}
49
+
50
+	@Override
51
+	public ExpressionScope getScopeForType(HighLevelDefinition definition, BaseScope scope) {
52
+		return new ExpressionScope(scope);
53
+	}
54
+
55
+	@Override
56
+	public ExpressionScope getScopeForStatement(Statement statement, StatementScope scope) {
57
+		return new ExpressionScope(scope);
58
+	}
59
+
60
+	@Override
61
+	public ExpressionScope getScopeForParameter(FunctionHeader header, FunctionParameter parameter, BaseScope scope) {
62
+		return new ExpressionScope(scope);
63
+	}
64
+
65
+	@Override
66
+	public MemberAnnotation createForMember(CodePosition position, CallArguments arguments) {
67
+		Expression value = arguments.arguments[0];
68
+		String constant = value.evaluateStringConstant();
69
+		return new NativeMemberAnnotation(constant);
70
+	}
71
+
72
+	@Override
73
+	public DefinitionAnnotation createForDefinition(CodePosition position, CallArguments arguments) {
74
+		Expression value = arguments.arguments[0];
75
+		String constant = value.evaluateStringConstant();
76
+		return new NativeDefinitionAnnotation(constant);
77
+	}
78
+
79
+	@Override
80
+	public StatementAnnotation createForStatement(CodePosition position, CallArguments arguments) {
81
+		throw new UnsupportedOperationException("Not supported");
82
+	}
83
+
84
+	@Override
85
+	public Annotation createForParameter(CodePosition position, CallArguments arguments) {
86
+		throw new UnsupportedOperationException("Not supported");
87
+	}
88
+}

+ 31
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/NativeDefinitionAnnotation.java View File

@@ -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.annotations;
7
+
8
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
9
+import org.openzen.zenscript.codemodel.scope.BaseScope;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class NativeDefinitionAnnotation implements DefinitionAnnotation {
16
+	private final String identifier;
17
+	
18
+	public NativeDefinitionAnnotation(String identifier) {
19
+		this.identifier = identifier;
20
+	}
21
+	
22
+	@Override
23
+	public void apply(HighLevelDefinition definition, BaseScope scope) {
24
+		definition.setTag(NativeTag.class, new NativeTag(identifier));
25
+	}
26
+
27
+	@Override
28
+	public void applyOnSubtype(HighLevelDefinition definition, BaseScope scope) {
29
+		// this annotation is not inherited
30
+	}
31
+}

+ 32
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/NativeMemberAnnotation.java View File

@@ -0,0 +1,32 @@
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.annotations;
7
+
8
+import org.openzen.zenscript.codemodel.member.FunctionalMember;
9
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
10
+import org.openzen.zenscript.codemodel.scope.BaseScope;
11
+
12
+/**
13
+ *
14
+ * @author Hoofdgebruiker
15
+ */
16
+public class NativeMemberAnnotation implements MemberAnnotation {
17
+	private final String identifier;
18
+	
19
+	public NativeMemberAnnotation(String identifier) {
20
+		this.identifier = identifier;
21
+	}
22
+	
23
+	@Override
24
+	public void apply(IDefinitionMember member, BaseScope scope) {
25
+		member.setTag(NativeTag.class, new NativeTag(identifier));
26
+	}
27
+
28
+	@Override
29
+	public void applyOnOverridingMethod(FunctionalMember member, BaseScope scope) {
30
+		// not inherited
31
+	}
32
+}

+ 18
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/NativeTag.java View File

@@ -0,0 +1,18 @@
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.annotations;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public class NativeTag {
13
+	public final String value;
14
+	
15
+	public NativeTag(String value) {
16
+		this.value = value;
17
+	}
18
+}

+ 107
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/PreconditionAnnotationDefinition.java View File

@@ -0,0 +1,107 @@
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.annotations;
7
+
8
+import java.util.Arrays;
9
+import java.util.Collections;
10
+import java.util.List;
11
+import org.openzen.zenscript.codemodel.FunctionHeader;
12
+import org.openzen.zenscript.codemodel.FunctionParameter;
13
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
14
+import org.openzen.zenscript.codemodel.definition.FunctionDefinition;
15
+import org.openzen.zenscript.codemodel.expression.CallArguments;
16
+import org.openzen.zenscript.codemodel.expression.Expression;
17
+import org.openzen.zenscript.codemodel.member.FunctionalMember;
18
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
19
+import org.openzen.zenscript.codemodel.scope.BaseScope;
20
+import org.openzen.zenscript.codemodel.scope.ExpressionScope;
21
+import org.openzen.zenscript.codemodel.scope.FunctionScope;
22
+import org.openzen.zenscript.codemodel.scope.StatementScope;
23
+import org.openzen.zenscript.codemodel.statement.Statement;
24
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
25
+import org.openzen.zenscript.codemodel.type.GenericName;
26
+import org.openzen.zenscript.shared.CodePosition;
27
+
28
+/**
29
+ *
30
+ * @author Hoofdgebruiker
31
+ */
32
+public class PreconditionAnnotationDefinition implements AnnotationDefinition {
33
+	public static final PreconditionAnnotationDefinition INSTANCE = new PreconditionAnnotationDefinition();
34
+	
35
+	private final List<GenericName> enforcementLevelName = Arrays.asList(
36
+			new GenericName("stdlib"),
37
+			new GenericName("EnforcementLevel"));
38
+	
39
+	private PreconditionAnnotationDefinition() {}
40
+
41
+	@Override
42
+	public String getAnnotationName() {
43
+		return "Precondition";
44
+	}
45
+
46
+	@Override
47
+	public List<FunctionHeader> getInitializers(BaseScope scope) {
48
+		return Collections.singletonList(new FunctionHeader(
49
+				BasicTypeID.VOID,
50
+				scope.getType(CodePosition.BUILTIN, enforcementLevelName),
51
+				BasicTypeID.BOOL,
52
+				BasicTypeID.STRING));
53
+	}
54
+
55
+	@Override
56
+	public ExpressionScope getScopeForMember(IDefinitionMember member, BaseScope scope) {
57
+		if (member instanceof FunctionalMember) {
58
+			FunctionHeader header = ((FunctionalMember)member).header;
59
+			return new ExpressionScope(new FunctionScope(scope, header));
60
+		} else {
61
+			throw new UnsupportedOperationException("Can only assign preconditions to methods");
62
+		}
63
+	}
64
+
65
+	@Override
66
+	public ExpressionScope getScopeForType(HighLevelDefinition definition, BaseScope scope) {
67
+		if (definition instanceof FunctionDefinition) {
68
+			FunctionHeader header = ((FunctionDefinition)definition).header;
69
+			return new ExpressionScope(new FunctionScope(scope, header));
70
+		} else {
71
+			throw new UnsupportedOperationException("Can only assign preconditions to functions");
72
+		}
73
+	}
74
+
75
+	@Override
76
+	public ExpressionScope getScopeForStatement(Statement statement, StatementScope scope) {
77
+		throw new UnsupportedOperationException("Not supported");
78
+	}
79
+
80
+	@Override
81
+	public ExpressionScope getScopeForParameter(FunctionHeader header, FunctionParameter parameter, BaseScope scope) {
82
+		throw new UnsupportedOperationException("Not supported");
83
+	}
84
+
85
+	@Override
86
+	public MemberAnnotation createForMember(CodePosition position, CallArguments arguments) {
87
+		String enforcement = arguments.arguments[0].evaluateEnumConstant().name;
88
+		Expression condition = arguments.arguments[1];
89
+		Expression message = arguments.arguments[2];
90
+		return new PreconditionForMethod(position, enforcement, condition, message);
91
+	}
92
+
93
+	@Override
94
+	public DefinitionAnnotation createForDefinition(CodePosition position, CallArguments arguments) {
95
+		throw new UnsupportedOperationException("Not supported");
96
+	}
97
+
98
+	@Override
99
+	public StatementAnnotation createForStatement(CodePosition position, CallArguments arguments) {
100
+		throw new UnsupportedOperationException("Not supported");
101
+	}
102
+
103
+	@Override
104
+	public Annotation createForParameter(CodePosition position, CallArguments arguments) {
105
+		throw new UnsupportedOperationException("Not supported");
106
+	}
107
+}

+ 67
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/PreconditionForMethod.java View File

@@ -0,0 +1,67 @@
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.annotations;
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.expression.ExpressionBuilder;
12
+import org.openzen.zenscript.codemodel.member.FunctionalMember;
13
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
14
+import org.openzen.zenscript.codemodel.scope.BaseScope;
15
+import org.openzen.zenscript.codemodel.scope.ExpressionScope;
16
+import org.openzen.zenscript.codemodel.statement.BlockStatement;
17
+import org.openzen.zenscript.codemodel.statement.IfStatement;
18
+import org.openzen.zenscript.codemodel.statement.Statement;
19
+import org.openzen.zenscript.codemodel.statement.ThrowStatement;
20
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
21
+import org.openzen.zenscript.shared.CodePosition;
22
+
23
+/**
24
+ *
25
+ * @author Hoofdgebruiker
26
+ */
27
+public class PreconditionForMethod implements MemberAnnotation {
28
+	private final CodePosition position;
29
+	private final String enforcement;
30
+	private final Expression condition;
31
+	private final Expression message;
32
+	
33
+	public PreconditionForMethod(
34
+			CodePosition position,
35
+			String enforcement,
36
+			Expression condition,
37
+			Expression message) {
38
+		this.position = position;
39
+		this.enforcement = enforcement;
40
+		this.condition = condition;
41
+		this.message = message;
42
+	}
43
+
44
+	@Override
45
+	public void apply(IDefinitionMember member, BaseScope scope) {
46
+		applyOnOverridingMethod((FunctionalMember)member, scope);
47
+	}
48
+
49
+	@Override
50
+	public void applyOnOverridingMethod(FunctionalMember member, BaseScope scope) {
51
+		if (member.body == null)
52
+			return;
53
+		
54
+		ExpressionScope expressionScope = new ExpressionScope(scope, BasicTypeID.BOOL);
55
+		List<Statement> statements = new ArrayList<>();
56
+		ExpressionBuilder expressionBuilder = new ExpressionBuilder(position, expressionScope);
57
+		Expression inverseCondition = expressionBuilder.not(condition);
58
+		Statement throwStatement = new ThrowStatement(CodePosition.BUILTIN, expressionBuilder.constructNew("stdlib.IllegalArgumentException", message));
59
+		statements.add(new IfStatement(CodePosition.BUILTIN, inverseCondition, throwStatement, null));
60
+		if (member.body instanceof BlockStatement) {
61
+			statements.addAll(((BlockStatement)member.body).statements);
62
+		} else {
63
+			statements.add(member.body);
64
+		}
65
+		member.body = new BlockStatement(position, statements);
66
+	}
67
+}

+ 19
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/StatementAnnotation.java View File

@@ -0,0 +1,19 @@
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.annotations;
7
+
8
+import org.openzen.zenscript.codemodel.scope.StatementScope;
9
+import org.openzen.zenscript.codemodel.statement.Statement;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public interface StatementAnnotation {
16
+	public static final StatementAnnotation[] NONE = new StatementAnnotation[0];
17
+	
18
+	public Statement apply(Statement statement, StatementScope scope);
19
+}

+ 13
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallExpression.java View File

@@ -46,4 +46,17 @@ public class CallExpression extends Expression {
46 46
 				? this
47 47
 				: new CallExpression(position, tTarget, member, instancedHeader, tArguments, null);
48 48
 	}
49
+	
50
+	@Override
51
+	public String evaluateStringConstant() {
52
+		if (member.builtin == null)
53
+			throw new UnsupportedOperationException("Cannot evaluate to a string constant!");
54
+		
55
+		switch (member.builtin) {
56
+			case STRING_ADD_STRING:
57
+				return target.evaluateStringConstant() + arguments.arguments[0].evaluateStringConstant();
58
+			default:
59
+				throw new UnsupportedOperationException("Cannot evaluate to a string constant!");
60
+		}
61
+	}
49 62
 }

+ 44
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstExpression.java View File

@@ -0,0 +1,44 @@
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.member.ConstMember;
9
+import org.openzen.zenscript.codemodel.member.EnumConstantMember;
10
+import org.openzen.zenscript.shared.CodePosition;
11
+
12
+/**
13
+ *
14
+ * @author Hoofdgebruiker
15
+ */
16
+public class ConstExpression extends Expression {
17
+	public final ConstMember constant;
18
+	
19
+	public ConstExpression(CodePosition position, ConstMember constant) {
20
+		super(position, constant.type, null);
21
+		
22
+		this.constant = constant;
23
+	}
24
+
25
+	@Override
26
+	public <T> T accept(ExpressionVisitor<T> visitor) {
27
+		return visitor.visitConst(this);
28
+	}
29
+
30
+	@Override
31
+	public Expression transform(ExpressionTransformer transformer) {
32
+		return this;
33
+	}
34
+	
35
+	@Override
36
+	public String evaluateStringConstant() {
37
+		return constant.value.evaluateStringConstant();
38
+	}
39
+	
40
+	@Override
41
+	public EnumConstantMember evaluateEnumConstant() {
42
+		return constant.value.evaluateEnumConstant();
43
+	}
44
+}

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantByteExpression.java View File

@@ -13,9 +13,9 @@ import org.openzen.zenscript.shared.CodePosition;
13 13
  * @author Hoofdgebruiker
14 14
  */
15 15
 public class ConstantByteExpression extends Expression {
16
-	public final byte value;
16
+	public final int value;
17 17
 	
18
-	public ConstantByteExpression(CodePosition position, byte value) {
18
+	public ConstantByteExpression(CodePosition position, int value) {
19 19
 		super(position, BasicTypeID.BYTE, null);
20 20
 		
21 21
 		this.value = value;

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantStringExpression.java View File

@@ -30,4 +30,9 @@ public class ConstantStringExpression extends Expression {
30 30
 	public Expression transform(ExpressionTransformer transformer) {
31 31
 		return this;
32 32
 	}
33
+	
34
+	@Override
35
+	public String evaluateStringConstant() {
36
+		return value;
37
+	}
33 38
 }

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantUShortExpression.java View File

@@ -13,9 +13,9 @@ import org.openzen.zenscript.shared.CodePosition;
13 13
  * @author Hoofdgebruiker
14 14
  */
15 15
 public class ConstantUShortExpression extends Expression {
16
-	public final short value;
16
+	public final int value;
17 17
 	
18
-	public ConstantUShortExpression(CodePosition position, short value) {
18
+	public ConstantUShortExpression(CodePosition position, int value) {
19 19
 		super(position, BasicTypeID.USHORT, null);
20 20
 		
21 21
 		this.value = value;

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/EnumConstantExpression.java View File

@@ -39,4 +39,9 @@ public class EnumConstantExpression extends Expression {
39 39
 	public Expression transform(ExpressionTransformer transformer) {
40 40
 		return this;
41 41
 	}
42
+	
43
+	@Override
44
+	public EnumConstantMember evaluateEnumConstant() {
45
+		return value;
46
+	}
42 47
 }

+ 40
- 5
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/Expression.java View File

@@ -7,17 +7,20 @@ package org.openzen.zenscript.codemodel.expression;
7 7
 
8 8
 import java.util.Collections;
9 9
 import java.util.List;
10
-import java.util.Map;
10
+import java.util.function.Consumer;
11 11
 import java.util.stream.Collectors;
12 12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
-import org.openzen.zenscript.codemodel.FunctionParameter;
14 13
 import org.openzen.zenscript.codemodel.OperatorType;
14
+import org.openzen.zenscript.codemodel.member.EnumConstantMember;
15 15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
16 16
 import org.openzen.zenscript.codemodel.type.GenericName;
17 17
 import org.openzen.zenscript.codemodel.type.ITypeID;
18 18
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
19 19
 import org.openzen.zenscript.shared.CodePosition;
20 20
 import org.openzen.zenscript.codemodel.scope.TypeScope;
21
+import org.openzen.zenscript.codemodel.statement.Statement;
22
+import org.openzen.zenscript.codemodel.statement.StatementTransformer;
23
+import org.openzen.zenscript.codemodel.type.FunctionTypeID;
21 24
 import org.openzen.zenscript.shared.CompileException;
22 25
 import org.openzen.zenscript.shared.CompileExceptionCode;
23 26
 
@@ -26,6 +29,8 @@ import org.openzen.zenscript.shared.CompileExceptionCode;
26 29
  * @author Hoofdgebruiker
27 30
  */
28 31
 public abstract class Expression implements IPartialExpression {
32
+	public static final Expression[] NONE = new Expression[0];
33
+	
29 34
 	public final CodePosition position;
30 35
 	public final ITypeID type;
31 36
 	public final ITypeID thrownType;
@@ -40,6 +45,21 @@ public abstract class Expression implements IPartialExpression {
40 45
 	
41 46
 	public abstract Expression transform(ExpressionTransformer transformer);
42 47
 	
48
+	public final Expression transform(StatementTransformer transformer) {
49
+		return transform((ExpressionTransformer)expression -> {
50
+			if (expression instanceof FunctionExpression) {
51
+				FunctionExpression function = (FunctionExpression)expression;
52
+				Statement body = function.body.transform(transformer);
53
+				if (body == function.body)
54
+					return function;
55
+				
56
+				return new FunctionExpression(function.position, (FunctionTypeID)function.type, function.closure, body);
57
+			} else {
58
+				return expression;
59
+			}
60
+		});
61
+	}
62
+	
43 63
 	@Override
44 64
 	public List<ITypeID> getAssignHints() {
45 65
 		return Collections.singletonList(type);
@@ -68,8 +88,8 @@ public abstract class Expression implements IPartialExpression {
68 88
 		return scope.getTypeMembers(type)
69 89
 				.getOrCreateGroup(OperatorType.CALL)
70 90
 				.getMethodMembers().stream()
71
-				.filter(method -> method.member.getHeader().parameters.length == arguments && !method.member.isStatic())
72
-				.map(method -> method.member.getHeader())
91
+				.filter(method -> method.member.header.parameters.length == arguments && !method.member.isStatic())
92
+				.map(method -> method.member.header)
73 93
 				.collect(Collectors.toList());
74 94
 	}
75 95
 	
@@ -81,7 +101,10 @@ public abstract class Expression implements IPartialExpression {
81 101
 	@Override
82 102
 	public IPartialExpression getMember(CodePosition position, TypeScope scope, List<ITypeID> hints, GenericName name) {
83 103
 		TypeMembers members = scope.getTypeMembers(type);
84
-		return members.getMemberExpression(position, this, name, false);
104
+		IPartialExpression result = members.getMemberExpression(position, this, name, false);
105
+		if (result == null)
106
+			System.out.println("No such member: " + name.name);
107
+		return result;
85 108
 	}
86 109
 	
87 110
 	@Override
@@ -89,6 +112,18 @@ public abstract class Expression implements IPartialExpression {
89 112
 		return null;
90 113
 	}
91 114
 	
115
+	public void forEachStatement(Consumer<Statement> consumer) {
116
+		
117
+	}
118
+	
119
+	public String evaluateStringConstant() {
120
+		throw new UnsupportedOperationException("Cannot evaluate this value to a string constant!");
121
+	}
122
+	
123
+	public EnumConstantMember evaluateEnumConstant() {
124
+		throw new UnsupportedOperationException("Cannot evaluate this value to an enum constant!");
125
+	}
126
+	
92 127
 	public static ITypeID binaryThrow(CodePosition position, ITypeID left, ITypeID right) {
93 128
 		if (left == right)
94 129
 			return left;

+ 72
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionBuilder.java View File

@@ -0,0 +1,72 @@
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 java.util.ArrayList;
9
+import java.util.List;
10
+import org.openzen.zenscript.codemodel.OperatorType;
11
+import org.openzen.zenscript.codemodel.member.ConstructorMember;
12
+import org.openzen.zenscript.codemodel.member.FunctionalMember;
13
+import org.openzen.zenscript.codemodel.scope.ExpressionScope;
14
+import org.openzen.zenscript.codemodel.type.GenericName;
15
+import org.openzen.zenscript.codemodel.type.ITypeID;
16
+import org.openzen.zenscript.codemodel.type.member.DefinitionMemberGroup;
17
+import org.openzen.zenscript.codemodel.type.member.TypeMembers;
18
+import org.openzen.zenscript.shared.CodePosition;
19
+import org.openzen.zenscript.shared.CompileException;
20
+import org.openzen.zenscript.shared.CompileExceptionCode;
21
+import org.openzen.zenscript.shared.StringUtils;
22
+
23
+/**
24
+ *
25
+ * @author Hoofdgebruiker
26
+ */
27
+public class ExpressionBuilder {
28
+	public final CodePosition position;
29
+	public final ExpressionScope scope;
30
+	
31
+	public ExpressionBuilder(CodePosition position, ExpressionScope scope) {
32
+		this.position = position;
33
+		this.scope = scope;
34
+	}
35
+	
36
+	public Expression constructNew(String typename, Expression... arguments) {
37
+		List<String> nameParts = StringUtils.split(typename, '.');
38
+		List<GenericName> name = new ArrayList<>();
39
+		for (String namePart : nameParts)
40
+			name.add(new GenericName(namePart));
41
+		ITypeID type = scope.getType(position, name);
42
+		if (type == null)
43
+			throw new CompileException(position, CompileExceptionCode.NO_SUCH_TYPE, "No such type: " + typename);
44
+		
45
+		return constructNew(type, arguments);
46
+	}
47
+	
48
+	public Expression constructNew(ITypeID type, Expression... arguments) {
49
+		DefinitionMemberGroup constructors = scope.getTypeMembers(type).getOrCreateGroup(OperatorType.CONSTRUCTOR);
50
+		List<ITypeID>[] predictedTypes = constructors.predictCallTypes(scope, scope.hints, arguments.length);
51
+		CallArguments compiledArguments = new CallArguments(arguments);
52
+		FunctionalMember member = constructors.selectMethod(position, scope, compiledArguments, true, true);
53
+		if (member == null)
54
+			throw new CompileException(position, CompileExceptionCode.CALL_NO_VALID_METHOD, "No matching constructor found");
55
+		if (!(member instanceof ConstructorMember))
56
+			throw new CompileException(position, CompileExceptionCode.INTERNAL_ERROR, "COMPILER BUG: constructor is not a constructor");
57
+		
58
+		return new NewExpression(
59
+				position,
60
+				type,
61
+				(ConstructorMember) member,
62
+				compiledArguments,
63
+				compiledArguments.getNumberOfTypeArguments() == 0 ? member.header : member.header.withGenericArguments(scope.getTypeRegistry(), compiledArguments.typeArguments),
64
+				scope);
65
+	}
66
+	
67
+	public Expression not(Expression value) {
68
+		TypeMembers members = scope.getTypeMembers(value.type);
69
+		return members.getOrCreateGroup(OperatorType.NOT)
70
+				.call(position, scope, value, CallArguments.EMPTY, false);
71
+	}
72
+}

+ 2
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionVisitor.java View File

@@ -38,6 +38,8 @@ public interface ExpressionVisitor<T> {
38 38
 	
39 39
 	public T visitConditional(ConditionalExpression expression);
40 40
 	
41
+	public T visitConst(ConstExpression expression);
42
+	
41 43
 	public T visitConstantBool(ConstantBoolExpression expression);
42 44
 	
43 45
 	public T visitConstantByte(ConstantByteExpression expression);

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/FunctionExpression.java View File

@@ -7,6 +7,7 @@ package org.openzen.zenscript.codemodel.expression;
7 7
 
8 8
 import java.util.HashMap;
9 9
 import java.util.Map;
10
+import java.util.function.Consumer;
10 11
 import org.openzen.zenscript.codemodel.FunctionHeader;
11 12
 import org.openzen.zenscript.codemodel.FunctionParameter;
12 13
 import org.openzen.zenscript.codemodel.statement.ExpressionStatement;
@@ -48,6 +49,11 @@ public class FunctionExpression extends Expression {
48 49
 		return tBody == body ? this : new FunctionExpression(position, (FunctionTypeID)type, closure, tBody);
49 50
 	}
50 51
 	
52
+	@Override
53
+	public void forEachStatement(Consumer<Statement> consumer) {
54
+		body.forEachStatement(consumer);
55
+	}
56
+	
51 57
 	/**
52 58
 	 * Checks if this is a simple function expression. A simple function
53 59
 	 * expression consists of a body with just a expression or return statement.

+ 3
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/VariantValueExpression.java View File

@@ -20,14 +20,14 @@ public class VariantValueExpression extends Expression {
20 20
 	public final Expression[] arguments;
21 21
 	
22 22
 	public VariantValueExpression(CodePosition position, ITypeID variantType, VariantDefinition.Option option) {
23
-		this(position, variantType, option, null);
23
+		this(position, variantType, option, Expression.NONE);
24 24
 	}
25 25
 	
26 26
 	public VariantValueExpression(CodePosition position, ITypeID variantType, VariantDefinition.Option option, Expression[] arguments) {
27
-		super(position, variantType, arguments == null ? null : multiThrow(position, arguments));
27
+		super(position, variantType, multiThrow(position, arguments));
28 28
 		
29 29
 		this.option = option;
30
-		this.arguments = null;
30
+		this.arguments = arguments;
31 31
 	}
32 32
 	
33 33
 	public int getNumberOfArguments() {

+ 2
- 5
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CasterMember.java View File

@@ -25,7 +25,7 @@ import org.openzen.zenscript.shared.CodePosition;
25 25
  *
26 26
  * @author Hoofdgebruiker
27 27
  */
28
-public class CasterMember extends FunctionalMember implements ICasterMember {
28
+public class CasterMember extends FunctionalMember {
29 29
 	public final ITypeID toType;
30 30
 	
31 31
 	public CasterMember(
@@ -65,7 +65,6 @@ public class CasterMember extends FunctionalMember implements ICasterMember {
65 65
 				builtin);
66 66
 	}
67 67
 	
68
-	@Override
69 68
 	public ITypeID getTargetType() {
70 69
 		return toType;
71 70
 	}
@@ -74,13 +73,11 @@ public class CasterMember extends FunctionalMember implements ICasterMember {
74 73
 	public Expression call(CodePosition position, Expression target, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope) {
75 74
 		throw new UnsupportedOperationException("Cannot call a caster!");
76 75
 	}
77
-
78
-	@Override
76
+	
79 77
 	public Expression cast(CodePosition position, Expression value, boolean implicit) {
80 78
 		return new CastExpression(position, value, this, implicit);
81 79
 	}
82 80
 	
83
-	@Override
84 81
 	public boolean isImplicit() {
85 82
 		return Modifiers.isImplicit(modifiers);
86 83
 	}

+ 61
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ConstMember.java View File

@@ -0,0 +1,61 @@
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.HighLevelDefinition;
10
+import org.openzen.zenscript.codemodel.expression.Expression;
11
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
13
+import org.openzen.zenscript.codemodel.type.ITypeID;
14
+import org.openzen.zenscript.codemodel.type.member.BuiltinID;
15
+import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
16
+import org.openzen.zenscript.codemodel.type.member.TypeMembers;
17
+import org.openzen.zenscript.shared.CodePosition;
18
+
19
+/**
20
+ *
21
+ * @author Hoofdgebruiker
22
+ */
23
+public class ConstMember extends DefinitionMember {
24
+	public final String name;
25
+	public final ITypeID type;
26
+	public Expression value;
27
+	public final BuiltinID builtin;
28
+	
29
+	public ConstMember(CodePosition position, HighLevelDefinition definition, int modifiers, String name, ITypeID type, BuiltinID builtin) {
30
+		super(position, definition, modifiers);
31
+		
32
+		this.name = name;
33
+		this.type = type;
34
+		this.builtin = builtin;
35
+	}
36
+
37
+	@Override
38
+	public String describe() {
39
+		return "const " + name;
40
+	}
41
+
42
+	@Override
43
+	public BuiltinID getBuiltin() {
44
+		return builtin;
45
+	}
46
+
47
+	@Override
48
+	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
49
+		type.addConst(this);
50
+	}
51
+
52
+	@Override
53
+	public IDefinitionMember instance(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> mapping) {
54
+		return this;
55
+	}
56
+
57
+	@Override
58
+	public <T> T accept(MemberVisitor<T> visitor) {
59
+		return visitor.visitConst(this);
60
+	}
61
+}

+ 0
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ConstructorMember.java View File

@@ -76,8 +76,6 @@ public class ConstructorMember extends FunctionalMember {
76 76
 				modifiers,
77 77
 				header.instance(registry, mapping),
78 78
 				builtin);
79
-		if (definition.name.equals("NFAState"))
80
-			System.out.println("X");
81 79
 		return result;
82 80
 	}
83 81
 

+ 2
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/DefinitionMember.java View File

@@ -7,6 +7,7 @@ package org.openzen.zenscript.codemodel.member;
7 7
 
8 8
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
9 9
 import org.openzen.zenscript.codemodel.Modifiers;
10
+import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
10 11
 import org.openzen.zenscript.shared.CodePosition;
11 12
 import org.openzen.zenscript.shared.Taggable;
12 13
 
@@ -18,6 +19,7 @@ public abstract class DefinitionMember extends Taggable implements IDefinitionMe
18 19
 	public final CodePosition position;
19 20
 	public final HighLevelDefinition definition;
20 21
 	public final int modifiers;
22
+	public MemberAnnotation[] annotations = MemberAnnotation.NONE;
21 23
 	
22 24
 	public DefinitionMember(CodePosition position, HighLevelDefinition definition, int modifiers) {
23 25
 		this.position = position;

+ 5
- 10
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FunctionalMember.java View File

@@ -23,11 +23,12 @@ import org.openzen.zenscript.shared.CodePosition;
23 23
  *
24 24
  * @author Hoofdgebruiker
25 25
  */
26
-public abstract class FunctionalMember extends DefinitionMember implements ICallableMember {
26
+public abstract class FunctionalMember extends DefinitionMember {
27 27
 	public final FunctionHeader header;
28 28
 	public final String name;
29 29
 	public final BuiltinID builtin;
30
-	public Statement body;
30
+	public Statement body = null;
31
+	public FunctionalMember overrides = null;
31 32
 	
32 33
 	public FunctionalMember(
33 34
 			CodePosition position,
@@ -47,17 +48,13 @@ public abstract class FunctionalMember extends DefinitionMember implements ICall
47 48
 		this.body = body;
48 49
 	}
49 50
 	
50
-	@Override
51
-	public FunctionHeader getHeader() {
52
-		return header;
53
-	}
51
+	public abstract String getInformalName();
54 52
 	
55 53
 	@Override
56 54
 	public BuiltinID getBuiltin() {
57 55
 		return builtin;
58 56
 	}
59
-
60
-	@Override
57
+	
61 58
 	public Expression call(CodePosition position, Expression target, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope) {
62 59
 		return new CallExpression(position, target, this, instancedHeader, arguments, scope);
63 60
 	}
@@ -66,12 +63,10 @@ public abstract class FunctionalMember extends DefinitionMember implements ICall
66 63
 		return call(position, target, header, arguments, scope);
67 64
 	}
68 65
 	
69
-	@Override
70 66
 	public Expression callWithComparator(CodePosition position, CompareType comparison, Expression target, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope) {
71 67
 		return new CompareExpression(position, target, arguments.arguments[0], this, comparison, scope);
72 68
 	}
73 69
 	
74
-	@Override
75 70
 	public Expression callStatic(CodePosition position, ITypeID target, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope) {
76 71
 		return new CallStaticExpression(position, target, this, arguments, instancedHeader, scope);
77 72
 	}

+ 2
- 14
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/GetterMember.java View File

@@ -23,7 +23,7 @@ import org.openzen.zenscript.shared.CodePosition;
23 23
  *
24 24
  * @author Hoofdgebruiker
25 25
  */
26
-public class GetterMember extends FunctionalMember implements IGettableMember {
26
+public class GetterMember extends FunctionalMember {
27 27
 	public final String name;
28 28
 	public final ITypeID type;
29 29
 	
@@ -44,27 +44,15 @@ public class GetterMember extends FunctionalMember implements IGettableMember {
44 44
 	public String getInformalName() {
45 45
 		return "getter " + name;
46 46
 	}
47
-
48
-	@Override
49
-	public String getName() {
50
-		return name;
51
-	}
52
-	
53
-	@Override
54
-	public ITypeID getType() {
55
-		return type;
56
-	}
57 47
 	
58
-	@Override
59 48
 	public Expression get(CodePosition position, Expression target) {
60 49
 		return new GetterExpression(position, target, this);
61 50
 	}
62 51
 	
63
-	@Override
64 52
 	public Expression getStatic(CodePosition position) {
65 53
 		return new StaticGetterExpression(position, this);
66 54
 	}
67
-
55
+	
68 56
 	@Override
69 57
 	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
70 58
 		type.addGetter(this, priority);

+ 0
- 32
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ICallableMember.java View File

@@ -1,32 +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.member;
7
-
8
-import org.openzen.zenscript.codemodel.CompareType;
9
-import org.openzen.zenscript.codemodel.FunctionHeader;
10
-import org.openzen.zenscript.codemodel.expression.CallArguments;
11
-import org.openzen.zenscript.codemodel.expression.Expression;
12
-import org.openzen.zenscript.codemodel.scope.TypeScope;
13
-import org.openzen.zenscript.codemodel.type.ITypeID;
14
-import org.openzen.zenscript.shared.CodePosition;
15
-
16
-/**
17
- *
18
- * @author Hoofdgebruiker
19
- */
20
-public interface ICallableMember extends IDefinitionMember {
21
-	public boolean isStatic();
22
-	
23
-	public String getInformalName();
24
-	
25
-	public FunctionHeader getHeader();
26
-	
27
-	public Expression call(CodePosition position, Expression target, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope);
28
-	
29
-	public Expression callWithComparator(CodePosition position, CompareType operator, Expression target, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope);
30
-	
31
-	public Expression callStatic(CodePosition position, ITypeID target, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope);
32
-}

+ 0
- 22
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ICasterMember.java View File

@@ -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.member;
7
-
8
-import org.openzen.zenscript.codemodel.expression.Expression;
9
-import org.openzen.zenscript.codemodel.type.ITypeID;
10
-import org.openzen.zenscript.shared.CodePosition;
11
-
12
-/**
13
- *
14
- * @author Hoofdgebruiker
15
- */
16
-public interface ICasterMember extends IDefinitionMember {
17
-	public ITypeID getTargetType();
18
-	
19
-	public Expression cast(CodePosition position, Expression value, boolean implicit);
20
-	
21
-	public boolean isImplicit();
22
-}

+ 0
- 26
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/IGettableMember.java View File

@@ -1,26 +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.member;
7
-
8
-import org.openzen.zenscript.codemodel.expression.Expression;
9
-import org.openzen.zenscript.codemodel.type.ITypeID;
10
-import org.openzen.zenscript.shared.CodePosition;
11
-
12
-/**
13
- *
14
- * @author Hoofdgebruiker
15
- */
16
-public interface IGettableMember extends IDefinitionMember {
17
-	public String getName();
18
-	
19
-	public boolean isStatic();
20
-	
21
-	public ITypeID getType();
22
-	
23
-	public Expression get(CodePosition position, Expression target);
24
-	
25
-	public Expression getStatic(CodePosition position);
26
-}

+ 2
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/MemberVisitor.java View File

@@ -10,6 +10,8 @@ package org.openzen.zenscript.codemodel.member;
10 10
  * @author Hoofdgebruiker
11 11
  */
12 12
 public interface MemberVisitor<T> {
13
+	public T visitConst(ConstMember member);
14
+	
13 15
 	public T visitField(FieldMember member);
14 16
 	
15 17
 	public T visitConstructor(ConstructorMember member);

+ 2
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/StaticInitializerMember.java View File

@@ -6,6 +6,7 @@
6 6
 package org.openzen.zenscript.codemodel.member;
7 7
 
8 8
 import java.util.Map;
9
+import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
9 10
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
10 11
 import org.openzen.zenscript.codemodel.statement.Statement;
11 12
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
@@ -23,6 +24,7 @@ import org.openzen.zenscript.shared.Taggable;
23 24
 public class StaticInitializerMember extends Taggable implements IDefinitionMember {
24 25
 	private final CodePosition position;
25 26
 	public Statement body;
27
+	public MemberAnnotation[] annotations = MemberAnnotation.NONE;
26 28
 	
27 29
 	public StaticInitializerMember(CodePosition position) {
28 30
 		this.position = position;

+ 0
- 94
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/ConstantGetterMember.java View File

@@ -1,94 +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.member.builtin;
7
-
8
-import java.util.Map;
9
-import java.util.function.Function;
10
-import org.openzen.zenscript.shared.CompileException;
11
-import org.openzen.zenscript.shared.CompileExceptionCode;
12
-import org.openzen.zenscript.codemodel.expression.Expression;
13
-import org.openzen.zenscript.codemodel.generic.TypeParameter;
14
-import org.openzen.zenscript.codemodel.member.IDefinitionMember;
15
-import org.openzen.zenscript.codemodel.member.IGettableMember;
16
-import org.openzen.zenscript.codemodel.member.MemberVisitor;
17
-import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
18
-import org.openzen.zenscript.codemodel.type.ITypeID;
19
-import org.openzen.zenscript.codemodel.type.member.BuiltinID;
20
-import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
21
-import org.openzen.zenscript.codemodel.type.member.TypeMembers;
22
-import org.openzen.zenscript.shared.CodePosition;
23
-import org.openzen.zenscript.shared.Taggable;
24
-
25
-/**
26
- *
27
- * @author Hoofdgebruiker
28
- */
29
-public class ConstantGetterMember extends Taggable implements IGettableMember {
30
-	private final String name;
31
-	private final Function<CodePosition, Expression> value;
32
-	private final ITypeID type;
33
-	
34
-	public ConstantGetterMember(String name, Function<CodePosition, Expression> value) {
35
-		this.name = name;
36
-		this.value = value;
37
-		this.type = value.apply(CodePosition.BUILTIN).type;
38
-	}
39
-	
40
-	@Override
41
-	public CodePosition getPosition() {
42
-		return CodePosition.BUILTIN;
43
-	}
44
-	
45
-	@Override
46
-	public BuiltinID getBuiltin() {
47
-		return null;
48
-	}
49
-	
50
-	@Override
51
-	public String getName() {
52
-		return name;
53
-	}
54
-	
55
-	@Override
56
-	public ITypeID getType() {
57
-		return type;
58
-	}
59
-	
60
-	@Override
61
-	public boolean isStatic() {
62
-		return true;
63
-	}
64
-	
65
-	@Override
66
-	public Expression get(CodePosition position, Expression target) {
67
-		throw new CompileException(position, CompileExceptionCode.USING_STATIC_ON_INSTANCE, "Not an instance member");
68
-	}
69
-	
70
-	@Override
71
-	public Expression getStatic(CodePosition position) {
72
-		return value.apply(position);
73
-	}
74
-
75
-	@Override
76
-	public String describe() {
77
-		return "constant getter " + name;
78
-	}
79
-
80
-	@Override
81
-	public void registerTo(TypeMembers type, TypeMemberPriority priority) {
82
-		type.addGetter(this, priority);
83
-	}
84
-
85
-	@Override
86
-	public IDefinitionMember instance(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> mapping) {
87
-		return this; // not instancable
88
-	}
89
-
90
-	@Override
91
-	public <T> T accept(MemberVisitor<T> visitor) {
92
-		throw new UnsupportedOperationException("Not a compilable member");
93
-	}
94
-}

+ 4
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialMemberGroupExpression.java View File

@@ -12,7 +12,7 @@ import org.openzen.zenscript.codemodel.FunctionHeader;
12 12
 import org.openzen.zenscript.codemodel.expression.CallArguments;
13 13
 import org.openzen.zenscript.codemodel.expression.Expression;
14 14
 import org.openzen.zenscript.codemodel.expression.LambdaClosure;
15
-import org.openzen.zenscript.codemodel.member.ICallableMember;
15
+import org.openzen.zenscript.codemodel.member.FunctionalMember;
16 16
 import org.openzen.zenscript.codemodel.type.member.DefinitionMemberGroup;
17 17
 import org.openzen.zenscript.codemodel.type.GenericName;
18 18
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -38,7 +38,7 @@ public class PartialMemberGroupExpression implements IPartialExpression {
38 38
 		this.allowStaticUsage = allowStaticMembers;
39 39
 	}
40 40
 	
41
-	public PartialMemberGroupExpression(CodePosition position, Expression target, ICallableMember member, ITypeID[] typeArguments, boolean allowStaticMembers) {
41
+	public PartialMemberGroupExpression(CodePosition position, Expression target, FunctionalMember member, ITypeID[] typeArguments, boolean allowStaticMembers) {
42 42
 		this.position = position;
43 43
 		this.target = target;
44 44
 		this.group = DefinitionMemberGroup.forMethod(member);
@@ -69,8 +69,8 @@ public class PartialMemberGroupExpression implements IPartialExpression {
69 69
 	@Override
70 70
 	public List<FunctionHeader> getPossibleFunctionHeaders(TypeScope scope, List<ITypeID> hints, int arguments) {
71 71
 		List<FunctionHeader> results = group.getMethodMembers().stream()
72
-				.filter(method -> method.member.getHeader().parameters.length == arguments && !method.member.isStatic())
73
-				.map(method -> method.member.getHeader())
72
+				.filter(method -> method.member.header.parameters.length == arguments && !method.member.isStatic())
73
+				.map(method -> method.member.header)
74 74
 				.collect(Collectors.toList());
75 75
 		if (results.isEmpty())
76 76
 			System.out.println("!");

+ 4
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialStaticMemberGroupExpression.java View File

@@ -11,7 +11,7 @@ import java.util.stream.Collectors;
11 11
 import org.openzen.zenscript.codemodel.FunctionHeader;
12 12
 import org.openzen.zenscript.codemodel.expression.CallArguments;
13 13
 import org.openzen.zenscript.codemodel.expression.Expression;
14
-import org.openzen.zenscript.codemodel.member.ICallableMember;
14
+import org.openzen.zenscript.codemodel.member.FunctionalMember;
15 15
 import org.openzen.zenscript.codemodel.type.member.DefinitionMemberGroup;
16 16
 import org.openzen.zenscript.codemodel.type.GenericName;
17 17
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -24,7 +24,7 @@ import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
24 24
  * @author Hoofdgebruiker
25 25
  */
26 26
 public class PartialStaticMemberGroupExpression implements IPartialExpression {
27
-	public static PartialStaticMemberGroupExpression forMethod(CodePosition position, ITypeID target, ICallableMember method, ITypeID[] typeArguments) {
27
+	public static PartialStaticMemberGroupExpression forMethod(CodePosition position, ITypeID target, FunctionalMember method, ITypeID[] typeArguments) {
28 28
 		DefinitionMemberGroup group = new DefinitionMemberGroup(true, method.getInformalName());
29 29
 		group.addMethod(method, TypeMemberPriority.SPECIFIED);
30 30
 		return new PartialStaticMemberGroupExpression(position, target, group, typeArguments);
@@ -55,8 +55,8 @@ public class PartialStaticMemberGroupExpression implements IPartialExpression {
55 55
 	@Override
56 56
 	public List<FunctionHeader> getPossibleFunctionHeaders(TypeScope scope, List<ITypeID> hints, int arguments) {
57 57
 		return group.getMethodMembers().stream()
58
-				.filter(method -> method.member.getHeader().parameters.length == arguments && method.member.isStatic())
59
-				.map(method -> method.member.getHeader())
58
+				.filter(method -> method.member.header.parameters.length == arguments && method.member.isStatic())
59
+				.map(method -> method.member.header)
60 60
 				.collect(Collectors.toList());
61 61
 	}
62 62
 

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialTypeExpression.java View File

@@ -49,8 +49,8 @@ public class PartialTypeExpression implements IPartialExpression {
49 49
 		return scope.getTypeMembers(type)
50 50
 				.getOrCreateGroup(OperatorType.CALL)
51 51
 				.getMethodMembers().stream()
52
-				.filter(method -> method.member.getHeader().parameters.length == arguments && method.member.isStatic())
53
-				.map(method -> method.member.getHeader())
52
+				.filter(method -> method.member.header.parameters.length == arguments && method.member.isStatic())
53
+				.map(method -> method.member.header)
54 54
 				.collect(Collectors.toList());
55 55
 	}
56 56
 

+ 19
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/processor/InterfaceProcessor.java View File

@@ -0,0 +1,19 @@
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.processor;
7
+
8
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
9
+import org.openzen.zenscript.codemodel.member.ImplementationMember;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public interface InterfaceProcessor {
16
+	public void apply(ImplementationMember implementation);
17
+
18
+	public void applyOnSubclass(HighLevelDefinition definition, ImplementationMember implementation);
19
+}

Linker/src/main/java/org/openzen/zenscript/linker/BaseScope.java → CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/BaseScope.java View File

@@ -3,14 +3,13 @@
3 3
  * To change this template file, choose Tools | Templates
4 4
  * and open the template in the editor.
5 5
  */
6
-package org.openzen.zenscript.linker;
6
+package org.openzen.zenscript.codemodel.scope;
7 7
 
8 8
 import java.util.List;
9 9
 import java.util.function.Function;
10 10
 import org.openzen.zenscript.codemodel.FunctionHeader;
11 11
 import org.openzen.zenscript.codemodel.expression.Expression;
12 12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13
-import org.openzen.zenscript.codemodel.scope.TypeScope;
14 13
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
15 14
 import org.openzen.zenscript.codemodel.type.GenericName;
16 15
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;

Linker/src/main/java/org/openzen/zenscript/linker/BlockScope.java → CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/BlockScope.java View File

@@ -3,10 +3,11 @@
3 3
  * To change this template file, choose Tools | Templates
4 4
  * and open the template in the editor.
5 5
  */
6
-package org.openzen.zenscript.linker;
6
+package org.openzen.zenscript.codemodel.scope;
7 7
 
8 8
 import java.util.List;
9 9
 import java.util.function.Function;
10
+import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
10 11
 import org.openzen.zenscript.codemodel.FunctionHeader;
11 12
 import org.openzen.zenscript.codemodel.expression.Expression;
12 13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
@@ -70,4 +71,9 @@ public class BlockScope extends StatementScope {
70 71
 	public IPartialExpression getOuterInstance(CodePosition position) {
71 72
 		return parent.getOuterInstance(position);
72 73
 	}
74
+
75
+	@Override
76
+	public AnnotationDefinition getAnnotation(String name) {
77
+		return parent.getAnnotation(name);
78
+	}
73 79
 }

Linker/src/main/java/org/openzen/zenscript/linker/DefinitionScope.java → CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/DefinitionScope.java View File

@@ -3,12 +3,13 @@
3 3
  * To change this template file, choose Tools | Templates
4 4
  * and open the template in the editor.
5 5
  */
6
-package org.openzen.zenscript.linker;
6
+package org.openzen.zenscript.codemodel.scope;
7 7
 
8 8
 import java.util.HashMap;
9 9
 import java.util.List;
10 10
 import java.util.Map;
11 11
 import java.util.function.Function;
12
+import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12 13
 
13 14
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
14 15
 import org.openzen.zenscript.shared.CompileException;
@@ -131,4 +132,9 @@ public class DefinitionScope extends BaseScope {
131 132
 			throw new UnsupportedOperationException("not yet supported");
132 133
 		}
133 134
 	}
135
+
136
+	@Override
137
+	public AnnotationDefinition getAnnotation(String name) {
138
+		return outer.getAnnotation(name);
139
+	}
134 140
 }

Linker/src/main/java/org/openzen/zenscript/linker/ExpressionScope.java → CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ExpressionScope.java View File

@@ -3,13 +3,14 @@
3 3
  * To change this template file, choose Tools | Templates
4 4
  * and open the template in the editor.
5 5
  */
6
-package org.openzen.zenscript.linker;
6
+package org.openzen.zenscript.codemodel.scope;
7 7
 
8 8
 import java.util.Collections;
9 9
 import java.util.HashMap;
10 10
 import java.util.List;
11 11
 import java.util.Map;
12 12
 import java.util.function.Function;
13
+import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
13 14
 import org.openzen.zenscript.codemodel.FunctionHeader;
14 15
 import org.openzen.zenscript.codemodel.expression.Expression;
15 16
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
@@ -62,6 +63,19 @@ public class ExpressionScope extends BaseScope {
62 63
 		this.genericInferenceMap = genericInferenceMap;
63 64
 	}
64 65
 	
66
+	private ExpressionScope(
67
+			BaseScope scope,
68
+			List<ITypeID> hints,
69
+			Function<CodePosition, Expression> dollar,
70
+			Map<TypeParameter, ITypeID> genericInferenceMap,
71
+			Map<String, VarStatement> innerVariables) {
72
+		this.outer = scope;
73
+		this.hints = hints;
74
+		this.dollar = dollar;
75
+		this.genericInferenceMap = genericInferenceMap;
76
+		this.innerVariables.putAll(innerVariables);
77
+	}
78
+	
65 79
 	public void addInnerVariable(VarStatement variable) {
66 80
 		innerVariables.put(variable.name, variable);
67 81
 	}
@@ -71,19 +85,19 @@ public class ExpressionScope extends BaseScope {
71 85
 	}
72 86
 	
73 87
 	public ExpressionScope withoutHints() {
74
-		return new ExpressionScope(outer, Collections.emptyList(), dollar, genericInferenceMap);
88
+		return new ExpressionScope(outer, Collections.emptyList(), dollar, genericInferenceMap, innerVariables);
75 89
 	}
76 90
 	
77 91
 	public ExpressionScope withHint(ITypeID hint) {
78
-		return new ExpressionScope(outer, Collections.singletonList(hint), dollar, genericInferenceMap);
92
+		return new ExpressionScope(outer, Collections.singletonList(hint), dollar, genericInferenceMap, innerVariables);
79 93
 	}
80 94
 	
81 95
 	public ExpressionScope withHints(List<ITypeID> hints) {
82
-		return new ExpressionScope(outer, hints, dollar, genericInferenceMap);
96
+		return new ExpressionScope(outer, hints, dollar, genericInferenceMap, innerVariables);
83 97
 	}
84 98
 	
85 99
 	public ExpressionScope createInner(List<ITypeID> hints, Function<CodePosition, Expression> dollar) {
86
-		return new ExpressionScope(outer, hints, dollar, genericInferenceMap);
100
+		return new ExpressionScope(outer, hints, dollar, genericInferenceMap, innerVariables);
87 101
 	}
88 102
 	
89 103
 	public ExpressionScope forCall(FunctionHeader header) {
@@ -94,7 +108,7 @@ public class ExpressionScope extends BaseScope {
94 108
 		for (TypeParameter parameter : header.typeParameters)
95 109
 			genericInferenceMap.put(parameter, null);
96 110
 		
97
-		return new ExpressionScope(outer, hints, dollar, genericInferenceMap);
111
+		return new ExpressionScope(outer, hints, dollar, genericInferenceMap, innerVariables);
98 112
 	}
99 113
 	
100 114
 	@Override
@@ -139,4 +153,9 @@ public class ExpressionScope extends BaseScope {
139 153
 	public IPartialExpression getOuterInstance(CodePosition position) {
140 154
 		return outer.getOuterInstance(position);
141 155
 	}
156
+
157
+	@Override
158
+	public AnnotationDefinition getAnnotation(String name) {
159
+		return outer.getAnnotation(name);
160
+	}
142 161
 }

Linker/src/main/java/org/openzen/zenscript/linker/FileScope.java → CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FileScope.java View File

@@ -3,13 +3,14 @@
3 3
  * To change this template file, choose Tools | Templates
4 4
  * and open the template in the editor.
5 5
  */
6
-package org.openzen.zenscript.linker;
6
+package org.openzen.zenscript.codemodel.scope;
7 7
 
8 8
 import java.util.HashMap;
9 9
 import java.util.List;
10 10
 import java.util.Map;
11 11
 import java.util.function.Function;
12 12
 import org.openzen.zenscript.codemodel.AccessScope;
13
+import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
13 14
 import org.openzen.zenscript.codemodel.FunctionHeader;
14 15
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
15 16
 import org.openzen.zenscript.codemodel.PackageDefinitions;
@@ -23,9 +24,9 @@ import org.openzen.zenscript.codemodel.statement.LoopStatement;
23 24
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
24 25
 import org.openzen.zenscript.codemodel.type.GenericName;
25 26
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
27
+import org.openzen.zenscript.codemodel.type.ISymbol;
26 28
 import org.openzen.zenscript.codemodel.type.ITypeID;
27 29
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
28
-import org.openzen.zenscript.linker.symbol.ISymbol;
29 30
 import org.openzen.zenscript.shared.CodePosition;
30 31
 import org.openzen.zenscript.shared.CompileException;
31 32
 import org.openzen.zenscript.shared.CompileExceptionCode;
@@ -41,6 +42,7 @@ public class FileScope extends BaseScope {
41 42
 	private final GlobalTypeRegistry globalRegistry;
42 43
 	private final Map<String, HighLevelDefinition> importedTypes = new HashMap<>();
43 44
 	private final Map<String, ISymbol> globalSymbols;
45
+	private final Map<String, AnnotationDefinition> annotations = new HashMap<>();
44 46
 	
45 47
 	public FileScope(
46 48
 			AccessScope access,
@@ -48,13 +50,18 @@ public class FileScope extends BaseScope {
48 50
 			PackageDefinitions packageDefinitions,
49 51
 			GlobalTypeRegistry globalRegistry,
50 52
 			List<ExpansionDefinition> expansions,
51
-			Map<String, ISymbol> globalSymbols) {
53
+			Map<String, ISymbol> globalSymbols,
54
+			List<AnnotationDefinition> annotations) {
52 55
 		this.rootPackage = rootPackage;
53 56
 		this.packageDefinitions = packageDefinitions;
54 57
 		this.globalRegistry = globalRegistry;
55 58
 		this.globalSymbols = globalSymbols;
56 59
 		
57 60
 		memberCache = new LocalMemberCache(access, globalRegistry, expansions);
61
+		
62
+		for (AnnotationDefinition annotation : annotations) {
63
+			this.annotations.put(annotation.getAnnotationName(), annotation);
64
+		}
58 65
 	}
59 66
 	
60 67
 	@Override
@@ -147,4 +154,9 @@ public class FileScope extends BaseScope {
147 154
 	public IPartialExpression getOuterInstance(CodePosition position) {
148 155
 		throw new CompileException(position, CompileExceptionCode.NO_OUTER_BECAUSE_OUTSIDE_TYPE, "Not in an inner type");
149 156
 	}
157
+
158
+	@Override
159
+	public AnnotationDefinition getAnnotation(String name) {
160
+		return annotations.get(name);
161
+	}
150 162
 }

Linker/src/main/java/org/openzen/zenscript/linker/ForeachScope.java → CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ForeachScope.java View File

@@ -3,10 +3,11 @@
3 3
  * To change this template file, choose Tools | Templates
4 4
  * and open the template in the editor.
5 5
  */
6
-package org.openzen.zenscript.linker;
6
+package org.openzen.zenscript.codemodel.scope;
7 7
 
8 8
 import java.util.List;
9 9
 import java.util.function.Function;
10
+import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
10 11
 import org.openzen.zenscript.codemodel.FunctionHeader;
11 12
 import org.openzen.zenscript.codemodel.expression.Expression;
12 13
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
@@ -90,4 +91,9 @@ public class ForeachScope extends StatementScope {
90 91
 	public IPartialExpression getOuterInstance(CodePosition position) {
91 92
 		return outer.getOuterInstance(position);
92 93
 	}
94
+
95
+	@Override
96
+	public AnnotationDefinition getAnnotation(String name) {
97
+		return outer.getAnnotation(name);
98
+	}
93 99
 }

Linker/src/main/java/org/openzen/zenscript/linker/FunctionScope.java → CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FunctionScope.java View File

@@ -3,10 +3,11 @@
3 3
  * To change this template file, choose Tools | Templates
4 4
  * and open the template in the editor.
5 5
  */
6
-package org.openzen.zenscript.linker;
6
+package org.openzen.zenscript.codemodel.scope;
7 7
 
8 8
 import java.util.List;
9 9
 import java.util.function.Function;
10
+import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
10 11
 import org.openzen.zenscript.codemodel.FunctionHeader;
11 12
 import org.openzen.zenscript.codemodel.FunctionParameter;
12 13
 import org.openzen.zenscript.codemodel.expression.Expression;
@@ -104,4 +105,9 @@ public class FunctionScope extends StatementScope {
104 105
 	public IPartialExpression getOuterInstance(CodePosition position) {
105 106
 		return outer.getOuterInstance(position);
106 107
 	}
108
+
109
+	@Override
110
+	public AnnotationDefinition getAnnotation(String name) {
111
+		return outer.getAnnotation(name);
112
+	}
107 113
 }

Linker/src/main/java/org/openzen/zenscript/linker/GenericFunctionScope.java → CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/GenericFunctionScope.java View File

@@ -3,12 +3,13 @@
3 3
  * To change this template file, choose Tools | Templates
4 4
  * and open the template in the editor.
5 5
  */
6
-package org.openzen.zenscript.linker;
6
+package org.openzen.zenscript.codemodel.scope;
7 7
 
8 8
 import java.util.HashMap;
9 9
 import java.util.List;
10 10
 import java.util.Map;
11 11
 import java.util.function.Function;
12
+import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12 13
 import org.openzen.zenscript.codemodel.FunctionHeader;
13 14
 import org.openzen.zenscript.codemodel.expression.Expression;
14 15
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
@@ -81,4 +82,9 @@ public class GenericFunctionScope extends BaseScope {
81 82
 	public IPartialExpression getOuterInstance(CodePosition position) {
82 83
 		return outer.getOuterInstance(position);
83 84
 	}
85
+
86
+	@Override
87
+	public AnnotationDefinition getAnnotation(String name) {
88
+		return outer.getAnnotation(name);
89
+	}
84 90
 }

Linker/src/main/java/org/openzen/zenscript/linker/GlobalScriptScope.java → CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/GlobalScriptScope.java View File

@@ -3,10 +3,11 @@
3 3
  * To change this template file, choose Tools | Templates
4 4
  * and open the template in the editor.
5 5
  */
6
-package org.openzen.zenscript.linker;
6
+package org.openzen.zenscript.codemodel.scope;
7 7
 
8 8
 import java.util.List;
9 9
 import java.util.function.Function;
10
+import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
10 11
 import org.openzen.zenscript.codemodel.FunctionHeader;
11 12
 import org.openzen.zenscript.codemodel.expression.Expression;
12 13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
@@ -21,9 +22,9 @@ import org.openzen.zenscript.shared.CodePosition;
21 22
  * @author Hoofdgebruiker
22 23
  */
23 24
 public class GlobalScriptScope extends StatementScope {
24
-	private final FileScope file;
25
+	private final BaseScope file;
25 26
 	
26
-	public GlobalScriptScope(FileScope file) {
27
+	public GlobalScriptScope(BaseScope file) {
27 28
 		this.file = file;
28 29
 	}
29 30
 
@@ -70,4 +71,9 @@ public class GlobalScriptScope extends StatementScope {
70 71
 	public IPartialExpression getOuterInstance(CodePosition position) {
71 72
 		return null;
72 73
 	}
74
+
75
+	@Override
76
+	public AnnotationDefinition getAnnotation(String name) {
77
+		return file.getAnnotation(name);
78
+	}
73 79
 }

Linker/src/main/java/org/openzen/zenscript/linker/ImplementationScope.java → CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ImplementationScope.java View File

@@ -3,10 +3,11 @@
3 3
  * To change this template file, choose Tools | Templates
4 4
  * and open the template in the editor.
5 5
  */
6
-package org.openzen.zenscript.linker;
6
+package org.openzen.zenscript.codemodel.scope;
7 7
 
8 8
 import java.util.List;
9 9
 import java.util.function.Function;
10
+import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
10 11
 import org.openzen.zenscript.codemodel.FunctionHeader;
11 12
 import org.openzen.zenscript.codemodel.expression.Expression;
12 13
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
@@ -96,4 +97,9 @@ public class ImplementationScope extends BaseScope {
96 97
 	public IPartialExpression getOuterInstance(CodePosition position) {
97 98
 		return new ThisExpression(position, outer.getThisType());
98 99
 	}
100
+
101
+	@Override
102
+	public AnnotationDefinition getAnnotation(String name) {
103
+		return outer.getAnnotation(name);
104
+	}
99 105
 }

Linker/src/main/java/org/openzen/zenscript/linker/LambdaScope.java → CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LambdaScope.java View File

@@ -3,10 +3,11 @@
3 3
  * To change this template file, choose Tools | Templates
4 4
  * and open the template in the editor.
5 5
  */
6
-package org.openzen.zenscript.linker;
6
+package org.openzen.zenscript.codemodel.scope;
7 7
 
8 8
 import java.util.List;
9 9
 import java.util.function.Function;
10
+import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
10 11
 import org.openzen.zenscript.codemodel.FunctionHeader;
11 12
 import org.openzen.zenscript.codemodel.FunctionParameter;
12 13
 import org.openzen.zenscript.codemodel.expression.Expression;
@@ -89,4 +90,9 @@ public class LambdaScope extends StatementScope {
89 90
 	public IPartialExpression getOuterInstance(CodePosition position) {
90 91
 		return outer.getOuterInstance(position);
91 92
 	}
93
+
94
+	@Override
95
+	public AnnotationDefinition getAnnotation(String name) {
96
+		return outer.getAnnotation(name);
97
+	}
92 98
 }

Linker/src/main/java/org/openzen/zenscript/linker/LoopScope.java → CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LoopScope.java View File

@@ -3,10 +3,11 @@
3 3
  * To change this template file, choose Tools | Templates
4 4
  * and open the template in the editor.
5 5
  */
6
-package org.openzen.zenscript.linker;
6
+package org.openzen.zenscript.codemodel.scope;
7 7
 
8 8
 import java.util.List;
9 9
 import java.util.function.Function;
10
+import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
10 11
 import org.openzen.zenscript.codemodel.FunctionHeader;
11 12
 import org.openzen.zenscript.codemodel.expression.Expression;
12 13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
@@ -78,5 +79,9 @@ public class LoopScope extends StatementScope {
78 79
 	public IPartialExpression getOuterInstance(CodePosition position) {
79 80
 		return outer.getOuterInstance(position);
80 81
 	}
81
-}
82 82
 
83
+	@Override
84
+	public AnnotationDefinition getAnnotation(String name) {
85
+		return outer.getAnnotation(name);
86
+	}
87
+}

Linker/src/main/java/org/openzen/zenscript/linker/StatementScope.java → CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/StatementScope.java View File

@@ -3,7 +3,7 @@
3 3
  * To change this template file, choose Tools | Templates
4 4
  * and open the template in the editor.
5 5
  */
6
-package org.openzen.zenscript.linker;
6
+package org.openzen.zenscript.codemodel.scope;
7 7
 
8 8
 import java.util.HashMap;
9 9
 import java.util.Map;

+ 3
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/TypeScope.java View File

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.scope;
7 7
 
8
+import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
8 9
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
9 10
 import org.openzen.zenscript.codemodel.type.ITypeID;
10 11
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
@@ -20,4 +21,6 @@ public interface TypeScope {
20 21
 	public LocalMemberCache getMemberCache();
21 22
 	
22 23
 	public TypeMembers getTypeMembers(ITypeID type);
24
+	
25
+	public AnnotationDefinition getAnnotation(String name);
23 26
 }

+ 21
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/BlockStatement.java View File

@@ -7,6 +7,7 @@ package org.openzen.zenscript.codemodel.statement;
7 7
 
8 8
 import java.util.ArrayList;
9 9
 import java.util.List;
10
+import java.util.function.Consumer;
10 11
 import org.openzen.zenscript.codemodel.expression.Expression;
11 12
 import org.openzen.zenscript.codemodel.expression.ExpressionTransformer;
12 13
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -30,6 +31,26 @@ public class BlockStatement extends Statement {
30 31
 	public <T> T accept(StatementVisitor<T> visitor) {
31 32
 		return visitor.visitBlock(this);
32 33
 	}
34
+	
35
+	@Override
36
+	public void forEachStatement(Consumer<Statement> consumer) {
37
+		consumer.accept(this);
38
+		for (Statement s : statements) {
39
+			s.forEachStatement(consumer);
40
+		}
41
+	}
42
+	
43
+	@Override
44
+	public Statement transform(StatementTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
45
+		List<Statement> tStatements = new ArrayList<>();
46
+		boolean unchanged = true;
47
+		for (Statement statement : statements) {
48
+			Statement tStatement = statement.transform(transformer, modified);
49
+			unchanged &= statement == tStatement;
50
+			tStatements.add(statement);
51
+		}
52
+		return unchanged ? this : new BlockStatement(position, tStatements);
53
+	}
33 54
 
34 55
 	@Override
35 56
 	public Statement transform(ExpressionTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {

+ 11
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/BreakStatement.java View File

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.statement;
7 7
 
8
+import java.util.function.Consumer;
8 9
 import org.openzen.zenscript.codemodel.expression.ExpressionTransformer;
9 10
 import org.openzen.zenscript.shared.CodePosition;
10 11
 import org.openzen.zenscript.shared.ConcatMap;
@@ -26,6 +27,16 @@ public class BreakStatement extends Statement {
26 27
 	public <T> T accept(StatementVisitor<T> visitor) {
27 28
 		return visitor.visitBreak(this);
28 29
 	}
30
+	
31
+	@Override
32
+	public void forEachStatement(Consumer<Statement> consumer) {
33
+		consumer.accept(this);
34
+	}
35
+
36
+	@Override
37
+	public Statement transform(StatementTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
38
+		return modified.containsKey(target) ? new BreakStatement(position, modified.get(target)) : this;
39
+	}
29 40
 
30 41
 	@Override
31 42
 	public Statement transform(ExpressionTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {

+ 5
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/CatchClause.java View File

@@ -24,6 +24,11 @@ public class CatchClause {
24 24
 		this.content = content;
25 25
 	}
26 26
 	
27
+	public CatchClause transform(StatementTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
28
+		Statement tContent = content.transform(transformer, modified);
29
+		return content == tContent ? this : new CatchClause(position, exceptionVariable, tContent);
30
+	}
31
+	
27 32
 	public CatchClause transform(ExpressionTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
28 33
 		Statement tContent = content.transform(transformer, modified);
29 34
 		return content == tContent ? this : new CatchClause(position, exceptionVariable, tContent);

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

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.statement;
7 7
 
8
+import java.util.function.Consumer;
8 9
 import org.openzen.zenscript.codemodel.expression.ExpressionTransformer;
9 10
 import org.openzen.zenscript.shared.CodePosition;
10 11
 import org.openzen.zenscript.shared.ConcatMap;
@@ -26,6 +27,16 @@ public class ContinueStatement extends Statement {
26 27
 	public <T> T accept(StatementVisitor<T> visitor) {
27 28
 		return visitor.visitContinue(this);
28 29
 	}
30
+	
31
+	@Override
32
+	public void forEachStatement(Consumer<Statement> consumer) {
33
+		consumer.accept(this);
34
+	}
35
+
36
+	@Override
37
+	public Statement transform(StatementTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
38
+		return modified.containsKey(target) ? new ContinueStatement(position, modified.get(target)) : this;
39
+	}
29 40
 
30 41
 	@Override
31 42
 	public Statement transform(ExpressionTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {

+ 23
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/DoWhileStatement.java View File

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.statement;
7 7
 
8
+import java.util.function.Consumer;
8 9
 import org.openzen.zenscript.codemodel.expression.Expression;
9 10
 import org.openzen.zenscript.codemodel.expression.ExpressionTransformer;
10 11
 import org.openzen.zenscript.shared.CodePosition;
@@ -28,10 +29,32 @@ public class DoWhileStatement extends LoopStatement {
28 29
 	public <T> T accept(StatementVisitor<T> visitor) {
29 30
 		return visitor.visitDoWhile(this);
30 31
 	}
32
+	
33
+	@Override
34
+	public void forEachStatement(Consumer<Statement> consumer) {
35
+		consumer.accept(this);
36
+		content.forEachStatement(consumer);
37
+	}
38
+
39
+	@Override
40
+	public Statement transform(StatementTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
41
+		Expression tCondition = condition.transform(transformer);
42
+		Statement tContent = content.transform(transformer, modified);
43
+		if (tCondition == condition && tContent == content)
44
+			return this;
45
+		
46
+		DoWhileStatement result = new DoWhileStatement(position, label, condition);
47
+		result.content = content.transform(transformer, modified.concat(this, result));
48
+		return result;
49
+	}
31 50
 
32 51
 	@Override
33 52
 	public Statement transform(ExpressionTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
34 53
 		Expression tCondition = condition.transform(transformer);
54
+		Statement tContent = content.transform(transformer, modified);
55
+		if (tCondition == condition && tContent == content)
56
+			return this;
57
+		
35 58
 		DoWhileStatement result = new DoWhileStatement(position, label, tCondition);
36 59
 		result.content = content.transform(transformer, modified.concat(this, result));
37 60
 		return result;

+ 11
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/EmptyStatement.java View File

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.statement;
7 7
 
8
+import java.util.function.Consumer;
8 9
 import org.openzen.zenscript.codemodel.expression.ExpressionTransformer;
9 10
 import org.openzen.zenscript.shared.CodePosition;
10 11
 import org.openzen.zenscript.shared.ConcatMap;
@@ -22,6 +23,16 @@ public class EmptyStatement extends Statement {
22 23
 	public <T> T accept(StatementVisitor<T> visitor) {
23 24
 		return visitor.visitEmpty(this);
24 25
 	}
26
+	
27
+	@Override
28
+	public void forEachStatement(Consumer<Statement> consumer) {
29
+		consumer.accept(this);
30
+	}
31
+
32
+	@Override
33
+	public Statement transform(StatementTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
34
+		return this;
35
+	}
25 36
 
26 37
 	@Override
27 38
 	public Statement transform(ExpressionTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {

+ 13
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ExpressionStatement.java View File

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.statement;
7 7
 
8
+import java.util.function.Consumer;
8 9
 import org.openzen.zenscript.codemodel.expression.Expression;
9 10
 import org.openzen.zenscript.codemodel.expression.ExpressionTransformer;
10 11
 import org.openzen.zenscript.shared.CodePosition;
@@ -27,6 +28,18 @@ public class ExpressionStatement extends Statement {
27 28
 	public <T> T accept(StatementVisitor<T> visitor) {
28 29
 		return visitor.visitExpression(this);
29 30
 	}
31
+	
32
+	@Override
33
+	public void forEachStatement(Consumer<Statement> consumer) {
34
+		consumer.accept(this);
35
+		expression.forEachStatement(consumer);
36
+	}
37
+
38
+	@Override
39
+	public Statement transform(StatementTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
40
+		Expression tExpression = expression.transform(transformer);
41
+		return tExpression == expression ? this : new ExpressionStatement(position, tExpression);
42
+	}
30 43
 
31 44
 	@Override
32 45
 	public Statement transform(ExpressionTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {

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

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.statement;
7 7
 
8
+import java.util.function.Consumer;
8 9
 import org.openzen.zenscript.codemodel.expression.Expression;
9 10
 import org.openzen.zenscript.codemodel.expression.ExpressionTransformer;
10 11
 import org.openzen.zenscript.codemodel.member.IIteratorMember;
@@ -33,10 +34,32 @@ public class ForeachStatement extends LoopStatement {
33 34
 	public <T> T accept(StatementVisitor<T> visitor) {
34 35
 		return visitor.visitForeach(this);
35 36
 	}
37
+	
38
+	@Override
39
+	public void forEachStatement(Consumer<Statement> consumer) {
40
+		consumer.accept(this);
41
+		content.forEachStatement(consumer);
42
+	}
43
+
44
+	@Override
45
+	public Statement transform(StatementTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
46
+		Expression tList = list.transform(transformer);
47
+		Statement tContent = content.transform(transformer, modified);
48
+		if (tList == list && tContent == content)
49
+			return this;
50
+		
51
+		ForeachStatement result = new ForeachStatement(position, loopVariables, iterator, tList);
52
+		result.content = content.transform(transformer, modified.concat(this, result));
53
+		return result;
54
+	}
36 55
 
37 56
 	@Override
38 57
 	public Statement transform(ExpressionTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
39 58
 		Expression tList = list.transform(transformer);
59
+		Statement tContent = content.transform(transformer, modified);
60
+		if (tList == list && tContent == content)
61
+			return this;
62
+		
40 63
 		ForeachStatement result = new ForeachStatement(position, loopVariables, iterator, tList);
41 64
 		result.content = content.transform(transformer, modified.concat(this, result));
42 65
 		return result;

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

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.statement;
7 7
 
8
+import java.util.function.Consumer;
8 9
 import org.openzen.zenscript.codemodel.expression.Expression;
9 10
 import org.openzen.zenscript.codemodel.expression.ExpressionTransformer;
10 11
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -32,12 +33,30 @@ public class IfStatement extends Statement {
32 33
 	public <T> T accept(StatementVisitor<T> visitor) {
33 34
 		return visitor.visitIf(this);
34 35
 	}
36
+	
37
+	@Override
38
+	public void forEachStatement(Consumer<Statement> consumer) {
39
+		consumer.accept(this);
40
+		onThen.forEachStatement(consumer);
41
+		if (onElse != null)
42
+			onElse.forEachStatement(consumer);
43
+	}
44
+
45
+	@Override
46
+	public Statement transform(StatementTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
47
+		Expression tCondition = condition.transform(transformer);
48
+		Statement tOnThen = onThen.transform(transformer, modified);
49
+		Statement tOnElse = onElse == null ? null : onElse.transform(transformer, modified);
50
+		return tCondition == condition && onThen == tOnThen && onElse == tOnElse
51
+				? this
52
+				: new IfStatement(position, tCondition, tOnThen, tOnElse);
53
+	}
35 54
 
36 55
 	@Override
37 56
 	public Statement transform(ExpressionTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
38 57
 		Expression tCondition = condition.transform(transformer);
39 58
 		Statement tOnThen = onThen.transform(transformer, modified);
40
-		Statement tOnElse = onElse.transform(transformer, modified);
59
+		Statement tOnElse = onElse == null ? null : onElse.transform(transformer, modified);
41 60
 		return tCondition == condition && onThen == tOnThen && onElse == tOnElse
42 61
 				? this
43 62
 				: new IfStatement(position, tCondition, tOnThen, tOnElse);

+ 14
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/LockStatement.java View File

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.statement;
7 7
 
8
+import java.util.function.Consumer;
8 9
 import org.openzen.zenscript.codemodel.expression.Expression;
9 10
 import org.openzen.zenscript.codemodel.expression.ExpressionTransformer;
10 11
 import org.openzen.zenscript.shared.CodePosition;
@@ -29,6 +30,19 @@ public class LockStatement extends Statement {
29 30
 	public <T> T accept(StatementVisitor<T> visitor) {
30 31
 		return visitor.visitLock(this);
31 32
 	}
33
+	
34
+	@Override
35
+	public void forEachStatement(Consumer<Statement> consumer) {
36
+		consumer.accept(this);
37
+		content.forEachStatement(consumer);
38
+	}
39
+
40
+	@Override
41
+	public Statement transform(StatementTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
42
+		Expression tObject = object.transform(transformer);
43
+		Statement tContent = content.transform(transformer, modified);
44
+		return tObject == object && tContent == content ? this : new LockStatement(position, tObject, tContent);
45
+	}
32 46
 
33 47
 	@Override
34 48
 	public Statement transform(ExpressionTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {

+ 12
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ReturnStatement.java View File

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.statement;
7 7
 
8
+import java.util.function.Consumer;
8 9
 import org.openzen.zenscript.codemodel.expression.Expression;
9 10
 import org.openzen.zenscript.codemodel.expression.ExpressionTransformer;
10 11
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -30,6 +31,11 @@ public class ReturnStatement extends Statement {
30 31
 		return value.type;
31 32
 	}
32 33
 	
34
+	@Override
35
+	public void forEachStatement(Consumer<Statement> consumer) {
36
+		consumer.accept(this);
37
+	}
38
+	
33 39
 	@Override
34 40
 	public Statement withReturnType(TypeScope scope, ITypeID returnType) {
35 41
 		return new ReturnStatement(position, value == null ? null : value.castImplicit(position, scope, returnType));
@@ -40,6 +46,12 @@ public class ReturnStatement extends Statement {
40 46
 		return visitor.visitReturn(this);
41 47
 	}
42 48
 
49
+	@Override
50
+	public Statement transform(StatementTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
51
+		Expression tValue = value.transform(transformer);
52
+		return tValue == value ? this : new ReturnStatement(position, tValue);
53
+	}
54
+
43 55
 	@Override
44 56
 	public Statement transform(ExpressionTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
45 57
 		Expression tValue = value.transform(transformer);

+ 11
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/Statement.java View File

@@ -6,7 +6,9 @@
6 6
 package org.openzen.zenscript.codemodel.statement;
7 7
 
8 8
 import java.util.List;
9
+import java.util.function.Consumer;
9 10
 import java.util.stream.Collectors;
11
+import org.openzen.zenscript.codemodel.annotations.StatementAnnotation;
10 12
 import org.openzen.zenscript.codemodel.expression.ExpressionTransformer;
11 13
 import org.openzen.zenscript.codemodel.type.ITypeID;
12 14
 import org.openzen.zenscript.shared.CodePosition;
@@ -21,6 +23,7 @@ import org.openzen.zenscript.shared.Taggable;
21 23
 public abstract class Statement extends Taggable {
22 24
 	public final CodePosition position;
23 25
 	public final ITypeID thrownType;
26
+	public StatementAnnotation[] annotations = StatementAnnotation.NONE;
24 27
 	
25 28
 	public Statement(CodePosition position, ITypeID thrownType) {
26 29
 		this.position = position;
@@ -37,6 +40,14 @@ public abstract class Statement extends Taggable {
37 40
 	
38 41
 	public abstract <T> T accept(StatementVisitor<T> visitor);
39 42
 	
43
+	public abstract void forEachStatement(Consumer<Statement> consumer);
44
+	
45
+	public final Statement transform(StatementTransformer transformer) {
46
+		return transform(transformer, ConcatMap.empty());
47
+	}
48
+	
49
+	public abstract Statement transform(StatementTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified);
50
+	
40 51
 	public abstract Statement transform(ExpressionTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified);
41 52
 	
42 53
 	public static List<Statement> withReturnType(TypeScope scope, List<Statement> statements, ITypeID returnType) {

+ 14
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/StatementTransformer.java View File

@@ -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.codemodel.statement;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public interface StatementTransformer {
13
+	Statement transform(Statement original);
14
+}

+ 8
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/SwitchCase.java View File

@@ -24,6 +24,14 @@ public class SwitchCase {
24 24
 		this.statements = statements;
25 25
 	}
26 26
 	
27
+	public SwitchCase transform(StatementTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
28
+		List<Statement> tStatements = new ArrayList<>();
29
+		for (Statement statement : statements) {
30
+			tStatements.add(statement.transform(transformer, modified));
31
+		}
32
+		return new SwitchCase(value, tStatements);
33
+	}
34
+	
27 35
 	public SwitchCase transform(ExpressionTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
28 36
 		List<Statement> tStatements = new ArrayList<>();
29 37
 		for (Statement statement : statements) {

+ 21
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/SwitchStatement.java View File

@@ -7,6 +7,7 @@ package org.openzen.zenscript.codemodel.statement;
7 7
 
8 8
 import java.util.ArrayList;
9 9
 import java.util.List;
10
+import java.util.function.Consumer;
10 11
 import org.openzen.zenscript.codemodel.expression.Expression;
11 12
 import org.openzen.zenscript.codemodel.expression.ExpressionTransformer;
12 13
 import org.openzen.zenscript.shared.CodePosition;
@@ -30,6 +31,26 @@ public class SwitchStatement extends LoopStatement {
30 31
 	public <T> T accept(StatementVisitor<T> visitor) {
31 32
 		return visitor.visitSwitch(this);
32 33
 	}
34
+	
35
+	@Override
36
+	public void forEachStatement(Consumer<Statement> consumer) {
37
+		consumer.accept(this);
38
+		for (SwitchCase switchCase : cases) {
39
+			for (Statement statement : switchCase.statements)
40
+				statement.forEachStatement(consumer);
41
+		}
42
+	}
43
+
44
+	@Override
45
+	public Statement transform(StatementTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
46
+		Expression tValue = value.transform(transformer);
47
+		SwitchStatement result = new SwitchStatement(position, label, tValue);
48
+		ConcatMap<LoopStatement, LoopStatement> tModified = modified.concat(this, result);
49
+		for (SwitchCase case_ : cases) {
50
+			result.cases.add(case_.transform(transformer, tModified));
51
+		}
52
+		return result;
53
+	}
33 54
 
34 55
 	@Override
35 56
 	public Statement transform(ExpressionTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {

+ 12
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ThrowStatement.java View File

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.statement;
7 7
 
8
+import java.util.function.Consumer;
8 9
 import org.openzen.zenscript.codemodel.expression.Expression;
9 10
 import org.openzen.zenscript.codemodel.expression.ExpressionTransformer;
10 11
 import org.openzen.zenscript.shared.CodePosition;
@@ -27,6 +28,17 @@ public class ThrowStatement extends Statement {
27 28
 	public <T> T accept(StatementVisitor<T> visitor) {
28 29
 		return visitor.visitThrow(this);
29 30
 	}
31
+	
32
+	@Override
33
+	public void forEachStatement(Consumer<Statement> consumer) {
34
+		consumer.accept(this);
35
+	}
36
+
37
+	@Override
38
+	public Statement transform(StatementTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
39
+		Expression tValue = value.transform(transformer);
40
+		return tValue == value ? this : new ThrowStatement(position, value);
41
+	}
30 42
 
31 43
 	@Override
32 44
 	public Statement transform(ExpressionTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {

+ 22
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/TryCatchStatement.java View File

@@ -7,6 +7,7 @@ package org.openzen.zenscript.codemodel.statement;
7 7
 
8 8
 import java.util.ArrayList;
9 9
 import java.util.List;
10
+import java.util.function.Consumer;
10 11
 import org.openzen.zenscript.codemodel.expression.ExpressionTransformer;
11 12
 import org.openzen.zenscript.shared.CodePosition;
12 13
 import org.openzen.zenscript.shared.ConcatMap;
@@ -39,6 +40,27 @@ public class TryCatchStatement extends Statement {
39 40
 	public <T> T accept(StatementVisitor<T> visitor) {
40 41
 		return visitor.visitTryCatch(this);
41 42
 	}
43
+	
44
+	@Override
45
+	public void forEachStatement(Consumer<Statement> consumer) {
46
+		consumer.accept(this);
47
+		for (CatchClause catchClause : catchClauses) {
48
+			catchClause.content.forEachStatement(consumer);
49
+		}
50
+		if (finallyClause != null)
51
+			finallyClause.forEachStatement(consumer);
52
+	}
53
+
54
+	@Override
55
+	public Statement transform(StatementTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
56
+		VarStatement tResource = resource == null ? null : resource.transform(transformer, modified);
57
+		Statement tContent = content.transform(transformer, modified);
58
+		List<CatchClause> tCatchClauses = new ArrayList<>();
59
+		for (CatchClause clause : catchClauses)
60
+			tCatchClauses.add(clause.transform(transformer, modified));
61
+		Statement tFinallyClause = finallyClause == null ? null : finallyClause.transform(transformer, modified);
62
+		return new TryCatchStatement(position, tResource, tContent, tCatchClauses, tFinallyClause);
63
+	}
42 64
 
43 65
 	@Override
44 66
 	public Statement transform(ExpressionTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {

+ 12
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/VarStatement.java View File

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.statement;
7 7
 
8
+import java.util.function.Consumer;
8 9
 import org.openzen.zenscript.codemodel.expression.Expression;
9 10
 import org.openzen.zenscript.codemodel.expression.ExpressionTransformer;
10 11
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -34,6 +35,17 @@ public class VarStatement extends Statement {
34 35
 	public <T> T accept(StatementVisitor<T> visitor) {
35 36
 		return visitor.visitVar(this);
36 37
 	}
38
+	
39
+	@Override
40
+	public void forEachStatement(Consumer<Statement> consumer) {
41
+		consumer.accept(this);
42
+	}
43
+
44
+	@Override
45
+	public VarStatement transform(StatementTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
46
+		Expression tInitializer = initializer == null ? null : initializer.transform(transformer);
47
+		return tInitializer == initializer ? this : new VarStatement(position, name, type, tInitializer, isFinal);
48
+	}
37 49
 
38 50
 	@Override
39 51
 	public VarStatement transform(ExpressionTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {

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

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.statement;
7 7
 
8
+import java.util.function.Consumer;
8 9
 import org.openzen.zenscript.codemodel.expression.Expression;
9 10
 import org.openzen.zenscript.codemodel.expression.ExpressionTransformer;
10 11
 import org.openzen.zenscript.shared.CodePosition;
@@ -28,11 +29,33 @@ public class WhileStatement extends LoopStatement {
28 29
 	public <T> T accept(StatementVisitor<T> visitor) {
29 30
 		return visitor.visitWhile(this);
30 31
 	}
32
+	
33
+	@Override
34
+	public void forEachStatement(Consumer<Statement> consumer) {
35
+		consumer.accept(this);
36
+		content.forEachStatement(consumer);
37
+	}
31 38
 
32 39
 	@Override
33
-	public Statement transform(ExpressionTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
40
+	public WhileStatement transform(StatementTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
34 41
 		Expression tCondition = condition.transform(transformer);
35
-		WhileStatement result = new WhileStatement(position, label, condition);
42
+		Statement tContent = content.transform(transformer, modified);
43
+		if (condition == tCondition && content == tContent)
44
+			return this;
45
+		
46
+		WhileStatement result = new WhileStatement(position, label, tCondition);
47
+		result.content = content.transform(transformer, modified.concat(this, result));
48
+		return result;
49
+	}
50
+
51
+	@Override
52
+	public WhileStatement transform(ExpressionTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
53
+		Expression tCondition = condition.transform(transformer);
54
+		Statement tContent = content.transform(transformer, modified);
55
+		if (condition == tCondition && content == tContent)
56
+			return this;
57
+		
58
+		WhileStatement result = new WhileStatement(position, label, tCondition);
36 59
 		result.content = content.transform(transformer, modified.concat(this, result));
37 60
 		return result;
38 61
 	}

Linker/src/main/java/org/openzen/zenscript/linker/symbol/ISymbol.java → CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ISymbol.java View File

@@ -3,7 +3,7 @@
3 3
  * To change this template file, choose Tools | Templates
4 4
  * and open the template in the editor.
5 5
  */
6
-package org.openzen.zenscript.linker.symbol;
6
+package org.openzen.zenscript.codemodel.type;
7 7
 
8 8
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
9 9
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;

+ 2
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ITypeID.java View File

@@ -15,6 +15,8 @@ import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
15 15
  * @author Hoofdgebruiker
16 16
  */
17 17
 public interface ITypeID {
18
+	public static final ITypeID[] NONE = new ITypeID[0];
19
+	
18 20
 	public ITypeID getUnmodified();
19 21
 	
20 22
 	public <T> T accept(ITypeVisitor<T> visitor);

Linker/src/main/java/org/openzen/zenscript/linker/symbol/TypeSymbol.java → CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeSymbol.java View File

@@ -3,7 +3,7 @@
3 3
  * To change this template file, choose Tools | Templates
4 4
  * and open the template in the editor.
5 5
  */
6
-package org.openzen.zenscript.linker.symbol;
6
+package org.openzen.zenscript.codemodel.type;
7 7
 
8 8
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
9 9
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;

+ 48
- 33
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/DefinitionMemberGroup.java View File

@@ -19,13 +19,15 @@ import org.openzen.zenscript.codemodel.expression.SetterExpression;
19 19
 import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
20 20
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
21 21
 import org.openzen.zenscript.codemodel.member.FieldMember;
22
-import org.openzen.zenscript.codemodel.member.ICallableMember;
23
-import org.openzen.zenscript.codemodel.member.IGettableMember;
24 22
 import org.openzen.zenscript.codemodel.member.SetterMember;
25 23
 import org.openzen.zenscript.codemodel.type.ITypeID;
26 24
 import org.openzen.zenscript.codemodel.CompareType;
27 25
 import org.openzen.zenscript.codemodel.FunctionHeader;
26
+import org.openzen.zenscript.codemodel.expression.ConstExpression;
28 27
 import org.openzen.zenscript.codemodel.expression.PostCallExpression;
28
+import org.openzen.zenscript.codemodel.member.ConstMember;
29
+import org.openzen.zenscript.codemodel.member.FunctionalMember;
30
+import org.openzen.zenscript.codemodel.member.GetterMember;
29 31
 import org.openzen.zenscript.codemodel.member.OperatorMember;
30 32
 import org.openzen.zenscript.shared.CodePosition;
31 33
 import org.openzen.zenscript.shared.CompileException;
@@ -37,16 +39,17 @@ import org.openzen.zenscript.codemodel.scope.TypeScope;
37 39
  * @author Hoofdgebruiker
38 40
  */
39 41
 public class DefinitionMemberGroup {
40
-	public static DefinitionMemberGroup forMethod(ICallableMember member) {
42
+	public static DefinitionMemberGroup forMethod(FunctionalMember member) {
41 43
 		DefinitionMemberGroup instance = new DefinitionMemberGroup(member.isStatic(), member.getInformalName());
42 44
 		instance.addMethod(member, TypeMemberPriority.SPECIFIED);
43 45
 		return instance;
44 46
 	}
45 47
 	
48
+	private TypeMember<ConstMember> constant;
46 49
 	private TypeMember<FieldMember> field;
47
-	private TypeMember<IGettableMember> getter;
50
+	private TypeMember<GetterMember> getter;
48 51
 	private TypeMember<SetterMember> setter;
49
-	private final List<TypeMember<ICallableMember>> methods = new ArrayList<>();
52
+	private final List<TypeMember<FunctionalMember>> methods = new ArrayList<>();
50 53
 	public final boolean isStatic;
51 54
 	public final String name;
52 55
 	
@@ -56,6 +59,8 @@ public class DefinitionMemberGroup {
56 59
 	}
57 60
 	
58 61
 	public void merge(CodePosition position, DefinitionMemberGroup other, TypeMemberPriority priority) {
62
+		if (other.constant != null)
63
+			setConst(other.constant.member, priority);
59 64
 		if (other.field != null)
60 65
 			setField(other.field.member, priority);
61 66
 		if (other.getter != null)
@@ -63,7 +68,7 @@ public class DefinitionMemberGroup {
63 68
 		if (other.setter != null)
64 69
 			setSetter(other.setter.member, priority);
65 70
 		
66
-		for (TypeMember<ICallableMember> method : other.methods)
71
+		for (TypeMember<FunctionalMember> method : other.methods)
67 72
 			addMethod(method.member, priority);
68 73
 	}
69 74
 	
@@ -71,7 +76,7 @@ public class DefinitionMemberGroup {
71 76
 		return this.field == null ? null : this.field.member;
72 77
 	}
73 78
 	
74
-	public IGettableMember getGetter() {
79
+	public GetterMember getGetter() {
75 80
 		return this.getter == null ? null : this.getter.member;
76 81
 	}
77 82
 	
@@ -84,18 +89,26 @@ public class DefinitionMemberGroup {
84 89
 	}
85 90
 	
86 91
 	public boolean hasMethod(FunctionHeader header) {
87
-		for (TypeMember<ICallableMember> method : methods) {
88
-			if (method.member.getHeader().isEquivalentTo(header))
92
+		for (TypeMember<FunctionalMember> method : methods) {
93
+			if (method.member.header.isEquivalentTo(header))
89 94
 				return true;
90 95
 		}
91 96
 		
92 97
 		return false;
93 98
 	}
94 99
 	
95
-	public List<TypeMember<ICallableMember>> getMethodMembers() {
100
+	public List<TypeMember<FunctionalMember>> getMethodMembers() {
96 101
 		return this.methods;
97 102
 	}
98 103
 	
104
+	public void setConst(ConstMember constant, TypeMemberPriority priority) {
105
+		if (this.constant != null) {
106
+			this.constant = this.constant.resolve(new TypeMember<>(priority, constant));
107
+		} else {
108
+			this.constant = new TypeMember<>(priority, constant);
109
+		}
110
+	}
111
+	
99 112
 	public void setField(FieldMember field, TypeMemberPriority priority) {
100 113
 		if (this.field != null) {
101 114
 			this.field = this.field.resolve(new TypeMember<>(priority, field));
@@ -104,7 +117,7 @@ public class DefinitionMemberGroup {
104 117
 		}
105 118
 	}
106 119
 	
107
-	public void setGetter(IGettableMember getter, TypeMemberPriority priority) {
120
+	public void setGetter(GetterMember getter, TypeMemberPriority priority) {
108 121
 		if (this.getter != null) {
109 122
 			this.getter = this.getter.resolve(new TypeMember<>(priority, getter));
110 123
 		} else {
@@ -120,9 +133,9 @@ public class DefinitionMemberGroup {
120 133
 		}
121 134
 	}
122 135
 	
123
-	public void addMethod(ICallableMember method, TypeMemberPriority priority) {
136
+	public void addMethod(FunctionalMember method, TypeMemberPriority priority) {
124 137
 		for (int i = 0; i < methods.size(); i++) {
125
-			if (methods.get(i).member.getHeader().isEquivalentTo(method.getHeader())) {
138
+			if (methods.get(i).member.header.isEquivalentTo(method.header)) {
126 139
 				methods.set(i, methods.get(i).resolve(new TypeMember<>(priority, method)));
127 140
 				return;
128 141
 			}
@@ -183,7 +196,9 @@ public class DefinitionMemberGroup {
183 196
 	}
184 197
 	
185 198
 	public Expression staticGetter(CodePosition position) {
186
-		if (getter != null) {
199
+		if (constant != null) {
200
+			return new ConstExpression(position, constant.member);
201
+		} else if (getter != null) {
187 202
 			if (!getter.member.isStatic())
188 203
 				throw new CompileException(position, CompileExceptionCode.MEMBER_NOT_STATIC, "This getter is not static");
189 204
 			
@@ -221,8 +236,8 @@ public class DefinitionMemberGroup {
221 236
 		for (int i = 0; i < result.length; i++)
222 237
 			result[i] = new ArrayList<>();
223 238
 		
224
-		for (TypeMember<ICallableMember> method : methods) {
225
-			FunctionHeader header = method.member.getHeader();
239
+		for (TypeMember<FunctionalMember> method : methods) {
240
+			FunctionHeader header = method.member.header;
226 241
 			if (header.parameters.length != arguments)
227 242
 				continue;
228 243
 			
@@ -246,8 +261,8 @@ public class DefinitionMemberGroup {
246 261
 	}
247 262
 	
248 263
 	public Expression call(CodePosition position, TypeScope scope, Expression target, CallArguments arguments, boolean allowStaticUsage) {
249
-		ICallableMember method = selectMethod(position, scope, arguments, true, allowStaticUsage);
250
-		FunctionHeader instancedHeader = method.getHeader().withGenericArguments(scope.getTypeRegistry(), arguments.typeArguments);
264
+		FunctionalMember method = selectMethod(position, scope, arguments, true, allowStaticUsage);
265
+		FunctionHeader instancedHeader = method.header.withGenericArguments(scope.getTypeRegistry(), arguments.typeArguments);
251 266
 		for (int i = 0; i < arguments.arguments.length; i++) {
252 267
 			arguments.arguments[i] = arguments.arguments[i].castImplicit(position, scope, instancedHeader.parameters[i].type);
253 268
 		}
@@ -259,7 +274,7 @@ public class DefinitionMemberGroup {
259 274
 		if (methods.isEmpty())
260 275
 			throw new CompileException(position, CompileExceptionCode.NO_SUCH_MEMBER, "There is no such operator");
261 276
 		
262
-		ICallableMember method = methods.get(0).member;
277
+		FunctionalMember method = methods.get(0).member;
263 278
 		if (!(method instanceof OperatorMember)) {
264 279
 			throw new CompileException(position, CompileExceptionCode.NO_SUCH_MEMBER, "Member is not an operator");
265 280
 		}
@@ -273,24 +288,24 @@ public class DefinitionMemberGroup {
273 288
 			Expression target,
274 289
 			CallArguments arguments,
275 290
 			CompareType compareType) {
276
-		ICallableMember method = selectMethod(position, scope, arguments, true, false);
277
-		FunctionHeader instancedHeader = method.getHeader().withGenericArguments(scope.getTypeRegistry(), arguments.typeArguments);
291
+		FunctionalMember method = selectMethod(position, scope, arguments, true, false);
292
+		FunctionHeader instancedHeader = method.header.withGenericArguments(scope.getTypeRegistry(), arguments.typeArguments);
278 293
 		return method.callWithComparator(position, compareType, target, instancedHeader, arguments, scope);
279 294
 	}
280 295
 	
281 296
 	public Expression callStatic(CodePosition position, ITypeID target, TypeScope scope, CallArguments arguments) {
282
-		ICallableMember method = selectMethod(position, scope, arguments, false, true);
283
-		FunctionHeader instancedHeader = method.getHeader().withGenericArguments(scope.getTypeRegistry(), arguments.typeArguments);
297
+		FunctionalMember method = selectMethod(position, scope, arguments, false, true);
298
+		FunctionHeader instancedHeader = method.header.withGenericArguments(scope.getTypeRegistry(), arguments.typeArguments);
284 299
 		return method.callStatic(position, target, instancedHeader, arguments, scope);
285 300
 	}
286 301
 	
287
-	public ICallableMember selectMethod(CodePosition position, TypeScope scope, CallArguments arguments, boolean allowNonStatic, boolean allowStatic) {
302
+	public FunctionalMember selectMethod(CodePosition position, TypeScope scope, CallArguments arguments, boolean allowNonStatic, boolean allowStatic) {
288 303
 		// try to match with exact types
289
-		outer: for (TypeMember<ICallableMember> method : methods) {
304
+		outer: for (TypeMember<FunctionalMember> method : methods) {
290 305
 			if (!(method.member.isStatic() ? allowStatic : allowNonStatic))
291 306
 				continue;
292 307
 			
293
-			FunctionHeader header = method.member.getHeader();
308
+			FunctionHeader header = method.member.header;
294 309
 			if (header.parameters.length != arguments.arguments.length)
295 310
 				continue;
296 311
 			if (header.getNumberOfTypeParameters() != arguments.getNumberOfTypeArguments())
@@ -309,12 +324,12 @@ public class DefinitionMemberGroup {
309 324
 		}
310 325
 		
311 326
 		// try to match with approximate types
312
-		ICallableMember selected = null;
313
-		outer: for (TypeMember<ICallableMember> method : methods) {
327
+		FunctionalMember selected = null;
328
+		outer: for (TypeMember<FunctionalMember> method : methods) {
314 329
 			if (!(method.member.isStatic() ? allowStatic : allowNonStatic))
315 330
 				continue;
316 331
 			
317
-			FunctionHeader header = method.member.getHeader();
332
+			FunctionHeader header = method.member.header;
318 333
 			if (header.parameters.length != arguments.arguments.length)
319 334
 				continue;
320 335
 			if (header.getNumberOfTypeParameters() != arguments.getNumberOfTypeArguments())
@@ -331,8 +346,8 @@ public class DefinitionMemberGroup {
331 346
 			
332 347
 			if (selected != null) {
333 348
 				StringBuilder explanation = new StringBuilder();
334
-				explanation.append("Function A: ").append(selected.getHeader().toString()).append("\n");
335
-				explanation.append("Function B: ").append(method.member.getHeader().toString());
349
+				explanation.append("Function A: ").append(selected.header.toString()).append("\n");
350
+				explanation.append("Function B: ").append(method.member.header.toString());
336 351
 				throw new CompileException(position, CompileExceptionCode.CALL_AMBIGUOUS, "Ambiguous call; multiple methods match:\n" + explanation.toString());
337 352
 			}
338 353
 			
@@ -346,13 +361,13 @@ public class DefinitionMemberGroup {
346 361
 				throw new CompileException(position, CompileExceptionCode.CALL_NO_VALID_METHOD, "This type has no " + name);
347 362
 			}
348 363
 			
349
-			outer: for (TypeMember<ICallableMember> method : methods) {
364
+			outer: for (TypeMember<FunctionalMember> method : methods) {
350 365
 				if (!(method.member.isStatic() ? allowStatic : allowNonStatic)) {
351 366
 					message.append(method.member.isStatic() ? "Method must not be static" : "Method must be static").append('\n');
352 367
 					continue;
353 368
 				}
354 369
 				
355
-				message.append(method.member.getHeader().explainWhyIncompatible(scope, arguments)).append("\n");
370
+				message.append(method.member.header.explainWhyIncompatible(scope, arguments)).append("\n");
356 371
 			}
357 372
 			
358 373
 			throw new CompileException(position, CompileExceptionCode.CALL_NO_VALID_METHOD, "No matching method found for " + name + ":\n" + message.toString());

+ 50
- 29
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java View File

@@ -20,17 +20,30 @@ import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
20 20
 import org.openzen.zenscript.codemodel.definition.FunctionDefinition;
21 21
 import org.openzen.zenscript.codemodel.definition.StructDefinition;
22 22
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
23
+import org.openzen.zenscript.codemodel.expression.ArrayExpression;
23 24
 import org.openzen.zenscript.codemodel.expression.CallTranslator;
25
+import org.openzen.zenscript.codemodel.expression.ConstantByteExpression;
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.ConstantUIntExpression;
33
+import org.openzen.zenscript.codemodel.expression.ConstantULongExpression;
34
+import org.openzen.zenscript.codemodel.expression.ConstantUShortExpression;
35
+import org.openzen.zenscript.codemodel.expression.EnumConstantExpression;
36
+import org.openzen.zenscript.codemodel.expression.Expression;
24 37
 import org.openzen.zenscript.codemodel.generic.GenericParameterBound;
25 38
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
26 39
 import org.openzen.zenscript.codemodel.member.CallerMember;
27 40
 import org.openzen.zenscript.codemodel.member.CasterMember;
41
+import org.openzen.zenscript.codemodel.member.ConstMember;
28 42
 import org.openzen.zenscript.codemodel.member.ConstructorMember;
29 43
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
30 44
 import org.openzen.zenscript.codemodel.member.FieldMember;
31 45
 import org.openzen.zenscript.codemodel.member.FunctionalMember;
32 46
 import org.openzen.zenscript.codemodel.member.GetterMember;
33
-import org.openzen.zenscript.codemodel.member.ICallableMember;
34 47
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
35 48
 import org.openzen.zenscript.codemodel.member.MethodMember;
36 49
 import org.openzen.zenscript.codemodel.member.OperatorMember;
@@ -96,9 +109,9 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
96 109
 		if (members.hasOperator(OperatorType.EQUALS)) {
97 110
 			DefinitionMemberGroup group = members.getOrCreateGroup(OperatorType.EQUALS);
98 111
 			DefinitionMemberGroup inverse = members.getOrCreateGroup(OperatorType.NOTEQUALS);
99
-			for (TypeMember<ICallableMember> method : group.getMethodMembers()) {
100
-				if (!inverse.hasMethod(method.member.getHeader())) {
101
-					inverse.addMethod(notequals(definition, BuiltinID.AUTOOP_NOTEQUALS, method.member.getHeader().parameters[0].type), TypeMemberPriority.SPECIFIED);
112
+			for (TypeMember<FunctionalMember> method : group.getMethodMembers()) {
113
+				if (!inverse.hasMethod(method.member.header)) {
114
+					inverse.addMethod(notequals(definition, BuiltinID.AUTOOP_NOTEQUALS, method.member.header.parameters[0].type), TypeMemberPriority.SPECIFIED);
102 115
 				}
103 116
 			}
104 117
 		}
@@ -481,7 +494,13 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
481 494
 		if (definition instanceof EnumDefinition) {
482 495
 			members.addGetter(getter(definition, ENUM_NAME, "name", STRING));
483 496
 			members.addGetter(getter(definition, ENUM_ORDINAL, "ordinal", INT));
484
-			members.addGetter(staticGetter(definition, ENUM_VALUES, "values", registry.getArray(type, 1)));
497
+			
498
+			List<EnumConstantMember> enumConstants = ((EnumDefinition) definition).enumConstants;
499
+			Expression[] constValues = new Expression[enumConstants.size()];
500
+			for (int i = 0; i < constValues.length; i++)
501
+				constValues[i] = new EnumConstantExpression(BUILTIN, type, enumConstants.get(i));
502
+			
503
+			members.addConst(constant(definition, ENUM_VALUES, "values", new ArrayExpression(BUILTIN, constValues, registry.getArray(type, 1))));
485 504
 			members.addOperator(compare(definition, ENUM_COMPARE, type));
486 505
 			
487 506
 			if (!members.canCast(BasicTypeID.STRING)) {
@@ -599,8 +618,8 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
599 618
 		members.addMethod(staticMethod(builtin, BYTE_PARSE, "parse", BYTE, STRING));
600 619
 		members.addMethod(staticMethod(builtin, BYTE_PARSE_WITH_BASE, "parse", BYTE, STRING, INT));
601 620
 		
602
-		members.addGetter(staticGetter(builtin, BYTE_GET_MIN_VALUE, "MIN_VALUE", BYTE));
603
-		members.addGetter(staticGetter(builtin, BYTE_GET_MAX_VALUE, "MAX_VALUE", BYTE));
621
+		members.addConst(constant(builtin, BYTE_GET_MIN_VALUE, "MIN_VALUE", new ConstantByteExpression(BUILTIN, 0)));
622
+		members.addConst(constant(builtin, BYTE_GET_MAX_VALUE, "MAX_VALUE", new ConstantByteExpression(BUILTIN, 255)));
604 623
 		
605 624
 		processType(builtin, BYTE);
606 625
 	}
@@ -637,8 +656,8 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
637 656
 		members.addMethod(staticMethod(builtin, SBYTE_PARSE, "parse", SBYTE, STRING));
638 657
 		members.addMethod(staticMethod(builtin, SBYTE_PARSE_WITH_BASE, "parse", SBYTE, STRING, INT));
639 658
 		
640
-		members.addGetter(staticGetter(builtin, SBYTE_GET_MIN_VALUE, "MIN_VALUE", SBYTE));
641
-		members.addGetter(staticGetter(builtin, SBYTE_GET_MAX_VALUE, "MAX_VALUE", SBYTE));
659
+		members.addConst(constant(builtin, SBYTE_GET_MIN_VALUE, "MIN_VALUE", new ConstantSByteExpression(BUILTIN, Byte.MIN_VALUE)));
660
+		members.addConst(constant(builtin, SBYTE_GET_MAX_VALUE, "MAX_VALUE", new ConstantSByteExpression(BUILTIN, Byte.MAX_VALUE)));
642 661
 		
643 662
 		processType(builtin, SBYTE);
644 663
 	}
@@ -675,8 +694,8 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
675 694
 		members.addMethod(staticMethod(builtin, SHORT_PARSE, "parse", SHORT, STRING));
676 695
 		members.addMethod(staticMethod(builtin, SHORT_PARSE_WITH_BASE, "parse", SHORT, STRING, INT));
677 696
 		
678
-		members.addGetter(staticGetter(builtin, SHORT_GET_MIN_VALUE, "MIN_VALUE", SHORT));
679
-		members.addGetter(staticGetter(builtin, SHORT_GET_MAX_VALUE, "MAX_VALUE", SHORT));
697
+		members.addConst(constant(builtin, SHORT_GET_MIN_VALUE, "MIN_VALUE", new ConstantShortExpression(BUILTIN, Short.MIN_VALUE)));
698
+		members.addConst(constant(builtin, SHORT_GET_MAX_VALUE, "MAX_VALUE", new ConstantShortExpression(BUILTIN, Short.MAX_VALUE)));
680 699
 		
681 700
 		processType(builtin, SHORT);
682 701
 	}
@@ -712,8 +731,8 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
712 731
 		members.addMethod(staticMethod(builtin, USHORT_PARSE, "parse", USHORT, STRING));
713 732
 		members.addMethod(staticMethod(builtin, USHORT_PARSE_WITH_BASE, "parse", USHORT, STRING, INT));
714 733
 		
715
-		members.addGetter(staticGetter(builtin, USHORT_GET_MIN_VALUE, "MIN_VALUE", USHORT));
716
-		members.addGetter(staticGetter(builtin, USHORT_GET_MAX_VALUE, "MAX_VALUE", USHORT));
734
+		members.addConst(constant(builtin, USHORT_GET_MIN_VALUE, "MIN_VALUE", new ConstantUShortExpression(BUILTIN, 0)));
735
+		members.addConst(constant(builtin, USHORT_GET_MAX_VALUE, "MAX_VALUE", new ConstantUShortExpression(BUILTIN, 65535)));
717 736
 		
718 737
 		processType(builtin, USHORT);
719 738
 	}
@@ -765,8 +784,8 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
765 784
 		members.addOperator(compare(builtin, FLOAT_COMPARE, FLOAT, INT_TO_FLOAT));
766 785
 		members.addOperator(compare(builtin, DOUBLE_COMPARE, DOUBLE, INT_TO_DOUBLE));
767 786
 		
768
-		members.addGetter(staticGetter(builtin, INT_GET_MIN_VALUE, "MIN_VALUE", INT));
769
-		members.addGetter(staticGetter(builtin, INT_GET_MAX_VALUE, "MAX_VALUE", INT));
787
+		members.addConst(constant(builtin, INT_GET_MIN_VALUE, "MIN_VALUE", new ConstantIntExpression(BUILTIN, Integer.MIN_VALUE)));
788
+		members.addConst(constant(builtin, INT_GET_MAX_VALUE, "MAX_VALUE", new ConstantIntExpression(BUILTIN, Integer.MAX_VALUE)));
770 789
 		
771 790
 		members.addCaster(castExplicit(builtin, INT_TO_BYTE, BYTE));
772 791
 		members.addCaster(castExplicit(builtin, INT_TO_SBYTE, SBYTE));
@@ -843,8 +862,8 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
843 862
 		members.addOperator(compare(builtin, FLOAT_COMPARE, FLOAT, UINT_TO_FLOAT));
844 863
 		members.addOperator(compare(builtin, DOUBLE_COMPARE, DOUBLE, UINT_TO_DOUBLE));
845 864
 		
846
-		members.addGetter(staticGetter(builtin, UINT_GET_MIN_VALUE, "MIN_VALUE", UINT));
847
-		members.addGetter(staticGetter(builtin, UINT_GET_MAX_VALUE, "MAX_VALUE", UINT));
865
+		members.addConst(constant(builtin, UINT_GET_MIN_VALUE, "MIN_VALUE", new ConstantUIntExpression(BUILTIN, 0)));
866
+		members.addConst(constant(builtin, UINT_GET_MAX_VALUE, "MAX_VALUE", new ConstantUIntExpression(BUILTIN, -1)));
848 867
 		
849 868
 		members.addCaster(castExplicit(builtin, UINT_TO_BYTE, BYTE));
850 869
 		members.addCaster(castExplicit(builtin, UINT_TO_SBYTE, SBYTE));
@@ -914,8 +933,8 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
914 933
 		members.addOperator(compare(builtin, FLOAT_COMPARE, FLOAT, LONG_TO_FLOAT));
915 934
 		members.addOperator(compare(builtin, DOUBLE_COMPARE, DOUBLE, LONG_TO_DOUBLE));
916 935
 		
917
-		members.addGetter(staticGetter(builtin, LONG_GET_MIN_VALUE, "MIN_VALUE", LONG));
918
-		members.addGetter(staticGetter(builtin, LONG_GET_MAX_VALUE, "MAX_VALUE", LONG));
936
+		members.addConst(constant(builtin, LONG_GET_MIN_VALUE, "MIN_VALUE", new ConstantLongExpression(BUILTIN, Long.MIN_VALUE)));
937
+		members.addConst(constant(builtin, LONG_GET_MAX_VALUE, "MAX_VALUE", new ConstantLongExpression(BUILTIN, Long.MAX_VALUE)));
919 938
 		
920 939
 		members.addCaster(castExplicit(builtin, LONG_TO_BYTE, BYTE));
921 940
 		members.addCaster(castExplicit(builtin, LONG_TO_SBYTE, SBYTE));
@@ -983,8 +1002,8 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
983 1002
 		members.addOperator(compare(builtin, FLOAT_COMPARE, FLOAT, ULONG_TO_FLOAT));
984 1003
 		members.addOperator(compare(builtin, DOUBLE_COMPARE, DOUBLE, ULONG_TO_DOUBLE));
985 1004
 		
986
-		members.addGetter(staticGetter(builtin, ULONG_GET_MIN_VALUE, "MIN_VALUE", ULONG));
987
-		members.addGetter(staticGetter(builtin, ULONG_GET_MAX_VALUE, "MAX_VALUE", ULONG));
1005
+		members.addConst(constant(builtin, ULONG_GET_MIN_VALUE, "MIN_VALUE", new ConstantULongExpression(BUILTIN, 0)));
1006
+		members.addConst(constant(builtin, ULONG_GET_MAX_VALUE, "MAX_VALUE", new ConstantULongExpression(BUILTIN, -1L)));
988 1007
 		
989 1008
 		members.addCaster(castExplicit(builtin, ULONG_TO_BYTE, BYTE));
990 1009
 		members.addCaster(castExplicit(builtin, ULONG_TO_SBYTE, SBYTE));
@@ -1038,8 +1057,8 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1038 1057
 		members.addOperator(compare(builtin, FLOAT_COMPARE, FLOAT));
1039 1058
 		members.addOperator(compare(builtin, DOUBLE_COMPARE, DOUBLE, LONG_TO_DOUBLE));
1040 1059
 		
1041
-		members.addGetter(staticGetter(builtin, FLOAT_GET_MIN_VALUE, "MIN_VALUE", FLOAT));
1042
-		members.addGetter(staticGetter(builtin, FLOAT_GET_MAX_VALUE, "MAX_VALUE", FLOAT));
1060
+		members.addConst(constant(builtin, FLOAT_GET_MIN_VALUE, "MIN_VALUE", new ConstantFloatExpression(BUILTIN, Float.MIN_VALUE)));
1061
+		members.addConst(constant(builtin, FLOAT_GET_MAX_VALUE, "MAX_VALUE", new ConstantFloatExpression(BUILTIN, Float.MAX_VALUE)));
1043 1062
 		
1044 1063
 		members.addCaster(castExplicit(builtin, FLOAT_TO_BYTE, BYTE));
1045 1064
 		members.addCaster(castExplicit(builtin, FLOAT_TO_SBYTE, SBYTE));
@@ -1073,8 +1092,8 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1073 1092
 		members.addOperator(div(builtin, DOUBLE_DIV_DOUBLE, DOUBLE, DOUBLE));
1074 1093
 		members.addOperator(compare(builtin, DOUBLE_COMPARE, DOUBLE));
1075 1094
 		
1076
-		members.addGetter(staticGetter(builtin, DOUBLE_GET_MIN_VALUE, "MIN_VALUE", DOUBLE));
1077
-		members.addGetter(staticGetter(builtin, DOUBLE_GET_MAX_VALUE, "MAX_VALUE", DOUBLE));
1095
+		members.addConst(constant(builtin, DOUBLE_GET_MIN_VALUE, "MIN_VALUE", new ConstantDoubleExpression(BUILTIN, Double.MIN_VALUE)));
1096
+		members.addConst(constant(builtin, DOUBLE_GET_MAX_VALUE, "MAX_VALUE", new ConstantDoubleExpression(BUILTIN, Double.MAX_VALUE)));
1078 1097
 		
1079 1098
 		members.addCaster(castExplicit(builtin, DOUBLE_TO_BYTE, BYTE));
1080 1099
 		members.addCaster(castExplicit(builtin, DOUBLE_TO_SBYTE, SBYTE));
@@ -1148,7 +1167,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1148 1167
 	}
1149 1168
 	
1150 1169
 	private static CallTranslator castedTargetCall(HighLevelDefinition definition, FunctionalMember member, BuiltinID casterBuiltin) {
1151
-		CasterMember caster = castImplicit(definition, casterBuiltin, member.getHeader().parameters[0].type);
1170
+		CasterMember caster = castImplicit(definition, casterBuiltin, member.header.parameters[0].type);
1152 1171
 		return call -> member.call(call.position, caster.cast(call.position, call.target, true), call.arguments, call.scope);
1153 1172
 	}
1154 1173
 	
@@ -1484,14 +1503,16 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1484 1503
 				id);
1485 1504
 	}
1486 1505
 	
1487
-	private static GetterMember staticGetter(HighLevelDefinition cls, BuiltinID id, String name, ITypeID type) {
1488
-		return new GetterMember(
1506
+	private static ConstMember constant(HighLevelDefinition cls, BuiltinID id, String name, Expression value) {
1507
+		ConstMember result = new ConstMember(
1489 1508
 				BUILTIN,
1490 1509
 				cls,
1491 1510
 				Modifiers.STATIC | Modifiers.PUBLIC,
1492 1511
 				name,
1493
-				type,
1512
+				value.type,
1494 1513
 				id);
1514
+		result.value = value;
1515
+		return result;
1495 1516
 	}
1496 1517
 	
1497 1518
 	private static ConstructorMember constructor(

+ 24
- 17
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMembers.java View File

@@ -18,18 +18,17 @@ import org.openzen.zenscript.codemodel.expression.Expression;
18 18
 import org.openzen.zenscript.codemodel.expression.InterfaceCastExpression;
19 19
 import org.openzen.zenscript.codemodel.expression.MakeConstExpression;
20 20
 import org.openzen.zenscript.codemodel.expression.NullExpression;
21
-import org.openzen.zenscript.codemodel.expression.SameObjectExpression;
22 21
 import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
23 22
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
24 23
 import org.openzen.zenscript.codemodel.member.CallerMember;
25 24
 import org.openzen.zenscript.codemodel.member.CasterMember;
25
+import org.openzen.zenscript.codemodel.member.ConstMember;
26 26
 import org.openzen.zenscript.codemodel.member.ConstructorMember;
27 27
 import org.openzen.zenscript.codemodel.member.DestructorMember;
28 28
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
29 29
 import org.openzen.zenscript.codemodel.member.FieldMember;
30
-import org.openzen.zenscript.codemodel.member.ICallableMember;
31
-import org.openzen.zenscript.codemodel.member.ICasterMember;
32
-import org.openzen.zenscript.codemodel.member.IGettableMember;
30
+import org.openzen.zenscript.codemodel.member.FunctionalMember;
31
+import org.openzen.zenscript.codemodel.member.GetterMember;
33 32
 import org.openzen.zenscript.codemodel.member.IIteratorMember;
34 33
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
35 34
 import org.openzen.zenscript.codemodel.member.InnerDefinition;
@@ -61,7 +60,7 @@ public final class TypeMembers {
61 60
 	private final LocalMemberCache cache;
62 61
 	public final ITypeID type;
63 62
 	
64
-	private final List<TypeMember<ICasterMember>> casters = new ArrayList<>();
63
+	private final List<TypeMember<CasterMember>> casters = new ArrayList<>();
65 64
 	private final List<TypeMember<ImplementationMember>> implementations = new ArrayList<>();
66 65
 	private final List<TypeMember<IIteratorMember>> iterators = new ArrayList<>();
67 66
 	
@@ -72,6 +71,9 @@ public final class TypeMembers {
72 71
 	private final Map<OperatorType, DefinitionMemberGroup> operators = new HashMap<>();
73 72
 	
74 73
 	public TypeMembers(LocalMemberCache cache, ITypeID type) {
74
+		if (type == null)
75
+			throw new NullPointerException("Type must not be null!");
76
+		
75 77
 		this.cache = cache;
76 78
 		this.type = type;
77 79
 	}
@@ -174,6 +176,11 @@ public final class TypeMembers {
174 176
 		casters.add(new TypeMember<>(priority, caster));
175 177
 	}
176 178
 	
179
+	public void addConst(ConstMember member) {
180
+		DefinitionMemberGroup group = getOrCreateGroup(member.name, true);
181
+		group.setConst(member, TypeMemberPriority.SPECIFIED);
182
+	}
183
+	
177 184
 	public void addField(FieldMember member) {
178 185
 		addField(member, TypeMemberPriority.SPECIFIED);
179 186
 	}
@@ -183,12 +190,12 @@ public final class TypeMembers {
183 190
 		group.setField(member, priority);
184 191
 	}
185 192
 	
186
-	public void addGetter(IGettableMember member) {
193
+	public void addGetter(GetterMember member) {
187 194
 		addGetter(member, TypeMemberPriority.SPECIFIED);
188 195
 	}
189 196
 	
190
-	public void addGetter(IGettableMember member, TypeMemberPriority priority) {
191
-		DefinitionMemberGroup group = getOrCreateGroup(member.getName(), member.isStatic());
197
+	public void addGetter(GetterMember member, TypeMemberPriority priority) {
198
+		DefinitionMemberGroup group = getOrCreateGroup(member.name, member.isStatic());
192 199
 		group.setGetter(member, priority);
193 200
 	}
194 201
 	
@@ -223,7 +230,7 @@ public final class TypeMembers {
223 230
 		group.addMethod(member, priority);
224 231
 	}
225 232
 	
226
-	public void addOperator(OperatorType operator, ICallableMember member, TypeMemberPriority priority) {
233
+	public void addOperator(OperatorType operator, FunctionalMember member, TypeMemberPriority priority) {
227 234
 		DefinitionMemberGroup group = getOrCreateGroup(operator);
228 235
 		group.addMethod(member, priority);
229 236
 	}
@@ -290,14 +297,14 @@ public final class TypeMembers {
290 297
 	public Expression compare(CodePosition position, TypeScope scope, CompareType operator, Expression left, Expression right) {
291 298
 		if (operator == CompareType.EQ) {
292 299
 			DefinitionMemberGroup equal = getOrCreateGroup(OperatorType.EQUALS);
293
-			for (TypeMember<ICallableMember> member : equal.getMethodMembers()) {
294
-				if (member.member.getHeader().accepts(scope, right))
300
+			for (TypeMember<FunctionalMember> member : equal.getMethodMembers()) {
301
+				if (member.member.header.accepts(scope, right))
295 302
 					return equal.call(position, scope, left, new CallArguments(right), false);
296 303
 			}
297 304
 		} else if (operator == CompareType.NE) {
298 305
 			DefinitionMemberGroup equal = getOrCreateGroup(OperatorType.NOTEQUALS);
299
-			for (TypeMember<ICallableMember> member : equal.getMethodMembers()) {
300
-				if (member.member.getHeader().accepts(scope, right)) {
306
+			for (TypeMember<FunctionalMember> member : equal.getMethodMembers()) {
307
+				if (member.member.header.accepts(scope, right)) {
301 308
 					return equal.call(position, scope, left, new CallArguments(right), false);
302 309
 				}
303 310
 			}
@@ -350,7 +357,7 @@ public final class TypeMembers {
350 357
 		if (type.isOptional() && type.unwrap() == toType)
351 358
 			return true;
352 359
 		
353
-		for (TypeMember<ICasterMember> caster : casters) {
360
+		for (TypeMember<CasterMember> caster : casters) {
354 361
 			if (caster.member.isImplicit() && toType == caster.member.getTargetType())
355 362
 				return true;
356 363
 		}
@@ -362,7 +369,7 @@ public final class TypeMembers {
362 369
 		if (canCastImplicit(toType))
363 370
 			return true;
364 371
 		
365
-		for (TypeMember<ICasterMember> caster : casters) {
372
+		for (TypeMember<CasterMember> caster : casters) {
366 373
 			if (toType == caster.member.getTargetType())
367 374
 				return true;
368 375
 		}
@@ -385,7 +392,7 @@ public final class TypeMembers {
385 392
 		if (type.isOptional() && type.unwrap() == toType)
386 393
 			return new CheckNullExpression(position, value);
387 394
 		
388
-		for (TypeMember<ICasterMember> caster : casters) {
395
+		for (TypeMember<CasterMember> caster : casters) {
389 396
 			if (caster.member.isImplicit() && toType == caster.member.getTargetType())
390 397
 				return caster.member.cast(position, value, implicit);
391 398
 		}
@@ -403,7 +410,7 @@ public final class TypeMembers {
403 410
 		if (this.canCastImplicit(toType))
404 411
 			return castImplicit(position, value, toType, false);
405 412
 		
406
-		for (TypeMember<ICasterMember> caster : casters)
413
+		for (TypeMember<CasterMember> caster : casters)
407 414
 			if (toType == caster.member.getTargetType())
408 415
 				return caster.member.cast(position, value, false);
409 416
 		

+ 1
- 1
CompilerShared/build.gradle View File

@@ -16,5 +16,5 @@ if (!hasProperty('mainClass')) {
16 16
 dependencies {
17 17
 	compile 'org.json:json:20180130'
18 18
 	compile project(':CodeModel')
19
-	compile project(':Linker')
19
+	compile project(':Validator')
20 20
 }

+ 14
- 1
CompilerShared/src/main/java/org/openzen/zenscript/compiler/CompileScope.java View File

@@ -5,8 +5,11 @@
5 5
  */
6 6
 package org.openzen.zenscript.compiler;
7 7
 
8
+import java.util.HashMap;
8 9
 import java.util.List;
10
+import java.util.Map;
9 11
 import org.openzen.zenscript.codemodel.AccessScope;
12
+import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
10 13
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
11 14
 import org.openzen.zenscript.codemodel.scope.TypeScope;
12 15
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
@@ -22,11 +25,16 @@ public class CompileScope implements TypeScope {
22 25
 	private final GlobalTypeRegistry globalRegistry;
23 26
 	private final List<ExpansionDefinition> expansions;
24 27
 	private final LocalMemberCache cache;
28
+	private final Map<String, AnnotationDefinition> annotations = new HashMap<>();
25 29
 	
26
-	public CompileScope(AccessScope access, GlobalTypeRegistry globalRegistry, List<ExpansionDefinition> expansions) {
30
+	public CompileScope(AccessScope access, GlobalTypeRegistry globalRegistry, List<ExpansionDefinition> expansions, List<AnnotationDefinition> annotations) {
27 31
 		this.globalRegistry = globalRegistry;
28 32
 		this.expansions = expansions;
29 33
 		this.cache = new LocalMemberCache(access, globalRegistry, expansions);
34
+		
35
+		for (AnnotationDefinition annotation : annotations) {
36
+			this.annotations.put(annotation.getAnnotationName(), annotation);
37
+		}
30 38
 	}
31 39
 
32 40
 	@Override
@@ -43,4 +51,9 @@ public class CompileScope implements TypeScope {
43 51
 	public TypeMembers getTypeMembers(ITypeID type) {
44 52
 		return cache.get(type);
45 53
 	}
54
+
55
+	@Override
56
+	public AnnotationDefinition getAnnotation(String name) {
57
+		return annotations.get(name);
58
+	}
46 59
 }

+ 79
- 8
CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java View File

@@ -5,15 +5,20 @@
5 5
  */
6 6
 package org.openzen.zenscript.compiler;
7 7
 
8
+import java.util.ArrayList;
8 9
 import java.util.HashMap;
9 10
 import java.util.List;
10 11
 import java.util.Map;
12
+import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
11 13
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12 14
 import org.openzen.zenscript.codemodel.PackageDefinitions;
13 15
 import org.openzen.zenscript.codemodel.ScriptBlock;
16
+import org.openzen.zenscript.codemodel.annotations.AnnotationProcessor;
14 17
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
15 18
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
16
-import org.openzen.zenscript.linker.symbol.ISymbol;
19
+import org.openzen.zenscript.codemodel.type.ISymbol;
20
+import org.openzen.zenscript.validator.ValidationLogEntry;
21
+import org.openzen.zenscript.validator.Validator;
17 22
 
18 23
 /**
19 24
  *
@@ -23,38 +28,97 @@ public class SemanticModule {
23 28
 	public final String name;
24 29
 	public final String[] dependencies;
25 30
 	
26
-	public final boolean isValid;
27
-	public final ZSPackage pkg;
31
+	private State state;
32
+	public final ZSPackage rootPackage;
33
+	public final ZSPackage modulePackage;
28 34
 	public final PackageDefinitions definitions;
29 35
 	public final List<ScriptBlock> scripts;
30 36
 	public final Map<String, ISymbol> globals = new HashMap<>();
31 37
 	
32 38
 	public final CompilationUnit compilationUnit;
33 39
 	public final List<ExpansionDefinition> expansions;
40
+	public final List<AnnotationDefinition> annotations;
34 41
 	
35 42
 	public SemanticModule(
36 43
 			String name,
37 44
 			String[] dependencies,
38
-			boolean isValid,
39
-			ZSPackage pkg,
45
+			State state,
46
+			ZSPackage rootPackage,
47
+			ZSPackage modulePackage,
40 48
 			PackageDefinitions definitions,
41 49
 			List<ScriptBlock> scripts,
42 50
 			CompilationUnit compilationUnit,
43
-			List<ExpansionDefinition> expansions)
51
+			List<ExpansionDefinition> expansions,
52
+			List<AnnotationDefinition> annotations)
44 53
 	{
45 54
 		this.name = name;
46 55
 		this.dependencies = dependencies;
47 56
 		
48
-		this.isValid = isValid;
49
-		this.pkg = pkg;
57
+		this.state = state;
58
+		this.rootPackage = rootPackage;
59
+		this.modulePackage = modulePackage;
50 60
 		this.definitions = definitions;
51 61
 		this.scripts = scripts;
52 62
 		
53 63
 		this.compilationUnit = compilationUnit;
54 64
 		this.expansions = expansions;
65
+		this.annotations = annotations;
66
+	}
67
+	
68
+	public boolean isValid() {
69
+		return state != State.INVALID;
70
+	}
71
+	
72
+	public SemanticModule normalize() {
73
+		if (state != State.SEMANTIC)
74
+			throw new IllegalStateException("Module is invalid");
75
+		
76
+		AnnotationProcessor annotationProcessor = new AnnotationProcessor(rootPackage, definitions, compilationUnit.globalTypeRegistry, expansions, annotations);
77
+		List<ScriptBlock> processedScripts = new ArrayList<>();
78
+		for (ScriptBlock block : scripts)
79
+			processedScripts.add(annotationProcessor.process(block));
80
+		for (HighLevelDefinition definition : definitions.getAll())
81
+			annotationProcessor.process(definition);
82
+		
83
+		return new SemanticModule(
84
+				name,
85
+				dependencies,
86
+				State.NORMALIZED,
87
+				rootPackage,
88
+				modulePackage,
89
+				definitions,
90
+				processedScripts,
91
+				compilationUnit,
92
+				expansions,
93
+				annotations);
94
+	}
95
+	
96
+	public boolean validate() {
97
+		if (state != State.NORMALIZED)
98
+			throw new IllegalStateException("Module is not yet normalized");
99
+		
100
+		Validator validator = new Validator();
101
+		boolean isValid = true;
102
+		for (ScriptBlock script : scripts) {
103
+			isValid &= validator.validate(script);
104
+		}
105
+		for (HighLevelDefinition definition : definitions.getAll()) {
106
+			isValid &= validator.validate(definition);
107
+		}
108
+		
109
+		for (ValidationLogEntry entry : validator.getLog()) {
110
+			System.out.println(entry.kind + " " + entry.position.toString() + ": " + entry.message);
111
+		}
112
+		state = isValid ? State.VALIDATED : State.INVALID;
113
+		if (!isValid && validator.getLog().isEmpty())
114
+			System.out.println("ERROR: module is invalid but no errors have been generated");
115
+		return isValid;
55 116
 	}
56 117
 	
57 118
 	public void compile(ZenCodeCompiler compiler) {
119
+		if (state != State.VALIDATED)
120
+			throw new IllegalStateException("Module is not yet validated");
121
+		
58 122
 		for (HighLevelDefinition definition : definitions.getAll()) {
59 123
 			compiler.addDefinition(definition, this);
60 124
 		}
@@ -63,4 +127,11 @@ public class SemanticModule {
63 127
 		}
64 128
 		compiler.finish();
65 129
 	}
130
+	
131
+	public enum State {
132
+		INVALID,
133
+		SEMANTIC,
134
+		NORMALIZED,
135
+		VALIDATED
136
+	}
66 137
 }

+ 0
- 1
Constructor/build.gradle View File

@@ -17,7 +17,6 @@ dependencies {
17 17
 	compile 'org.json:json:20180130'
18 18
 	compile project(':CodeModel')
19 19
 	compile project(':Parser')
20
-	compile project(':Linker')
21 20
 	compile project(':Validator')
22 21
 	compile project(':CompilerShared')
23 22
 	compile project(':JavaBytecodeCompiler')

+ 2
- 1
Constructor/libraries/stdlib/module.json View File

@@ -8,6 +8,7 @@
8 8
 		"IllegalArgumentException": {"type": "Definition", "definition": "IllegalArgumentException"},
9 9
 		"StringBuilder": {"type": "Definition", "definition": "StringBuilder"},
10 10
 		"StringBuildable": {"type": "Definition", "definition": "StringBuildable"},
11
-		"panic": {"type": "Definition", "definition": "panic"}
11
+		"panic": {"type": "Definition", "definition": "panic"},
12
+		"Result": {"type": "Definition", "definition": "Result"}
12 13
 	}
13 14
 }

+ 7
- 26
Constructor/src/main/java/org/openzen/zenscript/constructor/Module.java View File

@@ -16,18 +16,15 @@ import java.util.Map;
16 16
 import org.json.JSONArray;
17 17
 import org.json.JSONObject;
18 18
 import org.json.JSONTokener;
19
-import org.openzen.zenscript.codemodel.HighLevelDefinition;
20 19
 import org.openzen.zenscript.codemodel.PackageDefinitions;
21 20
 import org.openzen.zenscript.codemodel.ScriptBlock;
22 21
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
23 22
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
24 23
 import org.openzen.zenscript.constructor.module.ModuleSpace;
25 24
 import org.openzen.zenscript.compiler.SemanticModule;
26
-import org.openzen.zenscript.linker.symbol.ISymbol;
25
+import org.openzen.zenscript.codemodel.type.ISymbol;
27 26
 import org.openzen.zenscript.parser.ParsedFile;
28 27
 import org.openzen.zenscript.shared.CompileException;
29
-import org.openzen.zenscript.validator.ValidationLogEntry;
30
-import org.openzen.zenscript.validator.Validator;
31 28
 
32 29
 /**
33 30
  *
@@ -107,7 +104,7 @@ public class Module {
107 104
 			// respective definitions, such as fields, constructors, methods...
108 105
 			// It doesn't yet compile the method contents.
109 106
 			try {
110
-				file.compileTypes(rootPackage, pkg, definitions, registry.compilationUnit.globalTypeRegistry, expansions, globals);
107
+				file.compileTypes(rootPackage, pkg, definitions, registry.compilationUnit.globalTypeRegistry, expansions, globals, registry.getAnnotations());
111 108
 			} catch (CompileException ex) {
112 109
 				System.out.println(ex.getMessage());
113 110
 				failed = true;
@@ -115,14 +112,14 @@ public class Module {
115 112
 		}
116 113
 		
117 114
 		if (failed)
118
-			return new SemanticModule(name, dependencies, false, pkg, definitions, Collections.emptyList(), registry.compilationUnit, expansions);
115
+			return new SemanticModule(name, dependencies, SemanticModule.State.INVALID, rootPackage, pkg, definitions, Collections.emptyList(), registry.compilationUnit, expansions, registry.getAnnotations());
119 116
 		
120 117
 		for (ParsedFile file : files) {
121 118
 			// compileMembers will register all definition members to their
122 119
 			// respective definitions, such as fields, constructors, methods...
123 120
 			// It doesn't yet compile the method contents.
124 121
 			try {
125
-				file.compileMembers(rootPackage, pkg, definitions, registry.compilationUnit.globalTypeRegistry, expansions, globals);
122
+				file.compileMembers(rootPackage, pkg, definitions, registry.compilationUnit.globalTypeRegistry, expansions, globals, registry.getAnnotations());
126 123
 			} catch (CompileException ex) {
127 124
 				System.out.println(ex.getMessage());
128 125
 				failed = true;
@@ -130,7 +127,7 @@ public class Module {
130 127
 		}
131 128
 		
132 129
 		if (failed)
133
-			return new SemanticModule(name, dependencies, false, pkg, definitions, Collections.emptyList(), registry.compilationUnit, expansions);
130
+			return new SemanticModule(name, dependencies, SemanticModule.State.INVALID, rootPackage, pkg, definitions, Collections.emptyList(), registry.compilationUnit, expansions, registry.getAnnotations());
134 131
 		
135 132
 		// scripts will store all the script blocks encountered in the files
136 133
 		List<ScriptBlock> scripts = new ArrayList<>();
@@ -139,29 +136,13 @@ public class Module {
139 136
 			// into semantic code. This semantic code can then be compiled
140 137
 			// to various targets.
141 138
 			try {
142
-				file.compileCode(rootPackage, pkg, definitions, registry.compilationUnit.globalTypeRegistry, expansions, scripts, globals);
139
+				file.compileCode(rootPackage, pkg, definitions, registry.compilationUnit.globalTypeRegistry, expansions, scripts, globals, registry.getAnnotations());
143 140
 			} catch (CompileException ex) {
144 141
 				System.out.println(ex.getMessage());
145 142
 				failed = true;
146 143
 			}
147 144
 		}
148 145
 		
149
-		if (failed)
150
-			return new SemanticModule(name, dependencies, false, pkg, definitions, Collections.emptyList(), registry.compilationUnit, expansions);
151
-		
152
-		Validator validator = new Validator();
153
-		boolean isValid = true;
154
-		for (ScriptBlock script : scripts) {
155
-			isValid &= validator.validate(script);
156
-		}
157
-		for (HighLevelDefinition definition : definitions.getAll()) {
158
-			isValid &= validator.validate(definition);
159
-		}
160
-		
161
-		for (ValidationLogEntry entry : validator.getLog()) {
162
-			System.out.println(entry.kind + " " + entry.position.toString() + ": " + entry.message);
163
-		}
164
-		
165
-		return new SemanticModule(name, dependencies, isValid, pkg, definitions, scripts, registry.compilationUnit, expansions);
146
+		return new SemanticModule(name, dependencies, SemanticModule.State.SEMANTIC, rootPackage, pkg, definitions, Collections.emptyList(), registry.compilationUnit, expansions, registry.getAnnotations());
166 147
 	}
167 148
 }

+ 2
- 2
Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleLoader.java View File

@@ -18,7 +18,7 @@ import org.openzen.zenscript.constructor.ConstructorException;
18 18
 import org.openzen.zenscript.constructor.JSONUtils;
19 19
 import org.openzen.zenscript.constructor.Module;
20 20
 import org.openzen.zenscript.constructor.ModuleLoader;
21
-import org.openzen.zenscript.linker.symbol.TypeSymbol;
21
+import org.openzen.zenscript.codemodel.type.TypeSymbol;
22 22
 import org.openzen.zenscript.parser.ParsedFile;
23 23
 
24 24
 /**
@@ -72,7 +72,7 @@ public class DirectoryModuleLoader implements ModuleReference {
72 72
 				space.addModule(dependencyName, loader.getModule(dependencyName));
73 73
 
74 74
 			Module module = new Module(moduleName, directory, jsonFile);
75
-			ZSPackage pkg = new ZSPackage(null, module.packageName);
75
+			ZSPackage pkg = isStdlib ? unit.globalTypeRegistry.stdlib : new ZSPackage(null, module.packageName);
76 76
 
77 77
 			ParsedFile[] parsedFiles = module.parse(pkg);
78 78
 			SemanticModule result = Module.compileSyntaxToSemantic(module.name, module.dependencies, pkg, parsedFiles, space);

+ 18
- 3
Constructor/src/main/java/org/openzen/zenscript/constructor/module/ModuleSpace.java View File

@@ -10,29 +10,40 @@ import java.util.ArrayList;
10 10
 import java.util.HashMap;
11 11
 import java.util.List;
12 12
 import java.util.Map;
13
+import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
14
+import org.openzen.zenscript.codemodel.annotations.NativeAnnotationDefinition;
15
+import org.openzen.zenscript.codemodel.annotations.PreconditionAnnotationDefinition;
13 16
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
14 17
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
15 18
 import org.openzen.zenscript.compiler.CompilationUnit;
16 19
 import org.openzen.zenscript.constructor.ConstructorException;
17
-import org.openzen.zenscript.linker.symbol.ISymbol;
20
+import org.openzen.zenscript.codemodel.type.ISymbol;
18 21
 
19 22
 /**
20 23
  *
21 24
  * @author Hoofdgebruiker
22 25
  */
23
-public class ModuleSpace {
26
+public final class ModuleSpace {
24 27
 	private final ZSPackage rootPackage = new ZSPackage(null, "");
25 28
 	public final CompilationUnit compilationUnit;
26 29
 	public final ZSPackage globalsPackage = new ZSPackage(null, "");
27 30
 	private final List<ExpansionDefinition> expansions = new ArrayList<>();
28 31
 	private final Map<String, ISymbol> globals = new HashMap<>();
32
+	private final List<AnnotationDefinition> annotations = new ArrayList<>();
29 33
 	
30 34
 	public ModuleSpace(CompilationUnit compilationUnit) {
31 35
 		this.compilationUnit = compilationUnit;
36
+		
37
+		addAnnotation(NativeAnnotationDefinition.INSTANCE);
38
+		addAnnotation(PreconditionAnnotationDefinition.INSTANCE);
39
+	}
40
+	
41
+	public void addAnnotation(AnnotationDefinition annotation) {
42
+		annotations.add(annotation);
32 43
 	}
33 44
 	
34 45
 	public void addModule(String name, SemanticModule dependency) {
35
-		rootPackage.add(name, dependency.pkg);
46
+		rootPackage.add(name, dependency.modulePackage);
36 47
 		dependency.definitions.registerExpansionsTo(expansions);
37 48
 		
38 49
 		for (Map.Entry<String, ISymbol> globalEntry : dependency.globals.entrySet()) {
@@ -54,4 +65,8 @@ public class ModuleSpace {
54 65
 	public Map<String, ISymbol> collectGlobals() {
55 66
 		return globals;
56 67
 	}
68
+	
69
+	public List<AnnotationDefinition> getAnnotations() {
70
+		return annotations;
71
+	}
57 72
 }

+ 27
- 4
IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalTarget.java View File

@@ -77,10 +77,24 @@ public class LocalTarget implements IDETarget {
77 77
 			}
78 78
 			
79 79
 			SemanticModule module = moduleLoader.getModule(target.getModule());
80
+			module = module.normalize();
81
+			module.validate();
82
+			
80 83
 			ZenCodeCompiler compiler = target.createCompiler(module);
81
-			moduleLoader.getModule("stdlib").compile(compiler);
84
+			if (!module.isValid())
85
+				return compiler;
86
+			
87
+			SemanticModule stdlib = moduleLoader.getModule("stdlib");
88
+			stdlib = stdlib.normalize();
89
+			stdlib.validate();
90
+			if (!stdlib.isValid())
91
+				return compiler;
92
+			stdlib.compile(compiler);
93
+			
94
+			boolean isValid = compileDependencies(moduleLoader, compiler, compiledModules, module);
95
+			if (!isValid)
96
+				return compiler;
82 97
 			
83
-			compileDependencies(moduleLoader, compiler, compiledModules, module);
84 98
 			module.compile(compiler);
85 99
 			return compiler;
86 100
 		} catch (IOException ex) {
@@ -89,15 +103,24 @@ public class LocalTarget implements IDETarget {
89 103
 		}
90 104
 	}
91 105
 	
92
-	private void compileDependencies(ModuleLoader loader, ZenCodeCompiler compiler, Set<String> compiledModules, SemanticModule module) {
106
+	private boolean compileDependencies(ModuleLoader loader, ZenCodeCompiler compiler, Set<String> compiledModules, SemanticModule module) {
93 107
 		for (String dependency : module.dependencies) {
94 108
 			if (compiledModules.contains(module.name))
95 109
 				continue;
96 110
 			
97 111
 			SemanticModule dependencyModule = loader.getModule(dependency);
98
-			compileDependencies(loader, compiler, compiledModules, dependencyModule);
112
+			module = module.normalize();
113
+			module.validate();
114
+			if (!module.isValid())
115
+				return false;
116
+			
117
+			if (!compileDependencies(loader, compiler, compiledModules, dependencyModule))
118
+				return false;
119
+			
99 120
 			module.compile(compiler);
100 121
 			compiledModules.add(module.name);
101 122
 		}
123
+		
124
+		return true;
102 125
 	}
103 126
 }

+ 0
- 3
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/WindowView.java View File

@@ -5,13 +5,10 @@
5 5
  */
6 6
 package org.openzen.zenscript.ide.ui.view;
7 7
 
8
-import org.openzen.drawablegui.DComponent;
9 8
 import org.openzen.drawablegui.DDimensionPreferences;
10
-import org.openzen.drawablegui.DDrawable;
11 9
 import org.openzen.drawablegui.DEmptyView;
12 10
 import org.openzen.drawablegui.scroll.DScrollPane;
13 11
 import org.openzen.drawablegui.DSideLayout;
14
-import org.openzen.drawablegui.live.LiveList;
15 12
 import org.openzen.drawablegui.style.DStyleClass;
16 13
 import org.openzen.drawablegui.tree.DTreeView;
17 14
 import org.openzen.drawablegui.tree.DTreeViewStyle;

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

@@ -1342,6 +1342,96 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1342 1342
         javaWriter.label(end);
1343 1343
         return null;
1344 1344
     }
1345
+	
1346
+	@Override
1347
+	public Void visitConst(ConstExpression expression) {
1348
+		BuiltinID builtin = expression.constant.builtin;
1349
+		if (builtin == null) {
1350
+			if (!checkAndGetFieldInfo(expression.constant, true))
1351
+	            throw new IllegalStateException("Call target has no field info!");
1352
+			
1353
+			return null;
1354
+		}
1355
+		
1356
+		switch (builtin) {
1357
+			case BYTE_GET_MIN_VALUE:
1358
+				javaWriter.iConst0();
1359
+				break;
1360
+			case BYTE_GET_MAX_VALUE:
1361
+				javaWriter.constant(0xFF);
1362
+				break;
1363
+			case SBYTE_GET_MIN_VALUE:
1364
+				javaWriter.getStaticField(BYTE_MIN_VALUE);
1365
+				break;
1366
+			case SBYTE_GET_MAX_VALUE:
1367
+				javaWriter.getStaticField(BYTE_MAX_VALUE);
1368
+				break;
1369
+			case SHORT_GET_MIN_VALUE:
1370
+				javaWriter.getStaticField(SHORT_MIN_VALUE);
1371
+				break;
1372
+			case SHORT_GET_MAX_VALUE:
1373
+				javaWriter.getStaticField(SHORT_MAX_VALUE);
1374
+				break;
1375
+			case USHORT_GET_MIN_VALUE:
1376
+				javaWriter.iConst0();
1377
+				break;
1378
+			case USHORT_GET_MAX_VALUE:
1379
+				javaWriter.constant(0xFFFF);
1380
+				break;
1381
+			case INT_GET_MIN_VALUE:
1382
+				javaWriter.getStaticField(INTEGER_MIN_VALUE);
1383
+				break;
1384
+			case INT_GET_MAX_VALUE:
1385
+				javaWriter.getStaticField(INTEGER_MAX_VALUE);
1386
+				break;
1387
+			case UINT_GET_MIN_VALUE:
1388
+				javaWriter.iConst0();
1389
+				break;
1390
+			case UINT_GET_MAX_VALUE:
1391
+				javaWriter.constant(-1);
1392
+				break;
1393
+			case LONG_GET_MIN_VALUE:
1394
+				javaWriter.getStaticField(LONG_MIN_VALUE);
1395
+				break;
1396
+			case LONG_GET_MAX_VALUE:
1397
+				javaWriter.getStaticField(LONG_MAX_VALUE);
1398
+				break;
1399
+			case ULONG_GET_MIN_VALUE:
1400
+				javaWriter.iConst0();
1401
+				break;
1402
+			case ULONG_GET_MAX_VALUE:
1403
+				javaWriter.constant(-1L);
1404
+				break;
1405
+			case FLOAT_GET_MIN_VALUE:
1406
+				javaWriter.getStaticField(FLOAT_MIN_VALUE);
1407
+				break;
1408
+			case FLOAT_GET_MAX_VALUE:
1409
+				javaWriter.getStaticField(FLOAT_MAX_VALUE);
1410
+				break;
1411
+			case DOUBLE_GET_MIN_VALUE:
1412
+				javaWriter.getStaticField(DOUBLE_MIN_VALUE);
1413
+				break;
1414
+			case DOUBLE_GET_MAX_VALUE:
1415
+				javaWriter.getStaticField(DOUBLE_MAX_VALUE);
1416
+				break;
1417
+			case CHAR_GET_MIN_VALUE:
1418
+				javaWriter.getStaticField(CHARACTER_MIN_VALUE);
1419
+				break;
1420
+			case CHAR_GET_MAX_VALUE:
1421
+				javaWriter.getStaticField(CHARACTER_MAX_VALUE);
1422
+				break;
1423
+			case ENUM_VALUES: {
1424
+				DefinitionTypeID type = (DefinitionTypeID) expression.type;
1425
+				JavaClassInfo cls = type.definition.getTag(JavaClassInfo.class);
1426
+				javaWriter.invokeStatic(new JavaMethodInfo(cls, "values", "()[L" + cls.internalClassName + ";", PUBLIC_STATIC));
1427
+				break;
1428
+			}
1429
+			default:
1430
+				throw new UnsupportedOperationException("Unknown builtin: " + builtin);
1431
+		}
1432
+		
1433
+		return null;
1434
+	}
1345 1435
 
1346 1436
     @Override
1347 1437
     public Void visitConstantBool(ConstantBoolExpression expression) {
@@ -1354,7 +1444,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1354 1444
 
1355 1445
     @Override
1356 1446
     public Void visitConstantByte(ConstantByteExpression expression) {
1357
-        getJavaWriter().biPush(expression.value);
1447
+        getJavaWriter().constant(expression.value);
1358 1448
         return null;
1359 1449
     }
1360 1450
 
@@ -1973,7 +2063,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1973 2063
 				throw new UnsupportedOperationException("Unknown builtin: " + builtin);
1974 2064
 		}
1975 2065
 		
1976
-        return null;
2066
+		throw new UnsupportedOperationException("Unknown builtin: " + builtin);
1977 2067
     }
1978 2068
 
1979 2069
     @Override

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

@@ -20,6 +20,7 @@ import org.openzen.zenscript.codemodel.expression.CastExpression;
20 20
 import org.openzen.zenscript.codemodel.expression.CheckNullExpression;
21 21
 import org.openzen.zenscript.codemodel.expression.CoalesceExpression;
22 22
 import org.openzen.zenscript.codemodel.expression.ConditionalExpression;
23
+import org.openzen.zenscript.codemodel.expression.ConstExpression;
23 24
 import org.openzen.zenscript.codemodel.expression.ConstantBoolExpression;
24 25
 import org.openzen.zenscript.codemodel.expression.ConstantByteExpression;
25 26
 import org.openzen.zenscript.codemodel.expression.ConstantCharExpression;
@@ -156,6 +157,11 @@ public class JavaPreDecrementVisitor implements ExpressionVisitor<Void> {
156 157
 	public Void visitConditional(ConditionalExpression expression) {
157 158
 		throw new UnsupportedOperationException("Invalid increment target");
158 159
 	}
160
+	
161
+	@Override
162
+	public Void visitConst(ConstExpression expression) {
163
+		throw new UnsupportedOperationException("Invalid increment target");
164
+	}
159 165
 
160 166
 	@Override
161 167
 	public Void visitConstantBool(ConstantBoolExpression expression) {

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

@@ -20,6 +20,7 @@ import org.openzen.zenscript.codemodel.expression.CastExpression;
20 20
 import org.openzen.zenscript.codemodel.expression.CheckNullExpression;
21 21
 import org.openzen.zenscript.codemodel.expression.CoalesceExpression;
22 22
 import org.openzen.zenscript.codemodel.expression.ConditionalExpression;
23
+import org.openzen.zenscript.codemodel.expression.ConstExpression;
23 24
 import org.openzen.zenscript.codemodel.expression.ConstantBoolExpression;
24 25
 import org.openzen.zenscript.codemodel.expression.ConstantByteExpression;
25 26
 import org.openzen.zenscript.codemodel.expression.ConstantCharExpression;
@@ -156,6 +157,11 @@ public class JavaPreIncrementVisitor implements ExpressionVisitor<Void> {
156 157
 	public Void visitConditional(ConditionalExpression expression) {
157 158
 		throw new UnsupportedOperationException("Invalid increment target");
158 159
 	}
160
+	
161
+	@Override
162
+	public Void visitConst(ConstExpression expression) {
163
+		throw new UnsupportedOperationException("Invalid increment target");
164
+	}
159 165
 
160 166
 	@Override
161 167
 	public Void visitConstantBool(ConstantBoolExpression expression) {

+ 10
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaMemberVisitor.java View File

@@ -19,7 +19,6 @@ import org.openzen.zenscript.javabytecode.compiler.*;
19 19
 import java.util.List;
20 20
 
21 21
 public class JavaMemberVisitor implements MemberVisitor<Void> {
22
-
23 22
     private final ClassWriter writer;
24 23
     private final JavaClassInfo toClass;
25 24
     private final HighLevelDefinition definition;
@@ -36,6 +35,16 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
36 35
         this.clinitStatementVisitor.start();
37 36
         CompilerUtils.writeDefaultFieldInitializers(javaWriter, definition, true);
38 37
     }
38
+	
39
+	@Override
40
+	public Void visitConst(ConstMember member) {
41
+        //TODO calc signature
42
+        String signature = null;
43
+        final String descriptor = Type.getDescriptor(member.type.accept(JavaTypeClassVisitor.INSTANCE));
44
+        writer.visitField(CompilerUtils.calcAccess(member.modifiers), member.name, descriptor, signature, null).visitEnd();
45
+        member.setTag(JavaFieldInfo.class, new JavaFieldInfo(toClass, member.name, descriptor));
46
+        return null;
47
+	}
39 48
 
40 49
     @Override
41 50
     public Void visitField(FieldMember member) {

+ 0
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/ExpressionHoistingChecker.java View File


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save