diff truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleLanguage.java @ 22070:a7ca9e9a1d51

Removing VirtualFrame parameter. Documenting.
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Thu, 06 Aug 2015 18:08:27 +0200
parents fec8f8a61f6c
children ff531952a91c
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleLanguage.java	Thu Aug 06 17:29:43 2015 +0200
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleLanguage.java	Thu Aug 06 18:08:27 2015 +0200
@@ -28,7 +28,6 @@
 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;
@@ -175,17 +174,36 @@
     protected abstract DebugSupportProvider getDebugSupport();
 
     /**
+     * Allows a language implementor to create a node that can effectively lookup up the context
+     * associated with current execution. The context is created by
+     * {@link #createContext(com.oracle.truffle.api.TruffleLanguage.Env)} method.
+     * 
+     * @return node to be inserted into program to effectively find out current execution context
+     *         for this language
      */
     @SuppressWarnings({"rawtypes", "unchecked"})
     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) {
+
+    /**
+     * Uses the {@link #createFindContextNode()} node to obtain the current context.
+     * 
+     * @param n the node created by this language's {@link #createFindContextNode()}
+     * @return the context created by
+     *         {@link #createContext(com.oracle.truffle.api.TruffleLanguage.Env)} method at the
+     *         beginning of the language execution
+     * @throws ClassCastException if the node has not been created by <code>this</code>.
+     *             {@link #createFindContextNode()} method.
+     */
+    @SuppressWarnings({"rawtypes", "unchecked"})
+    protected final C findContext(Node n) {
         FindContextNode fcn = (FindContextNode) n;
-        assert fcn.type() == getClass();
-        return (C) fcn.executeFindContext(frame);
+        if (fcn.getLanguageClass() != getClass()) {
+            throw new ClassCastException();
+        }
+        return (C) fcn.executeFindContext();
     }
 
     private static final class LangCtx<C> {