diff truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleLanguage.java @ 22068:fec8f8a61f6c

Introducing FindContextNode
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Thu, 06 Aug 2015 17:22:35 +0200
parents 78c3d3d8d86e
children a7ca9e9a1d51
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleLanguage.java	Thu Aug 06 08:33:18 2015 +0200
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleLanguage.java	Thu Aug 06 17:22:35 2015 +0200
@@ -28,6 +28,7 @@
 import java.lang.annotation.*;
 
 import com.oracle.truffle.api.debug.*;
+import com.oracle.truffle.api.frame.VirtualFrame;
 import com.oracle.truffle.api.impl.*;
 import com.oracle.truffle.api.instrument.*;
 import com.oracle.truffle.api.nodes.Node;
@@ -174,19 +175,17 @@
     protected abstract DebugSupportProvider getDebugSupport();
 
     /**
-     * Finds the currently executing context for this language and current thread. Obtains data
-     * previously created by {@link #createContext(com.oracle.truffle.api.TruffleLanguage.Env)}
-     * method.
-     *
-     * @return the context associated with current execution
-     * @throws IllegalStateException if no context is associated with the execution
      */
     @SuppressWarnings({"rawtypes", "unchecked"})
-    protected final C findContext() {
-        final Class<? extends TruffleLanguage> c = getClass();
-        final Env env = API.findLanguage(null, c);
-        assert env.langCtx.lang == this;
-        return (C) env.langCtx.ctx;
+    protected final Node createFindContextNode() {
+        final Class<? extends TruffleLanguage<?>> c = (Class<? extends TruffleLanguage<?>>) getClass();
+        return new FindContextNode(c);
+    }
+    
+    public final C findContext(Node n, VirtualFrame frame) {
+        FindContextNode fcn = (FindContextNode) n;
+        assert fcn.type() == getClass();
+        return (C) fcn.executeFindContext(frame);
     }
 
     private static final class LangCtx<C> {
@@ -319,6 +318,11 @@
         }
 
         @Override
+        protected Object findContext(Env env) {
+            return env.langCtx.ctx;
+        }
+
+        @Override
         protected ToolSupportProvider getToolSupport(TruffleLanguage<?> l) {
             return l.getToolSupport();
         }