div/mod
This commit is contained in:
@@ -494,15 +494,11 @@ public class ExpressionCodegen extends JetVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static int opcodeForMethod(final String name) {
|
private static int opcodeForMethod(final String name) {
|
||||||
if (name.equals("plus")) {
|
if (name.equals("plus")) return Opcodes.IADD;
|
||||||
return Opcodes.IADD;
|
if (name.equals("minus")) return Opcodes.ISUB;
|
||||||
}
|
if (name.equals("times")) return Opcodes.IMUL;
|
||||||
if (name.equals("minus")) {
|
if (name.equals("div")) return Opcodes.IDIV;
|
||||||
return Opcodes.ISUB;
|
if (name.equals("mod")) return Opcodes.IREM;
|
||||||
}
|
|
||||||
if (name.equals("times")) {
|
|
||||||
return Opcodes.IMUL;
|
|
||||||
}
|
|
||||||
throw new UnsupportedOperationException("Don't know how to generate binary op method " + name);
|
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 com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.JetLightProjectDescriptor;
|
import org.jetbrains.jet.JetLightProjectDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.JetFileType;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||||
@@ -171,6 +172,25 @@ public class NamespaceGenTest extends LightCodeInsightFixtureTestCase {
|
|||||||
assertEquals(7, main.invoke(null, 5));
|
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) {
|
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