diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedBinary.java b/src/main/java/de/maishai/typedast/typedclass/TypedBinary.java index 2aa1270..0546da8 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedBinary.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedBinary.java @@ -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); diff --git a/src/main/resources/JavaTestfiles/ClassCanBeTyped.java b/src/main/resources/JavaTestfiles/ClassCanBeTyped.java index d02fcc5..85a8236 100644 --- a/src/main/resources/JavaTestfiles/ClassCanBeTyped.java +++ b/src/main/resources/JavaTestfiles/ClassCanBeTyped.java @@ -5,7 +5,7 @@ public class ClassCanBeTyped { public boolean test(boolean b, boolean c) { - return b == c; + return b || c; } }