all binary operator supported

This commit is contained in:
404Simon 2024-05-14 14:27:55 +02:00
parent 69548745c2
commit 8cdbf7a23b
2 changed files with 76 additions and 1 deletions

View File

@ -111,6 +111,81 @@ public class TypedBinary implements TypedExpression {
ctx.getMv().visitJumpInsn(Opcodes.IF_ICMPNE, returnFalse);
ctx.getMv().visitJumpInsn(Opcodes.GOTO, returnTrue);
ctx.getMv().visitLabel(returnFalse);
ctx.getMv().visitInsn(Opcodes.ICONST_0);
ctx.getMv().visitJumpInsn(Opcodes.GOTO, end);
ctx.getMv().visitLabel(returnTrue);
ctx.getMv().visitInsn(Opcodes.ICONST_1);
ctx.getMv().visitLabel(end);
} else if (op == Operator.GT) {
Label end = new Label();
Label returnTrue = new Label();
Label returnFalse = new Label();
left.codeGen(ctx);
right.codeGen(ctx);
ctx.getMv().visitJumpInsn(Opcodes.IF_ICMPLE, returnFalse);
ctx.getMv().visitJumpInsn(Opcodes.GOTO, returnTrue);
ctx.getMv().visitLabel(returnFalse);
ctx.getMv().visitInsn(Opcodes.ICONST_0);
ctx.getMv().visitJumpInsn(Opcodes.GOTO, end);
ctx.getMv().visitLabel(returnTrue);
ctx.getMv().visitInsn(Opcodes.ICONST_1);
ctx.getMv().visitLabel(end);
} else if (op == Operator.LT) {
Label end = new Label();
Label returnTrue = new Label();
Label returnFalse = new Label();
left.codeGen(ctx);
right.codeGen(ctx);
ctx.getMv().visitJumpInsn(Opcodes.IF_ICMPGE, returnFalse);
ctx.getMv().visitJumpInsn(Opcodes.GOTO, returnTrue);
ctx.getMv().visitLabel(returnFalse);
ctx.getMv().visitInsn(Opcodes.ICONST_0);
ctx.getMv().visitJumpInsn(Opcodes.GOTO, end);
ctx.getMv().visitLabel(returnTrue);
ctx.getMv().visitInsn(Opcodes.ICONST_1);
ctx.getMv().visitLabel(end);
} else if (op == Operator.GE) {
Label end = new Label();
Label returnTrue = new Label();
Label returnFalse = new Label();
left.codeGen(ctx);
right.codeGen(ctx);
ctx.getMv().visitJumpInsn(Opcodes.IF_ICMPLT, returnFalse);
ctx.getMv().visitJumpInsn(Opcodes.GOTO, returnTrue);
ctx.getMv().visitLabel(returnFalse);
ctx.getMv().visitInsn(Opcodes.ICONST_0);
ctx.getMv().visitJumpInsn(Opcodes.GOTO, end);
ctx.getMv().visitLabel(returnTrue);
ctx.getMv().visitInsn(Opcodes.ICONST_1);
ctx.getMv().visitLabel(end);
} else if (op == Operator.LE) {
Label end = new Label();
Label returnTrue = new Label();
Label returnFalse = new Label();
left.codeGen(ctx);
right.codeGen(ctx);
ctx.getMv().visitJumpInsn(Opcodes.IF_ICMPGT, returnFalse);
ctx.getMv().visitJumpInsn(Opcodes.GOTO, returnTrue);
ctx.getMv().visitLabel(returnFalse);
ctx.getMv().visitInsn(Opcodes.ICONST_0);
ctx.getMv().visitJumpInsn(Opcodes.GOTO, end);
ctx.getMv().visitLabel(returnTrue);
ctx.getMv().visitInsn(Opcodes.ICONST_1);
ctx.getMv().visitLabel(end);
} else if (op == Operator.NE) {
Label end = new Label();
Label returnTrue = new Label();
Label returnFalse = new Label();
left.codeGen(ctx);
right.codeGen(ctx);
ctx.getMv().visitJumpInsn(Opcodes.IF_ICMPEQ, returnFalse);
ctx.getMv().visitJumpInsn(Opcodes.GOTO, returnTrue);
ctx.getMv().visitLabel(returnFalse);
ctx.getMv().visitInsn(Opcodes.ICONST_0);
ctx.getMv().visitJumpInsn(Opcodes.GOTO, end);

View File

@ -5,7 +5,7 @@ public class ClassCanBeTyped {
public boolean test(boolean b, boolean c) {
return b == c;
return b || c;
}
}