Преглед на файлове

WIP: Possibly TryRethrow and panic Expressions

kindlich преди 6 години
родител
ревизия
1c6c2bcf77
No known key found for this signature in database

+ 25
- 2
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java Целия файл

@@ -3890,12 +3890,35 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
3890 3890
 
3891 3891
 	@Override
3892 3892
 	public Void visitTryRethrowAsException(TryRethrowAsExceptionExpression expression) {
3893
-		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
3893
+		expression.value.accept(this);
3894
+		javaWriter.dup();
3895
+		//FIXME better way of finding the error
3896
+		final String internalName = context.getInternalName(expression.value.type) + "$Error";
3897
+		javaWriter.instanceOf(internalName);
3898
+		final Label end = new Label();
3899
+		javaWriter.ifNE(end);
3900
+		javaWriter.newObject(Type.getInternalName(Exception.class));
3901
+		javaWriter.dup();
3902
+		javaWriter.invokeSpecial(Type.getInternalName(Exception.class), "<init>", "()V");
3903
+		javaWriter.label(end);
3904
+		return null;
3894 3905
 	}
3895 3906
 
3896 3907
 	@Override
3897 3908
 	public Void visitTryRethrowAsResult(TryRethrowAsResultExpression expression) {
3898
-		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
3909
+		expression.value.accept(this);
3910
+		javaWriter.dup();
3911
+		//FIXME better way of finding the error
3912
+		final String internalName = context.getInternalName(expression.value.type) + "$Error";
3913
+		javaWriter.instanceOf(internalName);
3914
+		final Label end = new Label();
3915
+		javaWriter.ifNE(end);
3916
+		javaWriter.newObject(internalName);
3917
+		javaWriter.dupX1();
3918
+		javaWriter.swap();
3919
+		javaWriter.invokeSpecial(internalName, "<init>", "(Ljava/lang/Object;)V");
3920
+		javaWriter.label(end);
3921
+		return null;
3899 3922
 	}
3900 3923
 
3901 3924
 	@Override

+ 1
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaNonPushingExpressionVisitor.java Целия файл

@@ -558,7 +558,7 @@ public class JavaNonPushingExpressionVisitor implements ExpressionVisitor<Void>
558 558
 	public Void visitPanic(PanicExpression expression) {
559 559
 		javaWriter.newObject("java/lang/AssertionError");
560 560
 		javaWriter.dup();
561
-		expression.value.accept(this);
561
+		expression.value.accept(original);
562 562
 		javaWriter.invokeSpecial(AssertionError.class, "<init>", "(Ljava/lang/String;)V");
563 563
 		javaWriter.aThrow();
564 564
 		return null;

Loading…
Отказ
Запис