This commit is contained in:
Dmitry Jemerov
2011-04-07 12:09:43 +02:00
parent 6cbe151ba8
commit dc326ca3cd
2 changed files with 25 additions and 9 deletions
@@ -494,15 +494,11 @@ public class ExpressionCodegen extends JetVisitor {
}
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;
}
if (name.equals("plus")) return Opcodes.IADD;
if (name.equals("minus")) return Opcodes.ISUB;
if (name.equals("times")) return Opcodes.IMUL;
if (name.equals("div")) return Opcodes.IDIV;
if (name.equals("mod")) return Opcodes.IREM;
throw new UnsupportedOperationException("Don't know how to generate binary op method " + name);
}
@@ -4,6 +4,7 @@ import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.JetLightProjectDescriptor;
import org.jetbrains.jet.lang.JetFileType;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetNamespace;
import org.jetbrains.jet.parsing.JetParsingTest;
@@ -171,6 +172,25 @@ public class NamespaceGenTest extends LightCodeInsightFixtureTestCase {
assertEquals(7, main.invoke(null, 5));
}
public void testDiv() throws Exception {
binOpTest("fun foo(a: Int, b: Int): Int = a / b", 12, 3, 4);
}
public void testMod() throws Exception {
binOpTest("fun foo(a: Int, b: Int): Int = a % b", 14, 3, 2);
}
private void binOpTest(final String text, final int arg1, final int arg2, final int expected) throws Exception {
loadText(text);
System.out.println(generateToText());
final Method main = generateFunction();
assertEquals(expected, main.invoke(null, arg1, arg2));
}
private void loadText(final String text) {
myFixture.configureByText(JetFileType.INSTANCE, text);
}
private void loadFile(final String name) {
myFixture.configureByFile(JetParsingTest.getTestDataDir() + "/codegen/" + name);
}