Browse Source

Fixed LocalVariableGet calls when inside a lambda

kindlich 4 years ago
parent
commit
6d51a81766
No known key found for this signature in database

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

@@ -2064,6 +2064,17 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
2064 2064
 		final JavaStatementVisitor CSV = new JavaStatementVisitor(context, new JavaExpressionVisitor(context, module, functionWriter) {
2065 2065
 			@Override
2066 2066
 			public Void visitGetLocalVariable(GetLocalVariableExpression varExpression) {
2067
+				final JavaLocalVariableInfo localVariable = functionWriter.tryGetLocalVariable(varExpression.variable.variable);
2068
+				if(localVariable != null) {
2069
+					final Label label = new Label();
2070
+					localVariable.end = label;
2071
+					functionWriter.label(label);
2072
+					functionWriter.load(localVariable);
2073
+					return null;
2074
+				}
2075
+
2076
+
2077
+
2067 2078
 				final int position = calculateMemberPosition(varExpression, expression);
2068 2079
 				functionWriter.loadObject(0);
2069 2080
 				functionWriter.getField(className, "captured" + position, context.getDescriptor(varExpression.variable.type));

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

@@ -11,6 +11,7 @@ import org.openzen.zenscript.javashared.JavaField;
11 11
 import org.openzen.zenscript.javashared.JavaMethod;
12 12
 import org.openzen.zenscript.javashared.JavaParameterInfo;
13 13
 
14
+import javax.lang.model.element.VariableElement;
14 15
 import java.util.ArrayList;
15 16
 import java.util.HashMap;
16 17
 import java.util.List;
@@ -85,9 +86,13 @@ public class JavaWriter {
85 86
 	public void setLocalVariable(VariableID variable, JavaLocalVariableInfo info) {
86 87
 		localVariables.put(variable, info);
87 88
 	}
88
-	
89
+
90
+	public JavaLocalVariableInfo tryGetLocalVariable(VariableID variable) {
91
+		return localVariables.get(variable);
92
+	}
93
+
89 94
 	public JavaLocalVariableInfo getLocalVariable(VariableID variable) {
90
-		JavaLocalVariableInfo result = localVariables.get(variable);
95
+		JavaLocalVariableInfo result = tryGetLocalVariable(variable);
91 96
 		if (result == null)
92 97
 			throw new IllegalStateException("Local variable unknown");
93 98
 		

Loading…
Cancel
Save