From fc436af336dcf260a7a3b18b3e0b01c5d8126b3e Mon Sep 17 00:00:00 2001
From: Tomas Stupka <tomas.stupka@oracle.com>
Date: Thu, 27 Apr 2017 13:56:58 +0200
Subject: [PATCH] handle foreign objects in CastListNode and PrecedenceNode

---
 .../truffle/r/nodes/unary/CastListNode.java   |  4 +++
 .../truffle/r/nodes/unary/PrecedenceNode.java |  9 +++---
 .../truffle/r/test/ExpectedTestOutput.test    | 32 +++++++++++++++++++
 .../r/test/library/fastr/TestJavaInterop.java | 13 ++++++++
 4 files changed, 53 insertions(+), 5 deletions(-)

diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastListNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastListNode.java
index 2ea4c2b07e..9a868b06d2 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastListNode.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastListNode.java
@@ -166,4 +166,8 @@ public abstract class CastListNode extends CastBaseNode {
     public static CastListNode createForRFFI(boolean preserveNames, boolean preserveDimensions, boolean preserveAttributes) {
         return CastListNodeGen.create(preserveNames, preserveDimensions, preserveAttributes, true);
     }
+
+    protected boolean isForeignObject(TruffleObject to) {
+        return RRuntime.isForeignObject(to);
+    }
 }
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/PrecedenceNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/PrecedenceNode.java
index 1d8a29e9d0..52c861931e 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/PrecedenceNode.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/PrecedenceNode.java
@@ -153,11 +153,6 @@ public abstract class PrecedenceNode extends RBaseNode {
         return LIST_PRECEDENCE;
     }
 
-    @Specialization
-    protected int doRInteroptFloat(RInterop b, boolean recursive) {
-        return NO_PRECEDENCE;
-    }
-
     @Specialization(guards = "recursive")
     protected int doListRecursive(RList val, boolean recursive,
                     @Cached("createRecursive()") PrecedenceNode precedenceNode) {
@@ -227,4 +222,8 @@ public abstract class PrecedenceNode extends RBaseNode {
                     @Cached("createRecursive()") PrecedenceNode precedenceNode) {
         return precedenceNode.executeInteger(args.getArgument(0), recursive);
     }
+
+    protected boolean isForeignObject(TruffleObject to) {
+        return RRuntime.isForeignObject(to);
+    }
 }
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test
index 23d2b3fefd..002c9113b1 100644
--- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test
@@ -130568,6 +130568,38 @@ attr(,"is.truffle.object")
 #if (length(grep("FastR", R.Version()$version.string)) != 1) { "true127a32767214748364792233720368547758071.7976931348623157E3083.4028235E38testString" } else { tc <- .fastr.java.class('com.oracle.truffle.r.test.library.fastr.TestJavaInterop$TestClass'); t <- .fastr.interop.new(tc); t$allTypesStaticMethod(TRUE,127,"a",32767,2147483647,9223372036854775807,1.7976931348623157E308,3.4028235E38,"testString") }
 [1] "true127a32767214748364792233720368547758071.7976931348623157E3083.4028235E38testString"
 
