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();
}
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());
}
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());
}
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);
}
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);
}
Aggregations