correctly generate !=

This commit is contained in:
Dmitry Jemerov
2011-04-07 12:49:31 +02:00
parent 36ae75de34
commit 0af4b3b4c1
3 changed files with 14 additions and 2 deletions
@@ -107,6 +107,9 @@ public class ExpressionCodegen extends JetVisitor {
gen(elseExpression, asmType);
v.mark(endLabel);
if (asmType != Type.VOID_TYPE) {
myStack.push(StackValue.onStack(asmType));
}
}
@Override
@@ -141,7 +144,7 @@ public class ExpressionCodegen extends JetVisitor {
gen(expression.getBody(), Type.VOID_TYPE);
gen(expression.getCondition());
myStack.pop().condJump(condition, true, v);
myStack.pop().condJump(condition, false, v);
v.mark(end);
@@ -477,7 +480,7 @@ public class ExpressionCodegen extends JetVisitor {
if (leftType == Type.INT_TYPE && rightType == Type.INT_TYPE) {
gen(expression.getLeft(), Type.INT_TYPE);
gen(expression.getRight(), Type.INT_TYPE);
myStack.push(StackValue.icmp(JetTokens.EQEQ));
myStack.push(StackValue.icmp(opToken));
return;
}
else {
@@ -19,6 +19,7 @@ public abstract class StackValue {
}
public static StackValue onStack(Type type) {
assert type != Type.VOID_TYPE;
return new OnStack(type);
}
@@ -131,6 +132,9 @@ public abstract class StackValue {
if (opToken == JetTokens.EQEQ) {
opcode = jumpIfFalse ? Opcodes.IF_ICMPNE : Opcodes.IF_ICMPEQ;
}
else if (opToken == JetTokens.EXCLEQ) {
opcode = jumpIfFalse ? Opcodes.IF_ICMPEQ : Opcodes.IF_ICMPNE;
}
else if (opToken == JetTokens.GT) {
opcode = jumpIfFalse ? Opcodes.IF_ICMPLE : Opcodes.IF_ICMPGT;
}
@@ -180,6 +180,11 @@ public class NamespaceGenTest extends LightCodeInsightFixtureTestCase {
binOpTest("fun foo(a: Int, b: Int): Int = a % b", 14, 3, 2);
}
public void testNE() throws Exception {
binOpTest("fun foo(a: Int, b: Int): Int = if (a != b) 1 else 0", 5, 5, 0);
binOpTest("fun foo(a: Int, b: Int): Int = if (a != b) 1 else 0", 5, 3, 1);
}
public void testIfNoElse() throws Exception {
loadFile("ifNoElse.jet");
System.out.println(generateToText());