From e607ae43b5a2bc1a9b27ed02b611013390bcaee6 Mon Sep 17 00:00:00 2001 From: kindlich Date: Sat, 14 Sep 2024 23:41:51 +0200 Subject: [PATCH] Cleanup: Apply some things seen during the code-review --- .../javabytecode/compiler/JavaFieldBytecodeCompiler.java | 4 ++-- .../compiler/JavaNonPushingExpressionVisitor.java | 7 +++---- ...edExpressionVisitorToAccessCapturesInsideTheLambda.java | 5 +++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaFieldBytecodeCompiler.java b/JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaFieldBytecodeCompiler.java index 40d553a1..e5fbb32b 100644 --- a/JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaFieldBytecodeCompiler.java +++ b/JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaFieldBytecodeCompiler.java @@ -7,10 +7,10 @@ public class JavaFieldBytecodeCompiler implements JavaFieldCompiler { private final JavaWriter javaWriter; - private final ExpressionVisitor expressionVisitor; + private final JavaExpressionVisitor expressionVisitor; private final boolean pushing; - public JavaFieldBytecodeCompiler(JavaWriter javaWriter, ExpressionVisitor expressionVisitor, boolean pushing) { + public JavaFieldBytecodeCompiler(JavaWriter javaWriter, JavaExpressionVisitor expressionVisitor, boolean pushing) { this.javaWriter = javaWriter; this.expressionVisitor = expressionVisitor; this.pushing = pushing; diff --git a/JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaNonPushingExpressionVisitor.java b/JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaNonPushingExpressionVisitor.java index e071c1bb..f40b25b4 100644 --- a/JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaNonPushingExpressionVisitor.java +++ b/JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaNonPushingExpressionVisitor.java @@ -24,11 +24,11 @@ public class JavaNonPushingExpressionVisitor implements ExpressionVisitor private final JavaBytecodeContext context; private final JavaCompiledModule module; private final JavaWriter javaWriter; - private final ExpressionVisitor original; + private final JavaExpressionVisitor original; private final JavaFieldBytecodeCompiler fieldCompiler; private final JavaMangler mangler; - public JavaNonPushingExpressionVisitor(JavaBytecodeContext context, JavaCompiledModule module, JavaWriter javaWriter, JavaMangler mangler, ExpressionVisitor original) { + public JavaNonPushingExpressionVisitor(JavaBytecodeContext context, JavaCompiledModule module, JavaWriter javaWriter, JavaMangler mangler, JavaExpressionVisitor original) { this.context = context; this.module = module; this.javaWriter = javaWriter; @@ -335,8 +335,7 @@ public Void visitPlatformSpecific(Expression expression) { @Override public Void visitModification(ModificationExpression expression) { - // Todo: fix cast - ((JavaExpressionVisitor)original).modify(expression, PushOption.NONE); + original.modify(expression, PushOption.NONE); return null; } diff --git a/JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/capturing/JavaCapturedExpressionVisitorToAccessCapturesInsideTheLambda.java b/JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/capturing/JavaCapturedExpressionVisitorToAccessCapturesInsideTheLambda.java index 4d8acfc1..fd034bda 100644 --- a/JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/capturing/JavaCapturedExpressionVisitorToAccessCapturesInsideTheLambda.java +++ b/JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/capturing/JavaCapturedExpressionVisitorToAccessCapturesInsideTheLambda.java @@ -8,7 +8,7 @@ import org.openzen.zenscript.javabytecode.compiler.JavaWriter; /** - * {@link CapturedExpressionVisitor} used to inside a lambda expression. + * {@link CapturedExpressionVisitor} used to access captured values inside a lambda expression. */ public class JavaCapturedExpressionVisitorToAccessCapturesInsideTheLambda implements CapturedExpressionVisitor { @@ -41,6 +41,7 @@ public Void visitCapturedThis(CapturedThisExpression expression) { @Override public Void visitCapturedParameter(CapturedParameterExpression expression) { final int position = calculateMemberPosition(expression, this.functionExpression); + javaWriter.loadObject(0); javaWriter.getField(lambdaClassName, this.javaMangler.mangleCapturedParameter(position, false), context.getDescriptor(expression.parameter.type)); return null; @@ -57,7 +58,7 @@ public Void visitCapturedLocal(CapturedLocalVariableExpression expression) { @Override public Void visitRecaptured(CapturedClosureExpression expression) { - int position = findIndex(expression); + final int position = findIndex(expression); javaWriter.loadObject(0); javaWriter.getField(lambdaClassName, this.javaMangler.mangleCapturedParameter(position, false), context.getDescriptor(expression.type));