Search in sources :

Example 31 with CallTarget

use of com.oracle.truffle.api.CallTarget in project graal by oracle.

the class MethodGuardsTest method testGuardGreaterEqual.

@Test
public void testGuardGreaterEqual() {
    CallTarget root = createCallTarget(GuardGreaterEqualTestFactory.getInstance());
    assertEquals("do1", root.call(1));
    assertEquals("do2", root.call(0));
    assertEquals("do1", root.call(2));
    assertEquals("do2", root.call(0));
}
Also used : TestHelper.createCallTarget(com.oracle.truffle.api.dsl.test.TestHelper.createCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) Test(org.junit.Test)

Example 32 with CallTarget

use of com.oracle.truffle.api.CallTarget in project graal by oracle.

the class ArrayTest method testNode1.

@Test
public void testNode1() {
    final TestNode1 node = TestNode1NodeGen.create(null);
    RootNode root = new RootNode(null) {

        @Child
        TestNode1 test = node;

        @Override
        public Object execute(VirtualFrame frame) {
            return test.executeWith(frame, frame.getArguments()[0]);
        }
    };
    CallTarget target = Truffle.getRuntime().createCallTarget(root);
    Assert.assertEquals(1, (int) target.call(1));
    Assert.assertArrayEquals(new double[0], (double[]) target.call(new int[0]), 0.0d);
    Assert.assertArrayEquals(new double[0], (double[]) target.call(new double[0]), 0.0d);
    Assert.assertArrayEquals(new String[0], (String[]) target.call((Object) new String[0]));
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) CallTarget(com.oracle.truffle.api.CallTarget) Test(org.junit.Test)

Example 33 with CallTarget

use of com.oracle.truffle.api.CallTarget in project graal by oracle.

the class NullLiteralGuardsTest method testCompareObjectsNull.

@Test
public void testCompareObjectsNull() {
    CallTarget root = createCallTarget(CompareObjectsNullNodeFactory.getInstance());
    assertEquals("do1", root.call((Object) null));
    assertEquals("do2", root.call("42"));
}
Also used : TestHelper.createCallTarget(com.oracle.truffle.api.dsl.test.TestHelper.createCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) Test(org.junit.Test)

Example 34 with CallTarget

use of com.oracle.truffle.api.CallTarget in project graal by oracle.

the class NullLiteralGuardsTest method testCompareStringNull.

@Test
public void testCompareStringNull() {
    CallTarget root = createCallTarget(CompareStringNullNodeFactory.getInstance());
    assertEquals("do1", root.call("42"));
    assertEquals("do2", root.call((Object) null));
}
Also used : TestHelper.createCallTarget(com.oracle.truffle.api.dsl.test.TestHelper.createCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) Test(org.junit.Test)

Example 35 with CallTarget

use of com.oracle.truffle.api.CallTarget in project graal by oracle.

the class ImplicitCastTest method testImplicitCastExecute.

@Test
public void testImplicitCastExecute() {
    CallTarget target = ExampleNode.createTarget(ImplicitCastExecuteNodeGen.create(ExampleNode.createArguments(2)));
    Assert.assertEquals("s1", target.call(1, 2D));
    Assert.assertEquals("s0", target.call(1, 1));
    target = ExampleNode.createTarget(ImplicitCastExecuteNodeGen.create(ExampleNode.createArguments(2)));
    Assert.assertEquals("s0", target.call(1, 1));
    Assert.assertEquals("s1", target.call(1, 2D));
    target = ExampleNode.createTarget(ImplicitCastExecuteNodeGen.create(ExampleNode.createArguments(2)));
    Assert.assertEquals("s0", target.call(1, 1));
    Assert.assertEquals("s2", target.call(1, 2L));
    target = ExampleNode.createTarget(ImplicitCastExecuteNodeGen.create(ExampleNode.createArguments(2)));
    Assert.assertEquals("s2", target.call(1, 2L));
    Assert.assertEquals("s0", target.call(1, 1));
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) Test(org.junit.Test)

Aggregations

CallTarget (com.oracle.truffle.api.CallTarget)128 Test (org.junit.Test)102 TestHelper.createCallTarget (com.oracle.truffle.api.dsl.test.TestHelper.createCallTarget)50 RootCallTarget (com.oracle.truffle.api.RootCallTarget)26 RootNode (com.oracle.truffle.api.nodes.RootNode)17 TruffleRuntime (com.oracle.truffle.api.TruffleRuntime)15 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)10 UnsupportedSpecializationException (com.oracle.truffle.api.dsl.UnsupportedSpecializationException)9 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)9 Node (com.oracle.truffle.api.nodes.Node)9 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)9 TruffleContext (com.oracle.truffle.api.TruffleContext)6 LanguageContext (com.oracle.truffle.api.test.polyglot.LanguageSPITestLanguage.LanguageContext)6 Context (org.graalvm.polyglot.Context)6 Theory (org.junit.experimental.theories.Theory)6 TruffleException (com.oracle.truffle.api.TruffleException)5 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)5 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)5 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)5 Source (com.oracle.truffle.api.source.Source)5