changeset 22070:a7ca9e9a1d51

Removing VirtualFrame parameter. Documenting.
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Thu, 06 Aug 2015 18:08:27 +0200
parents d683f82dac22
children 38e0e8fd22dc
files truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/ImplicitExplicitExportTest.java truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleLanguage.java truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/FindContextNode.java truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLLanguage.java truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLFunctionLiteralNode.java
diffstat 6 files changed, 45 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/ImplicitExplicitExportTest.java	Thu Aug 06 17:29:43 2015 +0200
+++ b/truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/ImplicitExplicitExportTest.java	Thu Aug 06 18:08:27 2015 +0200
@@ -164,7 +164,7 @@
 
         private Object importExport(Source code) {
             final Node node = createFindContextNode();
-            Ctx ctx = findContext(node, null);
+            Ctx ctx = findContext(node);
             Properties p = new Properties();
             try (Reader r = code.getReader()) {
                 p.load(r);
--- 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> {
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java	Thu Aug 06 17:29:43 2015 +0200
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java	Thu Aug 06 18:08:27 2015 +0200
@@ -185,6 +185,7 @@
 
     private static Reference<TruffleVM> previousVM = new WeakReference<>(null);
     private static Assumption oneVM = Truffle.getRuntime().createAssumption();
+
     protected Closeable executionStart(TruffleVM vm, Debugger[] fillIn, Source s) {
         final Closeable debugClose = DEBUG.executionStart(vm, fillIn, s);
         final TruffleVM prev = CURRENT_VM.get();
@@ -192,7 +193,7 @@
             previousVM = new WeakReference<>(vm);
             oneVM.invalidate();
             oneVM = Truffle.getRuntime().createAssumption();
-            
+
         }
         CURRENT_VM.set(vm);
         class ContextCloseable implements Closeable {
@@ -208,13 +209,13 @@
     protected void dispatchEvent(TruffleVM vm, Object event) {
         SPI.dispatchEvent(vm, event);
     }
-    
+
     static Assumption oneVMAssumption() {
         return oneVM;
     }
-    
-    @SuppressWarnings("unchecked")
-    static <C> C findContext(Class<? extends TruffleLanguage<C>> type) {
+
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    static <C> C findContext(Class<? extends TruffleLanguage> type) {
         Env env = SPI.findLanguage(CURRENT_VM.get(), type);
         return (C) API.findContext(env);
     }
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/FindContextNode.java	Thu Aug 06 17:29:43 2015 +0200
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/FindContextNode.java	Thu Aug 06 18:08:27 2015 +0200
@@ -3,28 +3,28 @@
 import com.oracle.truffle.api.Assumption;
 import com.oracle.truffle.api.CompilerDirectives;
 import com.oracle.truffle.api.TruffleLanguage;
-import com.oracle.truffle.api.frame.VirtualFrame;
 import com.oracle.truffle.api.nodes.Node;
 
+@SuppressWarnings("rawtypes")
 public final class FindContextNode<C> extends Node {
-    private final Class<TruffleLanguage<C>> type;
-    private @CompilerDirectives.CompilationFinal C context; 
+    private final Class<TruffleLanguage> languageClass;
+    private @CompilerDirectives.CompilationFinal C context;
     private @CompilerDirectives.CompilationFinal Assumption oneVM;
 
-    public FindContextNode(Class<TruffleLanguage<C>> type) {
-        this.type = type;
+    public FindContextNode(Class<TruffleLanguage> type) {
+        this.languageClass = type;
     }
 
-    public C executeFindContext(VirtualFrame frame) {
+    public C executeFindContext() {
         if (context != null && oneVM.isValid()) {
             return context;
         }
         CompilerDirectives.transferToInterpreterAndInvalidate();
         oneVM = Accessor.oneVMAssumption();
-        return context = Accessor.findContext(type);
+        return context = Accessor.findContext(languageClass);
     }
 
-    public Class<? extends TruffleLanguage> type() {
-        return type;
+    public Class<? extends TruffleLanguage> getLanguageClass() {
+        return languageClass;
     }
 }
--- a/truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLLanguage.java	Thu Aug 06 17:29:43 2015 +0200
+++ b/truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLLanguage.java	Thu Aug 06 18:08:27 2015 +0200
@@ -403,7 +403,7 @@
                     throw new IllegalStateException(failed[0]);
                 }
                 Node n = createFindContextNode();
-                SLContext fillIn = findContext(n, null);
+                SLContext fillIn = findContext(n);
                 final SLFunctionRegistry functionRegistry = fillIn.getFunctionRegistry();
                 for (SLFunction f : c.getFunctionRegistry().getFunctions()) {
                     RootCallTarget callTarget = f.getCallTarget();
@@ -496,6 +496,10 @@
         return createFindContextNode();
     }
 
+    public SLContext findContext0(Node contextNode) {
+        return findContext(contextNode);
+    }
+
     private final class SLDebugProvider implements DebugSupportProvider {
 
         public SLDebugProvider() {
--- a/truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLFunctionLiteralNode.java	Thu Aug 06 17:29:43 2015 +0200
+++ b/truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLFunctionLiteralNode.java	Thu Aug 06 18:08:27 2015 +0200
@@ -70,7 +70,7 @@
 
     @Override
     public SLFunction executeGeneric(VirtualFrame frame) {
-        SLContext context = SLLanguage.INSTANCE.findContext(contextNode);
+        SLContext context = SLLanguage.INSTANCE.findContext0(contextNode);
         if (context != cachedContext) {
             CompilerDirectives.transferToInterpreterAndInvalidate();
             this.cachedContext = context;