Fix POP2 not being called for double and long!

This commit is contained in:
Victorious3 2023-03-01 16:33:03 +01:00
parent ba66f29fba
commit 3eebfdc9d9

View File

@ -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) { private void boxPrimitive(State state, TargetType type) {
var mv = state.mv; var mv = state.mv;
if (type.equals(TargetType.Boolean) || type.equals(TargetType.boolean_)) { if (type.equals(TargetType.Boolean) || type.equals(TargetType.boolean_)) {
@ -766,9 +773,11 @@ public class Codegen {
for (var e : block.statements()) { for (var e : block.statements()) {
generate(state, e); generate(state, e);
if (e instanceof TargetMethodCall) { if (e instanceof TargetMethodCall) {
if (e.type() != null) mv.visitInsn(POP); if (e.type() != null) popValue(state, e.type());
} else if (e instanceof TargetStatementExpression) { } else if (e instanceof TargetAssign) {
mv.visitInsn(POP); 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(); state.exitScope();
@ -885,7 +894,7 @@ public class Codegen {
if (_for.increment() != null) { if (_for.increment() != null) {
generate(state, _for.increment()); generate(state, _for.increment());
if (_for.increment().type() != null) { if (_for.increment().type() != null) {
mv.visitInsn(POP); popValue(state, _for.increment().type());
} }
} }
mv.visitJumpInsn(GOTO, start); mv.visitJumpInsn(GOTO, start);