From 39971ed01b31bf0163dc5b9ab18176200b49d2a6 Mon Sep 17 00:00:00 2001
From: Lukas Stadler <lukas.stadler@oracle.com>
Date: Tue, 13 Jun 2017 18:26:18 +0200
Subject: [PATCH] various small fixes

---
 .../truffle/r/nodes/builtin/base/Parse.java   |  6 +--
 .../builtin/helpers/BrowserInteractNode.java  | 10 +----
 .../r/nodes/control/ReplacementNode.java      | 11 +++--
 .../truffle/r/runtime/context/Engine.java     |  2 +-
 .../truffle/r/runtime/data/RLanguage.java     |  1 +
 .../r/runtime/nodes/RSyntaxFunction.java      | 42 -------------------
 6 files changed, 14 insertions(+), 58 deletions(-)

diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Parse.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Parse.java
index d39308b1ce..5d38f5473f 100644
--- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Parse.java
+++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Parse.java
@@ -112,7 +112,7 @@ public abstract class Parse extends RBuiltinNode.Arg6 {
 
     @TruffleBoundary
     @Specialization
-    protected Object parse(int conn, int n, @SuppressWarnings("unused") RNull text, String prompt, Object srcFile, String encoding) {
+    protected RExpression parse(int conn, int n, @SuppressWarnings("unused") RNull text, String prompt, Object srcFile, String encoding) {
         String[] lines;
         RConnection connection = RConnection.fromIndex(conn);
         if (connection == StdConnections.getStdin()) {
@@ -128,12 +128,12 @@ public abstract class Parse extends RBuiltinNode.Arg6 {
 
     @TruffleBoundary
     @Specialization
-    protected Object parse(int conn, int n, RAbstractStringVector text, String prompt, Object srcFile, String encoding) {
+    protected RExpression parse(int conn, int n, RAbstractStringVector text, String prompt, Object srcFile, String encoding) {
         RConnection connection = RConnection.fromIndex(conn);
         return doParse(connection, n, text.materialize().getDataWithoutCopying(), prompt, srcFile, encoding);
     }
 
-    private Object doParse(RConnection conn, int n, String[] lines, @SuppressWarnings("unused") String prompt, Object srcFile, @SuppressWarnings("unused") String encoding) {
+    private RExpression doParse(RConnection conn, int n, String[] lines, @SuppressWarnings("unused") String prompt, Object srcFile, @SuppressWarnings("unused") String encoding) {
         String coalescedLines = coalesce(lines);
         if (coalescedLines.length() == 0 || n == 0) {
             return RDataFactory.createExpression(new Object[0]);
diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/helpers/BrowserInteractNode.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/helpers/BrowserInteractNode.java
index c37597d069..af83fd603a 100644
--- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/helpers/BrowserInteractNode.java
+++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/helpers/BrowserInteractNode.java
@@ -23,7 +23,6 @@
 package com.oracle.truffle.r.nodes.builtin.helpers;
 
 import com.oracle.truffle.api.CompilerDirectives;
-import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
 import com.oracle.truffle.api.dsl.Specialization;
 import com.oracle.truffle.api.frame.MaterializedFrame;
 import com.oracle.truffle.api.frame.VirtualFrame;
@@ -88,7 +87,8 @@ public abstract class BrowserInteractNode extends RNode {
         if (currentCaller == null) {
             currentCaller = RCaller.topLevel;
         }
-        RCaller browserCaller = createCaller(currentCaller);
+        RCodeBuilder<RSyntaxNode> builder = RContext.getASTBuilder();
+        RCaller browserCaller = RCaller.create(null, currentCaller, builder.call(RSyntaxNode.INTERNAL, builder.lookup(RSyntaxNode.INTERNAL, "browser", true)));
         try {
             browserState.setInBrowser(browserCaller);
             LW: while (true) {
@@ -178,12 +178,6 @@ public abstract class BrowserInteractNode extends RNode {
         return exitMode;
     }
 
-    @TruffleBoundary
-    private static RCaller createCaller(RCaller currentCaller) {
-        RCodeBuilder<RSyntaxNode> builder = RContext.getASTBuilder();
-        return RCaller.create(null, currentCaller, builder.call(RSyntaxNode.INTERNAL, builder.lookup(RSyntaxNode.INTERNAL, "browser", true)));
-    }
-
     private String getSrcinfo(RStringVector element) {
         if (getSrcRefAttrNode == null) {
             CompilerDirectives.transferToInterpreterAndInvalidate();
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/ReplacementNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/ReplacementNode.java
index 2eb77334c9..ca56335a05 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/ReplacementNode.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/control/ReplacementNode.java
@@ -261,7 +261,8 @@ abstract class ReplacementNode extends OperatorNode {
                 replaceCall.execute(frame);
             } catch (FullCallNeededException e) {
                 CompilerDirectives.transferToInterpreterAndInvalidate();
-                replace(new GenericReplacementNode(getLazySourceSection(), operator, target, lhs, rhs, calls, targetVarName, isSuper, tempNamesStartIndex)).executeReplacement(frame);
+                replace(new GenericReplacementNode(getLazySourceSection(), operator, target, lhs, RContext.getASTBuilder().process(rhs.asRSyntaxNode()).asRNode(), calls, targetVarName, isSuper,
+                                tempNamesStartIndex)).executeReplacement(frame);
             }
         }
     }
@@ -308,7 +309,8 @@ abstract class ReplacementNode extends OperatorNode {
         @Override
         public Object execute(VirtualFrame frame) {
             CompilerDirectives.transferToInterpreterAndInvalidate();
-            GenericReplacementNode replacement = new GenericReplacementNode(getLazySourceSection(), operator, target, lhs, rhs, calls, targetVarName, isSuper, tempNamesStartIndex);
+            GenericReplacementNode replacement = new GenericReplacementNode(getLazySourceSection(), operator, target, lhs, RContext.getASTBuilder().process(rhs.asRSyntaxNode()).asRNode(), calls,
+                            targetVarName, isSuper, tempNamesStartIndex);
             return replace(replacement).execute(frame);
         }
 
@@ -322,7 +324,8 @@ abstract class ReplacementNode extends OperatorNode {
                 replaceCall.execute(frame);
             } catch (FullCallNeededException e) {
                 CompilerDirectives.transferToInterpreterAndInvalidate();
-                GenericReplacementNode replacement = replace(new GenericReplacementNode(getLazySourceSection(), operator, target, lhs, rhs, calls, targetVarName, isSuper, tempNamesStartIndex));
+                GenericReplacementNode replacement = replace(new GenericReplacementNode(getLazySourceSection(), operator, target, lhs, RContext.getASTBuilder().process(rhs.asRSyntaxNode()).asRNode(),
+                                calls, targetVarName, isSuper, tempNamesStartIndex));
 
                 if (e.rhsValue == null) {
                     // we haven't queried the rhs value yet
@@ -351,7 +354,7 @@ abstract class ReplacementNode extends OperatorNode {
 
         GenericReplacementNode(SourceSection source, RSyntaxLookup operator, RNode target, RSyntaxElement lhs, RNode rhs, List<RSyntaxCall> calls, String targetVarName, boolean isSuper,
                         int tempNamesStartIndex) {
-            super(source, operator, lhs, RContext.getASTBuilder().process(rhs.asRSyntaxNode()).asRNode(), tempNamesStartIndex);
+            super(source, operator, lhs, rhs, tempNamesStartIndex);
             /*
              * When there are more than two function calls in LHS, then we save some function calls
              * by saving the intermediate results into temporary variables and reusing them.
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/Engine.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/Engine.java
index fe6fc77fa9..1442f9e568 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/Engine.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/Engine.java
@@ -171,7 +171,7 @@ public interface Engine {
      * namespace, but the current stack is not empty. So when {@code frame} is not {@code null} a
      * {@code caller} should be passed to maintain the call stack correctly. {@code names} string
      * vector describing (optional) argument names
-     * 
+     *
      * @param names signature of the given parameters, may be {@code null} in which case the empty
      *            signature of correct cardinality shall be used.
      * @param evalPromises whether to evaluate promises in args array before calling the function.
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RLanguage.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RLanguage.java
index ed06179415..60e4849da5 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RLanguage.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RLanguage.java
@@ -76,6 +76,7 @@ public class RLanguage extends RSharingAttributeStorage implements RAbstractCont
         this.length = length;
     }
 
+    @TruffleBoundary
     public static Object fromList(Object o, RLanguage.RepType type) {
         RList l;
         if (o instanceof RPairList) {
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nodes/RSyntaxFunction.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nodes/RSyntaxFunction.java
index 0539766d5a..e72da32fb6 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nodes/RSyntaxFunction.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nodes/RSyntaxFunction.java
@@ -22,7 +22,6 @@
  */
 package com.oracle.truffle.r.runtime.nodes;
 
-import com.oracle.truffle.api.source.SourceSection;
 import com.oracle.truffle.r.runtime.ArgumentsSignature;
 
 /**
@@ -39,45 +38,4 @@ public interface RSyntaxFunction extends RSyntaxElement {
 
     String getSyntaxDebugName();
 
-    /**
-     * Helper function: creates a synthetic RSyntaxFunction.
-     */
-    static RSyntaxFunction createDummyFunction(SourceSection originalSource, ArgumentsSignature signature, RSyntaxElement[] arguments, RSyntaxElement body, String debugName) {
-        return new RSyntaxFunction() {
-            @Override
-            public SourceSection getLazySourceSection() {
-                return originalSource;
-            }
-
-            @Override
-            public SourceSection getSourceSection() {
-                return originalSource;
-            }
-
-            @Override
-            public ArgumentsSignature getSyntaxSignature() {
-                return signature;
-            }
-
-            @Override
-            public RSyntaxElement[] getSyntaxArgumentDefaults() {
-                return arguments;
-            }
-
-            @Override
-            public RSyntaxElement getSyntaxBody() {
-                return body;
-            }
-
-            @Override
-            public void setSourceSection(SourceSection src) {
-                // ignored
-            }
-
-            @Override
-            public String getSyntaxDebugName() {
-                return debugName;
-            }
-        };
-    }
 }
-- 
GitLab