Search in sources :

Example 6 with NodeLibrary

use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.

the class NodeDefaultsTest method testReceiverDefaults.

@Test
public void testReceiverDefaults() {
    Node n = new TestNode();
    NodeLibrary l = createLibrary(NodeLibrary.class, n);
    assertFalse(l.hasReceiverMember(n, null));
    assertFails(() -> l.getReceiverMember(n, null), UnsupportedMessageException.class);
}
Also used : NodeLibrary(com.oracle.truffle.api.interop.NodeLibrary) Node(com.oracle.truffle.api.nodes.Node) ProbeNode(com.oracle.truffle.api.instrumentation.ProbeNode) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) RootNode(com.oracle.truffle.api.nodes.RootNode) Test(org.junit.Test)

Example 7 with NodeLibrary

use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.

the class NodeDefaultsTest method testRootInstanceDefaults.

@Test
public void testRootInstanceDefaults() {
    Node n = new TestNode();
    NodeLibrary l = createLibrary(NodeLibrary.class, n);
    assertFalse(l.hasRootInstance(n, null));
    assertFails(() -> l.getRootInstance(n, null), UnsupportedMessageException.class);
}
Also used : NodeLibrary(com.oracle.truffle.api.interop.NodeLibrary) Node(com.oracle.truffle.api.nodes.Node) ProbeNode(com.oracle.truffle.api.instrumentation.ProbeNode) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) RootNode(com.oracle.truffle.api.nodes.RootNode) Test(org.junit.Test)

Example 8 with NodeLibrary

use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.

the class NodeDefaultsTest method testViewDefaults.

@Test
@SuppressWarnings("hiding")
public void testViewDefaults() {
    try (Context context = Context.create()) {
        ProxyLanguage language = new ProxyLanguage();
        ProxyLanguage.setDelegate(language);
        context.initialize(ProxyLanguage.ID);
        context.enter();
        Frame frame = Truffle.getRuntime().createMaterializedFrame(new Object[] {});
        Node n = new TestNode(ProxyLanguage.get(null), frame.getFrameDescriptor());
        NodeLibrary l = createLibrary(NodeLibrary.class, n);
        Object v = 42 * 42;
        // Integer is not associated with a language
        assertFails(() -> l.getView(n, frame, v), AssertionError.class);
        Object pv = new ProxyLanguageValue();
        assertSame(pv, l.getView(n, frame, pv));
    }
}
Also used : Context(org.graalvm.polyglot.Context) NodeLibrary(com.oracle.truffle.api.interop.NodeLibrary) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) Frame(com.oracle.truffle.api.frame.Frame) Node(com.oracle.truffle.api.nodes.Node) ProbeNode(com.oracle.truffle.api.instrumentation.ProbeNode) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) RootNode(com.oracle.truffle.api.nodes.RootNode) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage) Test(org.junit.Test)

Example 9 with NodeLibrary

use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.

the class NodeAssertionsTest method testReceiver.

@Test
public void testReceiver() throws UnsupportedMessageException {
    TestAssertsNode n = new TestAssertsNode();
    NodeLibrary l = createLibrary(NodeLibrary.class, n);
    Object invalidReceiverName = new Object();
    Object validReceiverName = "receiver";
    n.hasReceiverMember = false;
    n.getReceiverMember = null;
    assertFalse(l.hasReceiverMember(n, null));
    assertFails(() -> l.getReceiverMember(n, null), UnsupportedMessageException.class);
    n.hasReceiverMember = false;
    n.getReceiverMember = (frame) -> validReceiverName;
    assertFails(() -> l.hasReceiverMember(n, null), AssertionError.class);
    assertFails(() -> l.getReceiverMember(n, null), AssertionError.class);
    n.hasReceiverMember = true;
    n.getReceiverMember = null;
    assertFails(() -> l.hasReceiverMember(n, null), AssertionError.class);
    assertFails(() -> l.getReceiverMember(n, null), AssertionError.class);
    n.hasReceiverMember = true;
    n.getReceiverMember = (frame) -> validReceiverName;
    assertTrue(l.hasReceiverMember(n, null));
    assertSame(validReceiverName, l.getReceiverMember(n, null));
    n.hasReceiverMember = true;
    n.getReceiverMember = (frame) -> invalidReceiverName;
    assertFails(() -> l.hasReceiverMember(n, null), AssertionError.class);
    assertFails(() -> l.getReceiverMember(n, null), AssertionError.class);
    n.hasReceiverMember = true;
    n.getReceiverMember = (frame) -> validReceiverName;
    assertTrue(l.hasReceiverMember(n, null));
    assertSame(validReceiverName, l.getReceiverMember(n, null));
}
Also used : NodeLibrary(com.oracle.truffle.api.interop.NodeLibrary) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 10 with NodeLibrary

use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.

the class NodeAssertionsTest method testRootInstance.

@Test
public void testRootInstance() throws UnsupportedMessageException {
    TestAssertsNode n = new TestAssertsNode();
    NodeLibrary l = createLibrary(NodeLibrary.class, n);
    Object invalidRootInstance = new TruffleObject() {
    };
    // not executable
    Object validRootInstance = new ValidRootInstance();
    n.hasRootInstance = false;
    n.getRootInstance = null;
    assertFalse(l.hasRootInstance(n, null));
    assertFails(() -> l.getRootInstance(n, null), UnsupportedMessageException.class);
    n.hasRootInstance = false;
    n.getRootInstance = (frame) -> validRootInstance;
    assertFails(() -> l.hasRootInstance(n, null), AssertionError.class);
    assertFails(() -> l.getRootInstance(n, null), AssertionError.class);
    n.hasRootInstance = true;
    n.getRootInstance = null;
    assertFails(() -> l.hasRootInstance(n, null), AssertionError.class);
    assertFails(() -> l.getRootInstance(n, null), AssertionError.class);
    n.hasRootInstance = true;
    n.getRootInstance = frame -> validRootInstance;
    assertTrue(l.hasRootInstance(n, null));
    assertSame(validRootInstance, l.getRootInstance(n, null));
    n.hasRootInstance = true;
    n.getRootInstance = frame -> invalidRootInstance;
    assertFails(() -> l.hasRootInstance(n, null), AssertionError.class);
    assertFails(() -> l.getRootInstance(n, null), AssertionError.class);
}
Also used : NodeLibrary(com.oracle.truffle.api.interop.NodeLibrary) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Aggregations

NodeLibrary (com.oracle.truffle.api.interop.NodeLibrary)17 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)8 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)8 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)8 Node (com.oracle.truffle.api.nodes.Node)8 Test (org.junit.Test)8 RootNode (com.oracle.truffle.api.nodes.RootNode)6 Frame (com.oracle.truffle.api.frame.Frame)4 ProbeNode (com.oracle.truffle.api.instrumentation.ProbeNode)4 InteropLibrary (com.oracle.truffle.api.interop.InteropLibrary)4 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)4 ExecutableNode (com.oracle.truffle.api.nodes.ExecutableNode)3 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)2 LanguageInfo (com.oracle.truffle.api.nodes.LanguageInfo)2 ProxyLanguage (com.oracle.truffle.api.test.polyglot.ProxyLanguage)2 LLVMDebuggerValue (com.oracle.truffle.llvm.runtime.debug.LLVMDebuggerValue)2 Context (org.graalvm.polyglot.Context)2 CoverageData (org.graalvm.tools.lsp.server.utils.CoverageData)2 CoverageEventNode (org.graalvm.tools.lsp.server.utils.CoverageEventNode)2 Specialization (com.oracle.truffle.api.dsl.Specialization)1