Browse Source

- Made important modifications to error reporting so it provides meaningful info

- Fix various normalization bugs
- Fixed bugs with the new stored type system
Stan Hebben 6 years ago
parent
commit
bd90cfe0be
100 changed files with 583 additions and 482 deletions
  1. 12
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/ScriptBlock.java
  2. 19
    12
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/PreconditionForMethod.java
  3. 0
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/FunctionDefinition.java
  4. 3
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/VariantDefinition.java
  5. 3
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ZSPackage.java
  6. 2
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/Expression.java
  7. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionBuilder.java
  8. 0
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/InvalidExpression.java
  9. 2
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/MatchExpression.java
  10. 3
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/VariantValueExpression.java
  11. 9
    8
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/IPartialExpression.java
  12. 6
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialGlobalExpression.java
  13. 5
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialMemberGroupExpression.java
  14. 6
    6
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialPackageExpression.java
  15. 5
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialStaticMemberGroupExpression.java
  16. 2
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialTypeExpression.java
  17. 3
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialVariantOptionExpression.java
  18. 8
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/BaseScope.java
  19. 4
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/BlockScope.java
  20. 3
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/CompileTypeScope.java
  21. 5
    6
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/DefinitionScope.java
  22. 7
    6
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ExpressionScope.java
  23. 4
    6
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FileScope.java
  24. 4
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ForeachScope.java
  25. 4
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FunctionScope.java
  26. 4
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/GenericFunctionScope.java
  27. 3
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/GlobalScriptScope.java
  28. 3
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ImplementationScope.java
  29. 5
    6
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LambdaScope.java
  30. 4
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LoopScope.java
  31. 2
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/StatementScope.java
  32. 5
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/IfStatement.java
  33. 6
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/VarStatement.java
  34. 22
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/FunctionTypeID.java
  35. 5
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/InvalidTypeID.java
  36. 14
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ModifiedTypeID.java
  37. 1
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/StoredType.java
  38. 8
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeID.java
  39. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeMatcher.java
  40. 8
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java
  41. 93
    125
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberGroup.java
  42. 12
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMembers.java
  43. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/SharedStorageTag.java
  44. 4
    3
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java
  45. 5
    2
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
  46. 4
    4
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaForeachWriter.java
  47. 1
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreDecrementVisitor.java
  48. 1
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreIncrementVisitor.java
  49. 2
    2
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaStatementVisitor.java
  50. 0
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java
  51. 1
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaDefinitionVisitor.java
  52. 1
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceExpressionFormatter.java
  53. 2
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/scope/JavaSourceStatementScope.java
  54. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunction.java
  55. 7
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunctionParameter.java
  56. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedVariant.java
  57. 5
    2
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedVariantOption.java
  58. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedCallArguments.java
  59. 5
    8
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedDollarExpression.java
  60. 2
    2
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpression.java
  61. 3
    3
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionAndAnd.java
  62. 9
    4
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionArray.java
  63. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionAssign.java
  64. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionBinary.java
  65. 3
    3
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionBracket.java
  66. 26
    30
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCall.java
  67. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCast.java
  68. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCoalesce.java
  69. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCompare.java
  70. 4
    4
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionConditional.java
  71. 3
    3
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionFloat.java
  72. 10
    6
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionFunction.java
  73. 10
    9
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionIndex.java
  74. 2
    2
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionInt.java
  75. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionIs.java
  76. 10
    14
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionMap.java
  77. 3
    3
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionMember.java
  78. 2
    2
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionOpAssign.java
  79. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionOrOr.java
  80. 3
    3
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionOuter.java
  81. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionPostCall.java
  82. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionRange.java
  83. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionSame.java
  84. 2
    11
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionString.java
  85. 2
    2
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionSuper.java
  86. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionUnary.java
  87. 2
    3
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionVariable.java
  88. 15
    21
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedMatchExpression.java
  89. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedPanicExpression.java
  90. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedThrowExpression.java
  91. 4
    3
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedTryConvertExpression.java
  92. 4
    4
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedTryRethrowExpression.java
  93. 6
    6
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedCatchClause.java
  94. 15
    9
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedLambdaFunctionBody.java
  95. 8
    1
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementDoWhile.java
  96. 7
    2
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementExpression.java
  97. 22
    16
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementForeach.java
  98. 9
    1
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementIf.java
  99. 9
    3
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementLock.java
  100. 0
    0
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementReturn.java

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

5
  */
5
  */
6
 package org.openzen.zenscript.codemodel;
6
 package org.openzen.zenscript.codemodel;
7
 
7
 
8
+import java.util.ArrayList;
8
 import java.util.List;
9
 import java.util.List;
10
+import org.openzen.zencode.shared.ConcatMap;
9
 import org.openzen.zencode.shared.Taggable;
11
 import org.openzen.zencode.shared.Taggable;
10
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
12
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
13
+import org.openzen.zenscript.codemodel.scope.TypeScope;
14
+import org.openzen.zenscript.codemodel.statement.LoopStatement;
11
 import org.openzen.zenscript.codemodel.statement.Statement;
15
 import org.openzen.zenscript.codemodel.statement.Statement;
12
 
16
 
13
 /**
17
 /**
28
 		result.addAllTagsFrom(this);
32
 		result.addAllTagsFrom(this);
29
 		return result;
33
 		return result;
30
 	}
34
 	}
35
+	
36
+	public ScriptBlock normalize(TypeScope scope) {
37
+		List<Statement> result = new ArrayList<>();
38
+		for (Statement statement : statements) {
39
+			result.add(statement.normalize(scope, ConcatMap.empty(LoopStatement.class, LoopStatement.class)));
40
+		}
41
+		return new ScriptBlock(pkg, result);
42
+	}
31
 }
43
 }

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

9
 import java.util.Arrays;
9
 import java.util.Arrays;
10
 import java.util.List;
10
 import java.util.List;
11
 import org.openzen.zencode.shared.CodePosition;
11
 import org.openzen.zencode.shared.CodePosition;
12
+import org.openzen.zencode.shared.CompileException;
12
 import org.openzen.zenscript.codemodel.context.StatementContext;
13
 import org.openzen.zenscript.codemodel.context.StatementContext;
13
 import org.openzen.zenscript.codemodel.context.TypeContext;
14
 import org.openzen.zenscript.codemodel.context.TypeContext;
14
 import org.openzen.zenscript.codemodel.expression.Expression;
15
 import org.openzen.zenscript.codemodel.expression.Expression;
83
 		if (body == null)
84
 		if (body == null)
84
 			return body;
85
 			return body;
85
 		
86
 		
86
-		ExpressionScope expressionScope = new ExpressionScope(scope, BasicTypeID.BOOL.stored);
87
-		List<Statement> statements = new ArrayList<>();
88
-		ExpressionBuilder expressionBuilder = new ExpressionBuilder(position, expressionScope);
89
-		Expression inverseCondition = expressionBuilder.not(condition);
90
-		Statement throwStatement = new ExpressionStatement(position, new PanicExpression(position, BasicTypeID.VOID.stored, message));
91
-		statements.add(new IfStatement(position, inverseCondition, throwStatement, null));
92
-		
93
-		if (body instanceof BlockStatement) {
94
-			statements.addAll(Arrays.asList(((BlockStatement)body).statements));
95
-		} else {
96
-			statements.add(body);
87
+		try {
88
+			ExpressionScope expressionScope = new ExpressionScope(scope, BasicTypeID.BOOL.stored);
89
+			List<Statement> statements = new ArrayList<>();
90
+			ExpressionBuilder expressionBuilder = new ExpressionBuilder(position, expressionScope);
91
+			Expression inverseCondition = expressionBuilder.not(condition);
92
+			Statement throwStatement = new ExpressionStatement(position, new PanicExpression(position, BasicTypeID.VOID.stored, message));
93
+			statements.add(new IfStatement(position, inverseCondition, throwStatement, null));
94
+
95
+			if (body instanceof BlockStatement) {
96
+				statements.addAll(Arrays.asList(((BlockStatement)body).statements));
97
+			} else {
98
+				statements.add(body);
99
+			}
100
+			return new BlockStatement(position, statements.toArray(new Statement[statements.size()]));
101
+		} catch (CompileException ex) {
102
+			// TODO
103
+			ex.printStackTrace();
104
+			return body;
97
 		}
105
 		}
98
-		return new BlockStatement(position, statements.toArray(new Statement[statements.size()]));
99
 	}
106
 	}
100
 
107
 
101
 	@Override
108
 	@Override

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

25
  */
25
  */
26
 public class FunctionDefinition extends HighLevelDefinition {
26
 public class FunctionDefinition extends HighLevelDefinition {
27
 	public FunctionHeader header;
27
 	public FunctionHeader header;
28
-	public Statement statement;
29
 	public CallerMember caller;
28
 	public CallerMember caller;
30
 	public final TypeMemberGroup callerGroup;
29
 	public final TypeMemberGroup callerGroup;
31
 	
30
 	
46
 	}
45
 	}
47
 	
46
 	
48
 	public void setCode(Statement statement) {
47
 	public void setCode(Statement statement) {
49
-		this.statement = statement;
50
 		caller.setBody(statement);
48
 		caller.setBody(statement);
51
 	}
49
 	}
52
 
50
 

+ 3
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/VariantDefinition.java View File

45
 	}
45
 	}
46
 	
46
 	
47
 	public static class Option extends Taggable {
47
 	public static class Option extends Taggable {
48
+		public final CodePosition position;
48
 		public final VariantDefinition variant;
49
 		public final VariantDefinition variant;
49
 		public final String name;
50
 		public final String name;
50
 		public final int ordinal;
51
 		public final int ordinal;
51
 		public final StoredType[] types;
52
 		public final StoredType[] types;
52
 		
53
 		
53
-		public Option(VariantDefinition variant, String name, int ordinal, StoredType[] types) {
54
+		public Option(CodePosition position, VariantDefinition variant, String name, int ordinal, StoredType[] types) {
55
+			this.position = position;
54
 			this.variant = variant;
56
 			this.variant = variant;
55
 			this.name = name;
57
 			this.name = name;
56
 			this.ordinal = ordinal;
58
 			this.ordinal = ordinal;

+ 3
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ZSPackage.java View File

9
 import java.util.List;
9
 import java.util.List;
10
 import java.util.Map;
10
 import java.util.Map;
11
 import org.openzen.zencode.shared.CodePosition;
11
 import org.openzen.zencode.shared.CodePosition;
12
+import org.openzen.zencode.shared.CompileException;
12
 import org.openzen.zencode.shared.CompileExceptionCode;
13
 import org.openzen.zencode.shared.CompileExceptionCode;
13
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
14
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
14
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
15
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
15
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
16
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
16
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
17
 import org.openzen.zenscript.codemodel.partial.PartialPackageExpression;
17
 import org.openzen.zenscript.codemodel.partial.PartialPackageExpression;
18
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
18
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
50
 		subPackages.put(name, subPackage);
50
 		subPackages.put(name, subPackage);
51
 	}
51
 	}
52
 	
52
 	
53
-	public IPartialExpression getMember(CodePosition position, GlobalTypeRegistry registry, GenericName name) {
53
+	public IPartialExpression getMember(CodePosition position, GlobalTypeRegistry registry, GenericName name) throws CompileException {
54
 		if (subPackages.containsKey(name.name) && name.hasNoArguments())
54
 		if (subPackages.containsKey(name.name) && name.hasNoArguments())
55
 			return new PartialPackageExpression(position, subPackages.get(name.name));
55
 			return new PartialPackageExpression(position, subPackages.get(name.name));
56
 		
56
 		
57
 		if (types.containsKey(name.name)) {
57
 		if (types.containsKey(name.name)) {
58
 			if (types.get(name.name).typeParameters.length != name.getNumberOfArguments())
58
 			if (types.get(name.name).typeParameters.length != name.getNumberOfArguments())
59
-				return new InvalidExpression(position, CompileExceptionCode.TYPE_ARGUMENTS_INVALID_NUMBER, "Invalid number of type arguments");
59
+				throw new CompileException(position, CompileExceptionCode.TYPE_ARGUMENTS_INVALID_NUMBER, "Invalid number of type arguments");
60
 			
60
 			
61
 			return new PartialTypeExpression(position, registry.getForDefinition(types.get(name.name), name.arguments), name.arguments);
61
 			return new PartialTypeExpression(position, registry.getForDefinition(types.get(name.name), name.arguments), name.arguments);
62
 		}
62
 		}

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

11
 import java.util.function.Consumer;
11
 import java.util.function.Consumer;
12
 import java.util.stream.Collectors;
12
 import java.util.stream.Collectors;
13
 import org.openzen.zencode.shared.CodePosition;
13
 import org.openzen.zencode.shared.CodePosition;
14
+import org.openzen.zencode.shared.CompileException;
14
 import org.openzen.zencode.shared.CompileExceptionCode;
15
 import org.openzen.zencode.shared.CompileExceptionCode;
15
 import org.openzen.zenscript.codemodel.FunctionHeader;
16
 import org.openzen.zenscript.codemodel.FunctionHeader;
16
 import org.openzen.zenscript.codemodel.OperatorType;
17
 import org.openzen.zenscript.codemodel.OperatorType;
116
 	}
117
 	}
117
 	
118
 	
118
 	@Override
119
 	@Override
119
-	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) {
120
+	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) throws CompileException {
120
 		return scope.getTypeMembers(type).getOrCreateGroup(OperatorType.CALL).call(position, scope, this, arguments, false);
121
 		return scope.getTypeMembers(type).getOrCreateGroup(OperatorType.CALL).call(position, scope, this, arguments, false);
121
 	}
122
 	}
122
 	
123
 	

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

64
 				compiledArguments.getNumberOfTypeArguments() == 0 ? member.getHeader() : member.getHeader().fillGenericArguments(scope.getTypeRegistry(), compiledArguments.typeArguments, scope.getLocalTypeParameters()));
64
 				compiledArguments.getNumberOfTypeArguments() == 0 ? member.getHeader() : member.getHeader().fillGenericArguments(scope.getTypeRegistry(), compiledArguments.typeArguments, scope.getLocalTypeParameters()));
65
 	}
65
 	}
66
 	
66
 	
67
-	public Expression not(Expression value) {
67
+	public Expression not(Expression value) throws CompileException {
68
 		TypeMembers members = scope.getTypeMembers(value.type);
68
 		TypeMembers members = scope.getTypeMembers(value.type);
69
 		return members.getOrCreateGroup(OperatorType.NOT)
69
 		return members.getOrCreateGroup(OperatorType.NOT)
70
 				.call(position, scope, value, CallArguments.EMPTY, false);
70
 				.call(position, scope, value, CallArguments.EMPTY, false);

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

9
 import org.openzen.zencode.shared.CompileException;
9
 import org.openzen.zencode.shared.CompileException;
10
 import org.openzen.zencode.shared.CompileExceptionCode;
10
 import org.openzen.zencode.shared.CompileExceptionCode;
11
 import org.openzen.zenscript.codemodel.scope.TypeScope;
11
 import org.openzen.zenscript.codemodel.scope.TypeScope;
12
-import org.openzen.zenscript.codemodel.type.BasicTypeID;
13
 import org.openzen.zenscript.codemodel.type.StoredType;
12
 import org.openzen.zenscript.codemodel.type.StoredType;
14
 
13
 
15
 /**
14
 /**
27
 		this.message = message;
26
 		this.message = message;
28
 	}
27
 	}
29
 	
28
 	
30
-	public InvalidExpression(CodePosition position, CompileExceptionCode code, String message) {
31
-		this(position, BasicTypeID.UNDETERMINED.stored, code, message);
32
-	}
33
-	
34
 	public InvalidExpression(StoredType type, CompileException cause) {
29
 	public InvalidExpression(StoredType type, CompileException cause) {
35
 		this(cause.position, type, cause.code, cause.getMessage());
30
 		this(cause.position, type, cause.code, cause.getMessage());
36
 	}
31
 	}

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

16
 import org.openzen.zenscript.codemodel.statement.SwitchCase;
16
 import org.openzen.zenscript.codemodel.statement.SwitchCase;
17
 import org.openzen.zenscript.codemodel.statement.SwitchStatement;
17
 import org.openzen.zenscript.codemodel.statement.SwitchStatement;
18
 import org.openzen.zenscript.codemodel.statement.VarStatement;
18
 import org.openzen.zenscript.codemodel.statement.VarStatement;
19
+import org.openzen.zenscript.codemodel.statement.VariableID;
19
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
20
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
20
 import org.openzen.zenscript.codemodel.type.StoredType;
21
 import org.openzen.zenscript.codemodel.type.StoredType;
21
 
22
 
65
 	}
66
 	}
66
 	
67
 	
67
 	public SwitchedMatch convertToSwitch(String tempVariable) {
68
 	public SwitchedMatch convertToSwitch(String tempVariable) {
68
-		VarStatement result = new VarStatement(position, tempVariable, type, null, false);
69
+		VarStatement result = new VarStatement(position, new VariableID(), tempVariable, type, null, false);
69
 		SwitchStatement switchStatement = new SwitchStatement(position, null, value);
70
 		SwitchStatement switchStatement = new SwitchStatement(position, null, value);
70
 		boolean hasDefault = false;
71
 		boolean hasDefault = false;
71
 		for (MatchExpression.Case matchCase : cases) {
72
 		for (MatchExpression.Case matchCase : cases) {

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

7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
10
 import org.openzen.zenscript.codemodel.member.ref.VariantOptionRef;
11
 import org.openzen.zenscript.codemodel.member.ref.VariantOptionRef;
11
 import org.openzen.zenscript.codemodel.scope.TypeScope;
12
 import org.openzen.zenscript.codemodel.scope.TypeScope;
12
 import org.openzen.zenscript.codemodel.type.StoredType;
13
 import org.openzen.zenscript.codemodel.type.StoredType;
35
 	}
36
 	}
36
 	
37
 	
37
 	@Override
38
 	@Override
38
-	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) {
39
+	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) throws CompileException {
39
 		if (arguments != null)
40
 		if (arguments != null)
40
 			return super.call(position, scope, hints, arguments);
41
 			return super.call(position, scope, hints, arguments);
41
 		
42
 		
62
 	public Expression normalize(TypeScope scope) {
63
 	public Expression normalize(TypeScope scope) {
63
 		Expression[] normalized = new Expression[arguments.length];
64
 		Expression[] normalized = new Expression[arguments.length];
64
 		for (int i = 0; i < normalized.length; i++)
65
 		for (int i = 0; i < normalized.length; i++)
65
-			normalized[i] = arguments[i].normalize(scope);
66
+			normalized[i] = arguments[i].normalize(scope).castImplicit(position, scope, option.types[i]);
66
 		return new VariantValueExpression(position, type, option, normalized);
67
 		return new VariantValueExpression(position, type, option, normalized);
67
 	}
68
 	}
68
 }
69
 }

+ 9
- 8
CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/IPartialExpression.java View File

8
 import java.util.Collections;
8
 import java.util.Collections;
9
 import java.util.List;
9
 import java.util.List;
10
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
11
 import org.openzen.zencode.shared.CompileExceptionCode;
12
 import org.openzen.zencode.shared.CompileExceptionCode;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
 import org.openzen.zenscript.codemodel.expression.CallArguments;
14
 import org.openzen.zenscript.codemodel.expression.CallArguments;
29
 		return Collections.emptyList();
30
 		return Collections.emptyList();
30
 	}
31
 	}
31
 	
32
 	
32
-	Expression eval();
33
+	Expression eval() throws CompileException;
33
 	
34
 	
34
-	List<StoredType>[] predictCallTypes(TypeScope scope, List<StoredType> hints, int arguments);
35
+	List<StoredType>[] predictCallTypes(TypeScope scope, List<StoredType> hints, int arguments) throws CompileException;
35
 	
36
 	
36
-	List<FunctionHeader> getPossibleFunctionHeaders(TypeScope scope, List<StoredType> hints, int arguments);
37
+	List<FunctionHeader> getPossibleFunctionHeaders(TypeScope scope, List<StoredType> hints, int arguments) throws CompileException;
37
 	
38
 	
38
-	IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name);
39
+	IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) throws CompileException;
39
 	
40
 	
40
-	Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments);
41
+	Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) throws CompileException;
41
 	
42
 	
42
 	TypeID[] getGenericCallTypes();
43
 	TypeID[] getGenericCallTypes();
43
 	
44
 	
50
 		return null;
51
 		return null;
51
 	}
52
 	}
52
 	
53
 	
53
-	default Expression assign(CodePosition position, TypeScope scope, Expression value) {
54
+	default Expression assign(CodePosition position, TypeScope scope, Expression value) throws CompileException {
54
 		return new InvalidExpression(position, value.type, CompileExceptionCode.CANNOT_ASSIGN, "This expression is not assignable");
55
 		return new InvalidExpression(position, value.type, CompileExceptionCode.CANNOT_ASSIGN, "This expression is not assignable");
55
 	}
56
 	}
56
 	
57
 	
57
-	default IPartialExpression capture(CodePosition position, LambdaClosure closure) {
58
-		return new InvalidExpression(position, CompileExceptionCode.UNAVAILABLE_IN_CLOSURE, "expression not allowed in closure");
58
+	default IPartialExpression capture(CodePosition position, LambdaClosure closure) throws CompileException {
59
+		throw new CompileException(position, CompileExceptionCode.UNAVAILABLE_IN_CLOSURE, "expression not allowed in closure");
59
 	}
60
 	}
60
 }
61
 }

+ 6
- 5
CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialGlobalExpression.java View File

7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
10
 import org.openzen.zenscript.codemodel.FunctionHeader;
11
 import org.openzen.zenscript.codemodel.FunctionHeader;
11
 import org.openzen.zenscript.codemodel.expression.CallArguments;
12
 import org.openzen.zenscript.codemodel.expression.CallArguments;
12
 import org.openzen.zenscript.codemodel.expression.Expression;
13
 import org.openzen.zenscript.codemodel.expression.Expression;
35
 	}
36
 	}
36
 	
37
 	
37
 	@Override
38
 	@Override
38
-	public Expression eval() {
39
+	public Expression eval() throws CompileException {
39
 		return new GlobalExpression(position, name, resolution.eval());
40
 		return new GlobalExpression(position, name, resolution.eval());
40
 	}
41
 	}
41
 
42
 
42
 	@Override
43
 	@Override
43
-	public List<StoredType>[] predictCallTypes(TypeScope scope, List<StoredType> hints, int arguments) {
44
+	public List<StoredType>[] predictCallTypes(TypeScope scope, List<StoredType> hints, int arguments) throws CompileException {
44
 		return resolution.predictCallTypes(scope, hints, arguments);
45
 		return resolution.predictCallTypes(scope, hints, arguments);
45
 	}
46
 	}
46
 
47
 
47
 	@Override
48
 	@Override
48
-	public List<FunctionHeader> getPossibleFunctionHeaders(TypeScope scope, List<StoredType> hints, int arguments) {
49
+	public List<FunctionHeader> getPossibleFunctionHeaders(TypeScope scope, List<StoredType> hints, int arguments) throws CompileException {
49
 		return resolution.getPossibleFunctionHeaders(scope, hints, arguments);
50
 		return resolution.getPossibleFunctionHeaders(scope, hints, arguments);
50
 	}
51
 	}
51
 
52
 
52
 	@Override
53
 	@Override
53
-	public IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) {
54
+	public IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) throws CompileException {
54
 		return eval().getMember(position, scope, hints, name);
55
 		return eval().getMember(position, scope, hints, name);
55
 	}
56
 	}
56
 
57
 
57
 	@Override
58
 	@Override
58
-	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) {
59
+	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) throws CompileException {
59
 		return new GlobalCallExpression(position, name, arguments, resolution.call(position, scope, hints, arguments));
60
 		return new GlobalCallExpression(position, name, arguments, resolution.call(position, scope, hints, arguments));
60
 	}
61
 	}
61
 
62
 

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

68
 	}
68
 	}
69
 
69
 
70
 	@Override
70
 	@Override
71
-	public Expression eval() {
71
+	public Expression eval() throws CompileException {
72
 		return group.getter(position, scope, target, allowStaticUsage);
72
 		return group.getter(position, scope, target, allowStaticUsage);
73
 	}
73
 	}
74
 	
74
 	
107
 	}
107
 	}
108
 
108
 
109
 	@Override
109
 	@Override
110
-	public IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) {
110
+	public IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) throws CompileException {
111
 		return eval().getMember(position, scope, hints, name);
111
 		return eval().getMember(position, scope, hints, name);
112
 	}
112
 	}
113
 
113
 
114
 	@Override
114
 	@Override
115
-	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) {
115
+	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) throws CompileException {
116
 		return group.call(position, scope, target, arguments, allowStaticUsage);
116
 		return group.call(position, scope, target, arguments, allowStaticUsage);
117
 	}
117
 	}
118
 	
118
 	
119
 	@Override
119
 	@Override
120
-	public Expression assign(CodePosition position, TypeScope scope, Expression value) {
120
+	public Expression assign(CodePosition position, TypeScope scope, Expression value) throws CompileException {
121
 		return group.setter(position, scope, target, value, allowStaticUsage);
121
 		return group.setter(position, scope, target, value, allowStaticUsage);
122
 	}
122
 	}
123
 	
123
 	
124
 	@Override
124
 	@Override
125
-	public IPartialExpression capture(CodePosition position, LambdaClosure closure) {
125
+	public IPartialExpression capture(CodePosition position, LambdaClosure closure) throws CompileException {
126
 		return new PartialMemberGroupExpression(position, scope, target.capture(position, closure).eval(), group, typeArguments, allowStaticUsage);
126
 		return new PartialMemberGroupExpression(position, scope, target.capture(position, closure).eval(), group, typeArguments, allowStaticUsage);
127
 	}
127
 	}
128
 
128
 

+ 6
- 6
CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialPackageExpression.java View File

8
 import java.util.Collections;
8
 import java.util.Collections;
9
 import java.util.List;
9
 import java.util.List;
10
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
11
 import org.openzen.zencode.shared.CompileExceptionCode;
12
 import org.openzen.zencode.shared.CompileExceptionCode;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
14
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
14
 import org.openzen.zenscript.codemodel.expression.CallArguments;
15
 import org.openzen.zenscript.codemodel.expression.CallArguments;
15
 import org.openzen.zenscript.codemodel.expression.Expression;
16
 import org.openzen.zenscript.codemodel.expression.Expression;
16
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
17
 import org.openzen.zenscript.codemodel.type.GenericName;
17
 import org.openzen.zenscript.codemodel.type.GenericName;
18
 import org.openzen.zenscript.codemodel.scope.TypeScope;
18
 import org.openzen.zenscript.codemodel.scope.TypeScope;
19
 import org.openzen.zenscript.codemodel.type.StoredType;
19
 import org.openzen.zenscript.codemodel.type.StoredType;
33
 	}
33
 	}
34
 	
34
 	
35
 	@Override
35
 	@Override
36
-	public Expression eval() {
37
-		return new InvalidExpression(position, CompileExceptionCode.USING_PACKAGE_AS_EXPRESSION, "Cannot evaluate a package as expression");
36
+	public Expression eval() throws CompileException {
37
+		throw new CompileException(position, CompileExceptionCode.USING_PACKAGE_AS_EXPRESSION, "Cannot evaluate a package as expression");
38
 	}
38
 	}
39
 
39
 
40
 	@Override
40
 	@Override
48
 	}
48
 	}
49
 
49
 
50
 	@Override
50
 	@Override
51
-	public IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) {
51
+	public IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) throws CompileException {
52
 		return pkg.getMember(position, scope.getTypeRegistry(), name);
52
 		return pkg.getMember(position, scope.getTypeRegistry(), name);
53
 	}
53
 	}
54
 
54
 
55
 	@Override
55
 	@Override
56
-	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) {
57
-		return new InvalidExpression(position, CompileExceptionCode.USING_PACKAGE_AS_CALL_TARGET, "Cannot call a package");
56
+	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) throws CompileException {
57
+		throw new CompileException(position, CompileExceptionCode.USING_PACKAGE_AS_CALL_TARGET, "Cannot call a package");
58
 	}
58
 	}
59
 
59
 
60
 	@Override
60
 	@Override

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

9
 import java.util.List;
9
 import java.util.List;
10
 import java.util.stream.Collectors;
10
 import java.util.stream.Collectors;
11
 import org.openzen.zencode.shared.CodePosition;
11
 import org.openzen.zencode.shared.CodePosition;
12
+import org.openzen.zencode.shared.CompileException;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
 import org.openzen.zenscript.codemodel.expression.CallArguments;
14
 import org.openzen.zenscript.codemodel.expression.CallArguments;
14
 import org.openzen.zenscript.codemodel.expression.Expression;
15
 import org.openzen.zenscript.codemodel.expression.Expression;
46
 	}
47
 	}
47
 	
48
 	
48
 	@Override
49
 	@Override
49
-	public Expression eval() {
50
+	public Expression eval() throws CompileException {
50
 		return group.staticGetter(position, scope);
51
 		return group.staticGetter(position, scope);
51
 	}
52
 	}
52
 
53
 
64
 	}
65
 	}
65
 
66
 
66
 	@Override
67
 	@Override
67
-	public IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) {
68
+	public IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) throws CompileException {
68
 		return eval().getMember(position, scope, hints, name);
69
 		return eval().getMember(position, scope, hints, name);
69
 	}
70
 	}
70
 
71
 
71
 	@Override
72
 	@Override
72
-	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) {
73
+	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) throws CompileException {
73
 		return group.callStatic(position, target, scope, arguments);
74
 		return group.callStatic(position, target, scope, arguments);
74
 	}
75
 	}
75
 	
76
 	
76
 	@Override
77
 	@Override
77
-	public Expression assign(CodePosition position, TypeScope scope, Expression value) {
78
+	public Expression assign(CodePosition position, TypeScope scope, Expression value) throws CompileException {
78
 		return group.staticSetter(position, scope, value);
79
 		return group.staticSetter(position, scope, value);
79
 	}
80
 	}
80
 
81
 

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

8
 import java.util.List;
8
 import java.util.List;
9
 import java.util.stream.Collectors;
9
 import java.util.stream.Collectors;
10
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
11
 import org.openzen.zencode.shared.CompileExceptionCode;
12
 import org.openzen.zencode.shared.CompileExceptionCode;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
 import org.openzen.zenscript.codemodel.OperatorType;
14
 import org.openzen.zenscript.codemodel.OperatorType;
62
 	}
63
 	}
63
 
64
 
64
 	@Override
65
 	@Override
65
-	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) {
66
+	public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) throws CompileException {
66
 		if (arguments.getNumberOfTypeArguments() == 0 && (typeParameters != null && typeParameters.length > 0))
67
 		if (arguments.getNumberOfTypeArguments() == 0 && (typeParameters != null && typeParameters.length > 0))
67
 			arguments = new CallArguments(typeParameters, arguments.arguments);
68
 			arguments = new CallArguments(typeParameters, arguments.arguments);
68
 		
69
 		

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

9
 import java.util.Collections;
9
 import java.util.Collections;
10
 import java.util.List;
10
 import java.util.List;
11
 import org.openzen.zencode.shared.CodePosition;
11
 import org.openzen.zencode.shared.CodePosition;
12
+import org.openzen.zencode.shared.CompileException;
12
 import org.openzen.zencode.shared.CompileExceptionCode;
13
 import org.openzen.zencode.shared.CompileExceptionCode;
13
 import org.openzen.zenscript.codemodel.FunctionHeader;
14
 import org.openzen.zenscript.codemodel.FunctionHeader;
14
 import org.openzen.zenscript.codemodel.expression.CallArguments;
15
 import org.openzen.zenscript.codemodel.expression.CallArguments;
58
 	}
59
 	}
59
 
60
 
60
 	@Override
61
 	@Override
61
-	public IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) {
62
-		return new InvalidExpression(position, CompileExceptionCode.NO_SUCH_MEMBER, "Variant options don't have members");
62
+	public IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) throws CompileException {
63
+		throw new CompileException(position, CompileExceptionCode.NO_SUCH_MEMBER, "Variant options don't have members");
63
 	}
64
 	}
64
 
65
 
65
 	@Override
66
 	@Override

+ 8
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/BaseScope.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.codemodel.scope;
6
 package org.openzen.zenscript.codemodel.scope;
7
 
7
 
8
-import java.util.function.Function;
9
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
10
 import org.openzen.zenscript.codemodel.FunctionHeader;
10
 import org.openzen.zenscript.codemodel.FunctionHeader;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
21
  * @author Hoofdgebruiker
21
  * @author Hoofdgebruiker
22
  */
22
  */
23
 public abstract class BaseScope implements TypeScope {
23
 public abstract class BaseScope implements TypeScope {
24
-	public abstract IPartialExpression get(CodePosition position, GenericName name);
24
+	public abstract IPartialExpression get(CodePosition position, GenericName name) throws CompileException;
25
 	
25
 	
26
 	public abstract LoopStatement getLoop(String name);
26
 	public abstract LoopStatement getLoop(String name);
27
 	
27
 	
37
 		return getMemberCache().getRegistry();
37
 		return getMemberCache().getRegistry();
38
 	}
38
 	}
39
 	
39
 	
40
-	public abstract Function<CodePosition, Expression> getDollar();
40
+	public abstract DollarEvaluator getDollar();
41
 	
41
 	
42
-	public abstract IPartialExpression getOuterInstance(CodePosition position);
42
+	public abstract IPartialExpression getOuterInstance(CodePosition position) throws CompileException;
43
+	
44
+	public interface DollarEvaluator {
45
+		Expression apply(CodePosition position) throws CompileException;
46
+	}
43
 }
47
 }