+##com.oracle.truffle.r.test.library.fastr.TestJavaInterop.testCombine#
+#if (length(grep("FastR", R.Version()$version.string)) != 1) { 'interopt.byte' } else { class(c(.fastr.interop.toByte(123))) }
+[1] "interopt.byte"
+
+##com.oracle.truffle.r.test.library.fastr.TestJavaInterop.testCombine#
+#if (length(grep("FastR", R.Version()$version.string)) != 1) { 'list' } else { class(c(.fastr.interop.toByte(123), .fastr.interop.toByte(234))) }
+[1] "list"
+
+##com.oracle.truffle.r.test.library.fastr.TestJavaInterop.testCombine#
+#if (length(grep("FastR", R.Version()$version.string)) != 1) { 'list' } else { class(c(.fastr.interop.toByte(123), 1)) }
+[1] "list"
+
+##com.oracle.truffle.r.test.library.fastr.TestJavaInterop.testCombine#
+#if (length(grep("FastR", R.Version()$version.string)) != 1) { 'list' } else { class(c(1, .fastr.interop.toByte(123))) }
+[1] "list"
+
+##com.oracle.truffle.r.test.library.fastr.TestJavaInterop.testCombine#
+#if (length(grep("FastR", R.Version()$version.string)) != 1) { 'list' } else { tc <- .fastr.java.class('com.oracle.truffle.r.test.library.fastr.TestJavaInterop$TestClass'); t <- .fastr.interop.new(tc); class(c(1, t)) }
+[1] "list"
+
+##com.oracle.truffle.r.test.library.fastr.TestJavaInterop.testCombine#
+#if (length(grep("FastR", R.Version()$version.string)) != 1) { 'list' } else { tc <- .fastr.java.class('com.oracle.truffle.r.test.library.fastr.TestJavaInterop$TestClass'); t <- .fastr.interop.new(tc); class(c(t, 1)) }
+[1] "list"
+
+##com.oracle.truffle.r.test.library.fastr.TestJavaInterop.testCombine#
+#if (length(grep("FastR", R.Version()$version.string)) != 1) { 'list' } else { tc <- .fastr.java.class('com.oracle.truffle.r.test.library.fastr.TestJavaInterop$TestClass'); t <- .fastr.interop.new(tc); t1 <- .fastr.interop.new(tc); class(c(t, t1)) }
+[1] "list"
+
+##com.oracle.truffle.r.test.library.fastr.TestJavaInterop.testCombine#
+#if (length(grep("FastR", R.Version()$version.string)) != 1) { 'truffle.object' } else { tc <- .fastr.java.class('com.oracle.truffle.r.test.library.fastr.TestJavaInterop$TestClass'); t <- .fastr.interop.new(tc); class(c(t)) }
+[1] "truffle.object"
+
 ##com.oracle.truffle.r.test.library.fastr.TestJavaInterop.testFields#
 #if (length(grep("FastR", R.Version()$version.string)) != 1) { "a string" } else { tc <- .fastr.java.class('com.oracle.truffle.r.test.library.fastr.TestJavaInterop$TestClass'); t <- .fastr.interop.new(tc); t$fieldStaticStringObject }
 [1] "a string"
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/fastr/TestJavaInterop.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/fastr/TestJavaInterop.java
index 22d14b31b4..2a7bbe8986 100644
--- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/fastr/TestJavaInterop.java
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/fastr/TestJavaInterop.java
@@ -126,6 +126,19 @@ public class TestJavaInterop extends TestBase {
         assertEvalFastR("tc <- .fastr.java.class('" + TestNullClass.class.getName() + "'); t <- .fastr.interop.new(tc, NULL); class(t)", "'" + RType.TruffleObject.getName() + "'");
     }
 
+    @Test
+    public void testCombine() {
+        assertEvalFastR("class(c(.fastr.interop.toByte(123)))", "'interopt.byte'");
+        assertEvalFastR("class(c(.fastr.interop.toByte(123), .fastr.interop.toByte(234)))", "'list'");
+        assertEvalFastR("class(c(.fastr.interop.toByte(123), 1))", "'list'");
+        assertEvalFastR("class(c(1, .fastr.interop.toByte(123)))", "'list'");
+
+        assertEvalFastR("tc <- .fastr.java.class('" + TEST_CLASS + "'); t <- .fastr.interop.new(tc); class(c(t))", "'truffle.object'");
+        assertEvalFastR("tc <- .fastr.java.class('" + TEST_CLASS + "'); t <- .fastr.interop.new(tc); t1 <- .fastr.interop.new(tc); class(c(t, t1))", "'list'");
+        assertEvalFastR("tc <- .fastr.java.class('" + TEST_CLASS + "'); t <- .fastr.interop.new(tc); class(c(1, t))", "'list'");
+        assertEvalFastR("tc <- .fastr.java.class('" + TEST_CLASS + "'); t <- .fastr.interop.new(tc); class(c(t, 1))", "'list'");
+    }
+
     @Test
     public void testFields() throws IllegalArgumentException, IllegalAccessException {
         TestClass t = new TestClass();
-- 
GitLab