accurately depicted stack size

This commit is contained in:
404Simon 2024-05-20 17:53:15 +02:00
parent 02039a5334
commit acf7b4eff8
3 changed files with 9 additions and 2 deletions

View File

@ -98,7 +98,7 @@ public class TypedAssignment implements TypedStatement {
}
ctx.getMv().visitFieldInsn(Opcodes.PUTFIELD, receiver, location.getName(), value.getType().getDescriptor());
System.out.println("PUTFIELD: " + receiver + " " + location.getName() + " " + value.getType().getDescriptor());
ctx.popStack();
} else {
if(value.getType().getKind() == Type.Kind.REFERENCE) {
System.out.println("ASTORE " + ctx.getLocalVar(location.getName()).get().index());
@ -115,5 +115,8 @@ public class TypedAssignment implements TypedStatement {
location.getRecursiveOwnerChain().codeGen(ctx);
ctx.pushAnonToStack();
}
if (location.getRecursiveOwnerChain() == null && location.getField()) {
ctx.pushStack("this");
}
}
}

View File

@ -47,13 +47,15 @@ public class TypedReturn implements TypedStatement {
public void codeGen(MethodContext ctx) {
if (ret == null) {
ctx.getMv().visitInsn(Opcodes.RETURN);
System.out.println("RETURN");
} else {
System.out.println("return: " + ret);
ret.codeGen(ctx);
if (ret.getType().getKind() != Type.Kind.REFERENCE) {
ctx.getMv().visitInsn(Opcodes.IRETURN);
System.out.println("IRETURN");
} else {
ctx.getMv().visitInsn(Opcodes.ARETURN);
System.out.println("ARETURN");
}
}

View File

@ -1,4 +1,5 @@
public class ClassCanBeBytecoded {
public ClassCanBeBytecoded c;
public ClassCanBeBytecoded() {
}
@ -15,6 +16,7 @@ public class ClassCanBeBytecoded {
ClassCanBeBytecoded c;
c = new ClassCanBeBytecoded(result);
result = var1 + var1;
this.c = c;
return c;
}
}