use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class FrameTest method framesCanBeMaterialized.
@Test
public void framesCanBeMaterialized() {
final TruffleRuntime runtime = Truffle.getRuntime();
class FrameRootNode extends RootNode {
FrameRootNode() {
super(null);
}
@Override
public Object execute(VirtualFrame frame) {
FrameInstance frameInstance = runtime.getCurrentFrame();
Frame readWrite = frameInstance.getFrame(FrameInstance.FrameAccess.READ_WRITE);
Frame materialized = frameInstance.getFrame(FrameInstance.FrameAccess.MATERIALIZE);
assertTrue("Really materialized: " + materialized, materialized instanceof MaterializedFrame);
assertEquals("It's my frame", frame, readWrite);
return this;
}
}
FrameRootNode frn = new FrameRootNode();
Object ret = Truffle.getRuntime().createCallTarget(frn).call();
assertEquals("Returns itself", frn, ret);
}
use of com.oracle.truffle.api.nodes.RootNode 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)));
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class LoopNodeTest method testLoopCountReportingInCallTarget.
@Test
public void testLoopCountReportingInCallTarget() {
final GuestLanguageNode node = new GuestLanguageNode() {
@Override
public Object execute(VirtualFrame frame) {
int[] data = new int[] { 1, 2, 3, 4, 5 };
try {
int sum = 0;
for (int i = 0; i < data.length; i++) {
sum += data[i];
}
return sum;
} finally {
LoopNode.reportLoopCount(this, data.length);
}
}
};
RootNode root = new RootNode(null) {
@Override
public Object execute(VirtualFrame frame) {
return node.execute(frame);
}
};
CallTarget target = Truffle.getRuntime().createCallTarget(root);
for (int i = 0; i < 1000; i++) {
Assert.assertEquals(15, target.call());
}
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class ChildNodeTest method test.
@Test
public void test() {
TruffleRuntime runtime = Truffle.getRuntime();
TestChildNode leftChild = new TestChildNode();
TestChildNode rightChild = new TestChildNode();
TestRootNode rootNode = new TestRootNode(leftChild, rightChild);
CallTarget target = runtime.createCallTarget(rootNode);
assertEquals(rootNode, leftChild.getParent());
assertEquals(rootNode, rightChild.getParent());
Iterator<Node> iterator = rootNode.getChildren().iterator();
assertEquals(leftChild, iterator.next());
assertEquals(rightChild, iterator.next());
assertFalse(iterator.hasNext());
Object result = target.call();
assertEquals(42, result);
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class IsMimeTypeSupportedTestLanguage method parse.
@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
final Source code = request.getSource();
final String mimeType = code.getCharacters().toString();
return Truffle.getRuntime().createCallTarget(new RootNode(this) {
@Override
public Object execute(VirtualFrame frame) {
return getContextReference().get().isMimeTypeSupported(mimeType);
}
});
}
Aggregations