Search in sources :

Example 21 with RootNode

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);
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) Frame(com.oracle.truffle.api.frame.Frame) MaterializedFrame(com.oracle.truffle.api.frame.MaterializedFrame) TruffleRuntime(com.oracle.truffle.api.TruffleRuntime) MaterializedFrame(com.oracle.truffle.api.frame.MaterializedFrame) FrameInstance(com.oracle.truffle.api.frame.FrameInstance) Test(org.junit.Test)

Example 22 with RootNode

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)));
}
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 23 with 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());
    }
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) CallTarget(com.oracle.truffle.api.CallTarget) Test(org.junit.Test)

Example 24 with RootNode

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);
}
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 25 with RootNode

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);
        }
    });
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) Source(com.oracle.truffle.api.source.Source)

Aggregations

RootNode (com.oracle.truffle.api.nodes.RootNode)86 Test (org.junit.Test)36 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)24 Node (com.oracle.truffle.api.nodes.Node)23 CallTarget (com.oracle.truffle.api.CallTarget)16 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)16 RootCallTarget (com.oracle.truffle.api.RootCallTarget)12 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)12 RootTestNode (org.graalvm.compiler.truffle.test.nodes.RootTestNode)9 Source (com.oracle.truffle.api.source.Source)8 AbstractTestNode (org.graalvm.compiler.truffle.test.nodes.AbstractTestNode)8 TruffleRuntime (com.oracle.truffle.api.TruffleRuntime)7 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)6 SourceSection (com.oracle.truffle.api.source.SourceSection)6 LanguageInfo (com.oracle.truffle.api.nodes.LanguageInfo)5 ArrayList (java.util.ArrayList)5 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)4 TruffleContext (com.oracle.truffle.api.TruffleContext)3 TruffleException (com.oracle.truffle.api.TruffleException)3 TruffleLanguage (com.oracle.truffle.api.TruffleLanguage)3