+ 4
- 5
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/BlockScope.java View File

6
 package org.openzen.zenscript.codemodel.scope;
6
 package org.openzen.zenscript.codemodel.scope;
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
-import java.util.function.Function;
10
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
 import org.openzen.zenscript.codemodel.GenericMapper;
13
 import org.openzen.zenscript.codemodel.GenericMapper;
14
-import org.openzen.zenscript.codemodel.expression.Expression;
15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
16
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
15
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
17
 import org.openzen.zenscript.codemodel.type.GenericName;
16
 import org.openzen.zenscript.codemodel.type.GenericName;
38
 	}
37
 	}
39
 	
38
 	
40
 	@Override
39
 	@Override
41
-	public IPartialExpression get(CodePosition position, GenericName name) {
40
+	public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
42
 		IPartialExpression fromSuper = super.get(position, name);
41
 		IPartialExpression fromSuper = super.get(position, name);
43
 		if (fromSuper != null)
42
 		if (fromSuper != null)
44
 			return fromSuper;
43
 			return fromSuper;
72
 	}
71
 	}
73
 
72
 
74
 	@Override
73
 	@Override
75
-	public Function<CodePosition, Expression> getDollar() {
74
+	public DollarEvaluator getDollar() {
76
 		return parent.getDollar();
75
 		return parent.getDollar();
77
 	}
76
 	}
78
 	
77
 	
79
 	@Override
78
 	@Override
80
-	public IPartialExpression getOuterInstance(CodePosition position) {
79
+	public IPartialExpression getOuterInstance(CodePosition position) throws CompileException {
81
 		return parent.getOuterInstance(position);
80
 		return parent.getOuterInstance(position);
82
 	}
81
 	}
83
 
82
 

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

8
 import java.util.HashMap;
8
 import java.util.HashMap;
9
 import java.util.List;
9
 import java.util.List;
10
 import java.util.Map;
10
 import java.util.Map;
11
-import java.util.function.Function;
12
 import org.openzen.zencode.shared.CodePosition;
11
 import org.openzen.zencode.shared.CodePosition;
12
+import org.openzen.zencode.shared.CompileException;
13
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
 import org.openzen.zenscript.codemodel.FunctionHeader;
14
 import org.openzen.zenscript.codemodel.GenericMapper;
14
 import org.openzen.zenscript.codemodel.GenericMapper;
15
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
15
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
16
-import org.openzen.zenscript.codemodel.expression.Expression;
17
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
16
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
18
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
17
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
19
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
18
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
47
 	}
46
 	}
48
 
47
 
49
 	@Override
48
 	@Override
50
-	public IPartialExpression get(CodePosition position, GenericName name) {
49
+	public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
51
 		if (typeParameters.containsKey(name.name) && !name.hasArguments())
50
 		if (typeParameters.containsKey(name.name) && !name.hasArguments())
52
 			return new PartialTypeExpression(position, getTypeRegistry().getGeneric(typeParameters.get(name.name)), name.arguments);
51
 			return new PartialTypeExpression(position, getTypeRegistry().getGeneric(typeParameters.get(name.name)), name.arguments);
53
 
52
 
83
 	}
82
 	}
84
 
83
 
85
 	@Override
84
 	@Override
86
-	public Function<CodePosition, Expression> getDollar() {
85
+	public DollarEvaluator getDollar() {
87
 		return outer.getDollar();
86
 		return outer.getDollar();
88
 	}
87
 	}
89
 
88
 

+ 5
- 6
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/DefinitionScope.java View File

8
 import java.util.HashMap;
8
 import java.util.HashMap;
9
 import java.util.List;
9
 import java.util.List;
10
 import java.util.Map;
10
 import java.util.Map;
11
-import java.util.function.Function;
12
 import java.util.function.Supplier;
11
 import java.util.function.Supplier;
13
 import org.openzen.zencode.shared.CodePosition;
12
 import org.openzen.zencode.shared.CodePosition;
13
+import org.openzen.zencode.shared.CompileException;
14
 import org.openzen.zencode.shared.CompileExceptionCode;
14
 import org.openzen.zencode.shared.CompileExceptionCode;
15
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
15
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
16
 
16
 
19
 import org.openzen.zenscript.codemodel.GenericMapper;
19
 import org.openzen.zenscript.codemodel.GenericMapper;
20
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
20
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
21
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
21
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
22
-import org.openzen.zenscript.codemodel.expression.Expression;
23
 import org.openzen.zenscript.codemodel.expression.InvalidExpression;
22
 import org.openzen.zenscript.codemodel.expression.InvalidExpression;
24
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
23
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
25
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
24
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
93
 	}
92
 	}
94
 
93
 
95
 	@Override
94
 	@Override
96
-	public IPartialExpression get(CodePosition position, GenericName name) {
95
+	public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
97
 		if (members != null) {
96
 		if (members != null) {
98
 			if (members.hasInnerType(name.name))
97
 			if (members.hasInnerType(name.name))
99
 				return new PartialTypeExpression(position, members.getInnerType(position, name), name.arguments);
98
 				return new PartialTypeExpression(position, members.getInnerType(position, name), name.arguments);
150
 	}
149
 	}
151
 
150
 
152
 	@Override
151
 	@Override
153
-	public Function<CodePosition, Expression> getDollar() {
152
+	public DollarEvaluator getDollar() {
154
 		return outer.getDollar();
153
 		return outer.getDollar();
155
 	}
154
 	}
156
 	
155
 	
157
 	@Override
156
 	@Override
158
-	public IPartialExpression getOuterInstance(CodePosition position) {
157
+	public IPartialExpression getOuterInstance(CodePosition position) throws CompileException {
159
 		if (!definition.isInnerDefinition()) {
158
 		if (!definition.isInnerDefinition()) {
160
-			return new InvalidExpression(position, CompileExceptionCode.NO_OUTER_BECAUSE_NOT_INNER, "Type is not an inner type; cannot access outer type");
159
+			throw new CompileException(position, CompileExceptionCode.NO_OUTER_BECAUSE_NOT_INNER, "Type is not an inner type; cannot access outer type");
161
 		} else if (definition.isStatic()) {
160
 		} else if (definition.isStatic()) {
162
 			return new InvalidExpression(position, outer.getThisType(), CompileExceptionCode.NO_OUTER_BECAUSE_STATIC, "Inner type is static; cannot access outer type reference");
161
 			return new InvalidExpression(position, outer.getThisType(), CompileExceptionCode.NO_OUTER_BECAUSE_STATIC, "Inner type is static; cannot access outer type reference");
163
 		} else {
162
 		} else {

+ 7
- 6
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ExpressionScope.java View File

11
 import java.util.Map;
11
 import java.util.Map;
12
 import java.util.function.Function;
12
 import java.util.function.Function;
13
 import org.openzen.zencode.shared.CodePosition;
13
 import org.openzen.zencode.shared.CodePosition;
14
+import org.openzen.zencode.shared.CompileException;
14
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
15
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
15
 import org.openzen.zenscript.codemodel.FunctionHeader;
16
 import org.openzen.zenscript.codemodel.FunctionHeader;
16
 import org.openzen.zenscript.codemodel.GenericMapper;
17
 import org.openzen.zenscript.codemodel.GenericMapper;
36
  */
37
  */
37
 public class ExpressionScope extends BaseScope {
38
 public class ExpressionScope extends BaseScope {
38
 	private final BaseScope outer;
39
 	private final BaseScope outer;
39
-	private final Function<CodePosition, Expression> dollar;
40
+	private final DollarEvaluator dollar;
40
 	
41
 	
41
 	public final List<StoredType> hints;
42
 	public final List<StoredType> hints;
42
 	public final Map<TypeParameter, TypeID> genericInferenceMap;
43
 	public final Map<TypeParameter, TypeID> genericInferenceMap;
66
 	private ExpressionScope(
67
 	private ExpressionScope(
67
 			BaseScope scope,
68
 			BaseScope scope,
68
 			List<StoredType> hints,
69
 			List<StoredType> hints,
69
-			Function<CodePosition, Expression> dollar,
70
+			DollarEvaluator dollar,
70
 			Map<TypeParameter, TypeID> genericInferenceMap,
71
 			Map<TypeParameter, TypeID> genericInferenceMap,
71
 			Map<String, Function<CodePosition, Expression>> innerVariables) {
72
 			Map<String, Function<CodePosition, Expression>> innerVariables) {
72
 		this.outer = scope;
73
 		this.outer = scope;
100
 		return new ExpressionScope(outer, hints, dollar, genericInferenceMap, innerVariables);
101
 		return new ExpressionScope(outer, hints, dollar, genericInferenceMap, innerVariables);
101
 	}
102
 	}
102
 	
103
 	
103
-	public ExpressionScope createInner(List<StoredType> hints, Function<CodePosition, Expression> dollar) {
104
+	public ExpressionScope createInner(List<StoredType> hints, DollarEvaluator dollar) {
104
 		return new ExpressionScope(outer, hints, dollar, genericInferenceMap, innerVariables);
105
 		return new ExpressionScope(outer, hints, dollar, genericInferenceMap, innerVariables);
105
 	}
106
 	}
106
 	
107
 	
121
 	}
122
 	}
122
 	
123
 	
123
 	@Override
124
 	@Override
124
-	public IPartialExpression get(CodePosition position, GenericName name) {
125
+	public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
125
 		if (name.hasNoArguments() && innerVariables.containsKey(name.name))
126
 		if (name.hasNoArguments() && innerVariables.containsKey(name.name))
126
 			return innerVariables.get(name.name).apply(position);
127
 			return innerVariables.get(name.name).apply(position);
127
 		
128
 		
154
 	}
155
 	}
155
 
156
 
156
 	@Override
157
 	@Override
157
-	public Function<CodePosition, Expression> getDollar() {
158
+	public DollarEvaluator getDollar() {
158
 		return dollar == null ? outer.getDollar() : dollar;
159
 		return dollar == null ? outer.getDollar() : dollar;
159
 	}
160
 	}
160
 	
161
 	
161
 	@Override
162
 	@Override
162
-	public IPartialExpression getOuterInstance(CodePosition position) {
163
+	public IPartialExpression getOuterInstance(CodePosition position) throws CompileException {
163
 		return outer.getOuterInstance(position);
164
 		return outer.getOuterInstance(position);
164
 	}
165
 	}
165
 
166
 

+ 4
- 6
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FileScope.java View File

8
 import java.util.Collections;
8
 import java.util.Collections;
9
 import java.util.List;
9
 import java.util.List;
10
 import java.util.Map;
10
 import java.util.Map;
11
-import java.util.function.Function;
12
 import org.openzen.zencode.shared.CodePosition;
11
 import org.openzen.zencode.shared.CodePosition;
12
+import org.openzen.zencode.shared.CompileException;
13
 import org.openzen.zencode.shared.CompileExceptionCode;
13
 import org.openzen.zencode.shared.CompileExceptionCode;
14
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
14
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
15
 import org.openzen.zenscript.codemodel.FunctionHeader;
15
 import org.openzen.zenscript.codemodel.FunctionHeader;
16
 import org.openzen.zenscript.codemodel.GenericMapper;
16
 import org.openzen.zenscript.codemodel.GenericMapper;
17
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
17
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
18
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
18
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
19
-import org.openzen.zenscript.codemodel.expression.Expression;
20
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
21
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
19
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
22
 import org.openzen.zenscript.codemodel.partial.PartialGlobalExpression;
20
 import org.openzen.zenscript.codemodel.partial.PartialGlobalExpression;
23
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
21
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
114
 	}
112
 	}
115
 
113
 
116
 	@Override
114
 	@Override
117
-	public Function<CodePosition, Expression> getDollar() {
115
+	public DollarEvaluator getDollar() {
118
 		return null;
116
 		return null;
119
 	}
117
 	}
120
 	
118
 	
121
 	@Override
119
 	@Override
122
-	public IPartialExpression getOuterInstance(CodePosition position) {
123
-		return new InvalidExpression(position, CompileExceptionCode.NO_OUTER_BECAUSE_OUTSIDE_TYPE, "Not in an inner type");
120
+	public IPartialExpression getOuterInstance(CodePosition position) throws CompileException {
121
+		throw new CompileException(position, CompileExceptionCode.NO_OUTER_BECAUSE_OUTSIDE_TYPE, "Not in an inner type");
124
 	}
122
 	}
125
 
123
 
126
 	@Override
124
 	@Override

+ 4
- 5
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ForeachScope.java View File

6
 package org.openzen.zenscript.codemodel.scope;
6
 package org.openzen.zenscript.codemodel.scope;
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
-import java.util.function.Function;
10
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
 import org.openzen.zenscript.codemodel.GenericMapper;
13
 import org.openzen.zenscript.codemodel.GenericMapper;
14
-import org.openzen.zenscript.codemodel.expression.Expression;
15
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
14
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
16
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
17
 import org.openzen.zenscript.codemodel.statement.ForeachStatement;
16
 import org.openzen.zenscript.codemodel.statement.ForeachStatement;
43
 	}
42
 	}
44
 
43
 
45
 	@Override
44
 	@Override
46
-	public IPartialExpression get(CodePosition position, GenericName name) {
45
+	public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
47
 		if (name.hasNoArguments()) {
46
 		if (name.hasNoArguments()) {
48
 			for (VarStatement loopVariable : statement.loopVariables) {
47
 			for (VarStatement loopVariable : statement.loopVariables) {
49
 				if (loopVariable.name.equals(name.name))
48
 				if (loopVariable.name.equals(name.name))
92
 	}
91
 	}
93
 
92
 
94
 	@Override
93
 	@Override
95
-	public Function<CodePosition, Expression> getDollar() {
94
+	public DollarEvaluator getDollar() {
96
 		return outer.getDollar();
95
 		return outer.getDollar();
97
 	}
96
 	}
98
 	
97
 	
99
 	@Override
98
 	@Override
100
-	public IPartialExpression getOuterInstance(CodePosition position) {
99
+	public IPartialExpression getOuterInstance(CodePosition position) throws CompileException {
101
 		return outer.getOuterInstance(position);
100
 		return outer.getOuterInstance(position);
102
 	}
101
 	}
103
 
102
 

+ 4
- 5
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FunctionScope.java View File

6
 package org.openzen.zenscript.codemodel.scope;
6
 package org.openzen.zenscript.codemodel.scope;
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
-import java.util.function.Function;
10
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
 import org.openzen.zenscript.codemodel.FunctionParameter;
13
 import org.openzen.zenscript.codemodel.FunctionParameter;
14
 import org.openzen.zenscript.codemodel.GenericMapper;
14
 import org.openzen.zenscript.codemodel.GenericMapper;
15
-import org.openzen.zenscript.codemodel.expression.Expression;
16
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
15
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
17
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
16
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
18
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
17
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
62
 	}
61
 	}
63
 
62
 
64
 	@Override
63
 	@Override
65
-	public IPartialExpression get(CodePosition position, GenericName name) {
64
+	public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
66
 		IPartialExpression fromSuper = super.get(position, name);
65
 		IPartialExpression fromSuper = super.get(position, name);
67
 		if (fromSuper != null)
66
 		if (fromSuper != null)
68
 			return fromSuper;
67
 			return fromSuper;
110
 	}
109
 	}
