non-working break
This commit is contained in:
@@ -459,24 +459,30 @@ public class ExpressionCodegen extends JetVisitor {
|
|||||||
DeclarationDescriptor op = bindingContext.resolveReferenceExpression(expression.getOperationReference());
|
DeclarationDescriptor op = bindingContext.resolveReferenceExpression(expression.getOperationReference());
|
||||||
if (op instanceof FunctionDescriptor) {
|
if (op instanceof FunctionDescriptor) {
|
||||||
DeclarationDescriptor cls = op.getContainingDeclaration();
|
DeclarationDescriptor cls = op.getContainingDeclaration();
|
||||||
if (cls instanceof ClassDescriptor && cls.getName().equals("Int")) {
|
if (cls instanceof ClassDescriptor) {
|
||||||
if (op.getName().equals("compareTo")) {
|
final String className = cls.getName();
|
||||||
generateCompareOp(expression, opToken);
|
if (className.equals("Int")) {
|
||||||
}
|
if (op.getName().equals("compareTo")) {
|
||||||
else {
|
generateCompareOp(expression, opToken);
|
||||||
int opcode;
|
|
||||||
if (op.getName().equals("plus")) {
|
|
||||||
opcode = Opcodes.IADD;
|
|
||||||
}
|
|
||||||
else if (op.getName().equals("times")) {
|
|
||||||
opcode = Opcodes.IMUL;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new UnsupportedOperationException("Don't know how to generate binary op method " + op.getName());
|
int opcode;
|
||||||
|
if (op.getName().equals("plus")) {
|
||||||
|
opcode = Opcodes.IADD;
|
||||||
|
}
|
||||||
|
else if (op.getName().equals("times")) {
|
||||||
|
opcode = Opcodes.IMUL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new UnsupportedOperationException("Don't know how to generate binary op method " + op.getName());
|
||||||
|
}
|
||||||
|
generateBinaryOp(expression, (FunctionDescriptor) op, opcode);
|
||||||
}
|
}
|
||||||
generateBinaryOp(expression, (FunctionDescriptor) op, opcode);
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new UnsupportedOperationException("Don't know how to generate binary op for class " + className);
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new UnsupportedOperationException("Don't know how to generate binary op " + expression);
|
throw new UnsupportedOperationException("Don't know how to generate binary op " + expression);
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public abstract class StackValue {
|
|||||||
return new IntCompare(opToken);
|
return new IntCompare(opToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void condJump(Label label, boolean inverse, InstructionAdapter v);
|
public abstract void condJump(Label label, boolean jumpIfFalse, InstructionAdapter v);
|
||||||
|
|
||||||
public static class Local extends StackValue {
|
public static class Local extends StackValue {
|
||||||
private final int index;
|
private final int index;
|
||||||
@@ -48,9 +48,9 @@ public abstract class StackValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void condJump(Label label, boolean inverse, InstructionAdapter v) {
|
public void condJump(Label label, boolean jumpIfFalse, InstructionAdapter v) {
|
||||||
put(Type.INT_TYPE, v);
|
put(Type.INT_TYPE, v);
|
||||||
if (inverse) {
|
if (jumpIfFalse) {
|
||||||
v.ifeq(label);
|
v.ifeq(label);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -71,7 +71,7 @@ public abstract class StackValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void condJump(Label label, boolean inverse, InstructionAdapter v) {
|
public void condJump(Label label, boolean jumpIfFalse, InstructionAdapter v) {
|
||||||
throw new UnsupportedOperationException("don't know how to generate this condjump");
|
throw new UnsupportedOperationException("don't know how to generate this condjump");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,8 +100,16 @@ public abstract class StackValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void condJump(Label label, boolean inverse, InstructionAdapter v) {
|
public void condJump(Label label, boolean jumpIfFalse, InstructionAdapter v) {
|
||||||
throw new UnsupportedOperationException("don't know how to generate this condjump");
|
if (value instanceof Boolean) {
|
||||||
|
boolean boolValue = ((Boolean) value).booleanValue();
|
||||||
|
if (boolValue ^ jumpIfFalse) {
|
||||||
|
v.goTo(label);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new UnsupportedOperationException("don't know how to generate this condjump");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,16 +126,16 @@ public abstract class StackValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void condJump(Label label, boolean inverse, InstructionAdapter v) {
|
public void condJump(Label label, boolean jumpIfFalse, InstructionAdapter v) {
|
||||||
int opcode;
|
int opcode;
|
||||||
if (opToken == JetTokens.GT) {
|
if (opToken == JetTokens.GT) {
|
||||||
opcode = inverse ? Opcodes.IF_ICMPLE : Opcodes.IF_ICMPGT;
|
opcode = jumpIfFalse ? Opcodes.IF_ICMPLE : Opcodes.IF_ICMPGT;
|
||||||
}
|
}
|
||||||
else if (opToken == JetTokens.LT) {
|
else if (opToken == JetTokens.LT) {
|
||||||
opcode = inverse ? Opcodes.IF_ICMPGE : Opcodes.IF_ICMPLT;
|
opcode = jumpIfFalse ? Opcodes.IF_ICMPGE : Opcodes.IF_ICMPLT;
|
||||||
}
|
}
|
||||||
else if (opToken == JetTokens.LTEQ) {
|
else if (opToken == JetTokens.LTEQ) {
|
||||||
opcode = inverse ? Opcodes.IF_ICMPGT : Opcodes.IF_ICMPLE;
|
opcode = jumpIfFalse ? Opcodes.IF_ICMPGT : Opcodes.IF_ICMPLE;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new UnsupportedOperationException("don't know how to generate this condjump");
|
throw new UnsupportedOperationException("don't know how to generate this condjump");
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
fun fac(i: Int): Int {
|
||||||
|
var count = 1;
|
||||||
|
var result = 1;
|
||||||
|
while(true) {
|
||||||
|
count = count + 1;
|
||||||
|
result = result * count;
|
||||||
|
if (count == i) break;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -150,6 +150,10 @@ public class NamespaceGenTest extends LightCodeInsightFixtureTestCase {
|
|||||||
factorialTest("doWhile.jet");
|
factorialTest("doWhile.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBreak() throws Exception {
|
||||||
|
factorialTest("break.jet");
|
||||||
|
}
|
||||||
|
|
||||||
private void factorialTest(final String name) throws IllegalAccessException, InvocationTargetException {
|
private void factorialTest(final String name) throws IllegalAccessException, InvocationTargetException {
|
||||||
loadFile(name);
|
loadFile(name);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user