From 3eebfdc9d96a5ddb798afcd74de89045bf1047ac Mon Sep 17 00:00:00 2001 From: Victorious3 Date: Wed, 1 Mar 2023 16:33:03 +0100 Subject: [PATCH] Fix POP2 not being called for double and long! --- .../java/de/dhbwstuttgart/bytecode/Codegen.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java index 7403f2e16..df56b333f 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java @@ -82,6 +82,13 @@ public class Codegen { } } + private void popValue(State state, TargetType type) { + if (type.equals(TargetType.Double) || type.equals(TargetType.Long)) + state.mv.visitInsn(POP2); + else + state.mv.visitInsn(POP); + } + private void boxPrimitive(State state, TargetType type) { var mv = state.mv; if (type.equals(TargetType.Boolean) || type.equals(TargetType.boolean_)) { @@ -766,9 +773,11 @@ public class Codegen { for (var e : block.statements()) { generate(state, e); if (e instanceof TargetMethodCall) { - if (e.type() != null) mv.visitInsn(POP); - } else if (e instanceof TargetStatementExpression) { - mv.visitInsn(POP); + if (e.type() != null) popValue(state, e.type()); + } else if (e instanceof TargetAssign) { + mv.visitInsn(POP); // TODO Nasty fix, we don't know if it is a primitive double or long + } else if (e instanceof TargetStatementExpression se) { + popValue(state, se.type()); } } state.exitScope(); @@ -885,7 +894,7 @@ public class Codegen { if (_for.increment() != null) { generate(state, _for.increment()); if (_for.increment().type() != null) { - mv.visitInsn(POP); + popValue(state, _for.increment().type()); } } mv.visitJumpInsn(GOTO, start);