Search in sources :

Example 76 with RootNode

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

the class SuspendedEvent method isEvalRootStackFrame.

static boolean isEvalRootStackFrame(DebuggerSession session, FrameInstance instance) {
    CallTarget target = instance.getCallTarget();
    RootNode root = null;
    if (target instanceof RootCallTarget) {
        root = ((RootCallTarget) target).getRootNode();
    }
    if (root != null && session.getDebugger().getEnv().isEngineRoot(root)) {
        return true;
    }
    return false;
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) RootCallTarget(com.oracle.truffle.api.RootCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) RootCallTarget(com.oracle.truffle.api.RootCallTarget)

Example 77 with RootNode

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

the class ContextLookupTest method invalidLookup.

@Test
public void invalidLookup() throws Exception {
    LanguageLookupContext context = new LanguageLookupContext(null);
    PolyglotEngine vm = createBuilder().config(LanguageLookup.MIME_TYPE, "channel", context).build();
    vm.getLanguages().get(LanguageLookup.MIME_TYPE).getGlobalObject();
    try {
        LanguageLookup.getContext();
        fail();
    } catch (IllegalStateException e) {
    }
    try {
        LanguageLookup.getLanguage();
        fail();
    } catch (IllegalStateException e) {
    }
    RootNode root = new RootNode(context.language) {

        @Override
        public Object execute(VirtualFrame frame) {
            return null;
        }
    };
    try {
        root.getCurrentContext(LanguageLookup.class);
        fail();
    } catch (IllegalStateException e) {
    }
    try {
        // using an exposed context reference outside of PE does not work
        context.language.sharedChannelRef.get();
        fail();
    } catch (IllegalStateException e) {
    }
    try {
        // but you can create context references outside
        context.language.getContextReference();
    } catch (IllegalStateException e) {
    }
    try {
        // creating a context reference in the constructor does not work
        context.language.getContextReference().get();
        fail();
    } catch (IllegalStateException e) {
    // illegal state expected. context not yet initialized
    }
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) Test(org.junit.Test)

Example 78 with RootNode

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

the class JavaInterop method convertToJavaObject.

@CompilerDirectives.TruffleBoundary
@SuppressWarnings("unchecked")
private static <T> T convertToJavaObject(Class<T> type, TruffleObject foreignObject) {
    RootNode root = new TemporaryConvertRoot(ToJavaNode.create(), foreignObject, type);
    Object convertedValue = Truffle.getRuntime().createCallTarget(root).call();
    return (T) convertedValue;
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Example 79 with RootNode

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

the class ProxySPITestLanguage method parse.

@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
    Object result = "null result";
    if (runinside != null) {
        try {
            result = runinside.apply(getContext().env);
        } finally {
            runinside = null;
        }
    }
    if (result == null) {
        result = "null result";
    }
    final Object finalResult = result;
    return Truffle.getRuntime().createCallTarget(new RootNode(this) {

        @Override
        public Object execute(VirtualFrame frame) {
            return finalResult;
        }
    });
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode)

Example 80 with RootNode

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

the class ContextAPITestLanguage method parse.

@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
    Object result = "null result";
    if (runinside != null) {
        try {
            result = runinside.apply(getContext().env);
        } finally {
            runinside = null;
        }
    }
    if (result == null) {
        result = "null result";
    }
    final Object finalResult = result;
    return Truffle.getRuntime().createCallTarget(new RootNode(this) {

        @Override
        public Object execute(VirtualFrame frame) {
            return finalResult;
        }
    });
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode)

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