Search in sources :

Example 16 with VirtualFrame

use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.

the class LanguageSPITest method testPolyglotBindings.

@Test
public void testPolyglotBindings() {
    ProxyLanguage.setDelegate(new ProxyLanguage() {

        @Override
        protected CallTarget parse(ParsingRequest request) throws Exception {
            return Truffle.getRuntime().createCallTarget(new RootNode(languageInstance) {

                @Override
                public Object execute(VirtualFrame frame) {
                    return getCurrentContext(ProxyLanguage.class).env.getPolyglotBindings();
                }
            });
        }
    });
    Context c = Context.create();
    Value languageBindings = c.eval(ProxyLanguage.ID, "");
    Value polyglotBindings = c.getPolyglotBindings();
    polyglotBindings.putMember("foo", "bar");
    assertEquals("bar", polyglotBindings.getMember("foo").asString());
    assertEquals("bar", languageBindings.getMember("foo").asString());
    languageBindings.putMember("baz", "42");
    assertEquals("42", polyglotBindings.getMember("baz").asString());
    assertEquals("42", languageBindings.getMember("baz").asString());
    ValueAssert.assertValue(c, polyglotBindings);
    ValueAssert.assertValue(c, languageBindings);
    c.close();
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) Context(org.graalvm.polyglot.Context) LanguageContext(com.oracle.truffle.api.test.polyglot.LanguageSPITestLanguage.LanguageContext) TruffleContext(com.oracle.truffle.api.TruffleContext) RootNode(com.oracle.truffle.api.nodes.RootNode) CallTarget(com.oracle.truffle.api.CallTarget) RootCallTarget(com.oracle.truffle.api.RootCallTarget) Value(org.graalvm.polyglot.Value) TimeoutException(java.util.concurrent.TimeoutException) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) TruffleException(com.oracle.truffle.api.TruffleException) PolyglotException(org.graalvm.polyglot.PolyglotException) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 17 with VirtualFrame

use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.

the class FrameDescriptorTest method localsDefaultValue.

@Test
public void localsDefaultValue() throws Exception {
    Object defaultValue = "default";
    FrameDescriptor d = new FrameDescriptor(defaultValue);
    s1 = d.addFrameSlot("v1");
    s2 = d.addFrameSlot("v2");
    s3 = d.addFrameSlot("v3");
    VirtualFrame f = Truffle.getRuntime().createVirtualFrame(new Object[] { 1, 2 }, d);
    assertFrame(f, d);
    assertFrame(f.materialize(), d);
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) Test(org.junit.Test)

Example 18 with VirtualFrame

use of com.oracle.truffle.api.frame.VirtualFrame 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 19 with VirtualFrame

use of com.oracle.truffle.api.frame.VirtualFrame 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 20 with VirtualFrame

use of com.oracle.truffle.api.frame.VirtualFrame 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

VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)48 Test (org.junit.Test)34 RootNode (com.oracle.truffle.api.nodes.RootNode)27 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)14 CallTarget (com.oracle.truffle.api.CallTarget)11 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)9 RootCallTarget (com.oracle.truffle.api.RootCallTarget)6 EventContext (com.oracle.truffle.api.instrumentation.EventContext)5 DirectCallNode (com.oracle.truffle.api.nodes.DirectCallNode)5 ExecutionEventListener (com.oracle.truffle.api.instrumentation.ExecutionEventListener)4 Node (com.oracle.truffle.api.nodes.Node)4 AbstractTestNode (org.graalvm.compiler.truffle.test.nodes.AbstractTestNode)4 RootTestNode (org.graalvm.compiler.truffle.test.nodes.RootTestNode)4 Ignore (org.junit.Ignore)4 TruffleContext (com.oracle.truffle.api.TruffleContext)3 TruffleException (com.oracle.truffle.api.TruffleException)3 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)3 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)3 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)3 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)3