Search in sources :

Example 41 with CallTarget

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

the class LanguageSPITest method testPolyglotBindings.

@Test
public void testPolyglotBindings() {
    ProxyLanguage.setDelegate(new ProxyLanguage() {

        @Override
        protected CallTarget parse(ParsingRequest request) throws Exception {
            return Truffle.getRuntime().createCallTarget(new RootNode(languageInstance) {

                @Override
                public Object execute(VirtualFrame frame) {
                    return getCurrentContext(ProxyLanguage.class).env.getPolyglotBindings();
                }
            });
        }
    });
    Context c = Context.create();
    Value languageBindings = c.eval(ProxyLanguage.ID, "");
    Value polyglotBindings = c.getPolyglotBindings();
    polyglotBindings.putMember("foo", "bar");
    assertEquals("bar", polyglotBindings.getMember("foo").asString());
    assertEquals("bar", languageBindings.getMember("foo").asString());
    languageBindings.putMember("baz", "42");
    assertEquals("42", polyglotBindings.getMember("baz").asString());
    assertEquals("42", languageBindings.getMember("baz").asString());
    ValueAssert.assertValue(c, polyglotBindings);
    ValueAssert.assertValue(c, languageBindings);
    c.close();
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) Context(org.graalvm.polyglot.Context) LanguageContext(com.oracle.truffle.api.test.polyglot.LanguageSPITestLanguage.LanguageContext) TruffleContext(com.oracle.truffle.api.TruffleContext) RootNode(com.oracle.truffle.api.nodes.RootNode) CallTarget(com.oracle.truffle.api.CallTarget) RootCallTarget(com.oracle.truffle.api.RootCallTarget) Value(org.graalvm.polyglot.Value) TimeoutException(java.util.concurrent.TimeoutException) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) TruffleException(com.oracle.truffle.api.TruffleException) PolyglotException(org.graalvm.polyglot.PolyglotException) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 42 with CallTarget

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

the class ReplaceTest method test.

@Test
public void test() {
    TruffleRuntime runtime = Truffle.getRuntime();
    UnresolvedNode leftChild = new UnresolvedNode("20");
    UnresolvedNode rightChild = new UnresolvedNode("22");
    TestRootNode rootNode = new TestRootNode(new ValueNode[] { leftChild, rightChild });
    CallTarget target = runtime.createCallTarget(rootNode);
    assertEquals(rootNode, leftChild.getParent());
    assertEquals(rootNode, rightChild.getParent());
    Iterator<Node> iterator = rootNode.getChildren().iterator();
    Assert.assertEquals(leftChild, iterator.next());
    Assert.assertEquals(rightChild, iterator.next());
    Assert.assertFalse(iterator.hasNext());
    Object result = target.call();
    assertEquals(42, result);
    assertEquals(42, target.call());
    iterator = rootNode.getChildren().iterator();
    Assert.assertEquals(ResolvedNode.class, iterator.next().getClass());
    Assert.assertEquals(ResolvedNode.class, iterator.next().getClass());
    Assert.assertFalse(iterator.hasNext());
    iterator = rootNode.getChildren().iterator();
    Assert.assertEquals(rootNode, iterator.next().getParent());
    Assert.assertEquals(rootNode, iterator.next().getParent());
    Assert.assertFalse(iterator.hasNext());
}
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 43 with CallTarget

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

the class StackTraceTest method testCallTargetStackTrace.

@Test
public void testCallTargetStackTrace() {
    CallTarget createStackTrace = createCallTarget(new ReturnStackTraceNode());
    CallTarget call = createCallTarget(new TestCallWithCallTargetNode(createStackTrace));
    StackTrace stack = (StackTrace) call.call();
    assertInvariants(stack);
    Assert.assertEquals(2, stack.frames.size());
    Assert.assertSame(createStackTrace, stack.currentFrame.getCallTarget());
    Assert.assertNull(stack.currentFrame.getCallNode());
    Assert.assertSame(call, stack.callerFrame.getCallTarget());
    Assert.assertNull(stack.callerFrame.getCallNode());
}
Also used : RootCallTarget(com.oracle.truffle.api.RootCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) Test(org.junit.Test)

Example 44 with CallTarget

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

the class StackTraceTest method testIndirectStackTrace.

@Test
public void testIndirectStackTrace() {
    CallTarget createStackTrace = createCallTarget(new ReturnStackTraceNode());
    CallTarget call = createCallTarget(new TestCallWithIndirectTargetNode(createStackTrace));
    StackTrace stack = (StackTrace) call.call();
    Assert.assertEquals(2, stack.frames.size());
    Assert.assertSame(createStackTrace, stack.currentFrame.getCallTarget());
    Assert.assertNull(stack.currentFrame.getCallNode());
    Assert.assertSame(call, stack.callerFrame.getCallTarget());
    Assert.assertSame(findCallNode(call), stack.callerFrame.getCallNode());
    assertInvariants(stack);
}
Also used : RootCallTarget(com.oracle.truffle.api.RootCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) Test(org.junit.Test)

Example 45 with CallTarget

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

the class StackTraceTest method testSingleStackTrace.

@Test
public void testSingleStackTrace() {
    CallTarget callTarget = createCallTarget(new ReturnStackTraceNode());
    StackTrace stack = (StackTrace) callTarget.call();
    Assert.assertEquals(1, stack.frames.size());
    Assert.assertSame(callTarget, stack.currentFrame.getCallTarget());
    Assert.assertNull(stack.currentFrame.getCallNode());
    assertInvariants(stack);
}
Also used : RootCallTarget(com.oracle.truffle.api.RootCallTarget) 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