diff --git a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java index 7403f2e1..df56b333 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);