111
 
110
 
112
 	@Override
111
 	@Override
113
-	public Function<CodePosition, Expression> getDollar() {
112
+	public DollarEvaluator getDollar() {
114
 		for (FunctionParameter parameter : header.parameters)
113
 		for (FunctionParameter parameter : header.parameters)
115
 			if (parameter.name.equals("$"))
114
 			if (parameter.name.equals("$"))
116
 				return position -> new GetFunctionParameterExpression(position, parameter);
115
 				return position -> new GetFunctionParameterExpression(position, parameter);
119
 	}
118
 	}
120
 	
119
 	
121
 	@Override
120
 	@Override
122
-	public IPartialExpression getOuterInstance(CodePosition position) {
121
+	public IPartialExpression getOuterInstance(CodePosition position) throws CompileException {
123
 		return outer.getOuterInstance(position);
122
 		return outer.getOuterInstance(position);
124
 	}
123
 	}
125
 
124
 

+ 4
- 5
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/GenericFunctionScope.java View File

8
 import java.util.HashMap;
8
 import java.util.HashMap;
9
 import java.util.List;
9
 import java.util.List;
10
 import java.util.Map;
10
 import java.util.Map;
11
-import java.util.function.Function;
12
 import org.openzen.zencode.shared.CodePosition;
11
 import org.openzen.zencode.shared.CodePosition;
12
+import org.openzen.zencode.shared.CompileException;
13
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
13
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
14
 import org.openzen.zenscript.codemodel.FunctionHeader;
14
 import org.openzen.zenscript.codemodel.FunctionHeader;
15
 import org.openzen.zenscript.codemodel.GenericMapper;
15
 import org.openzen.zenscript.codemodel.GenericMapper;
16
-import org.openzen.zenscript.codemodel.expression.Expression;
17
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
16
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
18
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
17
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
19
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
18
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
47
 	}
46
 	}
48
 
47
 
49
 	@Override
48
 	@Override
50
-	public IPartialExpression get(CodePosition position, GenericName name) {
49
+	public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
51
 		if (parameters.containsKey(name.name) && name.hasNoArguments())
50
 		if (parameters.containsKey(name.name) && name.hasNoArguments())
52
 			return new PartialTypeExpression(position, getTypeRegistry().getGeneric(parameters.get(name.name)), name.arguments);
51
 			return new PartialTypeExpression(position, getTypeRegistry().getGeneric(parameters.get(name.name)), name.arguments);
53
 		
52
 		
83
 	}
82
 	}
84
 
83
 
85
 	@Override
84
 	@Override
86
-	public Function<CodePosition, Expression> getDollar() {
85
+	public DollarEvaluator getDollar() {
87
 		return outer.getDollar();
86
 		return outer.getDollar();
88
 	}
87
 	}
89
 	
88
 	
90
 	@Override
89
 	@Override
91
-	public IPartialExpression getOuterInstance(CodePosition position) {
90
+	public IPartialExpression getOuterInstance(CodePosition position) throws CompileException {
92
 		return outer.getOuterInstance(position);
91
 		return outer.getOuterInstance(position);
93
 	}
92
 	}
94
 
93
 

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

6
 package org.openzen.zenscript.codemodel.scope;
6
 package org.openzen.zenscript.codemodel.scope;
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
-import java.util.function.Function;
10
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
 import org.openzen.zenscript.codemodel.GenericMapper;
13
 import org.openzen.zenscript.codemodel.GenericMapper;
14
-import org.openzen.zenscript.codemodel.expression.Expression;
15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
16
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
15
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
17
 import org.openzen.zenscript.codemodel.type.GenericName;
16
 import org.openzen.zenscript.codemodel.type.GenericName;
38
 	}
37
 	}
39
 	
38
 	
40
 	@Override
39
 	@Override
41
-	public IPartialExpression get(CodePosition position, GenericName name) {
40
+	public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
42
 		IPartialExpression result = super.get(position, name);
41
 		IPartialExpression result = super.get(position, name);
43
 		if (result != null)
42
 		if (result != null)
44
 			return result;
43
 			return result;
72
 	}
71
 	}
73
 
72
 
74
 	@Override
73
 	@Override
75
-	public Function<CodePosition, Expression> getDollar() {
74
+	public DollarEvaluator getDollar() {
76
 		return null; // script arguments?
75
 		return null; // script arguments?
77
 	}
76
 	}
78
 
77
 

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

6
 package org.openzen.zenscript.codemodel.scope;
6
 package org.openzen.zenscript.codemodel.scope;
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
-import java.util.function.Function;
10
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
 import org.openzen.zenscript.codemodel.GenericMapper;
13
 import org.openzen.zenscript.codemodel.GenericMapper;
14
-import org.openzen.zenscript.codemodel.expression.Expression;
15
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
14
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
16
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
15
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
17
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
16
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
49
 	}
48
 	}
50
 
49
 
51
 	@Override
50
 	@Override
52
-	public IPartialExpression get(CodePosition position, GenericName name) {
51
+	public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
53
 		if (members.hasInnerType(name.name))
52
 		if (members.hasInnerType(name.name))
54
 			return new PartialTypeExpression(position, members.getInnerType(position, name), name.arguments);
53
 			return new PartialTypeExpression(position, members.getInnerType(position, name), name.arguments);
55
 		if (members.hasMember(name.name))
54
 		if (members.hasMember(name.name))
92
 	}
91
 	}
93
 
92
 
94
 	@Override
93
 	@Override
95
-	public Function<CodePosition, Expression> getDollar() {
94
+	public DollarEvaluator getDollar() {
96
 		return outer.getDollar();
95
 		return outer.getDollar();
97
 	}
96
 	}
98
 
97
 

+ 5
- 6
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LambdaScope.java View File

6
 package org.openzen.zenscript.codemodel.scope;
6
 package org.openzen.zenscript.codemodel.scope;
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
-import java.util.function.Function;
10
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
 import org.openzen.zenscript.codemodel.FunctionParameter;
13
 import org.openzen.zenscript.codemodel.FunctionParameter;
14
 import org.openzen.zenscript.codemodel.GenericMapper;
14
 import org.openzen.zenscript.codemodel.GenericMapper;
15
-import org.openzen.zenscript.codemodel.expression.Expression;
16
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
15
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
17
 import org.openzen.zenscript.codemodel.expression.LambdaClosure;
16
 import org.openzen.zenscript.codemodel.expression.LambdaClosure;
18
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
17
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
45
 	}
44
 	}
46
 	
45
 	
47
 	@Override
46
 	@Override
48
-	public IPartialExpression get(CodePosition position, GenericName name) {
47
+	public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
49
 		IPartialExpression outer = this.outer.get(position, name);
48
 		IPartialExpression outer = this.outer.get(position, name);
50
 		if (outer == null) {
49
 		if (outer == null) {
51
 			if (name.hasNoArguments()) {
50
 			if (name.hasNoArguments()) {
87
 	}
86
 	}
88
 
87
 
89
 	@Override
88
 	@Override
90
-	public Function<CodePosition, Expression> getDollar() {
91
-		Function<CodePosition, Expression> outerDollar = outer.getDollar();
89
+	public DollarEvaluator getDollar() {
90
+		DollarEvaluator outerDollar = outer.getDollar();
92
 		if (outerDollar == null)
91
 		if (outerDollar == null)
93
 			return null;
92
 			return null;
94
 		
93
 		
96
 	}
95
 	}
97
 	
96
 	
98
 	@Override
97
 	@Override
99
-	public IPartialExpression getOuterInstance(CodePosition position) {
98
+	public IPartialExpression getOuterInstance(CodePosition position) throws CompileException {
100
 		return outer.getOuterInstance(position);
99
 		return outer.getOuterInstance(position);
101
 	}
100
 	}
102
 
101
 

+ 4
- 5
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LoopScope.java View File

6
 package org.openzen.zenscript.codemodel.scope;
6
 package org.openzen.zenscript.codemodel.scope;
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
-import java.util.function.Function;
10
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
 import org.openzen.zenscript.codemodel.GenericMapper;
13
 import org.openzen.zenscript.codemodel.GenericMapper;
14
-import org.openzen.zenscript.codemodel.expression.Expression;
15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
16
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
15
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
17
 import org.openzen.zenscript.codemodel.type.GenericName;
16
 import org.openzen.zenscript.codemodel.type.GenericName;
40
 	}
39
 	}
41
 
40
 
42
 	@Override
41
 	@Override
43
-	public IPartialExpression get(CodePosition position, GenericName name) {
42
+	public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
44
 		IPartialExpression result = super.get(position, name);
43
 		IPartialExpression result = super.get(position, name);
45
 		if (result != null)
44
 		if (result != null)
46
 			return result;
45
 			return result;
80
 	}
79
 	}
81
 
80
 
82
 	@Override
81
 	@Override
83
-	public Function<CodePosition, Expression> getDollar() {
82
+	public DollarEvaluator getDollar() {
84
 		return outer.getDollar();
83
 		return outer.getDollar();
85
 	}
84
 	}
86
 	
85
 	
87
 	@Override
86
 	@Override
88
-	public IPartialExpression getOuterInstance(CodePosition position) {
87
+	public IPartialExpression getOuterInstance(CodePosition position) throws CompileException {
89
 		return outer.getOuterInstance(position);
88
 		return outer.getOuterInstance(position);
90
 	}
89
 	}
91
 
90
 

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

8
 import java.util.HashMap;
8
 import java.util.HashMap;
9
 import java.util.Map;
9
 import java.util.Map;
10
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
11
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
12
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13
 import org.openzen.zenscript.codemodel.statement.VarStatement;
14
 import org.openzen.zenscript.codemodel.statement.VarStatement;
25
 	}
26
 	}
26
 	
27
 	
27
 	@Override
28
 	@Override
28
-	public IPartialExpression get(CodePosition position, GenericName name) {
29
+	public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
29
 		if (variables.containsKey(name.name) && name.hasNoArguments())
30
 		if (variables.containsKey(name.name) && name.hasNoArguments())
30
 			return new GetLocalVariableExpression(position, variables.get(name.name));
31
 			return new GetLocalVariableExpression(position, variables.get(name.name));
31
 		
32
 		

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

77
 
77
 
78
 	@Override
78
 	@Override
79
 	public Statement normalize(TypeScope scope, ConcatMap<LoopStatement, LoopStatement> modified) {
79
 	public Statement normalize(TypeScope scope, ConcatMap<LoopStatement, LoopStatement> modified) {
80
-		return new IfStatement(position, condition.normalize(scope), onThen.normalize(scope, modified), onElse == null ? null : onElse.normalize(scope, modified));
80
+		return new IfStatement(
81
+				position,
82
+				condition.normalize(scope),
83
+				onThen.normalize(scope, modified),
84
+				onElse == null ? null : onElse.normalize(scope, modified));
81
 	}
85
 	}
82
 }
86
 }

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

21
 	public final String name;
21
 	public final String name;
22
 	public final StoredType type;
22
 	public final StoredType type;
23
 	public final Expression initializer;
23
 	public final Expression initializer;
24
+	public final VariableID variable;
24
 	public final boolean isFinal;
25
 	public final boolean isFinal;
25
 	
26
 	
26
-	public VarStatement(CodePosition position, String name, StoredType type, Expression initializer, boolean isFinal) {
27
+	public VarStatement(CodePosition position, VariableID variable, String name, StoredType type, Expression initializer, boolean isFinal) {
27
 		super(position, initializer == null ? null : initializer.thrownType);
28
 		super(position, initializer == null ? null : initializer.thrownType);
28
 		
29
 		
29
 		this.name = name;
30
 		this.name = name;
30
 		this.type = type;
31
 		this.type = type;
31
 		this.initializer = initializer;
32
 		this.initializer = initializer;
33
+		this.variable = variable;
32
 		this.isFinal = isFinal;
34
 		this.isFinal = isFinal;
33
 	}
35
 	}
34
 
36
 
50
 	@Override
52
 	@Override
51
 	public VarStatement transform(StatementTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
53
 	public VarStatement transform(StatementTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
52
 		Expression tInitializer = initializer == null ? null : initializer.transform(transformer);
54
 		Expression tInitializer = initializer == null ? null : initializer.transform(transformer);
53
-		return tInitializer == initializer ? this : new VarStatement(position, name, type, tInitializer, isFinal);
55
+		return tInitializer == initializer ? this : new VarStatement(position, variable, name, type, tInitializer, isFinal);
54
 	}
56
 	}
55
 
57
 
56
 	@Override
58
 	@Override
57
 	public VarStatement transform(ExpressionTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
59
 	public VarStatement transform(ExpressionTransformer transformer, ConcatMap<LoopStatement, LoopStatement> modified) {
58
 		Expression tInitializer = initializer == null ? null : initializer.transform(transformer);
60
 		Expression tInitializer = initializer == null ? null : initializer.transform(transformer);
59
-		return tInitializer == initializer ? this : new VarStatement(position, name, type, tInitializer, isFinal);
61
+		return tInitializer == initializer ? this : new VarStatement(position, variable, name, type, tInitializer, isFinal);
60
 	}
62
 	}
61
 
63
 
62
 	@Override
64
 	@Override
63
 	public VarStatement normalize(TypeScope scope, ConcatMap<LoopStatement, LoopStatement> modified) {
65
 	public VarStatement normalize(TypeScope scope, ConcatMap<LoopStatement, LoopStatement> modified) {
64
-		return new VarStatement(position, name, type.getNormalized(), initializer == null ? null : initializer.normalize(scope), isFinal);
66
+		return new VarStatement(position, variable, name, type.getNormalized(), initializer == null ? null : initializer.normalize(scope), isFinal);
65
 	}
67
 	}
66
 }
68
 }

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

11
 import org.openzen.zenscript.codemodel.FunctionParameter;
11
 import org.openzen.zenscript.codemodel.FunctionParameter;
12
 import org.openzen.zenscript.codemodel.GenericMapper;
12
 import org.openzen.zenscript.codemodel.GenericMapper;
13
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
13
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
14
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
15
+import org.openzen.zenscript.codemodel.type.storage.ValueStorageTag;
14
 
16
 
15
 /**
17
 /**
16
  *
18
  *
107
 	
109
 	
108
 	@Override
110
 	@Override
109
 	public String toString() {
111
 	public String toString() {
112
+		return toString(null);
113
+	}
114
+	
115
+	@Override
116
+	public String toString(StorageTag storage) {
110
 		StringBuilder result = new StringBuilder();
117
 		StringBuilder result = new StringBuilder();
118
+		result.append("function");
119
+		if (header.typeParameters.length > 0) {
120
+			result.append('<');
121
+			for (int i = 0; i < header.typeParameters.length; i++) {
122
+				if (i > 0)
123
+					result.append(", ");
124
+				
125
+				result.append(header.typeParameters[i].toString());
126
+			}
127
+			result.append('>');
128
+		}
129
+		if (storage != null && storage != ValueStorageTag.INSTANCE) {
130
+			result.append('`');
131
+			result.append(storage);
132
+		}
111
 		result.append('(');
133
 		result.append('(');
112
 		for (int i = 0; i < header.parameters.length; i++) {
134
 		for (int i = 0; i < header.parameters.length; i++) {
113
 			if (i > 0)
135
 			if (i > 0)

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

10
 import org.openzen.zencode.shared.CompileExceptionCode;
10
 import org.openzen.zencode.shared.CompileExceptionCode;
11
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.GenericMapper;
12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
13
-import org.openzen.zenscript.codemodel.type.storage.StorageTag;
14
-import org.openzen.zenscript.codemodel.type.storage.UniqueStorageTag;
15
 
13
 
16
 /**
14
 /**
17
  *
15
  *
67
 	public <C, R, E extends Exception> R accept(C context, TypeVisitorWithContext<C, R, E> visitor) throws E {
65
 	public <C, R, E extends Exception> R accept(C context, TypeVisitorWithContext<C, R, E> visitor) throws E {
68
 		return visitor.visitInvalid(context, this);
66
 		return visitor.visitInvalid(context, this);
69
 	}
67
 	}
68
+	
69
+	@Override
70
+	public String toString() {
71
+		return "invalid";
72
+	}
70
 }
73
 }

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

9
 import java.util.Objects;
9
 import java.util.Objects;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
10
 import org.openzen.zenscript.codemodel.GenericMapper;
11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
12
 
13
 
13
 /**
14
 /**
14
  *
15
  *
140
 			result.append("?");
141
 			result.append("?");
141
 		return result.toString();
142
 		return result.toString();
142
 	}
143
 	}
144
+	
145
+	@Override
146
+	public String toString(StorageTag storage) {
147
+		StringBuilder result = new StringBuilder();
148
+		if ((modifiers & MODIFIER_IMMUTABLE) > 0)
149
+			result.append("immutable ");
150
+		if ((modifiers & MODIFIER_CONST) > 0)
151
+			result.append("const ");
152
+		result.append(baseType.toString(storage));
153
+		if ((modifiers & MODIFIER_OPTIONAL) > 0)
154
+			result.append("?");
155
+		return result.toString();
156
+	}
143
 }
157
 }

+ 1
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/StoredType.java View File

122
 	
122
 	
123
 	@Override
123
 	@Override
124
 	public String toString() {
124
 	public String toString() {
125
-		if (storage == ValueStorageTag.INSTANCE)
126
-			return type.toString();
127
-		
128
-		return type.toString() + "`" + storage.toString();
125
+		return type.toString(storage);
129
 	}
126
 	}
130
 	
127
 	
131
 	public static class MatchingTypeVisitor implements TypeVisitor<Boolean> {
128
 	public static class MatchingTypeVisitor implements TypeVisitor<Boolean> {

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

11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
12
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
13
 import org.openzen.zenscript.codemodel.type.storage.StorageTag;
13
 import org.openzen.zenscript.codemodel.type.storage.StorageTag;
14
+import org.openzen.zenscript.codemodel.type.storage.ValueStorageTag;
14
 
15
 
15
 /**
16
 /**
16
  *
17
  *
80
 	default boolean isEnum() {
81
 	default boolean isEnum() {
81
 		return false;
82
 		return false;
82
 	}
83
 	}
84
+	
85
+	default String toString(StorageTag storage) {
86
+		if (storage == ValueStorageTag.INSTANCE)
87
+			return toString();
88
+		
89
+		return toString() + "`" + storage.toString();
90
+	}
83
 }
91
 }

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

60
 			return false;
60
 			return false;
61
 		}
61
 		}
62
 	}
62
 	}
63
+	
64
+	@Override
65
+	public Boolean visitInvalid(Matching context, InvalidTypeID invalid) {
66
+		return false;
67
+	}
63
 
68
 
64
 	@Override
69
 	@Override
65
 	public Boolean visitIterator(Matching context, IteratorTypeID iterator) {
70
 	public Boolean visitIterator(Matching context, IteratorTypeID iterator) {

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

6
 package org.openzen.zenscript.codemodel.type.member;
6
 package org.openzen.zenscript.codemodel.type.member;
7
 
7
 
8
 import java.util.Collections;
8
 import java.util.Collections;
9
-import java.util.HashMap;
10
 import java.util.List;
9
 import java.util.List;
11
 import java.util.Map;
10
 import java.util.Map;
12
 import org.openzen.zencode.shared.CodePosition;
11
 import org.openzen.zencode.shared.CodePosition;
68
 import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
67
 import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
69
 import org.openzen.zenscript.codemodel.expression.ConstantUSizeExpression;
68
 import org.openzen.zenscript.codemodel.expression.ConstantUSizeExpression;
70
 import org.openzen.zenscript.codemodel.member.IteratorMember;
69
 import org.openzen.zenscript.codemodel.member.IteratorMember;
70
+import org.openzen.zenscript.codemodel.type.InvalidTypeID;
71
 import org.openzen.zenscript.codemodel.type.StoredType;
71
 import org.openzen.zenscript.codemodel.type.StoredType;
72
 import org.openzen.zenscript.codemodel.type.StringTypeID;
72
 import org.openzen.zenscript.codemodel.type.StringTypeID;
73
 import org.openzen.zenscript.codemodel.type.TypeVisitorWithContext;
73
 import org.openzen.zenscript.codemodel.type.TypeVisitorWithContext;
413
 		return null;
413
 		return null;
414
 	}
414
 	}
415
 	
415
 	
416
+	@Override
417
+	public Void visitInvalid(Void context, InvalidTypeID invalid) {
418
+		return null;
419
+	}
420
+	
416
 	@Override
421
 	@Override
417
 	public Void visitIterator(Void context, IteratorTypeID iterator) {
422
 	public Void visitIterator(Void context, IteratorTypeID iterator) {
418
 		return null;
423
 		return null;
766
 		dec(builtin, INT_INC, INT);
771
 		dec(builtin, INT_INC, INT);
767
 
772
 
768
 		add(builtin, INT_ADD_INT, INT, INT);
773
 		add(builtin, INT_ADD_INT, INT, INT);
774
+		add(builtin, LONG_ADD_LONG, USIZE, LONG, INT_TO_LONG);
769
 		add(builtin, LONG_ADD_LONG, LONG, LONG, INT_TO_LONG);
775
 		add(builtin, LONG_ADD_LONG, LONG, LONG, INT_TO_LONG);
770
 		add(builtin, FLOAT_ADD_FLOAT, FLOAT, FLOAT, INT_TO_FLOAT);
776
 		add(builtin, FLOAT_ADD_FLOAT, FLOAT, FLOAT, INT_TO_FLOAT);
771
 		add(builtin, DOUBLE_ADD_DOUBLE, DOUBLE, DOUBLE, INT_TO_DOUBLE);
777
 		add(builtin, DOUBLE_ADD_DOUBLE, DOUBLE, DOUBLE, INT_TO_DOUBLE);
846
 		dec(builtin, UINT_INC, INT);
852
 		dec(builtin, UINT_INC, INT);
847
 
853
 
848
 		add(builtin, UINT_ADD_UINT, UINT, UINT);
854
 		add(builtin, UINT_ADD_UINT, UINT, UINT);
855
+		add(builtin, ULONG_ADD_ULONG, USIZE, ULONG, UINT_TO_ULONG);
849
 		add(builtin, ULONG_ADD_ULONG, ULONG, ULONG, UINT_TO_ULONG);
856
 		add(builtin, ULONG_ADD_ULONG, ULONG, ULONG, UINT_TO_ULONG);
850
 		add(builtin, FLOAT_ADD_FLOAT, FLOAT, FLOAT, UINT_TO_FLOAT);
857
 		add(builtin, FLOAT_ADD_FLOAT, FLOAT, FLOAT, UINT_TO_FLOAT);
851
 		add(builtin, DOUBLE_ADD_DOUBLE, DOUBLE, DOUBLE, UINT_TO_DOUBLE);
858
 		add(builtin, DOUBLE_ADD_DOUBLE, DOUBLE, DOUBLE, UINT_TO_DOUBLE);

+ 93
- 125
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberGroup.java View File

32
 import org.openzen.zenscript.codemodel.member.ref.GetterMemberRef;
32
 import org.openzen.zenscript.codemodel.member.ref.GetterMemberRef;
33
 import org.openzen.zenscript.codemodel.member.ref.SetterMemberRef;
33
 import org.openzen.zenscript.codemodel.member.ref.SetterMemberRef;
34
 import org.openzen.zenscript.codemodel.scope.TypeScope;
34
 import org.openzen.zenscript.codemodel.scope.TypeScope;
35
-import org.openzen.zenscript.codemodel.type.BasicTypeID;
36
 import org.openzen.zenscript.codemodel.type.StoredType;
35
 import org.openzen.zenscript.codemodel.type.StoredType;
37
 import org.openzen.zenscript.codemodel.type.TypeID;
36
 import org.openzen.zenscript.codemodel.type.TypeID;
38
 
37
 
160
 		methods.add(new TypeMember<>(priority, method));
159
 		methods.add(new TypeMember<>(priority, method));
161
 	}
160
 	}
162
 	
161
 	
163
-	public Expression getter(CodePosition position, TypeScope scope, Expression target, boolean allowStaticUsage) {
164
-		try {
165
-			if (getter != null) {
166
-				if (getter.member.isStatic()) {
167
-					if (!allowStaticUsage)
168
-						return new InvalidExpression(position, getter.member.getType(), CompileExceptionCode.USING_STATIC_ON_INSTANCE, "This field is static");
162
+	public Expression getter(CodePosition position, TypeScope scope, Expression target, boolean allowStaticUsage) throws CompileException {
163
+		if (getter != null) {
164
+			if (getter.member.isStatic()) {
165
+				if (!allowStaticUsage)
166
+					return new InvalidExpression(position, getter.member.getType(), CompileExceptionCode.USING_STATIC_ON_INSTANCE, "This field is static");
169
 
167
 
170
-					return getter.member.getStatic(position);
171
-				}
172
-
173
-				scope.getPreparer().prepare(getter.member.member);
174
-				return getter.member.get(position, target);
175
-			} else if (field != null) {
176
-				if (field.member.isStatic()) {
177
-					if (!allowStaticUsage)
178
-						return new InvalidExpression(position, field.member.getType(), CompileExceptionCode.USING_STATIC_ON_INSTANCE, "This field is static");
168
+				return getter.member.getStatic(position);
169
+			}
179
 
170
 
180
-					return new GetStaticFieldExpression(position, field.member);
181
-				}
171
+			scope.getPreparer().prepare(getter.member.member);
172
+			return getter.member.get(position, target);
173
+		} else if (field != null) {
174
+			if (field.member.isStatic()) {
175
+				if (!allowStaticUsage)
176
+					return new InvalidExpression(position, field.member.getType(), CompileExceptionCode.USING_STATIC_ON_INSTANCE, "This field is static");
182
 
177
 
183
-				scope.getPreparer().prepare(field.member.member);
184
-				return new GetFieldExpression(position, target, field.member);
185
-			} else {
186
-				return new InvalidExpression(position, CompileExceptionCode.MEMBER_NO_GETTER, "Value is not a property");
178
+				return new GetStaticFieldExpression(position, field.member);
187
 			}
179
 			}
188
-		} catch (CompileException ex) {
189
-			return new InvalidExpression(BasicTypeID.UNDETERMINED.stored, ex);
180
+
181
+			scope.getPreparer().prepare(field.member.member);
182
+			return new GetFieldExpression(position, target, field.member);
183
+		} else {
184
+			throw new CompileException(position, CompileExceptionCode.MEMBER_NO_GETTER, "Value is not a property");
190
 		}
185
 		}
191
 	}
186
 	}
192
 	
187
 	
193
-	public Expression setter(CodePosition position, TypeScope scope, Expression target, Expression value, boolean allowStaticUsage) {
194
-		try {
195
-			if (setter != null) {
196
-				if (setter.member.isStatic()) {
197
-					if (!allowStaticUsage)
198
-						return new InvalidExpression(position, setter.member.getType(), CompileExceptionCode.USING_STATIC_ON_INSTANCE, "This field is static");
199
-
200
-					scope.getPreparer().prepare(setter.member.member);
201
-					return new StaticSetterExpression(position, setter.member, value.castImplicit(position, scope, setter.member.getType()));
202
-				}
188
+	public Expression setter(CodePosition position, TypeScope scope, Expression target, Expression value, boolean allowStaticUsage) throws CompileException {
189
+		if (setter != null) {
190
+			if (setter.member.isStatic()) {
191
+				if (!allowStaticUsage)
192
+					return new InvalidExpression(position, setter.member.getType(), CompileExceptionCode.USING_STATIC_ON_INSTANCE, "This field is static");
203
 
193
 
204
 				scope.getPreparer().prepare(setter.member.member);
194
 				scope.getPreparer().prepare(setter.member.member);
205
-				return new SetterExpression(position, target, setter.member, value.castImplicit(position, scope, setter.member.getType()));
206
-			} else if (field != null) {
207
-				// TODO: perform proper checks on val fields
208
-				//if (field.isFinal)
209
-				//	throw new CompileException(position, "This field cannot be modified");
210
-				if (field.member.isStatic()) {
211
-					if (!allowStaticUsage)
212
-						return new InvalidExpression(position, field.member.getType(), CompileExceptionCode.USING_STATIC_ON_INSTANCE, "This field is static");
195
+				return new StaticSetterExpression(position, setter.member, value.castImplicit(position, scope, setter.member.getType()));
196
+			}
213
 
197
 
214
-					scope.getPreparer().prepare(field.member.member);
215
-					return new SetStaticFieldExpression(position, field.member, value.castImplicit(position, scope, field.member.getType()));
216
-				}
198
+			scope.getPreparer().prepare(setter.member.member);
199
+			return new SetterExpression(position, target, setter.member, value.castImplicit(position, scope, setter.member.getType()));
200
+		} else if (field != null) {
201
+			// TODO: perform proper checks on val fields
202
+			//if (field.isFinal)
203
+			//	throw new CompileException(position, "This field cannot be modified");
204
+			if (field.member.isStatic()) {
205
+				if (!allowStaticUsage)
206
+					return new InvalidExpression(position, field.member.getType(), CompileExceptionCode.USING_STATIC_ON_INSTANCE, "This field is static");
217
 
207
 
218
 				scope.getPreparer().prepare(field.member.member);
208
 				scope.getPreparer().prepare(field.member.member);
219
-				return new SetFieldExpression(position, target, field.member, value.castImplicit(position, scope, field.member.getType()));
220
-			} else {
221
-				return new InvalidExpression(position, CompileExceptionCode.MEMBER_NO_SETTER, "Value is not settable");
209
+				return new SetStaticFieldExpression(position, field.member, value.castImplicit(position, scope, field.member.getType()));
222
 			}
210
 			}
223
-		} catch (CompileException ex) {
224
-			return new InvalidExpression(BasicTypeID.UNDETERMINED.stored, ex);
211
+
212
+			scope.getPreparer().prepare(field.member.member);
213
+			return new SetFieldExpression(position, target, field.member, value.castImplicit(position, scope, field.member.getType()));
214
+		} else {
215
+			throw new CompileException(position, CompileExceptionCode.MEMBER_NO_SETTER, "Value is not settable");
225
 		}
216
 		}
226
 	}
217
 	}
227
 	
218
 	
228
-	public Expression staticGetter(CodePosition position, TypeScope scope) {
229
-		try {
230
-			if (constant != null) {
231
-				return new ConstExpression(position, constant.member);
232
-			} else if (getter != null) {
233
-				if (!getter.member.isStatic())
234
-					return new InvalidExpression(position, getter.member.getType(), CompileExceptionCode.MEMBER_NOT_STATIC, "This getter is not static");
219
+	public Expression staticGetter(CodePosition position, TypeScope scope) throws CompileException {
220
+		if (constant != null) {
221
+			return new ConstExpression(position, constant.member);
222
+		} else if (getter != null) {
223
+			if (!getter.member.isStatic())
224
+				return new InvalidExpression(position, getter.member.getType(), CompileExceptionCode.MEMBER_NOT_STATIC, "This getter is not static");
235
 
225
 
236
-				scope.getPreparer().prepare(getter.member.member);
237
-				return getter.member.getStatic(position);
238
-			} else if (field != null) {
239
-				if (!field.member.isStatic())
240
-					return new InvalidExpression(position, field.member.getType(), CompileExceptionCode.MEMBER_NOT_STATIC, "This field is not static");
226
+			scope.getPreparer().prepare(getter.member.member);
227
+			return getter.member.getStatic(position);
228
+		} else if (field != null) {
229
+			if (!field.member.isStatic())
230
+				return new InvalidExpression(position, field.member.getType(), CompileExceptionCode.MEMBER_NOT_STATIC, "This field is not static");
241
 
231
 
242
-				scope.getPreparer().prepare(field.member.member);
243
-				return new GetStaticFieldExpression(position, field.member);
244
-			} else {
245
-				return new InvalidExpression(position, CompileExceptionCode.MEMBER_NO_GETTER, "Member is not gettable");
246
-			}
247
-		} catch (CompileException ex) {
248
-			return new InvalidExpression(BasicTypeID.UNDETERMINED.stored, ex);
232
+			scope.getPreparer().prepare(field.member.member);
233
+			return new GetStaticFieldExpression(position, field.member);
234
+		} else {
235
+			throw new CompileException(position, CompileExceptionCode.MEMBER_NO_GETTER, "Member is not gettable");
249
 		}
236
 		}
250
 	}
237
 	}
251
 	
238
 	
252
-	public Expression staticSetter(CodePosition position, TypeScope scope, Expression value) {
253
-		try {
254
-			if (getter != null) {
255
-				if (!getter.member.isStatic())
256
-					return new InvalidExpression(position, getter.member.getType(), CompileExceptionCode.MEMBER_NOT_STATIC, "This getter is not static");
239
+	public Expression staticSetter(CodePosition position, TypeScope scope, Expression value) throws CompileException {
240
+		if (getter != null) {
241
+			if (!getter.member.isStatic())
242
+				return new InvalidExpression(position, getter.member.getType(), CompileExceptionCode.MEMBER_NOT_STATIC, "This getter is not static");
257
 
243
 
258
-				scope.getPreparer().prepare(setter.member.member);
259
-				return new StaticSetterExpression(position, setter.member, value.castImplicit(position, scope, setter.member.getType()));
260
-			} else if (field != null) {
261
-				//if (field.member.isFinal)
262
-				//	throw new CompileException(position, CompileExceptionCode.MEMBER_IS_FINAL, "This field cannot be modified");
263
-				if (!field.member.isStatic())
264
-					return new InvalidExpression(position, field.member.getType(), CompileExceptionCode.MEMBER_NOT_STATIC, "This field is not static");
244
+			scope.getPreparer().prepare(setter.member.member);
245
+			return new StaticSetterExpression(position, setter.member, value.castImplicit(position, scope, setter.member.getType()));
246
+		} else if (field != null) {
247
+			//if (field.member.isFinal)
248
+			//	throw new CompileException(position, CompileExceptionCode.MEMBER_IS_FINAL, "This field cannot be modified");
249
+			if (!field.member.isStatic())
250
+				return new InvalidExpression(position, field.member.getType(), CompileExceptionCode.MEMBER_NOT_STATIC, "This field is not static");
265
 
251
 
266
-				scope.getPreparer().prepare(field.member.member);
267
-				return new SetStaticFieldExpression(position, field.member, value.castImplicit(position, scope, field.member.getType()));
268
-			} else {
269
-				return new InvalidExpression(position, CompileExceptionCode.MEMBER_NO_SETTER, "Member is not settable");
270
-			}
271
-		} catch (CompileException ex) {
272
-			return new InvalidExpression(BasicTypeID.UNDETERMINED.stored, ex);
252
+			scope.getPreparer().prepare(field.member.member);
253
+			return new SetStaticFieldExpression(position, field.member, value.castImplicit(position, scope, field.member.getType()));
254
+		} else {
255
+			throw new CompileException(position, CompileExceptionCode.MEMBER_NO_SETTER, "Member is not settable");
273
 		}
256
 		}
274
 	}
257
 	}
275
 	
258
 	
302
 		return result;
285
 		return result;
303
 	}
286
 	}
304
 	
287
 	
305
-	public Expression call(CodePosition position, TypeScope scope, Expression target, CallArguments arguments, boolean allowStaticUsage) {
306
-		try {
307
-			FunctionalMemberRef method = selectMethod(position, scope, arguments, true, allowStaticUsage);
308
-			FunctionHeader instancedHeader = method.getHeader().fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments, scope.getLocalTypeParameters());
309
-			for (int i = 0; i < arguments.arguments.length; i++) {
310
-				arguments.arguments[i] = arguments.arguments[i].castImplicit(position, scope, instancedHeader.parameters[i].type);
311
-			}
312
-
313
-			scope.getPreparer().prepare(method.getTarget());
314
-			return method.call(position, target, instancedHeader, arguments, scope);
315
-		} catch (CompileException ex) {
316
-			return new InvalidExpression(position, ex.code, ex.getMessage());
288
+	public Expression call(CodePosition position, TypeScope scope, Expression target, CallArguments arguments, boolean allowStaticUsage) throws CompileException {
289
+		FunctionalMemberRef method = selectMethod(position, scope, arguments, true, allowStaticUsage);
290
+		FunctionHeader instancedHeader = method.getHeader().fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments, scope.getLocalTypeParameters());
291
+		for (int i = 0; i < arguments.arguments.length; i++) {
292
+			arguments.arguments[i] = arguments.arguments[i].castImplicit(position, scope, instancedHeader.parameters[i].type);
317
 		}
293
 		}
294
+
295
+		scope.getPreparer().prepare(method.getTarget());
296
+		return method.call(position, target, instancedHeader, arguments, scope);
318
 	}
297
 	}
319
 	
298
 	
320
-	public Expression callPostfix(CodePosition position, TypeScope scope, Expression target) {
299
+	public Expression callPostfix(CodePosition position, TypeScope scope, Expression target) throws CompileException {
321
 		if (methods.isEmpty())
300
 		if (methods.isEmpty())
322
-			return new InvalidExpression(position, CompileExceptionCode.NO_SUCH_MEMBER, "There is no such operator");
301
+			throw new CompileException(position, CompileExceptionCode.NO_SUCH_MEMBER, "There is no such operator");
323
 		
302
 		
324
 		FunctionalMemberRef method = methods.get(0).member;
303
 		FunctionalMemberRef method = methods.get(0).member;
325
 		if (!method.isOperator())
304
 		if (!method.isOperator())
326
-			return new InvalidExpression(position, CompileExceptionCode.NO_SUCH_MEMBER, "Member is not an operator");
305
+			throw new CompileException(position, CompileExceptionCode.NO_SUCH_MEMBER, "Member is not an operator");
327
 		
306
 		
328
-		try {
329
-			scope.getPreparer().prepare(method.getTarget());
330
-			return new PostCallExpression(position, target, method, method.getHeader());
331
-		} catch (CompileException ex) {
332
-			return new InvalidExpression(BasicTypeID.UNDETERMINED.stored, ex);
333
-		}
307
+		scope.getPreparer().prepare(method.getTarget());
308
+		return new PostCallExpression(position, target, method, method.getHeader());
334
 	}
309
 	}
335
 	
310
 	
336
 	public Expression callWithComparator(
311
 	public Expression callWithComparator(
338
 			TypeScope scope,
313
 			TypeScope scope,
339
 			Expression target,
314
 			Expression target,
340
 			CallArguments arguments,
315
 			CallArguments arguments,
341
-			CompareType compareType) {
342
-		try {
343
-			FunctionalMemberRef method = selectMethod(position, scope, arguments, true, false);
344
-			FunctionHeader instancedHeader = method.getHeader().fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments, scope.getLocalTypeParameters());
345
-			return method.callWithComparator(position, compareType, target, instancedHeader, arguments, scope);
346
-		} catch (CompileException ex) {
347
-			return new InvalidExpression(position, ex.code, ex.getMessage());
348
-		}
316
+			CompareType compareType) throws CompileException
317
+	{
318
+		FunctionalMemberRef method = selectMethod(position, scope, arguments, true, false);
319
+		FunctionHeader instancedHeader = method.getHeader().fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments, scope.getLocalTypeParameters());
320
+		return method.callWithComparator(position, compareType, target, instancedHeader, arguments, scope);
349
 	}
321
 	}
350
 	
322
 	
351
-	public Expression callStatic(CodePosition position, TypeID target, TypeScope scope, CallArguments arguments) {
352
-		try {
353
-			FunctionalMemberRef method = selectMethod(position, scope, arguments, false, true);
354
-			FunctionHeader instancedHeader = method.getHeader().fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments, scope.getLocalTypeParameters());
355
-			return method.callStatic(position, target, instancedHeader, arguments, scope);
356
-		} catch (CompileException ex) {
357
-			return new InvalidExpression(position, ex.code, ex.getMessage());
358
-		}
323
+	public Expression callStatic(CodePosition position, TypeID target, TypeScope scope, CallArguments arguments) throws CompileException {
324
+		FunctionalMemberRef method = selectMethod(position, scope, arguments, false, true);
325
+		FunctionHeader instancedHeader = method.getHeader().fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments, scope.getLocalTypeParameters());
326
+		return method.callStatic(position, target, instancedHeader, arguments, scope);
359
 	}
327
 	}
360
 	
328
 	
361
 	public FunctionalMemberRef selectMethod(CodePosition position, TypeScope scope, CallArguments arguments, boolean allowNonStatic, boolean allowStatic) throws CompileException {
329
 	public FunctionalMemberRef selectMethod(CodePosition position, TypeScope scope, CallArguments arguments, boolean allowNonStatic, boolean allowStatic) throws CompileException {

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

49
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
49
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
50
 import org.openzen.zenscript.codemodel.scope.TypeScope;
50
 import org.openzen.zenscript.codemodel.scope.TypeScope;
51
 import org.openzen.zenscript.codemodel.type.StoredType;
51
 import org.openzen.zenscript.codemodel.type.StoredType;
52
+import org.openzen.zenscript.codemodel.type.StringTypeID;
52
 import org.openzen.zenscript.codemodel.type.TypeID;
53
 import org.openzen.zenscript.codemodel.type.TypeID;
53
 
54
 
54
 /**
55
 /**
352
 		return variantOptions.get(name);
353
 		return variantOptions.get(name);
353
 	}
354
 	}
354
 	
355
 	
355
-	public Expression compare(CodePosition position, TypeScope scope, CompareType operator, Expression left, Expression right) {
356
+	public Expression compare(CodePosition position, TypeScope scope, CompareType operator, Expression left, Expression right) throws CompileException {
356
 		if (operator == CompareType.EQ) {
357
 		if (operator == CompareType.EQ) {
357
 			TypeMemberGroup equal = getOrCreateGroup(OperatorType.EQUALS);
358
 			TypeMemberGroup equal = getOrCreateGroup(OperatorType.EQUALS);
358
 			for (TypeMember<FunctionalMemberRef> member : equal.getMethodMembers()) {
359
 			for (TypeMember<FunctionalMemberRef> member : equal.getMethodMembers()) {
372
 		return compare.callWithComparator(position, scope, left, new CallArguments(right), operator);
373
 		return compare.callWithComparator(position, scope, left, new CallArguments(right), operator);
373
 	}
374
 	}
374
 	
375
 	
375
-	public Expression unary(CodePosition position, TypeScope scope, OperatorType operator, Expression value) {
376
+	public Expression unary(CodePosition position, TypeScope scope, OperatorType operator, Expression value) throws CompileException {
376
 		TypeMemberGroup members = getOrCreateGroup(operator);
377
 		TypeMemberGroup members = getOrCreateGroup(operator);
377
 		return members.call(position, scope, value, new CallArguments(Expression.NONE), false);
378
 		return members.call(position, scope, value, new CallArguments(Expression.NONE), false);
378
 	}
379
 	}
458
 	}
459
 	}
459
 	
460
 	
460
 	private Expression castEquivalent(CodePosition position, Expression value, StoredType toType) {
461
 	private Expression castEquivalent(CodePosition position, Expression value, StoredType toType) {
461
-		if (toType == value.type)
462
+		if (toType.equals(value.type))
462
 			return value;
463
 			return value;
463
 		
464
 		
465
+		if (!(toType.type instanceof StringTypeID))
466
+			System.out.println(position + ": " + value.type.storage + " -> " + toType.storage);
467
+		
464
 		return new StorageCastExpression(position, value, toType);
468
 		return new StorageCastExpression(position, value, toType);
465
 	}
469
 	}
466
 	
470
 	
467
 	public Expression castImplicit(CodePosition position, Expression value, StoredType toType, boolean implicit) {
471
 	public Expression castImplicit(CodePosition position, Expression value, StoredType toType, boolean implicit) {
472
+		if (toType == null)
473
+			throw new NullPointerException();
474
+		
468
 		toType = toType.getNormalized();
475
 		toType = toType.getNormalized();
469
 		if (toType.type == BasicTypeID.UNDETERMINED)
476
 		if (toType.type == BasicTypeID.UNDETERMINED)
470
 			return value;
477
 			return value;
500
 			return castImplicit(position, value, toType, false);
507
 			return castImplicit(position, value, toType, false);
501
 		
508
 		
502
 		for (TypeMember<CasterMemberRef> caster : casters)
509
 		for (TypeMember<CasterMemberRef> caster : casters)
503
-			if (toType == caster.member.toType)
504
-				return caster.member.cast(position, value, false);
510
+			if (areEquivalent(caster.member.toType, toType))
511
+				return castEquivalent(position, caster.member.cast(position, value, false), toType);
505
 		
512
 		
506
 		return new InvalidExpression(position, toType, CompileExceptionCode.INVALID_CAST, "Cannot cast " + toString() + " to " + toType + ", even explicitly");
513
 		return new InvalidExpression(position, toType, CompileExceptionCode.INVALID_CAST, "Cannot cast " + toString() + " to " + toType + ", even explicitly");
507
 	}
514
 	}

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/storage/SharedStorageTag.java View File

31
 
31
 
32
 	@Override
32
 	@Override
33
 	public boolean canCastFrom(StorageTag other) {
33
 	public boolean canCastFrom(StorageTag other) {
34
-		return other == this || other == UniqueStorageTag.INSTANCE;
34
+		return other == this || other == UniqueStorageTag.INSTANCE || other == StaticStorageTag.INSTANCE;
35
 	}
35
 	}
36
 
36
 
37
 	@Override
37
 	@Override

+ 4
- 3
CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java View File

88
 		ModuleTypeResolutionContext context = new ModuleTypeResolutionContext(compilationUnit.globalTypeRegistry, annotations, storageTypes, rootPackage, null, globals);
88
 		ModuleTypeResolutionContext context = new ModuleTypeResolutionContext(compilationUnit.globalTypeRegistry, annotations, storageTypes, rootPackage, null, globals);
89
 		AnnotationProcessor annotationProcessor = new AnnotationProcessor(context, expansions);
89
 		AnnotationProcessor annotationProcessor = new AnnotationProcessor(context, expansions);
90
 		List<ScriptBlock> processedScripts = new ArrayList<>();
90
 		List<ScriptBlock> processedScripts = new ArrayList<>();
91
+		FileScope fileScope = new FileScope(context, expansions, globals, member -> {});
92
+			
91
 		for (ScriptBlock block : scripts)
93
 		for (ScriptBlock block : scripts)
92
-			processedScripts.add(annotationProcessor.process(block));
94
+			processedScripts.add(annotationProcessor.process(block).normalize(fileScope));
95
+		
93
 		for (HighLevelDefinition definition : definitions.getAll()) {
96
 		for (HighLevelDefinition definition : definitions.getAll()) {
94
 			annotationProcessor.process(definition);
97
 			annotationProcessor.process(definition);
95
-			
96
-			FileScope fileScope = new FileScope(context, expansions, globals, member -> {});
97
 			definition.normalize(fileScope);
98
 			definition.normalize(fileScope);
98
 		}
99
 		}
99
 		
100
 		

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

1778
 	@Override
1778
 	@Override
1779
 	public Void visitGetLocalVariable(GetLocalVariableExpression expression) {
1779
 	public Void visitGetLocalVariable(GetLocalVariableExpression expression) {
1780
 		final Label label = new Label();
1780
 		final Label label = new Label();
1781
-		final JavaLocalVariableInfo tag = expression.variable.getTag(JavaLocalVariableInfo.class);
1781
+		final JavaLocalVariableInfo tag = expression.variable.variable.getTag(JavaLocalVariableInfo.class);
1782
+		if (tag == null)
1783
+			throw new RuntimeException("Missing tag @ " + expression.position);
1784
+		
1782
 		tag.end = label;
1785
 		tag.end = label;
1783
 		javaWriter.load(tag.type, tag.local);
1786
 		javaWriter.load(tag.type, tag.local);
1784
 		javaWriter.label(label);
1787
 		javaWriter.label(label);
2242
 		expression.value.accept(this);
2245
 		expression.value.accept(this);
2243
 		Label label = new Label();
2246
 		Label label = new Label();
2244
 		javaWriter.label(label);
2247
 		javaWriter.label(label);
2245
-		final JavaLocalVariableInfo tag = expression.variable.getTag(JavaLocalVariableInfo.class);
2248
+		final JavaLocalVariableInfo tag = expression.variable.variable.getTag(JavaLocalVariableInfo.class);
2246
 		tag.end = label;
2249
 		tag.end = label;
2247
 
2250
 
2248
 		javaWriter.store(tag.type, tag.local);
2251
 		javaWriter.store(tag.type, tag.local);

+ 4
- 4
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaForeachWriter.java View File

29
 		javaWriter.swap();
29
 		javaWriter.swap();
30
 		javaWriter.getField("zsynthetic/IntRange", "from", "I");
30
 		javaWriter.getField("zsynthetic/IntRange", "from", "I");
31
 
31
 
32
-		final int z = variables[0].getTag(JavaLocalVariableInfo.class).local;
32
+		final int z = variables[0].variable.getTag(JavaLocalVariableInfo.class).local;
33
 		javaWriter.storeInt(z);
33
 		javaWriter.storeInt(z);
34
 		javaWriter.label(startLabel);
34
 		javaWriter.label(startLabel);
35
 		javaWriter.dup();
35
 		javaWriter.dup();
41
 	}
41
 	}
42
 
42
 
43
 	public void visitArrayValueIterator() {
43
 	public void visitArrayValueIterator() {
44
-		handleArray(javaWriter.local(int.class), variables[0].getTag(JavaLocalVariableInfo.class));
44
+		handleArray(javaWriter.local(int.class), variables[0].variable.getTag(JavaLocalVariableInfo.class));
45
 	}
45
 	}
46
 
46
 
47
 	public void visitArrayKeyValueIterator() {
47
 	public void visitArrayKeyValueIterator() {
48
-		handleArray(variables[0].getTag(JavaLocalVariableInfo.class).local, variables[1].getTag(JavaLocalVariableInfo.class));
48
+		handleArray(variables[0].variable.getTag(JavaLocalVariableInfo.class).local, variables[1].variable.getTag(JavaLocalVariableInfo.class));
49
 	}
49
 	}
50
 
50
 
51
 	public void visitStringCharacterIterator() {
51
 	public void visitStringCharacterIterator() {
52
 		//TODO UNTESTED!
52
 		//TODO UNTESTED!
53
 		javaWriter.invokeSpecial("java/lang/String", "toCharArray()", "()[C");
53
 		javaWriter.invokeSpecial("java/lang/String", "toCharArray()", "()[C");
54
-		handleArray(javaWriter.local(int.class), variables[0].getTag(JavaLocalVariableInfo.class));
54
+		handleArray(javaWriter.local(int.class), variables[0].variable.getTag(JavaLocalVariableInfo.class));
55
 	}
55
 	}
56
 
56
 
57
 	private void handleArray(final int z, final JavaLocalVariableInfo arrayTypeInfo) {
57
 	private void handleArray(final int z, final JavaLocalVariableInfo arrayTypeInfo) {

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

221
 	
221
 	
222
 	@Override
222
 	@Override
223
 	public Void visitGetLocalVariable(GetLocalVariableExpression expression) {
223
 	public Void visitGetLocalVariable(GetLocalVariableExpression expression) {
224
-		javaWriter.idec(expression.variable.getTag(JavaLocalVariableInfo.class).local);
224
+		javaWriter.idec(expression.variable.variable.getTag(JavaLocalVariableInfo.class).local);
225
 		return null;
225
 		return null;
226
 	}
226
 	}
227
 
227
 

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

224
 
224
 
225
 	@Override
225
 	@Override
226
 	public Void visitGetLocalVariable(GetLocalVariableExpression expression) {
226
 	public Void visitGetLocalVariable(GetLocalVariableExpression expression) {
227
-		JavaLocalVariableInfo localVariable = expression.variable.getTag(JavaLocalVariableInfo.class);
227
+		JavaLocalVariableInfo localVariable = expression.variable.variable.getTag(JavaLocalVariableInfo.class);
228
 		javaWriter.iinc(localVariable.local);
228
 		javaWriter.iinc(localVariable.local);
229
 		javaWriter.load(localVariable);
229
 		javaWriter.load(localVariable);
230
 		return null;
230
 		return null;

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

103
             final Label variableStart = new Label();
103
             final Label variableStart = new Label();
104
             final JavaLocalVariableInfo info = new JavaLocalVariableInfo(type, javaWriter.local(type), variableStart, variable.name);
104
             final JavaLocalVariableInfo info = new JavaLocalVariableInfo(type, javaWriter.local(type), variableStart, variable.name);
105
             info.end = end;
105
             info.end = end;
106
-            variable.setTag(JavaLocalVariableInfo.class, info);
106
+            variable.variable.setTag(JavaLocalVariableInfo.class, info);
107
             javaWriter.addVariableInfo(info);
107
             javaWriter.addVariableInfo(info);
108
         }
108
         }
109
 
109
 
311
 		final Label variableStart = new Label();
311
 		final Label variableStart = new Label();
312
 		javaWriter.label(variableStart);
312
 		javaWriter.label(variableStart);
313
 		final JavaLocalVariableInfo info = new JavaLocalVariableInfo(type, local, variableStart, statement.name);
313
 		final JavaLocalVariableInfo info = new JavaLocalVariableInfo(type, local, variableStart, statement.name);
314
-		statement.setTag(JavaLocalVariableInfo.class, info);
314
+		statement.variable.setTag(JavaLocalVariableInfo.class, info);
315
 		javaWriter.addVariableInfo(info);
315
 		javaWriter.addVariableInfo(info);
316
 		return false;
316
 		return false;
317
 	}
317
 	}

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

2
 
2
 
3
 import org.objectweb.asm.*;
3
 import org.objectweb.asm.*;
4
 
4
 
5
-import java.lang.reflect.Field;
6
 import java.util.ArrayList;
5
 import java.util.ArrayList;
7
 import java.util.HashMap;
6
 import java.util.HashMap;
8
 import java.util.List;
7
 import java.util.List;

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

145
 		final JavaWriter writer = new JavaWriter(outerWriter, true, method, definition, signature, null);
145
 		final JavaWriter writer = new JavaWriter(outerWriter, true, method, definition, signature, null);
146
         final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, writer);
146
         final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, writer);
147
         statementVisitor.start();
147
         statementVisitor.start();
148
-		boolean returns = definition.statement.accept(statementVisitor);
148
+		boolean returns = definition.caller.body.accept(statementVisitor);
149
 		if (!returns) {
149
 		if (!returns) {
150
 			StoredType type = definition.header.getReturnType();
150
 			StoredType type = definition.header.getReturnType();
151
 			if (CompilerUtils.isPrimitive(type.type))
151
 			if (CompilerUtils.isPrimitive(type.type))

+ 1
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceExpressionFormatter.java View File

1695
 								.append(newArray(type.elementType, size))
1695
 								.append(newArray(type.elementType, size))
1696
 								.append(";")
1696
 								.append(";")
1697
 								.toString());
1697
 								.toString());
1698
-					VarStatement tempI = new VarStatement(expression.position, scope.createTempVariable(), BasicTypeID.INT.stored, null, true);
1698
+					VarStatement tempI = new VarStatement(expression.position, new VariableID(), scope.createTempVariable(), BasicTypeID.INT.stored, null, true);
1699
 					target.writeLine(new StringBuilder()
1699
 					target.writeLine(new StringBuilder()
1700
 								.append("for (int ")
1700
 								.append("for (int ")
1701
 								.append(tempI.name)
1701
 								.append(tempI.name)

+ 2
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/scope/JavaSourceStatementScope.java View File

13
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
13
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
14
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
14
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
15
 import org.openzen.zenscript.codemodel.statement.VarStatement;
15
 import org.openzen.zenscript.codemodel.statement.VarStatement;
16
+import org.openzen.zenscript.codemodel.statement.VariableID;
16
 import org.openzen.zenscript.codemodel.type.StoredType;
17
 import org.openzen.zenscript.codemodel.type.StoredType;
17
 import org.openzen.zenscript.codemodel.type.TypeID;
18
 import org.openzen.zenscript.codemodel.type.TypeID;
18
 import org.openzen.zenscript.formattershared.ExpressionString;
19
 import org.openzen.zenscript.formattershared.ExpressionString;
115
 		if (!shouldHoist)
116
 		if (!shouldHoist)
116
 			return expression;
117
 			return expression;
117
 		
118
 		
118
-		VarStatement temp = new VarStatement(expression.position, createTempVariable(), expression.type, expression, true);
119
+		VarStatement temp = new VarStatement(expression.position, new VariableID(), createTempVariable(), expression.type, expression, true);
119
 		new JavaSourceStatementFormatter(this).formatVar(target, temp);
120
 		new JavaSourceStatementFormatter(this).formatVar(target, temp);
120
 		return new GetLocalVariableExpression(expression.position, temp);
121
 		return new GetLocalVariableExpression(expression.position, temp);
121
 	}
122
 	}

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunction.java View File

78
 		compiled.setCode(body.compile(innerScope, compiled.header));
78
 		compiled.setCode(body.compile(innerScope, compiled.header));
79
 		
79
 		
80
 		if (compiled.header.getReturnType().isBasic(BasicTypeID.UNDETERMINED))
80
 		if (compiled.header.getReturnType().isBasic(BasicTypeID.UNDETERMINED))
81
-			compiled.header.setReturnType(compiled.statement.getReturnType());
81
+			compiled.header.setReturnType(compiled.caller.body.getReturnType());
82
 	}
82
 	}
83
 
83
 
84
 	@Override
84
 	@Override

+ 7
- 1
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunctionParameter.java View File

1
 package org.openzen.zenscript.parser.definitions;
1
 package org.openzen.zenscript.parser.definitions;
2
 
2
 
3
+import org.openzen.zencode.shared.CompileException;
3
 import org.openzen.zenscript.codemodel.FunctionParameter;
4
 import org.openzen.zenscript.codemodel.FunctionParameter;
4
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
5
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
5
 import org.openzen.zenscript.codemodel.expression.Expression;
6
 import org.openzen.zenscript.codemodel.expression.Expression;
7
+import org.openzen.zenscript.codemodel.expression.InvalidExpression;
6
 import org.openzen.zenscript.codemodel.scope.BaseScope;
8
 import org.openzen.zenscript.codemodel.scope.BaseScope;
7
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
9
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
8
 import org.openzen.zenscript.codemodel.type.StoredType;
10
 import org.openzen.zenscript.codemodel.type.StoredType;
43
 	
45
 	
44
 	public void compileInitializer(BaseScope scope, PrecompilationState state) {
46
 	public void compileInitializer(BaseScope scope, PrecompilationState state) {
45
 		if (defaultValue != null) {
47
 		if (defaultValue != null) {
46
-			compiled.defaultValue = defaultValue.compile(new ExpressionScope(scope, compiled.type)).eval();
48
+			try {
49
+				compiled.defaultValue = defaultValue.compile(new ExpressionScope(scope, compiled.type)).eval();
50
+			} catch (CompileException ex) {
51
+				compiled.defaultValue = new InvalidExpression(compiled.type, ex);
52
+			}
47
 		}
53
 		}
48
 	}
54
 	}
49
 }
55
 }

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

39
 		
39
 		
40
 		int ordinal = 0;
40
 		int ordinal = 0;
41
 		while (!tokens.isNext(ZSTokenType.T_ACLOSE) && !tokens.isNext(ZSTokenType.T_SEMICOLON)) {
41
 		while (!tokens.isNext(ZSTokenType.T_ACLOSE) && !tokens.isNext(ZSTokenType.T_SEMICOLON)) {
42
+			CodePosition optionPosition = tokens.getPosition();
42
 			String optionName = tokens.required(ZSTokenType.T_IDENTIFIER, "identifier expected").content;
43
 			String optionName = tokens.required(ZSTokenType.T_IDENTIFIER, "identifier expected").content;
43
 			List<IParsedType> types = new ArrayList<>();
44
 			List<IParsedType> types = new ArrayList<>();
44
 			if (tokens.optional(ZSTokenType.T_BROPEN) != null) {
45
 			if (tokens.optional(ZSTokenType.T_BROPEN) != null) {
48
 				}
49
 				}
49
 				tokens.required(ZSTokenType.T_BRCLOSE, ") expected");
50
 				tokens.required(ZSTokenType.T_BRCLOSE, ") expected");
50
 			}
51
 			}
51
-			result.addVariant(new ParsedVariantOption(optionName, ordinal++, types));
52
+			result.addVariant(new ParsedVariantOption(optionPosition, optionName, ordinal++, types));
52
 			if (tokens.optional(ZSTokenType.T_COMMA) == null)
53
 			if (tokens.optional(ZSTokenType.T_COMMA) == null)
53
 				break;
54
 				break;
54
 		}
55
 		}

+ 5
- 2
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedVariantOption.java View File

6
 package org.openzen.zenscript.parser.definitions;
6
 package org.openzen.zenscript.parser.definitions;
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
+import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
10
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
10
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
11
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
11
 import org.openzen.zenscript.codemodel.type.StoredType;
12
 import org.openzen.zenscript.codemodel.type.StoredType;
16
  * @author Hoofdgebruiker
17
  * @author Hoofdgebruiker
17
  */
18
  */
18
 public class ParsedVariantOption {
19
 public class ParsedVariantOption {
20
+	public final CodePosition position;
19
 	public final String name;
21
 	public final String name;
20
 	public final int ordinal;
22
 	public final int ordinal;
21
 	public final List<IParsedType> types;
23
 	public final List<IParsedType> types;
22
 	
24
 	
23
-	public ParsedVariantOption(String name, int ordinal, List<IParsedType> types) {
25
+	public ParsedVariantOption(CodePosition position, String name, int ordinal, List<IParsedType> types) {
26
+		this.position = position;
24
 		this.name = name;
27
 		this.name = name;
25
 		this.ordinal = ordinal;
28
 		this.ordinal = ordinal;
26
 		this.types = types;
29
 		this.types = types;
31
 		for (int i = 0; i < cTypes.length; i++)
34
 		for (int i = 0; i < cTypes.length; i++)
32
 			cTypes[i] = types.get(i).compile(context);
35
 			cTypes[i] = types.get(i).compile(context);
33
 		
36
 		
34
-		return new VariantDefinition.Option(variant, name, ordinal, cTypes);
37
+		return new VariantDefinition.Option(position, variant, name, ordinal, cTypes);
35
 	}
38
 	}
36
 }
39
 }

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedCallArguments.java View File

210
 		return new CallArguments(typeArguments2, cArguments);
210
 		return new CallArguments(typeArguments2, cArguments);
211
 	}
211
 	}
212
 	
212
 	
213
-	private CallArguments compileCallNaive(CodePosition position, ExpressionScope scope) {
213
+	private CallArguments compileCallNaive(CodePosition position, ExpressionScope scope) throws CompileException {
214
 		Expression[] cArguments = new Expression[arguments.size()];
214
 		Expression[] cArguments = new Expression[arguments.size()];
215
 		for (int i = 0; i < cArguments.length; i++) {
215
 		for (int i = 0; i < cArguments.length; i++) {
216
 			IPartialExpression cArgument = arguments.get(i).compile(scope);
216
 			IPartialExpression cArgument = arguments.get(i).compile(scope);

+ 5
- 8
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedDollarExpression.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.parser.expression;
6
 package org.openzen.zenscript.parser.expression;
7
 
7
 
8
-import java.util.function.Function;
9
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
10
 import org.openzen.zencode.shared.CompileExceptionCode;
10
 import org.openzen.zencode.shared.CompileExceptionCode;
11
-import org.openzen.zenscript.codemodel.expression.Expression;
12
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
11
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
12
+import org.openzen.zenscript.codemodel.scope.BaseScope.DollarEvaluator;
14
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
13
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
15
-import org.openzen.zenscript.codemodel.type.BasicTypeID;
16
 
14
 
17
 /**
15
 /**
18
  *
16
  *
24
 	}
22
 	}
25
 
23
 
26
 	@Override
24
 	@Override
27
-	public IPartialExpression compile(ExpressionScope scope) {
28
-		Function<CodePosition, Expression> dollar = scope.getDollar();
25
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
26
+		DollarEvaluator dollar = scope.getDollar();
29
 		if (dollar == null)
27
 		if (dollar == null)
30
-			return new InvalidExpression(
28
+			throw new CompileException(
31
 					position,
29
 					position,
32
-					scope.hints.isEmpty() ? BasicTypeID.UNDETERMINED.stored : scope.hints.get(0),
33
 					CompileExceptionCode.NO_DOLLAR_HERE,
30
 					CompileExceptionCode.NO_DOLLAR_HERE,
34
 					"No dollar expression available in this context");
31
 					"No dollar expression available in this context");
35
 		
32
 		

+ 2
- 2
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpression.java View File

577
 	 * @param scope
577
 	 * @param scope
578
 	 * @return 
578
 	 * @return 
579
 	 */
579
 	 */
580
-	public abstract IPartialExpression compile(ExpressionScope scope);
580
+	public abstract IPartialExpression compile(ExpressionScope scope) throws CompileException;
581
 
581
 
582
-	public Expression compileKey(ExpressionScope scope) {
582
+	public Expression compileKey(ExpressionScope scope) throws CompileException {
583
 		return compile(scope).eval();
583
 		return compile(scope).eval();
584
 	}
584
 	}
585
 	
585
 	

+ 3
- 3
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionAndAnd.java View File

7
 package org.openzen.zenscript.parser.expression;
7
 package org.openzen.zenscript.parser.expression;
8
 
8
 
9
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
10
 import org.openzen.zencode.shared.CompileExceptionCode;
11
 import org.openzen.zencode.shared.CompileExceptionCode;
11
 import org.openzen.zenscript.codemodel.expression.AndAndExpression;
12
 import org.openzen.zenscript.codemodel.expression.AndAndExpression;
12
 import org.openzen.zenscript.codemodel.expression.Expression;
13
 import org.openzen.zenscript.codemodel.expression.Expression;
13
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
14
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
15
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
15
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
16
 import org.openzen.zenscript.codemodel.type.StoredType;
16
 import org.openzen.zenscript.codemodel.type.StoredType;
34
 	}
34
 	}
35
 
35
 
36
 	@Override
36
 	@Override
37
-	public IPartialExpression compile(ExpressionScope scope) {
37
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
38
 		Expression left = this.left.compile(scope).eval();
38
 		Expression left = this.left.compile(scope).eval();
39
 		Expression right = this.right.compile(scope).eval();
39
 		Expression right = this.right.compile(scope).eval();
40
 		
40
 		
41
 		StoredType resultType = scope.getTypeMembers(left.type).union(right.type);
41
 		StoredType resultType = scope.getTypeMembers(left.type).union(right.type);
42
 		if (resultType == null)
42
 		if (resultType == null)
43
-			return new InvalidExpression(position, CompileExceptionCode.TYPE_CANNOT_UNITE, "These types could not be unified: " + left.type + " and " + right.type);
43
+			throw new CompileException(position, CompileExceptionCode.TYPE_CANNOT_UNITE, "These types could not be unified: " + left.type + " and " + right.type);
44
 		
44
 		
45
 		left = left.castImplicit(position, scope, resultType);
45
 		left = left.castImplicit(position, scope, resultType);
46
 		right = right.castImplicit(position, scope, resultType);
46
 		right = right.castImplicit(position, scope, resultType);

+ 9
- 4
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionArray.java View File

8
 
8
 
9
 import java.util.List;
9
 import java.util.List;
10
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
11
 import org.openzen.zencode.shared.CompileExceptionCode;
12
 import org.openzen.zencode.shared.CompileExceptionCode;
12
 import org.openzen.zenscript.codemodel.expression.ArrayExpression;
13
 import org.openzen.zenscript.codemodel.expression.ArrayExpression;
13
 import org.openzen.zenscript.codemodel.expression.Expression;
14
 import org.openzen.zenscript.codemodel.expression.Expression;
32
 	}
33
 	}
33
 
34
 
34
 	@Override
35
 	@Override
35
-	public IPartialExpression compile(ExpressionScope scope) {
36
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
36
 		StoredType asBaseType = null;
37
 		StoredType asBaseType = null;
37
 		StoredType asType = null;
38
 		StoredType asType = null;
38
 		boolean couldHintType = false;
39
 		boolean couldHintType = false;
55
 			for (int i = 0; i < contents.size(); i++)
56
 			for (int i = 0; i < contents.size(); i++)
56
 				cContents[i] = contents.get(i).compile(contentScope).eval().castImplicit(position, scope, asBaseType);
57
 				cContents[i] = contents.get(i).compile(contentScope).eval().castImplicit(position, scope, asBaseType);
57
 		} else if (contents.isEmpty()) {
58
 		} else if (contents.isEmpty()) {
58
-			return new InvalidExpression(position, CompileExceptionCode.UNTYPED_EMPTY_ARRAY, "Empty array with unknown type");
59
+			throw new CompileException(position, CompileExceptionCode.UNTYPED_EMPTY_ARRAY, "Empty array with unknown type");
59
 		} else {
60
 		} else {
60
 			ExpressionScope contentScope = scope.withoutHints();
61
 			ExpressionScope contentScope = scope.withoutHints();
61
 			StoredType resultType = null;
62
 			StoredType resultType = null;
62
 			for (int i = 0; i < contents.size(); i++) {
63
 			for (int i = 0; i < contents.size(); i++) {
63
 				cContents[i] = contents.get(i).compileKey(contentScope).eval();
64
 				cContents[i] = contents.get(i).compileKey(contentScope).eval();
64
-				resultType = resultType == null ? cContents[i].type : scope.getTypeMembers(resultType).union(cContents[i].type);
65
+				StoredType joinedType = resultType == null ? cContents[i].type : scope.getTypeMembers(resultType).union(cContents[i].type);
66
+				if (joinedType == null)
67
+					throw new CompileException(position, CompileExceptionCode.TYPE_CANNOT_UNITE, "Could not combine " + resultType + " with " + cContents[i].type);
68
+				
69
+				resultType = joinedType;
65
 			}
70
 			}
66
 			for (int i = 0; i < contents.size(); i++)
71
 			for (int i = 0; i < contents.size(); i++)
67
 				cContents[i] = cContents[i].castImplicit(position, scope, resultType);
72
 				cContents[i] = cContents[i].castImplicit(position, scope, resultType);
71
 	}
76
 	}
72
 
77
 
73
 	@Override
78
 	@Override
74
-	public Expression compileKey(ExpressionScope scope) {
79
+	public Expression compileKey(ExpressionScope scope) throws CompileException {
75
 		if (contents.size() == 1) {
80
 		if (contents.size() == 1) {
76
 			return contents.get(0).compile(scope).eval();
81
 			return contents.get(0).compile(scope).eval();
77
 		} else {
82
 		} else {

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

8
 
8
 
9
 import java.util.List;
9
 import java.util.List;
10
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
14
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
29
 	}
30
 	}
30
 
31
 
31
 	@Override
32
 	@Override
32
-	public IPartialExpression compile(ExpressionScope scope) {
33
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
33
 		IPartialExpression cLeft = left.compile(scope);
34
 		IPartialExpression cLeft = left.compile(scope);
34
 		List<StoredType> resultHints = cLeft.getAssignHints();
35
 		List<StoredType> resultHints = cLeft.getAssignHints();
35
 		
36
 		

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

7
 package org.openzen.zenscript.parser.expression;
7
 package org.openzen.zenscript.parser.expression;
8
 
8
 
9
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
10
 import org.openzen.zenscript.codemodel.OperatorType;
11
 import org.openzen.zenscript.codemodel.OperatorType;
11
 import org.openzen.zenscript.codemodel.expression.CallArguments;
12
 import org.openzen.zenscript.codemodel.expression.CallArguments;
12
 import org.openzen.zenscript.codemodel.expression.Expression;
13
 import org.openzen.zenscript.codemodel.expression.Expression;
32
 	}
33
 	}
33
 
34
 
34
 	@Override
35
 	@Override
35
-	public IPartialExpression compile(ExpressionScope scope) {
36
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
36
 		Expression cLeft = left.compile(scope).eval();
37
 		Expression cLeft = left.compile(scope).eval();
37
 		TypeMemberGroup members = scope.getTypeMembers(cLeft.type).getOrCreateGroup(this.operator);
38
 		TypeMemberGroup members = scope.getTypeMembers(cLeft.type).getOrCreateGroup(this.operator);
38
 		ExpressionScope innerScope = scope.withHints(members.predictCallTypes(scope, scope.getResultTypeHints(), 1)[0]);
39
 		ExpressionScope innerScope = scope.withHints(members.predictCallTypes(scope, scope.getResultTypeHints(), 1)[0]);

+ 3
- 3
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionBracket.java View File

8
 import java.util.ArrayList;
8
 import java.util.ArrayList;
9
 import java.util.List;
9
 import java.util.List;
10
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
11
 import org.openzen.zencode.shared.CompileExceptionCode;
12
 import org.openzen.zencode.shared.CompileExceptionCode;
12
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
14
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
15
 import org.openzen.zenscript.lexer.ParseException;
15
 import org.openzen.zenscript.lexer.ParseException;
31
 	}
31
 	}
32
 	
32
 	
33
 	@Override
33
 	@Override
34
-	public IPartialExpression compile(ExpressionScope scope) {
34
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
35
 		if (expressions.size() != 1) {
35
 		if (expressions.size() != 1) {
36
-			return new InvalidExpression(position, CompileExceptionCode.BRACKET_MULTIPLE_EXPRESSIONS, "Bracket expression may have only one expression");
36
+			throw new CompileException(position, CompileExceptionCode.BRACKET_MULTIPLE_EXPRESSIONS, "Bracket expression may have only one expression");
37
 		} else {
37
 		} else {
38
 			return expressions.get(0).compile(scope);
38
 			return expressions.get(0).compile(scope);
39
 		}
39
 		}

+ 26
- 30
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCall.java View File

46
 	}
46
 	}
47
 
47
 
48
 	@Override
48
 	@Override
49
-	public IPartialExpression compile(ExpressionScope scope) {
49
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
50
 		if (receiver instanceof ParsedExpressionVariable) {
50
 		if (receiver instanceof ParsedExpressionVariable) {
51
 			ParsedExpressionVariable variable = (ParsedExpressionVariable) receiver;
51
 			ParsedExpressionVariable variable = (ParsedExpressionVariable) receiver;
52
 			for (StoredType hint : scope.hints) {
52
 			for (StoredType hint : scope.hints) {
64
 			}
64
 			}
65
 		}
65
 		}
66
 		
66
 		
67
-		try {
68
-			if (receiver instanceof ParsedExpressionSuper) {
69
-				// super call (intended as first call in constructor)
70
-				StoredType targetType = scope.getThisType().getSuperType(scope.getTypeRegistry());
71
-				if (targetType == null)
72
-					return new InvalidExpression(position, CompileExceptionCode.SUPER_CALL_NO_SUPERCLASS, "Class has no superclass");
67
+		if (receiver instanceof ParsedExpressionSuper) {
68
+			// super call (intended as first call in constructor)
69
+			StoredType targetType = scope.getThisType().getSuperType(scope.getTypeRegistry());
70
+			if (targetType == null)
71
+				throw new CompileException(position, CompileExceptionCode.SUPER_CALL_NO_SUPERCLASS, "Class has no superclass");
73
 
72
 
74
-				TypeMemberGroup memberGroup = scope.getTypeMembers(targetType).getOrCreateGroup(OperatorType.CONSTRUCTOR);
75
-				CallArguments callArguments = arguments.compileCall(position, scope, null, memberGroup);
76
-				FunctionalMemberRef member = memberGroup.selectMethod(position, scope, callArguments, true, true);
77
-				if (!member.isConstructor())
78
-					return new InvalidExpression(position, CompileExceptionCode.INTERNAL_ERROR, "Constructor is not a constructor!");
73
+			TypeMemberGroup memberGroup = scope.getTypeMembers(targetType).getOrCreateGroup(OperatorType.CONSTRUCTOR);
74
+			CallArguments callArguments = arguments.compileCall(position, scope, null, memberGroup);
75
+			FunctionalMemberRef member = memberGroup.selectMethod(position, scope, callArguments, true, true);
76
+			if (!member.isConstructor())
77
+				throw new CompileException(position, CompileExceptionCode.INTERNAL_ERROR, "Constructor is not a constructor!");
79
 
78
 
80
-				return new ConstructorSuperCallExpression(position, targetType, member, callArguments);
81
-			} else if (receiver instanceof ParsedExpressionThis) {
82
-				// this call (intended as first call in constructor)
83
-				StoredType targetType = scope.getThisType();
79
+			return new ConstructorSuperCallExpression(position, targetType, member, callArguments);
80
+		} else if (receiver instanceof ParsedExpressionThis) {
81
+			// this call (intended as first call in constructor)
82
+			StoredType targetType = scope.getThisType();
84
 
83
 
85
-				TypeMemberGroup memberGroup = scope.getTypeMembers(targetType).getOrCreateGroup(OperatorType.CONSTRUCTOR);
86
-				CallArguments callArguments = arguments.compileCall(position, scope, null, memberGroup);
87
-				FunctionalMemberRef member = memberGroup.selectMethod(position, scope, callArguments, true, true);
88
-				if (!member.isConstructor())
89
-					return new InvalidExpression(position, CompileExceptionCode.INTERNAL_ERROR, "Constructor is not a constructor!");
84
+			TypeMemberGroup memberGroup = scope.getTypeMembers(targetType).getOrCreateGroup(OperatorType.CONSTRUCTOR);
85
+			CallArguments callArguments = arguments.compileCall(position, scope, null, memberGroup);
86
+			FunctionalMemberRef member = memberGroup.selectMethod(position, scope, callArguments, true, true);
87
+			if (!member.isConstructor())
88
+				throw new CompileException(position, CompileExceptionCode.INTERNAL_ERROR, "Constructor is not a constructor!");
90
 
89
 
91
-				return new ConstructorThisCallExpression(position, scope.getThisType(), member, callArguments);
92
-			}
93
-
94
-			IPartialExpression cReceiver = receiver.compile(scope.withoutHints());
95
-			List<FunctionHeader> headers = cReceiver.getPossibleFunctionHeaders(scope, scope.hints, arguments.arguments.size());
96
-			CallArguments callArguments = arguments.compileCall(position, scope, cReceiver.getGenericCallTypes(), headers);
97
-			return cReceiver.call(position, scope, scope.hints, callArguments);
98
-		} catch (CompileException ex) {
99
-			return new InvalidExpression(BasicTypeID.UNDETERMINED.stored, ex);
90
+			return new ConstructorThisCallExpression(position, scope.getThisType(), member, callArguments);
100
 		}
91
 		}
92
+
93
+		IPartialExpression cReceiver = receiver.compile(scope.withoutHints());
94
+		List<FunctionHeader> headers = cReceiver.getPossibleFunctionHeaders(scope, scope.hints, arguments.arguments.size());
95
+		CallArguments callArguments = arguments.compileCall(position, scope, cReceiver.getGenericCallTypes(), headers);
96
+		return cReceiver.call(position, scope, scope.hints, callArguments);
101
 	}
97
 	}
102
 	
98
 	
103
 	@Override
99
 	@Override

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

7
 package org.openzen.zenscript.parser.expression;
7
 package org.openzen.zenscript.parser.expression;
8
 
8
 
9
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
10
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
11
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
11
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
12
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
12
 import org.openzen.zenscript.codemodel.type.StoredType;
13
 import org.openzen.zenscript.codemodel.type.StoredType;
35
 	}
36
 	}
36
 
37
 
37
 	@Override
38
 	@Override
38
-	public IPartialExpression compile(ExpressionScope scope) {
39
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
39
 		StoredType type = this.type.compile(scope);
40
 		StoredType type = this.type.compile(scope);
40
 		return value.compile(scope.withHint(type))
41
 		return value.compile(scope.withHint(type))
41
 				.eval()
42
 				.eval()

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCoalesce.java View File

32
 	}
32
 	}
33
 
33
 
34
 	@Override
34
 	@Override
35
-	public IPartialExpression compile(ExpressionScope scope) {
35
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
36
 		Expression cLeft = left.compile(scope).eval();
36
 		Expression cLeft = left.compile(scope).eval();
37
 		StoredType cLeftType = cLeft.type;
37
 		StoredType cLeftType = cLeft.type;
38
 		if (!cLeftType.isOptional())
38
 		if (!cLeftType.isOptional())

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

7
 package org.openzen.zenscript.parser.expression;
7
 package org.openzen.zenscript.parser.expression;
8
 
8
 
9
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
10
 import org.openzen.zenscript.codemodel.CompareType;
11
 import org.openzen.zenscript.codemodel.CompareType;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
34
 	}
35
 	}
35
 
36
 
36
 	@Override
37
 	@Override
37
-	public IPartialExpression compile(ExpressionScope scope) {
38
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
38
 		Expression cLeft = left.compile(scope.withoutHints()).eval();
39
 		Expression cLeft = left.compile(scope.withoutHints()).eval();
39
 		Expression cRight = right.compile(scope.withHint(cLeft.type)).eval();
40
 		Expression cRight = right.compile(scope.withHint(cLeft.type)).eval();
40
 		return scope.getTypeMembers(cLeft.type).compare(position, scope, type, cLeft, cRight);
41
 		return scope.getTypeMembers(cLeft.type).compare(position, scope, type, cLeft, cRight);

+ 4
- 4
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionConditional.java View File

7
 package org.openzen.zenscript.parser.expression;
7
 package org.openzen.zenscript.parser.expression;
8
 
8
 
9
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
10
 import org.openzen.zencode.shared.CompileExceptionCode;
11
 import org.openzen.zencode.shared.CompileExceptionCode;
11
 import org.openzen.zenscript.codemodel.expression.ConditionalExpression;
12
 import org.openzen.zenscript.codemodel.expression.ConditionalExpression;
12
 import org.openzen.zenscript.codemodel.expression.Expression;
13
 import org.openzen.zenscript.codemodel.expression.Expression;
13
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
14
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
15
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
15
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
16
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
16
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
35
 	}
35
 	}
36
 
36
 
37
 	@Override
37
 	@Override
38
-	public IPartialExpression compile(ExpressionScope scope) {
38
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
39
 		Expression cIfThen = ifThen.compile(scope).eval();
39
 		Expression cIfThen = ifThen.compile(scope).eval();
40
 		Expression cIfElse = ifElse.compile(scope).eval();
40
 		Expression cIfElse = ifElse.compile(scope).eval();
41
 		
41
 		
45
 		for (StoredType hint : scope.hints) {
45
 		for (StoredType hint : scope.hints) {
46
 			if (thenMembers.canCastImplicit(hint) && elseMembers.canCastImplicit(hint)) {
46
 			if (thenMembers.canCastImplicit(hint) && elseMembers.canCastImplicit(hint)) {
47
 				if (resultType != null)
47
 				if (resultType != null)
48
-					return new InvalidExpression(position, CompileExceptionCode.MULTIPLE_MATCHING_HINTS, "Not sure which type to use");
48
+					throw new CompileException(position, CompileExceptionCode.MULTIPLE_MATCHING_HINTS, "Not sure which type to use");
49
 				
49
 				
50
 				resultType = hint;
50
 				resultType = hint;
51
 			}
51
 			}
55
 			resultType = thenMembers.union(cIfElse.type);
55
 			resultType = thenMembers.union(cIfElse.type);
56
 		
56
 		
57
 		if (resultType == null)
57
 		if (resultType == null)
58
-			return new InvalidExpression(position, CompileExceptionCode.TYPE_CANNOT_UNITE, "These types could not be unified: " + cIfThen.type + " and " + cIfElse.type);
58
+			throw new CompileException(position, CompileExceptionCode.TYPE_CANNOT_UNITE, "These types could not be unified: " + cIfThen.type + " and " + cIfElse.type);
59
 		
59
 		
60
 		cIfThen = cIfThen.castImplicit(position, scope, resultType);
60
 		cIfThen = cIfThen.castImplicit(position, scope, resultType);
61
 		cIfElse = cIfElse.castImplicit(position, scope, resultType);
61
 		cIfElse = cIfElse.castImplicit(position, scope, resultType);

+ 3
- 3
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionFloat.java View File

48
 	}
48
 	}
49
 
49
 
50
 	@Override
50
 	@Override
51
-	public IPartialExpression compile(ExpressionScope scope) {
51
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
52
 		if (scope.hints.isEmpty())
52
 		if (scope.hints.isEmpty())
53
 			return new ConstantDoubleExpression(position, value);
53
 			return new ConstantDoubleExpression(position, value);
54
 		
54
 		
87
 				types.append(scope.hints.get(i).toString());
87
 				types.append(scope.hints.get(i).toString());
88
 			}
88
 			}
89
 
89
 
90
-			return new InvalidExpression(position, CompileExceptionCode.INVALID_CAST, "Cannot cast a floating-point value to any of these types: " + types);
90
+			throw new CompileException(position, CompileExceptionCode.INVALID_CAST, "Cannot cast a floating-point value to any of these types: " + types);
91
 		} else {
91
 		} else {
92
-			return new InvalidExpression(position, CompileExceptionCode.INVALID_SUFFIX, "Invalid suffix: " + suffix);
92
+			throw new CompileException(position, CompileExceptionCode.INVALID_SUFFIX, "Invalid suffix: " + suffix);
93
 		}
93
 		}
94
 	}
94
 	}
95
 
95
 

+ 10
- 6
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionFunction.java View File

8
 
8
 
9
 import java.util.Map;
9
 import java.util.Map;
10
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
11
 import org.openzen.zencode.shared.CompileExceptionCode;
12
 import org.openzen.zencode.shared.CompileExceptionCode;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
 import org.openzen.zenscript.codemodel.GenericMapper;
14
 import org.openzen.zenscript.codemodel.GenericMapper;
25
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
26
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
26
 import org.openzen.zenscript.codemodel.type.StoredType;
27
 import org.openzen.zenscript.codemodel.type.StoredType;
27
 import org.openzen.zenscript.codemodel.type.TypeID;
28
 import org.openzen.zenscript.codemodel.type.TypeID;
28
-import org.openzen.zenscript.codemodel.type.storage.UniqueStorageTag;
29
+import org.openzen.zenscript.codemodel.type.storage.SharedStorageTag;
30
+import org.openzen.zenscript.codemodel.type.storage.StorageTag;
29
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
31
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
30
 import org.openzen.zenscript.parser.statements.ParsedFunctionBody;
32
 import org.openzen.zenscript.parser.statements.ParsedFunctionBody;
31
 
33
 
45
 	}
47
 	}
46
 
48
 
47
 	@Override
49
 	@Override
48
-	public IPartialExpression compile(ExpressionScope scope) {
50
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
49
 		FunctionHeader definedHeader = header.compile(scope);
51
 		FunctionHeader definedHeader = header.compile(scope);
50
 		FunctionHeader header = definedHeader;
52
 		FunctionHeader header = definedHeader;
53
+		StorageTag storage = SharedStorageTag.INSTANCE;
51
 		for (StoredType hint : scope.hints) {
54
 		for (StoredType hint : scope.hints) {
52
 			if (hint.getNormalized().type instanceof FunctionTypeID) {
55
 			if (hint.getNormalized().type instanceof FunctionTypeID) {
53
 				FunctionTypeID functionHint = (FunctionTypeID) hint.getNormalized().type;
56
 				FunctionTypeID functionHint = (FunctionTypeID) hint.getNormalized().type;
56
 						return new InvalidExpression(position, hint, CompileExceptionCode.MULTIPLE_MATCHING_HINTS, "Ambiguity trying to resolve function types, can't decide for the type");
59
 						return new InvalidExpression(position, hint, CompileExceptionCode.MULTIPLE_MATCHING_HINTS, "Ambiguity trying to resolve function types, can't decide for the type");
57
 					
60
 					
58
 					header = functionHint.header.forLambda(definedHeader);
61
 					header = functionHint.header.forLambda(definedHeader);
62
+					storage = hint.storage;
59
 				}
63
 				}
60
 			}
64
 			}
61
 		}
65
 		}
70
 		StatementScope innerScope = new LambdaScope(scope, closure, header);
74
 		StatementScope innerScope = new LambdaScope(scope, closure, header);
71
 		Statement statements = body.compile(innerScope, header);
75
 		Statement statements = body.compile(innerScope, header);
72
 		
76
 		
73
-		if (header.getReturnType().isBasic(BasicTypeID.UNDETERMINED)) {
77
+		if (header.getReturnType().isBasic(BasicTypeID.UNDETERMINED))
74
 			header.setReturnType(statements.getReturnType());
78
 			header.setReturnType(statements.getReturnType());
75
-		}
79
+		
76
 		if (!scope.genericInferenceMap.isEmpty()) {
80
 		if (!scope.genericInferenceMap.isEmpty()) {
77
 			// perform type parameter inference
81
 			// perform type parameter inference
78
 			StoredType returnType = statements.getReturnType();
82
 			StoredType returnType = statements.getReturnType();
79
 			Map<TypeParameter, TypeID> inferredTypes = returnType.type.inferTypeParameters(scope.getMemberCache(), genericHeader.getReturnType().type);
83
 			Map<TypeParameter, TypeID> inferredTypes = returnType.type.inferTypeParameters(scope.getMemberCache(), genericHeader.getReturnType().type);
80
 			if (inferredTypes == null)
84
 			if (inferredTypes == null)
81
-				return new InvalidExpression(position, CompileExceptionCode.TYPE_ARGUMENTS_NOT_INFERRABLE, "Could not infer generic type parameters");
85
+				throw new CompileException(position, CompileExceptionCode.TYPE_ARGUMENTS_NOT_INFERRABLE, "Could not infer generic type parameters");
82
 			
86
 			
83
 			scope.genericInferenceMap.putAll(inferredTypes);
87
 			scope.genericInferenceMap.putAll(inferredTypes);
84
 		}
88
 		}
85
 		
89
 		
86
 		StoredType functionType = scope.getTypeRegistry()
90
 		StoredType functionType = scope.getTypeRegistry()
87
 				.getFunction(genericHeader.withGenericArguments(scope.getTypeRegistry(), new GenericMapper(scope.getTypeRegistry(), scope.genericInferenceMap)))
91
 				.getFunction(genericHeader.withGenericArguments(scope.getTypeRegistry(), new GenericMapper(scope.getTypeRegistry(), scope.genericInferenceMap)))
88
-				.stored(UniqueStorageTag.INSTANCE);
92
+				.stored(storage);
89
 		return new FunctionExpression(position, functionType, closure, header, statements);
93
 		return new FunctionExpression(position, functionType, closure, header, statements);
90
 	}
94
 	}
91
 	
95
 	

+ 10
- 9
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionIndex.java View File

8
 
8
 
9
 import java.util.List;
9
 import java.util.List;
10
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
11
 import org.openzen.zenscript.codemodel.FunctionHeader;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
12
 import org.openzen.zenscript.codemodel.OperatorType;
13
 import org.openzen.zenscript.codemodel.OperatorType;
13
 import org.openzen.zenscript.codemodel.expression.CallArguments;
14
 import org.openzen.zenscript.codemodel.expression.CallArguments;
36
 	}
37
 	}
37
 
38
 
38
 	@Override
39
 	@Override
39
-	public IPartialExpression compile(ExpressionScope scope) {
40
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
40
 		return new PartialIndexedExpression(scope);
41
 		return new PartialIndexedExpression(scope);
41
 	}
42
 	}
42
 
43
 
49
 		private final ExpressionScope scope;
50
 		private final ExpressionScope scope;
50
 		private final Expression target;
51
 		private final Expression target;
51
 		
52
 		
52
-		private PartialIndexedExpression(ExpressionScope scope) {
53
+		private PartialIndexedExpression(ExpressionScope scope) throws CompileException {
53
 			this.scope = scope;
54
 			this.scope = scope;
54
 			target = value.compile(scope.withoutHints()).eval();
55
 			target = value.compile(scope.withoutHints()).eval();
55
 		}
56
 		}
56
 		
57
 		
57
 		@Override
58
 		@Override
58
-		public Expression eval() {
59
+		public Expression eval() throws CompileException {
59
 			TypeMemberGroup members = scope.getTypeMembers(target.type).getOrCreateGroup(OperatorType.INDEXGET);
60
 			TypeMemberGroup members = scope.getTypeMembers(target.type).getOrCreateGroup(OperatorType.INDEXGET);
60
 			List<StoredType>[] predictedTypes = members.predictCallTypes(scope, scope.hints, indexes.size());
61
 			List<StoredType>[] predictedTypes = members.predictCallTypes(scope, scope.hints, indexes.size());
61
 			Expression[] arguments = new Expression[indexes.size()];
62
 			Expression[] arguments = new Expression[indexes.size()];
66
 		}
67
 		}
67
 
68
 
68
 		@Override
69
 		@Override
69
-		public List<StoredType>[] predictCallTypes(TypeScope scope, List<StoredType> hints, int arguments) {
70
+		public List<StoredType>[] predictCallTypes(TypeScope scope, List<StoredType> hints, int arguments) throws CompileException {
70
 			return eval().predictCallTypes(scope, hints, arguments);
71
 			return eval().predictCallTypes(scope, hints, arguments);
71
 		}
72
 		}
72
 		
73
 		
73
 		@Override
74
 		@Override
74
-		public List<FunctionHeader> getPossibleFunctionHeaders(TypeScope scope, List<StoredType> hints, int arguments) {
75
+		public List<FunctionHeader> getPossibleFunctionHeaders(TypeScope scope, List<StoredType> hints, int arguments) throws CompileException {
75
 			return eval().getPossibleFunctionHeaders(scope, hints, arguments);
76
 			return eval().getPossibleFunctionHeaders(scope, hints, arguments);
76
 		}
77
 		}
77
 
78
 
78
 		@Override
79
 		@Override
79
-		public IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) {
80
+		public IPartialExpression getMember(CodePosition position, TypeScope scope, List<StoredType> hints, GenericName name) throws CompileException {
80
 			return eval().getMember(position, scope, hints, name);
81
 			return eval().getMember(position, scope, hints, name);
81
 		}
82
 		}
82
 
83
 
83
 		@Override
84
 		@Override
84
-		public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) {
85
+		public Expression call(CodePosition position, TypeScope scope, List<StoredType> hints, CallArguments arguments) throws CompileException {
85
 			return eval().call(position, scope, hints, arguments);
86
 			return eval().call(position, scope, hints, arguments);
86
 		}
87
 		}
87
 		
88
 		
88
 		@Override
89
 		@Override
89
-		public Expression assign(CodePosition position, TypeScope scope, Expression value) {
90
+		public Expression assign(CodePosition position, TypeScope scope, Expression value) throws CompileException {
90
 			TypeMemberGroup members = scope.getTypeMembers(target.type).getOrCreateGroup(OperatorType.INDEXSET);
91
 			TypeMemberGroup members = scope.getTypeMembers(target.type).getOrCreateGroup(OperatorType.INDEXSET);
91
 			List<StoredType>[] predictedTypes = members.predictCallTypes(scope, this.scope.hints, indexes.size() + 1);
92
 			List<StoredType>[] predictedTypes = members.predictCallTypes(scope, this.scope.hints, indexes.size() + 1);
92
 			
93
 			
105
 			return predictedTypes[indexes.size()];
106
 			return predictedTypes[indexes.size()];
106
 		}
107
 		}
107
 		
108
 		
108
-		private Expression getLength(CodePosition position) {
109
+		private Expression getLength(CodePosition position) throws CompileException {
109
 			return target.getMember(position, scope, scope.hints, new GenericName("length")).eval();
110
 			return target.getMember(position, scope, scope.hints, new GenericName("length")).eval();
110
 		}
111
 		}
111
 
112
 

+ 2
- 2
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionInt.java View File

110
 	}
110
 	}
111
 	
111
 	
112
 	@Override
112
 	@Override
113
-	public Expression compile(ExpressionScope scope) {
113
+	public Expression compile(ExpressionScope scope) throws CompileException {
114
 		if (suffix.equals("L") || suffix.equals("l"))
114
 		if (suffix.equals("L") || suffix.equals("l"))
115
 			return new ConstantLongExpression(position, value);
115
 			return new ConstantLongExpression(position, value);
116
 		if (suffix.equals("UL") || suffix.equals("ul"))
116
 		if (suffix.equals("UL") || suffix.equals("ul"))
182
 			else
182
 			else
183
 				return new ConstantLongExpression(position, value);
183
 				return new ConstantLongExpression(position, value);
184
 		} else {
184
 		} else {
185
-			return new InvalidExpression(position, CompileExceptionCode.INVALID_SUFFIX, "Invalid suffix: " + suffix);
185
+			throw new CompileException(position, CompileExceptionCode.INVALID_SUFFIX, "Invalid suffix: " + suffix);
186
 		}
186
 		}
187
 	}
187
 	}
188
 	
188
 	

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

6
 package org.openzen.zenscript.parser.expression;
6
 package org.openzen.zenscript.parser.expression;
7
 
7
 
8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
9
 import org.openzen.zenscript.codemodel.expression.Expression;
10
 import org.openzen.zenscript.codemodel.expression.Expression;
10
 import org.openzen.zenscript.codemodel.expression.IsExpression;
11
 import org.openzen.zenscript.codemodel.expression.IsExpression;
11
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
30
 	}
31
 	}
31
 
32
 
32
 	@Override
33
 	@Override
33
-	public IPartialExpression compile(ExpressionScope scope) {
34
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
34
 		TypeID isType = type.compileUnstored(scope);
35
 		TypeID isType = type.compileUnstored(scope);
35
 		Expression expression = this.expression.compile(scope.withHint(isType.stored(BorrowStorageTag.INVOCATION))).eval();
36
 		Expression expression = this.expression.compile(scope.withHint(isType.stored(BorrowStorageTag.INVOCATION))).eval();
36
 		return new IsExpression(position, expression, isType);
37
 		return new IsExpression(position, expression, isType);

+ 10
- 14
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionMap.java View File

44
 	}
44
 	}
45
 
45
 
46
 	@Override
46
 	@Override
47
-	public IPartialExpression compile(ExpressionScope scope) {
47
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
48
 		StoredType usedHint = null;
48
 		StoredType usedHint = null;
49
 		List<StoredType> keyHints = new ArrayList<>();
49
 		List<StoredType> keyHints = new ArrayList<>();
50
 		List<StoredType> valueHints = new ArrayList<>();
50
 		List<StoredType> valueHints = new ArrayList<>();
74
 		}
74
 		}
75
 		
75
 		
76
 		if (keys.isEmpty() && keyHints.size() == 1) {
76
 		if (keys.isEmpty() && keyHints.size() == 1) {
77
-			try {
78
-				FunctionalMemberRef constructor = scope
79
-							.getTypeMembers(usedHint)
80
-							.getOrCreateGroup(OperatorType.CONSTRUCTOR)
81
-							.selectMethod(position, scope, CallArguments.EMPTY, true, true);
82
-					return new NewExpression(position, usedHint, constructor, CallArguments.EMPTY);
83
-			} catch (CompileException ex) {
84
-				return new InvalidExpression(ex.position, ex.code, ex.getMessage());
85
-			}
77
+			FunctionalMemberRef constructor = scope
78
+					.getTypeMembers(usedHint)
79
+					.getOrCreateGroup(OperatorType.CONSTRUCTOR)
80
+					.selectMethod(position, scope, CallArguments.EMPTY, true, true);
81
+			return new NewExpression(position, usedHint, constructor, CallArguments.EMPTY);
86
 		}
82
 		}
87
 		
83
 		
88
 		if (!hasAssocHint && scope.hints.size() == 1) {
84
 		if (!hasAssocHint && scope.hints.size() == 1) {
90
 			StoredType hint = scope.hints.get(0);
86
 			StoredType hint = scope.hints.get(0);
91
 			for (int i = 0; i < keys.size(); i++) {
87
 			for (int i = 0; i < keys.size(); i++) {
92
 				if (keys.get(i) != null)
88
 				if (keys.get(i) != null)
93
-					return new InvalidExpression(position, CompileExceptionCode.UNSUPPORTED_NAMED_ARGUMENTS, "Named constructor arguments not yet supported");
89
+					throw new CompileException(position, CompileExceptionCode.UNSUPPORTED_NAMED_ARGUMENTS, "Named constructor arguments not yet supported");
94
 			}
90
 			}
95
 			ParsedCallArguments arguments = new ParsedCallArguments(null, values);
91
 			ParsedCallArguments arguments = new ParsedCallArguments(null, values);
96
 			return ParsedNewExpression.compile(position, hint, arguments, scope);
92
 			return ParsedNewExpression.compile(position, hint, arguments, scope);
101
 
97
 
102
 		for (int i = 0; i < keys.size(); i++) {
98
 		for (int i = 0; i < keys.size(); i++) {
103
 			if (keys.get(i) == null)
99
 			if (keys.get(i) == null)
104
-				return new InvalidExpression(position, CompileExceptionCode.MISSING_MAP_KEY, "Missing key");
100
+				throw new CompileException(position, CompileExceptionCode.MISSING_MAP_KEY, "Missing key");
105
 			
101
 			
106
 			cKeys[i] = keys.get(i).compileKey(scope.withHints(keyHints));
102
 			cKeys[i] = keys.get(i).compileKey(scope.withHints(keyHints));
107
 			cValues[i] = values.get(i).compile(scope.withHints(valueHints)).eval();
103
 			cValues[i] = values.get(i).compile(scope.withHints(valueHints)).eval();
119
 			}
115
 			}
120
 		}
116
 		}
121
 		if (keyType == null)
117
 		if (keyType == null)
122
-			return new InvalidExpression(position, CompileExceptionCode.UNTYPED_EMPTY_MAP, "Empty map without known type");
118
+			throw new CompileException(position, CompileExceptionCode.UNTYPED_EMPTY_MAP, "Empty map without known type");
123
 		
119
 		
124
 		for (int i = 0; i < cKeys.length; i++)
120
 		for (int i = 0; i < cKeys.length; i++)
125
 			cKeys[i] = cKeys[i].castImplicit(position, scope, keyType);
121
 			cKeys[i] = cKeys[i].castImplicit(position, scope, keyType);
136
 			}
132
 			}
137
 		}
133
 		}
138
 		if (valueType == null)
134
 		if (valueType == null)
139
-			return new InvalidExpression(position, CompileExceptionCode.UNTYPED_EMPTY_MAP, "Empty map without known type");
135
+			throw new CompileException(position, CompileExceptionCode.UNTYPED_EMPTY_MAP, "Empty map without known type");
140
 		
136
 		
141
 		for (int i = 0; i < cValues.length; i++)
137
 		for (int i = 0; i < cValues.length; i++)
142
 			cValues[i] = cValues[i].castImplicit(position, scope, valueType);
138
 			cValues[i] = cValues[i].castImplicit(position, scope, valueType);

+ 3
- 3
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionMember.java View File

8
 
8
 
9
 import java.util.List;
9
 import java.util.List;
10
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
11
 import org.openzen.zencode.shared.CompileExceptionCode;
12
 import org.openzen.zencode.shared.CompileExceptionCode;
12
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14
 import org.openzen.zenscript.codemodel.type.GenericName;
14
 import org.openzen.zenscript.codemodel.type.GenericName;
15
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
15
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
34
 	}
34
 	}
35
 
35
 
36
 	@Override
36
 	@Override
37
-	public IPartialExpression compile(ExpressionScope scope) {
37
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
38
 		IPartialExpression cValue = value.compile(scope.withoutHints());
38
 		IPartialExpression cValue = value.compile(scope.withoutHints());
39
 		TypeID[] typeParameters = IParsedType.compileList(genericParameters, scope);
39
 		TypeID[] typeParameters = IParsedType.compileList(genericParameters, scope);
40
 		IPartialExpression member = cValue.getMember(
40
 		IPartialExpression member = cValue.getMember(
43
 				scope.hints,
43
 				scope.hints,
44
 				new GenericName(this.member, typeParameters));
44
 				new GenericName(this.member, typeParameters));
45
 		if (member == null)
45
 		if (member == null)
46
-			return new InvalidExpression(position, CompileExceptionCode.NO_SUCH_MEMBER, "Member not found: " + this.member);
46
+			throw new CompileException(position, CompileExceptionCode.NO_SUCH_MEMBER, "Member not found: " + this.member);
47
 		
47
 		
48
 		return member;
48
 		return member;
49
 	}
49
 	}

+ 2
- 2
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionOpAssign.java View File

7
 package org.openzen.zenscript.parser.expression;
7
 package org.openzen.zenscript.parser.expression;
8
 
8
 
9
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
10
 import org.openzen.zenscript.codemodel.OperatorType;
11
 import org.openzen.zenscript.codemodel.OperatorType;
11
 import org.openzen.zenscript.codemodel.expression.CallArguments;
12
 import org.openzen.zenscript.codemodel.expression.CallArguments;
12
 import org.openzen.zenscript.codemodel.expression.Expression;
13
 import org.openzen.zenscript.codemodel.expression.Expression;
14
 import org.openzen.zenscript.codemodel.type.member.TypeMemberGroup;
15
 import org.openzen.zenscript.codemodel.type.member.TypeMemberGroup;
15
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
16
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
16
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
17
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
17
-import org.openzen.zenscript.parser.PrecompilationState;
18
 
18
 
19
 /**
19
 /**
20
  *
20
  *
34
 	}
34
 	}
35
 
35
 
36
 	@Override
36
 	@Override
37
-	public IPartialExpression compile(ExpressionScope scope) {
37
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
38
 		Expression cLeft = left.compile(scope).eval();
38
 		Expression cLeft = left.compile(scope).eval();
39
 		TypeMembers typeMembers = scope.getTypeMembers(cLeft.type);
39
 		TypeMembers typeMembers = scope.getTypeMembers(cLeft.type);
40
 		TypeMemberGroup members = typeMembers.getOrCreateGroup(operator);
40
 		TypeMemberGroup members = typeMembers.getOrCreateGroup(operator);

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

7
 package org.openzen.zenscript.parser.expression;
7
 package org.openzen.zenscript.parser.expression;
8
 
8
 
9
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
10
 import org.openzen.zenscript.codemodel.expression.Expression;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
11
 import org.openzen.zenscript.codemodel.expression.OrOrExpression;
12
 import org.openzen.zenscript.codemodel.expression.OrOrExpression;
12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
29
 	}
30
 	}
30
 
31
 
31
 	@Override
32
 	@Override
32
-	public IPartialExpression compile(ExpressionScope scope) {
33
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
33
 		Expression cLeft = left.compile(scope.withHints(BasicTypeID.HINT_BOOL)).eval().castImplicit(position, scope, BasicTypeID.BOOL.stored);
34
 		Expression cLeft = left.compile(scope.withHints(BasicTypeID.HINT_BOOL)).eval().castImplicit(position, scope, BasicTypeID.BOOL.stored);
34
 		Expression cRight = right.compile(scope.withHints(BasicTypeID.HINT_BOOL)).eval().castImplicit(position, scope, BasicTypeID.BOOL.stored);
35
 		Expression cRight = right.compile(scope.withHints(BasicTypeID.HINT_BOOL)).eval().castImplicit(position, scope, BasicTypeID.BOOL.stored);
35
 		return new OrOrExpression(position, cLeft, cRight);
36
 		return new OrOrExpression(position, cLeft, cRight);

+ 3
- 3
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionOuter.java View File

6
 package org.openzen.zenscript.parser.expression;
6
 package org.openzen.zenscript.parser.expression;
7
 
7
 
8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
9
 import org.openzen.zencode.shared.CompileExceptionCode;
10
 import org.openzen.zencode.shared.CompileExceptionCode;
10
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
11
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
11
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
12
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
12
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
13
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
13
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
27
 	}
27
 	}
28
 
28
 
29
 	@Override
29
 	@Override
30
-	public IPartialExpression compile(ExpressionScope scope) {
30
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
31
 		StoredType thisType = scope.getThisType();
31
 		StoredType thisType = scope.getThisType();
32
 		if (thisType == null || !(thisType.type instanceof DefinitionTypeID))
32
 		if (thisType == null || !(thisType.type instanceof DefinitionTypeID))
33
-			return new InvalidExpression(position, CompileExceptionCode.USING_THIS_OUTSIDE_TYPE, "Not in a type");
33
+			throw new CompileException(position, CompileExceptionCode.USING_THIS_OUTSIDE_TYPE, "Not in a type");
34
 		
34
 		
35
 		return scope.getOuterInstance(position);
35
 		return scope.getOuterInstance(position);
36
 	}
36
 	}

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

7
 package org.openzen.zenscript.parser.expression;
7
 package org.openzen.zenscript.parser.expression;
8
 
8
 
9
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
10
 import org.openzen.zenscript.codemodel.OperatorType;
11
 import org.openzen.zenscript.codemodel.OperatorType;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
28
 	}
29
 	}
29
 
30
 
30
 	@Override
31
 	@Override
31
-	public IPartialExpression compile(ExpressionScope scope) {
32
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
32
 		Expression cValue = value.compile(scope).eval();
33
 		Expression cValue = value.compile(scope).eval();
33
 		return scope.getTypeMembers(cValue.type).getOrCreateGroup(operator).callPostfix(position, scope, cValue);
34
 		return scope.getTypeMembers(cValue.type).getOrCreateGroup(operator).callPostfix(position, scope, cValue);
34
 	}
35
 	}

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

8
 import java.util.ArrayList;
8
 import java.util.ArrayList;
9
 import java.util.List;
9
 import java.util.List;
10
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.expression.RangeExpression;
13
 import org.openzen.zenscript.codemodel.expression.RangeExpression;
13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
31
 	}
32
 	}
32
 
33
 
33
 	@Override
34
 	@Override
34
-	public IPartialExpression compile(ExpressionScope scope) {
35
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
35
 		List<StoredType> fromHints = new ArrayList<>();
36
 		List<StoredType> fromHints = new ArrayList<>();
36
 		List<StoredType> toHints = new ArrayList<>();
37
 		List<StoredType> toHints = new ArrayList<>();
37
 		
38
 		

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

7
 package org.openzen.zenscript.parser.expression;
7
 package org.openzen.zenscript.parser.expression;
8
 
8
 
9
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
10
 import org.openzen.zenscript.codemodel.OperatorType;
11
 import org.openzen.zenscript.codemodel.OperatorType;
11
 import org.openzen.zenscript.codemodel.expression.CallArguments;
12
 import org.openzen.zenscript.codemodel.expression.CallArguments;
12
 import org.openzen.zenscript.codemodel.expression.Expression;
13
 import org.openzen.zenscript.codemodel.expression.Expression;
35
 	}
36
 	}
36
 
37
 
37
 	@Override
38
 	@Override
38
-	public IPartialExpression compile(ExpressionScope scope) {
39
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
39
 		Expression cLeft = left.compile(scope.withoutHints()).eval();
40
 		Expression cLeft = left.compile(scope.withoutHints()).eval();
40
 		Expression cRight = right.compile(scope.withHint(cLeft.type)).eval();
41
 		Expression cRight = right.compile(scope.withHint(cLeft.type)).eval();
41
 		return scope.getTypeMembers(cLeft.type)
42
 		return scope.getTypeMembers(cLeft.type)

+ 2
- 11
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionString.java View File

34
 
34
 
35
 	@Override
35
 	@Override
36
 	public IPartialExpression compile(ExpressionScope scope) {
36
 	public IPartialExpression compile(ExpressionScope scope) {
37
-		if (value.length() == 1) {
38
-			if (scope.hints.contains(BasicTypeID.CHAR)) {
39
-				return new ConstantCharExpression(position, value.charAt(0));
40
-			} else {
41
-				for (StoredType type : scope.hints)
42
-					if (type.type instanceof StringTypeID)
43
-						return new ConstantStringExpression(position, value);
44
-				
45
-				return new ConstantCharExpression(position, value.charAt(0));
46
-			}
47
-		}
37
+		if (value.length() == 1 && scope.hints.contains(BasicTypeID.CHAR.stored))
38
+			return new ConstantCharExpression(position, value.charAt(0));
48
 		
39
 		
49
 		return new ConstantStringExpression(position, value);
40
 		return new ConstantStringExpression(position, value);
50
 	}
41
 	}

+ 2
- 2
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionSuper.java View File

24
 	}
24
 	}
25
 	
25
 	
26
 	@Override
26
 	@Override
27
-	public IPartialExpression compile(ExpressionScope scope) {
27
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
28
 		StoredType type = scope.getThisType();
28
 		StoredType type = scope.getThisType();
29
 		StoredType targetType = type.getSuperType(scope.getTypeRegistry());
29
 		StoredType targetType = type.getSuperType(scope.getTypeRegistry());
30
 		if (targetType == null)
30
 		if (targetType == null)
31
-			return new InvalidExpression(position, CompileExceptionCode.SUPER_CALL_NO_SUPERCLASS, "Type has no superclass");
31
+			throw new CompileException(position, CompileExceptionCode.SUPER_CALL_NO_SUPERCLASS, "Type has no superclass");
32
 		
32
 		
33
 		return new PartialTypeExpression(position, targetType.type, null);
33
 		return new PartialTypeExpression(position, targetType.type, null);
34
 	}
34
 	}

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

7
 package org.openzen.zenscript.parser.expression;
7
 package org.openzen.zenscript.parser.expression;
8
 
8
 
9
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
10
 import org.openzen.zenscript.codemodel.OperatorType;
11
 import org.openzen.zenscript.codemodel.OperatorType;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
13
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
28
 	}
29
 	}
29
 
30
 
30
 	@Override
31
 	@Override
31
-	public IPartialExpression compile(ExpressionScope scope) {
32
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
32
 		Expression cValue = value.compile(scope).eval();
33
 		Expression cValue = value.compile(scope).eval();
33
 		return scope.getTypeMembers(cValue.type)
34
 		return scope.getTypeMembers(cValue.type)
34
 				.unary(position, scope, operator, cValue);
35
 				.unary(position, scope, operator, cValue);

+ 2
- 3
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionVariable.java View File

14
 import org.openzen.zenscript.codemodel.expression.ConstantStringExpression;
14
 import org.openzen.zenscript.codemodel.expression.ConstantStringExpression;
15
 import org.openzen.zenscript.codemodel.expression.EnumConstantExpression;
15
 import org.openzen.zenscript.codemodel.expression.EnumConstantExpression;
16
 import org.openzen.zenscript.codemodel.expression.Expression;
16
 import org.openzen.zenscript.codemodel.expression.Expression;
17
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
18
 import org.openzen.zenscript.codemodel.expression.VariantValueExpression;
17
 import org.openzen.zenscript.codemodel.expression.VariantValueExpression;
19
 import org.openzen.zenscript.codemodel.expression.switchvalue.EnumConstantSwitchValue;
18
 import org.openzen.zenscript.codemodel.expression.switchvalue.EnumConstantSwitchValue;
20
 import org.openzen.zenscript.codemodel.expression.switchvalue.SwitchValue;
19
 import org.openzen.zenscript.codemodel.expression.switchvalue.SwitchValue;
49
 	}
48
 	}
50
 
49
 
51
 	@Override
50
 	@Override
52
-	public IPartialExpression compile(ExpressionScope scope) {
51
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
53
 		TypeID[] genericArguments = TypeID.NONE;
52
 		TypeID[] genericArguments = TypeID.NONE;
54
 		if (genericParameters != null) {
53
 		if (genericParameters != null) {
55
 			genericArguments = new TypeID[genericParameters.size()];
54
 			genericArguments = new TypeID[genericParameters.size()];
71
 					return new VariantValueExpression(position, hint, option);
70
 					return new VariantValueExpression(position, hint, option);
72
 			}
71
 			}
73
 			
72
 			
74
-			return new InvalidExpression(position, CompileExceptionCode.UNDEFINED_VARIABLE, "No such symbol: " + name);
73
+			throw new CompileException(position, CompileExceptionCode.UNDEFINED_VARIABLE, "No such symbol: " + name);
75
 		} else {
74
 		} else {
76
 			return result;
75
 			return result;
77
 		}
76
 		}

+ 15
- 21
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedMatchExpression.java View File

10
 import org.openzen.zencode.shared.CompileException;
10
 import org.openzen.zencode.shared.CompileException;
11
 import org.openzen.zencode.shared.CompileExceptionCode;
11
 import org.openzen.zencode.shared.CompileExceptionCode;
12
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.expression.Expression;
13
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
14
 import org.openzen.zenscript.codemodel.expression.MatchExpression;
13
 import org.openzen.zenscript.codemodel.expression.MatchExpression;
15
 import org.openzen.zenscript.codemodel.expression.switchvalue.SwitchValue;
14
 import org.openzen.zenscript.codemodel.expression.switchvalue.SwitchValue;
16
 import org.openzen.zenscript.codemodel.expression.switchvalue.VariantOptionSwitchValue;
15
 import org.openzen.zenscript.codemodel.expression.switchvalue.VariantOptionSwitchValue;
17
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
16
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
18
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
17
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
19
-import org.openzen.zenscript.codemodel.type.BasicTypeID;
20
 import org.openzen.zenscript.codemodel.type.StoredType;
18
 import org.openzen.zenscript.codemodel.type.StoredType;
21
 
19
 
22
 /**
20
 /**
35
 	}
33
 	}
36
 
34
 
37
 	@Override
35
 	@Override
38
-	public IPartialExpression compile(ExpressionScope scope) {
39
-		try {
40
-			Expression cValue = value.compile(scope).eval();
41
-			MatchExpression.Case[] cCases = new MatchExpression.Case[cases.size()];
42
-			for (int i = 0; i < cases.size(); i++) {
43
-				Case matchCase = cases.get(i);
44
-				cCases[i] = matchCase.compile(cValue.type, scope);
45
-			}
46
-
47
-			StoredType result = cCases[0].value.type;
48
-			for (int i = 1; i < cCases.length; i++) {
49
-				StoredType oldResult = result;
50
-				result = scope.getTypeMembers(result).union(cCases[i].value.type);
51
-				if (result == null)
52
-					return new InvalidExpression(position, CompileExceptionCode.TYPE_CANNOT_UNITE, "Matches have different types: " + oldResult + " and " + cCases[i].value.type);
53
-			}
36
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
37
+		Expression cValue = value.compile(scope).eval();
38
+		MatchExpression.Case[] cCases = new MatchExpression.Case[cases.size()];
39
+		for (int i = 0; i < cases.size(); i++) {
40
+			Case matchCase = cases.get(i);
41
+			cCases[i] = matchCase.compile(cValue.type, scope);
42
+		}
54
 
43
 
55
-			return new MatchExpression(position, cValue, result, cCases);
56
-		} catch (CompileException ex) {
57
-			return new InvalidExpression(BasicTypeID.UNDETERMINED.stored, ex);
44
+		StoredType result = cCases[0].value.type;
45
+		for (int i = 1; i < cCases.length; i++) {
46
+			StoredType oldResult = result;
47
+			result = scope.getTypeMembers(result).union(cCases[i].value.type);
48
+			if (result == null)
49
+				throw new CompileException(position, CompileExceptionCode.TYPE_CANNOT_UNITE, "Matches have different types: " + oldResult + " and " + cCases[i].value.type);
58
 		}
50
 		}
51
+
52
+		return new MatchExpression(position, cValue, result, cCases);
59
 	}
53
 	}
60
 
54
 
61
 	@Override
55
 	@Override

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

6
 package org.openzen.zenscript.parser.expression;
6
 package org.openzen.zenscript.parser.expression;
7
 
7
 
8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
9
 import org.openzen.zenscript.codemodel.expression.PanicExpression;
10
 import org.openzen.zenscript.codemodel.expression.PanicExpression;
10
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
11
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
11
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
12
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
25
 	}
26
 	}
26
 	
27
 	
27
 	@Override
28
 	@Override
28
-	public IPartialExpression compile(ExpressionScope scope) {
29
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
29
 		return new PanicExpression(position, scope.getResultTypeHints().isEmpty() ? BasicTypeID.VOID.stored : scope.getResultTypeHints().get(0), value.compile(scope).eval());
30
 		return new PanicExpression(position, scope.getResultTypeHints().isEmpty() ? BasicTypeID.VOID.stored : scope.getResultTypeHints().get(0), value.compile(scope).eval());
30
 	}
31
 	}
31
 
32
 

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

6
 package org.openzen.zenscript.parser.expression;
6
 package org.openzen.zenscript.parser.expression;
7
 
7
 
8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
9
 import org.openzen.zenscript.codemodel.expression.Expression;
10
 import org.openzen.zenscript.codemodel.expression.Expression;
10
 import org.openzen.zenscript.codemodel.expression.ThrowExpression;
11
 import org.openzen.zenscript.codemodel.expression.ThrowExpression;
11
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
12
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
27
 	}
28
 	}
28
 
29
 
29
 	@Override
30
 	@Override
30
-	public IPartialExpression compile(ExpressionScope scope) {
31
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
31
 		Expression cValue = value.compile(scope).eval();
32
 		Expression cValue = value.compile(scope).eval();
32
 		StoredType resultType = BasicTypeID.VOID.stored;
33
 		StoredType resultType = BasicTypeID.VOID.stored;
33
 		if (scope.getResultTypeHints().size() == 1)
34
 		if (scope.getResultTypeHints().size() == 1)

+ 4
- 3
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedTryConvertExpression.java View File

6
 package org.openzen.zenscript.parser.expression;
6
 package org.openzen.zenscript.parser.expression;
7
 
7
 
8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
9
 import org.openzen.zencode.shared.CompileExceptionCode;
10
 import org.openzen.zencode.shared.CompileExceptionCode;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.expression.Expression;
29
 	}
30
 	}
30
 
31
 
31
 	@Override
32
 	@Override
32
-	public IPartialExpression compile(ExpressionScope scope) {
33
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
33
 		Expression cValue = value.compile(scope).eval();
34
 		Expression cValue = value.compile(scope).eval();
34
 		if (scope.getFunctionHeader() == null)
35
 		if (scope.getFunctionHeader() == null)
35
-			return new InvalidExpression(position, CompileExceptionCode.TRY_CONVERT_OUTSIDE_FUNCTION, "try? can only be used inside functions");
36
+			throw new CompileException(position, CompileExceptionCode.TRY_CONVERT_OUTSIDE_FUNCTION, "try? can only be used inside functions");
36
 		
37
 		
37
 		HighLevelDefinition result = scope.getTypeRegistry().stdlib.getDefinition("Result");
38
 		HighLevelDefinition result = scope.getTypeRegistry().stdlib.getDefinition("Result");
38
 		if (cValue.thrownType != null) {
39
 		if (cValue.thrownType != null) {
40
 			DefinitionTypeID resultType = scope.getTypeRegistry().getForDefinition(result, cValue.type.type, cValue.thrownType.type);
41
 			DefinitionTypeID resultType = scope.getTypeRegistry().getForDefinition(result, cValue.type.type, cValue.thrownType.type);
41
 			return new TryConvertExpression(position, resultType.stored(cValue.type.storage), cValue);
42
 			return new TryConvertExpression(position, resultType.stored(cValue.type.storage), cValue);
42
 		} else {
43
 		} else {
43
-			return new InvalidExpression(position, CompileExceptionCode.TRY_CONVERT_ILLEGAL_TARGET, "try? can only be used on expressions that throw");
44
+			throw new CompileException(position, CompileExceptionCode.TRY_CONVERT_ILLEGAL_TARGET, "try? can only be used on expressions that throw");
44
 		}
45
 		}
45
 	}
46
 	}
46
 
47
 

+ 4
- 4
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedTryRethrowExpression.java View File

6
 package org.openzen.zenscript.parser.expression;
6
 package org.openzen.zenscript.parser.expression;
7
 
7
 
8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
9
 import org.openzen.zencode.shared.CompileExceptionCode;
10
 import org.openzen.zencode.shared.CompileExceptionCode;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
12
 import org.openzen.zenscript.codemodel.expression.Expression;
12
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
13
 import org.openzen.zenscript.codemodel.expression.TryRethrowAsExceptionExpression;
13
 import org.openzen.zenscript.codemodel.expression.TryRethrowAsExceptionExpression;
14
 import org.openzen.zenscript.codemodel.expression.TryRethrowAsResultExpression;
14
 import org.openzen.zenscript.codemodel.expression.TryRethrowAsResultExpression;
15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
31
 	}
31
 	}
32
 
32
 
33
 	@Override
33
 	@Override
34
-	public IPartialExpression compile(ExpressionScope scope) {
34
+	public IPartialExpression compile(ExpressionScope scope) throws CompileException {
35
 		HighLevelDefinition result = scope.getTypeRegistry().stdlib.getDefinition("Result");
35
 		HighLevelDefinition result = scope.getTypeRegistry().stdlib.getDefinition("Result");
36
 		
36
 		
37
 		Expression cSource = source.compile(scope).eval();
37
 		Expression cSource = source.compile(scope).eval();
55
 			}
55
 			}
56
 			
56
 			
57
 			if (scope.getFunctionHeader() == null)
57
 			if (scope.getFunctionHeader() == null)
58
-				return new InvalidExpression(position, CompileExceptionCode.TRY_RETHROW_NOT_A_RESULT, "type is not a Result type, cannot convert");
58
+				throw new CompileException(position, CompileExceptionCode.TRY_RETHROW_NOT_A_RESULT, "type is not a Result type, cannot convert");
59
 			
59
 			
60
-			return new InvalidExpression(position, CompileExceptionCode.TRY_RETHROW_NOT_A_RESULT, "this expression doesn't throw an exception nor returns a result");
60
+			throw new CompileException(position, CompileExceptionCode.TRY_RETHROW_NOT_A_RESULT, "this expression doesn't throw an exception nor returns a result");
61
 		}
61
 		}
62
 	}
62
 	}
63
 
63
 

+ 6
- 6
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedCatchClause.java View File

6
 package org.openzen.zenscript.parser.statements;
6
 package org.openzen.zenscript.parser.statements;
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
-import java.util.function.Function;
10
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
+import org.openzen.zencode.shared.CompileException;
11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
 import org.openzen.zenscript.codemodel.GenericMapper;
13
 import org.openzen.zenscript.codemodel.GenericMapper;
14
-import org.openzen.zenscript.codemodel.expression.Expression;
15
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
14
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
16
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
17
 import org.openzen.zenscript.codemodel.statement.CatchClause;
16
 import org.openzen.zenscript.codemodel.statement.CatchClause;
20
 import org.openzen.zenscript.codemodel.type.GenericName;
19
 import org.openzen.zenscript.codemodel.type.GenericName;
21
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
20
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
22
 import org.openzen.zenscript.codemodel.scope.StatementScope;
21
 import org.openzen.zenscript.codemodel.scope.StatementScope;
22
+import org.openzen.zenscript.codemodel.statement.VariableID;
23
 import org.openzen.zenscript.codemodel.type.StoredType;
23
 import org.openzen.zenscript.codemodel.type.StoredType;
24
 import org.openzen.zenscript.codemodel.type.TypeID;
24
 import org.openzen.zenscript.codemodel.type.TypeID;
25
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
25
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
44
 	}
44
 	}
45
 	
45
 	
46
 	public CatchClause compile(StatementScope scope) {
46
 	public CatchClause compile(StatementScope scope) {
47
-		VarStatement exceptionVariable = new VarStatement(position, exceptionName, exceptionType.compile(scope), null, true);
47
+		VarStatement exceptionVariable = new VarStatement(position, new VariableID(), exceptionName, exceptionType.compile(scope), null, true);
48
 		CatchScope localScope = new CatchScope(scope, exceptionVariable);
48
 		CatchScope localScope = new CatchScope(scope, exceptionVariable);
49
 		return new CatchClause(position, exceptionVariable, content.compile(localScope));
49
 		return new CatchClause(position, exceptionVariable, content.compile(localScope));
50
 	}
50
 	}
59
 		}
59
 		}
60
 	
60
 	
61
 		@Override
61
 		@Override
62
-		public IPartialExpression get(CodePosition position, GenericName name) {
62
+		public IPartialExpression get(CodePosition position, GenericName name) throws CompileException {
63
 			if (name.hasNoArguments() && exceptionVariable.name.equals(name.name))
63
 			if (name.hasNoArguments() && exceptionVariable.name.equals(name.name))
64
 				return new GetLocalVariableExpression(position, exceptionVariable);
64
 				return new GetLocalVariableExpression(position, exceptionVariable);
65
 
65
 
97
 		}
97
 		}
98
 
98
 
99
 		@Override
99
 		@Override
100
-		public Function<CodePosition, Expression> getDollar() {
100
+		public DollarEvaluator getDollar() {
101
 			return outer.getDollar();
101
 			return outer.getDollar();
102
 		}
102
 		}
103
 
103
 
104
 		@Override
104
 		@Override
105
-		public IPartialExpression getOuterInstance(CodePosition position) {
105
+		public IPartialExpression getOuterInstance(CodePosition position) throws CompileException {
106
 			return outer.getOuterInstance(position);
106
 			return outer.getOuterInstance(position);
107
 		}
107
 		}
108
 
108
 

+ 15
- 9
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedLambdaFunctionBody.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.parser.statements;
6
 package org.openzen.zenscript.parser.statements;
7
 
7
 
8
+import org.openzen.zencode.shared.CompileException;
8
 import org.openzen.zenscript.codemodel.FunctionHeader;
9
 import org.openzen.zenscript.codemodel.FunctionHeader;
9
 import org.openzen.zenscript.codemodel.expression.Expression;
10
 import org.openzen.zenscript.codemodel.expression.Expression;
10
 import org.openzen.zenscript.codemodel.statement.ExpressionStatement;
11
 import org.openzen.zenscript.codemodel.statement.ExpressionStatement;
13
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
14
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
14
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
15
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
15
 import org.openzen.zenscript.codemodel.scope.StatementScope;
16
 import org.openzen.zenscript.codemodel.scope.StatementScope;
17
+import org.openzen.zenscript.codemodel.statement.InvalidStatement;
16
 import org.openzen.zenscript.parser.expression.ParsedExpression;
18
 import org.openzen.zenscript.parser.expression.ParsedExpression;
17
 
19
 
18
 /**
20
 /**
28
 	
30
 	
29
 	@Override
31
 	@Override
30
 	public Statement compile(StatementScope scope, FunctionHeader header) {
32
 	public Statement compile(StatementScope scope, FunctionHeader header) {
31
-		if (header.getReturnType().isBasic(BasicTypeID.VOID)) {
32
-			Expression value = this.value.compile(new ExpressionScope(scope)).eval();
33
-			return new ExpressionStatement(value.position, value);
34
-		} else {
35
-			Expression returnValue = value
36
-					.compile(new ExpressionScope(scope, header.getReturnType()))
37
-					.eval()
38
-					.castImplicit(value.position, scope, header.getReturnType());
39
-			return new ReturnStatement(value.position, returnValue);
33
+		try {
34
+			if (header.getReturnType().isBasic(BasicTypeID.VOID)) {
35
+				Expression value = this.value.compile(new ExpressionScope(scope)).eval();
36
+				return new ExpressionStatement(value.position, value);
37
+			} else {
38
+				Expression returnValue = value
39
+						.compile(new ExpressionScope(scope, header.getReturnType()))
40
+						.eval()
41
+						.castImplicit(value.position, scope, header.getReturnType());
42
+				return new ReturnStatement(value.position, returnValue);
43
+			}
44
+		} catch (CompileException ex) {
45
+			return new InvalidStatement(ex);
40
 		}
46
 		}
41
 	}
47
 	}
42
 }
48
 }

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

6
 package org.openzen.zenscript.parser.statements;
6
 package org.openzen.zenscript.parser.statements;
7
 
7
 
8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
9
 import org.openzen.zenscript.codemodel.WhitespaceInfo;
10
 import org.openzen.zenscript.codemodel.WhitespaceInfo;
10
 import org.openzen.zenscript.codemodel.expression.Expression;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
12
+import org.openzen.zenscript.codemodel.expression.InvalidExpression;
11
 import org.openzen.zenscript.codemodel.statement.DoWhileStatement;
13
 import org.openzen.zenscript.codemodel.statement.DoWhileStatement;
12
 import org.openzen.zenscript.codemodel.statement.Statement;
14
 import org.openzen.zenscript.codemodel.statement.Statement;
13
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
15
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
36
 
38
 
37
 	@Override
39
 	@Override
38
 	public Statement compile(StatementScope scope) {
40
 	public Statement compile(StatementScope scope) {
39
-		Expression condition = this.condition
41
+		Expression condition;
42
+		try {
43
+			condition = this.condition
40
 				.compile(new ExpressionScope(scope, BasicTypeID.HINT_BOOL))
44
 				.compile(new ExpressionScope(scope, BasicTypeID.HINT_BOOL))
41
 				.eval()
45
 				.eval()
42
 				.castImplicit(position, scope, BasicTypeID.BOOL.stored);
46
 				.castImplicit(position, scope, BasicTypeID.BOOL.stored);
47
+		} catch (CompileException ex) {
48
+			condition = new InvalidExpression(BasicTypeID.BOOL.stored, ex);
49
+		}
43
 		
50
 		
44
 		DoWhileStatement result = new DoWhileStatement(position, label, condition);
51
 		DoWhileStatement result = new DoWhileStatement(position, label, condition);
45
 		LoopScope innerScope = new LoopScope(result, scope);
52
 		LoopScope innerScope = new LoopScope(result, scope);

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

1
 package org.openzen.zenscript.parser.statements;
1
 package org.openzen.zenscript.parser.statements;
2
 
2
 
3
 import org.openzen.zencode.shared.CodePosition;
3
 import org.openzen.zencode.shared.CodePosition;
4
+import org.openzen.zencode.shared.CompileException;
4
 import org.openzen.zenscript.codemodel.WhitespaceInfo;
5
 import org.openzen.zenscript.codemodel.WhitespaceInfo;
5
 import org.openzen.zenscript.codemodel.statement.ExpressionStatement;
6
 import org.openzen.zenscript.codemodel.statement.ExpressionStatement;
6
 import org.openzen.zenscript.codemodel.statement.Statement;
7
 import org.openzen.zenscript.codemodel.statement.Statement;
7
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
8
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
8
 import org.openzen.zenscript.codemodel.scope.StatementScope;
9
 import org.openzen.zenscript.codemodel.scope.StatementScope;
10
+import org.openzen.zenscript.codemodel.statement.InvalidStatement;
9
 import org.openzen.zenscript.parser.ParsedAnnotation;
11
 import org.openzen.zenscript.parser.ParsedAnnotation;
10
-import org.openzen.zenscript.parser.PrecompilationState;
11
 import org.openzen.zenscript.parser.expression.ParsedExpression;
12
 import org.openzen.zenscript.parser.expression.ParsedExpression;
12
 
13
 
13
 public class ParsedStatementExpression extends ParsedStatement {
14
 public class ParsedStatementExpression extends ParsedStatement {
21
 
22
 
22
 	@Override
23
 	@Override
23
 	public Statement compile(StatementScope scope) {
24
 	public Statement compile(StatementScope scope) {
24
-		return result(new ExpressionStatement(position, this.expression.compile(new ExpressionScope(scope)).eval()), scope);
25
+		try {
26
+			return result(new ExpressionStatement(position, this.expression.compile(new ExpressionScope(scope)).eval()), scope);
27
+		} catch (CompileException ex) {
28
+			return result(new InvalidStatement(ex), scope);
29
+		}
25
 	}
30
 	}
26
 }
31
 }

+ 22
- 16
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementForeach.java View File

1
 package org.openzen.zenscript.parser.statements;
1
 package org.openzen.zenscript.parser.statements;
2
 
2
 
3
 import org.openzen.zencode.shared.CodePosition;
3
 import org.openzen.zencode.shared.CodePosition;
4
+import org.openzen.zencode.shared.CompileException;
4
 import org.openzen.zencode.shared.CompileExceptionCode;
5
 import org.openzen.zencode.shared.CompileExceptionCode;
5
 import org.openzen.zenscript.codemodel.WhitespaceInfo;
6
 import org.openzen.zenscript.codemodel.WhitespaceInfo;
6
 import org.openzen.zenscript.codemodel.expression.Expression;
7
 import org.openzen.zenscript.codemodel.expression.Expression;
13
 import org.openzen.zenscript.codemodel.scope.ForeachScope;
14
 import org.openzen.zenscript.codemodel.scope.ForeachScope;
14
 import org.openzen.zenscript.codemodel.scope.StatementScope;
15
 import org.openzen.zenscript.codemodel.scope.StatementScope;
15
 import org.openzen.zenscript.codemodel.statement.InvalidStatement;
16
 import org.openzen.zenscript.codemodel.statement.InvalidStatement;
17
+import org.openzen.zenscript.codemodel.statement.VariableID;
16
 import org.openzen.zenscript.codemodel.type.StoredType;
18
 import org.openzen.zenscript.codemodel.type.StoredType;
17
 import org.openzen.zenscript.parser.ParsedAnnotation;
19
 import org.openzen.zenscript.parser.ParsedAnnotation;
18
 import org.openzen.zenscript.parser.expression.ParsedExpression;
20
 import org.openzen.zenscript.parser.expression.ParsedExpression;
32
 
34
 
33
 	@Override
35
 	@Override
34
 	public Statement compile(StatementScope scope) {
36
 	public Statement compile(StatementScope scope) {
35
-		Expression list = this.list.compile(new ExpressionScope(scope)).eval();
36
-		
37
-		TypeMembers members = scope.getTypeMembers(list.type);
38
-		IteratorMemberRef iterator = members.getIterator(varnames.length);
39
-		if (iterator == null)
40
-			return new InvalidStatement(position, CompileExceptionCode.NO_SUCH_ITERATOR, list.type + " doesn't have an iterator with " + varnames.length + " variables");
41
-		
42
-		StoredType[] loopTypes = iterator.types;
43
-		VarStatement[] variables = new VarStatement[varnames.length];
44
-		for (int i = 0; i < variables.length; i++)
45
-			variables[i] = new VarStatement(position, varnames[i], loopTypes[i], null, true);
46
-		
47
-		ForeachStatement statement = new ForeachStatement(position, variables, iterator, list);
48
-		ForeachScope innerScope = new ForeachScope(statement, scope);
49
-		statement.content = this.body.compile(innerScope);
50
-		return result(statement, scope);
37
+		try {
38
+			Expression list = this.list.compile(new ExpressionScope(scope)).eval();
39
+
40
+			TypeMembers members = scope.getTypeMembers(list.type);
41
+			IteratorMemberRef iterator = members.getIterator(varnames.length);
42
+			if (iterator == null)
43
+				return new InvalidStatement(position, CompileExceptionCode.NO_SUCH_ITERATOR, list.type + " doesn't have an iterator with " + varnames.length + " variables");
44
+
45
+			StoredType[] loopTypes = iterator.types;
46
+			VarStatement[] variables = new VarStatement[varnames.length];
47
+			for (int i = 0; i < variables.length; i++)
48
+				variables[i] = new VarStatement(position, new VariableID(), varnames[i], loopTypes[i], null, true);
49
+
50
+			ForeachStatement statement = new ForeachStatement(position, variables, iterator, list);
51
+			ForeachScope innerScope = new ForeachScope(statement, scope);
52
+			statement.content = this.body.compile(innerScope);
53
+			return result(statement, scope);
54
+		} catch (CompileException ex) {
55
+			return result(new InvalidStatement(ex), scope);
56
+		}
51
 	}
57
 	}
52
 }
58
 }

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

1
 package org.openzen.zenscript.parser.statements;
1
 package org.openzen.zenscript.parser.statements;
2
 
2
 
3
 import org.openzen.zencode.shared.CodePosition;
3
 import org.openzen.zencode.shared.CodePosition;
4
+import org.openzen.zencode.shared.CompileException;
4
 import org.openzen.zenscript.codemodel.WhitespaceInfo;
5
 import org.openzen.zenscript.codemodel.WhitespaceInfo;
5
 import org.openzen.zenscript.codemodel.expression.Expression;
6
 import org.openzen.zenscript.codemodel.expression.Expression;
7
+import org.openzen.zenscript.codemodel.expression.InvalidExpression;
6
 import org.openzen.zenscript.codemodel.statement.IfStatement;
8
 import org.openzen.zenscript.codemodel.statement.IfStatement;
7
 import org.openzen.zenscript.codemodel.statement.Statement;
9
 import org.openzen.zenscript.codemodel.statement.Statement;
8
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
10
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
26
 
28
 
27
 	@Override
29
 	@Override
28
 	public Statement compile(StatementScope scope) {
30
 	public Statement compile(StatementScope scope) {
29
-		Expression condition = this.condition.compile(new ExpressionScope(scope, BasicTypeID.HINT_BOOL)).eval();
31
+		Expression condition;
32
+		try {
33
+			condition = this.condition.compile(new ExpressionScope(scope, BasicTypeID.HINT_BOOL)).eval();
34
+		} catch (CompileException ex) {
35
+			condition = new InvalidExpression(BasicTypeID.BOOL.stored, ex);
36
+		}
37
+		
30
 		Statement onThen = this.onThen.compile(scope);
38
 		Statement onThen = this.onThen.compile(scope);
31
 		Statement onElse = this.onElse == null ? null : this.onElse.compile(scope);
39
 		Statement onElse = this.onElse == null ? null : this.onElse.compile(scope);
32
  		return result(new IfStatement(position, condition, onThen, onElse), scope);
40
  		return result(new IfStatement(position, condition, onThen, onElse), scope);

+ 9
- 3
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementLock.java View File

6
 package org.openzen.zenscript.parser.statements;
6
 package org.openzen.zenscript.parser.statements;
7
 
7
 
8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
9
 import org.openzen.zenscript.codemodel.WhitespaceInfo;
10
 import org.openzen.zenscript.codemodel.WhitespaceInfo;
10
 import org.openzen.zenscript.codemodel.expression.Expression;
11
 import org.openzen.zenscript.codemodel.expression.Expression;
11
 import org.openzen.zenscript.codemodel.statement.LockStatement;
12
 import org.openzen.zenscript.codemodel.statement.LockStatement;
12
 import org.openzen.zenscript.codemodel.statement.Statement;
13
 import org.openzen.zenscript.codemodel.statement.Statement;
13
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
14
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
14
 import org.openzen.zenscript.codemodel.scope.StatementScope;
15
 import org.openzen.zenscript.codemodel.scope.StatementScope;
16
+import org.openzen.zenscript.codemodel.statement.InvalidStatement;
15
 import org.openzen.zenscript.parser.ParsedAnnotation;
17
 import org.openzen.zenscript.parser.ParsedAnnotation;
16
 import org.openzen.zenscript.parser.expression.ParsedExpression;
18
 import org.openzen.zenscript.parser.expression.ParsedExpression;
17
 
19
 
32
 
34
 
33
 	@Override
35
 	@Override
34
 	public Statement compile(StatementScope scope) {
36
 	public Statement compile(StatementScope scope) {
35
-		Expression object = this.object.compile(new ExpressionScope(scope)).eval();
36
-		Statement content = this.content.compile(scope);
37
-		return result(new LockStatement(position, object, content), scope);
37
+		try {
38
+			Expression object = this.object.compile(new ExpressionScope(scope)).eval();
39
+			Statement content = this.content.compile(scope);
40
+			return result(new LockStatement(position, object, content), scope);
41
+		} catch (CompileException ex) {
42
+			return result(new InvalidStatement(ex), scope);
43
+		}
38
 	}
44
 	}
39
 }
45
 }

+ 0
- 0
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementReturn.java View File


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

Loading…
Cancel
Save