changeset 22416:b272920e26b2

Minor changes to interop functionality for SL
author Matthias Grimmer <grimmer@ssw.jku.at>
date Wed, 25 Nov 2015 12:18:46 +0100
parents c1f804ce6cad
children d158937952b6
files truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/SLImportBuiltin.java truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/access/SLReadPropertyNode.java truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/access/SLWritePropertyNode.java truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLContext.java
diffstat 4 files changed, 17 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/SLImportBuiltin.java	Mon Nov 23 16:30:16 2015 +0100
+++ b/truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/SLImportBuiltin.java	Wed Nov 25 12:18:46 2015 +0100
@@ -46,7 +46,8 @@
 import com.oracle.truffle.sl.SLLanguage;
 
 /**
- * Built-in function to import a foreign object.
+ * Built-in function that goes through the other registered languages to find an exported global
+ * symbol of the specified name. See <link>SLContext#import(String)</link>.
  */
 @NodeInfo(shortName = "import")
 public abstract class SLImportBuiltin extends SLBuiltinNode {
--- a/truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/access/SLReadPropertyNode.java	Mon Nov 23 16:30:16 2015 +0100
+++ b/truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/access/SLReadPropertyNode.java	Wed Nov 25 12:18:46 2015 +0100
@@ -51,8 +51,6 @@
 import com.oracle.truffle.api.nodes.NodeInfo;
 import com.oracle.truffle.api.object.DynamicObject;
 import com.oracle.truffle.api.source.SourceSection;
-import com.oracle.truffle.api.utilities.ConditionProfile;
-import com.oracle.truffle.sl.SLException;
 import com.oracle.truffle.sl.nodes.SLExpressionNode;
 import com.oracle.truffle.sl.nodes.interop.SLForeignToSLTypeNode;
 import com.oracle.truffle.sl.nodes.interop.SLForeignToSLTypeNodeGen;
@@ -68,7 +66,6 @@
 
     @Child private SLReadPropertyCacheNode cacheNode;
     private final String propertyName;
-    private final ConditionProfile receiverTypeCondition = ConditionProfile.createBinaryProfile();
 
     public SLReadPropertyNode(SourceSection src, String propertyName) {
         super(src);
@@ -78,12 +75,7 @@
 
     @Specialization(guards = "isSLObject(object)")
     public Object doSLObject(DynamicObject object) {
-        if (receiverTypeCondition.profile(SLContext.isSLObject(object))) {
-            return cacheNode.executeObject(SLContext.castSLObject(object));
-        } else {
-            CompilerDirectives.transferToInterpreter();
-            throw new SLException("unexpected receiver type");
-        }
+        return cacheNode.executeObject(SLContext.castSLObject(object));
     }
 
     @Child private Node foreignRead;
--- a/truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/access/SLWritePropertyNode.java	Mon Nov 23 16:30:16 2015 +0100
+++ b/truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/access/SLWritePropertyNode.java	Wed Nov 25 12:18:46 2015 +0100
@@ -52,8 +52,6 @@
 import com.oracle.truffle.api.nodes.NodeInfo;
 import com.oracle.truffle.api.object.DynamicObject;
 import com.oracle.truffle.api.source.SourceSection;
-import com.oracle.truffle.api.utilities.ConditionProfile;
-import com.oracle.truffle.sl.SLException;
 import com.oracle.truffle.sl.nodes.SLExpressionNode;
 import com.oracle.truffle.sl.runtime.SLContext;
 
@@ -71,7 +69,6 @@
     protected final String propertyName;
     @Child protected SLExpressionNode valueNode;
     @Child protected SLWritePropertyCacheNode cacheNode;
-    private final ConditionProfile receiverTypeCondition = ConditionProfile.createBinaryProfile();
 
     SLWritePropertyNode(SourceSection src, String propertyName) {
         super(src);
@@ -81,12 +78,7 @@
 
     @Specialization(guards = "isSLObject(object)")
     public Object doSLObject(DynamicObject object, Object value) {
-        if (receiverTypeCondition.profile(SLContext.isSLObject(object))) {
-            cacheNode.executeObject(SLContext.castSLObject(object), value);
-        } else {
-            CompilerDirectives.transferToInterpreter();
-            throw new SLException("unexpected receiver type");
-        }
+        cacheNode.executeObject(SLContext.castSLObject(object), value);
         return value;
     }
 
--- a/truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLContext.java	Mon Nov 23 16:30:16 2015 +0100
+++ b/truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLContext.java	Wed Nov 25 12:18:46 2015 +0100
@@ -221,7 +221,11 @@
     }
 
     public static boolean isSLObject(TruffleObject value) {
-        return value instanceof DynamicObject && ((DynamicObject) value).getShape().getObjectType() instanceof SLObjectType;
+        return value instanceof DynamicObject && isSLObject((DynamicObject) value);
+    }
+
+    public static boolean isSLObject(DynamicObject value) {
+        return value.getShape().getObjectType() instanceof SLObjectType;
     }
 
     public static DynamicObject castSLObject(Object value) {
@@ -243,6 +247,14 @@
         return env.parse(source).call();
     }
 
+    /**
+     * Goes through the other registered languages to find an exported global symbol of the
+     * specified name. The expected return type is either <code>TruffleObject</code>, or one of
+     * wrappers of Java primitive types ({@link Integer}, {@link Double}).
+     * 
+     * @param name the name of the symbol to search for
+     * @return object representing the symbol or <code>null</code>
+     */
     public Object importSymbol(String name) {
         Object object = env.importSymbol(name);
         Object slValue = fromForeignValue(object);