put IntCompare on stack
This commit is contained in:
@@ -486,7 +486,7 @@ public class ExpressionCodegen extends JetVisitor {
|
|||||||
if (op.getName().equals("equals")) {
|
if (op.getName().equals("equals")) {
|
||||||
final Type leftType = typeMapper.mapType(bindingContext.getExpressionType(expression.getLeft()));
|
final Type leftType = typeMapper.mapType(bindingContext.getExpressionType(expression.getLeft()));
|
||||||
final Type rightType = typeMapper.mapType(bindingContext.getExpressionType(expression.getRight()));
|
final Type rightType = typeMapper.mapType(bindingContext.getExpressionType(expression.getRight()));
|
||||||
if (leftType == Type.INT_TYPE && rightType == Type.INT_TYPE) {
|
if (isIntLikePrimitive(leftType) && isIntLikePrimitive(rightType)) {
|
||||||
gen(expression.getLeft(), Type.INT_TYPE);
|
gen(expression.getLeft(), Type.INT_TYPE);
|
||||||
gen(expression.getRight(), Type.INT_TYPE);
|
gen(expression.getRight(), Type.INT_TYPE);
|
||||||
myStack.push(StackValue.icmp(opToken));
|
myStack.push(StackValue.icmp(opToken));
|
||||||
@@ -505,6 +505,10 @@ public class ExpressionCodegen extends JetVisitor {
|
|||||||
throw new UnsupportedOperationException("Don't know how to generate binary op " + expression);
|
throw new UnsupportedOperationException("Don't know how to generate binary op " + expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isIntLikePrimitive(Type type) {
|
||||||
|
return type == Type.INT_TYPE || type == Type.BYTE_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
private static int opcodeForMethod(final String name) {
|
private static int opcodeForMethod(final String name) {
|
||||||
if (name.equals("plus")) return Opcodes.IADD;
|
if (name.equals("plus")) return Opcodes.IADD;
|
||||||
if (name.equals("minus")) return Opcodes.ISUB;
|
if (name.equals("minus")) return Opcodes.ISUB;
|
||||||
|
|||||||
@@ -133,7 +133,14 @@ public abstract class StackValue {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void put(Type type, InstructionAdapter v) {
|
public void put(Type type, InstructionAdapter v) {
|
||||||
throw new UnsupportedOperationException("don't know how to put an IntCompare on stack");
|
Label ifTrue = new Label();
|
||||||
|
Label end = new Label();
|
||||||
|
condJump(ifTrue, false, v);
|
||||||
|
v.iconst(0);
|
||||||
|
v.goTo(end);
|
||||||
|
v.mark(ifTrue);
|
||||||
|
v.iconst(1);
|
||||||
|
v.mark(end);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -207,6 +207,13 @@ public class NamespaceGenTest extends LightCodeInsightFixtureTestCase {
|
|||||||
assertEquals(10, main.invoke(null, "false"));
|
assertEquals(10, main.invoke(null, "false"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testReturnCmp() throws Exception {
|
||||||
|
loadText("fun foo(a: Int, b: Int): Boolean = a == b");
|
||||||
|
final Method main = generateFunction();
|
||||||
|
assertEquals(true, main.invoke(null, 1, 1));
|
||||||
|
assertEquals(false, main.invoke(null, 1, 2));
|
||||||
|
}
|
||||||
|
|
||||||
public void _testBoxedInt() throws Exception {
|
public void _testBoxedInt() throws Exception {
|
||||||
loadText("fun foo(a: Int?): Int = if (a != null) a else 239");
|
loadText("fun foo(a: Int?): Int = if (a != null) a else 239");
|
||||||
final Method main = generateFunction();
|
final Method main = generateFunction();
|
||||||
@@ -247,6 +254,11 @@ public class NamespaceGenTest extends LightCodeInsightFixtureTestCase {
|
|||||||
Byte.valueOf((byte) 127), Byte.valueOf((byte) 127), 254);
|
Byte.valueOf((byte) 127), Byte.valueOf((byte) 127), 254);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testByteCmp() throws Exception {
|
||||||
|
binOpTest("fun foo(a: Byte, b: Byte): Int = if (a == b) 1 else 0",
|
||||||
|
Byte.valueOf((byte) 127), Byte.valueOf((byte) 127), 1);
|
||||||
|
}
|
||||||
|
|
||||||
private void binOpTest(final String text, final Object arg1, final Object arg2, final int expected) throws Exception {
|
private void binOpTest(final String text, final Object arg1, final Object arg2, final int expected) throws Exception {
|
||||||
loadText(text);
|
loadText(text);
|
||||||
System.out.println(generateToText());
|
System.out.println(generateToText());
|
||||||
|
|||||||
Reference in New Issue
Block a user