From 3e2e325d4d032819cda544676bceefc72f180917 Mon Sep 17 00:00:00 2001
From: Zbynek Slajchrt <zbynek.slajchrt@oracle.com>
Date: Mon, 2 Oct 2017 20:52:50 +0200
Subject: [PATCH] Recent changes in FastR grid package adapted to GNUR 3.4.0

---
 .../fastrGrid/FastRGridExternalLookup.java    |  1 -
 .../truffle/r/library/fastrGrid/fastrGrid.R   | 24 +++++++-------
 .../truffle/r/nodes/builtin/base/Match.java   | 32 +++++++++++++++++++
 .../truffle/r/runtime/RInternalCode.java      |  2 +-
 4 files changed, 45 insertions(+), 14 deletions(-)

diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/FastRGridExternalLookup.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/FastRGridExternalLookup.java
index 8080509ff2..e3555f6a22 100644
--- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/FastRGridExternalLookup.java
+++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/FastRGridExternalLookup.java
@@ -38,7 +38,6 @@ import com.oracle.truffle.r.library.fastrGrid.graphics.CPar;
 import com.oracle.truffle.r.nodes.builtin.RExternalBuiltinNode;
 import com.oracle.truffle.r.nodes.builtin.RInternalCodeBuiltinNode;
 import com.oracle.truffle.r.runtime.RInternalCode;
-import com.oracle.truffle.r.runtime.RInternalError;
 import com.oracle.truffle.r.runtime.RRuntime;
 import com.oracle.truffle.r.runtime.data.RList;
 import com.oracle.truffle.r.runtime.data.RNull;
diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/fastrGrid.R b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/fastrGrid.R
index 068c5fb4f5..2dfc34c84e 100644
--- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/fastrGrid.R
+++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/fastrGrid.R
@@ -63,8 +63,8 @@ find.in.children <- function(path, name, strict, currPath, children, depth) {
 
 # path is a string, e.g. "A::B::C", or NULL if we are not searching for particular path
 # name is a string, the name of child we are looking for
-L_downvppath <- function(path, name, strict) {
-    currVp <- .Call(grid:::L_currentViewport)
+downvppath <- function(path, name, strict) {
+    currVp <- .Call(grid:::C_currentViewport)
     result <- find.viewport(path, name, strict, NULL, currVp, 1L);
     if (result[[1]]) {
         .Internal(.fastr.grid.doSetViewPort(result[[2L]], FALSE, FALSE));
@@ -74,17 +74,17 @@ L_downvppath <- function(path, name, strict) {
     }
 }
 
-L_downviewport <- function(name, strict) {
-    L_downvppath(0L, name, strict)
+downviewport <- function(name, strict) {
+    downvppath(0L, name, strict)
 }
 
-L_setviewport <- function(vp, hasParent) {
+setviewport <- function(vp, hasParent) {
     pushedVP <- grid:::pushedvp(vp);
     .Internal(.fastr.grid.doSetViewPort(pushedVP, hasParent, TRUE));
 }
 
-L_unsetviewport <- function(n) {
-    gvp <- .Call(grid:::L_currentViewport)
+unsetviewport <- function(n) {
+    gvp <- .Call(grid:::C_currentViewport)
     newVp <- gvp;
     for (i in 1:n) {
         gvp <- newVp;
@@ -152,8 +152,8 @@ getUnitData <- function(unit, index) {
 isPureNullUnitGrobDim <- function(unit, index, dimFunction) {
     # Can a grob have "null" width/height?
     # to be sure we cover everything, we keep the check here (like in GnuR)
-    savedgpar <- .Call(grid:::L_getGPar)
-    savedgrob <- .Call(grid:::L_getCurrentGrob)
+    savedgpar <- .Call(grid:::C_getGPar)
+    savedgrob <- .Call(grid:::C_getCurrentGrob)
 
     grob <- findGrob(getUnitData(unit, index), savedgrob)
 
@@ -161,8 +161,8 @@ isPureNullUnitGrobDim <- function(unit, index, dimFunction) {
     result <- isPureNullUnit(dimFunction(updatedgrob), 1)
     grid:::postDraw(updatedgrob)
 
-    .Call(grid:::L_setGPar, savedgpar)
-    .Call(grid:::L_setCurrentGrob, savedgrob)
+    .Call(grid:::C_setGPar, savedgpar)
+    .Call(grid:::C_setCurrentGrob, savedgrob)
     result
 }
 
@@ -190,7 +190,7 @@ isPureNullUnitArithmetic <- function(x, index) {
 # { gt <- grid.text("Hi there"); isPureNullUnit(unit(1, "grobheight", gt), 1) } == FALSE
 
 grobConversionPreDraw <- function(grobIn) {
-    grob <- findGrob(grobIn, .Call(grid:::L_getCurrentGrob))
+    grob <- findGrob(grobIn, .Call(grid:::C_getCurrentGrob))
     grid:::preDraw(grob)
 }
 
diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Match.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Match.java
index af640e76af..41c44bc23f 100644
--- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Match.java
+++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Match.java
@@ -390,6 +390,38 @@ public abstract class Match extends RBuiltinNode.Arg4 {
             return RDataFactory.createIntVector(result, setCompleteState(matchAll, nomatch));
         }
 
+        @Specialization
+        @TruffleBoundary
+        protected RIntVector match(RAbstractDoubleVector x, RAbstractLogicalVector table, int nomatch) {
+            int[] result = initResult(x.getLength(), nomatch);
+            boolean matchAll = true;
+            int[] values = {RRuntime.LOGICAL_TRUE, RRuntime.LOGICAL_FALSE, RRuntime.LOGICAL_NA};
+            int[] indexes = new int[values.length];
+            for (int i = 0; i < values.length; i++) {
+                byte value = (byte) values[i];
+                for (int j = 0; j < table.getLength(); j++) {
+                    if (table.getDataAt(j) == value) {
+                        indexes[i] = j + 1;
+                        break;
+                    }
+                }
+                values[i] = RRuntime.logical2int(value);
+            }
+            for (int i = 0; i < result.length; i++) {
+                double xx = x.getDataAt(i);
+                boolean match = false;
+                for (int j = 0; j < values.length; j++) {
+                    if (xx == values[j] && indexes[j] != 0) {
+                        result[i] = indexes[j];
+                        match = true;
+                        break;
+                    }
+                }
+                matchAll &= match;
+            }
+            return RDataFactory.createIntVector(result, setCompleteState(matchAll, nomatch));
+        }
+
         @Specialization(guards = "x.getLength() == 1")
         @TruffleBoundary
         protected int matchSizeOne(RAbstractStringVector x, RAbstractStringVector table, int nomatch,
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RInternalCode.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RInternalCode.java
index 90d023e31c..ee2c370c74 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RInternalCode.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RInternalCode.java
@@ -80,7 +80,7 @@ public final class RInternalCode {
             this.evaluatedEnvironment = env;
         }
         RFunction fun = (RFunction) env.get(name);
-        assert fun != null;
+        assert fun != null : "No internal function '" + name + "' found";
         return fun;
     }
 
-- 
GitLab