From f714a158058cee445fac1fa0750ffd7f82d4c83d Mon Sep 17 00:00:00 2001
From: Florian Angerer <florian.angerer@oracle.com>
Date: Fri, 22 Sep 2017 14:55:28 +0200
Subject: [PATCH] Added missing RFFIUpCallNode annotations and did necessary
 refactoring.

---
 .../ffi/impl/common/JavaUpCallsRFFIImpl.java  |  7 ++-
 .../truffle/r/ffi/impl/nodes/MiscNodes.java   | 12 ++--
 .../r/ffi/impl/nodes/RandFunctionsNodes.java  | 56 ++++++++++++++++++-
 .../r/ffi/impl/upcalls/StdUpCallsRFFI.java    | 10 ++++
 4 files changed, 77 insertions(+), 8 deletions(-)

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 c5c1f77155..54ab531ca9 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
@@ -136,7 +136,12 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI {
     private final Map<String, Object> nameSymbolCache = new ConcurrentHashMap<>();
 
     private static RuntimeException implementedAsNode() {
-        throw RInternalError.shouldNotReachHere("upcall function is implemented via a node");
+        // TODO: Exception handling over native boundaries is currently missing. Once this works,
+        // remove the following two lines.
+        System.err.println("upcall function is implemented via a node");
+        System.exit(1);
+
+        return RInternalError.shouldNotReachHere("upcall function is implemented via a node");
     }
 
     // Checkstyle: stop method name check
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 9a448ed172..515524a94b 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
@@ -113,7 +113,7 @@ public final class MiscNodes {
     }
 
     @TypeSystemReference(RTypes.class)
-    abstract static class RDoSlotNode extends FFIUpCallNode.Arg2 {
+    public abstract static class RDoSlotNode extends FFIUpCallNode.Arg2 {
 
         @Child private AccessSlotNode accessSlotNode;
 
@@ -137,7 +137,7 @@ public final class MiscNodes {
     }
 
     @TypeSystemReference(RTypes.class)
-    abstract static class RDoSlotAssignNode extends FFIUpCallNode.Arg3 {
+    public abstract static class RDoSlotAssignNode extends FFIUpCallNode.Arg3 {
 
         @Child private UpdateSlotNode updateSlotNode;
 
@@ -166,7 +166,7 @@ public final class MiscNodes {
     }
 
     @TypeSystemReference(RTypes.class)
-    abstract static class RDoNewObjectNode extends FFIUpCallNode.Arg1 {
+    public abstract static class RDoNewObjectNode extends FFIUpCallNode.Arg1 {
 
         @Child private NewObject newObjectNode;
 
@@ -185,7 +185,7 @@ public final class MiscNodes {
     }
 
     @TypeSystemReference(RTypes.class)
-    abstract static class NamesGetsNode extends FFIUpCallNode.Arg2 {
+    public abstract static class NamesGetsNode extends FFIUpCallNode.Arg2 {
 
         @Child private SetNamesAttributeNode setNamesNode;
 
@@ -198,6 +198,10 @@ public final class MiscNodes {
             setNamesNode.execute(vec, val);
             return vec;
         }
+
+        public static NamesGetsNode create() {
+            return MiscNodesFactory.NamesGetsNodeGen.create();
+        }
     }
 
 }
diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/RandFunctionsNodes.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/RandFunctionsNodes.java
index f168c1caed..a626970a7e 100644
--- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/RandFunctionsNodes.java
+++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/RandFunctionsNodes.java
@@ -24,13 +24,16 @@ package com.oracle.truffle.r.ffi.impl.nodes;
 
 import com.oracle.truffle.api.dsl.Specialization;
 import com.oracle.truffle.r.runtime.nmath.MathFunctions;
+import com.oracle.truffle.r.runtime.nmath.MathFunctions.Function3_1;
+import com.oracle.truffle.r.runtime.nmath.MathFunctions.Function3_2;
 import com.oracle.truffle.r.runtime.nmath.RandomFunctions;
 import com.oracle.truffle.r.runtime.nmath.RandomFunctions.RandFunction2_Double;
 import com.oracle.truffle.r.runtime.nmath.RandomFunctions.RandomNumberProvider;
+import com.oracle.truffle.r.runtime.nmath.distr.Unif;
 
 public final class RandFunctionsNodes {
 
-    public abstract static class RandFunction3_2Node extends FFIUpCallNode.Arg5 {
+    abstract static class RandFunction3_2Node extends FFIUpCallNode.Arg5 {
         private final MathFunctions.Function3_2 inner;
 
         protected RandFunction3_2Node(MathFunctions.Function3_2 inner) {
@@ -43,7 +46,7 @@ public final class RandFunctionsNodes {
         }
     }
 
-    public abstract static class RandFunction3_1Node extends FFIUpCallNode.Arg4 {
+    abstract static class RandFunction3_1Node extends FFIUpCallNode.Arg4 {
         private final MathFunctions.Function3_1 inner;
 
         protected RandFunction3_1Node(MathFunctions.Function3_1 inner) {
@@ -56,7 +59,7 @@ public final class RandFunctionsNodes {
         }
     }
 
-    public abstract static class RandFunction2Node extends FFIUpCallNode.Arg2 {
+    abstract static class RandFunction2Node extends FFIUpCallNode.Arg2 {
         @Child private RandomFunctions.RandFunction2_Double inner;
 
         protected RandFunction2Node(RandFunction2_Double inner) {
@@ -69,4 +72,51 @@ public final class RandFunctionsNodes {
         }
     }
 
+    public abstract static class RunifNode extends RandFunction2Node {
+
+        protected RunifNode(RandFunction2_Double inner) {
+            super(inner);
+        }
+
+        public static RunifNode create() {
+            return RandFunctionsNodesFactory.RunifNodeGen.create(new Unif.Runif());
+        }
+
+    }
+
+    public abstract static class DunifNode extends RandFunction3_1Node {
+
+        protected DunifNode(Function3_1 inner) {
+            super(inner);
+        }
+
+        public static DunifNode create() {
+            return RandFunctionsNodesFactory.DunifNodeGen.create(new Unif.DUnif());
+        }
+
+    }
+
+    public abstract static class QunifNode extends RandFunction3_2Node {
+
+        protected QunifNode(Function3_2 inner) {
+            super(inner);
+        }
+
+        public static QunifNode create() {
+            return RandFunctionsNodesFactory.QunifNodeGen.create(new Unif.QUnif());
+        }
+
+    }
+
+    public abstract static class PunifNode extends RandFunction3_2Node {
+
+        protected PunifNode(Function3_2 inner) {
+            super(inner);
+        }
+
+        public static PunifNode create() {
+            return RandFunctionsNodesFactory.PunifNodeGen.create(new Unif.PUnif());
+        }
+
+    }
 }
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 50a20bc8e1..881f80c785 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
@@ -37,7 +37,9 @@ 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.MatchNodes;
+import com.oracle.truffle.r.ffi.impl.nodes.MiscNodes;
 import com.oracle.truffle.r.ffi.impl.nodes.MiscNodes.LENGTHNode;
+import com.oracle.truffle.r.ffi.impl.nodes.RandFunctionsNodes;
 import com.oracle.truffle.r.ffi.processor.RFFICstring;
 import com.oracle.truffle.r.ffi.processor.RFFIRunGC;
 import com.oracle.truffle.r.ffi.processor.RFFIUpCallNode;
@@ -96,6 +98,7 @@ public interface StdUpCallsRFFI {
 
     Object R_do_MAKE_CLASS(@RFFICstring String clazz);
 
+    @RFFIUpCallNode(MiscNodes.RDoNewObjectNode.class)
     Object R_do_new_object(Object classDef);
 
     /**
@@ -316,8 +319,10 @@ public interface StdUpCallsRFFI {
 
     boolean isSeekable(Object x);
 
+    @RFFIUpCallNode(MiscNodes.RDoSlotNode.class)
     Object R_do_slot(Object o, Object name);
 
+    @RFFIUpCallNode(MiscNodes.RDoSlotAssignNode.class)
     Object R_do_slot_assign(Object o, Object name, Object value);
 
     Object R_MethodsNamespace();
@@ -326,14 +331,19 @@ public interface StdUpCallsRFFI {
 
     int FASTR_getConnectionChar(Object obj);
 
+    @RFFIUpCallNode(RandFunctionsNodes.DunifNode.class)
     double Rf_dunif(double a, double b, double c, int d);
 
+    @RFFIUpCallNode(RandFunctionsNodes.QunifNode.class)
     double Rf_qunif(double a, double b, double c, int d, int e);
 
+    @RFFIUpCallNode(RandFunctionsNodes.PunifNode.class)
     double Rf_punif(double a, double b, double c, int d, int e);
 
+    @RFFIUpCallNode(RandFunctionsNodes.RunifNode.class)
     double Rf_runif(double a, double b);
 
+    @RFFIUpCallNode(MiscNodes.NamesGetsNode.class)
     Object Rf_namesgets(Object vec, Object val);
 
     @RFFIUpCallNode(CopyMostAttrib.class)
-- 
GitLab