Explorar el Código

- Added try! and try? operators

- WIP on exception handling
Stan Hebben hace 6 años
padre
commit
58c21971e9
Se han modificado 100 ficheros con 453 adiciones y 124 borrados
  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 Ver fichero

@@ -67,6 +67,10 @@ import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
67 67
 import org.openzen.zenscript.codemodel.expression.StaticSetterExpression;
68 68
 import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression;
69 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 74
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
71 75
 import org.openzen.zenscript.codemodel.member.OperatorMember;
72 76
 import org.openzen.zenscript.shared.StringUtils;
@@ -610,6 +614,32 @@ public class ExpressionFormatter implements ExpressionVisitor<ExpressionString>
610 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 643
 	@Override
614 644
 	public ExpressionString visitWrapOptional(WrapOptionalExpression expression) {
615 645
 		return expression.value.accept(this);

+ 1
- 1
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/StatementFormatter.java Ver fichero

@@ -215,7 +215,7 @@ public class StatementFormatter implements StatementVisitor<Void> {
215 215
 				output.append(indent)
216 216
 						.append(settings.indent)
217 217
 						.append("case ")
218
-						.append(switchCase.value.accept(expressionFormatter))
218
+						.append(switchCase.value.accept(new SwitchValueFormatter(settings)))
219 219
 						.append(":\n");
220 220
 			}
221 221
 			for (Statement s : switchCase.statements)

+ 60
- 0
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/SwitchValueFormatter.java Ver fichero

@@ -0,0 +1,60 @@
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 Ver fichero

@@ -27,17 +27,20 @@ public class FunctionHeader {
27 27
 	public final TypeParameter[] typeParameters;
28 28
 	public final ITypeID returnType;
29 29
 	public final FunctionParameter[] parameters;
30
+	public final ITypeID thrownType;
30 31
 	
31 32
 	public FunctionHeader(ITypeID returnType) {
32 33
 		this.typeParameters = null;
33 34
 		this.returnType = returnType;
34 35
 		this.parameters = NO_PARAMETERS;
36
+		this.thrownType = null;
35 37
 	}
36 38
 	
37 39
 	public FunctionHeader(ITypeID returnType, ITypeID... parameterTypes) {
38 40
 		this.typeParameters = null;
39 41
 		this.returnType = returnType;
40 42
 		this.parameters = new FunctionParameter[parameterTypes.length];
43
+		this.thrownType = null;
41 44
 		
42 45
 		for (int i = 0; i < parameterTypes.length; i++)
43 46
 			parameters[i] = new FunctionParameter(parameterTypes[i], null);
@@ -47,12 +50,14 @@ public class FunctionHeader {
47 50
 		this.typeParameters = null;
48 51
 		this.returnType = returnType;
49 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 57
 		this.typeParameters = genericParameters;
54 58
 		this.returnType = returnType;
55 59
 		this.parameters = parameters;
60
+		this.thrownType = thrownType;
56 61
 	}
57 62
 	
58 63
 	public int getNumberOfTypeParameters() {
@@ -70,7 +75,7 @@ public class FunctionHeader {
70 75
 		for (int i = 0; i < parameters.length; i++)
71 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 81
 	public ITypeID[] inferTypes(LocalMemberCache cache, CallArguments arguments, List<ITypeID> resultHint) {
@@ -202,7 +207,7 @@ public class FunctionHeader {
202 207
 			ITypeID modified = this.parameters[i].type.withGenericArguments(registry, arguments);
203 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 213
 	public FunctionHeader withGenericArguments(GlobalTypeRegistry registry, ITypeID[] arguments) {
@@ -229,8 +234,7 @@ public class FunctionHeader {
229 234
 		for (int i = 0; i < lambdaHeader.parameters.length; i++)
230 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 240
 	public FunctionParameter getVariadicParameter() {
@@ -247,11 +251,11 @@ public class FunctionHeader {
247 251
 			return parameters.length + " parameters expected but " + arguments.arguments.length + " given.";
248 252
 		
249 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 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 Ver fichero

@@ -38,7 +38,7 @@ public class FunctionDefinition extends HighLevelDefinition {
38 38
 	public void setHeader(FunctionHeader header) {
39 39
 		this.header = header;
40 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 42
 		addMember(caller = new OperatorMember(position, this, modifiers | Modifiers.STATIC, OperatorType.CALL, header));
43 43
 		callerGroup.addMethod(caller, TypeMemberPriority.SPECIFIED);
44 44
 	}

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

@@ -59,6 +59,10 @@ public class ZSPackage {
59 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 66
 	public HighLevelDefinition getImport(List<String> name, int depth) {
63 67
 		if (depth >= name.size())
64 68
 			return null;
@@ -72,7 +76,19 @@ public class ZSPackage {
72 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 92
 		if (depth >= nameParts.size())
77 93
 			return null;
78 94
 		

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/AndAndExpression.java Ver fichero

@@ -17,7 +17,7 @@ public class AndAndExpression extends Expression {
17 17
 	public final Expression right;
18 18
 	
19 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 22
 		this.left = left;
23 23
 		this.right = right;

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ArrayExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/BasicCompareExpression.java Ver fichero

@@ -21,7 +21,7 @@ public class BasicCompareExpression extends Expression {
21 21
 	public final CompareType operator;
22 22
 	
23 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 26
 		this.left = left;
27 27
 		this.right = right;

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallExpression.java Ver fichero

@@ -21,7 +21,7 @@ public class CallExpression extends Expression {
21 21
 	public final FunctionHeader instancedHeader;
22 22
 	
23 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 26
 		this.target = target;
27 27
 		this.member = member;

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallStaticExpression.java Ver fichero

@@ -22,7 +22,7 @@ public class CallStaticExpression extends Expression {
22 22
 	public final FunctionHeader instancedHeader;
23 23
 	
24 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 27
 		this.member = member;
28 28
 		this.target = target;

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CapturedExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CastExpression.java Ver fichero

@@ -18,7 +18,7 @@ public class CastExpression extends Expression {
18 18
 	public final boolean isImplicit;
19 19
 	
20 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 23
 		this.target = target;
24 24
 		this.member = member;

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CheckNullExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CoalesceExpression.java Ver fichero

@@ -16,7 +16,7 @@ public class CoalesceExpression extends Expression {
16 16
 	public final Expression right;
17 17
 	
18 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 21
 		this.left = left;
22 22
 		this.right = right;

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConditionalExpression.java Ver fichero

@@ -23,7 +23,7 @@ public class ConditionalExpression extends Expression {
23 23
 			Expression ifThen,
24 24
 			Expression ifElse,
25 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 28
 		if (ifThen.type != ifElse.type)
29 29
 			throw new AssertionError();

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantBoolExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantByteExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantCharExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantDoubleExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantFloatExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantIntExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantLongExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantSByteExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantShortExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantStringExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantUIntExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantULongExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstantUShortExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstructorSuperCallExpression.java Ver fichero

@@ -21,7 +21,7 @@ public class ConstructorSuperCallExpression extends Expression {
21 21
 	public final CallArguments arguments;
22 22
 	
23 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 26
 		this.objectType = type;
27 27
 		this.constructor = constructor;

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstructorThisCallExpression.java Ver fichero

@@ -21,7 +21,7 @@ public class ConstructorThisCallExpression extends Expression {
21 21
 	public final CallArguments arguments;
22 22
 	
23 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 26
 		arguments = arguments.normalize(position, scope, constructor.header);
27 27
 		

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/EnumConstantExpression.java Ver fichero

@@ -19,13 +19,13 @@ public class EnumConstantExpression extends Expression {
19 19
 	public final EnumConstantMember value;
20 20
 	
21 21
 	public EnumConstantExpression(CodePosition position, ITypeID type, EnumConstantMember value) {
22
-		super(position, type);
22
+		super(position, type, null);
23 23
 		
24 24
 		this.value = value;
25 25
 	}
26 26
 	
27 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 30
 		this.value = value;
31 31
 	}

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

@@ -16,6 +16,8 @@ import org.openzen.zenscript.codemodel.type.ITypeID;
16 16
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
17 17
 import org.openzen.zenscript.shared.CodePosition;
18 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,14 +26,12 @@ import org.openzen.zenscript.codemodel.scope.TypeScope;
24 26
 public abstract class Expression implements IPartialExpression {
25 27
 	public final CodePosition position;
26 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 32
 		this.position = position;
30 33
 		this.type = type;
31
-	}
32
-	
33
-	public ITypeID getType() {
34
-		return type;
34
+		this.thrownType = thrownType;
35 35
 	}
36 36
 	
37 37
 	public abstract <T> T accept(ExpressionVisitor<T> visitor);
@@ -84,4 +84,22 @@ public abstract class Expression implements IPartialExpression {
84 84
 	public ITypeID[] getGenericCallTypes() {
85 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 Ver fichero

@@ -128,5 +128,13 @@ public interface ExpressionVisitor<T> {
128 128
 	
129 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 139
 	public T visitWrapOptional(WrapOptionalExpression expression);
132 140
 }

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/FunctionExpression.java Ver fichero

@@ -24,7 +24,7 @@ public class FunctionExpression extends Expression {
24 24
 			FunctionTypeID type,
25 25
 			LambdaClosure closure,
26 26
 			Statement body) {
27
-		super(position, type);
27
+		super(position, type, body.thrownType);
28 28
 		
29 29
 		this.header = type.header;
30 30
 		this.closure = closure;

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GenericCompareExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetFieldExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetFunctionParameterExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetLocalVariableExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetStaticFieldExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetterExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GlobalCallExpression.java Ver fichero

@@ -17,7 +17,7 @@ public class GlobalCallExpression extends Expression {
17 17
 	public final Expression resolution;
18 18
 	
19 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 22
 		this.name = name;
23 23
 		this.arguments = arguments;

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GlobalExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/InterfaceCastExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/IsExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/MakeConstExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/MapExpression.java Ver fichero

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

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

@@ -18,7 +18,7 @@ public class MatchExpression extends Expression {
18 18
 	public final Case[] cases;
19 19
 	
20 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 23
 		this.value = value;
24 24
 		this.cases = cases;
@@ -38,4 +38,15 @@ public class MatchExpression extends Expression {
38 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 Ver fichero

@@ -18,7 +18,7 @@ public class NewExpression extends Expression {
18 18
 	public final CallArguments arguments;
19 19
 	
20 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 23
 		this.constructor = constructor;
24 24
 		this.arguments = arguments;

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/NullExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/OrOrExpression.java Ver fichero

@@ -17,7 +17,7 @@ public class OrOrExpression extends Expression {
17 17
 	public final Expression right;
18 18
 	
19 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 22
 		this.left = left;
23 23
 		this.right = right;

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/PostCallExpression.java Ver fichero

@@ -20,7 +20,7 @@ public class PostCallExpression extends Expression {
20 20
 	public final OperatorMember member;
21 21
 	
22 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 25
 		if (member.operator != OperatorType.DECREMENT && member.operator != OperatorType.INCREMENT)
26 26
 			throw new IllegalArgumentException("Operator must be increment or decrement");

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/RangeExpression.java Ver fichero

@@ -17,7 +17,7 @@ public class RangeExpression extends Expression {
17 17
 	public final Expression to;
18 18
 	
19 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 22
 		this.from = from;
23 23
 		this.to = to;

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SameObjectExpression.java Ver fichero

@@ -18,7 +18,7 @@ public class SameObjectExpression extends Expression {
18 18
 	public final boolean inverted;
19 19
 	
20 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 23
 		this.left = left;
24 24
 		this.right = right;

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SetFieldExpression.java Ver fichero

@@ -18,7 +18,7 @@ public class SetFieldExpression extends Expression {
18 18
 	public final Expression value;
19 19
 	
20 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 23
 		this.target = target;
24 24
 		this.field = field;

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SetFunctionParameterExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SetLocalVariableExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SetStaticFieldExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SetterExpression.java Ver fichero

@@ -18,7 +18,7 @@ public class SetterExpression extends Expression {
18 18
 	public final Expression value;
19 19
 	
20 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 23
 		this.target = target;
24 24
 		this.setter = setter;

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/StaticGetterExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/StaticSetterExpression.java Ver fichero

@@ -17,7 +17,7 @@ public class StaticSetterExpression extends Expression {
17 17
 	public final Expression value;
18 18
 	
19 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 22
 		this.setter = setter;
23 23
 		this.value = value;

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/SupertypeCastExpression.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ThisExpression.java Ver fichero

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

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

@@ -0,0 +1,28 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.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 Ver fichero

@@ -0,0 +1,28 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.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 Ver fichero

@@ -0,0 +1,28 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.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 Ver fichero

@@ -6,7 +6,6 @@
6 6
 package org.openzen.zenscript.codemodel.expression;
7 7
 
8 8
 import java.util.List;
9
-import org.openzen.zenscript.codemodel.OperatorType;
10 9
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
11 10
 import org.openzen.zenscript.codemodel.scope.TypeScope;
12 11
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -25,19 +24,26 @@ public class VariantValueExpression extends Expression {
25 24
 	}
26 25
 	
27 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 29
 		this.option = option;
31 30
 		this.arguments = null;
32 31
 	}
33 32
 	
33
+	public int getNumberOfArguments() {
34
+		return arguments == null ? 0 : arguments.length;
35
+	}
36
+	
34 37
 	@Override
35 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 42
 		return new VariantValueExpression(position, type, option, arguments.arguments);
37 43
 	}
38
-
44
+	
39 45
 	@Override
40 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 Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ConstructorMember.java Ver fichero

@@ -26,7 +26,7 @@ import org.openzen.zenscript.shared.CodePosition;
26 26
  */
27 27
 public class ConstructorMember extends FunctionalMember {
28 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 32
 	public boolean isConstructorForwarded() {

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

@@ -6,6 +6,8 @@
6 6
 package org.openzen.zenscript.codemodel.statement;
7 7
 
8 8
 import java.util.List;
9
+import org.openzen.zenscript.codemodel.expression.Expression;
10
+import org.openzen.zenscript.codemodel.type.ITypeID;
9 11
 import org.openzen.zenscript.shared.CodePosition;
10 12
 
11 13
 /**
@@ -16,7 +18,7 @@ public class BlockStatement extends Statement {
16 18
 	public final List<Statement> statements;
17 19
 	
18 20
 	public BlockStatement(CodePosition position, List<Statement> statements) {
19
-		super(position);
21
+		super(position, getThrownType(statements));
20 22
 		
21 23
 		this.statements = statements;
22 24
 	}
@@ -25,4 +27,11 @@ public class BlockStatement extends Statement {
25 27
 	public <T> T accept(StatementVisitor<T> visitor) {
26 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 Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ContinueStatement.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/DoWhileStatement.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/EmptyStatement.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ExpressionStatement.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ForeachStatement.java Ver fichero

@@ -20,7 +20,7 @@ public class ForeachStatement extends LoopStatement {
20 20
 	public Statement content;
21 21
 	
22 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 25
 		this.loopVariables = loopVariables;
26 26
 		this.list = list;

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

@@ -6,6 +6,7 @@
6 6
 package org.openzen.zenscript.codemodel.statement;
7 7
 
8 8
 import org.openzen.zenscript.codemodel.expression.Expression;
9
+import org.openzen.zenscript.codemodel.type.ITypeID;
9 10
 import org.openzen.zenscript.shared.CodePosition;
10 11
 
11 12
 /**
@@ -18,7 +19,7 @@ public class IfStatement extends Statement {
18 19
 	public final Statement onElse;
19 20
 	
20 21
 	public IfStatement(CodePosition position, Expression condition, Statement onThen, Statement onElse) {
21
-		super(position);
22
+		super(position, getThrownType(condition, onThen, onElse));
22 23
 		
23 24
 		this.condition = condition;
24 25
 		this.onThen = onThen;
@@ -29,4 +30,11 @@ public class IfStatement extends Statement {
29 30
 	public <T> T accept(StatementVisitor<T> visitor) {
30 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 Ver fichero

@@ -17,7 +17,7 @@ public class LockStatement extends Statement {
17 17
 	public final Statement content;
18 18
 	
19 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 22
 		this.object = object;
23 23
 		this.content = content;

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

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.statement;
7 7
 
8
+import org.openzen.zenscript.codemodel.type.ITypeID;
8 9
 import org.openzen.zenscript.shared.CodePosition;
9 10
 
10 11
 /**
@@ -14,8 +15,8 @@ import org.openzen.zenscript.shared.CodePosition;
14 15
 public abstract class LoopStatement extends Statement {
15 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 21
 		this.label = label;
21 22
 	}

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ReturnStatement.java Ver fichero

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

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

@@ -18,9 +18,11 @@ import org.openzen.zenscript.shared.Taggable;
18 18
  */
19 19
 public abstract class Statement extends Taggable {
20 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 24
 		this.position = position;
25
+		this.thrownType = thrownType;
24 26
 	}
25 27
 	
26 28
 	public ITypeID getReturnType() {

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/SwitchStatement.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ThrowStatement.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/TryCatchStatement.java Ver fichero

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

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/VarStatement.java Ver fichero

@@ -20,7 +20,7 @@ public class VarStatement extends Statement {
20 20
 	public final boolean isFinal;
21 21
 	
22 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 25
 		this.name = name;
26 26
 		this.type = type;

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/WhileStatement.java Ver fichero

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

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

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

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

@@ -151,6 +151,11 @@ public class DefinitionTypeID implements ITypeID {
151 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 159
 	@Override
155 160
 	public boolean hasInferenceBlockingTypeParameters(TypeParameter[] parameters) {
156 161
 		if (typeParameters != null) {

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

@@ -10,6 +10,7 @@ import java.util.HashMap;
10 10
 import java.util.Map;
11 11
 import org.openzen.zenscript.codemodel.FunctionHeader;
12 12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
13 14
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
14 15
 import static org.openzen.zenscript.codemodel.type.member.TypeMembers.MODIFIER_CONST;
15 16
 import static org.openzen.zenscript.codemodel.type.member.TypeMembers.MODIFIER_OPTIONAL;
@@ -31,7 +32,11 @@ public class GlobalTypeRegistry {
31 32
 	private final Map<ITypeID, ConstTypeID> constTypes = new HashMap<>();
32 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 40
 		arrayTypes.put(ArrayTypeID.INT, ArrayTypeID.INT);
36 41
 		arrayTypes.put(ArrayTypeID.CHAR, ArrayTypeID.CHAR);
37 42
 		
@@ -108,7 +113,7 @@ public class GlobalTypeRegistry {
108 113
 		}
109 114
 	}
110 115
 	
111
-	public DefinitionTypeID getForDefinition(HighLevelDefinition definition, ITypeID[] genericArguments) {
116
+	public DefinitionTypeID getForDefinition(HighLevelDefinition definition, ITypeID... genericArguments) {
112 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 Ver fichero

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

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

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

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

@@ -303,7 +303,7 @@ public class DefinitionMemberGroup {
303 303
 			}
304 304
 			
305 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 307
 					continue outer;
308 308
 			}
309 309
 			
@@ -327,7 +327,7 @@ public class DefinitionMemberGroup {
327 327
 			}
328 328
 			
329 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 331
 					continue outer;
332 332
 			}
333 333
 			

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

@@ -67,7 +67,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
67 67
 	private final GlobalTypeRegistry registry;
68 68
 	private final TypeMembers members;
69 69
 	private final LocalMemberCache cache;
70
-
70
+	
71 71
 	public TypeMemberBuilder(GlobalTypeRegistry registry, TypeMembers members, LocalMemberCache cache) {
72 72
 		this.registry = registry;
73 73
 		this.members = members;
@@ -204,9 +204,9 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
204 204
 		
205 205
 		ClassDefinition definition = new ClassDefinition(BUILTIN, null, "", Modifiers.EXPORT);
206 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 210
 		members.addGetter(new GetterMember(BUILTIN, definition, Modifiers.PUBLIC | Modifiers.EXTERN, "objectHashCode", BasicTypeID.INT));
211 211
 		return null;
212 212
 	}

+ 3
- 3
Constructor/libraries/collections/src/LinkedList.zs Ver fichero

@@ -27,13 +27,13 @@ export class LinkedList<T> {
27 27
 		var node = first;
28 28
 		while index > 0 {
29 29
 			if node == null
30
-				throw new NoSuchElementException("index out of bounds");
30
+				return panic<T>("index out of bounds");
31 31
 			
32 32
 			node = node.next;
33 33
 		}
34 34
 		
35 35
 		if node == null
36
-			throw new NoSuchElementException("index out of bounds");
36
+			return panic<T>("index out of bounds");
37 37
 		
38 38
 		return node.value;
39 39
 	}
@@ -41,7 +41,7 @@ export class LinkedList<T> {
41 41
 	public implements Queue<T> {
42 42
 		poll() as T {
43 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 46
 			val result = first.value;
47 47
 			first = first.next;

+ 9
- 0
Constructor/libraries/io/src/IOException.zs Ver fichero

@@ -0,0 +1,9 @@
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 Ver fichero

@@ -1,10 +1,10 @@
1 1
 export interface Reader {
2 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 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 Ver fichero

@@ -1,25 +1,39 @@
1 1
 export variant Result<T, E> {
2
-	Success(T),
3
-	Failure(E);
2
+	Ok(T),
3
+	Error(E);
4 4
 	
5 5
 	public then<R>(fn as function(result as T) as R) as Result<R, E> {
6 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 12
 	public handle<X>(handler as function(error as E) as Result<T, X>) as Result<T, X> {
13 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 19
 	public expect() as T {
20 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,8 +41,8 @@ export variant Result<T, E> {
27 41
 export expand <T, E : Exception> Result<T, E> {
28 42
 	public unwrap() as T {
29 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 Ver fichero

@@ -20,9 +20,10 @@ import org.openzen.zenscript.linker.symbol.ISymbol;
20 20
  * @author Hoofdgebruiker
21 21
  */
22 22
 public class ModuleSpace {
23
-	public final GlobalTypeRegistry typeRegistry = new GlobalTypeRegistry();
24
-	public final ZSPackage globalsPackage = new ZSPackage("");
25 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 27
 	private final List<ExpansionDefinition> expansions = new ArrayList<>();
27 28
 	private final Map<String, ISymbol> globals = new HashMap<>();
28 29
 	

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

@@ -573,9 +573,30 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
573 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 596
     @Override
577 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 600
         expression.value.accept(this);
580 601
         return null;
581 602
     }

+ 0
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreDecrementVisitor.java Ver fichero


Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio

Loading…
Cancelar
Guardar