use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class LanguageSPITest method testPolyglotBindingsPreserveLanguage.
@Test
public void testPolyglotBindingsPreserveLanguage() {
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) {
Object bindings = getCurrentContext(ProxyLanguage.class).env.getPolyglotBindings();
try {
ForeignAccess.sendWrite(Message.WRITE.createNode(), (TruffleObject) bindings, "exportedValue", "convertOnToString");
} catch (UnknownIdentifierException | UnsupportedTypeException | UnsupportedMessageException e) {
throw new AssertionError(e);
}
return bindings;
}
});
}
@Override
protected String toString(LanguageContext context, Object value) {
if (value.equals("convertOnToString")) {
return "myStringToString";
}
return super.toString(context, value);
}
});
Context c = Context.create();
c.eval(ProxyLanguage.ID, "");
assertEquals("Make sure language specific toString was invoked.", "myStringToString", c.getPolyglotBindings().getMember("exportedValue").toString());
}
use of com.oracle.truffle.api.nodes.RootNode 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.nodes.RootNode 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.nodes.RootNode in project graal by oracle.
the class TruffleRuntimeTest method testCreateCallTarget.
@Test
public void testCreateCallTarget() {
RootNode rootNode = createTestRootNode(null);
RootCallTarget target = runtime.createCallTarget(rootNode);
assertNotNull(target);
assertEquals(target.call(), 42);
assertSame(rootNode, target.getRootNode());
}
use of com.oracle.truffle.api.nodes.RootNode 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);
}
Aggregations