Search in sources :

Example 16 with Node

use of com.oracle.truffle.api.nodes.Node in project graal by oracle.

the class NodeUtilTest method testChildren.

@Test
public void testChildren() {
    TestRootNode root = new TestRootNode();
    TestForEachNode testForEachNode = new TestForEachNode(1);
    root.child0 = testForEachNode;
    TestNode testNode1 = new TestNode();
    testForEachNode.firstChild = testNode1;
    TestNode testNode2 = new TestNode();
    testForEachNode.children[0] = testNode2;
    TestNode testNode3 = new TestNode();
    testForEachNode.lastChild = testNode3;
    int count = 0;
    for (Node node : testForEachNode.getChildren()) {
        ((VisitableNode) node).visited++;
        count++;
    }
    Assert.assertEquals(3, count);
    Assert.assertEquals(1, testNode1.visited);
    Assert.assertEquals(1, testNode2.visited);
    Assert.assertEquals(1, testNode3.visited);
}
Also used : Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) Test(org.junit.Test)

Example 17 with Node

use of com.oracle.truffle.api.nodes.Node 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 18 with Node

use of com.oracle.truffle.api.nodes.Node in project graal by oracle.

the class ForeignAccessMultiThreadedTest method accessNodeFromOtherThread.

@Test
public void accessNodeFromOtherThread() {
    Node n = Message.IS_EXECUTABLE.createNode();
    ForeignAccess.sendIsExecutable(n, this);
    // access from different thread allowed.
    assertEquals(2, cnt);
}
Also used : Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) Test(org.junit.Test)

Example 19 with Node

use of com.oracle.truffle.api.nodes.Node 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);
}
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 20 with Node

use of com.oracle.truffle.api.nodes.Node 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)

Aggregations

Node (com.oracle.truffle.api.nodes.Node)101 RootNode (com.oracle.truffle.api.nodes.RootNode)65 Test (org.junit.Test)46 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)21 ProbeNode (com.oracle.truffle.api.instrumentation.ProbeNode)21 Source (com.oracle.truffle.api.source.Source)16 NodeVisitor (com.oracle.truffle.api.nodes.NodeVisitor)11 CallTarget (com.oracle.truffle.api.CallTarget)9 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)9 DirectCallNode (com.oracle.truffle.api.nodes.DirectCallNode)8 WrapperNode (com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode)7 TruffleRuntime (com.oracle.truffle.api.TruffleRuntime)6 SourceSection (com.oracle.truffle.api.source.SourceSection)6 TestHelper.createNode (com.oracle.truffle.api.dsl.test.TestHelper.createNode)5 ValueNode (com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode)5 SLEvalRootNode (com.oracle.truffle.sl.nodes.SLEvalRootNode)5 SLStatementNode (com.oracle.truffle.sl.nodes.SLStatementNode)5 SLBlockNode (com.oracle.truffle.sl.nodes.controlflow.SLBlockNode)5 LinkedHashMap (java.util.LinkedHashMap)5 TruffleInstrument (com.oracle.truffle.api.instrumentation.TruffleInstrument)4