Skip to content
Snippets Groups Projects
Commit a8d66582 authored by Lukas Stadler's avatar Lukas Stadler
Browse files

simplify do.call (only one specialization)

parent 8d2ecc52
Branches
No related tags found
No related merge requests found
......@@ -29,6 +29,7 @@ import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.*;
import com.oracle.truffle.api.frame.*;
import com.oracle.truffle.api.utilities.*;
import com.oracle.truffle.r.nodes.*;
import com.oracle.truffle.r.nodes.builtin.*;
import com.oracle.truffle.r.nodes.builtin.base.GetFunctionsFactory.GetFactory;
......@@ -39,7 +40,7 @@ import com.oracle.truffle.r.runtime.data.model.*;
import com.oracle.truffle.r.runtime.env.*;
// TODO Implement properly, this is a simple implementation that works when the environment doesn't matter
@RBuiltin(name = "do.call", kind = INTERNAL, parameterNames = {"name", "args", "env"})
@RBuiltin(name = "do.call", kind = INTERNAL, parameterNames = {"what", "args", "envir"})
public abstract class DoCall extends RBuiltinNode {
@Child private CallInlineCacheNode callCache = CallInlineCacheNode.create(3);
......@@ -49,19 +50,24 @@ public abstract class DoCall extends RBuiltinNode {
@CompilationFinal private boolean needsCallerFrame;
private final RAttributeProfiles attrProfiles = RAttributeProfiles.create();
private final BranchProfile errorProfile = BranchProfile.create();
@Specialization(guards = "fname.getLength() == 1")
protected Object doDoCall(VirtualFrame frame, RAbstractStringVector fname, RList argsAsList, REnvironment env) {
if (getNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
getNode = insert(GetFactory.create(new RNode[4], getBuiltin(), getSuppliedSignature()));
@Specialization
protected Object doDoCall(VirtualFrame frame, Object what, RList argsAsList, REnvironment env) {
RFunction func;
if (what instanceof RFunction) {
func = (RFunction) what;
} else if (what instanceof String || (what instanceof RAbstractStringVector && ((RAbstractStringVector) what).getLength() == 1)) {
if (getNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
getNode = insert(GetFactory.create(new RNode[4], getBuiltin(), getSuppliedSignature()));
}
func = (RFunction) getNode.execute(frame, what, env, RType.Function.getName(), RRuntime.LOGICAL_TRUE);
} else {
errorProfile.enter();
throw RError.error(getEncapsulatingSourceSection(), RError.Message.MUST_BE_STRING_OR_FUNCTION, "what");
}
RFunction func = (RFunction) getNode.execute(frame, fname, env, RType.Function.getName(), RRuntime.LOGICAL_TRUE);
return doDoCall(frame, func, argsAsList, env);
}
@Specialization
protected Object doDoCall(VirtualFrame frame, RFunction func, RList argsAsList, @SuppressWarnings("unused") REnvironment env) {
Object[] argValues = argsAsList.getDataNonShared();
RStringVector n = argsAsList.getNames(attrProfiles);
String[] argNames = n == null ? new String[argValues.length] : n.getDataNonShared();
......
......@@ -70,7 +70,7 @@ public class GetFunctions {
@GenerateNodeFactory
public abstract static class Get extends Adapter {
public abstract Object execute(VirtualFrame frame, RAbstractStringVector name, REnvironment envir, String mode, byte inherits);
public abstract Object execute(VirtualFrame frame, Object name, REnvironment envir, String mode, byte inherits);
public static boolean isInherits(byte inherits) {
return inherits == RRuntime.LOGICAL_TRUE;
......
......@@ -321,6 +321,7 @@ public final class RError extends RuntimeException {
TYPE_EXPECTED("%s argument expected"),
CANNOT_CHANGE_DIRECTORY("cannot change working directory"),
FIRST_ARG_MUST_BE_STRING("first argument must be a character string"),
MUST_BE_STRING_OR_FUNCTION("'%s' must be a character string or a function"),
ARG_MUST_BE_CHARACTER_VECTOR_LENGTH_ONE("argument must be a character vector of length 1"),
ARG_SHOULD_BE_CHARACTER_VECTOR_LENGTH_ONE("argument should be a character vector of length 1\nall but the first element will be ignored"),
ZERO_LENGTH_VARIABLE("attempt to use zero-length variable name"),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment