Browse Source

- Added try! and try? operators

- WIP on exception handling
Stan Hebben 6 years ago
parent
commit
58c21971e9
100 changed files with 453 additions and 124 deletions
  1. 30
    0
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/ExpressionFormatter.java
  2. 1
    1
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/StatementFormatter.java
  3. 60
    0
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/SwitchValueFormatter.java
  4. 12
    8
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java
  5. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/FunctionDefinition.java
  6. 17
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ZSPackage.java
  7. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/AndAndExpression.java
  8. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ArrayExpression.java
  9. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/BasicCompareExpression.java
  10. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallExpression.java
  11. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallStaticExpression.java
  12. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CapturedExpression.java
  13. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CastExpression.java
  14. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CheckNullExpression.java
  15. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CoalesceExpression.java
  16. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConditionalExpression.java
  17. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantBoolExpression.java
  18. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantByteExpression.java
  19. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantCharExpression.java
  20. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantDoubleExpression.java
  21. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantFloatExpression.java
  22. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantIntExpression.java
  23. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantLongExpression.java
  24. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantSByteExpression.java
  25. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantShortExpression.java
  26. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantStringExpression.java
  27. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantUIntExpression.java
  28. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantULongExpression.java
  29. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantUShortExpression.java
  30. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstructorSuperCallExpression.java
  31. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstructorThisCallExpression.java
  32. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/EnumConstantExpression.java
  33. 23
    5
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/Expression.java
  34. 8
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionVisitor.java
  35. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/FunctionExpression.java
  36. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GenericCompareExpression.java
  37. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetFieldExpression.java
  38. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetFunctionParameterExpression.java
  39. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetLocalVariableExpression.java
  40. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetStaticFieldExpression.java
  41. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetterExpression.java
  42. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GlobalCallExpression.java
  43. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GlobalExpression.java
  44. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/InterfaceCastExpression.java
  45. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/IsExpression.java
  46. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/MakeConstExpression.java
  47. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/MapExpression.java
  48. 12
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/MatchExpression.java
  49. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/NewExpression.java
  50. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/NullExpression.java
  51. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/OrOrExpression.java
  52. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/PostCallExpression.java
  53. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/RangeExpression.java
  54. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SameObjectExpression.java
  55. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SetFieldExpression.java
  56. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SetFunctionParameterExpression.java
  57. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SetLocalVariableExpression.java
  58. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SetStaticFieldExpression.java
  59. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SetterExpression.java
  60. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/StaticGetterExpression.java
  61. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/StaticSetterExpression.java
  62. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SupertypeCastExpression.java
  63. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ThisExpression.java
  64. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/TryConvertExpression.java
  65. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/TryRethrowAsExceptionExpression.java
  66. 28
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/TryRethrowAsResultExpression.java
  67. 10
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/VariantValueExpression.java
  68. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/WrapOptionalExpression.java
  69. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ConstructorMember.java
  70. 10
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/BlockStatement.java
  71. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/BreakStatement.java
  72. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ContinueStatement.java
  73. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/DoWhileStatement.java
  74. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/EmptyStatement.java
  75. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ExpressionStatement.java
  76. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ForeachStatement.java
  77. 9
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/IfStatement.java
  78. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/LockStatement.java
  79. 3
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/LoopStatement.java
  80. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ReturnStatement.java
  81. 3
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/Statement.java
  82. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/SwitchStatement.java
  83. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ThrowStatement.java
  84. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/TryCatchStatement.java
  85. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/VarStatement.java
  86. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/WhileStatement.java
  87. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ConstTypeID.java
  88. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/DefinitionTypeID.java
  89. 7
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GlobalTypeRegistry.java
  90. 5
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ITypeID.java
  91. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/OptionalTypeID.java
  92. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/DefinitionMemberGroup.java
  93. 4
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java
  94. 3
    3
      Constructor/libraries/collections/src/LinkedList.zs
  95. 9
    0
      Constructor/libraries/io/src/IOException.zs
  96. 3
    3
      Constructor/libraries/io/src/Reader.zs
  97. 24
    10
      Constructor/libraries/stdlib/src/Result.zs
  98. 3
    2
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/ModuleSpace.java
  99. 22
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
  100. 0
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreDecrementVisitor.java

+ 30
- 0
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/ExpressionFormatter.java View File

67
 import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
67
 import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
68
 import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
68
 import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
69
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
69
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
70
+import org.openzen.zenscript.codemodel.expression.TryConvertExpression;
71
+import org.openzen.zenscript.codemodel.expression.TryRethrowAsExceptionExpression;
72
+import org.openzen.zenscript.codemodel.expression.TryRethrowAsResultExpression;
73
+import org.openzen.zenscript.codemodel.expression.VariantValueExpression;
70
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
74
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
71
 import org.openzen.zenscript.codemodel.member.OperatorMember;
75
 import org.openzen.zenscript.codemodel.member.OperatorMember;
72
 import org.openzen.zenscript.shared.StringUtils;
76
 import org.openzen.zenscript.shared.StringUtils;
610
 		return new ExpressionString("this", OperatorPriority.PRIMARY);
614
 		return new ExpressionString("this", OperatorPriority.PRIMARY);
611
 	}
615
 	}
612
 
616
 
617
+	@Override
618
+	public ExpressionString visitTryConvert(TryConvertExpression expression) {
619
+		ExpressionString value = expression.accept(this);
620
+		return new ExpressionString("try?" + value.value, value.priority);
621
+	}
622
+
623
+	@Override
624
+	public ExpressionString visitTryRethrowAsException(TryRethrowAsExceptionExpression expression) {
625
+		ExpressionString value = expression.accept(this);
626
+		return new ExpressionString("try!" + value.value, value.priority);
627
+	}
628
+
629
+	@Override
630
+	public ExpressionString visitTryRethrowAsResult(TryRethrowAsResultExpression expression) {
631
+		ExpressionString value = expression.accept(this);
632
+		return new ExpressionString("try!" + value.value, value.priority);
633
+	}
634
+	
635
+	@Override
636
+	public ExpressionString visitVariantValue(VariantValueExpression expression) {
637
+		StringBuilder result = new StringBuilder();
638
+		result.append("new ");
639
+		// TODO: finish this
640
+		return new ExpressionString(result.toString(), OperatorPriority.PRIMARY);
641
+	}
642
+
613
 	@Override
643
 	@Override
614
 	public ExpressionString visitWrapOptional(WrapOptionalExpression expression) {
644
 	public ExpressionString visitWrapOptional(WrapOptionalExpression expression) {
615
 		return expression.value.accept(this);
645
 		return expression.value.accept(this);

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

215
 				output.append(indent)
215
 				output.append(indent)
216
 						.append(settings.indent)
216
 						.append(settings.indent)
217
 						.append("case ")
217
 						.append("case ")
218
-						.append(switchCase.value.accept(expressionFormatter))
218
+						.append(switchCase.value.accept(new SwitchValueFormatter(settings)))
219
 						.append(":\n");
219
 						.append(":\n");
220
 			}
220
 			}
221
 			for (Statement s : switchCase.statements)
221
 			for (Statement s : switchCase.statements)

+ 60
- 0
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/SwitchValueFormatter.java View File

1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.formatter;
7
+
8
+import org.openzen.zenscript.codemodel.expression.switchvalue.CharSwitchValue;
9
+import org.openzen.zenscript.codemodel.expression.switchvalue.EnumConstantSwitchValue;
10
+import org.openzen.zenscript.codemodel.expression.switchvalue.IntSwitchValue;
11
+import org.openzen.zenscript.codemodel.expression.switchvalue.StringSwitchValue;
12
+import org.openzen.zenscript.codemodel.expression.switchvalue.SwitchValueVisitor;
13
+import org.openzen.zenscript.codemodel.expression.switchvalue.VariantOptionSwitchValue;
14
+import org.openzen.zenscript.shared.StringUtils;
15
+
16
+/**
17
+ *
18
+ * @author Hoofdgebruiker
19
+ */
20
+public class SwitchValueFormatter implements SwitchValueVisitor<String> {
21
+	private final FormattingSettings settings;
22
+	
23
+	public SwitchValueFormatter(FormattingSettings settings) {
24
+		this.settings = settings;
25
+	}
26
+
27
+	@Override
28
+	public String acceptInt(IntSwitchValue value) {
29
+		return Integer.toString(value.value);
30
+	}
31
+
32
+	@Override
33
+	public String acceptChar(CharSwitchValue value) {
34
+		return StringUtils.escape(new String(new char[] { value.value }), '\'', true);
35
+	}
36
+
37
+	@Override
38
+	public String acceptString(StringSwitchValue value) {
39
+		return StringUtils.escape(value.value, settings.useSingleQuotesForStrings ? '\'' : '"', true);
40
+	}
41
+
42
+	@Override
43
+	public String acceptEnumConstant(EnumConstantSwitchValue value) {
44
+		return value.constant.name;
45
+	}
46
+
47
+	@Override
48
+	public String acceptVariantOption(VariantOptionSwitchValue value) {
49
+		StringBuilder result = new StringBuilder();
50
+		result.append(value.option.name);
51
+		result.append("(");
52
+		for (int i = 0; i < value.parameters.length; i++) {
53
+			if (i > 0)
54
+				result.append(", ");
55
+			result.append(value.parameters[i]);
56
+		}
57
+		result.append(")");
58
+		return result.toString();
59
+	}
60
+}

+ 12
- 8
CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java View File

27
 	public final TypeParameter[] typeParameters;
27
 	public final TypeParameter[] typeParameters;
28
 	public final ITypeID returnType;
28
 	public final ITypeID returnType;
29
 	public final FunctionParameter[] parameters;
29
 	public final FunctionParameter[] parameters;
30
+	public final ITypeID thrownType;
30
 	
31
 	
31
 	public FunctionHeader(ITypeID returnType) {
32
 	public FunctionHeader(ITypeID returnType) {
32
 		this.typeParameters = null;
33
 		this.typeParameters = null;
33
 		this.returnType = returnType;
34
 		this.returnType = returnType;
34
 		this.parameters = NO_PARAMETERS;
35
 		this.parameters = NO_PARAMETERS;
36
+		this.thrownType = null;
35
 	}
37
 	}
36
 	
38
 	
37
 	public FunctionHeader(ITypeID returnType, ITypeID... parameterTypes) {
39
 	public FunctionHeader(ITypeID returnType, ITypeID... parameterTypes) {
38
 		this.typeParameters = null;
40
 		this.typeParameters = null;
39
 		this.returnType = returnType;
41
 		this.returnType = returnType;
40
 		this.parameters = new FunctionParameter[parameterTypes.length];
42
 		this.parameters = new FunctionParameter[parameterTypes.length];
43
+		this.thrownType = null;
41
 		
44
 		
42
 		for (int i = 0; i < parameterTypes.length; i++)
45
 		for (int i = 0; i < parameterTypes.length; i++)
43
 			parameters[i] = new FunctionParameter(parameterTypes[i], null);
46
 			parameters[i] = new FunctionParameter(parameterTypes[i], null);
47
 		this.typeParameters = null;
50
 		this.typeParameters = null;
48
 		this.returnType = returnType;
51
 		this.returnType = returnType;
49
 		this.parameters = parameters;
52
 		this.parameters = parameters;
53
+		this.thrownType = null;
50
 	}
54
 	}
51
 	
55
 	
52
-	public FunctionHeader(TypeParameter[] genericParameters, ITypeID returnType, FunctionParameter... parameters) {
56
+	public FunctionHeader(TypeParameter[] genericParameters, ITypeID returnType, ITypeID thrownType, FunctionParameter... parameters) {
53
 		this.typeParameters = genericParameters;
57
 		this.typeParameters = genericParameters;
54
 		this.returnType = returnType;
58
 		this.returnType = returnType;
55
 		this.parameters = parameters;
59
 		this.parameters = parameters;
60
+		this.thrownType = thrownType;
56
 	}
61
 	}
57
 	
62
 	
58
 	public int getNumberOfTypeParameters() {
63
 	public int getNumberOfTypeParameters() {
70
 		for (int i = 0; i < parameters.length; i++)
75
 		for (int i = 0; i < parameters.length; i++)
71
 			parameters[i] = this.parameters[i].withGenericArguments(registry, mapping);
76
 			parameters[i] = this.parameters[i].withGenericArguments(registry, mapping);
72
 		
77
 		
73
-		return new FunctionHeader(genericParameters, returnType, parameters);
78
+		return new FunctionHeader(genericParameters, returnType, thrownType == null ? null : thrownType.withGenericArguments(registry, mapping), parameters);
74
 	}
79
 	}
75
 	
80
 	
76
 	public ITypeID[] inferTypes(LocalMemberCache cache, CallArguments arguments, List<ITypeID> resultHint) {
81
 	public ITypeID[] inferTypes(LocalMemberCache cache, CallArguments arguments, List<ITypeID> resultHint) {
202
 			ITypeID modified = this.parameters[i].type.withGenericArguments(registry, arguments);
207
 			ITypeID modified = this.parameters[i].type.withGenericArguments(registry, arguments);
203
 			parameters[i] = modified == this.parameters[i].type ? this.parameters[i] : new FunctionParameter(modified, this.parameters[i].name);
208
 			parameters[i] = modified == this.parameters[i].type ? this.parameters[i] : new FunctionParameter(modified, this.parameters[i].name);
204
 		}
209
 		}
205
-		return new FunctionHeader(typeParameters, returnType, parameters);
210
+		return new FunctionHeader(typeParameters, returnType, thrownType == null ? null : thrownType.withGenericArguments(registry, arguments), parameters);
206
 	}
211
 	}
207
 	
212
 	
208
 	public FunctionHeader withGenericArguments(GlobalTypeRegistry registry, ITypeID[] arguments) {
213
 	public FunctionHeader withGenericArguments(GlobalTypeRegistry registry, ITypeID[] arguments) {
229
 		for (int i = 0; i < lambdaHeader.parameters.length; i++)
234
 		for (int i = 0; i < lambdaHeader.parameters.length; i++)
230
 			parameters[i] = new FunctionParameter(this.parameters[i].type, lambdaHeader.parameters[i].name);
235
 			parameters[i] = new FunctionParameter(this.parameters[i].type, lambdaHeader.parameters[i].name);
231
 		
236
 		
232
-		return new FunctionHeader(typeParameters, returnType, parameters);
233
-		//return this;
237
+		return new FunctionHeader(typeParameters, returnType, thrownType, parameters);
234
 	}
238
 	}
235
 	
239
 	
236
 	public FunctionParameter getVariadicParameter() {
240
 	public FunctionParameter getVariadicParameter() {
247
 			return parameters.length + " parameters expected but " + arguments.arguments.length + " given.";
251
 			return parameters.length + " parameters expected but " + arguments.arguments.length + " given.";
248
 		
252
 		
249
 		if (getNumberOfTypeParameters() != arguments.getNumberOfTypeArguments())
253
 		if (getNumberOfTypeParameters() != arguments.getNumberOfTypeArguments())
250
-			return typeParameters.length + " type parameters expected but " + arguments.typeArguments.length + " given.";
254
+			return getNumberOfTypeParameters() + " type parameters expected but " + arguments.getNumberOfTypeArguments() + " given.";
251
 		
255
 		
252
 		for (int i = 0; i < parameters.length; i++) {
256
 		for (int i = 0; i < parameters.length; i++) {
253
-			if (!scope.getTypeMembers(arguments.arguments[i].getType()).canCastImplicit(parameters[i].type)) {
254
-				return "Parameter " + i + ": cannot cast " + arguments.arguments[i].getType() + " to " + parameters[i].type;
257
+			if (!scope.getTypeMembers(arguments.arguments[i].type).canCastImplicit(parameters[i].type)) {
258
+				return "Parameter " + i + ": cannot cast " + arguments.arguments[i].type + " to " + parameters[i].type;
255
 			}
259
 			}
256
 		}
260
 		}
257
 		
261
 		

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

38
 	public void setHeader(FunctionHeader header) {
38
 	public void setHeader(FunctionHeader header) {
39
 		this.header = header;
39
 		this.header = header;
40
 		this.genericParameters = header.typeParameters;
40
 		this.genericParameters = header.typeParameters;
41
-		header = new FunctionHeader(null, header.returnType, header.parameters);
41
+		header = new FunctionHeader(null, header.returnType, header.thrownType, header.parameters);
42
 		addMember(caller = new OperatorMember(position, this, modifiers | Modifiers.STATIC, OperatorType.CALL, header));
42
 		addMember(caller = new OperatorMember(position, this, modifiers | Modifiers.STATIC, OperatorType.CALL, header));
43
 		callerGroup.addMethod(caller, TypeMemberPriority.SPECIFIED);
43
 		callerGroup.addMethod(caller, TypeMemberPriority.SPECIFIED);
44
 	}
44
 	}

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

59
 		return types.containsKey(name) || subPackages.containsKey(name);
59
 		return types.containsKey(name) || subPackages.containsKey(name);
60
 	}
60
 	}
61
 	
61
 	
62
+	public HighLevelDefinition getDefinition(String name) {
63
+		return types.get(name);
64
+	}
65
+	
62
 	public HighLevelDefinition getImport(List<String> name, int depth) {
66
 	public HighLevelDefinition getImport(List<String> name, int depth) {
63
 		if (depth >= name.size())
67
 		if (depth >= name.size())
64
 			return null;
68
 			return null;
72
 		return null;
76
 		return null;
73
 	}
77
 	}
74
 	
78
 	
75
-	public ITypeID getType(CodePosition position, TypeScope scope, List<GenericName> nameParts, int depth) {
79
+	public ITypeID getType(CodePosition position, TypeScope scope, List<GenericName> nameParts) {
80
+		return getType(position, scope, nameParts, 0);
81
+	}
82
+	
83
+	public ITypeID getType(CodePosition position, TypeScope scope, GenericName name) {
84
+		if (types.containsKey(name.name)) {
85
+			return scope.getTypeRegistry().getForDefinition(types.get(name.name), name.arguments);
86
+		}
87
+		
88
+		return null;
89
+	}
90
+	
91
+	private ITypeID getType(CodePosition position, TypeScope scope, List<GenericName> nameParts, int depth) {
76
 		if (depth >= nameParts.size())
92
 		if (depth >= nameParts.size())
77
 			return null;
93
 			return null;
78
 		
94
 		

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

17
 	public final Expression right;
17
 	public final Expression right;
18
 	
18
 	
19
 	public AndAndExpression(CodePosition position, Expression left, Expression right) {
19
 	public AndAndExpression(CodePosition position, Expression left, Expression right) {
20
-		super(position, BasicTypeID.BOOL);
20
+		super(position, BasicTypeID.BOOL, binaryThrow(position, left.thrownType, right.thrownType));
21
 		
21
 		
22
 		this.left = left;
22
 		this.left = left;
23
 		this.right = right;
23
 		this.right = right;

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

17
 	public final ArrayTypeID arrayType;
17
 	public final ArrayTypeID arrayType;
18
 	
18
 	
19
 	public ArrayExpression(CodePosition position, Expression[] expressions, ArrayTypeID type) {
19
 	public ArrayExpression(CodePosition position, Expression[] expressions, ArrayTypeID type) {
20
-		super(position, type);
20
+		super(position, type, multiThrow(position, expressions));
21
 		
21
 		
22
 		this.expressions = expressions;
22
 		this.expressions = expressions;
23
 		this.arrayType = type;
23
 		this.arrayType = type;

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

21
 	public final CompareType operator;
21
 	public final CompareType operator;
22
 	
22
 	
23
 	public BasicCompareExpression(CodePosition position, Expression left, Expression right, CompareType operator) {
23
 	public BasicCompareExpression(CodePosition position, Expression left, Expression right, CompareType operator) {
24
-		super(position, BasicTypeID.BOOL);
24
+		super(position, BasicTypeID.BOOL, binaryThrow(position, left.thrownType, right.thrownType));
25
 		
25
 		
26
 		this.left = left;
26
 		this.left = left;
27
 		this.right = right;
27
 		this.right = right;

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

21
 	public final FunctionHeader instancedHeader;
21
 	public final FunctionHeader instancedHeader;
22
 	
22
 	
23
 	public CallExpression(CodePosition position, Expression target, FunctionalMember member, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope) {
23
 	public CallExpression(CodePosition position, Expression target, FunctionalMember member, FunctionHeader instancedHeader, CallArguments arguments, TypeScope scope) {
24
-		super(position, instancedHeader.returnType);
24
+		super(position, instancedHeader.returnType, multiThrow(position, arguments.arguments));
25
 		
25
 		
26
 		this.target = target;
26
 		this.target = target;
27
 		this.member = member;
27
 		this.member = member;

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

22
 	public final FunctionHeader instancedHeader;
22
 	public final FunctionHeader instancedHeader;
23
 	
23
 	
24
 	public CallStaticExpression(CodePosition position, ITypeID target, FunctionalMember member, CallArguments arguments, FunctionHeader instancedHeader, TypeScope scope) {
24
 	public CallStaticExpression(CodePosition position, ITypeID target, FunctionalMember member, CallArguments arguments, FunctionHeader instancedHeader, TypeScope scope) {
25
-		super(position, member.header.returnType);
25
+		super(position, member.header.returnType, multiThrow(position, arguments.arguments));
26
 		
26
 		
27
 		this.member = member;
27
 		this.member = member;
28
 		this.target = target;
28
 		this.target = target;

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

16
 	public final LambdaClosure closure;
16
 	public final LambdaClosure closure;
17
 	
17
 	
18
 	public CapturedExpression(CodePosition position, ITypeID type, LambdaClosure closure) {
18
 	public CapturedExpression(CodePosition position, ITypeID type, LambdaClosure closure) {
19
-		super(position, type);
19
+		super(position, type, null);
20
 		
20
 		
21
 		this.closure = closure;
21
 		this.closure = closure;
22
 	}
22
 	}

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

18
 	public final boolean isImplicit;
18
 	public final boolean isImplicit;
19
 	
19
 	
20
 	public CastExpression(CodePosition position, Expression target, CasterMember member, boolean isImplicit) {
20
 	public CastExpression(CodePosition position, Expression target, CasterMember member, boolean isImplicit) {
21
-		super(position, member.getTargetType());
21
+		super(position, member.getTargetType(), binaryThrow(position, target.thrownType, member.header.thrownType));
22
 		
22
 		
23
 		this.target = target;
23
 		this.target = target;
24
 		this.member = member;
24
 		this.member = member;

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

16
 	public final Expression value;
16
 	public final Expression value;
17
 	
17
 	
18
 	public CheckNullExpression(CodePosition position, Expression value) {
18
 	public CheckNullExpression(CodePosition position, Expression value) {
19
-		super(position, value.type.unwrap());
19
+		super(position, value.type.unwrap(), value.thrownType);
20
 		
20
 		
21
 		this.value = value;
21
 		this.value = value;
22
 	}
22
 	}

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

16
 	public final Expression right;
16
 	public final Expression right;
17
 	
17
 	
18
 	public CoalesceExpression(CodePosition position, Expression left, Expression right) {
18
 	public CoalesceExpression(CodePosition position, Expression left, Expression right) {
19
-		super(position, right.type);
19
+		super(position, right.type, binaryThrow(position, left.thrownType, right.thrownType));
20
 		
20
 		
21
 		this.left = left;
21
 		this.left = left;
22
 		this.right = right;
22
 		this.right = right;

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

23
 			Expression ifThen,
23
 			Expression ifThen,
24
 			Expression ifElse,
24
 			Expression ifElse,
25
 			ITypeID type) {
25
 			ITypeID type) {
26
-		super(position, ifThen.type);
26
+		super(position, ifThen.type, binaryThrow(position, condition.thrownType, binaryThrow(position, ifThen.thrownType, ifElse.thrownType)));
27
 		
27
 		
28
 		if (ifThen.type != ifElse.type)
28
 		if (ifThen.type != ifElse.type)
29
 			throw new AssertionError();
29
 			throw new AssertionError();

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

16
 	public final boolean value;
16
 	public final boolean value;
17
 	
17
 	
18
 	public ConstantBoolExpression(CodePosition position, boolean value) {
18
 	public ConstantBoolExpression(CodePosition position, boolean value) {
19
-		super(position, BasicTypeID.BOOL);
19
+		super(position, BasicTypeID.BOOL, null);
20
 		
20
 		
21
 		this.value = value;
21
 		this.value = value;
22
 	}
22
 	}

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

16
 	public final byte value;
16
 	public final byte value;
17
 	
17
 	
18
 	public ConstantByteExpression(CodePosition position, byte value) {
18
 	public ConstantByteExpression(CodePosition position, byte value) {
19
-		super(position, BasicTypeID.BYTE);
19
+		super(position, BasicTypeID.BYTE, null);
20
 		
20
 		
21
 		this.value = value;
21
 		this.value = value;
22
 	}
22
 	}

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

16
 	public final char value;
16
 	public final char value;
17
 	
17
 	
18
 	public ConstantCharExpression(CodePosition position, char value) {
18
 	public ConstantCharExpression(CodePosition position, char value) {
19
-		super(position, BasicTypeID.CHAR);
19
+		super(position, BasicTypeID.CHAR, null);
20
 		
20
 		
21
 		this.value = value;
21
 		this.value = value;
22
 	}
22
 	}

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

16
 	public final double value;
16
 	public final double value;
17
 	
17
 	
18
 	public ConstantDoubleExpression(CodePosition position, double value) {
18
 	public ConstantDoubleExpression(CodePosition position, double value) {
19
-		super(position, BasicTypeID.DOUBLE);
19
+		super(position, BasicTypeID.DOUBLE, null);
20
 		
20
 		
21
 		this.value = value;
21
 		this.value = value;
22
 	}
22
 	}

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

16
 	public final float value;
16
 	public final float value;
17
 	
17
 	
18
 	public ConstantFloatExpression(CodePosition position, float value) {
18
 	public ConstantFloatExpression(CodePosition position, float value) {
19
-		super(position, BasicTypeID.FLOAT);
19
+		super(position, BasicTypeID.FLOAT, null);
20
 		
20
 		
21
 		this.value = value;
21
 		this.value = value;
22
 	}
22
 	}

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

16
 	public final int value;
16
 	public final int value;
17
 	
17
 	
18
 	public ConstantIntExpression(CodePosition position, int value) {
18
 	public ConstantIntExpression(CodePosition position, int value) {
19
-		super(position, BasicTypeID.INT);
19
+		super(position, BasicTypeID.INT, null);
20
 		
20
 		
21
 		this.value = value;
21
 		this.value = value;
22
 	}
22
 	}

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

16
 	public final long value;
16
 	public final long value;
17
 	
17
 	
18
 	public ConstantLongExpression(CodePosition position, long value) {
18
 	public ConstantLongExpression(CodePosition position, long value) {
19
-		super(position, BasicTypeID.LONG);
19
+		super(position, BasicTypeID.LONG, null);
20
 		
20
 		
21
 		this.value = value;
21
 		this.value = value;
22
 	}
22
 	}

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

16
 	public final byte value;
16
 	public final byte value;
17
 	
17
 	
18
 	public ConstantSByteExpression(CodePosition position, byte value) {
18
 	public ConstantSByteExpression(CodePosition position, byte value) {
19
-		super(position, BasicTypeID.SBYTE);
19
+		super(position, BasicTypeID.SBYTE, null);
20
 		
20
 		
21
 		this.value = value;
21
 		this.value = value;
22
 	}
22
 	}

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

16
 	public final short value;
16
 	public final short value;
17
 	
17
 	
18
 	public ConstantShortExpression(CodePosition position, short value) {
18
 	public ConstantShortExpression(CodePosition position, short value) {
19
-		super(position, BasicTypeID.SHORT);
19
+		super(position, BasicTypeID.SHORT, null);
20
 		
20
 		
21
 		this.value = value;
21
 		this.value = value;
22
 	}
22
 	}

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

16
 	public final String value;
16
 	public final String value;
17
 	
17
 	
18
 	public ConstantStringExpression(CodePosition position, String value) {
18
 	public ConstantStringExpression(CodePosition position, String value) {
19
-		super(position, BasicTypeID.STRING);
19
+		super(position, BasicTypeID.STRING, null);
20
 		
20
 		
21
 		this.value = value;
21
 		this.value = value;
22
 	}
22
 	}

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

16
 	public final int value;
16
 	public final int value;
17
 	
17
 	
18
 	public ConstantUIntExpression(CodePosition position, int value) {
18
 	public ConstantUIntExpression(CodePosition position, int value) {
19
-		super(position, BasicTypeID.UINT);
19
+		super(position, BasicTypeID.UINT, null);
20
 		
20
 		
21
 		this.value = value;
21
 		this.value = value;
22
 	}
22
 	}

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

16
 	public final long value;
16
 	public final long value;
17
 	
17
 	
18
 	public ConstantULongExpression(CodePosition position, long value) {
18
 	public ConstantULongExpression(CodePosition position, long value) {
19
-		super(position, BasicTypeID.ULONG);
19
+		super(position, BasicTypeID.ULONG, null);
20
 		
20
 		
21
 		this.value = value;
21
 		this.value = value;
22
 	}
22
 	}

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

16
 	public final short value;
16
 	public final short value;
17
 	
17
 	
18
 	public ConstantUShortExpression(CodePosition position, short value) {
18
 	public ConstantUShortExpression(CodePosition position, short value) {
19
-		super(position, BasicTypeID.USHORT);
19
+		super(position, BasicTypeID.USHORT, null);
20
 		
20
 		
21
 		this.value = value;
21
 		this.value = value;
22
 	}
22
 	}

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

21
 	public final CallArguments arguments;
21
 	public final CallArguments arguments;
22
 	
22
 	
23
 	public ConstructorSuperCallExpression(CodePosition position, ITypeID type, ConstructorMember constructor, CallArguments arguments, TypeScope scope) {
23
 	public ConstructorSuperCallExpression(CodePosition position, ITypeID type, ConstructorMember constructor, CallArguments arguments, TypeScope scope) {
24
-		super(position, BasicTypeID.VOID);
24
+		super(position, BasicTypeID.VOID, binaryThrow(position, constructor.header.thrownType, multiThrow(position, arguments.arguments)));
25
 		
25
 		
26
 		this.objectType = type;
26
 		this.objectType = type;
27
 		this.constructor = constructor;
27
 		this.constructor = constructor;

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

21
 	public final CallArguments arguments;
21
 	public final CallArguments arguments;
22
 	
22
 	
23
 	public ConstructorThisCallExpression(CodePosition position, ITypeID type, ConstructorMember constructor, CallArguments arguments, TypeScope scope) {
23
 	public ConstructorThisCallExpression(CodePosition position, ITypeID type, ConstructorMember constructor, CallArguments arguments, TypeScope scope) {
24
-		super(position, BasicTypeID.VOID);
24
+		super(position, BasicTypeID.VOID, binaryThrow(position, constructor.header.thrownType, multiThrow(position, arguments.arguments)));
25
 		
25
 		
26
 		arguments = arguments.normalize(position, scope, constructor.header);
26
 		arguments = arguments.normalize(position, scope, constructor.header);
27
 		
27
 		

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

19
 	public final EnumConstantMember value;
19
 	public final EnumConstantMember value;
20
 	
20
 	
21
 	public EnumConstantExpression(CodePosition position, ITypeID type, EnumConstantMember value) {
21
 	public EnumConstantExpression(CodePosition position, ITypeID type, EnumConstantMember value) {
22
-		super(position, type);
22
+		super(position, type, null);
23
 		
23
 		
24
 		this.value = value;
24
 		this.value = value;
25
 	}
25
 	}
26
 	
26
 	
27
 	public EnumConstantExpression(CodePosition position, GlobalTypeRegistry registry, EnumDefinition type, EnumConstantMember value) {
27
 	public EnumConstantExpression(CodePosition position, GlobalTypeRegistry registry, EnumDefinition type, EnumConstantMember value) {
28
-		super(position, registry.getForDefinition(type, null));
28
+		super(position, registry.getForDefinition(type), null);
29
 		
29
 		
30
 		this.value = value;
30
 		this.value = value;
31
 	}
31
 	}

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

16
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
16
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
17
 import org.openzen.zenscript.shared.CodePosition;
17
 import org.openzen.zenscript.shared.CodePosition;
18
 import org.openzen.zenscript.codemodel.scope.TypeScope;
18
 import org.openzen.zenscript.codemodel.scope.TypeScope;
19
+import org.openzen.zenscript.shared.CompileException;
20
+import org.openzen.zenscript.shared.CompileExceptionCode;
19
 
21
 
20
 /**
22
 /**
21
  *
23
  *
24
 public abstract class Expression implements IPartialExpression {
26
 public abstract class Expression implements IPartialExpression {
25
 	public final CodePosition position;
27
 	public final CodePosition position;
26
 	public final ITypeID type;
28
 	public final ITypeID type;
29
+	public final ITypeID thrownType;
27
 	
30
 	
28
-	public Expression(CodePosition position, ITypeID type) {
31
+	public Expression(CodePosition position, ITypeID type, ITypeID thrownType) {
29
 		this.position = position;
32
 		this.position = position;
30
 		this.type = type;
33
 		this.type = type;
31
-	}
32
-	
33
-	public ITypeID getType() {
34
-		return type;
34
+		this.thrownType = thrownType;
35
 	}
35
 	}
36
 	
36
 	
37
 	public abstract <T> T accept(ExpressionVisitor<T> visitor);
37
 	public abstract <T> T accept(ExpressionVisitor<T> visitor);
84
 	public ITypeID[] getGenericCallTypes() {
84
 	public ITypeID[] getGenericCallTypes() {
85
 		return null;
85
 		return null;
86
 	}
86
 	}
87
+	
88
+	public static ITypeID binaryThrow(CodePosition position, ITypeID left, ITypeID right) {
89
+		if (left == right)
90
+			return left;
91
+		else if (left == null)
92
+			return right;
93
+		else if (right == null)
94
+			return left;
95
+		else
96
+			throw new CompileException(position, CompileExceptionCode.DIFFERENT_EXCEPTIONS, "two different exceptions in same operation: " + left.toString() + " and " + right.toString());
97
+	}
98
+	
99
+	public static ITypeID multiThrow(CodePosition position, Expression[] expressions) {
100
+		ITypeID result = null;
101
+		for (Expression expression : expressions)
102
+			result = binaryThrow(position, result, expression.thrownType);
103
+		return result;
104
+	}
87
 }
105
 }

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

128
 	
128
 	
129
 	public T visitThis(ThisExpression expression);
129
 	public T visitThis(ThisExpression expression);
130
 	
130
 	
131
+	public T visitTryConvert(TryConvertExpression expression);
132
+	
133
+	public T visitTryRethrowAsException(TryRethrowAsExceptionExpression expression);
134
+	
135
+	public T visitTryRethrowAsResult(TryRethrowAsResultExpression expression);
136
+	
137
+	public T visitVariantValue(VariantValueExpression expression);
138
+	
131
 	public T visitWrapOptional(WrapOptionalExpression expression);
139
 	public T visitWrapOptional(WrapOptionalExpression expression);
132
 }
140
 }

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

24
 			FunctionTypeID type,
24
 			FunctionTypeID type,
25
 			LambdaClosure closure,
25
 			LambdaClosure closure,
26
 			Statement body) {
26
 			Statement body) {
27
-		super(position, type);
27
+		super(position, type, body.thrownType);
28
 		
28
 		
29
 		this.header = type.header;
29
 		this.header = type.header;
30
 		this.closure = closure;
30
 		this.closure = closure;

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

18
 	public final CompareType operator;
18
 	public final CompareType operator;
19
 	
19
 	
20
 	public GenericCompareExpression(CodePosition position, Expression value, CompareType operator) {
20
 	public GenericCompareExpression(CodePosition position, Expression value, CompareType operator) {
21
-		super(position, BasicTypeID.BOOL);
21
+		super(position, BasicTypeID.BOOL, value.thrownType);
22
 		
22
 		
23
 		this.value = value;
23
 		this.value = value;
24
 		this.operator = operator;
24
 		this.operator = operator;

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

23
 	public final FieldMember field;
23
 	public final FieldMember field;
24
 	
24
 	
25
 	public GetFieldExpression(CodePosition position, Expression target, FieldMember field) {
25
 	public GetFieldExpression(CodePosition position, Expression target, FieldMember field) {
26
-		super(position, field.type);
26
+		super(position, field.type, target.thrownType);
27
 		
27
 		
28
 		this.target = target;
28
 		this.target = target;
29
 		this.field = field;
29
 		this.field = field;

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

17
 	public final FunctionParameter parameter;
17
 	public final FunctionParameter parameter;
18
 	
18
 	
19
 	public GetFunctionParameterExpression(CodePosition position, FunctionParameter parameter) {
19
 	public GetFunctionParameterExpression(CodePosition position, FunctionParameter parameter) {
20
-		super(position, parameter.type);
20
+		super(position, parameter.type, null);
21
 		
21
 		
22
 		this.parameter = parameter;
22
 		this.parameter = parameter;
23
 	}
23
 	}

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

17
 	public final VarStatement variable;
17
 	public final VarStatement variable;
18
 	
18
 	
19
 	public GetLocalVariableExpression(CodePosition position, VarStatement variable) {
19
 	public GetLocalVariableExpression(CodePosition position, VarStatement variable) {
20
-		super(position, variable.type);
20
+		super(position, variable.type, null);
21
 		
21
 		
22
 		this.variable = variable;
22
 		this.variable = variable;
23
 	}
23
 	}

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

19
 	public final FieldMember field;
19
 	public final FieldMember field;
20
 	
20
 	
21
 	public GetStaticFieldExpression(CodePosition position, FieldMember field) {
21
 	public GetStaticFieldExpression(CodePosition position, FieldMember field) {
22
-		super(position, field.type);
22
+		super(position, field.type, null);
23
 		
23
 		
24
 		this.field = field;
24
 		this.field = field;
25
 	}
25
 	}

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

17
 	public final GetterMember getter;
17
 	public final GetterMember getter;
18
 	
18
 	
19
 	public GetterExpression(CodePosition position, Expression target, GetterMember getter) {
19
 	public GetterExpression(CodePosition position, Expression target, GetterMember getter) {
20
-		super(position, getter.type);
20
+		super(position, getter.type, target.thrownType);
21
 		
21
 		
22
 		this.target = target;
22
 		this.target = target;
23
 		this.getter = getter;
23
 		this.getter = getter;

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

17
 	public final Expression resolution;
17
 	public final Expression resolution;
18
 	
18
 	
19
 	public GlobalCallExpression(CodePosition position, String name, CallArguments arguments, Expression resolution) {
19
 	public GlobalCallExpression(CodePosition position, String name, CallArguments arguments, Expression resolution) {
20
-		super(position, resolution.type);
20
+		super(position, resolution.type, resolution.thrownType);
21
 		
21
 		
22
 		this.name = name;
22
 		this.name = name;
23
 		this.arguments = arguments;
23
 		this.arguments = arguments;

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

16
 	public final Expression resolution;
16
 	public final Expression resolution;
17
 	
17
 	
18
 	public GlobalExpression(CodePosition position, String name, Expression resolution) {
18
 	public GlobalExpression(CodePosition position, String name, Expression resolution) {
19
-		super(position, resolution.type);
19
+		super(position, resolution.type, resolution.thrownType);
20
 		
20
 		
21
 		this.name = name;
21
 		this.name = name;
22
 		this.resolution = resolution;
22
 		this.resolution = resolution;

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

16
 	public final Expression value;
16
 	public final Expression value;
17
 	
17
 	
18
 	public InterfaceCastExpression(CodePosition position, Expression value, ITypeID toType) {
18
 	public InterfaceCastExpression(CodePosition position, Expression value, ITypeID toType) {
19
-		super(position, toType);
19
+		super(position, toType, value.thrownType);
20
 		
20
 		
21
 		this.value = value;
21
 		this.value = value;
22
 	}
22
 	}

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

18
 	public final ITypeID isType;
18
 	public final ITypeID isType;
19
 	
19
 	
20
 	public IsExpression(CodePosition position, Expression value, ITypeID type) {
20
 	public IsExpression(CodePosition position, Expression value, ITypeID type) {
21
-		super(position, BasicTypeID.BOOL);
21
+		super(position, BasicTypeID.BOOL, value.thrownType);
22
 		
22
 		
23
 		this.value = value;
23
 		this.value = value;
24
 		this.isType = type;
24
 		this.isType = type;

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

16
 	public final Expression value;
16
 	public final Expression value;
17
 	
17
 	
18
 	public MakeConstExpression(CodePosition position, Expression value, ITypeID constType) {
18
 	public MakeConstExpression(CodePosition position, Expression value, ITypeID constType) {
19
-		super(position, constType);
19
+		super(position, constType, value.thrownType);
20
 		
20
 		
21
 		this.value = value;
21
 		this.value = value;
22
 	}
22
 	}

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

21
 			Expression[] keys,
21
 			Expression[] keys,
22
 			Expression[] values,
22
 			Expression[] values,
23
 			ITypeID type) {
23
 			ITypeID type) {
24
-		super(position, type);
24
+		super(position, type, binaryThrow(position, multiThrow(position, keys), multiThrow(position, values)));
25
 		
25
 		
26
 		this.keys = keys;
26
 		this.keys = keys;
27
 		this.values = values;
27
 		this.values = values;

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

18
 	public final Case[] cases;
18
 	public final Case[] cases;
19
 	
19
 	
20
 	public MatchExpression(CodePosition position, Expression value, ITypeID type, Case[] cases) {
20
 	public MatchExpression(CodePosition position, Expression value, ITypeID type, Case[] cases) {
21
-		super(position, type);
21
+		super(position, type, binaryThrow(position, value.thrownType, getThrownType(position, cases)));
22
 		
22
 		
23
 		this.value = value;
23
 		this.value = value;
24
 		this.cases = cases;
24
 		this.cases = cases;
38
 			this.value = value;
38
 			this.value = value;
39
 		}
39
 		}
40
 	}
40
 	}
41
+	
42
+	private static ITypeID getThrownType(CodePosition position, Case[] cases) {
43
+		if (cases.length == 0)
44
+			return null;
45
+		
46
+		ITypeID result = cases[0].value.thrownType;
47
+		for (int i = 1; i < cases.length; i++)
48
+			result = binaryThrow(position, result, cases[i].value.thrownType);
49
+		
50
+		return result;
51
+	}
41
 }
52
 }

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

18
 	public final CallArguments arguments;
18
 	public final CallArguments arguments;
19
 	
19
 	
20
 	public NewExpression(CodePosition position, ITypeID type, ConstructorMember constructor, CallArguments arguments) {
20
 	public NewExpression(CodePosition position, ITypeID type, ConstructorMember constructor, CallArguments arguments) {
21
-		super(position, type);
21
+		super(position, type, binaryThrow(position, constructor.header.thrownType, multiThrow(position, arguments.arguments)));
22
 		
22
 		
23
 		this.constructor = constructor;
23
 		this.constructor = constructor;
24
 		this.arguments = arguments;
24
 		this.arguments = arguments;

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

15
  */
15
  */
16
 public class NullExpression extends Expression {
16
 public class NullExpression extends Expression {
17
 	public NullExpression(CodePosition position) {
17
 	public NullExpression(CodePosition position) {
18
-		super(position, BasicTypeID.NULL);
18
+		super(position, BasicTypeID.NULL, null);
19
 	}
19
 	}
20
 	
20
 	
21
 	public NullExpression(CodePosition position, ITypeID optionalType) {
21
 	public NullExpression(CodePosition position, ITypeID optionalType) {
22
-		super(position, optionalType);
22
+		super(position, optionalType, null);
23
 	}
23
 	}
24
 
24
 
25
 	@Override
25
 	@Override

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

17
 	public final Expression right;
17
 	public final Expression right;
18
 	
18
 	
19
 	public OrOrExpression(CodePosition position, Expression left, Expression right) {
19
 	public OrOrExpression(CodePosition position, Expression left, Expression right) {
20
-		super(position, BasicTypeID.BOOL);
20
+		super(position, BasicTypeID.BOOL, binaryThrow(position, left.thrownType, right.thrownType));
21
 		
21
 		
22
 		this.left = left;
22
 		this.left = left;
23
 		this.right = right;
23
 		this.right = right;

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

20
 	public final OperatorMember member;
20
 	public final OperatorMember member;
21
 	
21
 	
22
 	public PostCallExpression(CodePosition position, Expression target, OperatorMember member, FunctionHeader instancedHeader) {
22
 	public PostCallExpression(CodePosition position, Expression target, OperatorMember member, FunctionHeader instancedHeader) {
23
-		super(position, instancedHeader.returnType);
23
+		super(position, instancedHeader.returnType, binaryThrow(position, member.header.thrownType, target.thrownType));
24
 		
24
 		
25
 		if (member.operator != OperatorType.DECREMENT && member.operator != OperatorType.INCREMENT)
25
 		if (member.operator != OperatorType.DECREMENT && member.operator != OperatorType.INCREMENT)
26
 			throw new IllegalArgumentException("Operator must be increment or decrement");
26
 			throw new IllegalArgumentException("Operator must be increment or decrement");

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

17
 	public final Expression to;
17
 	public final Expression to;
18
 	
18
 	
19
 	public RangeExpression(CodePosition position, GlobalTypeRegistry registry, Expression from, Expression to) {
19
 	public RangeExpression(CodePosition position, GlobalTypeRegistry registry, Expression from, Expression to) {
20
-		super(position, registry.getRange(from.getType(), to.getType()));
20
+		super(position, registry.getRange(from.type, to.type), binaryThrow(position, from.thrownType, to.thrownType));
21
 	
21
 	
22
 		this.from = from;
22
 		this.from = from;
23
 		this.to = to;
23
 		this.to = to;

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

18
 	public final boolean inverted;
18
 	public final boolean inverted;
19
 	
19
 	
20
 	public SameObjectExpression(CodePosition position, Expression left, Expression right, boolean inverted) {
20
 	public SameObjectExpression(CodePosition position, Expression left, Expression right, boolean inverted) {
21
-		super(position, BasicTypeID.BOOL);
21
+		super(position, BasicTypeID.BOOL, binaryThrow(position, left.thrownType, right.thrownType));
22
 		
22
 		
23
 		this.left = left;
23
 		this.left = left;
24
 		this.right = right;
24
 		this.right = right;

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

18
 	public final Expression value;
18
 	public final Expression value;
19
 	
19
 	
20
 	public SetFieldExpression(CodePosition position, Expression target, FieldMember field, Expression value) {
20
 	public SetFieldExpression(CodePosition position, Expression target, FieldMember field, Expression value) {
21
-		super(position, field.type);
21
+		super(position, field.type, binaryThrow(position, target.thrownType, value.thrownType));
22
 		
22
 		
23
 		this.target = target;
23
 		this.target = target;
24
 		this.field = field;
24
 		this.field = field;

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

17
 	public final Expression value;
17
 	public final Expression value;
18
 	
18
 	
19
 	public SetFunctionParameterExpression(CodePosition position, FunctionParameter parameter, Expression value) {
19
 	public SetFunctionParameterExpression(CodePosition position, FunctionParameter parameter, Expression value) {
20
-		super(position, parameter.type);
20
+		super(position, parameter.type, value.thrownType);
21
 		
21
 		
22
 		this.parameter = parameter;
22
 		this.parameter = parameter;
23
 		this.value = value;
23
 		this.value = value;

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

17
 	public final Expression value;
17
 	public final Expression value;
18
 	
18
 	
19
 	public SetLocalVariableExpression(CodePosition position, VarStatement variable, Expression value) {
19
 	public SetLocalVariableExpression(CodePosition position, VarStatement variable, Expression value) {
20
-		super(position, variable.type);
20
+		super(position, variable.type, value.thrownType);
21
 		
21
 		
22
 		this.variable = variable;
22
 		this.variable = variable;
23
 		this.value = value;
23
 		this.value = value;

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

17
 	public final Expression value;
17
 	public final Expression value;
18
 	
18
 	
19
 	public SetStaticFieldExpression(CodePosition position, FieldMember field, Expression value) {
19
 	public SetStaticFieldExpression(CodePosition position, FieldMember field, Expression value) {
20
-		super(position, field.type);
20
+		super(position, field.type, value.thrownType);
21
 		
21
 		
22
 		this.field = field;
22
 		this.field = field;
23
 		this.value = value;
23
 		this.value = value;

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

18
 	public final Expression value;
18
 	public final Expression value;
19
 	
19
 	
20
 	public SetterExpression(CodePosition position, Expression target, SetterMember setter, Expression value) {
20
 	public SetterExpression(CodePosition position, Expression target, SetterMember setter, Expression value) {
21
-		super(position, setter.type);
21
+		super(position, setter.type, binaryThrow(position, value.thrownType, setter.header.thrownType));
22
 		
22
 		
23
 		this.target = target;
23
 		this.target = target;
24
 		this.setter = setter;
24
 		this.setter = setter;

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

16
 	public final GetterMember getter;
16
 	public final GetterMember getter;
17
 	
17
 	
18
 	public StaticGetterExpression(CodePosition position, GetterMember getter) {
18
 	public StaticGetterExpression(CodePosition position, GetterMember getter) {
19
-		super(position, getter.type);
19
+		super(position, getter.type, getter.header.thrownType);
20
 		
20
 		
21
 		this.getter = getter;
21
 		this.getter = getter;
22
 	}
22
 	}

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

17
 	public final Expression value;
17
 	public final Expression value;
18
 	
18
 	
19
 	public StaticSetterExpression(CodePosition position, SetterMember setter, Expression value) {
19
 	public StaticSetterExpression(CodePosition position, SetterMember setter, Expression value) {
20
-		super(position, setter.type);
20
+		super(position, setter.type, binaryThrow(position, setter.header.thrownType, value.thrownType));
21
 		
21
 		
22
 		this.setter = setter;
22
 		this.setter = setter;
23
 		this.value = value;
23
 		this.value = value;

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

17
 	public final Expression value;
17
 	public final Expression value;
18
 	
18
 	
19
 	public SupertypeCastExpression(CodePosition position, Expression value, ITypeID type) {
19
 	public SupertypeCastExpression(CodePosition position, Expression value, ITypeID type) {
20
-		super(position, type);
20
+		super(position, type, value.thrownType);
21
 		
21
 		
22
 		this.value = value;
22
 		this.value = value;
23
 	}
23
 	}

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

15
  */
15
  */
16
 public class ThisExpression extends Expression {
16
 public class ThisExpression extends Expression {
17
 	public ThisExpression(CodePosition position, ITypeID type) {
17
 	public ThisExpression(CodePosition position, ITypeID type) {
18
-		super(position, type);
18
+		super(position, type, null);
19
 	}
19
 	}
20
 	
20
 	
21
 	@Override
21
 	@Override

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

1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.ITypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class TryConvertExpression extends Expression {
16
+	public final Expression value;
17
+	
18
+	public TryConvertExpression(CodePosition position, ITypeID type, Expression value) {
19
+		super(position, type, null);
20
+		
21
+		this.value = value;
22
+	}
23
+	
24
+	@Override
25
+	public <T> T accept(ExpressionVisitor<T> visitor) {
26
+		return visitor.visitTryConvert(this);
27
+	}
28
+}

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

1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.ITypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class TryRethrowAsExceptionExpression extends Expression {
16
+	public final Expression value;
17
+	
18
+	public TryRethrowAsExceptionExpression(CodePosition position, ITypeID type, Expression value, ITypeID thrownType) {
19
+		super(position, type, thrownType);
20
+		
21
+		this.value = value;
22
+	}
23
+
24
+	@Override
25
+	public <T> T accept(ExpressionVisitor<T> visitor) {
26
+		return visitor.visitTryRethrowAsException(this);
27
+	}
28
+}

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

1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.type.ITypeID;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class TryRethrowAsResultExpression extends Expression {
16
+	public final Expression value;
17
+	
18
+	public TryRethrowAsResultExpression(CodePosition position, ITypeID type, Expression value) {
19
+		super(position, type, null);
20
+		
21
+		this.value = value;
22
+	}
23
+
24
+	@Override
25
+	public <T> T accept(ExpressionVisitor<T> visitor) {
26
+		return visitor.visitTryRethrowAsResult(this);
27
+	}
28
+}

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

6
 package org.openzen.zenscript.codemodel.expression;
6
 package org.openzen.zenscript.codemodel.expression;
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
-import org.openzen.zenscript.codemodel.OperatorType;
10
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
9
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
11
 import org.openzen.zenscript.codemodel.scope.TypeScope;
10
 import org.openzen.zenscript.codemodel.scope.TypeScope;
12
 import org.openzen.zenscript.codemodel.type.ITypeID;
11
 import org.openzen.zenscript.codemodel.type.ITypeID;
25
 	}
24
 	}
26
 	
25
 	
27
 	public VariantValueExpression(CodePosition position, ITypeID variantType, VariantDefinition.Option option, Expression[] arguments) {
26
 	public VariantValueExpression(CodePosition position, ITypeID variantType, VariantDefinition.Option option, Expression[] arguments) {
28
-		super(position, variantType);
27
+		super(position, variantType, arguments == null ? null : multiThrow(position, arguments));
29
 		
28
 		
30
 		this.option = option;
29
 		this.option = option;
31
 		this.arguments = null;
30
 		this.arguments = null;
32
 	}
31
 	}
33
 	
32
 	
33
+	public int getNumberOfArguments() {
34
+		return arguments == null ? 0 : arguments.length;
35
+	}
36
+	
34
 	@Override
37
 	@Override
35
 	public Expression call(CodePosition position, TypeScope scope, List<ITypeID> hints, CallArguments arguments) {
38
 	public Expression call(CodePosition position, TypeScope scope, List<ITypeID> hints, CallArguments arguments) {
39
+		if (arguments != null)
40
+			return super.call(position, scope, hints, arguments);
41
+		
36
 		return new VariantValueExpression(position, type, option, arguments.arguments);
42
 		return new VariantValueExpression(position, type, option, arguments.arguments);
37
 	}
43
 	}
38
-
44
+	
39
 	@Override
45
 	@Override
40
 	public <T> T accept(ExpressionVisitor<T> visitor) {
46
 	public <T> T accept(ExpressionVisitor<T> visitor) {
41
-		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
47
+		return visitor.visitVariantValue(this);
42
 	}
48
 	}
43
 }
49
 }

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

16
 	public final Expression value;
16
 	public final Expression value;
17
 	
17
 	
18
 	public WrapOptionalExpression(CodePosition position, Expression value, ITypeID optionalType) {
18
 	public WrapOptionalExpression(CodePosition position, Expression value, ITypeID optionalType) {
19
-		super(position, optionalType);
19
+		super(position, optionalType, value.thrownType);
20
 		
20
 		
21
 		if (value.type.isOptional())
21
 		if (value.type.isOptional())
22
 			throw new IllegalArgumentException("Value is already optional");
22
 			throw new IllegalArgumentException("Value is already optional");

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

26
  */
26
  */
27
 public class ConstructorMember extends FunctionalMember {
27
 public class ConstructorMember extends FunctionalMember {
28
 	public ConstructorMember(CodePosition position, HighLevelDefinition definition, int modifiers, FunctionHeader header) {
28
 	public ConstructorMember(CodePosition position, HighLevelDefinition definition, int modifiers, FunctionHeader header) {
29
-		super(position, definition, modifiers, "this", new FunctionHeader(header.typeParameters, BasicTypeID.VOID, header.parameters));
29
+		super(position, definition, modifiers, "this", new FunctionHeader(header.typeParameters, BasicTypeID.VOID, header.thrownType, header.parameters));
30
 	}
30
 	}
31
 	
31
 	
32
 	public boolean isConstructorForwarded() {
32
 	public boolean isConstructorForwarded() {

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

6
 package org.openzen.zenscript.codemodel.statement;
6
 package org.openzen.zenscript.codemodel.statement;
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
+import org.openzen.zenscript.codemodel.expression.Expression;
10
+import org.openzen.zenscript.codemodel.type.ITypeID;
9
 import org.openzen.zenscript.shared.CodePosition;
11
 import org.openzen.zenscript.shared.CodePosition;
10
 
12
 
11
 /**
13
 /**
16
 	public final List<Statement> statements;
18
 	public final List<Statement> statements;
17
 	
19
 	
18
 	public BlockStatement(CodePosition position, List<Statement> statements) {
20
 	public BlockStatement(CodePosition position, List<Statement> statements) {
19
-		super(position);
21
+		super(position, getThrownType(statements));
20
 		
22
 		
21
 		this.statements = statements;
23
 		this.statements = statements;
22
 	}
24
 	}
25
 	public <T> T accept(StatementVisitor<T> visitor) {
27
 	public <T> T accept(StatementVisitor<T> visitor) {
26
 		return visitor.visitBlock(this);
28
 		return visitor.visitBlock(this);
27
 	}
29
 	}
30
+	
31
+	private static ITypeID getThrownType(List<Statement> statements) {
32
+		ITypeID result = null;
33
+		for (Statement statement : statements)
34
+			result = Expression.binaryThrow(statement.position, result, statement.thrownType);
35
+		return result;
36
+	}
28
 }
37
 }

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

15
 	public final LoopStatement target;
15
 	public final LoopStatement target;
16
 	
16
 	
17
 	public BreakStatement(CodePosition position, LoopStatement target) {
17
 	public BreakStatement(CodePosition position, LoopStatement target) {
18
-		super(position);
18
+		super(position, null);
19
 		
19
 		
20
 		this.target = target;
20
 		this.target = target;
21
 	}
21
 	}

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

15
 	public final LoopStatement target;
15
 	public final LoopStatement target;
16
 	
16
 	
17
 	public ContinueStatement(CodePosition position, LoopStatement target) {
17
 	public ContinueStatement(CodePosition position, LoopStatement target) {
18
-		super(position);
18
+		super(position, null);
19
 		
19
 		
20
 		this.target = target;
20
 		this.target = target;
21
 	}
21
 	}

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

17
 	public final Expression condition;
17
 	public final Expression condition;
18
 	
18
 	
19
 	public DoWhileStatement(CodePosition position, String label, Expression condition) {
19
 	public DoWhileStatement(CodePosition position, String label, Expression condition) {
20
-		super(position, label);
20
+		super(position, label, null); // TODO: thrown type
21
 		
21
 		
22
 		this.condition = condition;
22
 		this.condition = condition;
23
 	}
23
 	}

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

13
  */
13
  */
14
 public class EmptyStatement extends Statement {
14
 public class EmptyStatement extends Statement {
15
 	public EmptyStatement(CodePosition position) {
15
 	public EmptyStatement(CodePosition position) {
16
-		super(position);
16
+		super(position, null);
17
 	}
17
 	}
18
 
18
 
19
 	@Override
19
 	@Override

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

16
 	public final Expression expression;
16
 	public final Expression expression;
17
 	
17
 	
18
 	public ExpressionStatement(CodePosition position, Expression expression) {
18
 	public ExpressionStatement(CodePosition position, Expression expression) {
19
-		super(position);
19
+		super(position, expression.thrownType);
20
 		
20
 		
21
 		this.expression = expression;
21
 		this.expression = expression;
22
 	}
22
 	}

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

20
 	public Statement content;
20
 	public Statement content;
21
 	
21
 	
22
 	public ForeachStatement(CodePosition position, VarStatement[] loopVariables, IIteratorMember iterator, Expression list) {
22
 	public ForeachStatement(CodePosition position, VarStatement[] loopVariables, IIteratorMember iterator, Expression list) {
23
-		super(position, loopVariables[0].name);
23
+		super(position, loopVariables[0].name, null); // TODO: thrown type
24
 		
24
 		
25
 		this.loopVariables = loopVariables;
25
 		this.loopVariables = loopVariables;
26
 		this.list = list;
26
 		this.list = list;

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

6
 package org.openzen.zenscript.codemodel.statement;
6
 package org.openzen.zenscript.codemodel.statement;
7
 
7
 
8
 import org.openzen.zenscript.codemodel.expression.Expression;
8
 import org.openzen.zenscript.codemodel.expression.Expression;
9
+import org.openzen.zenscript.codemodel.type.ITypeID;
9
 import org.openzen.zenscript.shared.CodePosition;
10
 import org.openzen.zenscript.shared.CodePosition;
10
 
11
 
11
 /**
12
 /**
18
 	public final Statement onElse;
19
 	public final Statement onElse;
19
 	
20
 	
20
 	public IfStatement(CodePosition position, Expression condition, Statement onThen, Statement onElse) {
21
 	public IfStatement(CodePosition position, Expression condition, Statement onThen, Statement onElse) {
21
-		super(position);
22
+		super(position, getThrownType(condition, onThen, onElse));
22
 		
23
 		
23
 		this.condition = condition;
24
 		this.condition = condition;
24
 		this.onThen = onThen;
25
 		this.onThen = onThen;
29
 	public <T> T accept(StatementVisitor<T> visitor) {
30
 	public <T> T accept(StatementVisitor<T> visitor) {
30
 		return visitor.visitIf(this);
31
 		return visitor.visitIf(this);
31
 	}
32
 	}
33
+	
34
+	private static ITypeID getThrownType(Expression condition, Statement onThen, Statement onElse) {
35
+		ITypeID result = Expression.binaryThrow(onThen.position, condition.thrownType, onThen.thrownType);
36
+		if (onElse != null)
37
+			result = Expression.binaryThrow(onElse.position, result, onElse.thrownType);
38
+		return result;
39
+	}
32
 }
40
 }

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

17
 	public final Statement content;
17
 	public final Statement content;
18
 	
18
 	
19
 	public LockStatement(CodePosition position, Expression object, Statement content) {
19
 	public LockStatement(CodePosition position, Expression object, Statement content) {
20
-		super(position);
20
+		super(position, Expression.binaryThrow(position, object.thrownType, content.thrownType));
21
 		
21
 		
22
 		this.object = object;
22
 		this.object = object;
23
 		this.content = content;
23
 		this.content = content;

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

5
  */
5
  */
6
 package org.openzen.zenscript.codemodel.statement;
6
 package org.openzen.zenscript.codemodel.statement;
7
 
7
 
8
+import org.openzen.zenscript.codemodel.type.ITypeID;
8
 import org.openzen.zenscript.shared.CodePosition;
9
 import org.openzen.zenscript.shared.CodePosition;
9
 
10
 
10
 /**
11
 /**
14
 public abstract class LoopStatement extends Statement {
15
 public abstract class LoopStatement extends Statement {
15
 	public String label;
16
 	public String label;
16
 	
17
 	
17
-	public LoopStatement(CodePosition position, String label) {
18
-		super(position);
18
+	public LoopStatement(CodePosition position, String label, ITypeID thrownType) {
19
+		super(position, thrownType);
19
 		
20
 		
20
 		this.label = label;
21
 		this.label = label;
21
 	}
22
 	}

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

18
 	public final Expression value;
18
 	public final Expression value;
19
 	
19
 	
20
 	public ReturnStatement(CodePosition position, Expression value) {
20
 	public ReturnStatement(CodePosition position, Expression value) {
21
-		super(position);
21
+		super(position, value == null ? null : value.thrownType);
22
 		
22
 		
23
 		this.value = value;
23
 		this.value = value;
24
 	}
24
 	}

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

18
  */
18
  */
19
 public abstract class Statement extends Taggable {
19
 public abstract class Statement extends Taggable {
20
 	public final CodePosition position;
20
 	public final CodePosition position;
21
+	public final ITypeID thrownType;
21
 	
22
 	
22
-	public Statement(CodePosition position) {
23
+	public Statement(CodePosition position, ITypeID thrownType) {
23
 		this.position = position;
24
 		this.position = position;
25
+		this.thrownType = thrownType;
24
 	}
26
 	}
25
 	
27
 	
26
 	public ITypeID getReturnType() {
28
 	public ITypeID getReturnType() {

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

19
 	public final List<SwitchCase> cases = new ArrayList<>();
19
 	public final List<SwitchCase> cases = new ArrayList<>();
20
 	
20
 	
21
 	public SwitchStatement(CodePosition position, String label, Expression value) {
21
 	public SwitchStatement(CodePosition position, String label, Expression value) {
22
-		super(position, label);
22
+		super(position, label, null); // TODO: thrown type
23
 		
23
 		
24
 		this.value = value;
24
 		this.value = value;
25
 	}
25
 	}

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

16
 	public final Expression value;
16
 	public final Expression value;
17
 	
17
 	
18
 	public ThrowStatement(CodePosition position, Expression value) {
18
 	public ThrowStatement(CodePosition position, Expression value) {
19
-		super(position);
19
+		super(position, value.type);
20
 		
20
 		
21
 		this.value = value;
21
 		this.value = value;
22
 	}
22
 	}

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

24
 			Statement content,
24
 			Statement content,
25
 			List<CatchClause> catchClauses,
25
 			List<CatchClause> catchClauses,
26
 			Statement finallyClause) {
26
 			Statement finallyClause) {
27
-		super(position);
27
+		super(position, null); // TODO: thrown type
28
 		
28
 		
29
 		this.resource = resource;
29
 		this.resource = resource;
30
 		this.content = content;
30
 		this.content = content;

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

20
 	public final boolean isFinal;
20
 	public final boolean isFinal;
21
 	
21
 	
22
 	public VarStatement(CodePosition position, String name, ITypeID type, Expression initializer, boolean isFinal) {
22
 	public VarStatement(CodePosition position, String name, ITypeID type, Expression initializer, boolean isFinal) {
23
-		super(position);
23
+		super(position, initializer == null ? null : initializer.thrownType);
24
 		
24
 		
25
 		this.name = name;
25
 		this.name = name;
26
 		this.type = type;
26
 		this.type = type;

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

17
 	public Statement content;
17
 	public Statement content;
18
 	
18
 	
19
 	public WhileStatement(CodePosition position, String label, Expression condition) {
19
 	public WhileStatement(CodePosition position, String label, Expression condition) {
20
-		super(position, label);
20
+		super(position, label, null); // TODO: thrown type
21
 		
21
 		
22
 		this.condition = condition;
22
 		this.condition = condition;
23
 	}
23
 	}

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

7
 
7
 
8
 import java.util.Map;
8
 import java.util.Map;
9
 import java.util.Objects;
9
 import java.util.Objects;
10
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
11
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
12
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
12
 
13
 
46
 		return true;
47
 		return true;
47
 	}
48
 	}
48
 	
49
 	
50
+	@Override
51
+	public boolean isDefinition(HighLevelDefinition definition) {
52
+		return baseType.isDefinition(definition);
53
+	}
54
+	
49
 	@Override
55
 	@Override
50
 	public ITypeID unwrap() {
56
 	public ITypeID unwrap() {
51
 		return baseType;
57
 		return baseType;

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

151
 		return definition instanceof VariantDefinition;
151
 		return definition instanceof VariantDefinition;
152
 	}
152
 	}
153
 	
153
 	
154
+	@Override
155
+	public boolean isDefinition(HighLevelDefinition definition) {
156
+		return definition == this.definition;
157
+	}
158
+	
154
 	@Override
159
 	@Override
155
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
160
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
156
 		if (typeParameters != null) {
161
 		if (typeParameters != null) {

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

10
 import java.util.Map;
10
 import java.util.Map;
11
 import org.openzen.zenscript.codemodel.FunctionHeader;
11
 import org.openzen.zenscript.codemodel.FunctionHeader;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
13
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
14
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
14
 import static org.openzen.zenscript.codemodel.type.member.TypeMembers.MODIFIER_CONST;
15
 import static org.openzen.zenscript.codemodel.type.member.TypeMembers.MODIFIER_CONST;
15
 import static org.openzen.zenscript.codemodel.type.member.TypeMembers.MODIFIER_OPTIONAL;
16
 import static org.openzen.zenscript.codemodel.type.member.TypeMembers.MODIFIER_OPTIONAL;
31
 	private final Map<ITypeID, ConstTypeID> constTypes = new HashMap<>();
32
 	private final Map<ITypeID, ConstTypeID> constTypes = new HashMap<>();
32
 	private final Map<ITypeID, OptionalTypeID> optionalTypes = new HashMap<>();
33
 	private final Map<ITypeID, OptionalTypeID> optionalTypes = new HashMap<>();
33
 	
34
 	
34
-	public GlobalTypeRegistry() {
35
+	public final ZSPackage stdlib;
36
+	
37
+	public GlobalTypeRegistry(ZSPackage stdlib) {
38
+		this.stdlib = stdlib;
39
+		
35
 		arrayTypes.put(ArrayTypeID.INT, ArrayTypeID.INT);
40
 		arrayTypes.put(ArrayTypeID.INT, ArrayTypeID.INT);
36
 		arrayTypes.put(ArrayTypeID.CHAR, ArrayTypeID.CHAR);
41
 		arrayTypes.put(ArrayTypeID.CHAR, ArrayTypeID.CHAR);
37
 		
42
 		
108
 		}
113
 		}
109
 	}
114
 	}
110
 	
115
 	
111
-	public DefinitionTypeID getForDefinition(HighLevelDefinition definition, ITypeID[] genericArguments) {
116
+	public DefinitionTypeID getForDefinition(HighLevelDefinition definition, ITypeID... genericArguments) {
112
 		return this.getForDefinition(definition, genericArguments, Collections.emptyMap());
117
 		return this.getForDefinition(definition, genericArguments, Collections.emptyMap());
113
 	}
118
 	}
114
 	
119
 	

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

6
 package org.openzen.zenscript.codemodel.type;
6
 package org.openzen.zenscript.codemodel.type;
7
 
7
 
8
 import java.util.Map;
8
 import java.util.Map;
9
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
9
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
10
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
10
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
11
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
11
 
12
 
46
 		return false;
47
 		return false;
47
 	}
48
 	}
48
 	
49
 	
50
+	public default boolean isDefinition(HighLevelDefinition definition) {
51
+		return false;
52
+	}
53
+	
49
 	public ITypeID withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments);
54
 	public ITypeID withGenericArguments(GlobalTypeRegistry registry, Map<TypeParameter, ITypeID> arguments);
50
 	
55
 	
51
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters);
56
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters);

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

7
 
7
 
8
 import java.util.Map;
8
 import java.util.Map;
9
 import java.util.Objects;
9
 import java.util.Objects;
10
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
11
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
12
 
13
 
56
 		return baseType.isObjectType();
57
 		return baseType.isObjectType();
57
 	}
58
 	}
58
 	
59
 	
60
+	@Override
61
+	public boolean isDefinition(HighLevelDefinition definition) {
62
+		return baseType.isDefinition(definition);
63
+	}
64
+	
59
 	@Override
65
 	@Override
60
 	public ITypeID unwrap() {
66
 	public ITypeID unwrap() {
61
 		return baseType;
67
 		return baseType;

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

303
 			}
303
 			}
304
 			
304
 			
305
 			for (int i = 0; i < header.parameters.length; i++) {
305
 			for (int i = 0; i < header.parameters.length; i++) {
306
-				if (arguments.arguments[i].getType() != header.parameters[i].type)
306
+				if (arguments.arguments[i].type != header.parameters[i].type)
307
 					continue outer;
307
 					continue outer;
308
 			}
308
 			}
309
 			
309
 			
327
 			}
327
 			}
328
 			
328
 			
329
 			for (int i = 0; i < header.parameters.length; i++) {
329
 			for (int i = 0; i < header.parameters.length; i++) {
330
-				if (!scope.getTypeMembers(arguments.arguments[i].getType()).canCastImplicit(header.parameters[i].type))
330
+				if (!scope.getTypeMembers(arguments.arguments[i].type).canCastImplicit(header.parameters[i].type))
331
 					continue outer;
331
 					continue outer;
332
 			}
332
 			}
333
 			
333
 			

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

67
 	private final GlobalTypeRegistry registry;
67
 	private final GlobalTypeRegistry registry;
68
 	private final TypeMembers members;
68
 	private final TypeMembers members;
69
 	private final LocalMemberCache cache;
69
 	private final LocalMemberCache cache;
70
-
70
+	
71
 	public TypeMemberBuilder(GlobalTypeRegistry registry, TypeMembers members, LocalMemberCache cache) {
71
 	public TypeMemberBuilder(GlobalTypeRegistry registry, TypeMembers members, LocalMemberCache cache) {
72
 		this.registry = registry;
72
 		this.registry = registry;
73
 		this.members = members;
73
 		this.members = members;
204
 		
204
 		
205
 		ClassDefinition definition = new ClassDefinition(BUILTIN, null, "", Modifiers.EXPORT);
205
 		ClassDefinition definition = new ClassDefinition(BUILTIN, null, "", Modifiers.EXPORT);
206
 		members.addConstructor(new ConstructorMember(BUILTIN, definition, 0, new FunctionHeader(VOID)));
206
 		members.addConstructor(new ConstructorMember(BUILTIN, definition, 0, new FunctionHeader(VOID)));
207
-		members.addMethod(new MethodMember(BUILTIN, definition, 0, "getOptional", new FunctionHeader(map.keys, registry.getOptional(valueType), new FunctionParameter[0])));
208
-		members.addMethod(new MethodMember(BUILTIN, definition, 0, "put", new FunctionHeader(map.keys, BasicTypeID.VOID, new FunctionParameter(valueType))));
209
-		members.addMethod(new MethodMember(BUILTIN, definition, 0, "contains", new FunctionHeader(map.keys, BasicTypeID.BOOL, new FunctionParameter[0])));
207
+		members.addMethod(new MethodMember(BUILTIN, definition, 0, "getOptional", new FunctionHeader(map.keys, registry.getOptional(valueType), null, new FunctionParameter[0])));
208
+		members.addMethod(new MethodMember(BUILTIN, definition, 0, "put", new FunctionHeader(map.keys, BasicTypeID.VOID, null, new FunctionParameter(valueType))));
209
+		members.addMethod(new MethodMember(BUILTIN, definition, 0, "contains", new FunctionHeader(map.keys, BasicTypeID.BOOL, null, new FunctionParameter[0])));
210
 		members.addGetter(new GetterMember(BUILTIN, definition, Modifiers.PUBLIC | Modifiers.EXTERN, "objectHashCode", BasicTypeID.INT));
210
 		members.addGetter(new GetterMember(BUILTIN, definition, Modifiers.PUBLIC | Modifiers.EXTERN, "objectHashCode", BasicTypeID.INT));
211
 		return null;
211
 		return null;
212
 	}
212
 	}

+ 3
- 3
Constructor/libraries/collections/src/LinkedList.zs View File

27
 		var node = first;
27
 		var node = first;
28
 		while index > 0 {
28
 		while index > 0 {
29
 			if node == null
29
 			if node == null
30
-				throw new NoSuchElementException("index out of bounds");
30
+				return panic<T>("index out of bounds");
31
 			
31
 			
32
 			node = node.next;
32
 			node = node.next;
33
 		}
33
 		}
34
 		
34
 		
35
 		if node == null
35
 		if node == null
36
-			throw new NoSuchElementException("index out of bounds");
36
+			return panic<T>("index out of bounds");
37
 		
37
 		
38
 		return node.value;
38
 		return node.value;
39
 	}
39
 	}
41
 	public implements Queue<T> {
41
 	public implements Queue<T> {
42
 		poll() as T {
42
 		poll() as T {
43
 			if first == null
43
 			if first == null
44
-				throw new NoSuchElementException("Cannot poll an empty queue");
44
+				return panic<T>("Cannot poll an empty queue");
45
 			
45
 			
46
 			val result = first.value;
46
 			val result = first.value;
47
 			first = first.next;
47
 			first = first.next;

+ 9
- 0
Constructor/libraries/io/src/IOException.zs View File

1
+public class IOException : Exception {
2
+	public this(message as string) {
3
+		super(message);
4
+	}
5
+	
6
+	/*public this(message as string, cause as Exception) {
7
+		super(message, cause);
8
+	}*/
9
+}

+ 3
- 3
Constructor/libraries/io/src/Reader.zs View File

1
 export interface Reader {
1
 export interface Reader {
2
 	~this;
2
 	~this;
3
 	
3
 	
4
-	read() as int;
4
+	read() as int throws IOException;
5
 	
5
 	
6
-	read(buffer as char[]) as int
6
+	read(buffer as char[]) as int throws IOException
7
 		=> read(buffer, 0, buffer.length);
7
 		=> read(buffer, 0, buffer.length);
8
 	
8
 	
9
-	read(buffer as char[], offset as int, length as int) as int;
9
+	read(buffer as char[], offset as int, length as int) as int throws IOException;
10
 }
10
 }

+ 24
- 10
Constructor/libraries/stdlib/src/Result.zs View File

1
 export variant Result<T, E> {
1
 export variant Result<T, E> {
2
-	Success(T),
3
-	Failure(E);
2
+	Ok(T),
3
+	Error(E);
4
 	
4
 	
5
 	public then<R>(fn as function(result as T) as R) as Result<R, E> {
5
 	public then<R>(fn as function(result as T) as R) as Result<R, E> {
6
 		return match this {
6
 		return match this {
7
-			Success(result) => Success(fn(result)),
8
-			Failure(error) => Failure(error)
7
+			Ok(result) => Ok(fn(result)),
8
+			Error(error) => Error(error)
9
 		};
9
 		};
10
 	}
10
 	}
11
 	
11
 	
12
 	public handle<X>(handler as function(error as E) as Result<T, X>) as Result<T, X> {
12
 	public handle<X>(handler as function(error as E) as Result<T, X>) as Result<T, X> {
13
 		return match this {
13
 		return match this {
14
-			Success(result) => Success(result),
15
-			Failure(error) => handler(error)
14
+			Ok(result) => Ok(result),
15
+			Error(error) => handler(error)
16
 		};
16
 		};
17
 	}
17
 	}
18
 	
18
 	
19
 	public expect() as T {
19
 	public expect() as T {
20
 		return match this {
20
 		return match this {
21
-			Success(result) => result,
22
-			Failure(error) => panic<T>("demand with error value")
21
+			Ok(result) => result,
22
+			Error(error) => panic<T>("demand with error value")
23
+		};
24
+	}
25
+	
26
+	public orElse(other as T) as T {
27
+		return match this {
28
+			Ok(result) => result,
29
+			Error(error) => other
30
+		};
31
+	}
32
+	
33
+	public orElse(other as function(error as E) as T) as T {
34
+		return match this {
35
+			Ok(result) => result,
36
+			Error(error) => other(error)
23
 		};
37
 		};
24
 	}
38
 	}
25
 }
39
 }
27
 export expand <T, E : Exception> Result<T, E> {
41
 export expand <T, E : Exception> Result<T, E> {
28
 	public unwrap() as T {
42
 	public unwrap() as T {
29
 		return match this {
43
 		return match this {
30
-			Success(result) => result,
31
-			Failure(error) => { throw error; }
44
+			Ok(result) => result,
45
+			Error(error) => { throw error; }
32
 		};
46
 		};
33
 	}
47
 	}
34
 }
48
 }

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

20
  * @author Hoofdgebruiker
20
  * @author Hoofdgebruiker
21
  */
21
  */
22
 public class ModuleSpace {
22
 public class ModuleSpace {
23
-	public final GlobalTypeRegistry typeRegistry = new GlobalTypeRegistry();
24
-	public final ZSPackage globalsPackage = new ZSPackage("");
25
 	private final ZSPackage rootPackage = new ZSPackage("");
23
 	private final ZSPackage rootPackage = new ZSPackage("");
24
+	private final ZSPackage stdlib = new ZSPackage("");
25
+	public final GlobalTypeRegistry typeRegistry = new GlobalTypeRegistry(stdlib);
26
+	public final ZSPackage globalsPackage = new ZSPackage("");
26
 	private final List<ExpansionDefinition> expansions = new ArrayList<>();
27
 	private final List<ExpansionDefinition> expansions = new ArrayList<>();
27
 	private final Map<String, ISymbol> globals = new HashMap<>();
28
 	private final Map<String, ISymbol> globals = new HashMap<>();
28
 	
29
 	

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

573
         return null;
573
         return null;
574
     }
574
     }
575
 
575
 
576
+	@Override
577
+	public Void visitTryConvert(TryConvertExpression expression) {
578
+		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
579
+	}
580
+
581
+	@Override
582
+	public Void visitTryRethrowAsException(TryRethrowAsExceptionExpression expression) {
583
+		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
584
+	}
585
+
586
+	@Override
587
+	public Void visitTryRethrowAsResult(TryRethrowAsResultExpression expression) {
588
+		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
589
+	}
590
+	
591
+	@Override
592
+	public Void visitVariantValue(VariantValueExpression expression) {
593
+		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
594
+	}
595
+
576
     @Override
596
     @Override
577
     public Void visitWrapOptional(WrapOptionalExpression expression) {
597
     public Void visitWrapOptional(WrapOptionalExpression expression) {
578
-        //TODO What am I supposed to do here?
598
+		// TODO: convert basic types (char, int, float, ...) to their boxed (Character, Integer, Float, ...) counterparts
599
+		// -- any object type values can just be passed as-is
579
         expression.value.accept(this);
600
         expression.value.accept(this);
580
         return null;
601
         return null;
581
     }
602
     }

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


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

Loading…
Cancel
Save