Browse Source

Merge remote-tracking branch 'Stan/development' into development

kindlich 6 years ago
parent
commit
6c66704a78
No known key found for this signature in database
29 changed files with 341 additions and 35 deletions
  1. 6
    0
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/ExpressionFormatter.java
  2. 1
    0
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/ZenScriptOperator.java
  3. 3
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstructorSuperCallExpression.java
  4. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionVisitor.java
  5. 26
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/MatchExpression.java
  6. 33
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/PanicExpression.java
  7. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialTypeExpression.java
  8. 0
    1
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java
  9. 2
    0
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalTarget.java
  10. 11
    5
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
  11. 6
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreDecrementVisitor.java
  12. 6
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaPreIncrementVisitor.java
  13. 6
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/ExpressionHoistingChecker.java
  14. 69
    2
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaDefinitionVisitor.java
  15. 7
    5
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaExpansionMemberCompiler.java
  16. 19
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaMemberCompiler.java
  17. 9
    2
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceExpressionFormatter.java
  18. 5
    3
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceFile.java
  19. 26
    5
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceStatementFormatter.java
  20. 29
    2
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceUtils.java
  21. 5
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareDefinitionVisitor.java
  22. 10
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/scope/JavaSourceFileScope.java
  23. 1
    0
      Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenType.java
  24. 5
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpression.java
  25. 2
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCall.java
  26. 36
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedPanicExpression.java
  27. 4
    0
      Shared/src/main/java/org/openzen/zenscript/shared/StringUtils.java
  28. 2
    1
      Validator/src/main/java/org/openzen/zenscript/validator/ValidationLogEntry.java
  29. 9
    0
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/ExpressionValidator.java

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

@@ -56,6 +56,7 @@ import org.openzen.zenscript.codemodel.expression.MatchExpression;
56 56
 import org.openzen.zenscript.codemodel.expression.NewExpression;
57 57
 import org.openzen.zenscript.codemodel.expression.NullExpression;
58 58
 import org.openzen.zenscript.codemodel.expression.OrOrExpression;
59
+import org.openzen.zenscript.codemodel.expression.PanicExpression;
59 60
 import org.openzen.zenscript.codemodel.expression.PostCallExpression;
60 61
 import org.openzen.zenscript.codemodel.expression.RangeExpression;
61 62
 import org.openzen.zenscript.codemodel.expression.SameObjectExpression;
@@ -545,6 +546,11 @@ public class ExpressionFormatter implements ExpressionVisitor<ExpressionString>
545 546
 		return binary(expression.left, expression.right, ZenScriptOperator.OROR);
546 547
 	}
547 548
 	
549
+	@Override
550
+	public ExpressionString visitPanic(PanicExpression expression) {
551
+		return expression.value.accept(this).unaryPrefix(ZenScriptOperator.PANIC);
552
+	}
553
+	
548 554
 	@Override
