Browse Source

Fixed LocalVariableGet calls when inside a lambda

kindlich 5 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
 		final JavaStatementVisitor CSV = new JavaStatementVisitor(context, new JavaExpressionVisitor(context, module, functionWriter) {
2064
 		final JavaStatementVisitor CSV = new JavaStatementVisitor(context, new JavaExpressionVisitor(context, module, functionWriter) {
2065
 			@Override
2065
 			@Override
2066
 			public Void visitGetLocalVariable(GetLocalVariableExpression varExpression) {
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
 				final int position = calculateMemberPosition(varExpression, expression);
2078
 				final int position = calculateMemberPosition(varExpression, expression);
2068
 				functionWriter.loadObject(0);
2079
 				functionWriter.loadObject(0);
2069
 				functionWriter.getField(className, "captured" + position, context.getDescriptor(varExpression.variable.type));
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
 import org.openzen.zenscript.javashared.JavaMethod;
11
 import org.openzen.zenscript.javashared.JavaMethod;
12
 import org.openzen.zenscript.javashared.JavaParameterInfo;
12
 import org.openzen.zenscript.javashared.JavaParameterInfo;
13
 
13
 
14
+import javax.lang.model.element.VariableElement;
14
 import java.util.ArrayList;
15
 import java.util.ArrayList;
15
 import java.util.HashMap;
16
 import java.util.HashMap;
16
 import java.util.List;
17
 import java.util.List;
85
 	public void setLocalVariable(VariableID variable, JavaLocalVariableInfo info) {
86
 	public void setLocalVariable(VariableID variable, JavaLocalVariableInfo info) {
86
 		localVariables.put(variable, info);
87
 		localVariables.put(variable, info);
87
 	}
88
 	}
88
-	
89
+
90
+	public JavaLocalVariableInfo tryGetLocalVariable(VariableID variable) {
91
+		return localVariables.get(variable);
92
+	}
93
+
89
 	public JavaLocalVariableInfo getLocalVariable(VariableID variable) {
94
 	public JavaLocalVariableInfo getLocalVariable(VariableID variable) {
90
-		JavaLocalVariableInfo result = localVariables.get(variable);
95
+		JavaLocalVariableInfo result = tryGetLocalVariable(variable);
91
 		if (result == null)
96
 		if (result == null)
92
 			throw new IllegalStateException("Local variable unknown");
97
 			throw new IllegalStateException("Local variable unknown");
93
 		
98
 		

Loading…
Cancel
Save