From 86ba66b964eb49888362c3a255f21cde2bc112de Mon Sep 17 00:00:00 2001 From: Florian Angerer <florian.angerer@oracle.com> Date: Fri, 22 Sep 2017 14:07:00 +0200 Subject: [PATCH] Using RCodeBuilder instead of RASTUtils. --- .../r/engine/RRuntimeASTAccessImpl.java | 19 +++++++++++++------ .../vector/CachedExtractVectorNode.java | 2 +- .../vector/CachedReplaceVectorNode.java | 2 +- .../truffle/r/runtime/RRuntimeASTAccess.java | 2 +- .../truffle/r/runtime/data/RLanguage.java | 2 +- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/RRuntimeASTAccessImpl.java b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/RRuntimeASTAccessImpl.java index a439a0b7db..d0d48097d5 100644 --- a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/RRuntimeASTAccessImpl.java +++ b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/RRuntimeASTAccessImpl.java @@ -92,6 +92,7 @@ import com.oracle.truffle.r.runtime.nodes.RCodeBuilder; import com.oracle.truffle.r.runtime.nodes.RCodeBuilder.Argument; import com.oracle.truffle.r.runtime.nodes.RInstrumentableNode; import com.oracle.truffle.r.runtime.nodes.RNode; +import com.oracle.truffle.r.runtime.nodes.RSourceSectionNode; import com.oracle.truffle.r.runtime.nodes.RSyntaxCall; import com.oracle.truffle.r.runtime.nodes.RSyntaxElement; import com.oracle.truffle.r.runtime.nodes.RSyntaxFunction; @@ -222,21 +223,27 @@ class RRuntimeASTAccessImpl implements RRuntimeASTAccess { @Override @TruffleBoundary - public Object fromList(RList list, RLanguage.RepType repType) { + public Object createLanguageFromList(RList list, RLanguage.RepType repType) { int length = list.getLength(); if (length == 0) { return RNull.instance; } else if (repType == RLanguage.RepType.CALL) { RStringVector formals = list.getNames(); - RSyntaxNode[] arguments = new RSyntaxNode[length - 1]; - String[] sigNames = new String[arguments.length]; + + List<RCodeBuilder.Argument<RSyntaxNode>> argList = new ArrayList<>(length - 1); for (int i = 1; i < length; i++) { - arguments[i - 1] = (RSyntaxNode) unwrapToRNode(list.getDataAtAsObject(i)); String formal = formals == null ? null : formals.getDataAt(i); - sigNames[i - 1] = formal != null && formal.length() > 0 ? formal : null; + RSyntaxNode syntaxArg = (RSyntaxNode) unwrapToRNode(list.getDataAtAsObject(i)); + if (formal != null) { + argList.add(RCodeBuilder.argument(RSourceSectionNode.LAZY_DEPARSE, formal, syntaxArg)); + } else { + argList.add(RCodeBuilder.argument(syntaxArg)); + } } + RNode fn = unwrapToRNode(list.getDataAtAsObject(0)); - RLanguage result = RDataFactory.createLanguage(RASTUtils.createCall(fn, false, ArgumentsSignature.get(sigNames), arguments).asRNode()); + RSyntaxNode call = RContext.getASTBuilder().call(RSourceSectionNode.LAZY_DEPARSE, fn.asRSyntaxNode(), argList); + RLanguage result = RDataFactory.createLanguage(call.asRNode()); if (formals != null && formals.getLength() > 0 && formals.getDataAt(0).length() > 0) { result.setCallLHSName(formals.getDataAt(0)); } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/CachedExtractVectorNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/CachedExtractVectorNode.java index 7ce6f47b09..f6e1fdd15a 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/CachedExtractVectorNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/CachedExtractVectorNode.java @@ -274,7 +274,7 @@ final class CachedExtractVectorNode extends CachedVectorNode { @TruffleBoundary private static Object materializeLanguage(RAbstractVector extractedVector) { - return RContext.getRRuntimeASTAccess().fromList((RList) extractedVector, RLanguage.RepType.CALL); + return RContext.getRRuntimeASTAccess().createLanguageFromList((RList) extractedVector, RLanguage.RepType.CALL); } private Object extract(int dimensionIndex, RAbstractStringVector vector, Object pos, PositionProfile profile) { diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/CachedReplaceVectorNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/CachedReplaceVectorNode.java index 71a7e7c718..73b47fda38 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/CachedReplaceVectorNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/CachedReplaceVectorNode.java @@ -318,7 +318,7 @@ final class CachedReplaceVectorNode extends CachedVectorNode { private Object wrapResult(RAbstractVector vector, RLanguage.RepType repType) { switch (vectorType) { case Language: - return RContext.getRRuntimeASTAccess().fromList((RList) vector, repType); + return RContext.getRRuntimeASTAccess().createLanguageFromList((RList) vector, repType); default: return vector; } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntimeASTAccess.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntimeASTAccess.java index fe78327aeb..cda3444897 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntimeASTAccess.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntimeASTAccess.java @@ -73,7 +73,7 @@ public interface RRuntimeASTAccess { * object whose rep is a {@code RCallNode} with the first list element as the function and the * remainder as the arguments, or a {@code RFunction} (as determined by repType). */ - Object fromList(RList list, RLanguage.RepType repType); + Object createLanguageFromList(RList list, RLanguage.RepType repType); /** * Get the "names" attribute for an {@link RLanguage} object, or {@code null} if none. 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 aa46ff8da7..9595b1723d 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 @@ -84,7 +84,7 @@ public final class RLanguage extends RSharingAttributeStorage implements RAbstra } else { l = (RList) o; } - return RContext.getRRuntimeASTAccess().fromList(l, type); + return RContext.getRRuntimeASTAccess().createLanguageFromList(l, type); } public RBaseNode getRep() { -- GitLab