test for continue; minus works

This commit is contained in:
Dmitry Jemerov
2011-04-07 11:45:35 +02:00
parent fcdba8c950
commit 6cbe151ba8
3 changed files with 32 additions and 10 deletions
@@ -465,16 +465,7 @@ public class ExpressionCodegen extends JetVisitor {
generateCompareOp(expression, opToken);
}
else {
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());
}
int opcode = opcodeForMethod(op.getName());
generateBinaryOp(expression, (FunctionDescriptor) op, opcode);
}
return;
@@ -502,6 +493,19 @@ public class ExpressionCodegen extends JetVisitor {
throw new UnsupportedOperationException("Don't know how to generate binary op " + expression);
}
private static int opcodeForMethod(final String name) {
if (name.equals("plus")) {
return Opcodes.IADD;
}
if (name.equals("minus")) {
return Opcodes.ISUB;
}
if (name.equals("times")) {
return Opcodes.IMUL;
}
throw new UnsupportedOperationException("Don't know how to generate binary op method " + name);
}
private void generateBinaryOp(JetBinaryExpression expression, FunctionDescriptor op, int opcode) {
JetType returnType = op.getUnsubstitutedReturnType();
if (returnType.equals(stdlib.getIntType())) {
+10
View File
@@ -0,0 +1,10 @@
fun continue_test(i: Int): Int {
var count = i;
var result = 0;
while(count > 0) {
count = count - 1;
if (count <= 2) continue;
result = result + count;
}
return result;
}
@@ -163,6 +163,14 @@ public class NamespaceGenTest extends LightCodeInsightFixtureTestCase {
assertEquals(120, main.invoke(null, 5));
}
public void testContinue() throws Exception {
loadFile("continue.jet");
System.out.println(generateToText());
final Method main = generateFunction();
assertEquals(3, main.invoke(null, 4));
assertEquals(7, main.invoke(null, 5));
}
private void loadFile(final String name) {
myFixture.configureByFile(JetParsingTest.getTestDataDir() + "/codegen/" + name);
}