From afbe4acb490e435fd556e49760a586aef8113020 Mon Sep 17 00:00:00 2001
From: Florian Angerer <florian.angerer@oracle.com>
Date: Thu, 21 Sep 2017 18:59:55 +0200
Subject: [PATCH] Implemented 'Rf_NonNullStringMatch'.

---
 .../ffi/impl/common/JavaUpCallsRFFIImpl.java  |   5 +
 .../truffle/r/ffi/impl/nodes/MatchNodes.java  |  49 +++++
 .../truffle/r/ffi/impl/nodes/MiscNodes.java   |  15 --
 .../r/ffi/impl/upcalls/StdUpCallsRFFI.java    |   7 +-
 .../fficall/src/common/rffi_upcalls.h         |   1 +
 .../fficall/src/common/rffi_upcallsindex.h    | 171 +++++++++---------
 .../fficall/src/truffle_common/match.c        |  30 +++
 com.oracle.truffle.r.native/version.source    |   2 +-
 8 files changed, 177 insertions(+), 103 deletions(-)
 create mode 100644 com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/MatchNodes.java
 create mode 100644 com.oracle.truffle.r.native/fficall/src/truffle_common/match.c

diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/common/JavaUpCallsRFFIImpl.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/common/JavaUpCallsRFFIImpl.java
index b73fac10a4..c5c1f77155 100644
--- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/common/JavaUpCallsRFFIImpl.java
+++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/common/JavaUpCallsRFFIImpl.java
@@ -1684,4 +1684,9 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI {
         throw implementedAsNode();
     }
 
+    @Override
+    public Object Rf_NonNullStringMatch(Object s, Object t) {
+        throw implementedAsNode();
+    }
+
 }
diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/MatchNodes.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/MatchNodes.java
new file mode 100644
index 0000000000..f307b7ffdd
--- /dev/null
+++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/MatchNodes.java
@@ -0,0 +1,49 @@
+package com.oracle.truffle.r.ffi.impl.nodes;
+
+import com.oracle.truffle.api.dsl.Fallback;
+import com.oracle.truffle.api.dsl.Specialization;
+import com.oracle.truffle.api.dsl.TypeSystemReference;
+import com.oracle.truffle.r.runtime.RInternalError;
+import com.oracle.truffle.r.runtime.RRuntime;
+import com.oracle.truffle.r.runtime.data.RTypes;
+import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector;
+
+public final class MatchNodes {
+
+    @TypeSystemReference(RTypes.class)
+    public abstract static class MatchNode extends FFIUpCallNode.Arg3 {
+
+        @SuppressWarnings("unused")
+        @Specialization
+        Object match(Object itables, Object ix, int nmatch) {
+            throw RInternalError.unimplemented("Rf_match");
+        }
+
+        public static MatchNode create() {
+            return MatchNodesFactory.MatchNodeGen.create();
+        }
+    }
+
+    @TypeSystemReference(RTypes.class)
+    public abstract static class NonNullStringMatchNode extends FFIUpCallNode.Arg2 {
+
+        @Specialization(guards = {"s.getLength() == 1", "t.getLength() == 1"})
+        Object matchSingle(RAbstractStringVector s, RAbstractStringVector t) {
+            if (s.getDataAt(0) == RRuntime.STRING_NA || t.getDataAt(0) == RRuntime.STRING_NA) {
+                return RRuntime.LOGICAL_FALSE;
+            }
+            return RRuntime.asLogical(s.getDataAt(0).equals(t.getDataAt(0)));
+        }
+
+        @Fallback
+        @SuppressWarnings("unused")
+        Object match(Object s, Object t) {
+            throw RInternalError.unimplemented("Rf_NonNullStringMatch");
+        }
+
+        public static NonNullStringMatchNode create() {
+            return MatchNodesFactory.NonNullStringMatchNodeGen.create();
+        }
+    }
+
+}
diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/MiscNodes.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/MiscNodes.java
index c595d84a47..9a448ed172 100644
--- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/MiscNodes.java
+++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/MiscNodes.java
@@ -40,7 +40,6 @@ import com.oracle.truffle.r.nodes.objects.NewObject;
 import com.oracle.truffle.r.nodes.objects.NewObjectNodeGen;
 import com.oracle.truffle.r.runtime.RError;
 import com.oracle.truffle.r.runtime.data.CharSXPWrapper;
-import com.oracle.truffle.r.runtime.RInternalError;
 import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames;
 import com.oracle.truffle.r.runtime.data.RNull;
 import com.oracle.truffle.r.runtime.data.RSymbol;
@@ -201,18 +200,4 @@ public final class MiscNodes {
         }
     }
 
-    @TypeSystemReference(RTypes.class)
-    public abstract static class MatchNode extends FFIUpCallNode.Arg3 {
-
-        @SuppressWarnings("unused")
-        @Specialization
-        Object match(Object itables, Object ix, int nmatch) {
-            throw RInternalError.unimplemented("Rf_match");
-        }
-
-        public static MatchNode create() {
-            return MiscNodesFactory.MatchNodeGen.create();
-        }
-    }
-
 }
diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/upcalls/StdUpCallsRFFI.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/upcalls/StdUpCallsRFFI.java
index eee88cd69e..50a20bc8e1 100644
--- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/upcalls/StdUpCallsRFFI.java
+++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/upcalls/StdUpCallsRFFI.java
@@ -36,7 +36,7 @@ import com.oracle.truffle.r.ffi.impl.nodes.ListAccessNodes.CADRNode;
 import com.oracle.truffle.r.ffi.impl.nodes.ListAccessNodes.CARNode;
 import com.oracle.truffle.r.ffi.impl.nodes.ListAccessNodes.CDDRNode;
 import com.oracle.truffle.r.ffi.impl.nodes.ListAccessNodes.CDRNode;
-import com.oracle.truffle.r.ffi.impl.nodes.MiscNodes;
+import com.oracle.truffle.r.ffi.impl.nodes.MatchNodes;
 import com.oracle.truffle.r.ffi.impl.nodes.MiscNodes.LENGTHNode;
 import com.oracle.truffle.r.ffi.processor.RFFICstring;
 import com.oracle.truffle.r.ffi.processor.RFFIRunGC;
@@ -345,6 +345,9 @@ public interface StdUpCallsRFFI {
     @RFFIUpCallNode(CADDRNode.class)
     Object Rf_asCharacterFactor(Object x);
 
-    @RFFIUpCallNode(MiscNodes.MatchNode.class)
+    @RFFIUpCallNode(MatchNodes.MatchNode.class)
     Object Rf_match(Object itables, Object ix, int nmatch);
+
+    @RFFIUpCallNode(MatchNodes.NonNullStringMatchNode.class)
+    Object Rf_NonNullStringMatch(Object s, Object t);
 }
diff --git a/com.oracle.truffle.r.native/fficall/src/common/rffi_upcalls.h b/com.oracle.truffle.r.native/fficall/src/common/rffi_upcalls.h
index 6a0da3c3b7..e48fc20e3c 100644
--- a/com.oracle.truffle.r.native/fficall/src/common/rffi_upcalls.h
+++ b/com.oracle.truffle.r.native/fficall/src/common/rffi_upcalls.h
@@ -276,6 +276,7 @@ typedef double (*call_Rf_dunif)(double a, double b, double c, int d);
 typedef double (*call_Rf_punif)(double a, double b, double c, int d, int e);
 typedef double (*call_Rf_runif)(double x, double y);
 typedef SEXP (*call_Rf_match)(SEXP itable, SEXP ix, int nmatch);
+typedef Rboolean (*call_Rf_NonNullStringMatch)(SEXP s, SEXP t);
 
 typedef SEXP (*call_getvar)();
 
diff --git a/com.oracle.truffle.r.native/fficall/src/common/rffi_upcallsindex.h b/com.oracle.truffle.r.native/fficall/src/common/rffi_upcallsindex.h
index 87bae66a40..968cebc4bd 100644
--- a/com.oracle.truffle.r.native/fficall/src/common/rffi_upcallsindex.h
+++ b/com.oracle.truffle.r.native/fficall/src/common/rffi_upcallsindex.h
@@ -80,91 +80,92 @@
 #define R_new_custom_connection_x 75
 #define R_tryEval_x 76
 #define Rf_GetOption1_x 77
