Skip to content
Snippets Groups Projects
Commit 376422b9 authored by Tomas Stupka's avatar Tomas Stupka
Browse files

Foreign object and RInteropScalar specializations in Identical builtin

parent 8e08d032
Branches
No related tags found
No related merge requests found
...@@ -33,6 +33,7 @@ import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; ...@@ -33,6 +33,7 @@ import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.object.DynamicObject; import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.profiles.ConditionProfile; import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.r.nodes.attributes.IterableAttributeNode; import com.oracle.truffle.r.nodes.attributes.IterableAttributeNode;
import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode;
...@@ -44,6 +45,7 @@ import com.oracle.truffle.r.runtime.data.RAttributable; ...@@ -44,6 +45,7 @@ import com.oracle.truffle.r.runtime.data.RAttributable;
import com.oracle.truffle.r.runtime.data.RAttributesLayout; import com.oracle.truffle.r.runtime.data.RAttributesLayout;
import com.oracle.truffle.r.runtime.data.RExternalPtr; import com.oracle.truffle.r.runtime.data.RExternalPtr;
import com.oracle.truffle.r.runtime.data.RFunction; import com.oracle.truffle.r.runtime.data.RFunction;
import com.oracle.truffle.r.runtime.data.RInteropScalar;
import com.oracle.truffle.r.runtime.data.RLanguage; import com.oracle.truffle.r.runtime.data.RLanguage;
import com.oracle.truffle.r.runtime.data.RListBase; import com.oracle.truffle.r.runtime.data.RListBase;
import com.oracle.truffle.r.runtime.data.RPairList; import com.oracle.truffle.r.runtime.data.RPairList;
...@@ -333,6 +335,16 @@ public abstract class Identical extends RBuiltinNode.Arg7 { ...@@ -333,6 +335,16 @@ public abstract class Identical extends RBuiltinNode.Arg7 {
return identicalAttr(x, y, numEq, singleNA, attribAsSet, ignoreBytecode, ignoreEnvironment); return identicalAttr(x, y, numEq, singleNA, attribAsSet, ignoreBytecode, ignoreEnvironment);
} }
@Specialization
protected byte doInternalIdenticalForeignObject(RInteropScalar x, RInteropScalar y, boolean numEq, boolean singleNA, boolean attribAsSet, boolean ignoreBytecode, boolean ignoreEnvironment) {
return RRuntime.asLogical(x == y);
}
@Specialization(guards = "areForeignObjects(x, y)")
protected byte doInternalIdenticalForeignObject(TruffleObject x, TruffleObject y, boolean numEq, boolean singleNA, boolean attribAsSet, boolean ignoreBytecode, boolean ignoreEnvironment) {
return RRuntime.asLogical(x == y);
}
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Fallback @Fallback
protected byte doInternalIdenticalWrongTypes(Object x, Object y, Object numEq, Object singleNA, Object attribAsSet, Object ignoreBytecode, Object ignoreEnvironment) { protected byte doInternalIdenticalWrongTypes(Object x, Object y, Object numEq, Object singleNA, Object attribAsSet, Object ignoreBytecode, Object ignoreEnvironment) {
...@@ -340,6 +352,10 @@ public abstract class Identical extends RBuiltinNode.Arg7 { ...@@ -340,6 +352,10 @@ public abstract class Identical extends RBuiltinNode.Arg7 {
return RRuntime.LOGICAL_FALSE; return RRuntime.LOGICAL_FALSE;
} }
protected boolean areForeignObjects(TruffleObject x, TruffleObject y) {
return RRuntime.isForeignObject(x) && RRuntime.isForeignObject(x);
}
protected boolean vectorsLists(RAbstractVector x, RAbstractVector y) { protected boolean vectorsLists(RAbstractVector x, RAbstractVector y) {
return x instanceof RListBase && y instanceof RListBase; return x instanceof RListBase && y instanceof RListBase;
} }
......
...@@ -347,6 +347,15 @@ public class TestJavaInterop extends TestBase { ...@@ -347,6 +347,15 @@ public class TestJavaInterop extends TestBase {
assertEvalFastR("to <- .fastr.interop.new(.fastr.java.class('" + TEST_CLASS + "')); attr(to, which = 'a')", "cat('Error in attr(to, which = \"a\") : external object cannot be attributed\n')"); assertEvalFastR("to <- .fastr.interop.new(.fastr.java.class('" + TEST_CLASS + "')); attr(to, which = 'a')", "cat('Error in attr(to, which = \"a\") : external object cannot be attributed\n')");
} }
public void testIdentical() {
assertEvalFastR("b1 <- .fastr.interop.toByte(1); identical(b1, b1)", "TRUE");
assertEvalFastR("b1 <- .fastr.interop.toByte(1); b2 <- .fastr.interop.toByte(1); identical(b1, b2)", "FALSE");
assertEvalFastR("b1 <- .fastr.interop.toByte(1); s1 <- .fastr.interop.toShort(1); identical(b1, s1)", "FALSE");
assertEvalFastR("al <- .fastr.interop.new(.fastr.java.class('java.util.ArrayList')); identical(t, t)", "TRUE");
assertEvalFastR("ll <- .fastr.interop.new(.fastr.java.class('java.util.LinkedList')); al <- .fastr.interop.new(.fastr.java.class('java.util.ArrayList')); identical(al, ll)", "FALSE");
}
private String getRValue(Object value) { private String getRValue(Object value) {
if (value == null) { if (value == null) {
return "NULL"; return "NULL";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment