Search in sources :

Example 16 with NodeLibrary

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

the class NodeAssertionsTest method testView.

@Test
@SuppressWarnings("hiding")
public void testView() {
    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[] {});
        TestAssertsNode n = new TestAssertsNode(ProxyLanguage.get(null), frame.getFrameDescriptor());
        NodeLibrary l = createLibrary(NodeLibrary.class, n);
        n.getView = (f, x) -> x;
        assertFails(() -> l.getView(n, null, true), AssertionError.class);
        assertFails(() -> l.getView(n, null, new Object()), AssertionError.class);
        assertFails(() -> l.getView(n, frame, true), AssertionError.class);
        assertFails(() -> l.getView(n, frame, new Object()), AssertionError.class);
        NodeDefaultsTest.ProxyLanguageValue pv = new NodeDefaultsTest.ProxyLanguageValue();
        assertSame(pv, l.getView(n, frame, pv));
        assertFails(() -> l.getView(n, null, pv), AssertionError.class);
        assertFails(() -> l.getView(new TestAssertsNode(ProxyLanguage.get(null), null), frame, pv), AssertionError.class);
        assertFails(() -> l.getView(new TestAssertsNode(null, frame.getFrameDescriptor()), frame, pv), AssertionError.class);
    }
}
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) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage) Test(org.junit.Test)

Example 17 with NodeLibrary

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

the class NodeAssertionsTest method testScope.

@Test
public void testScope() throws UnsupportedMessageException {
    TestAssertsNode n = new TestAssertsNode();
    NodeLibrary l = createLibrary(NodeLibrary.class, n);
    Object invalidScope = new TruffleObject() {
    };
    Object validScope = new ValidScope();
    n.hasScope = false;
    n.getScope = null;
    assertFalse(l.hasScope(n, null));
    assertFails(() -> l.getScope(n, null, true), UnsupportedMessageException.class);
    n.hasScope = false;
    n.getScope = (frame) -> validScope;
    assertFails(() -> l.hasScope(n, null), AssertionError.class);
    assertFails(() -> l.getScope(n, null, true), AssertionError.class);
    n.hasScope = true;
    n.getScope = null;
    assertFails(() -> l.hasScope(n, null), AssertionError.class);
    assertFails(() -> l.getScope(n, null, true), AssertionError.class);
    n.hasScope = true;
    n.getScope = frame -> validScope;
    assertTrue(l.hasScope(n, null));
    assertSame(validScope, l.getScope(n, null, true));
    n.hasScope = true;
    n.getScope = frame -> invalidScope;
    assertFails(() -> l.hasScope(n, null), AssertionError.class);
    assertFails(() -> l.getScope(n, null, true), 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