more sane types for StackValue.cmp()

This commit is contained in:
Dmitry Jemerov
2011-04-08 18:38:41 +02:00
parent 4953608fb5
commit 5bebb848b6
2 changed files with 8 additions and 5 deletions
@@ -594,7 +594,7 @@ public class ExpressionCodegen extends JetVisitor {
private void generateCompareOp(JetBinaryExpression expression, IElementType opToken, Type type) { private void generateCompareOp(JetBinaryExpression expression, IElementType opToken, Type type) {
gen(expression.getLeft(), type); gen(expression.getLeft(), type);
gen(expression.getRight(), type); gen(expression.getRight(), type);
myStack.push(StackValue.cmp(opToken, type)); myStack.push(StackValue.cmp(opToken));
} }
private void generateAssignmentExpression(JetBinaryExpression expression) { private void generateAssignmentExpression(JetBinaryExpression expression) {
@@ -32,8 +32,8 @@ public abstract class StackValue {
return new Constant(value, type); return new Constant(value, type);
} }
public static StackValue cmp(IElementType opToken, Type type) { public static StackValue cmp(IElementType opToken) {
return new NumberCompare(opToken, type); return new NumberCompare(opToken);
} }
public abstract void condJump(Label label, boolean jumpIfFalse, InstructionAdapter v); public abstract void condJump(Label label, boolean jumpIfFalse, InstructionAdapter v);
@@ -158,13 +158,16 @@ public abstract class StackValue {
private static class NumberCompare extends StackValue { private static class NumberCompare extends StackValue {
private final IElementType opToken; private final IElementType opToken;
public NumberCompare(IElementType opToken, Type type) { public NumberCompare(IElementType opToken) {
super(type); super(Type.BOOLEAN_TYPE);
this.opToken = opToken; this.opToken = opToken;
} }
@Override @Override
public void put(Type type, InstructionAdapter v) { public void put(Type type, InstructionAdapter v) {
if (type != Type.BOOLEAN_TYPE) {
throw new UnsupportedOperationException("don't know how to put a compare as a non-boolean type");
}
Label ifTrue = new Label(); Label ifTrue = new Label();
Label end = new Label(); Label end = new Label();
condJump(ifTrue, false, v); condJump(ifTrue, false, v);