test for continue; minus works
This commit is contained in:
@@ -465,16 +465,7 @@ public class ExpressionCodegen extends JetVisitor {
|
|||||||
generateCompareOp(expression, opToken);
|
generateCompareOp(expression, opToken);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int opcode;
|
int opcode = opcodeForMethod(op.getName());
|
||||||
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;
|
return;
|
||||||
@@ -502,6 +493,19 @@ 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 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) {
|
private void generateBinaryOp(JetBinaryExpression expression, FunctionDescriptor op, int opcode) {
|
||||||
JetType returnType = op.getUnsubstitutedReturnType();
|
JetType returnType = op.getUnsubstitutedReturnType();
|
||||||
if (returnType.equals(stdlib.getIntType())) {
|
if (returnType.equals(stdlib.getIntType())) {
|
||||||
|
|||||||
@@ -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));
|
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) {
|
private void loadFile(final String name) {
|
||||||
myFixture.configureByFile(JetParsingTest.getTestDataDir() + "/codegen/" + name);
|
myFixture.configureByFile(JetParsingTest.getTestDataDir() + "/codegen/" + name);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user