-#define Rf_PairToVectorList_x 78
-#define Rf_ScalarDouble_x 79
-#define Rf_ScalarInteger_x 80
-#define Rf_ScalarLogical_x 81
-#define Rf_ScalarString_x 82
-#define Rf_VectorToPairList_x 83
-#define Rf_allocArray_x 84
-#define Rf_allocMatrix_x 85
-#define Rf_allocVector_x 86
-#define Rf_any_duplicated_x 87
-#define Rf_asChar_x 88
-#define Rf_asCharacterFactor_x 89
-#define Rf_asInteger_x 90
-#define Rf_asLogical_x 91
-#define Rf_asReal_x 92
-#define Rf_classgets_x 93
-#define Rf_coerceVector_x 94
-#define Rf_cons_x 95
-#define Rf_copyListMatrix_x 96
-#define Rf_copyMatrix_x 97
-#define Rf_copyMostAttrib_x 98
-#define Rf_defineVar_x 99
-#define Rf_dunif_x 100
-#define Rf_duplicate_x 101
-#define Rf_error_x 102
-#define Rf_errorcall_x 103
-#define Rf_eval_x 104
-#define Rf_findFun_x 105
-#define Rf_findVar_x 106
-#define Rf_findVarInFrame_x 107
-#define Rf_findVarInFrame3_x 108
-#define Rf_getAttrib_x 109
-#define Rf_gsetVar_x 110
-#define Rf_inherits_x 111
-#define Rf_install_x 112
-#define Rf_installChar_x 113
-#define Rf_isNull_x 114
-#define Rf_isString_x 115
-#define Rf_lengthgets_x 116
-#define Rf_match_x 117
-#define Rf_mkCharLenCE_x 118
-#define Rf_namesgets_x 119
-#define Rf_ncols_x 120
-#define Rf_nrows_x 121
-#define Rf_protect_x 122
-#define Rf_punif_x 123
-#define Rf_qunif_x 124
-#define Rf_runif_x 125
-#define Rf_setAttrib_x 126
-#define Rf_str2type_x 127
-#define Rf_unprotect_x 128
-#define Rf_unprotect_ptr_x 129
-#define Rf_warning_x 130
-#define Rf_warningcall_x 131
-#define Rprintf_x 132
-#define SETCADR_x 133
-#define SETCAR_x 134
-#define SETCDR_x 135
-#define SET_NAMED_FASTR_x 136
-#define SET_RDEBUG_x 137
-#define SET_RSTEP_x 138
-#define SET_S4_OBJECT_x 139
-#define SET_STRING_ELT_x 140
-#define SET_SYMVALUE_x 141
-#define SET_TAG_x 142
-#define SET_TYPEOF_FASTR_x 143
-#define SET_VECTOR_ELT_x 144
-#define STRING_ELT_x 145
-#define SYMVALUE_x 146
-#define TAG_x 147
-#define TYPEOF_x 148
-#define UNSET_S4_OBJECT_x 149
-#define VECTOR_ELT_x 150
-#define forceSymbols_x 151
-#define getCCallable_x 152
-#define getConnectionClassString_x 153
-#define getOpenModeString_x 154
-#define getSummaryDescription_x 155
-#define isSeekable_x 156
-#define registerCCallable_x 157
-#define registerRoutines_x 158
-#define setDotSymbolValues_x 159
-#define unif_rand_x 160
-#define useDynamicSymbols_x 161
+#define Rf_NonNullStringMatch_x 78
+#define Rf_PairToVectorList_x 79
+#define Rf_ScalarDouble_x 80
+#define Rf_ScalarInteger_x 81
+#define Rf_ScalarLogical_x 82
+#define Rf_ScalarString_x 83
+#define Rf_VectorToPairList_x 84
+#define Rf_allocArray_x 85
+#define Rf_allocMatrix_x 86
+#define Rf_allocVector_x 87
+#define Rf_any_duplicated_x 88
+#define Rf_asChar_x 89
+#define Rf_asCharacterFactor_x 90
+#define Rf_asInteger_x 91
+#define Rf_asLogical_x 92
+#define Rf_asReal_x 93
+#define Rf_classgets_x 94
+#define Rf_coerceVector_x 95
+#define Rf_cons_x 96
+#define Rf_copyListMatrix_x 97
+#define Rf_copyMatrix_x 98
+#define Rf_copyMostAttrib_x 99
+#define Rf_defineVar_x 100
+#define Rf_dunif_x 101
+#define Rf_duplicate_x 102
+#define Rf_error_x 103
+#define Rf_errorcall_x 104
+#define Rf_eval_x 105
+#define Rf_findFun_x 106
+#define Rf_findVar_x 107
+#define Rf_findVarInFrame_x 108
+#define Rf_findVarInFrame3_x 109
+#define Rf_getAttrib_x 110
+#define Rf_gsetVar_x 111
+#define Rf_inherits_x 112
+#define Rf_install_x 113
+#define Rf_installChar_x 114
+#define Rf_isNull_x 115
+#define Rf_isString_x 116
+#define Rf_lengthgets_x 117
+#define Rf_match_x 118
+#define Rf_mkCharLenCE_x 119
+#define Rf_namesgets_x 120
+#define Rf_ncols_x 121
+#define Rf_nrows_x 122
+#define Rf_protect_x 123
+#define Rf_punif_x 124
+#define Rf_qunif_x 125
+#define Rf_runif_x 126
+#define Rf_setAttrib_x 127
+#define Rf_str2type_x 128
+#define Rf_unprotect_x 129
+#define Rf_unprotect_ptr_x 130
+#define Rf_warning_x 131
+#define Rf_warningcall_x 132
+#define Rprintf_x 133
+#define SETCADR_x 134
+#define SETCAR_x 135
+#define SETCDR_x 136
+#define SET_NAMED_FASTR_x 137
+#define SET_RDEBUG_x 138
+#define SET_RSTEP_x 139
+#define SET_S4_OBJECT_x 140
+#define SET_STRING_ELT_x 141
+#define SET_SYMVALUE_x 142
+#define SET_TAG_x 143
+#define SET_TYPEOF_FASTR_x 144
+#define SET_VECTOR_ELT_x 145
+#define STRING_ELT_x 146
+#define SYMVALUE_x 147
+#define TAG_x 148
+#define TYPEOF_x 149
+#define UNSET_S4_OBJECT_x 150
+#define VECTOR_ELT_x 151
+#define forceSymbols_x 152
+#define getCCallable_x 153
+#define getConnectionClassString_x 154
+#define getOpenModeString_x 155
+#define getSummaryDescription_x 156
+#define isSeekable_x 157
+#define registerCCallable_x 158
+#define registerRoutines_x 159
+#define setDotSymbolValues_x 160
+#define unif_rand_x 161
+#define useDynamicSymbols_x 162
 
-#define UPCALLS_TABLE_SIZE 162
+#define UPCALLS_TABLE_SIZE 163
 
 #endif // RFFI_UPCALLSINDEX_H
diff --git a/com.oracle.truffle.r.native/fficall/src/truffle_common/match.c b/com.oracle.truffle.r.native/fficall/src/truffle_common/match.c
new file mode 100644
index 0000000000..9a5d46d50c
--- /dev/null
+++ b/com.oracle.truffle.r.native/fficall/src/truffle_common/match.c
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+#include "../truffle_nfi/rffiutils.h"
+#include "rffi_upcalls.h"
+
+Rboolean Rf_NonNullStringMatch(SEXP s, SEXP t)
+{
+	return ((call_Rf_NonNullStringMatch) callbacks[Rf_NonNullStringMatch_x])(s, t);
+}
+
diff --git a/com.oracle.truffle.r.native/version.source b/com.oracle.truffle.r.native/version.source
index 81b5c5d06c..e522732c77 100644
--- a/com.oracle.truffle.r.native/version.source
+++ b/com.oracle.truffle.r.native/version.source
@@ -1 +1 @@
-37
+38
-- 
GitLab