Search in sources :

Example 46 with CallTarget

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

the class StackTraceTest method testFirstFrameIsCurrentFrame.

@Test
public void testFirstFrameIsCurrentFrame() {
    CallTarget callTarget = createCallTarget(new ReturnStackTraceNode());
    StackTrace stack = (StackTrace) callTarget.call();
    Assert.assertEquals(1, stack.frames.size());
    assertFrameEquals(stack.currentFrame, stack.frames.get(0));
}
Also used : RootCallTarget(com.oracle.truffle.api.RootCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) Test(org.junit.Test)

Example 47 with CallTarget

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

the class AccessorTest method testAccessorInstrumentationHandlerNotInitialized.

/**
 * Test that {@link CallTarget}s can be called even when the instrumentation framework is not
 * initialized (e.g., when not using the {@link PolyglotEngine}).
 */
@Test
public void testAccessorInstrumentationHandlerNotInitialized() throws IllegalAccessException {
    Object savedAccessor = instrumenthandler.get(null);
    instrumenthandler.set(null, null);
    try {
        CallTarget testCallTarget = Truffle.getRuntime().createCallTarget(RootNode.createConstantNode(42));
        assertEquals(42, testCallTarget.call(new Object[0]));
    } finally {
        instrumenthandler.set(null, savedAccessor);
    }
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) Test(org.junit.Test)

Example 48 with CallTarget

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

the class ChildrenNodesTest method test.

@Test
public void test() {
    TruffleRuntime runtime = Truffle.getRuntime();
    TestChildNode firstChild = new TestChildNode();
    TestChildNode secondChild = new TestChildNode();
    TestRootNode rootNode = new TestRootNode(new TestChildNode[] { firstChild, secondChild });
    CallTarget target = runtime.createCallTarget(rootNode);
    Assert.assertEquals(rootNode, firstChild.getParent());
    Assert.assertEquals(rootNode, secondChild.getParent());
    Iterator<Node> iterator = rootNode.getChildren().iterator();
    Assert.assertEquals(firstChild, iterator.next());
    Assert.assertEquals(secondChild, iterator.next());
    Assert.assertFalse(iterator.hasNext());
    Object result = target.call();
    Assert.assertEquals(42, result);
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) TruffleRuntime(com.oracle.truffle.api.TruffleRuntime) Test(org.junit.Test)

Example 49 with CallTarget

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

the class FinalFieldTest method test.

@Test
public void test() {
    TruffleRuntime runtime = Truffle.getRuntime();
    TestRootNode rootNode = new TestRootNode(new TestChildNode[] { new TestChildNode(20), new TestChildNode(22) });
    CallTarget target = runtime.createCallTarget(rootNode);
    Object result = target.call();
    Assert.assertEquals(42, result);
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) TruffleRuntime(com.oracle.truffle.api.TruffleRuntime) Test(org.junit.Test)

Example 50 with CallTarget

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

the class InterfaceChildFieldTest method testChildren.

@Test
public void testChildren() {
    TruffleRuntime runtime = Truffle.getRuntime();
    TestChildInterface[] children = new TestChildInterface[5];
    for (int i = 0; i < children.length; i++) {
        children[i] = new TestLeafNode();
    }
    TestChildrenNode parent = new TestChildrenNode(children);
    TestRootNode rootNode = new TestRootNode(parent);
    CallTarget target = runtime.createCallTarget(rootNode);
    Iterator<Node> iterator = parent.getChildren().iterator();
    for (int i = 0; i < children.length; i++) {
        Assert.assertEquals(children[i], iterator.next());
    }
    Assert.assertFalse(iterator.hasNext());
    Object result = target.call();
    Assert.assertEquals(105, result);
    Assert.assertEquals(2 + children.length, NodeUtil.countNodes(rootNode));
    Assert.assertEquals(2 + children.length, NodeUtil.countNodes(NodeUtil.cloneNode(rootNode)));
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) TruffleRuntime(com.oracle.truffle.api.TruffleRuntime) 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