# HG changeset patch # User Matthias Grimmer # Date 1448450326 -3600 # Node ID b272920e26b2a52c3f024f622d8e12f3593cc9eb # Parent c1f804ce6cad8c53a41e43347ee821498392947c Minor changes to interop functionality for SL diff -r c1f804ce6cad -r b272920e26b2 truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/SLImportBuiltin.java --- 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 SLContext#import(String). */ @NodeInfo(shortName = "import") public abstract class SLImportBuiltin extends SLBuiltinNode { diff -r c1f804ce6cad -r b272920e26b2 truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/access/SLReadPropertyNode.java --- 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; diff -r c1f804ce6cad -r b272920e26b2 truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/access/SLWritePropertyNode.java --- 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; } diff -r c1f804ce6cad -r b272920e26b2 truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLContext.java --- 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 TruffleObject, 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 null + */ public Object importSymbol(String name) { Object object = env.importSymbol(name); Object slValue = fromForeignValue(object);