549 555
 	public ExpressionString visitPostCall(PostCallExpression expression) {
550 556
 		return unaryPostfix(expression.target, ZenScriptOperator.INCREMENT, expression.member.getOperator() == OperatorType.INCREMENT ? "++" : "--");

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

@@ -60,6 +60,7 @@ public enum ZenScriptOperator implements FormattableOperator {
60 60
 	CALL(9, null),
61 61
 	CAST(9, null),
62 62
 	
63
+	PANIC(10, "panic "),
63 64
 	PRIMARY(10, null);
64 65
 	
65 66
 	private final int priority;

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

@@ -5,7 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.expression;
7 7
 
8
-import org.openzen.zenscript.codemodel.member.ConstructorMember;
8
+import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
9 9
 import org.openzen.zenscript.codemodel.scope.TypeScope;
10 10
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
11 11
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -17,10 +17,10 @@ import org.openzen.zenscript.shared.CodePosition;
17 17
  */
18 18
 public class ConstructorSuperCallExpression extends Expression {
19 19
 	public final ITypeID objectType;
20
-	public final ConstructorMember constructor;
20
+	public final FunctionalMemberRef constructor;
21 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, FunctionalMemberRef constructor, CallArguments arguments, TypeScope scope) {
24 24
 		super(position, BasicTypeID.VOID, binaryThrow(position, constructor.header.thrownType, multiThrow(position, arguments.arguments)));
25 25
 		
26 26
 		this.objectType = type;

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

@@ -104,6 +104,8 @@ public interface ExpressionVisitor<T> {
104 104
 	
105 105
 	public T visitOrOr(OrOrExpression expression);
106 106
 	
107
+	public T visitPanic(PanicExpression expression);
108
+	
107 109
 	public T visitPostCall(PostCallExpression expression);
108 110
 	
109 111
 	public T visitRange(RangeExpression expression);

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

@@ -5,12 +5,18 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.expression;
7 7
 
8
+import java.util.ArrayList;
9
+import java.util.Arrays;
8 10
 import java.util.Collections;
11
+import java.util.List;
9 12
 import org.openzen.zenscript.codemodel.expression.switchvalue.SwitchValue;
13
+import org.openzen.zenscript.codemodel.statement.BreakStatement;
10 14
 import org.openzen.zenscript.codemodel.statement.ExpressionStatement;
15
+import org.openzen.zenscript.codemodel.statement.Statement;
11 16
 import org.openzen.zenscript.codemodel.statement.SwitchCase;
12 17
 import org.openzen.zenscript.codemodel.statement.SwitchStatement;
13 18
 import org.openzen.zenscript.codemodel.statement.VarStatement;
19
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
14 20
 import org.openzen.zenscript.codemodel.type.ITypeID;
15 21
 import org.openzen.zenscript.shared.CodePosition;
16 22
 
@@ -49,10 +55,28 @@ public class MatchExpression extends Expression {
49 55
 	public SwitchedMatch convertToSwitch(String tempVariable) {
50 56
 		VarStatement result = new VarStatement(position, tempVariable, type, null, false);
51 57
 		SwitchStatement switchStatement = new SwitchStatement(position, null, value);
58
+		boolean hasDefault = false;
52 59
 		for (MatchExpression.Case matchCase : cases) {
53
-			Expression caseExpression = new SetLocalVariableExpression(matchCase.value.position, result, matchCase.value);
54
-			SwitchCase switchCase = new SwitchCase(matchCase.key, Collections.singletonList(new ExpressionStatement(matchCase.value.position, caseExpression)));
60
+			Expression caseExpression;
61
+			boolean reachable = true;
62
+			if (matchCase.value instanceof ThrowExpression || matchCase.value instanceof PanicExpression) {
63
+				caseExpression = matchCase.value;
64
+				reachable = false;
65
+			} else {
66
+				caseExpression = new SetLocalVariableExpression(matchCase.value.position, result, matchCase.value);
67
+			}
68
+			List<Statement> statements = new ArrayList<>();
69
+			statements.add(new ExpressionStatement(matchCase.value.position, caseExpression));
70
+			if (reachable)
71
+				statements.add(new BreakStatement(matchCase.value.position, switchStatement));
72
+			SwitchCase switchCase = new SwitchCase(matchCase.key, statements);
55 73
 			switchStatement.cases.add(switchCase);
74
+			
75
+			if (matchCase.key == null)
76
+				hasDefault = true;
77
+		}
78
+		if (!hasDefault) {
79
+			switchStatement.cases.add(new SwitchCase(null, Collections.singletonList(new ExpressionStatement(position, new PanicExpression(position, BasicTypeID.VOID, new ConstantStringExpression(position, "Missing case"))))));
56 80
 		}
57 81
 		return new SwitchedMatch(result, switchStatement);
58 82
 	}

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

@@ -0,0 +1,33 @@
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 PanicExpression extends Expression {
16
+	public final Expression value;
17
+	
18
+	public PanicExpression(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.visitPanic(this);
27
+	}
28
+
29
+	@Override
30
+	public Expression transform(ExpressionTransformer transformer) {
31
+		return new PanicExpression(position, type, transformer.transform(value));
32
+	}
33
+}

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

@@ -61,7 +61,7 @@ public class PartialTypeExpression implements IPartialExpression {
61 61
 
62 62
 	@Override
63 63
 	public Expression call(CodePosition position, TypeScope scope, List<ITypeID> hints, CallArguments arguments) {
64
-		if (arguments.getNumberOfTypeArguments() == 0 && typeParameters.length > 0)
64
+		if (arguments.getNumberOfTypeArguments() == 0 && (typeParameters != null && typeParameters.length > 0))
65 65
 			arguments = new CallArguments(typeParameters, arguments.arguments);
66 66
 		
67 67
 		return scope.getTypeMembers(type).getOrCreateGroup(OperatorType.CALL).callStatic(position, type, scope, arguments);

+ 0
- 1
CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java View File

@@ -122,7 +122,6 @@ public class SemanticModule {
122 122
 		for (ScriptBlock script : scripts) {
123 123
 			compiler.addScriptBlock(script);
124 124
 		}
125
-		compiler.finish();
126 125
 	}
127 126
 	
128 127
 	public enum State {

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

@@ -90,12 +90,14 @@ public class LocalTarget implements IDETarget {
90 90
 			if (!stdlib.isValid())
91 91
 				return compiler;
92 92
 			stdlib.compile(compiler);
93
+			compiledModules.add(stdlib.name);
93 94
 			
94 95
 			boolean isValid = compileDependencies(moduleLoader, compiler, compiledModules, module);
95 96
 			if (!isValid)
96 97
 				return compiler;
97 98
 			
98 99
 			module.compile(compiler);
100
+			compiler.finish();
99 101
 			return compiler;
100 102
 		} catch (IOException ex) {
101 103
 			ex.printStackTrace();

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

@@ -1985,11 +1985,17 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void> {
1985 1985
 
1986 1986
         return null;
1987 1987
     }
1988
-
1989
-    @Override
1990
-    public Void visitPostCall(PostCallExpression expression) {
1991
-        expression.target.accept(this);
1992
-        javaWriter.dup(expression.type.accept(new JavaTypeVisitor()));
1988
+	
1989
+	@Override
1990
+	public Void visitPanic(PanicExpression expression) {
1991
+		// TODO: compile to: throw new AssertionError(expression.value)
1992
+		throw new UnsupportedOperationException("Not yet supported");
1993
+	}
1994
+	
1995
+	@Override
1996
+	public Void visitPostCall(PostCallExpression expression) {
1997
+		expression.target.accept(this);
1998
+		javaWriter.dup(expression.type.accept(new JavaTypeVisitor()));
1993 1999
         if (!checkAndExecuteByteCodeImplementation(expression.member) && !checkAndExecuteMethodInfo(expression.member))
1994 2000
             throw new IllegalStateException("Call target has no method info!");
1995 2001
 

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

@@ -54,6 +54,7 @@ import org.openzen.zenscript.codemodel.expression.MatchExpression;
54 54
 import org.openzen.zenscript.codemodel.expression.NewExpression;
55 55
 import org.openzen.zenscript.codemodel.expression.NullExpression;
56 56
 import org.openzen.zenscript.codemodel.expression.OrOrExpression;
57
+import org.openzen.zenscript.codemodel.expression.PanicExpression;
57 58
 import org.openzen.zenscript.codemodel.expression.PostCallExpression;
58 59
 import org.openzen.zenscript.codemodel.expression.RangeExpression;
59 60
 import org.openzen.zenscript.codemodel.expression.SameObjectExpression;
@@ -350,6 +351,11 @@ public class JavaPreDecrementVisitor implements ExpressionVisitor<Void> {
350 351
 	public Void visitOrOr(OrOrExpression expression) {
351 352
 		throw new UnsupportedOperationException("Invalid increment target");
352 353
 	}
354
+	
355
+	@Override
356
+	public Void visitPanic(PanicExpression expression) {
357
+		throw new UnsupportedOperationException("Invalid increment target");
358
+	}
353 359
 
354 360
 	@Override
355 361
 	public Void visitPostCall(PostCallExpression expression) {

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

@@ -54,6 +54,7 @@ import org.openzen.zenscript.codemodel.expression.MatchExpression;
54 54
 import org.openzen.zenscript.codemodel.expression.NewExpression;
55 55
 import org.openzen.zenscript.codemodel.expression.NullExpression;
56 56
 import org.openzen.zenscript.codemodel.expression.OrOrExpression;
57
+import org.openzen.zenscript.codemodel.expression.PanicExpression;
57 58
 import org.openzen.zenscript.codemodel.expression.PostCallExpression;
58 59
 import org.openzen.zenscript.codemodel.expression.RangeExpression;
59 60
 import org.openzen.zenscript.codemodel.expression.SameObjectExpression;
@@ -356,6 +357,11 @@ public class JavaPreIncrementVisitor implements ExpressionVisitor<Void> {
356 357
 	public Void visitOrOr(OrOrExpression expression) {
357 358
 		throw new UnsupportedOperationException("Invalid increment target");
358 359
 	}
360
+	
361
+	@Override
362
+	public Void visitPanic(PanicExpression expression) {
363
+		throw new UnsupportedOperationException("Invalid increment target");
364
+	}
359 365
 
360 366
 	@Override
361 367
 	public Void visitPostCall(PostCallExpression expression) {

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

@@ -53,6 +53,7 @@ import org.openzen.zenscript.codemodel.expression.MatchExpression;
53 53
 import org.openzen.zenscript.codemodel.expression.NewExpression;
54 54
 import org.openzen.zenscript.codemodel.expression.NullExpression;
55 55
 import org.openzen.zenscript.codemodel.expression.OrOrExpression;
56
+import org.openzen.zenscript.codemodel.expression.PanicExpression;
56 57
 import org.openzen.zenscript.codemodel.expression.PostCallExpression;
57 58
 import org.openzen.zenscript.codemodel.expression.RangeExpression;
58 59
 import org.openzen.zenscript.codemodel.expression.SameObjectExpression;
@@ -315,6 +316,11 @@ public class ExpressionHoistingChecker implements ExpressionVisitor<Boolean> {
315 316
 	public Boolean visitOrOr(OrOrExpression expression) {
316 317
 		return true;
317 318
 	}
319
+	
320
+	@Override
321
+	public Boolean visitPanic(PanicExpression expression) {
322
+		return true;
323
+	}
318 324
 
319 325
 	@Override
320 326
 	public Boolean visitPostCall(PostCallExpression expression) {

+ 69
- 2
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaDefinitionVisitor.java View File

@@ -42,6 +42,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<Void> {
42 42
 	public Void visitClass(ClassDefinition definition) {
43 43
 		convertModifiers(definition.modifiers);
44 44
 		output.append("class ").append(definition.name);
45
+		JavaSourceUtils.formatTypeParameters(scope, output, definition.genericParameters);
45 46
 		if (definition.superType != null) {
46 47
 			output.append(" extends ");
47 48
 			output.append(scope.type(definition.superType));
@@ -73,8 +74,9 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<Void> {
73 74
 
74 75
 	@Override
75 76
 	public Void visitInterface(InterfaceDefinition definition) {
76
-		convertModifiers(definition.modifiers);
77
+		convertModifiers(definition.modifiers | Modifiers.VIRTUAL); // to prevent 'final'
77 78
 		output.append("interface ").append(definition.name);
79
+		JavaSourceUtils.formatTypeParameters(scope, output, definition.genericParameters);
78 80
 		output.append(" {\n");
79 81
 		compileMembers(definition);
80 82
 		output.append("}\n");
@@ -115,6 +117,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<Void> {
115 117
 	public Void visitStruct(StructDefinition definition) {
116 118
 		convertModifiers(definition.modifiers | Modifiers.FINAL);
117 119
 		output.append("class ").append(definition.name);
120
+		JavaSourceUtils.formatTypeParameters(scope, output, definition.genericParameters);
118 121
 		output.append(" {\n");
119 122
 		compileMembers(definition);
120 123
 		output.append("}\n");
@@ -124,6 +127,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<Void> {
124 127
 	@Override
125 128
 	public Void visitFunction(FunctionDefinition definition) {
126 129
 		convertModifiers(definition.modifiers | Modifiers.STATIC);
130
+		
127 131
 		return null;
128 132
 	}
129 133
 
@@ -133,6 +137,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<Void> {
133 137
 		output.append("class ");
134 138
 		output.append(scope.className);
135 139
 		output.append(" {\n");
140
+		output.append(settings.indent).append("private ").append(scope.className).append("() {}\n");
136 141
 		
137 142
 		JavaExpansionMemberCompiler memberCompiler = new JavaExpansionMemberCompiler(settings, definition.target, "\t", output, scope);
138 143
 		for (IDefinitionMember member : definition.members)
@@ -150,6 +155,68 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<Void> {
150 155
 
151 156
 	@Override
152 157
 	public Void visitVariant(VariantDefinition variant) {
158
+		convertModifiers(variant.modifiers | Modifiers.VIRTUAL | Modifiers.ABSTRACT);
159
+		output.append("class ").append(variant.name);
160
+		JavaSourceUtils.formatTypeParameters(scope, output, variant.genericParameters);
161
+		output.append("{\n");
162
+		compileMembers(variant);
163
+		output.append(settings.indent).append("public abstract Discriminant getDiscriminant();\n");
164
+		
165
+		output.append(settings.indent).append("\n");
166
+		output.append(settings.indent).append("public static enum Discriminant {\n");
167
+		for (VariantDefinition.Option option : variant.options) {
168
+			output.append(settings.indent).append(settings.indent).append(option.name).append(",\n");
169
+		}
170
+		output.append(settings.indent).append("}\n");
171
+		
172
+		for (VariantDefinition.Option option : variant.options) {
173
+			output.append(settings.indent).append("\n");
174
+			output.append(settings.indent).append("public static class ").append(option.name);
175
+			JavaSourceUtils.formatTypeParameters(scope, output, variant.genericParameters);
176
+			output.append(" extends ");
177
+			output.append(variant.name);
178
+			if (variant.genericParameters != null && variant.genericParameters.length > 0) {
179
+				output.append('<');
180
+				for (int i = 0; i < variant.genericParameters.length; i++) {
181
+					if (i > 0)
182
+						output.append(", ");
183
+					output.append(variant.genericParameters[i].name);
184
+				}
185
+				output.append('>');
186
+			}
187
+			output.append(" {\n");
188
+			
189
+			for (int i = 0; i < option.types.length; i++) {
190
+				String name = option.types.length == 1 ? "value" : "value" + (i + 1);
191
+				output.append(settings.indent).append(settings.indent).append("public final ").append(scope.type(option.types[i])).append(" ").append(name).append(";\n");
192
+			}
193
+			output.append(settings.indent).append(settings.indent).append("\n");
194
+			output.append(settings.indent).append(settings.indent).append("public ").append(option.name).append("(");
195
+			for (int i = 0; i < option.types.length; i++) {
196
+				if (i > 0)
197
+					output.append(", ");
198
+				String name = option.types.length == 1 ? "value" : "value" + (i + 1);
199
+				output.append(scope.type(option.types[i])).append(' ').append(name);
200
+			}
201
+			output.append("){\n");
202
+			for (int i = 0; i < option.types.length; i++) {
203
+				if (i > 0)
204
+					output.append(settings.indent).append(settings.indent).append(settings.indent).append(";\n");
205
+				
206
+				String name = option.types.length == 1 ? "value" : "value" + (i + 1);
207
+				output.append(settings.indent).append(settings.indent).append(settings.indent).append("this.").append(name).append(" = ").append(name).append(";\n");
208
+			}
209
+			output.append(settings.indent).append(settings.indent).append("}\n");
210
+			
211
+			output.append(settings.indent).append(settings.indent).append("\n");
212
+			output.append(settings.indent).append(settings.indent).append("@Override\n");
213
+			output.append(settings.indent).append(settings.indent).append("public Discriminant getDiscriminant() {\n");
214
+			output.append(settings.indent).append(settings.indent).append(settings.indent).append("return Discriminant.").append(option.name).append(";\n");
215
+			output.append(settings.indent).append(settings.indent).append("}\n");
216
+			output.append(settings.indent).append("}\n");
217
+		}
218
+		
219
+		output.append("}\n");
153 220
 		return null;
154 221
 	}
155 222
 	
@@ -173,7 +240,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<Void> {
173 240
 	}
174 241
 	
175 242
 	private void compileMembers(HighLevelDefinition definition) {
176
-		JavaMemberCompiler memberCompiler = new JavaMemberCompiler(settings, "\t", output, scope, false);
243
+		JavaMemberCompiler memberCompiler = new JavaMemberCompiler(settings, "\t", output, scope, false, scope.isInterface);
177 244
 		for (IDefinitionMember member : definition.members)
178 245
 			member.accept(memberCompiler);
179 246
 		memberCompiler.finish();

+ 7
- 5
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaExpansionMemberCompiler.java View File

@@ -29,6 +29,7 @@ import org.openzen.zenscript.codemodel.member.OperatorMember;
29 29
 import org.openzen.zenscript.codemodel.member.SetterMember;
30 30
 import org.openzen.zenscript.codemodel.member.StaticInitializerMember;
31 31
 import org.openzen.zenscript.codemodel.statement.BlockStatement;
32
+import org.openzen.zenscript.codemodel.statement.EmptyStatement;
32 33
 import org.openzen.zenscript.codemodel.statement.Statement;
33 34
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
34 35
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -141,7 +142,8 @@ public class JavaExpansionMemberCompiler implements MemberVisitor<Void> {
141 142
 		addSpacing();
142 143
 		
143 144
 		output.append(indent);
144
-		modifiers(member.modifiers);
145
+		
146
+		modifiers(member.modifiers | Modifiers.STATIC);
145 147
 		JavaSourceUtils.formatTypeParameters(scope, output, member.header.typeParameters);
146 148
 		output.append(scope.type(member.header.returnType));
147 149
 		output.append(" ");
@@ -156,7 +158,7 @@ public class JavaExpansionMemberCompiler implements MemberVisitor<Void> {
156 158
 		addSpacing();
157 159
 		
158 160
 		output.append(indent);
159
-		modifiers(member.modifiers);
161
+		modifiers(member.modifiers | Modifiers.STATIC);
160 162
 		output.append(scope.type(member.type));
161 163
 		output.append(" ");
162 164
 		output.append("get").append(StringUtils.capitalize(member.name));
@@ -170,7 +172,7 @@ public class JavaExpansionMemberCompiler implements MemberVisitor<Void> {
170 172
 		addSpacing();
171 173
 		
172 174
 		output.append(indent);
173
-		modifiers(member.modifiers);
175
+		modifiers(member.modifiers | Modifiers.STATIC);
174 176
 		output.append("void set").append(StringUtils.capitalize(member.name));
175 177
 		output.append("(");
176 178
 		output.append(scope.type(member.type));
@@ -186,7 +188,7 @@ public class JavaExpansionMemberCompiler implements MemberVisitor<Void> {
186 188
 		addSpacing();
187 189
 		
188 190
 		output.append(indent);
189
-		modifiers(member.modifiers);
191
+		modifiers(member.modifiers | Modifiers.STATIC);
190 192
 		output.append(scope.type(member.header.returnType));
191 193
 		output.append(' ');
192 194
 		output.append(getOperatorName(member.operator));
@@ -200,7 +202,7 @@ public class JavaExpansionMemberCompiler implements MemberVisitor<Void> {
200 202
 		addSpacing();
201 203
 		
202 204
 		output.append(indent);
203
-		modifiers(member.modifiers);
205
+		modifiers(member.modifiers | Modifiers.STATIC);
204 206
 		output.append(scope.type(member.toType));
205 207
 		output.append(" ");
206 208
 		output.append("to").append(member.toType.accept(new JavaSourceTypeNameVisitor()));

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

@@ -48,14 +48,16 @@ public class JavaMemberCompiler implements MemberVisitor<Void> {
48 48
 	private final JavaSourceFormattingSettings settings;
49 49
 	private final List<FieldMember> fields = new ArrayList<>();
50 50
 	private final boolean isExpansion;
51
+	private final boolean isInterface;
51 52
 	private boolean first = true;
52 53
 	
53
-	public JavaMemberCompiler(JavaSourceFormattingSettings settings, String indent, StringBuilder output, JavaSourceFileScope scope, boolean isExpansion) {
54
+	public JavaMemberCompiler(JavaSourceFormattingSettings settings, String indent, StringBuilder output, JavaSourceFileScope scope, boolean isExpansion, boolean isInterface) {
54 55
 		this.indent = indent;
55 56
 		this.output = output;
56 57
 		this.scope = scope;
57 58
 		this.settings = settings;
58 59
 		this.isExpansion = isExpansion;
60
+		this.isInterface = isInterface;
59 61
 		
60 62
 		fieldInitializerScope = new JavaSourceStatementScope(
61 63
 				scope,
@@ -144,7 +146,11 @@ public class JavaMemberCompiler implements MemberVisitor<Void> {
144 146
 	public Void visitMethod(MethodMember member) {
145 147
 		addSpacing();
146 148
 		
149
+		
147 150
 		output.append(indent);
151
+		if (isInterface && member.body != null && !(member.body instanceof EmptyStatement))
152
+			output.append("default ");
153
+		
148 154
 		modifiers(member.modifiers);
149 155
 		JavaSourceUtils.formatTypeParameters(scope, output, member.header.typeParameters);
150 156
 		output.append(member.header.returnType.accept(scope.typeVisitor));
@@ -160,6 +166,9 @@ public class JavaMemberCompiler implements MemberVisitor<Void> {
160 166
 		addSpacing();
161 167
 		
162 168
 		output.append(indent);
169
+		if (isInterface && member.body != null && !(member.body instanceof EmptyStatement))
170
+			output.append("default ");
171
+		
163 172
 		modifiers(member.modifiers);
164 173
 		output.append(scope.type(member.type));
165 174
 		output.append(" ");
@@ -174,6 +183,9 @@ public class JavaMemberCompiler implements MemberVisitor<Void> {
174 183
 		addSpacing();
175 184
 		
176 185
 		output.append(indent);
186
+		if (isInterface && member.body != null && !(member.body instanceof EmptyStatement))
187
+			output.append("default ");
188
+		
177 189
 		modifiers(member.modifiers);
178 190
 		output.append("void set").append(StringUtils.capitalize(member.name));
179 191
 		output.append("(");
@@ -193,6 +205,9 @@ public class JavaMemberCompiler implements MemberVisitor<Void> {
193 205
 			throw new IllegalStateException("Missing method tag!");
194 206
 		
195 207
 		output.append(indent);
208
+		if (isInterface && member.body != null && !(member.body instanceof EmptyStatement))
209
+			output.append("default ");
210
+		
196 211
 		modifiers(member.modifiers);
197 212
 		output.append(scope.type(member.header.returnType));
198 213
 		output.append(' ');
@@ -207,6 +222,9 @@ public class JavaMemberCompiler implements MemberVisitor<Void> {
207 222
 		addSpacing();
208 223
 		
209 224
 		output.append(indent);
225
+		if (isInterface && member.body != null && !(member.body instanceof EmptyStatement))
226
+			output.append("default ");
227
+		
210 228
 		modifiers(member.modifiers);
211 229
 		output.append(scope.type(member.toType));
212 230
 		output.append(" ");

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

@@ -57,6 +57,7 @@ import org.openzen.zenscript.codemodel.expression.MatchExpression;
57 57
 import org.openzen.zenscript.codemodel.expression.NewExpression;
58 58
 import org.openzen.zenscript.codemodel.expression.NullExpression;
59 59
 import org.openzen.zenscript.codemodel.expression.OrOrExpression;
60
+import org.openzen.zenscript.codemodel.expression.PanicExpression;
60 61
 import org.openzen.zenscript.codemodel.expression.PostCallExpression;
61 62
 import org.openzen.zenscript.codemodel.expression.RangeExpression;
62 63
 import org.openzen.zenscript.codemodel.expression.SameObjectExpression;
@@ -504,6 +505,11 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
504 505
 		return binary(expression.left, expression.right, JavaOperator.OROR);
505 506
 	}
506 507
 	
508
+	@Override
509
+	public ExpressionString visitPanic(PanicExpression expression) {
510
+		return new ExpressionString("throw new AssertionError(" + expression.value.accept(this).value + ")", JavaOperator.PRIMARY);
511
+	}
512
+	
507 513
 	@Override
508 514
 	public ExpressionString visitPostCall(PostCallExpression expression) {
509 515
 		return unaryPostfix(expression.target, expression.member.getOperator() == OperatorType.INCREMENT ? JavaOperator.INCREMENT : JavaOperator.DECREMENT);
@@ -1371,7 +1377,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
1371 1377
 			case STRING_CONSTRUCTOR_CHARACTERS:
1372 1378
 				return callStatic("new String", expression.arguments.arguments[0]);
1373 1379
 			case ASSOC_CONSTRUCTOR: {
1374
-				String typeName = scope.fileScope.importer.importType("java.util.HashMap");
1380
+				String typeName = scope.type(new JavaSourceClass("HashMap", "java.util.HashMap"));
1375 1381
 				AssocTypeID type = (AssocTypeID) expression.type;
1376 1382
 				
1377 1383
 				StringBuilder result = new StringBuilder();
@@ -1383,7 +1389,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
1383 1389
 				return new ExpressionString(result.toString(), JavaOperator.NEW);
1384 1390
 			}
1385 1391
 			case GENERICMAP_CONSTRUCTOR: {
1386
-				String typeName = scope.fileScope.importer.importType("java.util.HashMap");
1392
+				String typeName = scope.type(new JavaSourceClass("HashMap", "java.util.HashMap"));
1387 1393
 				StringBuilder result = new StringBuilder();
1388 1394
 				result.append("new ").append(typeName).append("<Class<?>, Object>()");
1389 1395
 				return new ExpressionString(result.toString(), JavaOperator.NEW);
@@ -1438,6 +1444,7 @@ public class JavaSourceExpressionFormatter implements ExpressionVisitor<Expressi
1438 1444
 							.append(value.value)
1439 1445
 							.append(";")
1440 1446
 							.toString());
1447
+					return new ExpressionString(temp, JavaOperator.PRIMARY);
1441 1448
 				} else {
1442 1449
 					// TODO: implement
1443 1450
 					throw new UnsupportedOperationException("Not yet supported!");

+ 5
- 3
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceFile.java View File

@@ -17,6 +17,7 @@ import java.util.HashSet;
17 17
 import java.util.Map;
18 18
 import java.util.Set;
19 19
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
20
+import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
20 21
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
21 22
 import org.openzen.zenscript.compiler.CompileScope;
22 23
 import org.openzen.zenscript.compiler.SemanticModule;
@@ -61,22 +62,23 @@ public class JavaSourceFile {
61 62
 	}
62 63
 	
63 64
 	public void write() {
65
+		System.out.println("Calling write on " + file.getName());
66
+		
64 67
 		for (Map.Entry<HighLevelDefinition, SemanticModule> entry : definitions.entrySet()) {
65 68
 			HighLevelDefinition definition = entry.getKey();
66 69
 			SemanticModule module = entry.getValue();
67 70
 			CompileScope scope = new CompileScope(definition.access, module.compilationUnit.globalTypeRegistry, module.expansions, module.annotations);
68 71
 			JavaDefinitionVisitor visitor = new JavaDefinitionVisitor(
69 72
 					compiler.settings,
70
-					new JavaSourceFileScope(importer, compiler.typeGenerator, compiler.helperGenerator, getName(), scope),
73
+					new JavaSourceFileScope(importer, compiler.typeGenerator, compiler.helperGenerator, getName(), scope, definition instanceof InterfaceDefinition),
71 74
 					contents);
72 75
 			definition.accept(visitor);
73 76
 		}
74 77
 		
75 78
 		if (!file.getParentFile().exists())
76 79
 			file.getParentFile().mkdirs();
77
-		file.delete();
78 80
 		
79
-		try (Writer writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file)), StandardCharsets.UTF_8)) {
81
+		try (Writer writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file, false)), StandardCharsets.UTF_8)) {
80 82
 			writer.write("package ");
81 83
 			writer.write(pkg.fullName);
82 84
 			writer.write(";\n\n");

+ 26
- 5
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceStatementFormatter.java View File

@@ -8,6 +8,7 @@ package org.openzen.zenscript.javasource;
8 8
 import java.util.ArrayList;
9 9
 import java.util.Collections;
10 10
 import java.util.List;
11
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
11 12
 import org.openzen.zenscript.codemodel.OperatorType;
12 13
 import org.openzen.zenscript.codemodel.expression.CallArguments;
13 14
 import org.openzen.zenscript.codemodel.expression.Expression;
@@ -39,12 +40,14 @@ import org.openzen.zenscript.codemodel.statement.ThrowStatement;
39 40
 import org.openzen.zenscript.codemodel.statement.TryCatchStatement;
40 41
 import org.openzen.zenscript.codemodel.statement.VarStatement;
41 42
 import org.openzen.zenscript.codemodel.statement.WhileStatement;
43
+import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
42 44
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
43 45
 import org.openzen.zenscript.formattershared.ExpressionString;
44 46
 import org.openzen.zenscript.formattershared.StatementFormatter;
45 47
 import org.openzen.zenscript.formattershared.StatementFormattingSubBlock;
46 48
 import org.openzen.zenscript.formattershared.StatementFormattingTarget;
47 49
 import org.openzen.zenscript.javasource.scope.JavaSourceStatementScope;
50
+import org.openzen.zenscript.javasource.tags.JavaSourceClass;
48 51
 import org.openzen.zenscript.shared.StringUtils;
49 52
 
50 53
 /**
@@ -126,14 +129,31 @@ public class JavaSourceStatementFormatter implements StatementFormatter.Formatte
126 129
 			Expression value = scope.duplicable(target, statement.value);
127 130
 			ExpressionString valueString = scope.expression(target, value);
128 131
 			List<StatementFormattingSubBlock> blocks = new ArrayList<>();
129
-			String variantType = scope.type(statement.value.type);
132
+			
133
+			DefinitionTypeID variantType = (DefinitionTypeID)statement.value.type;
134
+			HighLevelDefinition variant = variantType.definition;
135
+			String variantTypeName = scope.type(variant.getTag(JavaSourceClass.class));
136
+			JavaSourceStatementScope innerScope = scope.createBlockScope(statement);
130 137
 			for (SwitchCase switchCase : statement.cases) {
131 138
 				VariantOptionSwitchValue switchValue = (VariantOptionSwitchValue)switchCase.value;
132 139
 				String header = switchValue == null ? "default:" : "case " + switchValue.option.getName() + ":";
133 140
 				List<String> statements = new ArrayList<>();
134 141
 				if (switchValue != null) {
135
-					for (VarStatement var : switchValue.parameters)
136
-						statements.add(scope.type(var.type) + " " + var.name + " = (" + variantType + "." + switchValue.option.getName() + ")" + valueString.value + ";");
142
+					for (VarStatement var : switchValue.parameters) {
143
+						StringBuilder statementOutput = new StringBuilder();
144
+						statementOutput.append(scope.type(var.type)).append(" ").append(var.name).append(" = ((").append(variantTypeName).append(".").append(switchValue.option.getName());
145
+						if (variant.genericParameters != null && variant.genericParameters.length > 0) {
146
+							statementOutput.append("<");
147
+							for (int i = 0; i < variantType.typeParameters.length; i++) {
148
+								if (i > 0)
149
+									statementOutput.append(", ");
150
+								statementOutput.append(scope.type(variantType.typeParameters[i]));
151
+							}
152
+							statementOutput.append(">");
153
+						}
154
+						statementOutput.append(")").append(valueString.value).append(").").append("value").append(";");
155
+						statements.add(statementOutput.toString());
156
+					}
137 157
 				}
138 158
 				blocks.add(new StatementFormattingSubBlock(header, statements, switchCase.statements));
139 159
 			}
@@ -225,10 +245,11 @@ public class JavaSourceStatementFormatter implements StatementFormatter.Formatte
225 245
 			String name = statement.loopVariables[0].name;
226 246
 			
227 247
 			if (statement.list instanceof RangeExpression) {
248
+				String limitName = "limitFor" + StringUtils.capitalize(name);
228 249
 				RangeExpression range = (RangeExpression)(statement.list);
229
-				target.writeLine("int limitFor = " + name + " = " + scope.expression(target, range.to) + ";");
250
+				target.writeLine("int " + limitName + " = " + scope.expression(target, range.to) + ";");
230 251
 				target.writeInner(
231
-						"for (int " + name + " = " + scope.expression(target, range.from) + "; " + name + " < limitFor" + name + "; " + name + "++)",
252
+						"for (int " + name + " = " + scope.expression(target, range.from) + "; " + name + " < " + limitName + "; " + name + "++)",
232 253
 						statement.content,
233 254
 						statement,
234 255
 						"");

+ 29
- 2
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceUtils.java View File

@@ -5,6 +5,10 @@
5 5
  */
6 6
 package org.openzen.zenscript.javasource;
7 7
 
8
+import org.openzen.zenscript.codemodel.generic.GenericParameterBound;
9
+import org.openzen.zenscript.codemodel.generic.GenericParameterBoundVisitor;
10
+import org.openzen.zenscript.codemodel.generic.ParameterSuperBound;
11
+import org.openzen.zenscript.codemodel.generic.ParameterTypeBound;
8 12
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
9 13
 import org.openzen.zenscript.javasource.scope.JavaSourceFileScope;
10 14
 
@@ -19,6 +23,7 @@ public class JavaSourceUtils {
19 23
 		if (parameters == null || parameters.length == 0)
20 24
 			return;
21 25
 		
26
+		TypeParameterBoundVisitor boundVisitor = new TypeParameterBoundVisitor(scope, output);
22 27
 		output.append("<");
23 28
 		for (int i = 0; i < parameters.length; i++) {
24 29
 			if (i > 0)
@@ -28,10 +33,32 @@ public class JavaSourceUtils {
28 33
 			output.append(typeParameter.name);
29 34
 			
30 35
 			if (typeParameter.bounds.size() > 0) {
31
-				output.append(" ");
32
-				// TODO
36
+				for (GenericParameterBound bound : typeParameter.bounds)
37
+					bound.accept(boundVisitor);
33 38
 			}
34 39
 		}
35 40
 		output.append("> ");
36 41
 	}
42
+	
43
+	private static class TypeParameterBoundVisitor implements GenericParameterBoundVisitor<Void> {
44
+		private final JavaSourceFileScope scope;
45
+		private final StringBuilder output;
46
+		
47
+		public TypeParameterBoundVisitor(JavaSourceFileScope scope, StringBuilder output) {
48
+			this.scope = scope;
49
+			this.output = output;
50
+		}
51
+
52
+		@Override
53
+		public Void visitSuper(ParameterSuperBound bound) {
54
+			output.append(" super ").append(scope.type(bound.type));
55
+			return null;
56
+		}
57
+
58
+		@Override
59
+		public Void visitType(ParameterTypeBound bound) {
60
+			output.append(" extends ").append(scope.type(bound.type));
61
+			return null;
62
+		}
63
+	}
37 64
 }

+ 5
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareDefinitionVisitor.java View File

@@ -19,6 +19,7 @@ import org.openzen.zenscript.codemodel.definition.VariantDefinition;
19 19
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
20 20
 import org.openzen.zenscript.javasource.tags.JavaSourceClass;
21 21
 import org.openzen.zenscript.javasource.JavaSourceFile;
22
+import org.openzen.zenscript.javasource.tags.JavaSourceMethod;
22 23
 import org.openzen.zenscript.javasource.tags.JavaSourceVariantOption;
23 24
 
24 25
 /**
@@ -58,6 +59,10 @@ public class JavaSourcePrepareDefinitionVisitor implements DefinitionVisitor<Voi
58 59
 
59 60
 	@Override
60 61
 	public Void visitFunction(FunctionDefinition definition) {
62
+		JavaSourceClass cls = new JavaSourceClass(file.getName(), definition.pkg.fullName + "." + file.getName());
63
+		definition.setTag(JavaSourceClass.class, cls);
64
+		JavaSourceMethod method = new JavaSourceMethod(cls, JavaSourceMethod.Kind.STATIC, definition.name);
65
+		definition.caller.setTag(JavaSourceMethod.class, method);
61 66
 		return null;
62 67
 	}
63 68
 

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

@@ -25,13 +25,22 @@ public class JavaSourceFileScope {
25 25
 	public final JavaSourceTypeVisitor typeVisitor;
26 26
 	public final JavaSourceObjectTypeVisitor objectTypeVisitor;
27 27
 	public final TypeScope semanticScope;
28
+	public final boolean isInterface;
28 29
 	
29
-	public JavaSourceFileScope(JavaSourceImporter importer, JavaSourceSyntheticTypeGenerator typeGenerator, JavaSourceSyntheticHelperGenerator helperGenerator, String className, TypeScope semanticScope) {
30
+	public JavaSourceFileScope(
31
+			JavaSourceImporter importer, 
32
+			JavaSourceSyntheticTypeGenerator typeGenerator,
33
+			JavaSourceSyntheticHelperGenerator helperGenerator,
34
+			String className,
35
+			TypeScope semanticScope,
36
+			boolean isInterface)
37
+	{
30 38
 		this.importer = importer;
31 39
 		this.typeGenerator = typeGenerator;
32 40
 		this.helperGenerator = helperGenerator;
33 41
 		this.className = className;
34 42
 		this.semanticScope = semanticScope;
43
+		this.isInterface = isInterface;
35 44
 		
36 45
 		typeVisitor = new JavaSourceTypeVisitor(importer, typeGenerator);
37 46
 		objectTypeVisitor = typeVisitor.objectTypeVisitor;

+ 1
- 0
Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenType.java View File

@@ -128,6 +128,7 @@ public enum ZSTokenType implements TokenType {
128 128
 	K_WHILE(true, "while"),
129 129
 	K_FOR(true, "for"),
130 130
 	K_THROW(true, "throw"),
131
+	K_PANIC(true, "panic"),
131 132
 	K_LOCK(true, "lock"),
132 133
 	K_TRY(true, "try"),
133 134
 	K_CATCH(true, "catch"),

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

@@ -512,6 +512,11 @@ public abstract class ParsedExpression {
512 512
 				ParsedExpression value = parse(parser);
513 513
 				return new ParsedThrowExpression(position, value);
514 514
 			}
515
+			case K_PANIC: {
516
+				parser.next();
517
+				ParsedExpression value = parse(parser);
518
+				return new ParsedPanicExpression(position, value);
519
+			}
515 520
 			case K_MATCH: {
516 521
 				parser.next();
517 522
 				ParsedExpression source = parse(parser);

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

@@ -10,6 +10,7 @@ import java.util.List;
10 10
 import org.openzen.zenscript.codemodel.FunctionHeader;
11 11
 import org.openzen.zenscript.codemodel.OperatorType;
12 12
 import org.openzen.zenscript.codemodel.expression.CallArguments;
13
+import org.openzen.zenscript.codemodel.expression.ConstructorSuperCallExpression;
13 14
 import org.openzen.zenscript.codemodel.expression.ConstructorThisCallExpression;
14 15
 import org.openzen.zenscript.codemodel.expression.VariantValueExpression;
15 16
 import org.openzen.zenscript.codemodel.expression.switchvalue.SwitchValue;
@@ -70,7 +71,7 @@ public class ParsedExpressionCall extends ParsedExpression {
70 71
 			if (!member.isConstructor())
71 72
 				throw new CompileException(position, CompileExceptionCode.INTERNAL_ERROR, "Constructor is not a constructor!");
72 73
 			
73
-			return new ConstructorThisCallExpression(position, scope.getThisType().getSuperType(), member, callArguments, scope);
74
+			return new ConstructorSuperCallExpression(position, scope.getThisType().getSuperType(), member, callArguments, scope);
74 75
 		} else if (receiver instanceof ParsedExpressionThis) {
75 76
 			// this call (intended as first call in constructor)
76 77
 			ITypeID targetType = scope.getThisType();

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

@@ -0,0 +1,36 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.parser.expression;
7
+
8
+import org.openzen.zenscript.codemodel.expression.PanicExpression;
9
+import org.openzen.zenscript.codemodel.partial.IPartialExpression;
10
+import org.openzen.zenscript.codemodel.scope.ExpressionScope;
11
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
12
+import org.openzen.zenscript.shared.CodePosition;
13
+
14
+/**
15
+ *
16
+ * @author Hoofdgebruiker
17
+ */
18
+public class ParsedPanicExpression extends ParsedExpression {
19
+	public final ParsedExpression value;
20
+	
21
+	public ParsedPanicExpression(CodePosition position, ParsedExpression value) {
22
+		super(position);
23
+		
24
+		this.value = value;
25
+	}
26
+	
27
+	@Override
28
+	public IPartialExpression compile(ExpressionScope scope) {
29
+		return new PanicExpression(position, scope.getResultTypeHints().isEmpty() ? BasicTypeID.VOID : scope.getResultTypeHints().get(0), value.compile(scope).eval());
30
+	}
31
+
32
+	@Override
33
+	public boolean hasStrongType() {
34
+		return true;
35
+	}
36
+}

+ 4
- 0
Shared/src/main/java/org/openzen/zenscript/shared/StringUtils.java View File

@@ -231,10 +231,14 @@ public class StringUtils {
231 231
 				case '"':
232 232
 					if (quote == '"')
233 233
 						output.append("\\\"");
234
+					else
235
+						output.append('"');
234 236
 					break;
235 237
 				case '\'':
236 238
 					if (quote == '\'')
237 239
 						output.append("\\\'");
240
+					else
241
+						output.append("'");
238 242
 					break;
239 243
 				case '\n': output.append("\\n"); break;
240 244
 				case '\r': output.append("\\r"); break;

+ 2
- 1
Validator/src/main/java/org/openzen/zenscript/validator/ValidationLogEntry.java View File

@@ -62,6 +62,7 @@ public class ValidationLogEntry {
62 62
 		SETTING_FINAL_FIELD,
63 63
 		SETTING_FINAL_VARIABLE,
64 64
 		INVALID_SUPERTYPE,
65
-		MULTIPLE_DESTRUCTORS
65
+		MULTIPLE_DESTRUCTORS,
66
+		PANIC_ARGUMENT_NO_STRING
66 67
 	}
67 68
 }

+ 9
- 0
Validator/src/main/java/org/openzen/zenscript/validator/visitors/ExpressionValidator.java View File

@@ -57,6 +57,7 @@ import org.openzen.zenscript.codemodel.expression.MatchExpression;
57 57
 import org.openzen.zenscript.codemodel.expression.NewExpression;
58 58
 import org.openzen.zenscript.codemodel.expression.NullExpression;
59 59
 import org.openzen.zenscript.codemodel.expression.OrOrExpression;
60
+import org.openzen.zenscript.codemodel.expression.PanicExpression;
60 61
 import org.openzen.zenscript.codemodel.expression.PostCallExpression;
61 62
 import org.openzen.zenscript.codemodel.expression.RangeExpression;
62 63
 import org.openzen.zenscript.codemodel.expression.SameObjectExpression;
@@ -445,6 +446,14 @@ public class ExpressionValidator implements ExpressionVisitor<Void> {
445 446
 		return null;
446 447
 	}
447 448
 	
449
+	@Override
450
+	public Void visitPanic(PanicExpression expression) {
451
+		expression.value.accept(this);
452
+		if (expression.type != BasicTypeID.STRING)
453
+			validator.logError(ValidationLogEntry.Code.PANIC_ARGUMENT_NO_STRING, expression.position, "Argument to a panic must be a string");
454
+		return null;
455
+	}
456
+	
448 457
 	@Override
449 458
 	public Void visitPostCall(PostCallExpression expression) {
450 459
 		expression.target.accept(this);

Loading…
Cancel
Save