Skip to content
Snippets Groups Projects
Commit b55c823e authored by Adam Welc's avatar Adam Welc
Browse files

Fixes to "match.call" functions related to handling var arg.

parent cd931610
Branches
No related tags found
No related merge requests found
......@@ -147,7 +147,12 @@ public class RRuntimeASTAccessImpl implements RRuntimeASTAccess {
if (RASTUtils.isNamedFunctionNode(node)) {
return RASTUtils.findFunctionName(node, true);
} else {
return RDataFactory.createLanguage(RASTUtils.getFunctionNode(node));
Object functionNode = RASTUtils.getFunctionNode(node);
if (functionNode instanceof ConstantNode && ((ConstantNode) functionNode).getValue() instanceof RSymbol) {
return ((ConstantNode) functionNode).getValue();
} else {
return RDataFactory.createLanguage(functionNode);
}
}
} else {
CallArgumentsNode args = RASTUtils.findCallArgumentsNode(node);
......
......@@ -33,6 +33,7 @@ import com.oracle.truffle.api.frame.FrameInstance.FrameAccess;
import com.oracle.truffle.api.source.*;
import com.oracle.truffle.api.utilities.*;
import com.oracle.truffle.r.nodes.*;
import com.oracle.truffle.r.nodes.access.*;
import com.oracle.truffle.r.nodes.builtin.*;
import com.oracle.truffle.r.nodes.function.*;
import com.oracle.truffle.r.nodes.function.PromiseHelperNode.PromiseDeoptimizeFrameNode;
......@@ -121,6 +122,11 @@ public class FrameFunctions {
RNode[] listArgs = new RNode[temp.getArguments().length];
for (int i = 0; i < listArgs.length; i++) {
listArgs[i] = RASTUtils.createNodeForValue(temp.getArgument(i));
if (listArgs[i] == null) {
StringBuffer sb = new StringBuffer((i + 1) < 10 ? ".." : ".");
sb.append(i + 1);
listArgs[i] = ConstantNode.create(RDataFactory.createSymbol(sb.toString()));
}
}
RNode varArgs = PromiseNode.createVarArgsAsSyntax(listArgs, temp.getSignature(), this);
CallArgumentsNode callArgsNode = CallArgumentsNode.create(false, false, new RNode[]{varArgs}, signature);
......
......@@ -165,7 +165,16 @@ public class RASTUtils {
if (promiseRep instanceof VarArgNode) {
VarArgNode varArgNode = (VarArgNode) promiseRep;
RPromise varArgPromise = varArgNode.executeNonEvaluated((VirtualFrame) promise.getFrame());
return createNodeForValue(varArgPromise);
Node unwrappedRep = unwrap(varArgPromise.getRep());
if (unwrappedRep instanceof RCallNode) {
// this is for the return value is supposed to be of the form "..N" to represent
// unexpanded component of ..., as for example in:
// f1<-function(...) match.call(expand.dots=FALSE);
// f2<-function(...) f1(...); f2(c("a"))
return null;
} else {
return createNodeForValue(varArgPromise);
}
}
return NodeUtil.cloneNode(promiseRep);
} else {
......
......@@ -72,7 +72,7 @@ public abstract class ConstantNode extends RNode implements RSyntaxNode, Visibil
} else if (value instanceof String) {
return new ConstantObjectNode(value);
} else if (value instanceof RSymbol) {
return new ConstantObjectNode(((RSymbol) value).getName());
return new ConstantObjectNode(((RSymbol) value));
} else if (value instanceof RArgsValuesAndNames) {
// this can be created during argument matching and "call"
return new ConstantObjectNode(value);
......
......@@ -3083,6 +3083,13 @@ public class TestSimpleBuiltins extends TestBase {
assertEval("{ f <- function(...) match.call(expand.dots=FALSE) ; f(2, 3) }");
assertEval("{ f <- function(...) match.call(expand.dots=FALSE) ; f(x=2, y=3) }");
assertEval("{ f <- function(...) match.call(expand.dots=FALSE) ; f(x=2, 3) }");
assertEval("{ f1<-function(...) { dots <- match.call(expand.dots = FALSE)$...; dots }; f2<-function(...) f1(...); f2(\"a\") }");
assertEval("{ f1<-function(...) { dots <- match.call(expand.dots = FALSE)$...; dots }; f2<-function(...) f1(...); f2(c(\"a\")) }");
assertEval("{ f1<-function(...) { dots <- match.call(expand.dots = FALSE)$...; dots }; f2<-function(...) f1(...); f2(c(\"a\"), \"b\") }");
assertEval("{ f1<-function(...) { dots <- match.call(expand.dots = FALSE)$...; dots }; f2<-function(...) f1(...); f2(c(\"a\"), c(\"b\")) }");
assertEval("{ f1<-function(...) { dots <- match.call(expand.dots = FALSE)$...; dots }; f2<-function(...) f1(...); typeof(f2(\"a\")[[1]]) }");
assertEval("{ f1<-function(...) { dots <- match.call(expand.dots = FALSE)$...; dots }; f2<-function(...) f1(...); typeof(f2(c(\"a\"))[[1]]) }");
}
@Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment