diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/utils/Rprofmem.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/utils/Rprofmem.java index b88be4b9d9563568d5a0994910a3ed8b595e13c4..9708b8a15ea144246e4ab24bc74879036b442708 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/utils/Rprofmem.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/utils/Rprofmem.java @@ -125,7 +125,6 @@ public abstract class Rprofmem extends RExternalBuiltinNode.Arg3 implements RDat long size = RObjectSize.getObjectSize(data, myIgnoreObjectHandler); if (data instanceof RAbstractVector && size >= LARGE_VECTOR) { - RAbstractVector absv = (RAbstractVector) data; if (size > profmemState.threshold) { profmemState.out().printf("%d: %s\n", size, name); } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/APerm.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/APerm.java index 4d00fe2c217fea59696d2e98cfc66c43f28beb9b..a6cc8d2f64441a99abe144cc1b0c4dd40ebc939b 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/APerm.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/APerm.java @@ -57,7 +57,7 @@ public abstract class APerm extends RBuiltinNode { private void checkErrorConditions(RAbstractVector vector) { if (!vector.isArray()) { errorProfile.enter(); - throw RError.error(this, RError.Message.FIRST_ARG_MUST_BE_ARRAY); + throw RError.error(RError.SHOW_CALLER, RError.Message.FIRST_ARG_MUST_BE_ARRAY); } } @@ -171,13 +171,13 @@ public abstract class APerm extends RBuiltinNode { int pos = perm.getDataAt(i) - 1; // Adjust to zero based permute. if (pos >= perm.getLength() || pos < 0) { errorProfile.enter(); - throw RError.error(this, RError.Message.VALUE_OUT_OF_RANGE, "perm"); + throw RError.error(RError.SHOW_CALLER, RError.Message.VALUE_OUT_OF_RANGE, "perm"); } arrayPerm[i] = pos; if (visited[pos]) { // Duplicate dimension mapping in permute errorProfile.enter(); - throw RError.error(this, RError.Message.INVALID_ARGUMENT, "perm"); + throw RError.error(RError.SHOW_CALLER, RError.Message.INVALID_ARGUMENT, "perm"); } visited[pos] = true; } @@ -185,7 +185,7 @@ public abstract class APerm extends RBuiltinNode { } else { // perm size error errorProfile.enter(); - throw RError.error(this, RError.Message.IS_OF_WRONG_LENGTH, "perm", perm.getLength(), dim.length); + throw RError.error(RError.SHOW_CALLER, RError.Message.IS_OF_WRONG_LENGTH, "perm", perm.getLength(), dim.length); } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/All.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/All.java index aeae231f1a6706aa88f4b15024a01292f69372e6..a055c59ec8d41ace36318e02ac511ed07d1e4ca9 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/All.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/All.java @@ -25,99 +25,27 @@ package com.oracle.truffle.r.nodes.builtin.base; import static com.oracle.truffle.r.runtime.RDispatch.SUMMARY_GROUP_GENERIC; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; -import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.*; -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.r.nodes.builtin.CastBuilder; -import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; -import com.oracle.truffle.r.nodes.unary.CastLogicalNode; -import com.oracle.truffle.r.nodes.unary.CastLogicalNodeGen; -import com.oracle.truffle.r.runtime.RRuntime; +import com.oracle.truffle.api.dsl.Fallback; +import com.oracle.truffle.r.runtime.RInternalError; import com.oracle.truffle.r.runtime.builtins.RBuiltin; -import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames; -import com.oracle.truffle.r.runtime.data.RLogicalVector; -import com.oracle.truffle.r.runtime.data.RMissing; -import com.oracle.truffle.r.runtime.data.RNull; -import com.oracle.truffle.r.runtime.data.RSequence; -import com.oracle.truffle.r.runtime.data.RVector; /** * TODO: Added primitive {@code na.rm} support, but this code needs rewriting in the same manner as * {@link Any} and there is opportunity to share code. */ @RBuiltin(name = "all", kind = PRIMITIVE, parameterNames = {"...", "na.rm"}, dispatch = SUMMARY_GROUP_GENERIC, behavior = PURE) -public abstract class All extends RBuiltinNode { - - @Child private CastLogicalNode castLogicalNode; - - @Override - public Object[] getDefaultParameterValues() { - return new Object[]{RArgsValuesAndNames.EMPTY, RRuntime.LOGICAL_FALSE}; - } +public abstract class All extends Quantifier { @Override - protected void createCasts(CastBuilder casts) { - // casts.arg("...").mustBe(integerValue().or(logicalValue())).asLogicalVector(); - casts.arg("na.rm").asLogicalVector().findFirst(RRuntime.LOGICAL_NA).map(toBoolean()); + protected boolean emptyVectorResult() { + return true; } - @Specialization - protected byte all(byte value, @SuppressWarnings("unused") boolean naRm) { - return value; + @Fallback + @SuppressWarnings("unused") + protected byte op(Object vector, Object naRm) { + throw RInternalError.shouldNotReachHere(); } - @Specialization - protected byte all(RLogicalVector vector, boolean naRm) { - return accumulate(vector, naRm); - } - - @Specialization - protected byte all(@SuppressWarnings("unused") RNull vector, @SuppressWarnings("unused") boolean naRm) { - return RRuntime.LOGICAL_TRUE; - } - - @Specialization - protected byte all(@SuppressWarnings("unused") RMissing vector, @SuppressWarnings("unused") boolean naRm) { - return RRuntime.LOGICAL_TRUE; - } - - @Specialization - protected byte all(RArgsValuesAndNames args, boolean naRm) { - if (castLogicalNode == null) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - castLogicalNode = insert(CastLogicalNodeGen.create(true, false, false)); - } - Object[] argValues = args.getArguments(); - for (Object argValue : argValues) { - byte result; - if (argValue instanceof RVector || argValue instanceof RSequence) { - result = accumulate((RLogicalVector) castLogicalNode.execute(argValue), naRm); - } else if (argValue == RNull.instance) { - result = RRuntime.LOGICAL_TRUE; - } else { - result = (byte) castLogicalNode.execute(argValue); - if (result == RRuntime.LOGICAL_NA && naRm) { - continue; - } - } - if (result != RRuntime.LOGICAL_TRUE) { - return result; - } - } - return RRuntime.LOGICAL_TRUE; - } - - private static byte accumulate(RLogicalVector vector, boolean naRm) { - for (int i = 0; i < vector.getLength(); i++) { - byte b = vector.getDataAt(i); - if (b == RRuntime.LOGICAL_NA && naRm) { - continue; - } - if (b != RRuntime.LOGICAL_TRUE) { - return b; - } - } - return RRuntime.LOGICAL_TRUE; - } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Any.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Any.java index 669b8bab732c5aea14e4c8ae877008c611ef0e6a..f610412b15a1c8140ad32c72e0dc76ada9620630 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Any.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Any.java @@ -26,113 +26,22 @@ import static com.oracle.truffle.r.runtime.RDispatch.SUMMARY_GROUP_GENERIC; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.nodes.ExplodeLoop; -import com.oracle.truffle.api.profiles.BranchProfile; -import com.oracle.truffle.api.profiles.ConditionProfile; -import com.oracle.truffle.r.nodes.builtin.CastBuilder; -import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; -import com.oracle.truffle.r.nodes.unary.CastLogicalNode; -import com.oracle.truffle.r.nodes.unary.CastLogicalNodeGen; -import com.oracle.truffle.r.runtime.RRuntime; +import com.oracle.truffle.api.dsl.Fallback; +import com.oracle.truffle.r.runtime.RInternalError; import com.oracle.truffle.r.runtime.builtins.RBuiltin; -import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames; -import com.oracle.truffle.r.runtime.data.RNull; -import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector; -import com.oracle.truffle.r.runtime.ops.na.NACheck; @RBuiltin(name = "any", kind = PRIMITIVE, parameterNames = {"...", "na.rm"}, dispatch = SUMMARY_GROUP_GENERIC, behavior = PURE) -public abstract class Any extends RBuiltinNode { - - protected static final int MAX_CACHED_LENGTH = 10; - - private final NACheck naCheck = NACheck.create(); - private final ConditionProfile naRmProfile = ConditionProfile.createBinaryProfile(); - private final BranchProfile trueBranch = BranchProfile.create(); - private final BranchProfile falseBranch = BranchProfile.create(); - - @Children private final CastLogicalNode[] castLogicalNode = new CastLogicalNode[MAX_CACHED_LENGTH]; +public abstract class Any extends Quantifier { @Override - public Object[] getDefaultParameterValues() { - return new Object[]{RArgsValuesAndNames.EMPTY, RRuntime.LOGICAL_FALSE}; + protected boolean emptyVectorResult() { + return false; } - @Override - protected void createCasts(CastBuilder casts) { - casts.toLogical(1); + @Fallback + @SuppressWarnings("unused") + protected byte op(Object vector, Object naRm) { + throw RInternalError.shouldNotReachHere(); } - @Specialization(limit = "1", guards = {"cachedLength == args.getLength()", "cachedLength < MAX_CACHED_LENGTH"}) - @ExplodeLoop - protected byte anyCachedLength(RArgsValuesAndNames args, byte naRm, // - @Cached("args.getLength()") int cachedLength) { - boolean profiledNaRm = naRmProfile.profile(naRm != RRuntime.LOGICAL_FALSE); - Object[] arguments = args.getArguments(); - - byte result = RRuntime.LOGICAL_FALSE; - for (int i = 0; i < cachedLength; i++) { - Object argValue = arguments[i]; - byte v = processArgument(argValue, i, profiledNaRm); - if (v == RRuntime.LOGICAL_TRUE) { - return RRuntime.LOGICAL_TRUE; - } else if (v == RRuntime.LOGICAL_NA) { - result = RRuntime.LOGICAL_NA; - } - } - return result; - } - - @Specialization(contains = "anyCachedLength") - protected byte any(RArgsValuesAndNames args, byte naRm) { - boolean profiledNaRm = naRmProfile.profile(naRm != RRuntime.LOGICAL_FALSE); - - byte result = RRuntime.LOGICAL_FALSE; - for (Object argValue : args.getArguments()) { - byte v = processArgument(argValue, 0, profiledNaRm); - if (v == RRuntime.LOGICAL_TRUE) { - return RRuntime.LOGICAL_TRUE; - } else if (v == RRuntime.LOGICAL_NA) { - result = RRuntime.LOGICAL_NA; - } - } - return result; - } - - private byte processArgument(Object argValue, int index, boolean profiledNaRm) { - byte result = RRuntime.LOGICAL_FALSE; - if (argValue != RNull.instance) { - if (castLogicalNode[index] == null) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - castLogicalNode[index] = insert(CastLogicalNodeGen.create(true, false, false)); - } - Object castValue = castLogicalNode[index].execute(argValue); - if (castValue instanceof RAbstractLogicalVector) { - RAbstractLogicalVector vector = (RAbstractLogicalVector) castValue; - naCheck.enable(vector); - for (int i = 0; i < vector.getLength(); i++) { - byte b = vector.getDataAt(i); - if (!profiledNaRm && naCheck.check(b)) { - result = RRuntime.LOGICAL_NA; - } else if (b == RRuntime.LOGICAL_TRUE) { - trueBranch.enter(); - return RRuntime.LOGICAL_TRUE; - } - } - } else { - byte b = (byte) castValue; - naCheck.enable(true); - if (!profiledNaRm && naCheck.check(b)) { - result = RRuntime.LOGICAL_NA; - } else if (b == RRuntime.LOGICAL_TRUE) { - trueBranch.enter(); - return RRuntime.LOGICAL_TRUE; - } - } - } - falseBranch.enter(); - return result; - } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Assign.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Assign.java index f0db2b54703a95e4e9f0ed6e19fd5af7cbd31acb..1af8e0ba9aa15ae52e70af657e5b4e8f90e20ea0 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Assign.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Assign.java @@ -42,6 +42,7 @@ import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; import com.oracle.truffle.r.runtime.env.REnvironment; import com.oracle.truffle.r.runtime.env.REnvironment.PutException; +import com.oracle.truffle.r.runtime.nodes.RBaseNode; /** * The {@code assign} builtin. There are two special cases worth optimizing: @@ -58,6 +59,19 @@ public abstract class Assign extends RBuiltinNode { private final BranchProfile errorProfile = BranchProfile.create(); private final BranchProfile warningProfile = BranchProfile.create(); + private final boolean direct; + + protected Assign() { + this(false); + } + + protected Assign(boolean direct) { + this.direct = direct; + } + + private RBaseNode errorContext() { + return direct ? this : RError.SHOW_CALLER; + } /** * TODO: This method becomes obsolete when Assign and AssignFastPaths are modified to have the @@ -69,10 +83,10 @@ public abstract class Assign extends RBuiltinNode { return xVec.getDataAt(0); } else if (len == 0) { errorProfile.enter(); - throw RError.error(this, RError.Message.INVALID_FIRST_ARGUMENT); + throw RError.error(errorContext(), RError.Message.INVALID_FIRST_ARGUMENT); } else { warningProfile.enter(); - RError.warning(this, RError.Message.ONLY_FIRST_VARIABLE_NAME); + RError.warning(errorContext(), RError.Message.ONLY_FIRST_VARIABLE_NAME); return xVec.getDataAt(0); } } @@ -92,7 +106,7 @@ public abstract class Assign extends RBuiltinNode { * The general case that requires searching the environment hierarchy. */ @Specialization - protected Object assignInherit(RAbstractStringVector xVec, Object value, REnvironment envir, byte inherits, // + protected Object assign(RAbstractStringVector xVec, Object value, REnvironment envir, byte inherits, // @Cached("createBinaryProfile()") ConditionProfile inheritsProfile) { String x = checkVariable(xVec); REnvironment env = envir; @@ -112,14 +126,14 @@ public abstract class Assign extends RBuiltinNode { } if (env == REnvironment.emptyEnv()) { errorProfile.enter(); - throw RError.error(this, RError.Message.CANNOT_ASSIGN_IN_EMPTY_ENV); + throw RError.error(errorContext(), RError.Message.CANNOT_ASSIGN_IN_EMPTY_ENV); } } try { env.put(x, value); } catch (PutException ex) { errorProfile.enter(); - throw RError.error(this, ex); + throw RError.error(errorContext(), ex); } return value; } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BaseGammaFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BaseGammaFunctions.java index 9c39c508526239c6362bd5a201b28acca420f4e5..adb566aeda9e73250d7a5488c51475279161c901 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BaseGammaFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BaseGammaFunctions.java @@ -19,6 +19,8 @@ import static com.oracle.truffle.r.library.stats.StatsUtil.DBL_MIN_EXP; import static com.oracle.truffle.r.library.stats.StatsUtil.M_LOG10_2; import static com.oracle.truffle.r.library.stats.StatsUtil.M_PI; import static com.oracle.truffle.r.library.stats.StatsUtil.fmax2; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.complexValue; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.numericValue; import static com.oracle.truffle.r.runtime.RDispatch.MATH_GROUP_GENERIC; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; @@ -26,11 +28,11 @@ import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; -import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.NodeChild; import com.oracle.truffle.api.dsl.NodeChildren; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.r.library.stats.GammaFunctions; +import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.nodes.builtin.base.BaseGammaFunctionsFactory.DpsiFnCalcNodeGen; import com.oracle.truffle.r.runtime.RError; @@ -39,7 +41,6 @@ import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.data.RDataFactory; import com.oracle.truffle.r.runtime.data.RDoubleVector; import com.oracle.truffle.r.runtime.data.closures.RClosures; -import com.oracle.truffle.r.runtime.data.model.RAbstractComplexVector; import com.oracle.truffle.r.runtime.data.model.RAbstractDoubleVector; import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector; import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector; @@ -71,6 +72,11 @@ public class BaseGammaFunctions { private final NACheck naValCheck = NACheck.create(); + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("x").mustBe(complexValue().not(), RError.Message.UNIMPLEMENTED_COMPLEX_FUN).mustBe(numericValue(), RError.Message.NON_NUMERIC_MATH).asDoubleVector(); + } + @Specialization protected RDoubleVector lgamma(RAbstractDoubleVector x) { naValCheck.enable(true); @@ -93,17 +99,6 @@ public class BaseGammaFunctions { return lgamma(RClosures.createLogicalToDoubleVector(x)); } - @Specialization - @TruffleBoundary - protected Object lgamma(@SuppressWarnings("unused") RAbstractComplexVector x) { - return RError.error(this, RError.Message.UNIMPLEMENTED_COMPLEX_FUN); - } - - @Fallback - @TruffleBoundary - protected Object lgamma(@SuppressWarnings("unused") Object x) { - throw RError.error(this, RError.Message.NON_NUMERIC_MATH); - } } @RBuiltin(name = "digamma", kind = PRIMITIVE, parameterNames = {"x"}, dispatch = MATH_GROUP_GENERIC, behavior = PURE) @@ -121,6 +116,11 @@ public class BaseGammaFunctions { return dpsiFnCalc.executeDouble(x, n, kode, ans); } + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("x").mustBe(complexValue().not(), RError.Message.UNIMPLEMENTED_COMPLEX_FUN).mustBe(numericValue(), RError.Message.NON_NUMERIC_MATH).asDoubleVector(); + } + @Specialization protected RDoubleVector digamma(RAbstractDoubleVector x) { naValCheck.enable(x); @@ -156,17 +156,6 @@ public class BaseGammaFunctions { return digamma(RClosures.createLogicalToDoubleVector(x)); } - @Specialization - @TruffleBoundary - protected Object digamma(@SuppressWarnings("unused") RAbstractComplexVector x) { - return RError.error(this, RError.Message.UNIMPLEMENTED_COMPLEX_FUN); - } - - @Fallback - @TruffleBoundary - protected Object digamma(@SuppressWarnings("unused") Object x) { - throw RError.error(this, RError.Message.NON_NUMERIC_MATH); - } } @NodeChildren({@NodeChild(value = "x"), @NodeChild(value = "n"), @NodeChild(value = "kode"), @NodeChild(value = "ans")}) diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Bind.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Bind.java index 7f2684dfb933ae557ceb560e6dead4f45196733b..e13c710b22d8d160e1f58bb545f3a787f3417087 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Bind.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Bind.java @@ -396,7 +396,7 @@ public abstract class Bind extends RBaseNode { @Override protected void createCasts(CastBuilder casts) { - casts.arg("deparse.level").asIntegerVector().findFirst(); + casts.arg("deparse.level").asIntegerVector().findFirst(0); } private int precedence(Object[] args) { @@ -514,7 +514,7 @@ public abstract class Bind extends RBaseNode { @Override protected void createCasts(CastBuilder casts) { - casts.arg("deparse.level").asIntegerVector().findFirst(); + casts.arg("deparse.level").asIntegerVector().findFirst(0); } private int precedence(Object[] args) { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BitwiseFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BitwiseFunctions.java index 2661b83fdd58b015a5f6e1a1757614aa112ffd72..32a6af18214ee275174a356d2d4623277d5cadd1 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BitwiseFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BitwiseFunctions.java @@ -11,25 +11,27 @@ package com.oracle.truffle.r.nodes.builtin.base; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.*; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; +import java.util.function.Function; + +import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.profiles.BranchProfile; import com.oracle.truffle.api.profiles.LoopConditionProfile; -import com.oracle.truffle.r.nodes.binary.CastTypeNode; -import com.oracle.truffle.r.nodes.binary.CastTypeNodeGen; +import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.nodes.unary.TypeofNode; import com.oracle.truffle.r.nodes.unary.TypeofNodeGen; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RInternalError; import com.oracle.truffle.r.runtime.RRuntime; -import com.oracle.truffle.r.runtime.RType; import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.data.RDataFactory; -import com.oracle.truffle.r.runtime.data.model.RAbstractDoubleVector; +import com.oracle.truffle.r.runtime.data.RNull; import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector; +import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; import com.oracle.truffle.r.runtime.data.model.RAbstractVector; import com.oracle.truffle.r.runtime.ops.na.NACheck; @@ -37,13 +39,10 @@ public class BitwiseFunctions { public abstract static class BasicBitwise extends RBuiltinNode { - private final BranchProfile errorProfile = BranchProfile.create(); private final NACheck naCheckA = NACheck.create(); private final NACheck naCheckB = NACheck.create(); private final LoopConditionProfile loopProfile = LoopConditionProfile.createCountingProfile(); - @Child private CastTypeNode castTypeA = CastTypeNodeGen.create(null, null); - @Child private CastTypeNode castTypeB = CastTypeNodeGen.create(null, null); @Child private TypeofNode typeofA = TypeofNodeGen.create(); @Child private TypeofNode typeofB = TypeofNodeGen.create(); @@ -62,10 +61,7 @@ public class BitwiseFunctions { } } - protected Object basicBit(RAbstractVector a, RAbstractVector b, Operation op) { - checkBasicBit(a, b, op); - RAbstractIntVector aVec = (RAbstractIntVector) castTypeA.execute(a, RType.Integer); - RAbstractIntVector bVec = (RAbstractIntVector) castTypeB.execute(b, RType.Integer); + protected Object basicBit(RAbstractIntVector aVec, RAbstractIntVector bVec, Operation op) { naCheckA.enable(aVec); naCheckB.enable(bVec); int aLen = aVec.getLength(); @@ -119,8 +115,7 @@ public class BitwiseFunctions { return RDataFactory.createIntVector(ans, completeVector); } - protected Object bitNot(RAbstractVector a) { - RAbstractIntVector aVec = (RAbstractIntVector) castTypeA.execute(a, RType.Integer); + protected Object bitNot(RAbstractIntVector aVec) { int[] ans = new int[aVec.getLength()]; for (int i = 0; i < aVec.getLength(); i++) { ans[i] = ~aVec.getDataAt(i); @@ -136,107 +131,144 @@ public class BitwiseFunctions { return RDataFactory.createIntVector(na, RDataFactory.INCOMPLETE_VECTOR); } - protected void checkBasicBit(RAbstractVector a, RAbstractVector b, Operation op) { - hasSameTypes(a, b); - hasSupportedType(a, op); - } - - protected void checkShiftOrNot(RAbstractVector a, Operation op) { - hasSupportedType(a, op); - } - - protected void hasSameTypes(RAbstractVector a, RAbstractVector b) { - RType aType = typeofA.execute(a); - RType bType = typeofB.execute(b); - boolean aCorrectType = (aType == RType.Integer || aType == RType.Double) ? true : false; - boolean bCorrectType = (bType == RType.Integer || bType == RType.Double) ? true : false; - if ((aCorrectType && bCorrectType) || aType == bType) { - return; - } else { - errorProfile.enter(); - throw RError.error(this, RError.Message.SAME_TYPE, "a", "b"); - } - } - - protected void hasSupportedType(RAbstractVector a, Operation op) { - if (!(a instanceof RAbstractIntVector) && !(a instanceof RAbstractDoubleVector)) { - errorProfile.enter(); - String type = typeofA.execute(a).getName(); - throw RError.error(this, RError.Message.UNIMPLEMENTED_TYPE_IN_FUNCTION, type, op.name); - } + protected Function<Object, String> getArgType() { + return x -> typeofA.execute(x).getName(); } - protected boolean shiftByCharacter(RAbstractVector n) { - return typeofB.execute(n) == RType.Character; - } } @RBuiltin(name = "bitwiseAnd", kind = INTERNAL, parameterNames = {"a", "b"}, behavior = PURE) public abstract static class BitwiseAnd extends BasicBitwise { + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("a").mustBe(doubleValue().or(integerValue()), RError.Message.UNIMPLEMENTED_TYPE_IN_FUNCTION, getArgType(), Operation.AND.name).asIntegerVector(); + casts.arg("b").mustBe(doubleValue().or(integerValue()), RError.Message.UNIMPLEMENTED_TYPE_IN_FUNCTION, getArgType(), Operation.AND.name).asIntegerVector(); + } + @Specialization - protected Object bitwAnd(RAbstractVector a, RAbstractVector b) { + protected Object bitwAnd(RAbstractIntVector a, RAbstractIntVector b) { return basicBit(a, b, Operation.AND); } + + @Fallback + @SuppressWarnings("unused") + protected Object differentTypes(Object a, Object b) { + throw RError.error(this, RError.Message.SAME_TYPE, "a", "b"); + } + } @RBuiltin(name = "bitwiseOr", kind = INTERNAL, parameterNames = {"a", "b"}, behavior = PURE) public abstract static class BitwiseOr extends BasicBitwise { + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("a").mustBe(doubleValue().or(integerValue()), RError.Message.UNIMPLEMENTED_TYPE_IN_FUNCTION, getArgType(), Operation.OR.name).asIntegerVector(); + casts.arg("b").mustBe(doubleValue().or(integerValue()), RError.Message.UNIMPLEMENTED_TYPE_IN_FUNCTION, getArgType(), Operation.OR.name).asIntegerVector(); + } + @Specialization - protected Object bitwOr(RAbstractVector a, RAbstractVector b) { + protected Object bitwOr(RAbstractIntVector a, RAbstractIntVector b) { return basicBit(a, b, Operation.OR); } + + @Fallback + @SuppressWarnings("unused") + protected Object differentTypes(Object a, Object b) { + throw RError.error(this, RError.Message.SAME_TYPE, "a", "b"); + } } @RBuiltin(name = "bitwiseXor", kind = INTERNAL, parameterNames = {"a", "b"}, behavior = PURE) public abstract static class BitwiseXor extends BasicBitwise { + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("a").mustBe(doubleValue().or(integerValue()), RError.Message.UNIMPLEMENTED_TYPE_IN_FUNCTION, getArgType(), Operation.XOR.name).asIntegerVector(); + casts.arg("b").mustBe(doubleValue().or(integerValue()), RError.Message.UNIMPLEMENTED_TYPE_IN_FUNCTION, getArgType(), Operation.XOR.name).asIntegerVector(); + } + @Specialization - protected Object bitwXor(RAbstractVector a, RAbstractVector b) { + protected Object bitwXor(RAbstractIntVector a, RAbstractIntVector b) { return basicBit(a, b, Operation.XOR); } + + @Fallback + @SuppressWarnings("unused") + protected Object differentTypes(Object a, Object b) { + throw RError.error(this, RError.Message.SAME_TYPE, "a", "b"); + } } @RBuiltin(name = "bitwiseShiftR", kind = INTERNAL, parameterNames = {"a", "n"}, behavior = PURE) public abstract static class BitwiseShiftR extends BasicBitwise { - @Specialization(guards = {"!shiftByCharacter(n)"}) - protected Object bitwShiftR(RAbstractVector a, RAbstractVector n) { + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("a").mustBe(doubleValue().or(integerValue()), RError.Message.UNIMPLEMENTED_TYPE_IN_FUNCTION, getArgType(), Operation.SHIFTR.name).asIntegerVector(); + casts.arg("n").mapIf(stringValue(), asStringVector(), asIntegerVector()); + } + + @Specialization + protected Object bitwShiftR(RAbstractIntVector a, RAbstractIntVector n) { return basicBit(a, n, Operation.SHIFTR); } - @Specialization(guards = {"shiftByCharacter(n)"}) + @Specialization + @SuppressWarnings("unused") + protected Object bitwShiftR(RAbstractIntVector a, RNull n) { + return RDataFactory.createEmptyIntVector(); + } + + @Specialization @SuppressWarnings("unused") - protected Object bitwShiftRChar(RAbstractVector a, RAbstractVector n) { - checkShiftOrNot(a, Operation.SHIFTR); + protected Object bitwShiftRChar(RAbstractIntVector a, RAbstractStringVector n) { return makeNA(a.getLength()); } + } @RBuiltin(name = "bitwiseShiftL", kind = INTERNAL, parameterNames = {"a", "n"}, behavior = PURE) public abstract static class BitwiseShiftL extends BasicBitwise { - @Specialization(guards = {"!shiftByCharacter(n)"}) - protected Object bitwShiftR(RAbstractVector a, RAbstractVector n) { + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("a").mustBe(doubleValue().or(integerValue()), RError.ROOTNODE, RError.Message.UNIMPLEMENTED_TYPE_IN_FUNCTION, getArgType(), Operation.SHIFTL.name).asIntegerVector(); + casts.arg("n").mapIf(stringValue(), chain(asStringVector()).with(shouldBe(anyValue().not(), RError.SHOW_CALLER, false, RError.Message.NA_INTRODUCED_COERCION)).end(), asIntegerVector()); + } + + @Specialization + protected Object bitwShiftL(RAbstractIntVector a, RAbstractIntVector n) { return basicBit(a, n, Operation.SHIFTL); } - @Specialization(guards = {"shiftByCharacter(n)"}) + @Specialization @SuppressWarnings("unused") - protected Object bitwShiftRChar(RAbstractVector a, RAbstractVector n) { - checkShiftOrNot(a, Operation.SHIFTL); + protected Object bitwShiftL(RAbstractIntVector a, RNull n) { + return RDataFactory.createEmptyIntVector(); + } + + @Specialization + @SuppressWarnings("unused") + protected Object bitwShiftLChar(RAbstractVector a, RAbstractStringVector n) { return makeNA(a.getLength()); } + } @RBuiltin(name = "bitwiseNot", kind = INTERNAL, parameterNames = {"a"}, behavior = PURE) public abstract static class BitwiseNot extends BasicBitwise { + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("a").mustBe(doubleValue().or(integerValue()), RError.Message.UNIMPLEMENTED_TYPE_IN_FUNCTION, getArgType(), Operation.NOT.name).asIntegerVector(); + } + @Specialization - protected Object bitwNot(RAbstractVector a) { - checkShiftOrNot(a, Operation.NOT); + protected Object bitwNot(RAbstractIntVector a) { return bitNot(a); } + } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BrowserFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BrowserFunctions.java index 075aeb715f6b20b4703c40294f2ac2c18ea058e5..8909bff42e888192b915661115b3544a08e45672 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BrowserFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BrowserFunctions.java @@ -63,8 +63,8 @@ public class BrowserFunctions { protected void createCasts(CastBuilder casts) { // TODO: add support for conditions conditions casts.arg("condition").mustBe(nullValue(), RError.Message.GENERIC, "Only NULL conditions currently supported in browser"); - casts.arg("expr").asLogicalVector().findFirst().map(toBoolean()); - casts.arg("skipCalls").asIntegerVector().findFirst(); + casts.arg("expr").asLogicalVector().findFirst(RRuntime.LOGICAL_FALSE).map(toBoolean()); + casts.arg("skipCalls").asIntegerVector().findFirst(0); } @SuppressWarnings("unused") @@ -103,7 +103,7 @@ public class BrowserFunctions { @Override protected void createCasts(CastBuilder casts) { - casts.arg("n").asIntegerVector().findFirst().mustBe(gt(0), Message.POSITIVE_CONTEXTS); + casts.arg("n").asIntegerVector().findFirst(0).mustBe(gt(0), Message.POSITIVE_CONTEXTS); } /** diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Cat.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Cat.java index 820ebe68374842f7955c7060ed0fea3dffdbd603..6441f318336fdcd7c3cec5a646d2878ee05a6ad4 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Cat.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Cat.java @@ -27,9 +27,9 @@ import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.asInteger; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.defaultValue; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.gt0; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.instanceOf; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.logicalValue; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.nullValue; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.numericValue; -import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.scalarLogicalValue; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.singleElement; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.stringValue; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.toBoolean; @@ -80,7 +80,7 @@ public abstract class Cat extends RBuiltinNode { casts.arg("sep").mustBe(stringValue(), RError.Message.INVALID_SEP); casts.arg("fill").mustBe(numericValue()).asVector().mustBe(singleElement()).findFirst().mustBe(nullValue().not()).shouldBe(instanceOf(Byte.class).or(instanceOf(Integer.class).and(gt0())), - Message.NON_POSITIVE_FILL).mapIf(scalarLogicalValue(), asBoolean(), asInteger()); + Message.NON_POSITIVE_FILL).mapIf(logicalValue(), asBoolean(), asInteger()); casts.arg("labels").map(defaultValue(RDataFactory.createStringVector(0))).mustBe(stringValue()).asStringVector(); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Choose.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Choose.java index 10c97ffae1341a1bb1d21a740161976e0e7d5641..8550d93fb754556db7da34fc1b88871171a66b9b 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Choose.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Choose.java @@ -53,7 +53,7 @@ public abstract class Choose extends RBuiltinNode { private final NACheck na = NACheck.create(); @Override - protected void createCasts(@SuppressWarnings("unused") CastBuilder casts) { + protected void createCasts(CastBuilder casts) { casts.arg("n").mustBe(numericValue(), RError.SHOW_CALLER, Message.NON_NUMERIC_MATH).mapIf(logicalValue(), asIntegerVector()); casts.arg("k").mustBe(numericValue(), RError.SHOW_CALLER, Message.NON_NUMERIC_MATH).mapIf(logicalValue(), asIntegerVector()); } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CompilePKGS.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CompilePKGS.java index b9c7803a55416402196ffc8dc9a18124a0e21790..c8839005d1ad0e8282a8843bd7b3d63f38c5e6bd 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CompilePKGS.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CompilePKGS.java @@ -38,7 +38,7 @@ public abstract class CompilePKGS extends RBuiltinNode { @Override protected void createCasts(CastBuilder casts) { - casts.arg("enable").asIntegerVector().findFirst(); + casts.arg("enable").asIntegerVector().findFirst(0); } @Specialization diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ConnectionFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ConnectionFunctions.java index 28fd1e0032f707972b68dc481269d8c0208723fe..f8874611fb802b6b6ff3752e363234c4a9952960 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ConnectionFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ConnectionFunctions.java @@ -303,7 +303,7 @@ public abstract class ConnectionFunctions { @Override protected void createCasts(CastBuilder casts) { - casts.arg("host").mustBe(scalarStringValue()); + casts.arg("host").mustBe(stringValue()).asStringVector().findFirst(); casts.arg("port").asIntegerVector().findFirst().notNA().mustBe(gte(0)); casts.arg("server").asLogicalVector().findFirst().notNA().map(toBoolean()); Casts.open(casts); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Crossprod.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Crossprod.java index bd48e8980243abb1d75214c3cc5b599653657019..45c06fb0744976a153d2169e18108c22aa38914e 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Crossprod.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Crossprod.java @@ -22,12 +22,15 @@ */ package com.oracle.truffle.r.nodes.builtin.base; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.*; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; +import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.data.RDoubleVector; import com.oracle.truffle.r.runtime.data.RNull; @@ -37,18 +40,16 @@ import com.oracle.truffle.r.runtime.data.model.RAbstractVector; @RBuiltin(name = "crossprod", kind = INTERNAL, parameterNames = {"x", "y"}, behavior = PURE) public abstract class Crossprod extends RBuiltinNode { - @Child private MatMult matMult; + @Child private MatMult matMult = MatMultNodeGen.create(/* promoteDimNames: */ false, null); @Child private Transpose transpose; - private void ensureMatMult() { - if (matMult == null) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - matMult = insert(MatMultNodeGen.create(/* promoteDimNames: */ false, null)); - } + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("x").mustBe(numericValue().or(complexValue()), RError.ROOTNODE, RError.Message.NUMERIC_COMPLEX_MATRIX_VECTOR); + casts.arg("y").mustBe(nullValue().or(numericValue()).or(complexValue()), RError.ROOTNODE, RError.Message.NUMERIC_COMPLEX_MATRIX_VECTOR); } private Object matMult(Object op1, Object op2) { - ensureMatMult(); return matMult.executeObject(op1, op2); } @@ -60,9 +61,8 @@ public abstract class Crossprod extends RBuiltinNode { return transpose.execute(value); } - @Specialization(guards = {"isMatrix(x)", "isMatrix(y)"}) + @Specialization(guards = {"x.isMatrix()", "y.isMatrix()"}) protected RDoubleVector crossprod(RAbstractDoubleVector x, RAbstractDoubleVector y) { - ensureMatMult(); int xRows = x.getDimensions()[0]; int xCols = x.getDimensions()[1]; int yRows = y.getDimensions()[0]; @@ -95,9 +95,8 @@ public abstract class Crossprod extends RBuiltinNode { return matMult(transpose(x), y); } - @Specialization(guards = "isMatrix(x)") - protected Object crossprodDoubleMatrix(RAbstractDoubleVector x, @SuppressWarnings("unused") RNull y) { - ensureMatMult(); + @Specialization(guards = "x.isMatrix()") + protected RDoubleVector crossprodDoubleMatrix(RAbstractDoubleVector x, @SuppressWarnings("unused") RNull y) { int xRows = x.getDimensions()[0]; int xCols = x.getDimensions()[1]; return mirror(matMult.doubleMatrixMultiply(x, x, xCols, xRows, xRows, xCols, xRows, 1, 1, xRows, true)); @@ -107,8 +106,4 @@ public abstract class Crossprod extends RBuiltinNode { protected Object crossprod(RAbstractVector x, @SuppressWarnings("unused") RNull y) { return matMult(transpose(x), x); } - - protected static boolean isMatrix(RAbstractVector v) { - return v.isMatrix(); - } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CumMax.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CumMax.java index b7782c6d00e951bd5cae5355e3987c012a2748dc..872c30682870f76dfe1809bae6033b5a2ca4b094 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CumMax.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CumMax.java @@ -10,34 +10,33 @@ */ package com.oracle.truffle.r.nodes.builtin.base; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.asDoubleVector; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.asIntegerVector; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.complexValue; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.integerValue; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.logicalValue; import static com.oracle.truffle.r.runtime.RDispatch.MATH_GROUP_GENERIC; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; import java.util.Arrays; -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.profiles.ConditionProfile; +import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; -import com.oracle.truffle.r.nodes.unary.CastDoubleNode; -import com.oracle.truffle.r.nodes.unary.CastDoubleNodeGen; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.data.RAttributeProfiles; -import com.oracle.truffle.r.runtime.data.RComplexVector; import com.oracle.truffle.r.runtime.data.RDataFactory; import com.oracle.truffle.r.runtime.data.RDoubleVector; import com.oracle.truffle.r.runtime.data.RIntSequence; import com.oracle.truffle.r.runtime.data.RIntVector; -import com.oracle.truffle.r.runtime.data.model.RAbstractComplexVector; +import com.oracle.truffle.r.runtime.data.RNull; import com.oracle.truffle.r.runtime.data.model.RAbstractDoubleVector; import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector; -import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector; -import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; import com.oracle.truffle.r.runtime.ops.na.NACheck; @RBuiltin(name = "cummax", kind = PRIMITIVE, parameterNames = {"x"}, dispatch = MATH_GROUP_GENERIC, behavior = PURE) @@ -46,7 +45,10 @@ public abstract class CumMax extends RBuiltinNode { private final NACheck na = NACheck.create(); private final RAttributeProfiles attrProfiles = RAttributeProfiles.create(); - @Child private CastDoubleNode castDouble; + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("x").mustBe(complexValue().not(), RError.Message.CUMMAX_UNDEFINED_FOR_COMPLEX).mapIf(integerValue().or(logicalValue()), asIntegerVector(), asDoubleVector()); + } @Specialization protected double cummax(double arg) { @@ -59,17 +61,8 @@ public abstract class CumMax extends RBuiltinNode { } @Specialization - protected Object cummax(String arg) { - return na.convertStringToDouble(arg); - } - - @Specialization - protected int cummax(byte arg) { - na.enable(arg); - if (na.check(arg)) { - return RRuntime.INT_NA; - } - return arg; + protected RDoubleVector cumNull(@SuppressWarnings("unused") RNull rnull) { + return RDataFactory.createEmptyDoubleVector(); } @Specialization @@ -127,40 +120,4 @@ public abstract class CumMax extends RBuiltinNode { return RDataFactory.createIntVector(cmaxV, na.neverSeenNA(), v.getNames(attrProfiles)); } - @Specialization - protected RIntVector cummax(RAbstractLogicalVector v) { - int[] cmaxV = new int[v.getLength()]; - int max = v.getDataAt(0); - cmaxV[0] = max; - na.enable(v); - int i; - for (i = 1; i < v.getLength(); i++) { - if (v.getDataAt(i) > max) { - max = v.getDataAt(i); - } - if (na.check(v.getDataAt(i))) { - break; - } - cmaxV[i] = max; - } - if (!na.neverSeenNA()) { - Arrays.fill(cmaxV, i, cmaxV.length, RRuntime.INT_NA); - } - return RDataFactory.createIntVector(cmaxV, na.neverSeenNA(), v.getNames(attrProfiles)); - } - - @Specialization - protected RDoubleVector cummax(RAbstractStringVector v) { - if (castDouble == null) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - castDouble = insert(CastDoubleNodeGen.create(false, false, false)); - } - return cummax((RDoubleVector) castDouble.executeDouble(v)); - } - - @Specialization - @TruffleBoundary - protected RComplexVector cummax(@SuppressWarnings("unused") RAbstractComplexVector v) { - throw RError.error(this, RError.Message.CUMMAX_UNDEFINED_FOR_COMPLEX); - } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CumMin.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CumMin.java index 2750b3179beb14df90563f66649ddee6b23699f3..f0a1f1439b96b46b6e64cde014ba7948e4f6adaf 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CumMin.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CumMin.java @@ -10,34 +10,33 @@ */ package com.oracle.truffle.r.nodes.builtin.base; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.asDoubleVector; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.asIntegerVector; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.complexValue; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.integerValue; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.logicalValue; import static com.oracle.truffle.r.runtime.RDispatch.MATH_GROUP_GENERIC; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; import java.util.Arrays; -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.profiles.ConditionProfile; +import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; -import com.oracle.truffle.r.nodes.unary.CastDoubleNode; -import com.oracle.truffle.r.nodes.unary.CastDoubleNodeGen; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.data.RAttributeProfiles; -import com.oracle.truffle.r.runtime.data.RComplexVector; import com.oracle.truffle.r.runtime.data.RDataFactory; import com.oracle.truffle.r.runtime.data.RDoubleVector; import com.oracle.truffle.r.runtime.data.RIntSequence; import com.oracle.truffle.r.runtime.data.RIntVector; -import com.oracle.truffle.r.runtime.data.model.RAbstractComplexVector; +import com.oracle.truffle.r.runtime.data.RNull; import com.oracle.truffle.r.runtime.data.model.RAbstractDoubleVector; import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector; -import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector; -import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; import com.oracle.truffle.r.runtime.ops.na.NACheck; @RBuiltin(name = "cummin", kind = PRIMITIVE, parameterNames = {"x"}, dispatch = MATH_GROUP_GENERIC, behavior = PURE) @@ -46,7 +45,10 @@ public abstract class CumMin extends RBuiltinNode { private final NACheck na = NACheck.create(); private final RAttributeProfiles attrProfiles = RAttributeProfiles.create(); - @Child private CastDoubleNode castDouble; + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("x").mustBe(complexValue().not(), RError.Message.CUMMIN_UNDEFINED_FOR_COMPLEX).mapIf(integerValue().or(logicalValue()), asIntegerVector(), asDoubleVector()); + } @Specialization protected double cummin(double arg) { @@ -59,17 +61,8 @@ public abstract class CumMin extends RBuiltinNode { } @Specialization - protected int cummin(byte arg) { - na.enable(arg); - if (na.check(arg)) { - return RRuntime.INT_NA; - } - return arg; - } - - @Specialization - protected double cummin(String arg) { - return na.convertStringToDouble(arg); + protected RDoubleVector cumNull(@SuppressWarnings("unused") RNull rnull) { + return RDataFactory.createEmptyDoubleVector(); } @Specialization @@ -127,40 +120,4 @@ public abstract class CumMin extends RBuiltinNode { return RDataFactory.createIntVector(cminV, na.neverSeenNA(), v.getNames(attrProfiles)); } - @Specialization - protected RIntVector cummin(RAbstractLogicalVector v) { - int[] cminV = new int[v.getLength()]; - int min = v.getDataAt(0); - cminV[0] = min; - na.enable(v); - int i; - for (i = 1; i < v.getLength(); i++) { - if (v.getDataAt(i) < min) { - min = v.getDataAt(i); - } - if (na.check(v.getDataAt(i))) { - break; - } - cminV[i] = min; - } - if (!na.neverSeenNA()) { - Arrays.fill(cminV, i, cminV.length, RRuntime.INT_NA); - } - return RDataFactory.createIntVector(cminV, na.neverSeenNA(), v.getNames(attrProfiles)); - } - - @Specialization - protected RDoubleVector cummin(RAbstractStringVector v) { - if (castDouble == null) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - castDouble = insert(CastDoubleNodeGen.create(false, false, false)); - } - return cummin((RDoubleVector) castDouble.executeDouble(v)); - } - - @Specialization - @TruffleBoundary - protected RComplexVector cummin(@SuppressWarnings("unused") RAbstractComplexVector v) { - throw RError.error(this, RError.Message.CUMMIN_UNDEFINED_FOR_COMPLEX); - } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CumProd.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CumProd.java index 96fc9287d2681b8242bd61eea13be9be67dea076..3411fd0b41182c5fef1ec000cb22793c7694b3c9 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CumProd.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CumProd.java @@ -10,6 +10,13 @@ */ package com.oracle.truffle.r.nodes.builtin.base; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.asDoubleVector; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.asIntegerVector; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.chain; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.complexValue; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.integerValue; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.logicalValue; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.mapIf; import static com.oracle.truffle.r.runtime.RDispatch.MATH_GROUP_GENERIC; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; @@ -17,6 +24,7 @@ import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; import java.util.Arrays; import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.builtins.RBuiltin; @@ -26,11 +34,10 @@ import com.oracle.truffle.r.runtime.data.RComplexVector; import com.oracle.truffle.r.runtime.data.RDataFactory; import com.oracle.truffle.r.runtime.data.RDoubleVector; import com.oracle.truffle.r.runtime.data.RIntVector; +import com.oracle.truffle.r.runtime.data.RNull; import com.oracle.truffle.r.runtime.data.model.RAbstractComplexVector; import com.oracle.truffle.r.runtime.data.model.RAbstractDoubleVector; import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector; -import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector; -import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; import com.oracle.truffle.r.runtime.ops.BinaryArithmetic; import com.oracle.truffle.r.runtime.ops.na.NACheck; @@ -42,6 +49,11 @@ public abstract class CumProd extends RBuiltinNode { @Child private BinaryArithmetic mul = BinaryArithmetic.MULTIPLY.create(); + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("x").mapIf(integerValue().or(logicalValue()), asIntegerVector(), chain(mapIf(complexValue().not(), asDoubleVector())).end()); + } + @Specialization protected int cumprod(int arg) { return arg; @@ -53,12 +65,8 @@ public abstract class CumProd extends RBuiltinNode { } @Specialization - protected int cumprod(byte arg) { - na.enable(arg); - if (na.check(arg)) { - return RRuntime.INT_NA; - } - return arg; + protected RDoubleVector cumNull(@SuppressWarnings("unused") RNull rnull) { + return RDataFactory.createEmptyDoubleVector(); } @Specialization @@ -105,47 +113,6 @@ public abstract class CumProd extends RBuiltinNode { return RDataFactory.createDoubleVector(array, !na.neverSeenNA(), arg.getNames(attrProfiles)); } - @Specialization - protected RIntVector cumprod(RAbstractLogicalVector arg) { - int[] array = new int[arg.getLength()]; - na.enable(arg); - int prev = 1; - int i; - for (i = 0; i < arg.getLength(); i++) { - if (na.check(arg.getDataAt(i))) { - break; - } - prev = mul.op(prev, arg.getDataAt(i)); - if (na.check(prev)) { - break; - } - array[i] = prev; - } - if (!na.neverSeenNA()) { - Arrays.fill(array, i, array.length, RRuntime.INT_NA); - } - return RDataFactory.createIntVector(array, !na.neverSeenNA(), arg.getNames(attrProfiles)); - } - - @Specialization - protected RDoubleVector cumprod(RAbstractStringVector arg) { - double[] array = new double[arg.getLength()]; - na.enable(arg); - double prev = 1; - int i; - for (i = 0; i < arg.getLength(); i++) { - prev = mul.op(prev, na.convertStringToDouble(arg.getDataAt(i))); - if (na.check(arg.getDataAt(i))) { - break; - } - array[i] = prev; - } - if (!na.neverSeenNA()) { - Arrays.fill(array, i, array.length, RRuntime.DOUBLE_NA); - } - return RDataFactory.createDoubleVector(array, !na.neverSeenNA(), arg.getNames(attrProfiles)); - } - @Specialization protected RComplexVector cumprod(RAbstractComplexVector arg) { double[] array = new double[arg.getLength() * 2]; diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CumSum.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CumSum.java index 2195f2c9dd28e04248e240ab0598c90f01edabc6..40f8f3c57d18b265f2a4cdaf3db001790f36cc10 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CumSum.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CumSum.java @@ -22,6 +22,13 @@ */ package com.oracle.truffle.r.nodes.builtin.base; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.asDoubleVector; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.asIntegerVector; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.chain; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.complexValue; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.integerValue; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.logicalValue; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.mapIf; import static com.oracle.truffle.r.runtime.RDispatch.MATH_GROUP_GENERIC; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; @@ -29,6 +36,7 @@ import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; import java.util.Arrays; import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.builtins.RBuiltin; @@ -39,11 +47,10 @@ import com.oracle.truffle.r.runtime.data.RDataFactory; import com.oracle.truffle.r.runtime.data.RDoubleVector; import com.oracle.truffle.r.runtime.data.RIntSequence; import com.oracle.truffle.r.runtime.data.RIntVector; +import com.oracle.truffle.r.runtime.data.RNull; import com.oracle.truffle.r.runtime.data.model.RAbstractComplexVector; import com.oracle.truffle.r.runtime.data.model.RAbstractDoubleVector; import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector; -import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector; -import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; import com.oracle.truffle.r.runtime.ops.BinaryArithmetic; import com.oracle.truffle.r.runtime.ops.na.NACheck; @@ -55,6 +62,11 @@ public abstract class CumSum extends RBuiltinNode { @Child private BinaryArithmetic add = BinaryArithmetic.ADD.create(); + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("x").mapIf(integerValue().or(logicalValue()), asIntegerVector(), chain(mapIf(complexValue().not(), asDoubleVector())).end()); + } + @Specialization protected double cumsum(double arg) { return arg; @@ -66,12 +78,8 @@ public abstract class CumSum extends RBuiltinNode { } @Specialization - protected int cumsum(byte arg) { - na.enable(arg); - if (na.check(arg)) { - return RRuntime.INT_NA; - } - return arg; + protected RDoubleVector cumNull(@SuppressWarnings("unused") RNull rnull) { + return RDataFactory.createEmptyDoubleVector(); } @Specialization @@ -136,45 +144,6 @@ public abstract class CumSum extends RBuiltinNode { return RDataFactory.createIntVector(res, na.neverSeenNA(), arg.getNames(attrProfiles)); } - @Specialization - protected RIntVector cumsum(RAbstractLogicalVector arg) { - int[] res = new int[arg.getLength()]; - int prev = 0; - int i; - na.enable(true); - for (i = 0; i < arg.getLength(); i++) { - prev = add.op(prev, arg.getDataAt(i)); - if (na.check(arg.getDataAt(i))) { - break; - } - res[i] = prev; - } - if (!na.neverSeenNA()) { - Arrays.fill(res, i, res.length, RRuntime.INT_NA); - } - return RDataFactory.createIntVector(res, na.neverSeenNA(), arg.getNames(attrProfiles)); - } - - @Specialization - protected RDoubleVector cumsum(RAbstractStringVector arg) { - double[] res = new double[arg.getLength()]; - double prev = 0.0; - na.enable(true); - int i; - for (i = 0; i < arg.getLength(); i++) { - double value = na.convertStringToDouble(arg.getDataAt(i)); - prev = add.op(prev, value); - if (na.check(arg.getDataAt(i))) { - break; - } - res[i] = prev; - } - if (!na.neverSeenNA()) { - Arrays.fill(res, i, res.length, RRuntime.DOUBLE_NA); - } - return RDataFactory.createDoubleVector(res, na.neverSeenNA(), arg.getNames(attrProfiles)); - } - @Specialization protected RComplexVector cumsum(RAbstractComplexVector arg) { double[] res = new double[arg.getLength() * 2]; diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/DuplicatedFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/DuplicatedFunctions.java index 8e2b60251006dc758d19cd5ff7ef30c96a181261..03d2eb7c7da92316ad144a9ec3957f4da0245805 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/DuplicatedFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/DuplicatedFunctions.java @@ -48,7 +48,7 @@ public class DuplicatedFunctions { protected void casts(CastBuilder casts) { casts.arg("x").mustBe(nullValue().or(abstractVectorValue()), RError.SHOW_CALLER, RError.Message.GENERIC, "duplicated() applies only to vectors").asVector(); - casts.arg("fromLast").asLogicalVector().findFirst(); + casts.arg("fromLast").asLogicalVector().findFirst(RRuntime.LOGICAL_FALSE); } protected boolean isIncomparable(RAbstractVector incomparables) { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Exists.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Exists.java index 7da0608fe22dba6faab19da2b12cf42ea5de880c..e70b055c123b0f7e907fa223ab80bec3434eba1b 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Exists.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Exists.java @@ -53,7 +53,7 @@ public abstract class Exists extends RBuiltinNode { public abstract byte execute(String nameVec, REnvironment env, String mode, boolean inherits); @Override - protected void createCasts(@SuppressWarnings("unused") CastBuilder casts) { + protected void createCasts(CastBuilder casts) { casts.arg("x").mustBe(stringValue(), Message.INVALID_FIRST_ARGUMENT).asStringVector().findFirst(); casts.arg("envir").mustBe(REnvironment.class); casts.arg("mode").mustBe(stringValue()).asStringVector().findFirst(); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Formals.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Formals.java index d333030a981313d1e74458f4616ddab525d7b9fc..13749fcbc3c370ec9bc8d607a079f77c1ce63b23 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Formals.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Formals.java @@ -57,7 +57,7 @@ public abstract class Formals extends RBuiltinNode { } @Fallback - protected Object formals(Object fun) { + protected Object formals(@SuppressWarnings("unused") Object fun) { // for anything that is not a function, GnuR returns NULL return RNull.instance; } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/FrameFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/FrameFunctions.java index 536f8770b038b4a5e88d2773beb52453365b056f..babd9d29b4aa7da41a451f38fe8ccfbf20557341 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/FrameFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/FrameFunctions.java @@ -75,7 +75,6 @@ import com.oracle.truffle.r.runtime.data.RNull; import com.oracle.truffle.r.runtime.data.RPairList; import com.oracle.truffle.r.runtime.data.RPromise; import com.oracle.truffle.r.runtime.data.RPromise.Closure; -import com.oracle.truffle.r.runtime.data.RSymbol; import com.oracle.truffle.r.runtime.env.REnvironment; import com.oracle.truffle.r.runtime.gnur.SEXPTYPE; import com.oracle.truffle.r.runtime.nodes.RNode; @@ -339,12 +338,6 @@ public class FrameFunctions { return false; } - private static RSymbol createVarArgSymbol(VarArgNode varArgNode) { - CompilerAsserts.neverPartOfCompilation(); // for string concatenation and interning - String varArgSymbol = createVarArgName(varArgNode); - return RDataFactory.createSymbolInterned(varArgSymbol); - } - private static String createVarArgName(VarArgNode varArgNode) { CompilerAsserts.neverPartOfCompilation(); // for string concatenation and interning int vn = varArgNode.getIndex() + 1; diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GetFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GetFunctions.java index 19d0acc4b7f43f8d331e226fccf24349f207d157..1898de31ae2fd9d3eda061feeecdc2c30566c106 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GetFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GetFunctions.java @@ -65,7 +65,6 @@ import com.oracle.truffle.r.runtime.data.RPromise; import com.oracle.truffle.r.runtime.data.RS4Object; import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; import com.oracle.truffle.r.runtime.env.REnvironment; -import com.oracle.truffle.r.runtime.env.REnvironment.Function; /** * assert: not expected to be fast even when called as, e.g., {@code get("x")}. @@ -78,21 +77,24 @@ public class GetFunctions { @Child private PromiseHelperNode promiseHelper = new PromiseHelperNode(); @Child protected TypeFromModeNode typeFromMode = TypeFromModeNodeGen.create(); + @CompilationFinal private boolean firstExecution = true; + public abstract Object execute(VirtualFrame frame, Object name, REnvironment envir, String mode, byte inherits); protected void unknownObject(String x, RType modeType, String modeString) throws RError { unknownObjectErrorProfile.enter(); if (modeType == RType.Any) { - throw RError.error(this, RError.Message.UNKNOWN_OBJECT, x); + throw RError.error(RError.SHOW_CALLER, RError.Message.UNKNOWN_OBJECT, x); } else { - throw RError.error(this, RError.Message.UNKNOWN_OBJECT_MODE, x, modeType == null ? modeString : modeType.getName()); + throw RError.error(RError.SHOW_CALLER, RError.Message.UNKNOWN_OBJECT_MODE, x, modeType == null ? modeString : modeType.getName()); } } - protected Object checkPromise(VirtualFrame frame, Object r, String identifier, boolean evaluateOnSlowPath) { + protected Object checkPromise(VirtualFrame frame, Object r, String identifier) { if (r instanceof RPromise) { - if (evaluateOnSlowPath) { - CompilerDirectives.transferToInterpreter(); + if (firstExecution) { + CompilerDirectives.transferToInterpreterAndInvalidate(); + firstExecution = false; return ReadVariableNode.evalPromiseSlowPathWithName(identifier, frame, (RPromise) r); } return promiseHelper.evaluate(frame, (RPromise) r); @@ -107,7 +109,7 @@ public class GetFunctions { protected Object getAndCheck(VirtualFrame frame, RAbstractStringVector xv, REnvironment env, RType modeType, boolean fail) throws RError { String x = xv.getDataAt(0); - Object obj = checkPromise(frame, env.get(x), x, !(env instanceof Function)); + Object obj = checkPromise(frame, env.get(x), x); if (obj != null && RRuntime.checkType(obj, modeType)) { return obj; } else { @@ -128,7 +130,7 @@ public class GetFunctions { while (env != REnvironment.emptyEnv()) { env = env.getParent(); if (env != REnvironment.emptyEnv()) { - r = checkPromise(frame, env.get(x), x, !(env instanceof Function)); + r = checkPromise(frame, env.get(x), x); if (r != null && RRuntime.checkType(r, modeType)) { break; } @@ -282,7 +284,7 @@ public class GetFunctions { String x = state.checkNA(xv.getDataAt(i)); state.names[i] = x; RType modeType = typeFromMode.execute(mode.getDataAt(state.modeLength == 1 ? 0 : i)); - Object r = checkPromise(frame, env.get(x), x, !(env instanceof Function)); + Object r = checkPromise(frame, env.get(x), x); if (r != null && RRuntime.checkType(r, modeType)) { state.data[i] = r; } else { @@ -306,7 +308,7 @@ public class GetFunctions { while (env != REnvironment.emptyEnv()) { env = env.getParent(); if (env != REnvironment.emptyEnv()) { - r = checkPromise(frame, env.get(x), x, !(env instanceof Function)); + r = checkPromise(frame, env.get(x), x); if (r != null && RRuntime.checkType(r, modeType)) { break; } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GrepFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GrepFunctions.java index 6dfe4964c2fa2b08ee628edf23f8be899333289c..fd868f0d0d96cfaf558de82a801429364cef12bc 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GrepFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GrepFunctions.java @@ -78,11 +78,11 @@ public class GrepFunctions { } protected void castIgnoreCase(CastBuilder casts) { - casts.arg("ignore.case").asLogicalVector().findFirst(); + casts.arg("ignore.case").asLogicalVector().findFirst(RRuntime.LOGICAL_FALSE); } protected void castPerl(CastBuilder casts) { - casts.arg("perl").asLogicalVector().findFirst(); + casts.arg("perl").asLogicalVector().findFirst(RRuntime.LOGICAL_FALSE); } protected void castFixed(CastBuilder casts, byte defaultValue) { @@ -90,15 +90,15 @@ public class GrepFunctions { } protected void castValue(CastBuilder casts) { - casts.arg("value").asLogicalVector().findFirst(); + casts.arg("value").asLogicalVector().findFirst(RRuntime.LOGICAL_FALSE); } protected void castUseBytes(CastBuilder casts) { - casts.arg("useBytes").asLogicalVector().findFirst(); + casts.arg("useBytes").asLogicalVector().findFirst(RRuntime.LOGICAL_FALSE); } protected void castInvert(CastBuilder casts) { - casts.arg("invert").asLogicalVector().findFirst(); + casts.arg("invert").asLogicalVector().findFirst(RRuntime.LOGICAL_FALSE); } protected void castCosts(CastBuilder casts) { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/HiddenInternalFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/HiddenInternalFunctions.java index 0703cc38ae5b1f7fe6f2542026ba82d621e11555..0de9b7a77ce26cbf755439f550204af27a035556 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/HiddenInternalFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/HiddenInternalFunctions.java @@ -173,7 +173,7 @@ public class HiddenInternalFunctions { try { impEnv.put(impsym, binding); } catch (PutException ex) { - throw RError.error(this, ex); + throw RError.error(RError.SHOW_CALLER, ex); } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/IConv.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/IConv.java index 3edaab6d1b5d8156c7f7b3eb4a090a27a5415fcc..e50baf1fcb93c6a6deabeefe515c403a9c5c64e0 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/IConv.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/IConv.java @@ -30,6 +30,7 @@ import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.runtime.RError; +import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.data.RDataFactory; import com.oracle.truffle.r.runtime.data.RStringVector; @@ -47,8 +48,8 @@ public abstract class IConv extends RBuiltinNode { casts.arg("to").mustBe(stringValue(), RError.NO_CALLER, RError.Message.INVALID_ARGUMENT, "to").asStringVector().mustBe(size(1), RError.NO_CALLER, RError.Message.INVALID_ARGUMENT, "to"); casts.arg("sub").mustBe(stringValue(), RError.NO_CALLER, RError.Message.INVALID_ARGUMENT, "sub").asStringVector().mustBe(size(1), RError.NO_CALLER, RError.Message.INVALID_ARGUMENT, "sub"); - casts.arg("mark").asLogicalVector().findFirst(); - casts.arg("toRaw").asLogicalVector().findFirst(); + casts.arg("mark").asLogicalVector().findFirst(RRuntime.LOGICAL_FALSE); + casts.arg("toRaw").asLogicalVector().findFirst(RRuntime.LOGICAL_FALSE); } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/InheritsBuiltin.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/InheritsBuiltin.java index 68d4166c8e20bdc7d52e2e5592c32e19726a4b2a..e6c8ec77d4dadf8564670ecbd855c7143a1cf207 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/InheritsBuiltin.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/InheritsBuiltin.java @@ -11,7 +11,7 @@ package com.oracle.truffle.r.nodes.builtin.base; -import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.scalarLogicalValue; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.logicalValue; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.stringValue; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.toBoolean; import static com.oracle.truffle.r.runtime.RError.Message.NOT_CHARACTER_VECTOR; @@ -37,7 +37,7 @@ public abstract class InheritsBuiltin extends RBuiltinNode { @Override protected void createCasts(CastBuilder casts) { casts.arg("what").mustBe(stringValue(), NOT_CHARACTER_VECTOR, "what"); - casts.arg("which").mustBe(scalarLogicalValue(), NOT_LEN_ONE_LOGICAL_VECTOR, "which").map(toBoolean()); + casts.arg("which").mustBe(logicalValue(), NOT_LEN_ONE_LOGICAL_VECTOR, "which").asLogicalVector().findFirst().map(toBoolean()); } @Specialization diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LoadSaveFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LoadSaveFunctions.java index 9618bcdb1fb8751a6e646b5b6c1b28bccd90fd7d..ac1c513d6958b6a8a905b90bede125b0a218a468 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LoadSaveFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LoadSaveFunctions.java @@ -99,9 +99,9 @@ public class LoadSaveFunctions { throw RError.error(this, RError.Message.GENERIC, "the input does not start with a magic number compatible with loading from a connection"); } } catch (IOException iox) { - throw RError.error(this, RError.Message.ERROR_READING_CONNECTION, iox.getMessage()); + throw RError.error(RError.SHOW_CALLER, RError.Message.ERROR_READING_CONNECTION, iox.getMessage()); } catch (PutException px) { - throw RError.error(this, px); + throw RError.error(RError.SHOW_CALLER, px); } } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LocaleFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LocaleFunctions.java index c55810944e2010f2a4f0612444b9a2d566b64aef..9dc1f6f364579a32c4f7d3082ef1ba375224036f 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LocaleFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LocaleFunctions.java @@ -22,6 +22,13 @@ */ package com.oracle.truffle.r.nodes.builtin.base; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.numericValue; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.singleElement; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.stringValue; +import static com.oracle.truffle.r.runtime.RError.Message.ARGUMENT_NOT_CHAR_VECTOR; +import static com.oracle.truffle.r.runtime.RError.Message.INVALID_ARGUMENT; +import static com.oracle.truffle.r.runtime.RError.Message.INVALID_VALUE; +import static com.oracle.truffle.r.runtime.RError.NO_CALLER; import static com.oracle.truffle.r.runtime.builtins.RBehavior.MODIFIES_STATE; import static com.oracle.truffle.r.runtime.builtins.RBehavior.READS_STATE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; @@ -31,6 +38,7 @@ import java.nio.charset.Charset; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RInternalError; @@ -40,7 +48,6 @@ import com.oracle.truffle.r.runtime.data.RDataFactory; import com.oracle.truffle.r.runtime.data.RList; import com.oracle.truffle.r.runtime.data.RNull; import com.oracle.truffle.r.runtime.data.RStringVector; -import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector; import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; public class LocaleFunctions { @@ -48,11 +55,15 @@ public class LocaleFunctions { @RBuiltin(name = "Sys.getlocale", kind = INTERNAL, parameterNames = {"category"}, behavior = READS_STATE) public abstract static class GetLocale extends RBuiltinNode { + @Override + protected void createCasts(CastBuilder casts) { + Casts.category(casts); + } + @Specialization @TruffleBoundary - protected Object getLocale(RAbstractIntVector categoryVec) { + protected Object getLocale(int category) { // TODO implement all: for now just return not available (NULL) - int category = categoryVec.getDataAt(0); switch (category) { case 3: // "LC_CTYPE", return RDataFactory.createStringVector(Charset.defaultCharset().name()); @@ -82,16 +93,15 @@ public class LocaleFunctions { @RBuiltin(name = "Sys.setlocale", kind = INTERNAL, parameterNames = {"category", "locale"}, behavior = MODIFIES_STATE) public abstract static class SetLocale extends RBuiltinNode { - @Specialization - @TruffleBoundary - protected Object setLocale(@SuppressWarnings("unused") RAbstractIntVector categoryVec, RAbstractStringVector locale) { - // TODO implement properly!! - return locale; + @Override + protected void createCasts(CastBuilder casts) { + Casts.category(casts); + casts.arg("locale").mustBe(stringValue()).asStringVector().mustBe(singleElement()).findFirst(); } @Specialization @TruffleBoundary - protected Object setLocale(@SuppressWarnings("unused") RAbstractIntVector categoryVec, RNull locale) { + protected Object setLocale(@SuppressWarnings("unused") int category, String locale) { // TODO implement properly!! return locale; } @@ -124,6 +134,11 @@ public class LocaleFunctions { @RBuiltin(name = "enc2native", kind = PRIMITIVE, parameterNames = "x", behavior = READS_STATE) public abstract static class Enc2Native extends RBuiltinNode { + @Override + protected void createCasts(CastBuilder casts) { + Casts.xCharacterVector(casts); + } + @Specialization protected Object enc2Native(RAbstractStringVector x) { // TODO implement properly @@ -133,6 +148,11 @@ public class LocaleFunctions { @RBuiltin(name = "enc2utf8", kind = PRIMITIVE, parameterNames = "x", behavior = READS_STATE) public abstract static class Enc2Utf8 extends RBuiltinNode { + @Override + protected void createCasts(CastBuilder casts) { + Casts.xCharacterVector(casts); + } + @Specialization protected Object enc2Native(RAbstractStringVector x) { // TODO implement properly @@ -142,6 +162,11 @@ public class LocaleFunctions { @RBuiltin(name = "bindtextdomain", kind = PRIMITIVE, parameterNames = {"domain", "dirname"}, behavior = READS_STATE) public abstract static class BindTextDomain extends RBuiltinNode { + @Override + protected void createCasts(@SuppressWarnings("unused") CastBuilder casts) { + casts.arg("domain").mustBe(stringValue(), INVALID_VALUE, "domain"); + } + @SuppressWarnings("unused") @Specialization protected RNull bindtextdomain(RAbstractStringVector domain, Object dirname) { @@ -149,4 +174,14 @@ public class LocaleFunctions { return RNull.instance; } } + + private static final class Casts { + private static void xCharacterVector(CastBuilder casts) { + casts.arg("x").mustBe(stringValue(), ARGUMENT_NOT_CHAR_VECTOR); + } + + private static void category(CastBuilder casts) { + casts.arg("category").mustBe(numericValue(), NO_CALLER, INVALID_ARGUMENT, "category").asIntegerVector().findFirst(); + } + } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Ls.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Ls.java index 3f958d27efd911a5ff2df9fc5fe401f197de7a03..c7bd9e803344a24d85f625fac7636dbc4c0a7f11 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Ls.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Ls.java @@ -22,13 +22,16 @@ */ package com.oracle.truffle.r.nodes.builtin.base; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.toBoolean; +import static com.oracle.truffle.r.runtime.RError.Message.INVALID_ARGUMENT; +import static com.oracle.truffle.r.runtime.RError.NO_CALLER; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; -import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.data.RStringVector; import com.oracle.truffle.r.runtime.env.REnvironment; @@ -36,9 +39,16 @@ import com.oracle.truffle.r.runtime.env.REnvironment; @RBuiltin(name = "ls", aliases = {"objects"}, kind = INTERNAL, parameterNames = {"envir", "all.names", "sorted"}, behavior = PURE) public abstract class Ls extends RBuiltinNode { + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("envir").mustBe(REnvironment.class, NO_CALLER, INVALID_ARGUMENT, "envir"); + casts.arg("all.names").asLogicalVector().findFirst().map(toBoolean()); + casts.arg("sorted").asLogicalVector().findFirst().map(toBoolean()); + } + @Specialization @TruffleBoundary - protected RStringVector ls(REnvironment envir, byte allNames, byte sorted) { - return envir.ls(RRuntime.fromLogical(allNames), null, RRuntime.fromLogical(sorted)); + protected RStringVector ls(REnvironment envir, boolean allNames, boolean sorted) { + return envir.ls(allNames, null, sorted); } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/MakeNames.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/MakeNames.java index bba53b2726983cd0c892f65ec4695d5d0e8eaf92..608da437d082ded06b7b0f36170292c617717754 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/MakeNames.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/MakeNames.java @@ -22,6 +22,7 @@ */ package com.oracle.truffle.r.nodes.builtin.base; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.*; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; @@ -30,19 +31,12 @@ import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.profiles.ConditionProfile; import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; -import com.oracle.truffle.r.nodes.unary.CastLogicalNode; -import com.oracle.truffle.r.nodes.unary.CastLogicalNodeGen; -import com.oracle.truffle.r.nodes.unary.CastNode; -import com.oracle.truffle.r.nodes.unary.CastToVectorNode; -import com.oracle.truffle.r.nodes.unary.CastToVectorNodeGen; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.Utils; import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.data.RStringVector; -import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector; import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; -import com.oracle.truffle.r.runtime.nodes.RBaseNode; import com.oracle.truffle.r.runtime.ops.na.NACheck; @RBuiltin(name = "make.names", kind = INTERNAL, parameterNames = {"names", "allow_"}, behavior = PURE) @@ -53,7 +47,8 @@ public abstract class MakeNames extends RBuiltinNode { @Override protected void createCasts(CastBuilder casts) { - casts.custom(1, new AllowUnderscoreConverter()); + casts.arg("names").mustBe(stringValue(), RError.SHOW_CALLER, RError.Message.NON_CHARACTER_NAMES); + casts.arg("allow_").asLogicalVector().findFirst(RError.SHOW_CALLER, RError.Message.INVALID_VALUE, "allow_").mustBe(notLogicalNA(), RError.SHOW_CALLER, RError.Message.INVALID_VALUE, "allow_"); } @TruffleBoundary @@ -176,38 +171,4 @@ public abstract class MakeNames extends RBuiltinNode { } } - @Specialization(guards = "!wrongAllowUnderscore(allowUnderScoreArg)") - protected RAbstractStringVector makeNames(RAbstractStringVector names, RAbstractLogicalVector allowUnderScoreArg) { - return makeNames(names, allowUnderScoreArg.getDataAt(0)); - } - - @SuppressWarnings("unused") - @Specialization(guards = "wrongAllowUnderscore(allowUnderScoreArg)") - protected RAbstractStringVector makeNamesWrongUnderscoreEmpty(RAbstractStringVector names, RAbstractLogicalVector allowUnderScoreArg) { - throw invalidAllowValue(this); - } - - protected static boolean wrongAllowUnderscore(RAbstractLogicalVector allowUnderScoreArg) { - return allowUnderScoreArg.getLength() == 0 || RRuntime.isNA(allowUnderScoreArg.getDataAt(0)); - } - - private static final class AllowUnderscoreConverter extends CastNode { - - @Child private CastLogicalNode castLogical = CastLogicalNodeGen.create(false, false, false); - @Child private CastToVectorNode castVector = CastToVectorNodeGen.create(false); - - @Override - public RAbstractLogicalVector execute(Object value) { - try { - // TODO Catching RError! - return (RAbstractLogicalVector) castLogical.execute(castVector.execute(value)); - } catch (RError x) { - throw invalidAllowValue(this); - } - } - } - - private static RError invalidAllowValue(RBaseNode invokingNode) throws RError { - throw RError.error(invokingNode, RError.Message.INVALID_VALUE, "allow_"); - } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/MakeUnique.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/MakeUnique.java index 8a4065d95e6c666f53f372e324f74dc8066960e7..f00beccacd6bb2b30b1e28a5c6dd2e6a207a19c7 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/MakeUnique.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/MakeUnique.java @@ -22,19 +22,20 @@ */ package com.oracle.truffle.r.nodes.builtin.base; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.size; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.stringValue; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.profiles.ConditionProfile; +import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.builtins.RBuiltin; -import com.oracle.truffle.r.runtime.data.RString; import com.oracle.truffle.r.runtime.data.RStringVector; import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; -import com.oracle.truffle.r.runtime.data.model.RAbstractVector; import com.oracle.truffle.r.runtime.ops.na.NACheck; @RBuiltin(name = "make.unique", kind = INTERNAL, parameterNames = {"names", "sep"}, behavior = PURE) @@ -44,6 +45,13 @@ public abstract class MakeUnique extends RBuiltinNode { private final ConditionProfile duplicatesProfile = ConditionProfile.createBinaryProfile(); private final NACheck dummyCheck = NACheck.create(); // never triggered (used for vector update) + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("names").mustBe(stringValue(), RError.SHOW_CALLER, RError.Message.NOT_CHARACTER_VECTOR, "names"); + casts.arg("sep").defaultError(RError.SHOW_CALLER, RError.Message.MUST_BE_STRING, "sep").mustBe(stringValue()).asStringVector().mustBe(size(1)).findFirst(); + + } + @Specialization protected RAbstractStringVector makeUnique(RAbstractStringVector names, String sep) { if (namesProfile.profile(names.getLength() == 0 || names.getLength() == 1)) { @@ -91,28 +99,4 @@ public abstract class MakeUnique extends RBuiltinNode { return s1 + sep + index; } - @Specialization(guards = "sepIsString(sep)") - protected RAbstractStringVector makeUnique(RAbstractStringVector names, RAbstractVector sep) { - return makeUnique(names, (String) sep.getDataAtAsObject(0)); - } - - @SuppressWarnings("unused") - @Specialization(guards = "!sepIsString(sep)") - protected RAbstractStringVector makeUniqueWrongSep(RAbstractStringVector names, RAbstractVector sep) { - throw RError.error(this, RError.Message.MUST_BE_STRING, "sep"); - } - - @SuppressWarnings("unused") - @Specialization(guards = "!namesIsStringVector(names)") - protected RAbstractStringVector makeUnique(RAbstractVector names, Object sep) { - throw RError.error(this, RError.Message.NOT_CHARACTER_VECTOR, "names"); - } - - protected boolean namesIsStringVector(RAbstractVector names) { - return names.getElementClass() == RString.class; - } - - protected boolean sepIsString(RAbstractVector sep) { - return sep.getElementClass() == RString.class && sep.getLength() == 1; - } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/MatMult.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/MatMult.java index a24242b07bc1142361a4162b9efc6dc6d2746814..b493cfcbd39bfb2dbbcd38812164ad77ce869501 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/MatMult.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/MatMult.java @@ -27,6 +27,9 @@ import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; +import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; +import com.oracle.truffle.api.dsl.Cached; +import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.profiles.BranchProfile; import com.oracle.truffle.api.profiles.ConditionProfile; @@ -48,8 +51,6 @@ import com.oracle.truffle.r.runtime.data.model.RAbstractComplexVector; import com.oracle.truffle.r.runtime.data.model.RAbstractDoubleVector; import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector; import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector; -import com.oracle.truffle.r.runtime.data.model.RAbstractRawVector; -import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; import com.oracle.truffle.r.runtime.data.model.RAbstractVector; import com.oracle.truffle.r.runtime.nodes.RNode; import com.oracle.truffle.r.runtime.ops.BinaryArithmetic; @@ -133,13 +134,6 @@ public abstract class MatMult extends RBuiltinNode { private final BranchProfile incompleteProfile = BranchProfile.create(); @CompilationFinal private boolean seenLargeMatrix; - @Specialization(guards = "matmat(a, b)") - protected RDoubleVector matmatmult(RAbstractDoubleVector a, RAbstractDoubleVector b) { - int[] aDimensions = a.getDimensions(); - int[] bDimensions = b.getDimensions(); - return doubleMatrixMultiply(a, b, aDimensions[0], aDimensions[1], bDimensions[0], bDimensions[1]); - } - private RDoubleVector doubleMatrixMultiply(RAbstractDoubleVector a, RAbstractDoubleVector b, int aRows, int aCols, int bRows, int bCols) { return doubleMatrixMultiply(a, b, aRows, aCols, bRows, bCols, 1, aRows, 1, bRows, false); } @@ -268,598 +262,404 @@ public abstract class MatMult extends RBuiltinNode { } } - @Specialization(guards = "vecvec(a, b)") - protected RDoubleVector vecvecmult(RAbstractDoubleVector a, RAbstractDoubleVector b) { - if (a.getLength() != b.getLength()) { - errorProfile.enter(); - throw RError.error(this, RError.Message.NON_CONFORMABLE_ARGS); - } - double result = 0.0; - na.enable(a); - na.enable(b); - for (int k = 0; k < a.getLength(); k++) { - double aValue = a.getDataAt(k); - double bValue = b.getDataAt(k); - if (na.check(aValue) || na.check(bValue)) { - return RDataFactory.createDoubleVector(new double[]{RRuntime.DOUBLE_NA}, false, new int[]{1, 1}); + @Specialization + protected RDoubleVector multiply(RAbstractDoubleVector a, RAbstractDoubleVector b, + @Cached("createBinaryProfile()") ConditionProfile aIsMatrix, + @Cached("createBinaryProfile()") ConditionProfile bIsMatrix, + @Cached("createBinaryProfile()") ConditionProfile lengthEquals) { + if (aIsMatrix.profile(a.isMatrix())) { + if (bIsMatrix.profile(b.isMatrix())) { + int[] aDimensions = a.getDimensions(); + int[] bDimensions = b.getDimensions(); + return doubleMatrixMultiply(a, b, aDimensions[0], aDimensions[1], bDimensions[0], bDimensions[1]); + } else { + int aRows = a.getDimensions()[0]; + int aCols = a.getDimensions()[1]; + int bRows; + int bCols; + if (lengthEquals.profile(aCols == b.getLength())) { + bRows = b.getLength(); + bCols = 1; + } else { + bRows = 1; + bCols = b.getLength(); + } + return doubleMatrixMultiply(a, b, aRows, aCols, bRows, bCols); } - result = add.applyDouble(result, mult.applyDouble(aValue, bValue)); - } - return RDataFactory.createDoubleVector(new double[]{result}, true, new int[]{1, 1}); - } - - @Specialization(guards = "matvec(a, b)") - protected RDoubleVector matvecmult(RAbstractDoubleVector a, RAbstractDoubleVector b) { - int aRows = a.getDimensions()[0]; - int aCols = a.getDimensions()[1]; - int bRows; - int bCols; - if (aCols == b.getLength()) { - bRows = b.getLength(); - bCols = 1; - } else { - bRows = 1; - bCols = b.getLength(); - } - return doubleMatrixMultiply(a, b, aRows, aCols, bRows, bCols); - } - - @Specialization(guards = "vecmat(a, b)") - protected RDoubleVector vecmatmult(RAbstractDoubleVector a, RAbstractDoubleVector b) { - int bRows = b.getDimensions()[0]; - int bCols = b.getDimensions()[1]; - int aRows; - int aCols; - if (bRows == a.getLength()) { - aRows = 1; - aCols = a.getLength(); } else { - aRows = a.getLength(); - aCols = 1; - } - return doubleMatrixMultiply(a, b, aRows, aCols, bRows, bCols); - } - - // complex-complex - - @Specialization(guards = "matmat(a, b)") - protected RComplexVector matmatmult(RAbstractComplexVector a, RAbstractComplexVector b) { - final int aCols = a.getDimensions()[1]; - final int bRows = b.getDimensions()[0]; - if (aCols != bRows) { - errorProfile.enter(); - throw RError.error(this, RError.Message.NON_CONFORMABLE_ARGS); - } - final int aRows = a.getDimensions()[0]; - final int bCols = b.getDimensions()[1]; - double[] result = new double[(aRows * bCols) << 1]; - na.enable(a); - na.enable(b); - for (int row = 0; row < aRows; row++) { - for (int col = 0; col < bCols; col++) { - RComplex x = RDataFactory.createComplexZero(); - for (int k = 0; k < aCols; k++) { - x = add.applyComplex(x, mult.applyComplex(a.getDataAt(k * aRows + row), b.getDataAt(col * bRows + k))); - na.check(x); + if (bIsMatrix.profile(b.isMatrix())) { + int bRows = b.getDimensions()[0]; + int bCols = b.getDimensions()[1]; + int aRows; + int aCols; + if (lengthEquals.profile(bRows == a.getLength())) { + aRows = 1; + aCols = a.getLength(); + } else { + aRows = a.getLength(); + aCols = 1; + } + return doubleMatrixMultiply(a, b, aRows, aCols, bRows, bCols); + } else { + if (a.getLength() != b.getLength()) { + errorProfile.enter(); + throw RError.error(this, RError.Message.NON_CONFORMABLE_ARGS); } - final int index = 2 * (col * aRows + row); - result[index] = x.getRealPart(); - result[index + 1] = x.getImaginaryPart(); + double result = 0.0; + na.enable(a); + na.enable(b); + for (int k = 0; k < a.getLength(); k++) { + double aValue = a.getDataAt(k); + double bValue = b.getDataAt(k); + if (na.check(aValue) || na.check(bValue)) { + return RDataFactory.createDoubleVector(new double[]{RRuntime.DOUBLE_NA}, false, new int[]{1, 1}); + } + result = add.applyDouble(result, mult.applyDouble(aValue, bValue)); + } + return RDataFactory.createDoubleVector(new double[]{result}, true, new int[]{1, 1}); } } - return RDataFactory.createComplexVector(result, na.neverSeenNA(), new int[]{aRows, bCols}); } - @Specialization(guards = "vecvec(a, b)") - protected RComplexVector vecvecmult(RAbstractComplexVector a, RAbstractComplexVector b) { - if (a.getLength() != b.getLength()) { - errorProfile.enter(); - throw RError.error(this, RError.Message.NON_CONFORMABLE_ARGS); - } - RComplex result = RDataFactory.createComplexZero(); - na.enable(a); - na.enable(b); - for (int k = 0; k < a.getLength(); k++) { - result = add.applyComplex(result, mult.applyComplex(a.getDataAt(k), b.getDataAt(k))); - na.check(result); - } - return RDataFactory.createComplexVector(new double[]{result.getRealPart(), result.getImaginaryPart()}, na.neverSeenNA(), new int[]{1, 1}); - } + // complex-complex - @Specialization(guards = "matvec(a, b)") - protected RComplexVector matvecmult(RAbstractComplexVector a, RAbstractComplexVector b) { - final int aCols = a.getDimensions()[1]; - final int aRows = a.getDimensions()[0]; - if (aCols != 1 && aCols != b.getLength()) { - errorProfile.enter(); - throw RError.error(this, RError.Message.NON_CONFORMABLE_ARGS); - } - na.enable(a); - na.enable(b); - if (notOneColumn.profile(aCols != 1)) { - double[] result = new double[aRows << 1]; - for (int row = 0; row < aRows; row++) { - RComplex x = RDataFactory.createComplexZero(); - for (int k = 0; k < b.getLength(); k++) { - x = add.applyComplex(x, mult.applyComplex(a.getDataAt(k * aRows + row), b.getDataAt(k))); - na.check(x); + @Specialization + protected RComplexVector multiply(RAbstractComplexVector a, RAbstractComplexVector b, + @Cached("createBinaryProfile()") ConditionProfile aIsMatrix, + @Cached("createBinaryProfile()") ConditionProfile bIsMatrix) { + if (aIsMatrix.profile(a.isMatrix())) { + if (bIsMatrix.profile(b.isMatrix())) { + final int aCols = a.getDimensions()[1]; + final int bRows = b.getDimensions()[0]; + if (aCols != bRows) { + errorProfile.enter(); + throw RError.error(this, RError.Message.NON_CONFORMABLE_ARGS); } - result[row << 1] = x.getRealPart(); - result[row << 1 + 1] = x.getImaginaryPart(); - } - return RDataFactory.createComplexVector(result, na.neverSeenNA(), new int[]{aRows, 1}); - } else { - double[] result = new double[aRows * b.getLength() << 1]; - for (int row = 0; row < aRows; row++) { - for (int k = 0; k < b.getLength(); k++) { - RComplex x = mult.applyComplex(a.getDataAt(row), b.getDataAt(k)); - na.check(x); - result[(k * aRows + row) << 1] = x.getRealPart(); - result[(k * aRows + row) << 1 + 1] = x.getRealPart(); + final int aRows = a.getDimensions()[0]; + final int bCols = b.getDimensions()[1]; + double[] result = new double[(aRows * bCols) << 1]; + na.enable(a); + na.enable(b); + for (int row = 0; row < aRows; row++) { + for (int col = 0; col < bCols; col++) { + RComplex x = RDataFactory.createComplexZero(); + for (int k = 0; k < aCols; k++) { + x = add.applyComplex(x, mult.applyComplex(a.getDataAt(k * aRows + row), b.getDataAt(col * bRows + k))); + na.check(x); + } + final int index = 2 * (col * aRows + row); + result[index] = x.getRealPart(); + result[index + 1] = x.getImaginaryPart(); + } } - } - return RDataFactory.createComplexVector(result, na.neverSeenNA(), new int[]{aRows, b.getLength()}); - } - } - - @Specialization(guards = "vecmat(a, b)") - protected RComplexVector vecmatmult(RAbstractComplexVector a, RAbstractComplexVector b) { - final int bRows = b.getDimensions()[0]; - final int bCols = b.getDimensions()[1]; - if (bRows != 1 && bRows != a.getLength()) { - errorProfile.enter(); - throw RError.error(this, RError.Message.NON_CONFORMABLE_ARGS); - } - na.enable(a); - na.enable(b); - if (notOneRow.profile(bRows != 1)) { - double[] result = new double[bCols << 1]; - for (int k = 0; k < bCols; k++) { - RComplex x = RDataFactory.createComplexZero(); - for (int row = 0; row < a.getLength(); row++) { - x = add.applyComplex(x, mult.applyComplex(a.getDataAt(row), b.getDataAt(k * a.getLength() + row))); - na.check(x); + return RDataFactory.createComplexVector(result, na.neverSeenNA(), new int[]{aRows, bCols}); + } else { + final int aCols = a.getDimensions()[1]; + final int aRows = a.getDimensions()[0]; + if (aCols != 1 && aCols != b.getLength()) { + errorProfile.enter(); + throw RError.error(this, RError.Message.NON_CONFORMABLE_ARGS); + } + na.enable(a); + na.enable(b); + if (notOneColumn.profile(aCols != 1)) { + double[] result = new double[aRows << 1]; + for (int row = 0; row < aRows; row++) { + RComplex x = RDataFactory.createComplexZero(); + for (int k = 0; k < b.getLength(); k++) { + x = add.applyComplex(x, mult.applyComplex(a.getDataAt(k * aRows + row), b.getDataAt(k))); + na.check(x); + } + result[row << 1] = x.getRealPart(); + result[row << 1 + 1] = x.getImaginaryPart(); + } + return RDataFactory.createComplexVector(result, na.neverSeenNA(), new int[]{aRows, 1}); + } else { + double[] result = new double[aRows * b.getLength() << 1]; + for (int row = 0; row < aRows; row++) { + for (int k = 0; k < b.getLength(); k++) { + RComplex x = mult.applyComplex(a.getDataAt(row), b.getDataAt(k)); + na.check(x); + result[(k * aRows + row) << 1] = x.getRealPart(); + result[(k * aRows + row) << 1 + 1] = x.getRealPart(); + } + } + return RDataFactory.createComplexVector(result, na.neverSeenNA(), new int[]{aRows, b.getLength()}); } - result[k << 1] = x.getRealPart(); - result[k << 1 + 1] = x.getImaginaryPart(); } - return RDataFactory.createComplexVector(result, na.neverSeenNA(), new int[]{1, bCols}); } else { - double[] result = new double[(bCols * a.getLength()) << 1]; - for (int row = 0; row < a.getLength(); row++) { - for (int k = 0; k < bCols; k++) { - RComplex x = mult.applyComplex(a.getDataAt(row), b.getDataAt(k)); - na.check(x); - result[(k * a.getLength() + row) << 1] = x.getRealPart(); - result[(k * a.getLength() + row) << 1 + 1] = x.getImaginaryPart(); + if (bIsMatrix.profile(b.isMatrix())) { + final int bRows = b.getDimensions()[0]; + final int bCols = b.getDimensions()[1]; + if (bRows != 1 && bRows != a.getLength()) { + errorProfile.enter(); + throw RError.error(this, RError.Message.NON_CONFORMABLE_ARGS); } + na.enable(a); + na.enable(b); + if (notOneRow.profile(bRows != 1)) { + double[] result = new double[bCols << 1]; + for (int k = 0; k < bCols; k++) { + RComplex x = RDataFactory.createComplexZero(); + for (int row = 0; row < a.getLength(); row++) { + x = add.applyComplex(x, mult.applyComplex(a.getDataAt(row), b.getDataAt(k * a.getLength() + row))); + na.check(x); + } + result[k << 1] = x.getRealPart(); + result[k << 1 + 1] = x.getImaginaryPart(); + } + return RDataFactory.createComplexVector(result, na.neverSeenNA(), new int[]{1, bCols}); + } else { + double[] result = new double[(bCols * a.getLength()) << 1]; + for (int row = 0; row < a.getLength(); row++) { + for (int k = 0; k < bCols; k++) { + RComplex x = mult.applyComplex(a.getDataAt(row), b.getDataAt(k)); + na.check(x); + result[(k * a.getLength() + row) << 1] = x.getRealPart(); + result[(k * a.getLength() + row) << 1 + 1] = x.getImaginaryPart(); + } + } + return RDataFactory.createComplexVector(result, na.neverSeenNA(), new int[]{a.getLength(), bCols}); + } + } else { + if (a.getLength() != b.getLength()) { + errorProfile.enter(); + throw RError.error(this, RError.Message.NON_CONFORMABLE_ARGS); + } + RComplex result = RDataFactory.createComplexZero(); + na.enable(a); + na.enable(b); + for (int k = 0; k < a.getLength(); k++) { + result = add.applyComplex(result, mult.applyComplex(a.getDataAt(k), b.getDataAt(k))); + na.check(result); + } + return RDataFactory.createComplexVector(new double[]{result.getRealPart(), result.getImaginaryPart()}, na.neverSeenNA(), new int[]{1, 1}); } - return RDataFactory.createComplexVector(result, na.neverSeenNA(), new int[]{a.getLength(), bCols}); } } // int-int - @Specialization(guards = "matmat(a, b)") - protected RIntVector matmatmult(RAbstractIntVector a, RAbstractIntVector b) { - final int aCols = a.getDimensions()[1]; - final int bRows = b.getDimensions()[0]; - if (aCols != bRows) { - errorProfile.enter(); - throw RError.error(this, RError.Message.NON_CONFORMABLE_ARGS); - } - final int aRows = a.getDimensions()[0]; - final int bCols = b.getDimensions()[1]; - int[] result = new int[aRows * bCols]; - na.enable(a); - na.enable(b); - for (int row = 0; row < aRows; row++) { - for (int col = 0; col < bCols; col++) { - int x = 0; - for (int k = 0; k < aCols; k++) { - x = add.applyInteger(x, mult.applyInteger(a.getDataAt(k * aRows + row), b.getDataAt(col * bRows + k))); - na.check(x); + @Specialization + protected RIntVector multiply(RAbstractIntVector a, RAbstractIntVector b, + @Cached("createBinaryProfile()") ConditionProfile aIsMatrix, + @Cached("createBinaryProfile()") ConditionProfile bIsMatrix) { + if (aIsMatrix.profile(a.isMatrix())) { + if (bIsMatrix.profile(b.isMatrix())) { + final int aCols = a.getDimensions()[1]; + final int bRows = b.getDimensions()[0]; + if (aCols != bRows) { + errorProfile.enter(); + throw RError.error(this, RError.Message.NON_CONFORMABLE_ARGS); } - result[col * aRows + row] = x; - } - } - return RDataFactory.createIntVector(result, na.neverSeenNA(), new int[]{aRows, bCols}); - } - - @Specialization(guards = "vecvec(a, b)") - protected RIntVector vecvecmult(RAbstractIntVector a, RAbstractIntVector b) { - if (a.getLength() != b.getLength()) { - errorProfile.enter(); - throw RError.error(this, RError.Message.NON_CONFORMABLE_ARGS); - } - int result = 0; - na.enable(result); - for (int k = 0; k < a.getLength(); k++) { - result = add.applyInteger(result, mult.applyInteger(a.getDataAt(k), b.getDataAt(k))); - na.check(result); - } - return RDataFactory.createIntVector(new int[]{result}, na.neverSeenNA(), new int[]{1, 1}); - } - - @Specialization(guards = "matvec(a, b)") - protected RIntVector matvecmult(RAbstractIntVector a, RAbstractIntVector b) { - final int aCols = a.getDimensions()[1]; - final int aRows = a.getDimensions()[0]; - if (aCols != 1 && aCols != b.getLength()) { - errorProfile.enter(); - throw RError.error(this, RError.Message.NON_CONFORMABLE_ARGS); - } - na.enable(a); - na.enable(b); - if (notOneColumn.profile(aCols != 1)) { - int[] result = new int[aRows]; - for (int row = 0; row < aRows; row++) { - int x = 0; - for (int k = 0; k < b.getLength(); k++) { - x = add.applyInteger(x, mult.applyInteger(a.getDataAt(k * aRows + row), b.getDataAt(k))); - na.check(x); + final int aRows = a.getDimensions()[0]; + final int bCols = b.getDimensions()[1]; + int[] result = new int[aRows * bCols]; + na.enable(a); + na.enable(b); + for (int row = 0; row < aRows; row++) { + for (int col = 0; col < bCols; col++) { + int x = 0; + for (int k = 0; k < aCols; k++) { + x = add.applyInteger(x, mult.applyInteger(a.getDataAt(k * aRows + row), b.getDataAt(col * bRows + k))); + na.check(x); + } + result[col * aRows + row] = x; + } } - result[row] = x; - } - return RDataFactory.createIntVector(result, na.neverSeenNA(), new int[]{aRows, 1}); - } else { - int[] result = new int[aRows * b.getLength()]; - for (int row = 0; row < aRows; row++) { - for (int k = 0; k < b.getLength(); k++) { - int x = mult.applyInteger(a.getDataAt(row), b.getDataAt(k)); - na.check(x); - result[k * aRows + row] = x; + return RDataFactory.createIntVector(result, na.neverSeenNA(), new int[]{aRows, bCols}); + } else { + final int aCols = a.getDimensions()[1]; + final int aRows = a.getDimensions()[0]; + if (aCols != 1 && aCols != b.getLength()) { + errorProfile.enter(); + throw RError.error(this, RError.Message.NON_CONFORMABLE_ARGS); } - } - return RDataFactory.createIntVector(result, na.neverSeenNA(), new int[]{aRows, b.getLength()}); - } - } - - @Specialization(guards = "vecmat(a, b)") - protected RIntVector vecmatmult(RAbstractIntVector a, RAbstractIntVector b) { - final int bCols = b.getDimensions()[1]; - final int bRows = b.getDimensions()[0]; - if (bRows != 1 && bRows != a.getLength()) { - errorProfile.enter(); - throw RError.error(this, RError.Message.NON_CONFORMABLE_ARGS); - } - na.enable(a); - na.enable(b); - if (notOneRow.profile(bRows != 1)) { - int[] result = new int[bCols]; - for (int k = 0; k < bCols; k++) { - int x = 0; - for (int row = 0; row < a.getLength(); row++) { - x = add.applyInteger(x, mult.applyInteger(a.getDataAt(row), b.getDataAt(k * a.getLength() + row))); - na.check(x); + na.enable(a); + na.enable(b); + if (notOneColumn.profile(aCols != 1)) { + int[] result = new int[aRows]; + for (int row = 0; row < aRows; row++) { + int x = 0; + for (int k = 0; k < b.getLength(); k++) { + x = add.applyInteger(x, mult.applyInteger(a.getDataAt(k * aRows + row), b.getDataAt(k))); + na.check(x); + } + result[row] = x; + } + return RDataFactory.createIntVector(result, na.neverSeenNA(), new int[]{aRows, 1}); + } else { + int[] result = new int[aRows * b.getLength()]; + for (int row = 0; row < aRows; row++) { + for (int k = 0; k < b.getLength(); k++) { + int x = mult.applyInteger(a.getDataAt(row), b.getDataAt(k)); + na.check(x); + result[k * aRows + row] = x; + } + } + return RDataFactory.createIntVector(result, na.neverSeenNA(), new int[]{aRows, b.getLength()}); } - result[k] = x; } - return RDataFactory.createIntVector(result, na.neverSeenNA(), new int[]{1, bCols}); } else { - int[] result = new int[bCols * a.getLength()]; - for (int row = 0; row < a.getLength(); row++) { - for (int k = 0; k < bCols; k++) { - int x = mult.applyInteger(a.getDataAt(row), b.getDataAt(k)); - na.check(x); - result[k * a.getLength() + row] = x; + if (bIsMatrix.profile(b.isMatrix())) { + final int bCols = b.getDimensions()[1]; + final int bRows = b.getDimensions()[0]; + if (bRows != 1 && bRows != a.getLength()) { + errorProfile.enter(); + throw RError.error(this, RError.Message.NON_CONFORMABLE_ARGS); } + na.enable(a); + na.enable(b); + if (notOneRow.profile(bRows != 1)) { + int[] result = new int[bCols]; + for (int k = 0; k < bCols; k++) { + int x = 0; + for (int row = 0; row < a.getLength(); row++) { + x = add.applyInteger(x, mult.applyInteger(a.getDataAt(row), b.getDataAt(k * a.getLength() + row))); + na.check(x); + } + result[k] = x; + } + return RDataFactory.createIntVector(result, na.neverSeenNA(), new int[]{1, bCols}); + } else { + int[] result = new int[bCols * a.getLength()]; + for (int row = 0; row < a.getLength(); row++) { + for (int k = 0; k < bCols; k++) { + int x = mult.applyInteger(a.getDataAt(row), b.getDataAt(k)); + na.check(x); + result[k * a.getLength() + row] = x; + } + } + return RDataFactory.createIntVector(result, na.neverSeenNA(), new int[]{a.getLength(), bCols}); + } + } else { + if (a.getLength() != b.getLength()) { + errorProfile.enter(); + throw RError.error(this, RError.Message.NON_CONFORMABLE_ARGS); + } + int result = 0; + na.enable(result); + for (int k = 0; k < a.getLength(); k++) { + result = add.applyInteger(result, mult.applyInteger(a.getDataAt(k), b.getDataAt(k))); + na.check(result); + } + return RDataFactory.createIntVector(new int[]{result}, na.neverSeenNA(), new int[]{1, 1}); } - return RDataFactory.createIntVector(result, na.neverSeenNA(), new int[]{a.getLength(), bCols}); } } // logical-logical - @Specialization(guards = "matmat(a, b)") - protected RIntVector matmatmult(RAbstractLogicalVector a, RAbstractLogicalVector b) { - return matmatmult(RClosures.createLogicalToIntVector(a), RClosures.createLogicalToIntVector(b)); - } - - @Specialization(guards = "vecvec(a, b)") - protected RIntVector vecvecmult(RAbstractLogicalVector a, RAbstractLogicalVector b) { - return vecvecmult(RClosures.createLogicalToIntVector(a), RClosures.createLogicalToIntVector(b)); - } - - @Specialization(guards = "matvec(a, b)") - protected RIntVector matvecmult(RAbstractLogicalVector a, RAbstractLogicalVector b) { - return matvecmult(RClosures.createLogicalToIntVector(a), RClosures.createLogicalToIntVector(b)); - } - - @Specialization(guards = "vecmat(a, b)") - protected RIntVector vecmatmult(RAbstractLogicalVector a, RAbstractLogicalVector b) { - return vecmatmult(RClosures.createLogicalToIntVector(a), RClosures.createLogicalToIntVector(b)); + @Specialization + protected RIntVector multiply(RAbstractLogicalVector aOriginal, RAbstractLogicalVector bOriginal, + @Cached("createBinaryProfile()") ConditionProfile aIsMatrix, + @Cached("createBinaryProfile()") ConditionProfile bIsMatrix) { + return multiply(RClosures.createLogicalToIntVector(aOriginal), RClosures.createLogicalToIntVector(bOriginal), aIsMatrix, bIsMatrix); } // to int - @Specialization(guards = "matmat(a, b)") - protected RIntVector matmatmult(RAbstractLogicalVector a, RAbstractIntVector b) { - return matmatmult(RClosures.createLogicalToIntVector(a), b); - } - - @Specialization(guards = "vecvec(a, b)") - protected RIntVector vecvecmult(RAbstractLogicalVector a, RAbstractIntVector b) { - return vecvecmult(RClosures.createLogicalToIntVector(a), b); - } - - @Specialization(guards = "matvec(a, b)") - protected RIntVector matvecmult(RAbstractLogicalVector a, RAbstractIntVector b) { - return matvecmult(RClosures.createLogicalToIntVector(a), b); - } - - @Specialization(guards = "vecmat(a, b)") - protected RIntVector vecmatmult(RAbstractLogicalVector a, RAbstractIntVector b) { - return vecmatmult(RClosures.createLogicalToIntVector(a), b); - } - - @Specialization(guards = "matmat(a, b)") - protected RIntVector matmatmult(RAbstractIntVector a, RAbstractLogicalVector b) { - return matmatmult(a, RClosures.createLogicalToIntVector(b)); - } - - @Specialization(guards = "vecvec(a, b)") - protected RIntVector vecvecmult(RAbstractIntVector a, RAbstractLogicalVector b) { - return vecvecmult(a, RClosures.createLogicalToIntVector(b)); - } - - @Specialization(guards = "matvec(a, b)") - protected RIntVector matvecmult(RAbstractIntVector a, RAbstractLogicalVector b) { - return matvecmult(a, RClosures.createLogicalToIntVector(b)); + @Specialization + protected RIntVector multiply(RAbstractLogicalVector a, RAbstractIntVector b, + @Cached("createBinaryProfile()") ConditionProfile aIsMatrix, + @Cached("createBinaryProfile()") ConditionProfile bIsMatrix) { + return multiply(RClosures.createLogicalToIntVector(a), b, aIsMatrix, bIsMatrix); } - @Specialization(guards = "vecmat(a, b)") - protected RIntVector vecmatmult(RAbstractIntVector a, RAbstractLogicalVector b) { - return vecmatmult(a, RClosures.createLogicalToIntVector(b)); + @Specialization + protected RIntVector multiply(RAbstractIntVector a, RAbstractLogicalVector b, + @Cached("createBinaryProfile()") ConditionProfile aIsMatrix, + @Cached("createBinaryProfile()") ConditionProfile bIsMatrix) { + return multiply(a, RClosures.createLogicalToIntVector(b), aIsMatrix, bIsMatrix); } // to complex - @Specialization(guards = "matmat(a, b)") - protected RComplexVector matmatmult(RAbstractIntVector a, RAbstractComplexVector b) { - return matmatmult(RClosures.createIntToComplexVector(a), b); - } - - @Specialization(guards = "vecvec(a, b)") - protected RComplexVector vecvecmult(RAbstractIntVector a, RAbstractComplexVector b) { - return vecvecmult(RClosures.createIntToComplexVector(a), b); - } - - @Specialization(guards = "matvec(a, b)") - protected RComplexVector matvecmult(RAbstractIntVector a, RAbstractComplexVector b) { - return matvecmult(RClosures.createIntToComplexVector(a), b); - } - - @Specialization(guards = "vecmat(a, b)") - protected RComplexVector vecmatmult(RAbstractIntVector a, RAbstractComplexVector b) { - return vecmatmult(RClosures.createIntToComplexVector(a), b); - } - - @Specialization(guards = "matmat(a, b)") - protected RComplexVector matmatmult(RAbstractComplexVector a, RAbstractIntVector b) { - return matmatmult(a, RClosures.createIntToComplexVector(b)); - } - - @Specialization(guards = "vecvec(a, b)") - protected RComplexVector vecvecmult(RAbstractComplexVector a, RAbstractIntVector b) { - return vecvecmult(a, RClosures.createIntToComplexVector(b)); - } - - @Specialization(guards = "matvec(a, b)") - protected RComplexVector matvecmult(RAbstractComplexVector a, RAbstractIntVector b) { - return matvecmult(a, RClosures.createIntToComplexVector(b)); - } - - @Specialization(guards = "vecmat(a, b)") - protected RComplexVector vecmatmult(RAbstractComplexVector a, RAbstractIntVector b) { - return vecmatmult(a, RClosures.createIntToComplexVector(b)); - } - - @Specialization(guards = "matmat(a, b)") - protected RComplexVector matmatmult(RAbstractLogicalVector a, RAbstractComplexVector b) { - return matmatmult(RClosures.createLogicalToComplexVector(a), b); - } - - @Specialization(guards = "vecvec(a, b)") - protected RComplexVector vecvecmult(RAbstractLogicalVector a, RAbstractComplexVector b) { - return vecvecmult(RClosures.createLogicalToComplexVector(a), b); - } - - @Specialization(guards = "matvec(a, b)") - protected RComplexVector matvecmult(RAbstractLogicalVector a, RAbstractComplexVector b) { - return matvecmult(RClosures.createLogicalToComplexVector(a), b); - } - - @Specialization(guards = "vecmat(a, b)") - protected RComplexVector vecmatmult(RAbstractLogicalVector a, RAbstractComplexVector b) { - return vecmatmult(RClosures.createLogicalToComplexVector(a), b); - } - - @Specialization(guards = "matmat(a, b)") - protected RComplexVector matmatmult(RAbstractComplexVector a, RAbstractLogicalVector b) { - return matmatmult(a, RClosures.createLogicalToComplexVector(b)); - } - - @Specialization(guards = "vecvec(a, b)") - protected RComplexVector vecvecmult(RAbstractComplexVector a, RAbstractLogicalVector b) { - return vecvecmult(a, RClosures.createLogicalToComplexVector(b)); - } - - @Specialization(guards = "matvec(a, b)") - protected RComplexVector matvecmult(RAbstractComplexVector a, RAbstractLogicalVector b) { - return matvecmult(a, RClosures.createLogicalToComplexVector(b)); - } - - @Specialization(guards = "vecmat(a, b)") - protected RComplexVector vecmatmult(RAbstractComplexVector a, RAbstractLogicalVector b) { - return vecmatmult(a, RClosures.createLogicalToComplexVector(b)); - } - - @Specialization(guards = "matmat(a, b)") - protected RComplexVector matmatmult(RAbstractDoubleVector a, RAbstractComplexVector b) { - return matmatmult(RClosures.createDoubleToComplexVector(a), b); - } - - @Specialization(guards = "vecvec(a, b)") - protected RComplexVector vecvecmult(RAbstractDoubleVector a, RAbstractComplexVector b) { - return vecvecmult(RClosures.createDoubleToComplexVector(a), b); - } - - @Specialization(guards = "matvec(a, b)") - protected RComplexVector matvecmult(RAbstractDoubleVector a, RAbstractComplexVector b) { - return matvecmult(RClosures.createDoubleToComplexVector(a), b); + @Specialization + protected RComplexVector multiply(RAbstractIntVector a, RAbstractComplexVector b, + @Cached("createBinaryProfile()") ConditionProfile aIsMatrix, + @Cached("createBinaryProfile()") ConditionProfile bIsMatrix) { + return multiply(RClosures.createIntToComplexVector(a), b, aIsMatrix, bIsMatrix); } - @Specialization(guards = "vecmat(a, b)") - protected RComplexVector vecmatmult(RAbstractDoubleVector a, RAbstractComplexVector b) { - return vecmatmult(RClosures.createDoubleToComplexVector(a), b); + @Specialization + protected RComplexVector multiply(RAbstractComplexVector a, RAbstractIntVector b, + @Cached("createBinaryProfile()") ConditionProfile aIsMatrix, + @Cached("createBinaryProfile()") ConditionProfile bIsMatrix) { + return multiply(a, RClosures.createIntToComplexVector(b), aIsMatrix, bIsMatrix); } - @Specialization(guards = "matmat(a, b)") - protected RComplexVector matmatmult(RAbstractComplexVector a, RAbstractDoubleVector b) { - return matmatmult(a, RClosures.createDoubleToComplexVector(b)); + @Specialization + protected RComplexVector multiply(RAbstractLogicalVector a, RAbstractComplexVector b, + @Cached("createBinaryProfile()") ConditionProfile aIsMatrix, + @Cached("createBinaryProfile()") ConditionProfile bIsMatrix) { + return multiply(RClosures.createLogicalToComplexVector(a), b, aIsMatrix, bIsMatrix); } - @Specialization(guards = "vecvec(a, b)") - protected RComplexVector vecvecmult(RAbstractComplexVector a, RAbstractDoubleVector b) { - return vecvecmult(a, RClosures.createDoubleToComplexVector(b)); + @Specialization + protected RComplexVector multiply(RAbstractComplexVector a, RAbstractLogicalVector b, + @Cached("createBinaryProfile()") ConditionProfile aIsMatrix, + @Cached("createBinaryProfile()") ConditionProfile bIsMatrix) { + return multiply(a, RClosures.createLogicalToComplexVector(b), aIsMatrix, bIsMatrix); } - @Specialization(guards = "matvec(a, b)") - protected RComplexVector matvecmult(RAbstractComplexVector a, RAbstractDoubleVector b) { - return matvecmult(a, RClosures.createDoubleToComplexVector(b)); + @Specialization + protected RComplexVector multiply(RAbstractDoubleVector a, RAbstractComplexVector b, + @Cached("createBinaryProfile()") ConditionProfile aIsMatrix, + @Cached("createBinaryProfile()") ConditionProfile bIsMatrix) { + return multiply(RClosures.createDoubleToComplexVector(a), b, aIsMatrix, bIsMatrix); } - @Specialization(guards = "vecmat(a, b)") - protected RComplexVector vecmatmult(RAbstractComplexVector a, RAbstractDoubleVector b) { - return vecmatmult(a, RClosures.createDoubleToComplexVector(b)); + @Specialization + protected RComplexVector multiply(RAbstractComplexVector a, RAbstractDoubleVector b, + @Cached("createBinaryProfile()") ConditionProfile aIsMatrix, + @Cached("createBinaryProfile()") ConditionProfile bIsMatrix) { + return multiply(a, RClosures.createDoubleToComplexVector(b), aIsMatrix, bIsMatrix); } // to double - @Specialization(guards = "matmat(a, b)") - protected RDoubleVector matmatmult(RAbstractIntVector a, RAbstractDoubleVector b) { - return matmatmult(RClosures.createIntToDoubleVector(a), b); - } - - @Specialization(guards = "vecvec(a, b)") - protected RDoubleVector vecvecmult(RAbstractIntVector a, RAbstractDoubleVector b) { - return vecvecmult(RClosures.createIntToDoubleVector(a), b); - } - - @Specialization(guards = "matvec(a, b)") - protected RDoubleVector matvecmult(RAbstractIntVector a, RAbstractDoubleVector b) { - return matvecmult(RClosures.createIntToDoubleVector(a), b); - } - - @Specialization(guards = "vecmat(a, b)") - protected RDoubleVector vecmatmult(RAbstractIntVector a, RAbstractDoubleVector b) { - return vecmatmult(RClosures.createIntToDoubleVector(a), b); - } - - @Specialization(guards = "matmat(a, b)") - protected RDoubleVector matmatmult(RAbstractDoubleVector a, RAbstractIntVector b) { - return matmatmult(a, RClosures.createIntToDoubleVector(b)); - } - - @Specialization(guards = "vecvec(a, b)") - protected RDoubleVector vecvecmult(RAbstractDoubleVector a, RAbstractIntVector b) { - return vecvecmult(a, RClosures.createIntToDoubleVector(b)); - } - - @Specialization(guards = "matvec(a, b)") - protected RDoubleVector matvecmult(RAbstractDoubleVector a, RAbstractIntVector b) { - return matvecmult(a, RClosures.createIntToDoubleVector(b)); - } - - @Specialization(guards = "vecmat(a, b)") - protected RDoubleVector vecmatmult(RAbstractDoubleVector a, RAbstractIntVector b) { - return vecmatmult(a, RClosures.createIntToDoubleVector(b)); - } - - @Specialization(guards = "matmat(a, b)") - protected RDoubleVector matmatmult(RAbstractLogicalVector a, RAbstractDoubleVector b) { - return matmatmult(RClosures.createLogicalToDoubleVector(a), b); - } - - @Specialization(guards = "vecvec(a, b)") - protected RDoubleVector vecvecmult(RAbstractLogicalVector a, RAbstractDoubleVector b) { - return vecvecmult(RClosures.createLogicalToDoubleVector(a), b); - } - - @Specialization(guards = "matvec(a, b)") - protected RDoubleVector matvecmult(RAbstractLogicalVector a, RAbstractDoubleVector b) { - return matvecmult(RClosures.createLogicalToDoubleVector(a), b); - } - - @Specialization(guards = "vecmat(a, b)") - protected RDoubleVector vecmatmult(RAbstractLogicalVector a, RAbstractDoubleVector b) { - return vecmatmult(RClosures.createLogicalToDoubleVector(a), b); - } - - @Specialization(guards = "matmat(a, b)") - protected RDoubleVector matmatmult(RAbstractDoubleVector a, RAbstractLogicalVector b) { - return matmatmult(a, RClosures.createLogicalToDoubleVector(b)); - } - - @Specialization(guards = "vecvec(a, b)") - protected RDoubleVector vecvecmult(RAbstractDoubleVector a, RAbstractLogicalVector b) { - return vecvecmult(a, RClosures.createLogicalToDoubleVector(b)); - } - - @Specialization(guards = "matvec(a, b)") - protected RDoubleVector matvecmult(RAbstractDoubleVector a, RAbstractLogicalVector b) { - return matvecmult(a, RClosures.createLogicalToDoubleVector(b)); - } - - @Specialization(guards = "vecmat(a, b)") - protected RDoubleVector vecmatmult(RAbstractDoubleVector a, RAbstractLogicalVector b) { - return vecmatmult(a, RClosures.createLogicalToDoubleVector(b)); - } - - // errors - - @SuppressWarnings("unused") @Specialization - protected RDoubleVector doRaw(RAbstractRawVector a, Object b) { - throw RError.error(this, RError.Message.NUMERIC_COMPLEX_MATRIX_VECTOR); + protected RDoubleVector multiply(RAbstractIntVector a, RAbstractDoubleVector b, + @Cached("createBinaryProfile()") ConditionProfile aIsMatrix, + @Cached("createBinaryProfile()") ConditionProfile bIsMatrix, + @Cached("createBinaryProfile()") ConditionProfile lengthEquals) { + return multiply(RClosures.createIntToDoubleVector(a), b, aIsMatrix, bIsMatrix, lengthEquals); } - @SuppressWarnings("unused") @Specialization - protected RDoubleVector doRaw(Object a, RAbstractRawVector b) { - throw RError.error(this, RError.Message.NUMERIC_COMPLEX_MATRIX_VECTOR); + protected RDoubleVector multiply(RAbstractDoubleVector a, RAbstractIntVector b, + @Cached("createBinaryProfile()") ConditionProfile aIsMatrix, + @Cached("createBinaryProfile()") ConditionProfile bIsMatrix, + @Cached("createBinaryProfile()") ConditionProfile lengthEquals) { + return multiply(a, RClosures.createIntToDoubleVector(b), aIsMatrix, bIsMatrix, lengthEquals); } - @SuppressWarnings("unused") @Specialization - protected RDoubleVector doString(RAbstractStringVector a, Object b) { - throw RError.error(this, RError.Message.NUMERIC_COMPLEX_MATRIX_VECTOR); + protected RDoubleVector multiply(RAbstractLogicalVector a, RAbstractDoubleVector b, + @Cached("createBinaryProfile()") ConditionProfile aIsMatrix, + @Cached("createBinaryProfile()") ConditionProfile bIsMatrix, + @Cached("createBinaryProfile()") ConditionProfile lengthEquals) { + return multiply(RClosures.createLogicalToDoubleVector(a), b, aIsMatrix, bIsMatrix, lengthEquals); } - @SuppressWarnings("unused") @Specialization - protected RDoubleVector doString(Object a, RAbstractStringVector b) { - throw RError.error(this, RError.Message.NUMERIC_COMPLEX_MATRIX_VECTOR); + protected RDoubleVector multiply(RAbstractDoubleVector a, RAbstractLogicalVector b, + @Cached("createBinaryProfile()") ConditionProfile aIsMatrix, + @Cached("createBinaryProfile()") ConditionProfile bIsMatrix, + @Cached("createBinaryProfile()") ConditionProfile lengthEquals) { + return multiply(a, RClosures.createLogicalToDoubleVector(b), aIsMatrix, bIsMatrix, lengthEquals); } - // guards - - protected static boolean matmat(RAbstractVector a, RAbstractVector b) { - return a.isMatrix() && b.isMatrix(); - } - - protected static boolean vecvec(RAbstractVector a, RAbstractVector b) { - return !a.isMatrix() && !b.isMatrix(); - } + // errors - protected static boolean matvec(RAbstractVector a, RAbstractVector b) { - return a.isMatrix() && !b.isMatrix(); + @Fallback + @TruffleBoundary + protected RDoubleVector doRaw(@SuppressWarnings("unused") Object a, @SuppressWarnings("unused") Object b) { + throw RError.error(this, RError.Message.NUMERIC_COMPLEX_MATRIX_VECTOR); } - protected static boolean vecmat(RAbstractVector a, RAbstractVector b) { - return !a.isMatrix() && b.isMatrix(); - } + // guards protected static boolean bothZeroDim(RAbstractVector a, RAbstractVector b) { return hasZeroDim(a) && hasZeroDim(b); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Match.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Match.java index cb6bdc74d7327e7ab2d8b90e399cdb1ee7bad5b7..01c8a28c2ea9a76d08520759c85f9a87552b409e 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Match.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Match.java @@ -22,8 +22,6 @@ */ package com.oracle.truffle.r.nodes.builtin.base; -import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.instanceOf; -import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.nullValue; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/MatchFun.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/MatchFun.java index c857e315e262208120ed3bc35fcc060748174c39..a147ebce5d8d28ff9da96a6394e2b5b852ef2777 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/MatchFun.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/MatchFun.java @@ -22,11 +22,11 @@ */ package com.oracle.truffle.r.nodes.builtin.base; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.toBoolean; import static com.oracle.truffle.r.runtime.builtins.RBehavior.COMPLEX; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.SUBSTITUTE; import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Fallback; @@ -60,8 +60,6 @@ import com.oracle.truffle.r.runtime.nodes.RSyntaxNode; @RBuiltin(name = "match.fun", kind = SUBSTITUTE, parameterNames = {"fun", "descend"}, nonEvalArgs = 0, behavior = COMPLEX) public abstract class MatchFun extends RBuiltinNode { - @CompilationFinal private String lastFun; - @Override public Object[] getDefaultParameterValues() { return new Object[]{RMissing.instance, RRuntime.LOGICAL_TRUE}; @@ -69,7 +67,7 @@ public abstract class MatchFun extends RBuiltinNode { @Override protected void createCasts(CastBuilder casts) { - casts.firstBoolean(1, "descend"); + casts.arg("descend").asLogicalVector().findFirst().map(toBoolean()); } @Specialization diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Merge.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Merge.java index b8b26c8d0f9fa8c7b49909c99894cce1cb30ab7a..de430557f78ac9b516c9f6a1269c5e3d2e2304ad 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Merge.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Merge.java @@ -12,10 +12,14 @@ package com.oracle.truffle.r.nodes.builtin.base; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.integerValue; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.notEmpty; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.numericValue; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.toBoolean; +import static com.oracle.truffle.r.runtime.RError.Message.INVALID_LOGICAL; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; -import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; @@ -28,13 +32,26 @@ import com.oracle.truffle.r.runtime.data.RList; import com.oracle.truffle.r.runtime.data.RNull; import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector; -@RBuiltin(name = "merge", kind = INTERNAL, parameterNames = {"xinds", "xinds", "all.x", "all.y"}, behavior = PURE) +/** + * Note: invoked from merge.data.frame. + */ +@RBuiltin(name = "merge", kind = INTERNAL, parameterNames = {"xinds", "yinds", "all.x", "all.y"}, behavior = PURE) public abstract class Merge extends RBuiltinNode { @Override protected void createCasts(CastBuilder casts) { - casts.firstLogical(2); - casts.firstLogical(3); + addIntegerCast(casts, "xinds"); + addIntegerCast(casts, "yinds"); + addLogicalCast(casts, "all.x"); + addLogicalCast(casts, "all.y"); + } + + private void addIntegerCast(CastBuilder casts, String name) { + casts.arg(name).mustBe(integerValue()).asIntegerVector().mustBe(notEmpty()); + } + + private void addLogicalCast(CastBuilder casts, String name) { + casts.arg(name).defaultError(INVALID_LOGICAL, "all.x").notNA().mustBe(numericValue()).asLogicalVector().findFirst().map(toBoolean()); } private static void isortWithIndex(int[] x, int[] indx, int n) { @@ -62,8 +79,8 @@ public abstract class Merge extends RBuiltinNode { } } - @Specialization(guards = {"xIndsAbstract.getLength() > 0", "xIndsAbstract.getLength() > 0", "!isNA(allX)", "!isNA(allY)"}) - RList merge(RAbstractIntVector xIndsAbstract, RAbstractIntVector yIndsAbstract, byte allX, byte allY) { + @Specialization + RList merge(RAbstractIntVector xIndsAbstract, RAbstractIntVector yIndsAbstract, boolean allX, boolean allY) { RIntVector xInds = xIndsAbstract.materialize(); RIntVector yInds = yIndsAbstract.materialize(); @@ -139,7 +156,7 @@ public abstract class Merge extends RBuiltinNode { ans.updateDataAt(0, RDataFactory.createIntVector(ansXData, RDataFactory.COMPLETE_VECTOR), null); ans.updateDataAt(1, RDataFactory.createIntVector(ansYData, RDataFactory.COMPLETE_VECTOR), null); - if (allX == RRuntime.LOGICAL_TRUE) { + if (allX) { int[] xLoneData = new int[nxLone]; ans.updateDataAt(2, RDataFactory.createIntVector(xLoneData, RDataFactory.COMPLETE_VECTOR), null); for (int i = 0, ll = 0; i < nxLone; i++) { @@ -149,7 +166,7 @@ public abstract class Merge extends RBuiltinNode { ans.updateDataAt(2, RNull.instance, null); } - if (allY == RRuntime.LOGICAL_TRUE) { + if (allY) { int[] yLoneData = new int[nyLone]; ans.updateDataAt(3, RDataFactory.createIntVector(yLoneData, RDataFactory.COMPLETE_VECTOR), null); for (int i = 0, ll = 0; i < nyLone; i++) { @@ -187,24 +204,4 @@ public abstract class Merge extends RBuiltinNode { return ans; } - - @Fallback - Object merge(Object xInds, Object yInds, byte allX, byte allY) { - if (!(xInds instanceof Integer || (xInds instanceof RAbstractIntVector && ((RAbstractIntVector) xInds).getLength() > 0))) { - throw RError.error(this, RError.Message.INVALID_ARGUMENT, "xinds"); - } - if (!(yInds instanceof Integer || (yInds instanceof RAbstractIntVector && ((RAbstractIntVector) yInds).getLength() > 0))) { - throw RError.error(this, RError.Message.INVALID_ARGUMENT, "yinds"); - } - if (RRuntime.isNA(allX)) { - throw RError.error(this, RError.Message.INVALID_LOGICAL, "all.x"); - } else { - assert RRuntime.isNA(allY); - throw RError.error(this, RError.Message.INVALID_LOGICAL, "all.y"); - } - } - - protected boolean isNA(byte v) { - return RRuntime.isNA(v); - } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/NormalizePath.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/NormalizePath.java index 9d46b2bb64d65873fe9fe27c21622f061d036dea..52cbff0ce02ceead8e3e77bc4bb77cd657abcbd7 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/NormalizePath.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/NormalizePath.java @@ -22,6 +22,11 @@ */ package com.oracle.truffle.r.nodes.builtin.base; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.eq; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.singleElement; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.stringValue; +import static com.oracle.truffle.r.runtime.RError.Message.NOT_CHARACTER_VECTOR; +import static com.oracle.truffle.r.runtime.RError.Message.WRONG_WINSLASH; import static com.oracle.truffle.r.runtime.builtins.RBehavior.IO; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; @@ -33,6 +38,7 @@ import java.nio.file.NoSuchFileException; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.profiles.ConditionProfile; +import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RError.Message; @@ -48,6 +54,15 @@ public abstract class NormalizePath extends RBuiltinNode { private final ConditionProfile doesNotNeedToWork = ConditionProfile.createBinaryProfile(); + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("path").mustBe(stringValue(), NOT_CHARACTER_VECTOR, "path"); + casts.arg("winslash").defaultError(NOT_CHARACTER_VECTOR, "winslash").mustBe(stringValue()).asStringVector().mustBe(singleElement()).findFirst().mustBe(eq("/").or(eq("\\\\")).or(eq("\\")), + WRONG_WINSLASH); + // Note: NA is acceptable value for mustwork with special meaning + casts.arg("mustwork").asLogicalVector().findFirst(); + } + @Specialization @TruffleBoundary protected RStringVector doNormalizePath(RAbstractStringVector pathVec, @SuppressWarnings("unused") String winslash, byte mustWork) { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/OnExit.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/OnExit.java index 0761d7875b918bc0585456735f27084b2550a78f..3eb6440923f772d5c4ba513b9dda0b2723d8a656 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/OnExit.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/OnExit.java @@ -36,6 +36,7 @@ import com.oracle.truffle.api.profiles.BranchProfile; import com.oracle.truffle.api.profiles.ConditionProfile; import com.oracle.truffle.r.nodes.access.ConstantNode; import com.oracle.truffle.r.nodes.access.FrameSlotNode; +import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.runtime.RArguments; import com.oracle.truffle.r.runtime.RError; @@ -65,6 +66,11 @@ public abstract class OnExit extends RBuiltinNode { private final BranchProfile invalidateProfile = BranchProfile.create(); + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("add").asLogicalVector().findFirst(RRuntime.LOGICAL_FALSE); + } + @Override public Object[] getDefaultParameterValues() { return new Object[]{RNull.instance, RRuntime.LOGICAL_FALSE}; diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/OptionsFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/OptionsFunctions.java index 8749d957ebb229eca5851746c446f455812501af..3a6bc80e944456c0f3c0a92a392589bb391cdd28 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/OptionsFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/OptionsFunctions.java @@ -22,6 +22,7 @@ */ package com.oracle.truffle.r.nodes.builtin.base; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.*; import static com.oracle.truffle.r.runtime.RVisibility.CUSTOM; import static com.oracle.truffle.r.runtime.builtins.RBehavior.MODIFIES_STATE; import static com.oracle.truffle.r.runtime.builtins.RBehavior.READS_STATE; @@ -34,6 +35,7 @@ import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.profiles.ConditionProfile; +import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.runtime.ArgumentsSignature; import com.oracle.truffle.r.runtime.RError; @@ -169,6 +171,11 @@ public class OptionsFunctions { @RBuiltin(name = "getOption", kind = INTERNAL, parameterNames = "x", behavior = READS_STATE) public abstract static class GetOption extends RBuiltinNode { + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("x").mustBe(stringValue(), RError.SHOW_CALLER, RError.Message.MUST_BE_STRING, "x").asStringVector().findFirst(); + } + @TruffleBoundary @Specialization protected Object getOption(RAbstractStringVector x) { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Quantifier.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Quantifier.java new file mode 100644 index 0000000000000000000000000000000000000000..0b394130a6bcf3c2843144f35926cd99982ea017 --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Quantifier.java @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.r.nodes.builtin.base; + +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.integerValue; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.logicalValue; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.nullValue; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.toBoolean; + +import java.util.function.Function; + +import com.oracle.truffle.api.CompilerDirectives; +import com.oracle.truffle.api.dsl.Cached; +import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.nodes.ExplodeLoop; +import com.oracle.truffle.api.profiles.BranchProfile; +import com.oracle.truffle.r.nodes.builtin.CastBuilder; +import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; +import com.oracle.truffle.r.nodes.unary.CastNode; +import com.oracle.truffle.r.nodes.unary.TypeofNode; +import com.oracle.truffle.r.runtime.RError; +import com.oracle.truffle.r.runtime.RInternalError; +import com.oracle.truffle.r.runtime.RRuntime; +import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames; +import com.oracle.truffle.r.runtime.data.RMissing; +import com.oracle.truffle.r.runtime.data.RNull; +import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector; +import com.oracle.truffle.r.runtime.ops.na.NACheck; + +public abstract class Quantifier extends RBuiltinNode { + protected static final int MAX_CACHED_LENGTH = 10; + + private final NACheck naCheck = NACheck.create(); + private final BranchProfile trueBranch = BranchProfile.create(); + private final BranchProfile falseBranch = BranchProfile.create(); + + @Child private TypeofNode typeofNode = com.oracle.truffle.r.nodes.unary.TypeofNodeGen.create(); + private final Function<Object, String> argTypeName = arg -> typeofNode.execute(arg).getName(); + + private final CastBuilder argCastBuilder = new CastBuilder(); + + @Children private final CastNode[] argCastNodes = new CastNode[MAX_CACHED_LENGTH]; + + @Override + public Object[] getDefaultParameterValues() { + return new Object[]{RArgsValuesAndNames.EMPTY, RRuntime.LOGICAL_FALSE}; + } + + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("na.rm").asLogicalVector().findFirst(RRuntime.LOGICAL_NA).map(toBoolean()); + } + + private void createArgCast(int index) { + argCastBuilder.arg(index).shouldBe(nullValue().or(integerValue()).or(logicalValue()), RError.Message.COERCING_ARGUMENT, argTypeName, "logical").asLogicalVector(); + argCastNodes[index] = insert(argCastBuilder.getCasts()[index]); + } + + protected boolean emptyVectorResult() { + throw RInternalError.shouldNotReachHere("should be overridden"); + } + + @Specialization + protected byte op(@SuppressWarnings("unused") RNull vector, @SuppressWarnings("unused") boolean naRm) { + return RRuntime.asLogical(emptyVectorResult()); + } + + @Specialization + protected byte op(@SuppressWarnings("unused") RMissing vector, @SuppressWarnings("unused") boolean naRm) { + return RRuntime.asLogical(emptyVectorResult()); + } + + @Specialization(limit = "1", guards = {"cachedLength == args.getLength()", "cachedLength < MAX_CACHED_LENGTH"}) + @ExplodeLoop + protected byte opCachedLength(RArgsValuesAndNames args, boolean naRm, // + @Cached("args.getLength()") int cachedLength) { + Object[] arguments = args.getArguments(); + + byte result = RRuntime.asLogical(emptyVectorResult()); + for (int i = 0; i < cachedLength; i++) { + Object argValue = arguments[i]; + byte v = processArgument(argValue, i, naRm); + if (v == RRuntime.asLogical(!emptyVectorResult())) { + return RRuntime.asLogical(!emptyVectorResult()); + } else if (v == RRuntime.LOGICAL_NA) { + result = RRuntime.LOGICAL_NA; + } + } + return result; + } + + @Specialization(contains = "opCachedLength") + protected byte op(RArgsValuesAndNames args, boolean naRm) { + boolean profiledNaRm = naRm; + + byte result = RRuntime.asLogical(emptyVectorResult()); + for (Object argValue : args.getArguments()) { + byte v = processArgument(argValue, 0, profiledNaRm); + if (v == RRuntime.asLogical(!emptyVectorResult())) { + return RRuntime.asLogical(!emptyVectorResult()); + } else if (v == RRuntime.LOGICAL_NA) { + result = RRuntime.LOGICAL_NA; + } + } + return result; + } + + private byte processArgument(Object argValue, int index, boolean naRm) { + byte result = RRuntime.asLogical(emptyVectorResult()); + if (argValue != RNull.instance) { + if (argCastNodes[index] == null) { + CompilerDirectives.transferToInterpreterAndInvalidate(); + createArgCast(index); + } + Object castValue = argCastNodes[index].execute(argValue); + if (castValue instanceof RAbstractLogicalVector) { + RAbstractLogicalVector vector = (RAbstractLogicalVector) castValue; + naCheck.enable(vector); + for (int i = 0; i < vector.getLength(); i++) { + byte b = vector.getDataAt(i); + if (!naRm && naCheck.check(b)) { + result = RRuntime.LOGICAL_NA; + } else if (b == RRuntime.asLogical(!emptyVectorResult())) { + trueBranch.enter(); + return RRuntime.asLogical(!emptyVectorResult()); + } + } + } else { + byte b = (byte) castValue; + naCheck.enable(true); + if (!naRm && naCheck.check(b)) { + result = RRuntime.LOGICAL_NA; + } else if (b == RRuntime.asLogical(!emptyVectorResult())) { + trueBranch.enter(); + return RRuntime.asLogical(!emptyVectorResult()); + } + } + } + falseBranch.enter(); + return result; + } + +} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ReadDCF.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ReadDCF.java index 3bc66597230371ffa0fbd99c3a8bf37ade867c2d..813c92a2c95ad86f5efadc27eda2eb5ba3554869 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ReadDCF.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ReadDCF.java @@ -22,6 +22,7 @@ */ package com.oracle.truffle.r.nodes.builtin.base; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.*; import static com.oracle.truffle.r.runtime.builtins.RBehavior.IO; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; @@ -33,8 +34,8 @@ import java.util.Map; import java.util.Set; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; -import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.runtime.DCF; import com.oracle.truffle.r.runtime.RError; @@ -50,15 +51,20 @@ import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; @RBuiltin(name = "readDCF", kind = INTERNAL, parameterNames = {"conn", "fields", "keepwhite"}, behavior = IO) public abstract class ReadDCF extends RBuiltinNode { + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("conn").mustBe(RConnection.class); + casts.arg("fields").mapIf(nullValue(), asVector(false)).asStringVector(); + casts.arg("keepwhite").mapIf(nullValue(), asVector(false)).asStringVector(); + } + @Specialization @TruffleBoundary - protected RStringVector doReadDCF(RConnection conn, Object fieldsObj, Object keepWhiteObj) { - RAbstractStringVector fields = fieldsObj == RNull.instance ? null : (RAbstractStringVector) RRuntime.asAbstractVector(fieldsObj); - RAbstractStringVector keepWhite = keepWhiteObj == RNull.instance ? null : (RAbstractStringVector) RRuntime.asAbstractVector(keepWhiteObj); + protected RStringVector doReadDCF(RConnection conn, RAbstractStringVector fields, RAbstractStringVector keepWhite) { DCF dcf = null; try (RConnection openConn = conn.forceOpen("r")) { Set<String> keepWhiteSet = null; - if (keepWhite != null) { + if (keepWhite.getLength() > 0) { keepWhiteSet = new HashSet<>(keepWhite.getLength()); for (int i = 0; i < keepWhite.getLength(); i++) { keepWhiteSet.add(keepWhite.getDataAt(i)); @@ -116,7 +122,7 @@ public abstract class ReadDCF extends RBuiltinNode { } private static boolean needField(String fieldName, RAbstractStringVector fields) { - if (fields == null) { + if (fields.getLength() == 0) { return true; } for (int i = 0; i < fields.getLength(); i++) { @@ -127,9 +133,4 @@ public abstract class ReadDCF extends RBuiltinNode { return false; } - @SuppressWarnings("unused") - @Fallback - protected RStringVector doReadDCF(Object conn, Object fields, Object keepWhite) { - throw RError.error(this, RError.Message.INVALID_OR_UNIMPLEMENTED_ARGUMENTS); - } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ReadREnviron.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ReadREnviron.java index 91d68a96774c913b87f198d21aced47759a51838..dc155922033fcc9e97304de53e5470078165a209 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ReadREnviron.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ReadREnviron.java @@ -22,6 +22,7 @@ */ package com.oracle.truffle.r.nodes.builtin.base; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.*; import static com.oracle.truffle.r.runtime.RVisibility.OFF; import static com.oracle.truffle.r.runtime.builtins.RBehavior.COMPLEX; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; @@ -30,23 +31,25 @@ import java.io.FileNotFoundException; import java.io.IOException; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; -import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RRuntime; -import com.oracle.truffle.r.runtime.Utils; import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.context.RContext; -import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; -@RBuiltin(name = "readRenviron", visibility = OFF, kind = INTERNAL, parameterNames = "path", behavior = COMPLEX) +@RBuiltin(name = "readRenviron", visibility = OFF, kind = INTERNAL, parameterNames = "x", behavior = COMPLEX) public abstract class ReadREnviron extends RBuiltinNode { - @Specialization(guards = "lengthOneCVector(vec)") + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("x").mustBe(stringValue(), RError.SHOW_CALLER, RError.Message.ARGUMENT_MUST_BE_STRING, "x").asStringVector().findFirst(); + } + @TruffleBoundary - protected Object doReadEnviron(RAbstractStringVector vec) { - String path = Utils.tildeExpand(vec.getDataAt(0)); + @Specialization + protected Object doReadEnviron(String path) { byte result = RRuntime.LOGICAL_TRUE; try { RContext.getInstance().stateREnvVars.readEnvironFile(path); @@ -59,12 +62,4 @@ public abstract class ReadREnviron extends RBuiltinNode { return result; } - @Fallback - protected Object doReadEnviron(@SuppressWarnings("unused") Object vec) { - throw RError.error(this, RError.Message.ARGUMENT_MUST_BE_STRING, "x"); - } - - protected static boolean lengthOneCVector(RAbstractStringVector vec) { - return vec.getLength() == 1; - } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Readline.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Readline.java index 63d70486b2bf75f7fd5b293fdf39bd0454bed25d..41f4eb9edbf28b16507ff62062abc6b9f5758287 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Readline.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Readline.java @@ -27,6 +27,7 @@ import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.context.ConsoleHandler; @@ -35,6 +36,12 @@ import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; @RBuiltin(name = "readline", kind = INTERNAL, parameterNames = "prompt", behavior = IO) public abstract class Readline extends RBuiltinNode { + + @Override + protected void createCasts(CastBuilder casts) { + casts.arg("prompt").asStringVector().findFirst(""); + } + @Specialization @TruffleBoundary protected String readline(RAbstractStringVector prompt) { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Repeat.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Repeat.java index 12b25af55ac9e6b46c1311898a4f3e526d8bc076..ba423dae3cbafc423b481033a8fb9b51cba8348a 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Repeat.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Repeat.java @@ -22,11 +22,13 @@ */ package com.oracle.truffle.r.nodes.builtin.base; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.*; import static com.oracle.truffle.r.runtime.RDispatch.INTERNAL_GENERIC; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; import java.util.Arrays; +import java.util.function.Function; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.profiles.BranchProfile; @@ -40,6 +42,7 @@ import com.oracle.truffle.r.runtime.data.RAttributeProfiles; import com.oracle.truffle.r.runtime.data.RDataFactory; import com.oracle.truffle.r.runtime.data.RMissing; import com.oracle.truffle.r.runtime.data.RStringVector; +import com.oracle.truffle.r.runtime.data.RTypedValue; import com.oracle.truffle.r.runtime.data.RVector; import com.oracle.truffle.r.runtime.data.model.RAbstractDoubleVector; import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector; @@ -81,11 +84,17 @@ public abstract class Repeat extends RBuiltinNode { return new Object[]{RMissing.instance, 1, RRuntime.INT_NA, 1}; } + private String argType(Object arg) { + return ((RTypedValue) arg).getRType().getName(); + } + @Override protected void createCasts(CastBuilder casts) { - casts.toInteger(1); - casts.firstIntegerWithWarning(2, RRuntime.INT_NA, "length.out"); - casts.toInteger(3); + Function<Object, Object> argType = this::argType; + casts.arg("x").mustBe(abstractVectorValue(), RError.Message.ATTEMPT_TO_REPLICATE, argType); + casts.arg("times").defaultError(RError.Message.INVALID_ARGUMENT, "times").mustBe(nullValue().not()).asIntegerVector(); + casts.arg("length.out").asIntegerVector().shouldBe(size(1), RError.Message.FIRST_ELEMENT_USED, "length.out").findFirst(1); + casts.arg("each").asIntegerVector().shouldBe(size(1), RError.Message.FIRST_ELEMENT_USED, "each").findFirst(1); } protected boolean hasNames(RAbstractVector x) { @@ -98,7 +107,12 @@ public abstract class Repeat extends RBuiltinNode { @Specialization(guards = {"x.getLength() == 1", "times.getLength() == 1", "each <= 1", "!hasNames(x)"}) protected RAbstractVector repNoEachNoNamesSimple(RAbstractDoubleVector x, RAbstractIntVector times, int lengthOut, @SuppressWarnings("unused") int each) { - int length = lengthOutOrTimes.profile(!RRuntime.isNA(lengthOut)) ? lengthOut : times.getDataAt(0); + int t = times.getDataAt(0); + if (t < 0) { + errorBranch.enter(); + throw invalidTimes(); + } + int length = lengthOutOrTimes.profile(!RRuntime.isNA(lengthOut)) ? lengthOut : t; double[] data = new double[length]; Arrays.fill(data, x.getDataAt(0)); return RDataFactory.createDoubleVector(data, !RRuntime.isNA(x.getDataAt(0))); @@ -193,6 +207,10 @@ public abstract class Repeat extends RBuiltinNode { if (oneTimeGiven.profile(times.getLength() == 1)) { // only one times value is given final int howManyTimes = times.getDataAt(0); + if (howManyTimes < 0) { + errorBranch.enter(); + throw invalidTimes(); + } if (replicateOnce.profile(howManyTimes == 1)) { return (RVector) (copyIfSameSize ? x.copy() : x); } else { @@ -207,7 +225,12 @@ public abstract class Repeat extends RBuiltinNode { // iterate once over the times vector to determine result vector size int resultLength = 0; for (int i = 0; i < times.getLength(); i++) { - resultLength += times.getDataAt(i); + int t = times.getDataAt(i); + if (t < 0) { + errorBranch.enter(); + throw invalidTimes(); + } + resultLength += t; } // create and populate result vector RVector r = x.createEmptySameType(resultLength, x.isComplete()); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/RepeatInternal.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/RepeatInternal.java index 8515c9e92f97f8d0774f9f5ba2062522ec66dce0..7f06094b149caf725d448d3d353e6247432bd069 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/RepeatInternal.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/RepeatInternal.java @@ -22,9 +22,11 @@ */ package com.oracle.truffle.r.nodes.builtin.base; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.*; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; +import java.util.function.Function; import java.util.function.IntFunction; import com.oracle.truffle.api.dsl.Specialization; @@ -41,6 +43,7 @@ import com.oracle.truffle.r.runtime.data.RList; import com.oracle.truffle.r.runtime.data.RLogicalVector; import com.oracle.truffle.r.runtime.data.RRawVector; import com.oracle.truffle.r.runtime.data.RStringVector; +import com.oracle.truffle.r.runtime.data.RTypedValue; import com.oracle.truffle.r.runtime.data.model.RAbstractDoubleVector; import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector; import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector; @@ -54,9 +57,16 @@ public abstract class RepeatInternal extends RBuiltinNode { private final ConditionProfile timesOneProfile = ConditionProfile.createBinaryProfile(); private final BranchProfile errorProfile = BranchProfile.create(); + private String argType(Object arg) { + return ((RTypedValue) arg).getRType().getName(); + } + @Override protected void createCasts(CastBuilder casts) { - casts.toInteger(1); + Function<Object, Object> argType = this::argType; + casts.arg("x").mustBe(abstractVectorValue(), RError.SHOW_CALLER2, RError.Message.ATTEMPT_TO_REPLICATE, argType); + casts.arg("times").mustBe(abstractVectorValue(), RError.SHOW_CALLER, RError.Message.INCORRECT_ARG_TYPE, "second").asIntegerVector().mustBe(notEmpty(), RError.SHOW_CALLER, + RError.Message.INVALID_VALUE, "times"); } @FunctionalInterface @@ -76,6 +86,10 @@ public abstract class RepeatInternal extends RBuiltinNode { int valueLength = value.getLength(); if (timesOneProfile.profile(timesLength == 1)) { int timesValue = times.getDataAt(0); + if (timesValue < 0) { + errorProfile.enter(); + RError.error(this, RError.Message.INVALID_VALUE, "times"); + } int count = timesValue * valueLength; result = arrayConstructor.apply(count); int pos = 0; diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/RepeatLength.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/RepeatLength.java index 9c4dc2ac4c8f163dfe80726d21008aa929a3003d..da513b499b6d546ca31f20a88fb41a639f317134 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/RepeatLength.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/RepeatLength.java @@ -11,6 +11,7 @@ package com.oracle.truffle.r.nodes.builtin.base; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.*; import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; @@ -19,6 +20,7 @@ import java.util.Arrays; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; +import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.Utils; import com.oracle.truffle.r.runtime.builtins.RBuiltin; @@ -40,7 +42,10 @@ public abstract class RepeatLength extends RBuiltinNode { @Override protected void createCasts(CastBuilder casts) { - casts.toInteger(1); + casts.arg("x").mustBe(abstractVectorValue(), RError.SHOW_CALLER, RError.Message.ATTEMPT_TO_REPLICATE_NO_VECTOR); + // with default error message, SHOW_CALLER does not work + casts.arg("length.out").asIntegerVector().mustBe(size(1), RError.SHOW_CALLER, RError.Message.INVALID_VALUE, "length.out").findFirst(1).mustBe(notIntNA(), RError.SHOW_CALLER, + RError.Message.INVALID_VALUE, "length.out"); } @Specialization diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Rm.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Rm.java index 9005d96018a4e211fafd22acff0b1c4ad1985661..1179ceb44c580aa2af3a8a36cc0441b7e695e79b 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Rm.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Rm.java @@ -69,7 +69,7 @@ public abstract class Rm extends RBuiltinNode { } } } catch (PutException ex) { - throw RError.error(this, ex); + throw RError.error(RError.SHOW_CALLER, ex); } return RNull.instance; } @@ -85,7 +85,7 @@ public abstract class Rm extends RBuiltinNode { } } if (fs == null) { - RError.warning(this, RError.Message.UNKNOWN_OBJECT, x); + RError.warning(RError.SHOW_CALLER, RError.Message.UNKNOWN_OBJECT, x); } else { // use null (not an R value) to represent "undefined" FrameSlotChangeMonitor.setObjectAndInvalidate(frame, fs, null, false, invalidateProfile); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Seq.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Seq.java index 4d9963247acf9d1ae12a76b1155dd7cf855a65d3..3bb2747dee091d09176403b87d89c8891163dbef 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Seq.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Seq.java @@ -26,9 +26,11 @@ import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.SUBSTITUTE; import com.oracle.truffle.api.CompilerDirectives; +import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.profiles.BranchProfile; import com.oracle.truffle.api.profiles.ConditionProfile; +import com.oracle.truffle.r.nodes.builtin.CastBuilder; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RRuntime; @@ -55,6 +57,7 @@ import com.oracle.truffle.r.runtime.ops.na.NACheck; public abstract class Seq extends RBuiltinNode { private final ConditionProfile lengthProfile1 = ConditionProfile.createBinaryProfile(); private final ConditionProfile lengthProfile2 = ConditionProfile.createBinaryProfile(); + private final ConditionProfile topLengthProfile = ConditionProfile.createBinaryProfile(); private final BranchProfile error = BranchProfile.create(); @Child private Seq seqRecursive; @@ -112,7 +115,7 @@ public abstract class Seq extends RBuiltinNode { private void validateParams(double start, double to) { validateParam(start, "from"); - validateParam(start, "to"); + validateParam(to, "to"); } private void validateParams(RAbstractDoubleVector start, RAbstractDoubleVector to) { @@ -124,15 +127,6 @@ public abstract class Seq extends RBuiltinNode { } } - private void validateParams(RAbstractLogicalVector start, RAbstractLogicalVector to) { - if (start != null) { - validateParam(RRuntime.logical2int(start.getDataAt(0)), "from"); - } - if (to != null) { - validateParam(RRuntime.logical2int(start.getDataAt(0)), "to"); - } - } - private RDoubleVector getVectorWithComputedStride(double start, double to, double lengthOut, boolean ascending) { validateParams(start, to); int length = (int) Math.ceil(lengthOut); @@ -183,322 +177,368 @@ public abstract class Seq extends RBuiltinNode { return RDataFactory.createIntSequence(1, 1, start.getLength()); } - // int vector start, missing to + @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "zero(start, to)"}) + protected int seqZero(RAbstractIntVector start, RAbstractIntVector to, Object stride, RMissing lengthOut, RMissing alongWith) { + return 0; + } - @Specialization(guards = "!startEmpty(start)") - protected RIntSequence seqFromOneArg(RAbstractIntVector start, RMissing to, RMissing stride, RMissing lengthOut, RMissing alongWith) { - validateParam(start.getDataAt(0), "to"); - // GNU R really does that (take the length of start to create a sequence) - return RDataFactory.createIntSequence(1, 1, start.getLength()); + @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "zero(start, to)"}) + protected int seqZero(RAbstractDoubleVector start, RAbstractIntVector to, Object stride, RMissing lengthOut, RMissing alongWith) { + return 0; } - @Specialization(guards = "startEmpty(start)") - protected RIntVector seqFromOneArgEmpty(RAbstractIntVector start, RMissing to, RMissing stride, RMissing lengthOut, RMissing alongWith) { - return RDataFactory.createEmptyIntVector(); + @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "zero(start, to)"}) + protected int seqZero(RAbstractIntVector start, RAbstractDoubleVector to, Object stride, RMissing lengthOut, RMissing alongWith) { + return 0; } - @Specialization(guards = {"startLengthOne(start)", "!lengthZero(lengthOut)"}) - protected RDoubleSequence seq(RAbstractIntVector start, RMissing to, RMissing stride, int lengthOut, RMissing alongWith) { - validateParam(start.getDataAt(0), "from"); - return RDataFactory.createDoubleSequence(RRuntime.int2double(start.getDataAt(0)), 1, lengthOut); + @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "zero(start, to)"}) + protected int seqZero(RAbstractDoubleVector start, RAbstractDoubleVector to, Object stride, RMissing lengthOut, RMissing alongWith) { + return 0; } - @Specialization(guards = {"startLengthOne(start)", "!lengthZero(lengthOut)"}) - protected RDoubleSequence seq(RAbstractIntVector start, RMissing to, RMissing stride, double lengthOut, RMissing alongWith) { - validateParam(start.getDataAt(0), "from"); - return RDataFactory.createDoubleSequence(RRuntime.int2double(start.getDataAt(0)), 1, (int) Math.ceil(lengthOut)); + // int vector start, missing to + + @Specialization + protected RAbstractIntVector seqFromOneArg(RAbstractIntVector start, RMissing to, RMissing stride, RMissing lengthOut, RMissing alongWith) { + if (topLengthProfile.profile(start.getLength() == 0)) { + return RDataFactory.createEmptyIntVector(); + } else { + validateParam(start.getDataAt(0), "to"); + // GNU R really does that (take the length of start to create a sequence) + return RDataFactory.createIntSequence(1, 1, start.getLength()); + } } - @Specialization(guards = {"startLengthOne(start)", "lengthZero(lengthOut)"}) - protected RIntVector seqLengthZero(RAbstractIntVector start, RMissing to, RMissing stride, int lengthOut, RMissing alongWith) { + @Specialization + protected RAbstractVector seq(RAbstractIntVector start, RMissing to, RMissing stride, int lengthOut, RMissing alongWith) { + startLengthOne(start); validateParam(start.getDataAt(0), "from"); - return RDataFactory.createEmptyIntVector(); + if (topLengthProfile.profile(lengthOut == 0)) { + return RDataFactory.createEmptyIntVector(); + } else { + return RDataFactory.createDoubleSequence(RRuntime.int2double(start.getDataAt(0)), 1, lengthOut); + } } - @Specialization(guards = {"startLengthOne(start)", "lengthZero(lengthOut)"}) - protected RIntVector seqLengthZero(RAbstractIntVector start, RMissing to, RMissing stride, double lengthOut, RMissing alongWith) { + @Specialization + protected RAbstractVector seq(RAbstractIntVector start, RMissing to, RMissing stride, double lengthOut, RMissing alongWith) { + startLengthOne(start); validateParam(start.getDataAt(0), "from"); - return RDataFactory.createEmptyIntVector(); + if (topLengthProfile.profile(lengthOut == 0)) { + return RDataFactory.createEmptyIntVector(); + } else { + return RDataFactory.createDoubleSequence(RRuntime.int2double(start.getDataAt(0)), 1, (int) Math.ceil(lengthOut)); + } } // int vector start, int vector to - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "zero(start, to)"}) - protected int seqZero(RAbstractIntVector start, RAbstractIntVector to, Object stride, RMissing lengthOut, RMissing alongWith) { - return 0; - } - - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "!zero(start, to)"}) - protected RIntSequence seq(RAbstractIntVector start, RAbstractIntVector to, RMissing stride, RMissing lengthOut, RMissing alongWith) { + @Specialization + protected Object seq(RAbstractIntVector start, RAbstractIntVector to, RMissing stride, RMissing lengthOut, RMissing alongWith) { + startLengthOne(start); + toLengthOne(to); validateParams(start, to); - return RDataFactory.createIntSequence(start.getDataAt(0), ascending(start, to) ? 1 : -1, Math.abs(to.getDataAt(0) - start.getDataAt(0)) + 1); + if (topLengthProfile.profile(zero(start, to))) { + return 0; + } else { + return RDataFactory.createIntSequence(start.getDataAt(0), ascending(start, to) ? 1 : -1, Math.abs(to.getDataAt(0) - start.getDataAt(0)) + 1); + } } - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "!zero(start, to)"}) - protected RIntSequence seq(RAbstractIntVector start, RAbstractIntVector to, int stride, RMissing lengthOut, RMissing alongWith) { + @Specialization + protected Object seq(RAbstractIntVector start, RAbstractIntVector to, int stride, RMissing lengthOut, RMissing alongWith) { + startLengthOne(start); + toLengthOne(to); validateParams(start, to); - return RDataFactory.createIntSequence(start.getDataAt(0), stride, Math.abs((to.getDataAt(0) - start.getDataAt(0)) / stride) + 1); + if (topLengthProfile.profile(zero(start, to))) { + return 0; + } else { + return RDataFactory.createIntSequence(start.getDataAt(0), stride, Math.abs((to.getDataAt(0) - start.getDataAt(0)) / stride) + 1); + } } - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "!zero(start, to)"}) - protected RDoubleSequence seq(RAbstractIntVector start, RAbstractIntVector to, double stride, RMissing lengthOut, RMissing alongWith) { + @Specialization + protected Object seq(RAbstractIntVector start, RAbstractIntVector to, double stride, RMissing lengthOut, RMissing alongWith) { + startLengthOne(start); + toLengthOne(to); validateParams(start, to); - return RDataFactory.createDoubleSequence(RRuntime.int2double(start.getDataAt(0)), stride, (int) (Math.abs((to.getDataAt(0) - start.getDataAt(0)) / stride)) + 1); + if (topLengthProfile.profile(zero(start, to))) { + return 0; + } else { + return RDataFactory.createDoubleSequence(RRuntime.int2double(start.getDataAt(0)), stride, (int) (Math.abs((to.getDataAt(0) - start.getDataAt(0)) / stride)) + 1); + } } - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "!lengthZero(lengthOut)"}) + @Specialization protected RIntVector seq(RAbstractIntVector start, RAbstractIntVector to, RMissing stride, int lengthOut, RMissing alongWith) { - validateParams(start, to); - return getVectorWithComputedStride(start.getDataAt(0), to.getDataAt(0), RRuntime.int2double(lengthOut), ascending(start, to)); + startLengthOne(start); + toLengthOne(to); + if (topLengthProfile.profile(lengthOut == 0)) { + validateParams(start, to); + return RDataFactory.createEmptyIntVector(); + } else { + validateParams(start, to); + return getVectorWithComputedStride(start.getDataAt(0), to.getDataAt(0), RRuntime.int2double(lengthOut), ascending(start, to)); + } } - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "!lengthZero(lengthOut)"}) + @Specialization protected RIntVector seq(RAbstractIntVector start, RAbstractIntVector to, RMissing stride, double lengthOut, RMissing alongWith) { - validateParams(start, to); - return getVectorWithComputedStride(start.getDataAt(0), to.getDataAt(0), lengthOut, ascending(start, to)); - } - - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "lengthZero(lengthOut)"}) - protected RIntVector seqLengthZero(RAbstractIntVector start, RAbstractIntVector to, RMissing stride, int lengthOut, RMissing alongWith) { - validateParams(start, to); - return RDataFactory.createEmptyIntVector(); - } - - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "lengthZero(lengthOut)"}) - protected RIntVector seqLengthZero(RAbstractIntVector start, RAbstractIntVector to, RMissing stride, double lengthOut, RMissing alongWith) { - validateParams(start, to); - return RDataFactory.createEmptyIntVector(); - } - - @Specialization(guards = {"startLengthOne(start)", "lengthZeroAlong(alongWith)"}) - protected RIntVector seq(RAbstractIntVector start, RMissing to, RMissing stride, Object lengthOut, RAbstractVector alongWith) { - validateParam(start.getDataAt(0), "from"); - return RDataFactory.createEmptyIntVector(); + startLengthOne(start); + toLengthOne(to); + if (topLengthProfile.profile(lengthOut == 0)) { + validateParams(start, to); + return RDataFactory.createEmptyIntVector(); + } else { + validateParams(start, to); + return getVectorWithComputedStride(start.getDataAt(0), to.getDataAt(0), lengthOut, ascending(start, to)); + } } - @Specialization(guards = {"startLengthOne(start)", "!lengthZeroAlong(alongWith)"}) - protected RDoubleSequence seqLengthZero(RAbstractIntVector start, RMissing to, RMissing stride, Object lengthOut, RAbstractVector alongWith) { - validateParam(start.getDataAt(0), "from"); - return RDataFactory.createDoubleSequence(start.getDataAt(0), 1, alongWith.getLength()); + @Specialization + protected RAbstractVector seq(RAbstractIntVector start, RMissing to, RMissing stride, Object lengthOut, RAbstractVector alongWith) { + startLengthOne(start); + if (topLengthProfile.profile(alongWith.getLength() == 0)) { + validateParam(start.getDataAt(0), "from"); + return RDataFactory.createEmptyIntVector(); + } else { + validateParam(start.getDataAt(0), "from"); + return RDataFactory.createDoubleSequence(start.getDataAt(0), 1, alongWith.getLength()); + } } // int vector start, double vector to - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "zero(start, to)"}) - protected int seqZero(RAbstractIntVector start, RAbstractDoubleVector to, Object stride, RMissing lengthOut, RMissing alongWith) { - return 0; - } - - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "!zero(start, to)"}) - protected RIntSequence seq(RAbstractIntVector start, RAbstractDoubleVector to, RMissing stride, RMissing lengthOut, RMissing alongWith) { - validateParams(start, to); - return RDataFactory.createIntSequence(start.getDataAt(0), ascending(start, to) ? 1 : -1, (int) Math.abs(to.getDataAt(0) - start.getDataAt(0)) + 1); - } - - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "!zero(start, to)"}) - protected RDoubleSequence seq(RAbstractIntVector start, RAbstractDoubleVector to, int stride, RMissing lengthOut, RMissing alongWith) { - validateParams(start, to); - int length = (int) Math.abs(to.getDataAt(0) - start.getDataAt(0)) / stride; - if (start.getDataAt(0) + length * stride == to.getDataAt(0)) { - length++; - } - return RDataFactory.createDoubleSequence(start.getDataAt(0), stride, length); - } - - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "!zero(start, to)"}) - protected RDoubleSequence seq(RAbstractIntVector start, RAbstractDoubleVector to, double stride, RMissing lengthOut, RMissing alongWith) { + @Specialization + protected Object seq(RAbstractIntVector start, RAbstractDoubleVector to, RMissing stride, RMissing lengthOut, RMissing alongWith) { + startLengthOne(start); + toLengthOne(to); validateParams(start, to); - int length = (int) (Math.abs(to.getDataAt(0) - start.getDataAt(0)) / stride); - if (start.getDataAt(0) + length * stride == to.getDataAt(0)) { - length++; + if (topLengthProfile.profile(zero(start, to))) { + return 0; + } else { + return RDataFactory.createIntSequence(start.getDataAt(0), ascending(start, to) ? 1 : -1, (int) Math.abs(to.getDataAt(0) - start.getDataAt(0)) + 1); } - return RDataFactory.createDoubleSequence(start.getDataAt(0), stride, length); } - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "lengthZero(lengthOut)"}) - protected RIntVector seqLengthZero(RAbstractIntVector start, RAbstractDoubleVector to, RMissing stride, int lengthOut, RMissing alongWith) { - validateParams(start, to); - return RDataFactory.createEmptyIntVector(); + @Specialization + protected Object seq(RAbstractIntVector start, RAbstractDoubleVector to, int stride, RMissing lengthOut, RMissing alongWith) { + return seq(start, to, (double) stride, lengthOut, alongWith); } - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "!lengthZero(lengthOut)"}) - protected RDoubleVector seq(RAbstractIntVector start, RAbstractDoubleVector to, RMissing stride, int lengthOut, RMissing alongWith) { + @Specialization + protected Object seq(RAbstractIntVector start, RAbstractDoubleVector to, double stride, RMissing lengthOut, RMissing alongWith) { + startLengthOne(start); + toLengthOne(to); validateParams(start, to); - return getVectorWithComputedStride(RRuntime.int2double(start.getDataAt(0)), to.getDataAt(0), lengthOut, ascending(start, to)); + if (topLengthProfile.profile(zero(start, to))) { + return 0; + } else { + int length = (int) (Math.abs(to.getDataAt(0) - start.getDataAt(0)) / stride); + if (start.getDataAt(0) + length * stride == to.getDataAt(0)) { + length++; + } + return RDataFactory.createDoubleSequence(start.getDataAt(0), stride, length); + } } - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "lengthZero(lengthOut)"}) - protected RIntVector seqLengthZero(RAbstractIntVector start, RAbstractDoubleVector to, RMissing stride, double lengthOut, RMissing alongWith) { + @Specialization + protected RAbstractVector seqLengthZero(RAbstractIntVector start, RAbstractDoubleVector to, RMissing stride, int lengthOut, RMissing alongWith) { + startLengthOne(start); + toLengthOne(to); validateParams(start, to); - return RDataFactory.createEmptyIntVector(); + if (topLengthProfile.profile(lengthOut == 0)) { + return RDataFactory.createEmptyIntVector(); + } else { + return getVectorWithComputedStride(RRuntime.int2double(start.getDataAt(0)), to.getDataAt(0), lengthOut, ascending(start, to)); + } } - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "!lengthZero(lengthOut)"}) - protected RDoubleVector seq(RAbstractIntVector start, RAbstractDoubleVector to, RMissing stride, double lengthOut, RMissing alongWith) { + @Specialization + protected RAbstractVector seqLengthZero(RAbstractIntVector start, RAbstractDoubleVector to, RMissing stride, double lengthOut, RMissing alongWith) { + startLengthOne(start); + toLengthOne(to); validateParams(start, to); - return getVectorWithComputedStride(RRuntime.int2double(start.getDataAt(0)), to.getDataAt(0), lengthOut, ascending(start, to)); + if (topLengthProfile.profile(lengthOut == 0)) { + return RDataFactory.createEmptyIntVector(); + } else { + return getVectorWithComputedStride(RRuntime.int2double(start.getDataAt(0)), to.getDataAt(0), lengthOut, ascending(start, to)); + } } // double vector start, missing to - @Specialization(guards = "!startEmpty(start)") - protected RDoubleSequence seqFromOneArg(RAbstractDoubleVector start, RMissing to, RMissing stride, RMissing lengthOut, RMissing alongWith) { - validateParam(start.getDataAt(0), "from"); - // GNU R really does that (take the length of start to create a sequence) - return RDataFactory.createDoubleSequence(1, 1, start.getLength()); - } - - @Specialization(guards = "startEmpty(start)") - protected RIntVector seqFromOneArgEmpty(RAbstractDoubleVector start, RMissing to, RMissing stride, RMissing lengthOut, RMissing alongWith) { - return RDataFactory.createEmptyIntVector(); - } - - @Specialization(guards = {"startLengthOne(start)", "!lengthZero(lengthOut)"}) - protected RDoubleSequence seqLengthZero(RAbstractDoubleVector start, RMissing to, RMissing stride, int lengthOut, RMissing alongWith) { - validateParam(start.getDataAt(0), "from"); - return RDataFactory.createDoubleSequence(start.getDataAt(0), 1, lengthOut); - } - - @Specialization(guards = {"startLengthOne(start)", "!lengthZero(lengthOut)"}) - protected RDoubleSequence seqLengthZero(RAbstractDoubleVector start, RMissing to, RMissing stride, double lengthOut, RMissing alongWith) { - validateParam(start.getDataAt(0), "from"); - return RDataFactory.createDoubleSequence(start.getDataAt(0), 1, (int) Math.ceil(lengthOut)); - } - - @Specialization(guards = {"startLengthOne(start)", "lengthZero(lengthOut)"}) - protected RIntVector seq(RAbstractDoubleVector start, RMissing to, RMissing stride, int lengthOut, RMissing alongWith) { - validateParam(start.getDataAt(0), "from"); - return RDataFactory.createEmptyIntVector(); + @Specialization + protected RAbstractVector seqFromOneArg(RAbstractDoubleVector start, RMissing to, RMissing stride, RMissing lengthOut, RMissing alongWith) { + if (topLengthProfile.profile(start.getLength() == 0)) { + return RDataFactory.createEmptyIntVector(); + } else { + validateParam(start.getDataAt(0), "from"); + // GNU R really does that (take the length of start to create a sequence) + return RDataFactory.createDoubleSequence(1, 1, start.getLength()); + } } - @Specialization(guards = {"startLengthOne(start)", "lengthZero(lengthOut)"}) - protected RIntVector seq(RAbstractDoubleVector start, RMissing to, RMissing stride, double lengthOut, RMissing alongWith) { + @Specialization + protected RAbstractVector seqStartLengthOne(RAbstractDoubleVector start, RMissing to, RMissing stride, int lengthOut, RMissing alongWith) { + startLengthOne(start); validateParam(start.getDataAt(0), "from"); - return RDataFactory.createEmptyIntVector(); + if (topLengthProfile.profile(lengthOut == 0)) { + return RDataFactory.createEmptyIntVector(); + } else { + return RDataFactory.createDoubleSequence(start.getDataAt(0), 1, lengthOut); + } } - @Specialization(guards = {"startLengthOne(start)", "lengthZeroAlong(alongWith)"}) - protected RIntVector seq(RAbstractDoubleVector start, RMissing to, RMissing stride, Object lengthOut, RAbstractVector alongWith) { + @Specialization + protected RAbstractVector seqStartLengthOne(RAbstractDoubleVector start, RMissing to, RMissing stride, double lengthOut, RMissing alongWith) { + startLengthOne(start); validateParam(start.getDataAt(0), "from"); - return RDataFactory.createEmptyIntVector(); + if (topLengthProfile.profile(lengthOut == 0)) { + return RDataFactory.createEmptyIntVector(); + } else { + return RDataFactory.createDoubleSequence(start.getDataAt(0), 1, (int) Math.ceil(lengthOut)); + } } - @Specialization(guards = {"startLengthOne(start)", "!lengthZeroAlong(alongWith)"}) - protected RDoubleSequence seqLengthZero(RAbstractDoubleVector start, RMissing to, RMissing stride, Object lengthOut, RAbstractVector alongWith) { + @Specialization + protected RAbstractVector seqStartLengthOne(RAbstractDoubleVector start, RMissing to, RMissing stride, Object lengthOut, RAbstractVector alongWith) { + startLengthOne(start); validateParam(start.getDataAt(0), "from"); - return RDataFactory.createDoubleSequence(start.getDataAt(0), 1, alongWith.getLength()); + if (topLengthProfile.profile(alongWith.getLength() == 0)) { + return RDataFactory.createEmptyIntVector(); + } else { + return RDataFactory.createDoubleSequence(start.getDataAt(0), 1, alongWith.getLength()); + } } // double vector start, int vector to - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "zero(start, to)"}) - protected int seqZero(RAbstractDoubleVector start, RAbstractIntVector to, Object stride, RMissing lengthOut, RMissing alongWith) { - return 0; - } - - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "!zero(start, to)"}) - protected RAbstractVector seq(RAbstractDoubleVector start, RAbstractIntVector to, RMissing stride, RMissing lengthOut, RMissing alongWith) { + @Specialization + protected Object seq(RAbstractDoubleVector start, RAbstractIntVector to, RMissing stride, RMissing lengthOut, RMissing alongWith, + @Cached("createBinaryProfile()") ConditionProfile intProfile) { + startLengthOne(start); + toLengthOne(to); validateParams(start, to); - if ((int) start.getDataAt(0) == start.getDataAt(0)) { - return RDataFactory.createIntSequence((int) start.getDataAt(0), ascending(start, to) ? 1 : -1, (int) (Math.abs(to.getDataAt(0) - start.getDataAt(0)) + 1)); + if (topLengthProfile.profile(zero(start, to))) { + return 0; } else { - return RDataFactory.createDoubleSequence(start.getDataAt(0), ascending(start, to) ? 1 : -1, (int) (Math.abs(to.getDataAt(0) - start.getDataAt(0)) + 1)); + if (intProfile.profile((int) start.getDataAt(0) == start.getDataAt(0))) { + return RDataFactory.createIntSequence((int) start.getDataAt(0), ascending(start, to) ? 1 : -1, (int) (Math.abs(to.getDataAt(0) - start.getDataAt(0)) + 1)); + } else { + return RDataFactory.createDoubleSequence(start.getDataAt(0), ascending(start, to) ? 1 : -1, (int) (Math.abs(to.getDataAt(0) - start.getDataAt(0)) + 1)); + } } } - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "!zero(start, to)"}) - protected RDoubleSequence seq(RAbstractDoubleVector start, RAbstractIntVector to, int stride, RMissing lengthOut, RMissing alongWith) { - validateParams(start, to); - return RDataFactory.createDoubleSequence(start.getDataAt(0), stride, (int) Math.abs((to.getDataAt(0) - start.getDataAt(0)) / stride) + 1); - } - - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "!zero(start, to)"}) - protected RDoubleSequence seq(RAbstractDoubleVector start, RAbstractIntVector to, double stride, RMissing lengthOut, RMissing alongWith) { - validateParams(start, to); - return RDataFactory.createDoubleSequence(start.getDataAt(0), stride, (int) Math.abs((to.getDataAt(0) - start.getDataAt(0)) / stride) + 1); - } - - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "lengthZero(lengthOut)"}) - protected RIntVector seqLengthZero(RAbstractDoubleVector start, RAbstractIntVector to, RMissing stride, int lengthOut, RMissing alongWith) { - validateParams(start, to); - return RDataFactory.createEmptyIntVector(); + @Specialization + protected Object seq(RAbstractDoubleVector start, RAbstractIntVector to, int stride, RMissing lengthOut, RMissing alongWith) { + return seq(start, to, (double) stride, lengthOut, alongWith); } - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "!lengthZero(lengthOut)"}) - protected RDoubleVector seq(RAbstractDoubleVector start, RAbstractIntVector to, RMissing stride, int lengthOut, RMissing alongWith) { + @Specialization + protected Object seq(RAbstractDoubleVector start, RAbstractIntVector to, double stride, RMissing lengthOut, RMissing alongWith) { + startLengthOne(start); + toLengthOne(to); validateParams(start, to); - return getVectorWithComputedStride(start.getDataAt(0), RRuntime.int2double(to.getDataAt(0)), lengthOut, ascending(start, to)); + if (topLengthProfile.profile(zero(start, to))) { + return 0; + } else { + return RDataFactory.createDoubleSequence(start.getDataAt(0), stride, (int) Math.abs((to.getDataAt(0) - start.getDataAt(0)) / stride) + 1); + } } - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "lengthZero(lengthOut)"}) - protected RIntVector seqLengthZero(RAbstractDoubleVector start, RAbstractIntVector to, RMissing stride, double lengthOut, RMissing alongWith) { - validateParams(start, to); - return RDataFactory.createEmptyIntVector(); + @Specialization + protected RAbstractVector seqLengthZero(RAbstractDoubleVector start, RAbstractIntVector to, RMissing stride, int lengthOut, RMissing alongWith) { + startLengthOne(start); + toLengthOne(to); + if (topLengthProfile.profile(lengthOut == 0)) { + validateParams(start, to); + return RDataFactory.createEmptyIntVector(); + } else { + validateParams(start, to); + return getVectorWithComputedStride(start.getDataAt(0), RRuntime.int2double(to.getDataAt(0)), lengthOut, ascending(start, to)); + } } - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "!lengthZero(lengthOut)"}) - protected RDoubleVector seq(RAbstractDoubleVector start, RAbstractIntVector to, RMissing stride, double lengthOut, RMissing alongWith) { - validateParams(start, to); - return getVectorWithComputedStride(start.getDataAt(0), RRuntime.int2double(to.getDataAt(0)), lengthOut, ascending(start, to)); + @Specialization + protected RAbstractVector seqLengthZero(RAbstractDoubleVector start, RAbstractIntVector to, RMissing stride, double lengthOut, RMissing alongWith) { + startLengthOne(start); + toLengthOne(to); + if (topLengthProfile.profile(lengthOut == 0)) { + validateParams(start, to); + return RDataFactory.createEmptyIntVector(); + } else { + validateParams(start, to); + return getVectorWithComputedStride(start.getDataAt(0), RRuntime.int2double(to.getDataAt(0)), lengthOut, ascending(start, to)); + } } // double vector start, double vector to - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "zero(start, to)"}) - protected double seq(RAbstractDoubleVector start, RAbstractDoubleVector to, Object stride, RMissing lengthOut, RMissing alongWith) { - return 0; - } - - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "!zero(start, to)"}) - protected RAbstractVector seq(RAbstractDoubleVector start, RAbstractDoubleVector to, RMissing stride, RMissing lengthOut, RMissing alongWith) { + @Specialization + protected Object seq(RAbstractDoubleVector start, RAbstractDoubleVector to, RMissing stride, RMissing lengthOut, RMissing alongWith, // + @Cached("createBinaryProfile()") ConditionProfile intProfile) { + startLengthOne(start); + toLengthOne(to); validateParams(start, to); - if ((int) start.getDataAt(0) == start.getDataAt(0) && (int) to.getDataAt(0) == to.getDataAt(0)) { - return RDataFactory.createIntSequence((int) start.getDataAt(0), ascending(start, to) ? 1 : -1, (int) (Math.abs(to.getDataAt(0) - start.getDataAt(0)) + 1)); + if (topLengthProfile.profile(zero(start, to))) { + return 0; } else { - return RDataFactory.createDoubleSequence(start.getDataAt(0), ascending(start, to) ? 1 : -1, (int) (Math.abs(to.getDataAt(0) - start.getDataAt(0)) + 1)); + if (intProfile.profile((int) start.getDataAt(0) == start.getDataAt(0) && (int) to.getDataAt(0) == to.getDataAt(0))) { + return RDataFactory.createIntSequence((int) start.getDataAt(0), ascending(start, to) ? 1 : -1, (int) (Math.abs(to.getDataAt(0) - start.getDataAt(0)) + 1)); + } else { + return RDataFactory.createDoubleSequence(start.getDataAt(0), ascending(start, to) ? 1 : -1, (int) (Math.abs(to.getDataAt(0) - start.getDataAt(0)) + 1)); + } } } - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "!zero(start, to)"}) - protected RDoubleSequence seq(RAbstractDoubleVector start, RAbstractDoubleVector to, int stride, RMissing lengthOut, RMissing alongWith) { - validateParams(start, to); - return RDataFactory.createDoubleSequence(start.getDataAt(0), stride, (int) (Math.abs((to.getDataAt(0) - start.getDataAt(0)) / stride) + 1)); - } - - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "!zero(start, to)"}) - protected RDoubleSequence seq(RAbstractDoubleVector start, RAbstractDoubleVector to, double stride, RMissing lengthOut, RMissing alongWith) { - validateParams(start, to); - return RDataFactory.createDoubleSequence(start.getDataAt(0), stride, (int) (Math.abs((to.getDataAt(0) - start.getDataAt(0)) / stride) + 1)); - } - - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "!lengthZero(lengthOut)"}) - protected RDoubleVector seq(RAbstractDoubleVector start, RAbstractDoubleVector to, RMissing stride, int lengthOut, RMissing alongWith) { - validateParams(start, to); - return getVectorWithComputedStride(start.getDataAt(0), to.getDataAt(0), RRuntime.int2double(lengthOut), ascending(start, to)); + @Specialization + protected Object seq(RAbstractDoubleVector start, RAbstractDoubleVector to, int stride, RMissing lengthOut, RMissing alongWith) { + return seq(start, to, (double) stride, lengthOut, alongWith); } - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "lengthZero(lengthOut)"}) - protected RIntVector seqLengthZero(RAbstractDoubleVector start, RAbstractDoubleVector to, RMissing stride, int lengthOut, RMissing alongWith) { + @Specialization + protected Object seq(RAbstractDoubleVector start, RAbstractDoubleVector to, double stride, RMissing lengthOut, RMissing alongWith) { + startLengthOne(start); + toLengthOne(to); validateParams(start, to); - return RDataFactory.createEmptyIntVector(); + if (topLengthProfile.profile(zero(start, to))) { + return 0; + } else { + return RDataFactory.createDoubleSequence(start.getDataAt(0), stride, (int) (Math.abs((to.getDataAt(0) - start.getDataAt(0)) / stride) + 1)); + } } - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "!lengthZero(lengthOut)"}) - protected RDoubleVector seq(RAbstractDoubleVector start, RAbstractDoubleVector to, RMissing stride, double lengthOut, RMissing alongWith) { - validateParams(start, to); - return getVectorWithComputedStride(start.getDataAt(0), to.getDataAt(0), lengthOut, ascending(start, to)); + @Specialization + protected RAbstractVector seqLengthZero(RAbstractDoubleVector start, RAbstractDoubleVector to, RMissing stride, int lengthOut, RMissing alongWith) { + startLengthOne(start); + toLengthOne(to); + if (topLengthProfile.profile(lengthOut == 0)) { + validateParams(start, to); + return RDataFactory.createEmptyIntVector(); + } else { + validateParams(start, to); + return getVectorWithComputedStride(start.getDataAt(0), to.getDataAt(0), RRuntime.int2double(lengthOut), ascending(start, to)); + } } - @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "lengthZero(lengthOut)"}) - protected RIntVector seqLengthZero(RAbstractDoubleVector start, RAbstractDoubleVector to, RMissing stride, double lengthOut, RMissing alongWith) { - validateParams(start, to); - return RDataFactory.createEmptyIntVector(); + @Specialization + protected RAbstractVector seqLengthZero(RAbstractDoubleVector start, RAbstractDoubleVector to, RMissing stride, double lengthOut, RMissing alongWith) { + startLengthOne(start); + toLengthOne(to); + if (topLengthProfile.profile(lengthOut == 0)) { + validateParams(start, to); + return RDataFactory.createEmptyIntVector(); + } else { + validateParams(start, to); + return getVectorWithComputedStride(start.getDataAt(0), to.getDataAt(0), lengthOut, ascending(start, to)); + } } // logical vectors - private final NACheck naCheck = NACheck.create(); - @Specialization protected Object seq(RAbstractLogicalVector start, RAbstractLogicalVector to, Object stride, Object lengthOut, Object alongWith) { return seqRecursive(RClosures.createLogicalToDoubleVector(start), RClosures.createLogicalToDoubleVector(to), stride, lengthOut, alongWith); @@ -528,122 +568,57 @@ public abstract class Seq extends RBuiltinNode { return v.getElementClass() == RLogical.class; } - // @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "zero(start, to)"}) - // protected double seq(RAbstractLogicalVector start, RAbstractLogicalVector to, Object stride, - // RMissing lengthOut, RMissing alongWith) { - // controlVisibility(); - // return 0; - // } - // - // @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", "!zero(start, to)"}) - // protected RIntSequence seq(RAbstractLogicalVector start, RAbstractLogicalVector to, RMissing - // stride, RMissing lengthOut, RMissing alongWith) { - // controlVisibility(); - // validateParams(start, to); - // return RDataFactory.createIntSequence(RRuntime.logical2int(start.getDataAt(0)), - // ascending(start, - // to) ? 1 : -1, - // Math.abs(RRuntime.logical2int(to.getDataAt(0)) - RRuntime.logical2int(start.getDataAt(0))) + - // 1); - // } - // - // @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", - // "!lengthZero(lengthOut)"}) - // protected RDoubleVector seq(RAbstractLogicalVector start, RAbstractLogicalVector to, RMissing - // stride, int lengthOut, RMissing alongWith) { - // controlVisibility(); - // validateParams(start, to); - // return getVectorWithComputedStride(RRuntime.logical2double(start.getDataAt(0)), - // RRuntime.logical2double(to.getDataAt(0)), RRuntime.int2double(lengthOut), ascending(start, - // to)); - // } - // - // @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", - // "!lengthZero(lengthOut)"}) - // protected RDoubleVector seq(RAbstractLogicalVector start, RAbstractLogicalVector to, RMissing - // stride, double lengthOut, RMissing alongWith) { - // controlVisibility(); - // validateParams(start, to); - // return getVectorWithComputedStride(RRuntime.logical2double(start.getDataAt(0)), - // RRuntime.logical2double(to.getDataAt(0)), lengthOut, ascending(start, to)); - // } - // - // @Specialization(guards = {"startLengthOne(start)", "toLengthOne(to)", - // "lengthZero(lengthOut)"}) - // protected RIntVector seqLengthZero(RAbstractLogicalVector start, RAbstractLogicalVector to, - // RMissing stride, double lengthOut, RMissing alongWith) { - // controlVisibility(); - // validateParams(start, to); - // return RDataFactory.createEmptyIntVector(); - // } - // - // @Specialization(guards = "!startEmpty(start)") - // protected RIntSequence seqFromOneArg(RAbstractLogicalVector start, RMissing to, RMissing - // stride, - // RMissing lengthOut, RMissing alongWith) { - // controlVisibility(); - // validateParam(RRuntime.logical2int(start.getDataAt(0)), "to"); - // // GNU R really does that (take the length of start to create a sequence) - // return RDataFactory.createIntSequence(1, 1, start.getLength()); - // } - // - // @Specialization(guards = "startEmpty(start)") - // protected RIntVector seqFromOneArgEmpty(RAbstractLogicalVector start, RMissing to, RMissing - // stride, RMissing lengthOut, RMissing alongWith) { - // return RDataFactory.createEmptyIntVector(); - // } - - @Specialization(guards = "lengthZero(lengthOut)") - protected RIntVector seqLengthZero(RMissing start, RMissing to, RMissing stride, int lengthOut, RMissing alongWith) { - return RDataFactory.createEmptyIntVector(); - } - - @Specialization(guards = "!lengthZero(lengthOut)") - protected RIntSequence seq(RMissing start, RMissing to, RMissing stride, int lengthOut, RMissing alongWith) { - return RDataFactory.createIntSequence(1, 1, lengthOut); - } - - @Specialization(guards = "lengthZero(lengthOut)") - protected RIntVector seqLengthZero(RMissing start, RMissing to, RMissing stride, double lengthOut, RMissing alongWith) { - return RDataFactory.createEmptyIntVector(); - } - - @Specialization(guards = "!lengthZero(lengthOut)") - protected RIntSequence seq(RMissing start, RMissing to, RMissing stride, double lengthOut, RMissing alongWith) { - return RDataFactory.createIntSequence(1, 1, (int) Math.ceil(lengthOut)); - } - - @Specialization(guards = "lengthZeroAlong(alongWith)") - protected RIntVector seqLengthZeroAlong(RMissing start, RMissing to, RMissing stride, Object lengthOut, RAbstractVector alongWith) { - return RDataFactory.createEmptyIntVector(); - } - - @Specialization(guards = "!lengthZeroAlong(alongWith)") - protected RIntSequence seq(RMissing start, RMissing to, RMissing stride, Object lengthOut, RAbstractVector alongWith) { - return RDataFactory.createIntSequence(1, 1, alongWith.getLength()); - } - - @Specialization(guards = {"toLengthOne(to)", "positiveLengthOut(lengthOut)"}) + @Specialization + protected RAbstractVector seqLengthZero(RMissing start, RMissing to, RMissing stride, int lengthOut, RMissing alongWith) { + if (topLengthProfile.profile(lengthOut == 0)) { + return RDataFactory.createEmptyIntVector(); + } else { + return RDataFactory.createIntSequence(1, 1, lengthOut); + } + } + + @Specialization + protected RAbstractVector seqLengthZero(RMissing start, RMissing to, RMissing stride, double lengthOut, RMissing alongWith) { + if (topLengthProfile.profile(lengthOut == 0)) { + return RDataFactory.createEmptyIntVector(); + } else { + return RDataFactory.createIntSequence(1, 1, (int) Math.ceil(lengthOut)); + } + } + + @Specialization + protected RAbstractVector seqLengthZeroAlong(RMissing start, RMissing to, RMissing stride, Object lengthOut, RAbstractVector alongWith) { + if (topLengthProfile.profile(alongWith.getLength() == 0)) { + return RDataFactory.createEmptyIntVector(); + } else { + return RDataFactory.createIntSequence(1, 1, alongWith.getLength()); + } + } + + @Specialization protected RDoubleSequence seq(RMissing start, RAbstractIntVector to, RMissing stride, int lengthOut, RMissing alongWith) { + toLengthOne(to); + positiveLengthOut(lengthOut); validateParam(to.getDataAt(0), "to"); return RDataFactory.createDoubleSequence(to.getDataAt(0) - lengthOut + 1, 1, lengthOut); } - @Specialization(guards = {"toLengthOne(to)", "positiveLengthOut(lengthOut)"}) + @Specialization protected RDoubleSequence seq(RMissing start, RAbstractIntVector to, RMissing stride, double lengthOut, RMissing alongWith) { - validateParam(to.getDataAt(0), "to"); - final int intLength = (int) Math.ceil(lengthOut); - return RDataFactory.createDoubleSequence(to.getDataAt(0) - intLength + 1, 1, intLength); + return seq(start, to, stride, (int) Math.ceil(lengthOut), alongWith); } - @Specialization(guards = {"toLengthOne(to)", "positiveLengthOut(lengthOut)"}) + @Specialization protected RDoubleSequence seq(RMissing start, RAbstractDoubleVector to, RMissing stride, double lengthOut, RMissing alongWith) { + toLengthOne(to); + positiveLengthOut(lengthOut); validateParam(to.getDataAt(0), "to"); return RDataFactory.createDoubleSequence(to.getDataAt(0) - lengthOut + 1, 1, (int) Math.ceil(lengthOut)); } - @Specialization(guards = "toLengthOne(to)") + @Specialization protected Object seq(RMissing start, RAbstractVector to, Object stride, RMissing lengthOut, RMissing alongWith) { + toLengthOne(to); return seqRecursive(1.0, to, stride, lengthOut, alongWith); } @@ -683,12 +658,9 @@ public abstract class Seq extends RBuiltinNode { return start.getDataAt(0) == 0 && to.getDataAt(0) == 0; } - protected boolean startEmpty(RAbstractVector start) { - return start.getLength() == 0; - } - protected boolean startLengthOne(RAbstractVector start) { if (start.getLength() != 1) { + error.enter(); throw RError.error(this, RError.Message.MUST_BE_SCALAR, "from"); } return true; @@ -696,25 +668,15 @@ public abstract class Seq extends RBuiltinNode { protected boolean toLengthOne(RAbstractVector to) { if (to.getLength() != 1) { + error.enter(); throw RError.error(this, RError.Message.MUST_BE_SCALAR, "to"); } return true; } - protected boolean lengthZero(int lengthOut) { - return lengthOut == 0; - } - - protected boolean lengthZero(double lengthOut) { - return lengthOut == 0; - } - - protected boolean lengthZeroAlong(RAbstractVector alongWith) { - return alongWith.getLength() == 0; - } - protected boolean positiveLengthOut(int lengthOut) { if (lengthOut < 0) { + error.enter(); throw RError.error(this, RError.Message.MUST_BE_POSITIVE, "length.out"); } return true; @@ -722,6 +684,7 @@ public abstract class Seq extends RBuiltinNode { protected boolean positiveLengthOut(double lengthOut) { if (lengthOut < 0) { + error.enter(); throw RError.error(this, RError.Message.MUST_BE_POSITIVE, "length.out"); } return true; diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/SinkFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/SinkFunctions.java index 2b6ceab4056dc6631ee668e350091ab8bb2a2733..63bae90dc6e0cda03887b0cd17e2a47432be4641 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/SinkFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/SinkFunctions.java @@ -55,15 +55,15 @@ public class SinkFunctions { @Specialization @TruffleBoundary protected RNull sink(RConnection conn, boolean closeOnExit, boolean errcon, boolean split) { - if (errcon) { - // TODO - throw RError.nyi(this, "type=message"); - } if (split) { // TODO throw RError.nyi(this, "split"); } - StdConnections.pushDivertOut(conn, closeOnExit); + if (errcon) { + StdConnections.divertErr(conn); + } else { + StdConnections.pushDivertOut(conn, closeOnExit); + } return RNull.instance; } @@ -97,6 +97,5 @@ public class SinkFunctions { return StdConnections.stderrDiversion(); } } - } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/UpdateDim.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/UpdateDim.java index 9d255dec5bf0fe26971533f3867a15a6f6f27547..3f480667fc3d2080c52c9e8013d90498f965a01d 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/UpdateDim.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/UpdateDim.java @@ -28,11 +28,14 @@ import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.r.nodes.attributes.InitAttributesNode; +import com.oracle.truffle.r.nodes.attributes.PutAttributeNode; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.nodes.function.opt.ReuseNonSharedNode; import com.oracle.truffle.r.nodes.unary.CastIntegerNode; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.builtins.RBuiltin; +import com.oracle.truffle.r.runtime.data.RIntVector; import com.oracle.truffle.r.runtime.data.RNull; import com.oracle.truffle.r.runtime.data.RVector; import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector; @@ -51,16 +54,22 @@ public abstract class UpdateDim extends RBuiltinNode { } @Specialization - protected RAbstractVector updateDim(RAbstractVector vector, RAbstractVector dimensions, // - @Cached("createPreserveNames()") CastIntegerNode castInteger) { + protected RAbstractVector updateDim(RAbstractVector vector, RAbstractVector dimensions, + @Cached("createPreserveNames()") CastIntegerNode castInteger, + @Cached("createDim()") PutAttributeNode putDimensions, + @Cached("create()") InitAttributesNode initAttributes) { if (dimensions.getLength() == 0) { CompilerDirectives.transferToInterpreter(); throw RError.error(this, RError.Message.LENGTH_ZERO_DIM_INVALID); } - int[] dimsData = ((RAbstractIntVector) castInteger.execute(dimensions)).materialize().getDataCopy(); + RIntVector dimensionsMaterialized = ((RAbstractIntVector) castInteger.execute(dimensions)).materialize(); + int[] dimsData = dimensionsMaterialized.getDataCopy(); RVector.verifyDimensions(vector.getLength(), dimsData, this); RVector result = ((RAbstractVector) reuse.execute(vector)).materialize(); - result.resetDimensions(dimsData); + result.setInternalDimensions(dimsData); + result.setInternalNames(null); + result.setInternalDimNames(null); + putDimensions.execute(initAttributes.execute(result), dimensionsMaterialized); return result; } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/fastpaths/AssignFastPath.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/fastpaths/AssignFastPath.java index 80b7588ebc14af89bc0430feece1c59ad42f3ba6..4796242d0fdfba27505a0f57f9c80bbf33e20dd8 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/fastpaths/AssignFastPath.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/fastpaths/AssignFastPath.java @@ -35,29 +35,29 @@ import com.oracle.truffle.r.runtime.nodes.RFastPathNode; public abstract class AssignFastPath extends RFastPathNode { - @Child private Assign assign = AssignNodeGen.create(null); + @Child private Assign assign = AssignNodeGen.create(true, null); @Specialization @SuppressWarnings("unused") - protected Object getNonInherit(VirtualFrame frame, RAbstractStringVector x, Object value, RMissing pos, REnvironment envir, byte inherits, Object immediate) { + protected Object assign(VirtualFrame frame, RAbstractStringVector x, Object value, RMissing pos, REnvironment envir, byte inherits, Object immediate) { return assign.execute(frame, x, value, envir, inherits); } @Specialization @SuppressWarnings("unused") - protected Object getNonInherit(VirtualFrame frame, RAbstractStringVector x, Object value, RMissing pos, REnvironment envir, RMissing inherits, Object immediate) { + protected Object assign(VirtualFrame frame, RAbstractStringVector x, Object value, RMissing pos, REnvironment envir, RMissing inherits, Object immediate) { return assign.execute(frame, x, value, envir, RRuntime.LOGICAL_FALSE); } @Specialization @SuppressWarnings("unused") - protected Object getNonInherit(VirtualFrame frame, RAbstractStringVector x, Object value, REnvironment pos, RMissing envir, byte inherits, Object immediate) { + protected Object assign(VirtualFrame frame, RAbstractStringVector x, Object value, REnvironment pos, RMissing envir, byte inherits, Object immediate) { return assign.execute(frame, x, value, pos, inherits); } @Specialization @SuppressWarnings("unused") - protected Object getNonInherit(VirtualFrame frame, RAbstractStringVector x, Object value, REnvironment pos, RMissing envir, RMissing inherits, Object immediate) { + protected Object assign(VirtualFrame frame, RAbstractStringVector x, Object value, REnvironment pos, RMissing envir, RMissing inherits, Object immediate) { return assign.execute(frame, x, value, pos, RRuntime.LOGICAL_FALSE); } diff --git a/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/builtin/CastBuilderTest.java b/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/builtin/CastBuilderTest.java index 643b64da858064f69a299beda665b8937737063e..d744aeb454f874dd4bb7bc1d7863fd94c3933855 100644 --- a/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/builtin/CastBuilderTest.java +++ b/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/builtin/CastBuilderTest.java @@ -22,12 +22,13 @@ */ package com.oracle.truffle.r.nodes.builtin; -import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.asLogicalVector; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.*; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.asStringVector; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.chain; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.complexValue; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.constant; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.defaultValue; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.doubleToInt; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.doubleValue; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.elementAt; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.equalTo; @@ -35,6 +36,7 @@ import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.findFirst; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.gte; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.instanceOf; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.integerValue; +import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.isFractional; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.logicalValue; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.lte; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.map; @@ -52,6 +54,7 @@ import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.stringValue; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.toBoolean; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.trueValue; import static com.oracle.truffle.r.nodes.casts.CastUtils.samples; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -363,6 +366,7 @@ public class CastBuilderTest { assertEquals("A", cast(RRuntime.DOUBLE_NA)); } + @SuppressWarnings("deprecation") public InitialPhaseBuilder<String> matchStringArg(InitialPhaseBuilder<Object> phaseBuilder, String... optValues) { ArgumentValueFilter<String> opts = null; for (String opt : optValues) { @@ -371,6 +375,7 @@ public class CastBuilderTest { return phaseBuilder.mustBe(scalarStringValue().and(opts)); } + @SuppressWarnings("deprecation") @Test public void testMatchArg() { @@ -453,6 +458,7 @@ public class CastBuilderTest { } } + @SuppressWarnings("deprecation") @Test public void testSample5() { ArgumentTypeFilter<Object, Object> complexOrExpr = integerValue().or(doubleValue()).or(complexValue()).or(logicalValue()); @@ -647,6 +653,17 @@ public class CastBuilderTest { cast(RNull.instance); } + @Test + public void testSample17() { + cb.arg(0, "from").asDoubleVector().findFirst().mapIf(doubleNA().not().and(isFractional().not()), doubleToInt()); + + assertEquals(42, cast("42")); + assertEquals(42.2, cast("42.2")); + Object r = cast(RRuntime.STRING_NA); + assertTrue(r instanceof Double); + assertTrue(RRuntime.isNA((double) r)); + } + @Test public void testPreserveNonVectorFlag() { cb.arg(0, "x").asVector(true); diff --git a/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/casts/PredefFiltersSamplers.java b/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/casts/PredefFiltersSamplers.java index abc1459de7be218498b49f1b4396e6f6784716f2..4ec9ca46f6a12f44c3005b8e5772b8aca6f355ba 100644 --- a/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/casts/PredefFiltersSamplers.java +++ b/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/casts/PredefFiltersSamplers.java @@ -29,6 +29,7 @@ import java.util.Collections; import java.util.Objects; import com.oracle.truffle.r.nodes.builtin.CastBuilder.PredefFilters; +import com.oracle.truffle.r.nodes.builtin.ValuePredicateArgumentFilter; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.data.RComplex; import com.oracle.truffle.r.runtime.data.RDataFactory; @@ -147,6 +148,11 @@ public final class PredefFiltersSamplers implements PredefFilters { return ValuePredicateArgumentFilterSampler.fromLambdaWithSamples((Double x) -> RRuntime.isNA(x), samples(RRuntime.DOUBLE_NA), samples(0d)); } + @Override + public ValuePredicateArgumentFilterSampler<Double> isFractional() { + return ValuePredicateArgumentFilterSampler.fromLambdaWithSamples((Double x) -> !RRuntime.isNA(x) && !Double.isInfinite(x) && x != Math.floor(x), samples(0d), samples(RRuntime.DOUBLE_NA)); + } + @Override public ValuePredicateArgumentFilterSampler<String> stringNA() { return ValuePredicateArgumentFilterSampler.fromLambdaWithSamples((String x) -> RRuntime.isNA(x), samples(RRuntime.STRING_NA), samples("")); @@ -162,6 +168,11 @@ public final class PredefFiltersSamplers implements PredefFilters { return ValuePredicateArgumentFilterSampler.fromLambdaWithSamples((Double arg) -> arg != null && arg.doubleValue() == x, samples(x), CastUtils.<Double> samples(x + 1)); } + @Override + public ValuePredicateArgumentFilter<String> eq(String x) { + return ValuePredicateArgumentFilterSampler.fromLambdaWithSamples((String arg) -> arg != null && arg.equals(x), samples(x), CastUtils.samples(x + 1)); + } + @Override public ValuePredicateArgumentFilterSampler<Integer> gt(int x) { return ValuePredicateArgumentFilterSampler.fromLambdaWithSamples((Integer arg) -> arg != null && arg > x, samples(x + 1), samples(x)); @@ -247,8 +258,7 @@ public final class PredefFiltersSamplers implements PredefFilters { @Override public <R extends RAbstractComplexVector> TypePredicateArgumentFilterSampler<Object, R> complexValue() { - return TypePredicateArgumentFilterSampler.fromLambda(x -> x instanceof RComplex || - x instanceof RAbstractComplexVector, RAbstractComplexVector.class, RComplex.class); + return TypePredicateArgumentFilterSampler.fromLambda(x -> x instanceof RAbstractComplexVector, RAbstractComplexVector.class, RComplex.class); } @Override @@ -257,6 +267,11 @@ public final class PredefFiltersSamplers implements PredefFilters { x instanceof RAbstractRawVector, RAbstractRawVector.class, RRaw.class); } + @Override + public <R> TypePredicateArgumentFilterSampler<Object, R> anyValue() { + return TypePredicateArgumentFilterSampler.fromLambda(x -> true, Object.class, Object.class); + } + @Override public TypePredicateArgumentFilterSampler<Object, String> scalarStringValue() { return TypePredicateArgumentFilterSampler.fromLambda(x -> x instanceof String, CastUtils.<String> samples(), CastUtils.<Object> samples(null), String.class); diff --git a/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/casts/PredefMappersSamplers.java b/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/casts/PredefMappersSamplers.java index 52a28c37d4e226b6c792392ffe4c9dfe97c1e3c0..172f30fa5348957ca63470f4ccd4d8659dad26a8 100644 --- a/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/casts/PredefMappersSamplers.java +++ b/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/casts/PredefMappersSamplers.java @@ -27,9 +27,11 @@ import static com.oracle.truffle.r.nodes.casts.CastUtils.samples; import java.util.Collections; import com.oracle.truffle.api.profiles.ConditionProfile; +import com.oracle.truffle.r.nodes.builtin.ValuePredicateArgumentMapper; import com.oracle.truffle.r.nodes.builtin.CastBuilder.PredefMappers; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.data.RNull; +import com.oracle.truffle.r.runtime.ops.na.NACheck; public final class PredefMappersSamplers implements PredefMappers { @@ -39,6 +41,15 @@ public final class PredefMappersSamplers implements PredefMappers { CastUtils.<Byte> samples(), Byte.class, Boolean.class); } + @Override + public ValuePredicateArgumentMapperSampler<Double, Integer> doubleToInt() { + final NACheck naCheck = NACheck.create(); + return ValuePredicateArgumentMapperSampler.fromLambda(x -> { + naCheck.enable(x); + return naCheck.convertDoubleToInt(x); + }, x -> x == null ? null : (double) x, Double.class, Integer.class); + } + @Override public ValuePredicateArgumentMapperSampler<String, Integer> charAt0(int defaultValue) { return ValuePredicateArgumentMapperSampler.fromLambda(x -> { diff --git a/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/casts/TestCasts.java b/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/casts/TestCasts.java index 494f5e2116c721d4c45615faa7f51a370d209f15..1a8c6e4272263f78eab2371f775570e1d57d4fb4 100644 --- a/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/casts/TestCasts.java +++ b/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/casts/TestCasts.java @@ -237,6 +237,7 @@ public class TestCasts extends TestBase { final boolean mustBeResultCompilationConstant; + @SuppressWarnings("deprecation") protected Root(String name, boolean mustBeResultCompilationConstant) { super(name, new CastBuilder().arg(0).mapIf(scalarIntegerValue(), constant(10)).builder().getCasts()[0]); this.mustBeResultCompilationConstant = mustBeResultCompilationConstant; @@ -343,6 +344,7 @@ public class TestCasts extends TestBase { public void testComplexPipeline1() { class Root extends TestRootNode<CastNode> { + @SuppressWarnings("deprecation") protected Root(String name) { super(name, new CastBuilder().arg(0).mustBe(numericValue()).asVector().mustBe(singleElement()).findFirst().mustBe(nullValue().not()).shouldBe( ValuePredicateArgumentFilterSampler.fromLambdaWithResTypes(x -> x instanceof Byte || x instanceof Integer && ((Integer) x) > 0, Object.class), @@ -404,6 +406,7 @@ public class TestCasts extends TestBase { public void testFilterAndExpression() { class Root extends TestRootNode<CastNode> { + @SuppressWarnings("deprecation") protected Root(String name) { super(name, new CastBuilder().arg(0).mustBe(scalarIntegerValue()).shouldBe(gt0().and(lt(10))).builder().getCasts()[0]); } @@ -422,6 +425,7 @@ public class TestCasts extends TestBase { public void testFilterNotAndExpression() { class Root extends TestRootNode<CastNode> { + @SuppressWarnings("deprecation") protected Root(String name) { super(name, new CastBuilder().arg(0).mustBe(scalarIntegerValue()).shouldBe(gt0().and(lt(10)).not()).builder().getCasts()[0]); } @@ -440,6 +444,7 @@ public class TestCasts extends TestBase { public void testComplexPipeline3() { class Root extends TestRootNode<CastNode> { + @SuppressWarnings("deprecation") protected Root(String name) { super(name, new CastBuilder().arg(0).mustBe(numericValue()).asVector().mustBe(singleElement()).findFirst().mustBe(nullValue().not()).shouldBe( instanceOf(Byte.class).or(instanceOf(Integer.class).and(gt0())), Message.NON_POSITIVE_FILL).mapIf(scalarLogicalValue(), asBoolean(), diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/CastBuilder.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/CastBuilder.java index 4ae1fed9db904e17510cfedef30c04bf988f11f4..4c235819a8f2c14e7dfc3e0c8271d6be1f4e3a8a 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/CastBuilder.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/CastBuilder.java @@ -71,6 +71,7 @@ import com.oracle.truffle.r.runtime.data.model.RAbstractRawVector; import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; import com.oracle.truffle.r.runtime.data.model.RAbstractVector; import com.oracle.truffle.r.runtime.nodes.RBaseNode; +import com.oracle.truffle.r.runtime.ops.na.NACheck; public final class CastBuilder { @@ -265,12 +266,16 @@ public final class CastBuilder { ValuePredicateArgumentFilter<Double> doubleNA(); + ValuePredicateArgumentFilter<Double> isFractional(); + ValuePredicateArgumentFilter<String> stringNA(); ValuePredicateArgumentFilter<Integer> eq(int x); ValuePredicateArgumentFilter<Double> eq(double x); + ValuePredicateArgumentFilter<String> eq(String x); + ValuePredicateArgumentFilter<Integer> gt(int x); ValuePredicateArgumentFilter<Double> gt(double x); @@ -303,6 +308,8 @@ public final class CastBuilder { <R extends RAbstractRawVector> TypePredicateArgumentFilter<Object, R> rawValue(); + <R> TypePredicateArgumentFilter<Object, R> anyValue(); + TypePredicateArgumentFilter<Object, String> scalarStringValue(); TypePredicateArgumentFilter<Object, Integer> scalarIntegerValue(); @@ -320,6 +327,8 @@ public final class CastBuilder { public interface PredefMappers { ValuePredicateArgumentMapper<Byte, Boolean> toBoolean(); + ValuePredicateArgumentMapper<Double, Integer> doubleToInt(); + ValuePredicateArgumentMapper<String, Integer> charAt0(int defaultValue); <T> ValuePredicateArgumentMapper<T, RNull> nullConstant(); @@ -428,6 +437,11 @@ public final class CastBuilder { return ValuePredicateArgumentFilter.fromLambda((Double x) -> RRuntime.isNA(x)); } + @Override + public ValuePredicateArgumentFilter<Double> isFractional() { + return ValuePredicateArgumentFilter.fromLambda((Double x) -> !RRuntime.isNA(x) && !Double.isInfinite(x) && x != Math.floor(x)); + } + @Override public ValuePredicateArgumentFilter<String> stringNA() { return ValuePredicateArgumentFilter.fromLambda((String x) -> RRuntime.isNA(x)); @@ -443,6 +457,11 @@ public final class CastBuilder { return ValuePredicateArgumentFilter.fromLambda((Double arg) -> arg != null && arg.doubleValue() == x); } + @Override + public ValuePredicateArgumentFilter<String> eq(String x) { + return ValuePredicateArgumentFilter.fromLambda((String arg) -> arg != null && arg.equals(x)); + } + @Override public ValuePredicateArgumentFilter<Integer> gt(int x) { return ValuePredicateArgumentFilter.fromLambda((Integer arg) -> arg != null && arg > x); @@ -516,7 +535,7 @@ public final class CastBuilder { @Override public <R extends RAbstractComplexVector> TypePredicateArgumentFilter<Object, R> complexValue() { - return TypePredicateArgumentFilter.fromLambda(x -> x instanceof RComplex || x instanceof RAbstractComplexVector); + return TypePredicateArgumentFilter.fromLambda(x -> x instanceof RAbstractComplexVector); } @Override @@ -524,6 +543,11 @@ public final class CastBuilder { return TypePredicateArgumentFilter.fromLambda(x -> x instanceof RRaw || x instanceof RAbstractRawVector); } + @Override + public <R> TypePredicateArgumentFilter<Object, R> anyValue() { + return TypePredicateArgumentFilter.fromLambda(x -> true); + } + /** * @deprecated tests for scalar types are dangerous */ @@ -583,6 +607,15 @@ public final class CastBuilder { return ValuePredicateArgumentMapper.fromLambda(x -> RRuntime.fromLogical(x)); } + @Override + public ValuePredicateArgumentMapper<Double, Integer> doubleToInt() { + final NACheck naCheck = NACheck.create(); + return ValuePredicateArgumentMapper.fromLambda(x -> { + naCheck.enable(x); + return naCheck.convertDoubleToInt(x); + }); + } + @Override public ValuePredicateArgumentMapper<String, Integer> charAt0(int defaultValue) { final ConditionProfile profile = ConditionProfile.createBinaryProfile(); @@ -706,6 +739,10 @@ public final class CastBuilder { return phaseBuilder -> ConditionalMapNode.create(filter, trueBranchFactory.apply(phaseBuilder), falseBranchFactory.apply(phaseBuilder)); } + public static <T> Function<ArgCastBuilder<T, ?>, CastNode> mapIf(ArgumentFilter<?, ?> filter, Function<ArgCastBuilder<T, ?>, CastNode> trueBranchFactory) { + return phaseBuilder -> ConditionalMapNode.create(filter, trueBranchFactory.apply(phaseBuilder), null); + } + public static <T> ChainBuilder<T> chain(CastNode firstCast) { return new ChainBuilder<>(pb -> firstCast); } @@ -770,6 +807,14 @@ public final class CastBuilder { return phaseBuilder -> CastLogicalNodeGen.create(preserveNames, preserveDimensions, preserveAttributes); } + public static <T> Function<ArgCastBuilder<T, ?>, CastNode> asVector() { + return phaseBuilder -> CastToVectorNodeGen.create(true); + } + + public static <T> Function<ArgCastBuilder<T, ?>, CastNode> asVector(boolean preserveNonVector) { + return phaseBuilder -> CastToVectorNodeGen.create(preserveNonVector); + } + public static <T> FindFirstNodeBuilder<T> findFirst(RBaseNode callObj, RError.Message message, Object... messageArgs) { return new FindFirstNodeBuilder<>(callObj, message, messageArgs); } @@ -890,6 +935,10 @@ public final class CastBuilder { return predefFilters().doubleNA().not(); } + public static ValuePredicateArgumentFilter<Double> isFractional() { + return predefFilters().isFractional(); + } + public static ValuePredicateArgumentFilter<String> stringNA() { return predefFilters().stringNA(); } @@ -906,6 +955,10 @@ public final class CastBuilder { return predefFilters().eq(x); } + public static ValuePredicateArgumentFilter<String> eq(String x) { + return predefFilters().eq(x); + } + public static ArgumentValueFilter<Integer> neq(int x) { return predefFilters().eq(x).not(); } @@ -1014,6 +1067,10 @@ public final class CastBuilder { return predefFilters().rawValue(); } + public static <R> TypePredicateArgumentFilter<Object, R> anyValue() { + return predefFilters().anyValue(); + } + public static ArgumentTypeFilter<Object, Object> numericValue() { return integerValue().or(doubleValue()).or(logicalValue()); } @@ -1026,22 +1083,42 @@ public final class CastBuilder { return numericValue().or(stringValue()).or(complexValue()).or(rawValue()).or(instanceOf(RAbstractListVector.class)); } + /** + * @deprecated tests for scalar types are dangerous + */ + @Deprecated public static TypePredicateArgumentFilter<Object, String> scalarStringValue() { return predefFilters().scalarStringValue(); } + /** + * @deprecated tests for scalar types are dangerous + */ + @Deprecated public static TypePredicateArgumentFilter<Object, Integer> scalarIntegerValue() { return predefFilters().scalarIntegerValue(); } + /** + * @deprecated tests for scalar types are dangerous + */ + @Deprecated public static TypePredicateArgumentFilter<Object, Double> scalarDoubleValue() { return predefFilters().scalarDoubleValue(); } + /** + * @deprecated tests for scalar types are dangerous + */ + @Deprecated public static TypePredicateArgumentFilter<Object, Byte> scalarLogicalValue() { return predefFilters().scalarLogicalValue(); } + /** + * @deprecated tests for scalar types are dangerous + */ + @Deprecated public static TypePredicateArgumentFilter<Object, RComplex> scalarComplexValue() { return predefFilters().scalarComplexValue(); } @@ -1054,6 +1131,10 @@ public final class CastBuilder { return predefMappers().toBoolean(); } + public static ValuePredicateArgumentMapper<Double, Integer> doubleToInt() { + return predefMappers().doubleToInt(); + } + public static ValuePredicateArgumentMapper<String, Integer> charAt0(int defaultValue) { return predefMappers().charAt0(defaultValue); } @@ -1124,7 +1205,7 @@ public final class CastBuilder { } default THIS shouldBe(ArgumentFilter<? super T, ?> argFilter) { - return shouldBe(argFilter, state().defaultWarning().message, state().defaultWarning().args); + return shouldBe(argFilter, state().defaultWarning().callObj, state().defaultWarning().message, state().defaultWarning().args); } default <R, THAT extends ArgCastBuilder<R, THAT>> THAT alias(Function<THIS, THAT> aliaser) { @@ -1294,7 +1375,7 @@ public final class CastBuilder { } default <S> InitialPhaseBuilder<S> mustBe(ArgumentFilter<? super T, S> argFilter) { - return mustBe(argFilter, state().defaultError().message, state().defaultError().args); + return mustBe(argFilter, state().defaultError().callObj, state().defaultError().message, state().defaultError().args); } default <S> InitialPhaseBuilder<S> mustBe(Class<S> cls, RBaseNode callObj, RError.Message message, Object... messageArgs) { @@ -1345,13 +1426,6 @@ public final class CastBuilder { return state().factory.newInitialPhaseBuilder(this); } - @SuppressWarnings("overloads") - default <S, R> InitialPhaseBuilder<Object> mapIf(ArgumentFilter<? super T, S> argFilter, Function<ArgCastBuilder<T, ?>, CastNode> trueBranchNode) { - state().castBuilder().insert(state().index(), ConditionalMapNode.create(argFilter, trueBranchNode.apply(this), null)); - - return state().factory.newInitialPhaseBuilder(this); - } - @SuppressWarnings("overloads") default <S, R> InitialPhaseBuilder<Object> mapIf(ArgumentFilter<? super T, S> argFilter, ArgumentMapper<S, R> trueBranchMapper, ArgumentMapper<T, T> falseBranchMapper) { state().castBuilder().insert( @@ -1368,6 +1442,13 @@ public final class CastBuilder { return state().factory.newInitialPhaseBuilder(this); } + @SuppressWarnings("overloads") + default <S, R> InitialPhaseBuilder<Object> mapIf(ArgumentFilter<? super T, S> argFilter, Function<ArgCastBuilder<T, ?>, CastNode> trueBranchNodeFactory) { + state().castBuilder().insert(state().index(), ConditionalMapNode.create(argFilter, trueBranchNodeFactory.apply(this), null)); + + return state().factory.newInitialPhaseBuilder(this); + } + @SuppressWarnings("overloads") default <S, R> InitialPhaseBuilder<Object> mapIf(ArgumentFilter<? super T, S> argFilter, Function<ArgCastBuilder<T, ?>, CastNode> trueBranchNodeFactory, Function<ArgCastBuilder<T, ?>, CastNode> falseBranchNodeFactory) { @@ -1401,6 +1482,10 @@ public final class CastBuilder { return this; } + /** + * This method should be used as a step in pipeline, not as an argument to {@code mustBe}. + * Example: {@code casts.arg("x").notNA()}. + */ default InitialPhaseBuilder<T> notNA() { state().castBuilder().insert(state().index(), NonNANodeGen.create(state().defaultError().callObj, state().defaultError().message, state().defaultError().args, null)); return this; @@ -1528,7 +1613,7 @@ public final class CastBuilder { } default CoercedPhaseBuilder<T, S> mustBe(ArgumentFilter<? super T, ? extends T> argFilter) { - return mustBe(argFilter, state().defaultError().message, state().defaultError().args); + return mustBe(argFilter, state().defaultError().callObj, state().defaultError().message, state().defaultError().args); } } @@ -1540,6 +1625,7 @@ public final class CastBuilder { return state().factory.newHeadPhaseBuilder(this); } + @SuppressWarnings("overloads") default <S, R> HeadPhaseBuilder<Object> mapIf(ArgumentFilter<? super T, S> argFilter, ArgumentMapper<S, R> trueBranchMapper) { state().castBuilder().insert(state().index(), ConditionalMapNode.create(argFilter, MapNode.create(trueBranchMapper), null)); @@ -1562,6 +1648,13 @@ public final class CastBuilder { return state().factory.newHeadPhaseBuilder(this); } + @SuppressWarnings("overloads") + default <S, R> HeadPhaseBuilder<Object> mapIf(ArgumentFilter<? super T, S> argFilter, Function<ArgCastBuilder<T, ?>, CastNode> trueBranchNodeFactory) { + state().castBuilder().insert(state().index(), ConditionalMapNode.create(argFilter, trueBranchNodeFactory.apply(this), null)); + + return state().factory.newHeadPhaseBuilder(this); + } + @SuppressWarnings("overloads") default <S, R> HeadPhaseBuilder<Object> mapIf(ArgumentFilter<? super T, S> argFilter, Function<ArgCastBuilder<T, ?>, CastNode> trueBranchNodeFactory, Function<ArgCastBuilder<T, ?>, CastNode> falseBranchNodeFactory) { @@ -1587,7 +1680,7 @@ public final class CastBuilder { } default <S> HeadPhaseBuilder<S> mustBe(ArgumentFilter<? super T, S> argFilter) { - return mustBe(argFilter, state().defaultError().message, state().defaultError().args); + return mustBe(argFilter, state().defaultError().callObj, state().defaultError().message, state().defaultError().args); } default <S> HeadPhaseBuilder<S> mustBe(Class<S> cls, RError.Message message, Object... messageArgs) { diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/FastROptions.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/FastROptions.java index febf13d5cb0bca08184346206c0bef62cab51c31..dca4160352aa4e20ce5b12f61385cdae22a23066 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/FastROptions.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/FastROptions.java @@ -25,8 +25,8 @@ package com.oracle.truffle.r.runtime; import java.util.Map; import java.util.Map.Entry; +import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; -import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; /** * Options to control the behavior of the FastR system, that relate to the implementation, i.e., are @@ -78,12 +78,12 @@ public enum FastROptions { this.value = defaultValue; } - @TruffleBoundary public boolean getBooleanValue() { assert isBoolean; if (value instanceof Boolean) { return (Boolean) value; } else { + CompilerDirectives.transferToInterpreter(); System.out.println("boolean option value expected with " + name() + " - forgot +/- ?"); System.exit(2); return false; @@ -91,25 +91,29 @@ public enum FastROptions { } - @TruffleBoundary public String getStringValue() { assert !isBoolean; if (value == null || value instanceof String) { return (String) value; } else { + CompilerDirectives.transferToInterpreter(); System.out.println("string option value expected with " + name()); System.exit(2); return ""; } } - @TruffleBoundary public int getNonNegativeIntValue() { assert !isBoolean; + if (value instanceof Integer) { + return (Integer) value; + } + CompilerDirectives.transferToInterpreterAndInvalidate(); if (value instanceof String) { try { int res = Integer.decode((String) value); if (res >= 0) { + value = res; return res; } // else fall through to error message } catch (NumberFormatException x) { diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java index 6ae438d0d1a6c28c09886d83dfc65bbc0a90c034..a3ead4d622238846c1a29cadb135dff9804c65d3 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java @@ -281,6 +281,7 @@ public final class RError extends RuntimeException { // below: GNU R gives also expression for the argument NOT_FUNCTION("'%s' is not a function, character or symbol"), NON_CHARACTER("non-character argument"), + NON_CHARACTER_NAMES("non-character names"), NON_NUMERIC_MATH("non-numeric argument to mathematical function"), NAN_PRODUCED("NaNs produced"), NUMERIC_COMPLEX_MATRIX_VECTOR("requires numeric/complex matrix/vector arguments"), @@ -540,6 +541,7 @@ public final class RError extends RuntimeException { ARGUMENTS_PASSED_0_1("0 arguments passed to '%s' which requires 1"), ARGUMENT_IGNORED("argument '%s' will be ignored"), NOT_CHARACTER_VECTOR("'%s' must be a character vector"), + WRONG_WINSLASH("'winslash' must be '/' or '\\\\\\\\'"), CANNOT_MAKE_VECTOR_OF_MODE("vector: cannot make a vector of mode '%s'"), SET_ROWNAMES_NO_DIMS("attempt to set 'rownames' on an object with no dimensions"), COLUMNS_NOT_MULTIPLE("number of columns of result is not a multiple of vector length (arg %d)"), @@ -621,6 +623,7 @@ public final class RError extends RuntimeException { FILE_OPEN_TMP("file(\"\") only supports open = \"w+\" and open = \"w+b\": using the former"), FILE_APPEND_WRITE("write error during file append"), REQUIRES_CHAR_VECTOR("'%s' requires a character vector"), + ARGUMENT_NOT_CHAR_VECTOR("argument is not a character vector"), NOT_VALID_NAMES("not a valid named list"), CHAR_ARGUMENT("character argument expected"), CANNOT_BE_INVALID("'%s' cannot be NA, NaN or infinite"), @@ -714,7 +717,10 @@ public final class RError extends RuntimeException { BAD_ENVIRONMENT("bad %s environment argument"), CANNOT_BE_LENGTH("'%s' cannot be of length %d"), SECOND_ARGUMENT_LIST("second argument must be a list"), - DOES_NOT_HAVE_DIMNAMES("'%s' does not have named dimnames"); + DOES_NOT_HAVE_DIMNAMES("'%s' does not have named dimnames"), + ATTEMPT_TO_REPLICATE("attempt to replicate an object of type '%s'"), + ATTEMPT_TO_REPLICATE_NO_VECTOR("attempt to replicate non-vector"), + INCORRECT_ARG_TYPE("incorrect type for %s argument"); public final String message; final boolean hasArgs; 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 af2310947b1ee4fd4ad20e9a1b350b6ad1a9f14d..eaa93ed3a24a22855d083fcf4255dd177b92fe5c 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 @@ -30,7 +30,6 @@ import com.oracle.truffle.r.runtime.context.RContext; import com.oracle.truffle.r.runtime.data.model.RAbstractContainer; import com.oracle.truffle.r.runtime.data.model.RAbstractVector; import com.oracle.truffle.r.runtime.nodes.RBaseNode; -import com.oracle.truffle.r.runtime.nodes.RNode; /** * Denotes an (unevaluated) R language element. It is equivalent to a LANGSXP value in GnuR. It @@ -198,7 +197,7 @@ public class RLanguage extends RSharingAttributeStorage implements RAbstractCont @Override public RLanguage copy() { - RLanguage l = new RLanguage((RNode) getRep(), this.length); + RLanguage l = new RLanguage(getRep(), this.length); if (this.attributes != null) { l.attributes = attributes.copy(); } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test index 4a99662fa24958266b89ebb879edc7d0212a5b90..bff55d8caa2d1860e270b43fcccca7e49b816efd 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test @@ -1341,6 +1341,20 @@ character(0) #argv <- structure(list(category = 'LC_TIME', locale = 'C'), .Names = c('category', 'locale'));do.call('Sys.setlocale', argv) [1] "C" +##com.oracle.truffle.r.test.builtins.TestBuiltin_Syssetlocale.testSyssetlocaleInvalidArgs +#.Internal(Sys.setlocale('3L', 'C')) +Error: invalid 'category' argument +In addition: Warning message: +NAs introduced by coercion + +##com.oracle.truffle.r.test.builtins.TestBuiltin_Syssetlocale.testSyssetlocaleInvalidArgs +#.Internal(Sys.setlocale(4, 42)) +Error: invalid 'locale' argument + +##com.oracle.truffle.r.test.builtins.TestBuiltin_Syssetlocale.testSyssetlocaleInvalidArgs +#.Internal(Sys.setlocale(4, c('more', 'elements'))) +Error: invalid 'locale' argument + ##com.oracle.truffle.r.test.builtins.TestBuiltin_Syssleep.testSyssleep1 #argv <- list(0.5); .Internal(Sys.sleep(argv[[1]])) @@ -9403,6 +9417,10 @@ Warning message: In bitwShiftL(c(3, 2, 4), c(3 + (0+3i))) : imaginary parts discarded in coercion +##com.oracle.truffle.r.test.builtins.TestBuiltin_bitwiseShiftL.testBitwiseFunctions +#{ bitwShiftL(c(8,4,2), NULL) } +integer(0) + ##com.oracle.truffle.r.test.builtins.TestBuiltin_bitwiseShiftR.testBitwiseFunctions #{ bitwShiftR(c(1,2,3,4), c("Hello")) } [1] NA NA NA NA @@ -18448,6 +18466,10 @@ logical(0) #argv <- list(structure('lattice', .Names = ''), FALSE, FALSE, NA); .Internal(duplicated(argv[[1]], argv[[2]], argv[[3]], argv[[4]])) [1] FALSE +##com.oracle.truffle.r.test.builtins.TestBuiltin_enc2native.testInvalidArguments +#enc2native(42); +Error in enc2native(42) : argumemt is not a character vector + ##com.oracle.truffle.r.test.builtins.TestBuiltin_enc2native.testenc2native1 #argv <- list(character(0));enc2native(argv[[1]]); character(0) @@ -18460,6 +18482,10 @@ named character(0) #argv <- list('José Pinheiro [aut] (S version)');enc2native(argv[[1]]); [1] "José Pinheiro [aut] (S version)" +##com.oracle.truffle.r.test.builtins.TestBuiltin_enc2utf8.testInvalidArguments +#enc2utf8(42); +Error in enc2utf8(42) : argumemt is not a character vector + ##com.oracle.truffle.r.test.builtins.TestBuiltin_enc2utf8.testenc2utf81 #argv <- list('Add Text to a Plot');enc2utf8(argv[[1]]); [1] "Add Text to a Plot" @@ -28321,6 +28347,26 @@ Error in log1p(c(1 + (0+1i), -1 - (0+1i))) : #argv <- structure(list(length = 0), .Names = 'length');do.call('logical', argv) logical(0) +##com.oracle.truffle.r.test.builtins.TestBuiltin_ls.basicTests +#e <- new.env(); assign('.x',42,e); assign('y','42',e); ls(envir=e, all.names=FALSE) +[1] "y" + +##com.oracle.truffle.r.test.builtins.TestBuiltin_ls.basicTests +#e <- new.env(); assign('.x',42,e); assign('y','42',e); ls(envir=e, all.names=TRUE) +[1] ".x" "y" + +##com.oracle.truffle.r.test.builtins.TestBuiltin_ls.basicTests +#f <- function(){ x <- 42; a <- 'two'; ls() }; f() +[1] "a" "x" + +##com.oracle.truffle.r.test.builtins.TestBuiltin_ls.invalidArgTests +#.Internal(ls(42, TRUE, TRUE)) +Error: invalid 'envir' argument + +##com.oracle.truffle.r.test.builtins.TestBuiltin_makenames.testMakeNames +#{ .Internal(make.names(42, F)) } +Error: non-character names + ##com.oracle.truffle.r.test.builtins.TestBuiltin_makenames.testMakeNames #{ make.names("$") } [1] "X." @@ -28434,6 +28480,30 @@ character(0) #argv <- list(c('Subject', 'predict.fixed', 'predict.Subject'), TRUE); .Internal(make.names(argv[[1]], argv[[2]])) [1] "Subject" "predict.fixed" "predict.Subject" +##com.oracle.truffle.r.test.builtins.TestBuiltin_makeunique.testMakeUnique +#{ .Internal(make.unique(NULL, ".")) } +Error: 'names' must be a character vector + +##com.oracle.truffle.r.test.builtins.TestBuiltin_makeunique.testMakeUnique +#{ .Internal(make.unique(c("7", "42"), 42)) } +Error: 'sep' must be a character string + +##com.oracle.truffle.r.test.builtins.TestBuiltin_makeunique.testMakeUnique +#{ .Internal(make.unique(c("7", "42"), NULL)) } +Error: 'sep' must be a character string + +##com.oracle.truffle.r.test.builtins.TestBuiltin_makeunique.testMakeUnique +#{ .Internal(make.unique(c("7", "42"), c(".", "."))) } +Error: 'sep' must be a character string + +##com.oracle.truffle.r.test.builtins.TestBuiltin_makeunique.testMakeUnique +#{ .Internal(make.unique(c("7", "42"), character())) } +Error: 'sep' must be a character string + +##com.oracle.truffle.r.test.builtins.TestBuiltin_makeunique.testMakeUnique +#{ .Internal(make.unique(c(7, 42), ".")) } +Error: 'names' must be a character vector + ##com.oracle.truffle.r.test.builtins.TestBuiltin_makeunique.testMakeUnique #{ make.unique("a") } [1] "a" @@ -30369,6 +30439,29 @@ Time difference of 31 days #argv <- structure(list(from = as.raw(c(253, 55, 122, 88, 90, 0, 0, 1, 105, 34, 222, 54, 2, 0, 33, 1, 28, 0, 0, 0, 16, 207, 88, 204, 224, 7, 207, 0, 28, 93, 0, 24, 140, 130, 182, 196, 17, 52, 92, 78, 225, 221, 115, 179, 63, 98, 20, 119, 183, 90, 101, 43, 5, 112, 179, 75, 69, 222, 0, 0, 155, 136, 185, 16, 0, 1, 52, 208, 15, 0, 0, 0, 105, 254, 40, 141, 62, 48, 13, 139, 2, 0, 0, 0, 0, 1, 89, 90)), type = 'xz', asChar = TRUE), .Names = c('from', 'type', 'asChar'));do.call('memDecompress', argv) [1] "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" +##com.oracle.truffle.r.test.builtins.TestBuiltin_merge.testExamplesFromHelp +#x <- data.frame(k1 = c(NA,NA,3,4,5), k2 = c(1,NA,NA,4,5), data = 1:5);y <- data.frame(k1 = c(NA,2,NA,4,5), k2 = c(NA,NA,3,4,5), data = 1:5);merge(x, y, by = 'k1') + k1 k2.x data.x k2.y data.y +1 4 4 4 4 4 +2 5 5 5 5 5 +3 NA 1 1 NA 1 +4 NA 1 1 3 3 +5 NA NA 2 NA 1 +6 NA NA 2 3 3 + +##com.oracle.truffle.r.test.builtins.TestBuiltin_merge.testExamplesFromHelp +#x <- data.frame(k1 = c(NA,NA,3,4,5), k2 = c(1,NA,NA,4,5), data = 1:5);y <- data.frame(k1 = c(NA,2,NA,4,5), k2 = c(NA,NA,3,4,5), data = 1:5);merge(x, y, by = 'k2', incomparables = NA) + k2 k1.x data.x k1.y data.y +1 4 4 4 4 4 +2 5 5 5 5 5 + +##com.oracle.truffle.r.test.builtins.TestBuiltin_merge.testExamplesFromHelp +#x <- data.frame(k1 = c(NA,NA,3,4,5), k2 = c(1,NA,NA,4,5), data = 1:5);y <- data.frame(k1 = c(NA,2,NA,4,5), k2 = c(NA,NA,3,4,5), data = 1:5);merge(x, y, by = c('k1','k2')) + k1 k2 data.x data.y +1 4 4 4 4 +2 5 5 5 5 +3 NA NA 2 1 + ##com.oracle.truffle.r.test.builtins.TestBuiltin_merge.testmerge1 #argv <- list(c(0L, 0L, 0L, 0L, 0L), 0L, FALSE, TRUE); .Internal(merge(argv[[1]], argv[[2]], argv[[3]], argv[[4]])) $xi @@ -36916,6 +37009,18 @@ FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #argv <- list(150000, 3e+09);`<=`(argv[[1]],argv[[2]]); [1] TRUE +##com.oracle.truffle.r.test.builtins.TestBuiltin_options.testOptions +#{ getOption(NULL) } +Error in getOption(NULL) : 'x' must be a character string + +##com.oracle.truffle.r.test.builtins.TestBuiltin_options.testOptions +#{ getOption(c("warn", "width") } +Error: unexpected '}' in "{ getOption(c("warn", "width") }" + +##com.oracle.truffle.r.test.builtins.TestBuiltin_options.testOptions +#{ getOption(character() } +Error: unexpected '}' in "{ getOption(character() }" + ##com.oracle.truffle.r.test.builtins.TestBuiltin_options.testoptions1 #argv <- list('survfit.print.n'); .Internal(options(argv[[1]])) $survfit.print.n @@ -40470,6 +40575,86 @@ attr(,"useBytes") #{ rep(1:3,2) } [1] 1 2 3 1 2 3 +##com.oracle.truffle.r.test.builtins.TestBuiltin_rep.testRep +#{ rep(7, each="7") } +[1] 7 7 7 7 7 7 7 + +##com.oracle.truffle.r.test.builtins.TestBuiltin_rep.testRep +#{ rep(7, each=NA) } +[1] 7 + +##com.oracle.truffle.r.test.builtins.TestBuiltin_rep.testRep +#{ rep(7, each=NULL) } +[1] 7 +Warning message: +In rep(7, each = NULL) : first element used of 'each' argument + +##com.oracle.truffle.r.test.builtins.TestBuiltin_rep.testRep +#{ rep(7, each=c(7, 42)) } +[1] 7 7 7 7 7 7 7 +Warning message: +In rep(7, each = c(7, 42)) : first element used of 'each' argument + +##com.oracle.truffle.r.test.builtins.TestBuiltin_rep.testRep +#{ rep(7, each=integer()) } +[1] 7 +Warning message: +In rep(7, each = integer()) : first element used of 'each' argument + +##com.oracle.truffle.r.test.builtins.TestBuiltin_rep.testRep +#{ rep(7, length.out="7") } +[1] 7 7 7 7 7 7 7 + +##com.oracle.truffle.r.test.builtins.TestBuiltin_rep.testRep +#{ rep(7, length.out=NA) } +[1] 7 + +##com.oracle.truffle.r.test.builtins.TestBuiltin_rep.testRep +#{ rep(7, length.out=NULL) } +[1] 7 +Warning message: +In rep(7, length.out = NULL) : first element used of 'length.out' argument + +##com.oracle.truffle.r.test.builtins.TestBuiltin_rep.testRep +#{ rep(7, length.out=c(7, 42)) } +[1] 7 7 7 7 7 7 7 +Warning message: +In rep(7, length.out = c(7, 42)) : + first element used of 'length.out' argument + +##com.oracle.truffle.r.test.builtins.TestBuiltin_rep.testRep +#{ rep(7, length.out=integer()) } +[1] 7 +Warning message: +In rep(7, length.out = integer()) : + first element used of 'length.out' argument + +##com.oracle.truffle.r.test.builtins.TestBuiltin_rep.testRep +#{ rep(7, times="7") } +[1] 7 7 7 7 7 7 7 + +##com.oracle.truffle.r.test.builtins.TestBuiltin_rep.testRep +#{ rep(7, times="foo") } +Error in rep(7, times = "foo") : invalid 'times' argument +In addition: Warning message: +NAs introduced by coercion + +##com.oracle.truffle.r.test.builtins.TestBuiltin_rep.testRep +#{ rep(7, times=-1) } +Error in rep(7, times = -1) : invalid 'times' argument + +##com.oracle.truffle.r.test.builtins.TestBuiltin_rep.testRep +#{ rep(7, times=NA) } +Error in rep(7, times = NA) : invalid 'times' argument + +##com.oracle.truffle.r.test.builtins.TestBuiltin_rep.testRep +#{ rep(7, times=NULL) } +Error in rep(7, times = NULL) : invalid 'times' argument + +##com.oracle.truffle.r.test.builtins.TestBuiltin_rep.testRep +#{ rep(7, times=character()) } +Error in rep(7, times = character()) : invalid 'times' argument + ##com.oracle.truffle.r.test.builtins.TestBuiltin_rep.testRep #{ rep(NA,8) } [1] NA NA NA NA NA NA NA NA @@ -40519,6 +40704,15 @@ numeric(0) #{ rep(c(1,2),c(3,3)) } [1] 1 1 1 2 2 2 +##com.oracle.truffle.r.test.builtins.TestBuiltin_rep.testRep +#{ rep(c(7, 42), times=c(2, NA)) } +Error in rep(c(7, 42), times = c(2, NA)) : invalid 'times' argument + +##com.oracle.truffle.r.test.builtins.TestBuiltin_rep.testRep +#{ rep(function() 42) } +Error in rep(function() 42) : + attempt to replicate an object of type 'closure' + ##com.oracle.truffle.r.test.builtins.TestBuiltin_rep.testRep #{ x <- 1 ; names(x) <- c("X") ; rep(x, times=0) } named numeric(0) @@ -40849,6 +41043,26 @@ Levels: A B C D #{ rep_len(3.14159, 3) } [1] 3.14159 3.14159 3.14159 +##com.oracle.truffle.r.test.builtins.TestBuiltin_rep_len.testRepLen +#{ rep_len(7, "7") } +[1] 7 7 7 7 7 7 7 + +##com.oracle.truffle.r.test.builtins.TestBuiltin_rep_len.testRepLen +#{ rep_len(7, NA) } +Error in rep_len(7, NA) : invalid 'length.out' value + +##com.oracle.truffle.r.test.builtins.TestBuiltin_rep_len.testRepLen +#{ rep_len(7, NULL) } +Error in rep_len(7, NULL) : invalid 'length.out' value + +##com.oracle.truffle.r.test.builtins.TestBuiltin_rep_len.testRepLen +#{ rep_len(7, c(7, 42)) } +Error in rep_len(7, c(7, 42)) : invalid 'length.out' value + +##com.oracle.truffle.r.test.builtins.TestBuiltin_rep_len.testRepLen +#{ rep_len(7, integer()) } +Error in rep_len(7, integer()) : invalid 'length.out' value + ##com.oracle.truffle.r.test.builtins.TestBuiltin_rep_len.testRepLen #{ rep_len(TRUE, 2) } [1] TRUE TRUE @@ -40861,6 +41075,10 @@ Levels: A B C D #{ rep_len(c(3.1415, 0.8), 1) } [1] 3.1415 +##com.oracle.truffle.r.test.builtins.TestBuiltin_rep_len.testRepLen +#{ rep_len(function() 42, 7) } +Error in rep_len(function() 42, 7) : attempt to replicate non-vector + ##com.oracle.truffle.r.test.builtins.TestBuiltin_rep_len.testRepLen #{ x<-as.raw(16); rep_len(x, 2) } [1] 10 10 @@ -40934,6 +41152,26 @@ character(0) #{ rep.int(1L,3L) } [1] 1 1 1 +##com.oracle.truffle.r.test.builtins.TestBuiltin_repint.testRepInt +#{ rep.int(7, "7") } +[1] 7 7 7 7 7 7 7 + +##com.oracle.truffle.r.test.builtins.TestBuiltin_repint.testRepInt +#{ rep.int(7, NA) } +Error in rep.int(7, NA) : invalid 'times' value + +##com.oracle.truffle.r.test.builtins.TestBuiltin_repint.testRepInt +#{ rep.int(7, NULL) } +Error in rep.int(7, NULL) : incorrect type for second argument + +##com.oracle.truffle.r.test.builtins.TestBuiltin_repint.testRepInt +#{ rep.int(7, c(7, 42)) } +Error in rep.int(7, c(7, 42)) : invalid 'times' value + +##com.oracle.truffle.r.test.builtins.TestBuiltin_repint.testRepInt +#{ rep.int(7, character()) } +Error in rep.int(7, character()) : invalid 'times' value + ##com.oracle.truffle.r.test.builtins.TestBuiltin_repint.testRepInt #{ rep.int(as.raw(14), 4) } [1] 0e 0e 0e 0e @@ -40954,10 +41192,19 @@ Error in rep.int(c(1, 2, 3), c(2, 8)) : invalid 'times' value #{ rep.int(c(1,2,3),c(2,8,3)) } [1] 1 1 2 2 2 2 2 2 2 2 3 3 3 +##com.oracle.truffle.r.test.builtins.TestBuiltin_repint.testRepInt +#{ rep.int(function() 42, 7) } +Error in rep.int(function() 42, 7) : + attempt to replicate an object of type 'closure' + ##com.oracle.truffle.r.test.builtins.TestBuiltin_repint.testRepInt #{ rep.int(seq_len(2), rep.int(8, 2)) } [1] 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 +##com.oracle.truffle.r.test.builtins.TestBuiltin_repint.testRepInt +#{ rep_int(7, function() 42) } +Error: could not find function "rep_int" + ##com.oracle.truffle.r.test.builtins.TestBuiltin_repint.testrepint1 #argv <- list(1, 6); .Internal(rep.int(argv[[1]], argv[[2]])) [1] 1 1 1 1 1 1 @@ -54108,6 +54355,11 @@ Levels: Control Treat Warning message: In rm("ieps") : object 'ieps' not found +##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSimpleRm +#{ rm("sum", envir=getNamespace("stats")) } +Error in rm("sum", envir = getNamespace("stats")) : + cannot remove bindings from a locked environment + ##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSimpleRm #{ x <- 200 ; rm("x") ; x } Error: object 'x' not found diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_Syssetlocale.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_Syssetlocale.java index 363b64538d0641b0bc3fae9f47d32ee89837faef..557d6a7a791d74c8b0a01c1a6f28793124f9b973 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_Syssetlocale.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_Syssetlocale.java @@ -26,4 +26,11 @@ public class TestBuiltin_Syssetlocale extends TestBase { public void testSyssetlocale3() { assertEval("argv <- structure(list(category = 'LC_TIME', locale = 'C'), .Names = c('category', 'locale'));do.call('Sys.setlocale', argv)"); } + + @Test + public void testSyssetlocaleInvalidArgs() { + assertEval(Output.IgnoreErrorContext, ".Internal(Sys.setlocale(4, c('more', 'elements')))"); + assertEval(Output.IgnoreErrorContext, ".Internal(Sys.setlocale(4, 42))"); + assertEval(Output.IgnoreErrorMessage, ".Internal(Sys.setlocale('3L', 'C'))"); + } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_Syssleep.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_Syssleep.java index abe3abb0b30a816225d33129917a4e63b5a2e5df..1be9da224b58ad225bde4597f21c5e2031b028e0 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_Syssleep.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_Syssleep.java @@ -24,6 +24,6 @@ public class TestBuiltin_Syssleep extends TestBase { @Test public void testSyssleep2() { - assertEval(Ignored.Unknown, "argv <- list(FALSE); .Internal(Sys.sleep(argv[[1]]))"); + assertEval("argv <- list(FALSE); .Internal(Sys.sleep(argv[[1]]))"); } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_all.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_all.java index 3dd4c3fbe04b6fb936bace35c38c45a5efd467a0..b656b2072f9acb4bfba25aed04995ae8509a8034 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_all.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_all.java @@ -29,13 +29,12 @@ public class TestBuiltin_all extends TestBase { @Test public void testall3() { - assertEval(Ignored.Unknown, "argv <- list(c(1, 1, 3, 1, 1, 3, 3, 3, 3), FALSE, NULL);all(argv[[1]],argv[[2]],argv[[3]]);"); + assertEval(Output.IgnoreWarningContext, "argv <- list(c(1, 1, 3, 1, 1, 3, 3, 3, 3), FALSE, NULL);all(argv[[1]],argv[[2]],argv[[3]]);"); } @Test public void testall4() { - assertEval(Ignored.Unknown, - "argv <- list(structure(c(0, 0, 3, 0, 0, 0, 1, 0, 0, 2, 2, 3.2, -1, 1, 3.2, 4, 3, 0, 0, 0, 0, 3.2, 0, 0, 3.2, 0, 202, 0, 0, 0, 241, 0, 243, 0, 0), .Dim = c(5L, 7L), .Dimnames = list(c('r1', 'r2', 'r3', 'r4', 'r5'), c('c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7'))));all(argv[[1]]);"); + assertEval("argv <- list(structure(c(0, 0, 3, 0, 0, 0, 1, 0, 0, 2, 2, 3.2, -1, 1, 3.2, 4, 3, 0, 0, 0, 0, 3.2, 0, 0, 3.2, 0, 202, 0, 0, 0, 241, 0, 243, 0, 0), .Dim = c(5L, 7L), .Dimnames = list(c('r1', 'r2', 'r3', 'r4', 'r5'), c('c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7'))));all(argv[[1]]);"); } @Test @@ -119,10 +118,10 @@ public class TestBuiltin_all extends TestBase { assertEval("{ all(TRUE, TRUE, NA, na.rm=TRUE) }"); // FIXME coercion warning missing - assertEval(Ignored.Unknown, "{ all(1) }"); - assertEval(Ignored.Unknown, "{ all(0) }"); - assertEval(Ignored.Unknown, "{ all(TRUE,c(TRUE,TRUE),1) }"); - assertEval(Ignored.Unknown, "{ all(TRUE,c(TRUE,TRUE),1,0) }"); + assertEval("{ all(1) }"); + assertEval("{ all(0) }"); + assertEval(Output.IgnoreWarningContext, "{ all(TRUE,c(TRUE,TRUE),1) }"); + assertEval("{ all(TRUE,c(TRUE,TRUE),1,0) }"); assertEval("{ all(NULL) }"); assertEval("{ all(NULL, NULL) }"); diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_any.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_any.java index 55e38d938b0c8b1a72b993435d18d22e12feba09..2a2fc85c6ceaddd68bbe8e9bb995944873c60417 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_any.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_any.java @@ -39,7 +39,7 @@ public class TestBuiltin_any extends TestBase { @Test public void testany5() { - assertEval(Ignored.Unknown, "argv <- list(structure(c(14, 2, 0, 2, -7, 0), .Dim = c(3L, 2L)));any(argv[[1]]);"); + assertEval("argv <- list(structure(c(14, 2, 0, 2, -7, 0), .Dim = c(3L, 2L)));any(argv[[1]]);"); } @Test @@ -94,7 +94,7 @@ public class TestBuiltin_any extends TestBase { @Test public void testany17() { - assertEval(Ignored.Unknown, "argv <- list('NA');do.call('any', argv)"); + assertEval(Output.IgnoreWarningContext, "argv <- list('NA');do.call('any', argv)"); } @Test @@ -118,10 +118,8 @@ public class TestBuiltin_any extends TestBase { assertEval("{ any(NULL); }"); - // FIXME coercion warning missing - assertEval(Ignored.Unknown, Output.IgnoreWarningContext, "{ any(1) }"); - // FIXME coercion warning missing - assertEval(Ignored.Unknown, Output.IgnoreWarningContext, "{ any(0) }"); + assertEval("{ any(1) }"); + assertEval("{ any(0) }"); assertEval("{ d<-data.frame(c(1L,2L), c(10L, 20L)); any(d) }"); } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_aperm.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_aperm.java index fc32ee8818e9fe75e36df392ec25640a879ef4f6..a0c32a8668bb5f0fafa6ddc11f34714662ecad51 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_aperm.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_aperm.java @@ -196,19 +196,19 @@ public class TestBuiltin_aperm extends TestBase { assertEval(Output.IgnoreWarningContext, "{ aperm(array(1:27,c(3,3,3)), c(1+1i,3+3i,2+2i))[1,2,3] == array(1:27,c(3,3,3))[1,3,2]; }"); // perm is not a permutation vector - assertEval(Output.IgnoreErrorContext, "{ aperm(array(1,c( 3,3,3)), c(1,2,1)); }"); + assertEval("{ aperm(array(1,c( 3,3,3)), c(1,2,1)); }"); // perm value out of bounds - assertEval(Output.IgnoreErrorContext, "{ aperm(array(1,c(3,3,3)), c(1,2,0)); }"); + assertEval("{ aperm(array(1,c(3,3,3)), c(1,2,0)); }"); // first argument not an array - assertEval(Output.IgnoreErrorContext, "{ aperm(c(1,2,3)); }"); + assertEval("{ aperm(c(1,2,3)); }"); // Invalid first argument, not array - assertEval(Output.IgnoreErrorContext, "{ aperm(c(c(2,3), c(4,5), c(6,7)), c(3,4)) }"); + assertEval("{ aperm(c(c(2,3), c(4,5), c(6,7)), c(3,4)) }"); // invalid perm length - assertEval(Output.IgnoreErrorContext, "{ aperm(array(1,c(3,3,3)), c(1,2)); }"); + assertEval("{ aperm(array(1,c(3,3,3)), c(1,2)); }"); // Complex Vector assertEval("{ aperm(array(c(3+2i, 5+0i, 1+3i, 5-3i), c(2,2,2))) }"); diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_ascomplex.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_ascomplex.java index dbad713c053aa50dd4ba44a6bb5dc340e358017b..e8c02db81367dfeafb82b671b8e4771134568f50 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_ascomplex.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_ascomplex.java @@ -34,8 +34,7 @@ public class TestBuiltin_ascomplex extends TestBase { @Test public void testascomplex4() { - assertEval(Ignored.Unknown, - "argv <- list(structure(c(-0.626453810742332, 0.183643324222082, -0.835628612410047, 1.59528080213779, 0.329507771815361, -0.820468384118015, 0.487429052428485, 0.738324705129217, 0.575781351653492, -0.305388387156356, 1.51178116845085, 0.389843236411431, -0.621240580541804, -2.2146998871775, 1.12493091814311, -0.0449336090152309, -0.0161902630989461, 0.943836210685299, 0.821221195098089, 0.593901321217509, 0.918977371608218, 0.782136300731067, 0.0745649833651906, -1.98935169586337, 0.61982574789471), .Dim = c(5L, 5L), .Dimnames = list(c('1', '2', '3', '4', '5'), c('a', 'b', 'c', 'd', 'e'))));as.complex(argv[[1]]);"); + assertEval("argv <- list(structure(c(-0.626453810742332, 0.183643324222082, -0.835628612410047, 1.59528080213779, 0.329507771815361, -0.820468384118015, 0.487429052428485, 0.738324705129217, 0.575781351653492, -0.305388387156356, 1.51178116845085, 0.389843236411431, -0.621240580541804, -2.2146998871775, 1.12493091814311, -0.0449336090152309, -0.0161902630989461, 0.943836210685299, 0.821221195098089, 0.593901321217509, 0.918977371608218, 0.782136300731067, 0.0745649833651906, -1.98935169586337, 0.61982574789471), .Dim = c(5L, 5L), .Dimnames = list(c('1', '2', '3', '4', '5'), c('a', 'b', 'c', 'd', 'e'))));as.complex(argv[[1]]);"); } @Test diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_attach.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_attach.java index a776d2af7f05f449ed74307b25ecec69abb94bc4..9162f204511713221e774dd47c8c21b17d771eac 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_attach.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_attach.java @@ -51,6 +51,6 @@ public class TestBuiltin_attach extends TestBase { @Test public void sharingTests() { - assertEval(Ignored.Unimplemented, "d <- data.frame(colNameX=c(1,2,3)); attach(d); d$colNameX[1] <- 42; colNameX"); + assertEval("d <- data.frame(colNameX=c(1,2,3)); attach(d); d$colNameX[1] <- 42; colNameX"); } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_bitwiseAnd.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_bitwiseAnd.java index bc5109260fa03710cab03d40e1335d0c18de281e..d26c48edf1e96dc6a58e248e60ac8a04aede7bb1 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_bitwiseAnd.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_bitwiseAnd.java @@ -34,9 +34,9 @@ public class TestBuiltin_bitwiseAnd extends TestBase { assertEval("{ bitwAnd(c(10L,20L,30L,40L), c(3,5,7)) }"); assertEval("{ bitwAnd(c(10.5,11.6,17.8), c(5L,7L,8L)) }"); - assertEval(Ignored.Unknown, "{ bitwAnd(NULL, NULL) }"); + assertEval(Output.IgnoreErrorContext, "{ bitwAnd(NULL, NULL) }"); assertEval(Ignored.Unknown, "{ bitwAnd(c(), c(1,2,3)) }"); // Error message mismatch - assertEval(Output.IgnoreErrorContext, "{ bitwAnd(c(1,2,3,4), c(TRUE)) }"); + assertEval(Output.IgnoreErrorMessage, "{ bitwAnd(c(1,2,3,4), c(TRUE)) }"); } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_bitwiseOr.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_bitwiseOr.java index 607ca2ddba0cfa2f8a07f822b720f233a4674df7..830c2e07353f7a0b52f592d1d3a57c8b1975d432 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_bitwiseOr.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_bitwiseOr.java @@ -27,6 +27,6 @@ public class TestBuiltin_bitwiseOr extends TestBase { assertEval("{ bitwOr(c(10,11,12,13,14,15), c(1,1,1,1,1,1)) }"); assertEval("{ bitwOr(c(25,57,66), c(10,20,30,40,50,60)) }"); // Error message mismatch - assertEval(Output.IgnoreErrorContext, "{ bitwOr(c(1,2,3,4), c(3+3i)) }"); + assertEval(Output.IgnoreErrorMessage, "{ bitwOr(c(1,2,3,4), c(3+3i)) }"); } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_bitwiseShiftL.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_bitwiseShiftL.java index 6cd42ccb8aabc97d2f0b9ae370c60b97a9d3ba6c..6e33441b3be4ea000c0c32de930a6a988bd4e62e 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_bitwiseShiftL.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_bitwiseShiftL.java @@ -27,14 +27,15 @@ public class TestBuiltin_bitwiseShiftL extends TestBase { assertEval("{ bitwShiftL(c(10,11,12,13,14,15), c(1,1,1,1,1,1)) }"); assertEval("{ bitwShiftL(c(100,200,300), 1) }"); assertEval("{ bitwShiftL(c(25,57,66), c(10,20,30,40,50,60)) }"); + assertEval("{ bitwShiftL(c(8,4,2), NULL) }"); - assertEval(Output.IgnoreErrorContext, "{ bitwShiftL(TRUE, c(TRUE, FALSE)) }"); + assertEval("{ bitwShiftL(TRUE, c(TRUE, FALSE)) }"); // Error message mismatch - assertEval(Ignored.Unknown, Output.IgnoreErrorContext, "{ bitwShiftL(c(3+3i), c(3,2,4)) }"); + assertEval(Output.IgnoreErrorContext, "{ bitwShiftL(c(3+3i), c(3,2,4)) }"); // Warning message mismatch - assertEval(Ignored.Unknown, "{ bitwShiftL(c(3,2,4), c(3+3i)) }"); + assertEval(Output.IgnoreWarningContext, "{ bitwShiftL(c(3,2,4), c(3+3i)) }"); // No warning message printed for NAs produced by coercion - assertEval(Ignored.Unknown, "{ bitwShiftL(c(1,2,3,4), c(\"a\")) }"); + assertEval("{ bitwShiftL(c(1,2,3,4), c(\"a\")) }"); } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_bitwiseShiftR.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_bitwiseShiftR.java index dde3268bc5e00f4519827eca4d7d8cb5a9d410b0..459a1421dddec339bff3acb18f6736b9d8c23e56 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_bitwiseShiftR.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_bitwiseShiftR.java @@ -28,7 +28,7 @@ public class TestBuiltin_bitwiseShiftR extends TestBase { assertEval("{ bitwShiftR(c(100,200,300), 1) }"); assertEval("{ bitwShiftR(c(25,57,66), c(10,20,30,40,50,60)) }"); - assertEval(Ignored.Unknown, Output.IgnoreWarningContext, "{ bitwShiftR(c(3,2,4), c(3+3i)) }"); + assertEval(Output.IgnoreWarningContext, "{ bitwShiftR(c(3,2,4), c(3+3i)) }"); // No warning message printed for NAs produced by coercion assertEval(Ignored.Unknown, "{ bitwShiftR(c(1,2,3,4), c(\"Hello\")) }"); diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_bitwiseXor.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_bitwiseXor.java index 44507562922a2a7f8b92a1d66fedbfbec58975a4..6e242a3f7a2d49991105e91ff8e3a5429118aa83 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_bitwiseXor.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_bitwiseXor.java @@ -28,6 +28,6 @@ public class TestBuiltin_bitwiseXor extends TestBase { assertEval("{ bitwXor(c(25,57,66), c(10,20,30,40,50,60)) }"); assertEval("{ bitwXor(20,30) }"); - assertEval(Output.IgnoreErrorContext, "{ bitwXor(c(\"r\"), c(16,17)) }"); + assertEval(Output.IgnoreErrorMessage, "{ bitwXor(c(\"r\"), c(16,17)) }"); } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_cummax.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_cummax.java index 4189fdf32f307f28d35ff96915bac9999d01d0a0..43352fd855913cabdbe011d89dfc3529576be380 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_cummax.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_cummax.java @@ -45,7 +45,7 @@ public class TestBuiltin_cummax extends TestBase { @Test public void testcummax6() { - assertEval(Ignored.Unknown, "argv <- list(NULL);cummax(argv[[1]]);"); + assertEval("argv <- list(NULL);cummax(argv[[1]]);"); } @Test diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_cummin.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_cummin.java index b6ce4958fe52af2d54dc8e347a282872202314ec..247a4b6c9a2a773291727a47eadee3c6dc663b1b 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_cummin.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_cummin.java @@ -50,7 +50,7 @@ public class TestBuiltin_cummin extends TestBase { @Test public void testcummin7() { - assertEval(Ignored.Unknown, "argv <- list(NULL);cummin(argv[[1]]);"); + assertEval("argv <- list(NULL);cummin(argv[[1]]);"); } @Test diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_cumprod.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_cumprod.java index 9467aa56985c4e90f1862522836fde76b94ff5c6..033eb601b4781e29fe58f2a2741846d6c8d1f077 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_cumprod.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_cumprod.java @@ -55,7 +55,7 @@ public class TestBuiltin_cumprod extends TestBase { @Test public void testcumprod8() { - assertEval(Ignored.Unknown, "argv <- list(NULL);cumprod(argv[[1]]);"); + assertEval("argv <- list(NULL);cumprod(argv[[1]]);"); } @Test diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_cumsum.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_cumsum.java index 0bd4a01807095e3cf9ad574533733b4f47c878aa..a4be02abad4a1a1228373a139caefe8b7884c9f1 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_cumsum.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_cumsum.java @@ -39,7 +39,7 @@ public class TestBuiltin_cumsum extends TestBase { @Test public void testcumsum5() { - assertEval(Ignored.Unknown, "argv <- list(NULL);cumsum(argv[[1]]);"); + assertEval("argv <- list(NULL);cumsum(argv[[1]]);"); } @Test @@ -108,7 +108,7 @@ public class TestBuiltin_cumsum extends TestBase { assertEval(Ignored.Unknown, "{ cumsum(c(1,2,3,0/0,5)) }"); assertEval(Ignored.Unknown, "{ cumsum(c(1,0/0,5+1i)) }"); - assertEval(Ignored.Unknown, "{ cumsum(as.raw(1:6)) }"); + assertEval("{ cumsum(as.raw(1:6)) }"); // FIXME 1e+308 assertEval(Ignored.Unknown, "{ cumsum(rep(1e308, 3) ) }"); // FIXME 1e+308 diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_enc2native.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_enc2native.java index e1206744b91190bc66dce716ff7ff7fa96e95b51..b271802aa3c77bd6c589e381a4ae095bc47802f2 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_enc2native.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_enc2native.java @@ -31,4 +31,10 @@ public class TestBuiltin_enc2native extends TestBase { public void testenc2native4() { assertEval("argv <- list('José Pinheiro [aut] (S version)');enc2native(argv[[1]]);"); } + + @Test + public void testInvalidArguments() { + // Note: GnuR has typo in the message + assertEval(Output.IgnoreErrorMessage, "enc2native(42);"); + } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_enc2utf8.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_enc2utf8.java index 9cafe3f976507a09931be1333ff305a0da1343f7..de6cf882ae70d601ef7f36653d0fe86a232bca62 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_enc2utf8.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_enc2utf8.java @@ -41,4 +41,10 @@ public class TestBuiltin_enc2utf8 extends TestBase { public void testenc2utf86() { assertEval("argv <- list(NA_character_);do.call('enc2utf8', argv)"); } + + @Test + public void testInvalidArguments() { + // Note: GnuR has typo in the message + assertEval(Output.IgnoreErrorMessage, "enc2utf8(42);"); + } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_formals.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_formals.java index 0cec14139f90878754fd089d30db96edfcdf8d77..ca049b700fa0d8a8bc422856007c564d5e34717f 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_formals.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_formals.java @@ -24,18 +24,17 @@ public class TestBuiltin_formals extends TestBase { @Test public void testformals2() { - assertEval(Ignored.Unknown, "argv <- list(logical(0)); .Internal(formals(argv[[1]]))"); + assertEval("argv <- list(logical(0)); .Internal(formals(argv[[1]]))"); } @Test public void testformals3() { - assertEval(Ignored.Unknown, "argv <- list(structure(numeric(0), .Dim = c(0L, 0L))); .Internal(formals(argv[[1]]))"); + assertEval("argv <- list(structure(numeric(0), .Dim = c(0L, 0L))); .Internal(formals(argv[[1]]))"); } @Test public void testformals4() { - assertEval(Ignored.Unknown, - "argv <- list(structure(list(c0 = structure(integer(0), .Label = character(0), class = 'factor')), .Names = 'c0', row.names = character(0), class = 'data.frame')); .Internal(formals(argv[[1]]))"); + assertEval("argv <- list(structure(list(c0 = structure(integer(0), .Label = character(0), class = 'factor')), .Names = 'c0', row.names = character(0), class = 'data.frame')); .Internal(formals(argv[[1]]))"); } @Test diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_get.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_get.java index 7c028c4f80e8b3bf7d5609d16c31e5b44e58d8c3..71ad84e6ef169c30f8eeb6d78d6cec134f20346e 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_get.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_get.java @@ -24,12 +24,12 @@ public class TestBuiltin_get extends TestBase { assertEval("{y<-function(){y<-2;get(\"y\",mode=\"integer\",inherits=FALSE);get(\"y\",mode=\"integer\",inherits=FALSE)};y();}"); assertEval("{y<-function(){y<-2;get(\"y\",mode=\"double\")};y();}"); assertEval("{y<-function(){y<-2;get(\"y\",mode=\"double\",inherits=FALSE)};y();}"); - assertEval(Output.IgnoreErrorContext, "{ get(\"dummy\") }"); - assertEval(Output.IgnoreErrorContext, "{ x <- 33 ; f <- function() { if (FALSE) { x <- 22 } ; get(\"x\", inherits = FALSE) } ; f() }"); - assertEval(Output.IgnoreErrorContext, "{ x <- 33 ; f <- function() { get(\"x\", inherits = FALSE) } ; f() }"); + assertEval("{ get(\"dummy\") }"); + assertEval("{ x <- 33 ; f <- function() { if (FALSE) { x <- 22 } ; get(\"x\", inherits = FALSE) } ; f() }"); + assertEval("{ x <- 33 ; f <- function() { get(\"x\", inherits = FALSE) } ; f() }"); assertEval("{ get(\".Platform\", globalenv())$endian }"); assertEval("{ get(\".Platform\")$endian }"); - assertEval(Output.IgnoreErrorContext, "{y<-function(){y<-2;get(\"y\",mode=\"closure\",inherits=FALSE);};y();}"); + assertEval("{y<-function(){y<-2;get(\"y\",mode=\"closure\",inherits=FALSE);};y();}"); // behavior specific to RS4Object as environment: assertEval("setClass('foo', representation(x='numeric')); f <- new('foo'); e <- new.env(); e$x <- 1; attr(f, '.xData') <- e; get('x', envir=f)"); diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_isNamespaceEnv.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_isNamespaceEnv.java index 48d1b4114a92094dc95f008b58d9e98a7e820b2d..2769b43b83c7e694c6727f116d50f293f6250591 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_isNamespaceEnv.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_isNamespaceEnv.java @@ -19,17 +19,16 @@ public class TestBuiltin_isNamespaceEnv extends TestBase { @Test public void testisNamespaceEnv1() { - assertEval(Ignored.Unknown, "argv <- list(FALSE); .Internal(isNamespaceEnv(argv[[1]]))"); + assertEval("argv <- list(FALSE); .Internal(isNamespaceEnv(argv[[1]]))"); } @Test public void testisNamespaceEnv2() { - assertEval(Ignored.Unknown, "argv <- list(structure(numeric(0), .Dim = c(0L, 0L))); .Internal(isNamespaceEnv(argv[[1]]))"); + assertEval("argv <- list(structure(numeric(0), .Dim = c(0L, 0L))); .Internal(isNamespaceEnv(argv[[1]]))"); } @Test public void testisNamespaceEnv3() { - assertEval(Ignored.Unknown, - "argv <- list(structure(list(c0 = structure(integer(0), .Label = character(0), class = 'factor')), .Names = 'c0', row.names = character(0), class = 'data.frame')); .Internal(isNamespaceEnv(argv[[1]]))"); + assertEval("argv <- list(structure(list(c0 = structure(integer(0), .Label = character(0), class = 'factor')), .Names = 'c0', row.names = character(0), class = 'data.frame')); .Internal(isNamespaceEnv(argv[[1]]))"); } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_ls.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_ls.java new file mode 100644 index 0000000000000000000000000000000000000000..507802bf6a87ac883a7c9a3385e3f53962a02b57 --- /dev/null +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_ls.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2016, 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.oracle.truffle.r.test.builtins; + +import org.junit.Test; + +import com.oracle.truffle.r.test.TestBase; + +public class TestBuiltin_ls extends TestBase { + @Test + public void basicTests() { + assertEval("f <- function(){ x <- 42; a <- 'two'; ls() }; f()"); + assertEval(template("e <- new.env(); assign('.x',42,e); assign('y','42',e); ls(envir=e, all.names=%0)", new String[]{"TRUE", "FALSE"})); + } + + @Test + public void invalidArgTests() { + assertEval(".Internal(ls(42, TRUE, TRUE))"); + } +} diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_makenames.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_makenames.java index 4bdd7f1b7c7e4688d198e0316b0c262f72784f23..fcfe5c698cd975916cc3edeff9cbd57e06e5e152 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_makenames.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_makenames.java @@ -89,8 +89,10 @@ public class TestBuiltin_makenames extends TestBase { assertEval("{ make.names(\"else\")}"); assertEval("{ make.names(\"NA_integer_\", allow_=FALSE) }"); - assertEval(Output.IgnoreErrorContext, "{ make.names(\"a_a\", allow_=\"a\") }"); - assertEval(Output.IgnoreErrorContext, "{ make.names(\"a_a\", allow_=logical()) }"); - assertEval(Output.IgnoreErrorContext, "{ make.names(\"a_a\", allow_=NULL) }"); + assertEval("{ make.names(\"a_a\", allow_=\"a\") }"); + assertEval("{ make.names(\"a_a\", allow_=logical()) }"); + assertEval("{ make.names(\"a_a\", allow_=NULL) }"); + + assertEval("{ .Internal(make.names(42, F)) }"); } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_makeunique.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_makeunique.java index b6a376df3dfde96adc008401d739792c529e4d09..db726d9db92d7e40ed5f7b2dce447fbd9a5ff9d8 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_makeunique.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_makeunique.java @@ -44,8 +44,16 @@ public class TestBuiltin_makeunique extends TestBase { assertEval("{ make.unique(c(\"a\", \"a\")) }"); assertEval("{ make.unique(c(\"a\", \"a\", \"a\")) }"); assertEval("{ make.unique(c(\"a\", \"a\"), \"_\") }"); - assertEval(Output.IgnoreErrorContext, "{ make.unique(1) }"); - assertEval(Output.IgnoreErrorContext, "{ make.unique(\"a\", 1) }"); - assertEval(Output.IgnoreErrorContext, "{ make.unique(\"a\", character()) }"); + assertEval("{ make.unique(1) }"); + assertEval("{ make.unique(\"a\", 1) }"); + assertEval("{ make.unique(\"a\", character()) }"); + + assertEval("{ .Internal(make.unique(c(7, 42), \".\")) }"); + assertEval("{ .Internal(make.unique(NULL, \".\")) }"); + assertEval("{ .Internal(make.unique(c(\"7\", \"42\"), 42)) }"); + assertEval("{ .Internal(make.unique(c(\"7\", \"42\"), character())) }"); + assertEval("{ .Internal(make.unique(c(\"7\", \"42\"), c(\".\", \".\"))) }"); + assertEval("{ .Internal(make.unique(c(\"7\", \"42\"), NULL)) }"); + } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_matrix.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_matrix.java index 9fcc5547d1cd6a1ca5b5d172561ab67b6baaf28c..e6957f67d0fc32a920ca0c1b248a1e05cde65ba9 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_matrix.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_matrix.java @@ -134,8 +134,7 @@ public class TestBuiltin_matrix extends TestBase { @Test public void testmatrix24() { - assertEval(Ignored.Unknown, - "argv <- list(c(TRUE, FALSE, FALSE, TRUE), 2L, 2L, TRUE, NULL, FALSE, FALSE); .Internal(matrix(argv[[1]], argv[[2]], argv[[3]], argv[[4]], argv[[5]], argv[[6]], argv[[7]]))"); + assertEval("argv <- list(c(TRUE, FALSE, FALSE, TRUE), 2L, 2L, TRUE, NULL, FALSE, FALSE); .Internal(matrix(argv[[1]], argv[[2]], argv[[3]], argv[[4]], argv[[5]], argv[[6]], argv[[7]]))"); } @Test @@ -180,8 +179,7 @@ public class TestBuiltin_matrix extends TestBase { @Test public void testmatrix33() { - assertEval(Ignored.Unknown, - "argv <- list(c(1+2i, 3-4i, 5+0i, -6+0i), 2L, 2L, TRUE, NULL, FALSE, FALSE); .Internal(matrix(argv[[1]], argv[[2]], argv[[3]], argv[[4]], argv[[5]], argv[[6]], argv[[7]]))"); + assertEval("argv <- list(c(1+2i, 3-4i, 5+0i, -6+0i), 2L, 2L, TRUE, NULL, FALSE, FALSE); .Internal(matrix(argv[[1]], argv[[2]], argv[[3]], argv[[4]], argv[[5]], argv[[6]], argv[[7]]))"); } @Test diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_max.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_max.java index d1cd0ce9a3569fdcf8371d1fc99ab2384df9dd78..ab0c41a417dea4c28bc67e0653ec9525676034ea 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_max.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_max.java @@ -217,7 +217,7 @@ public class TestBuiltin_max extends TestBase { assertEval(Ignored.Unknown, Output.IgnoreWarningContext, "{ max(integer(0)) }"); assertEval(Ignored.Unknown, Output.IgnoreWarningContext, "{ max(integer()) }"); - assertEval(Ignored.Unknown, Output.IgnoreWarningContext, "{ max(as.double(NA), na.rm=TRUE) }"); + assertEval(Output.IgnoreWarningContext, "{ max(as.double(NA), na.rm=TRUE) }"); assertEval(Ignored.Unknown, Output.IgnoreWarningContext, "{ max(as.integer(NA), na.rm=TRUE) }"); assertEval(Ignored.Unknown, Output.IgnoreWarningContext, "{ max(as.integer(NA), as.integer(NA), na.rm=TRUE) }"); } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_merge.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_merge.java index 8663c21840ec2756e5429aafa089fe849a5853d2..4674eef29d533a1422cb0ef50bde98cc40d08a81 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_merge.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_merge.java @@ -37,4 +37,13 @@ public class TestBuiltin_merge extends TestBase { assertEval("argv <- structure(list(x = structure(list(gender = structure(c(1L, 1L, 2L), .Label = c('F', 'M'), class = 'factor'), age = c(20, 30, 40), filename = structure(1:3, .Label = c('q1.csv', 'q2.csv', 'q3.csv'), class = 'factor')), .Names = c('gender', 'age', 'filename'), row.names = c(NA, -3L), class = 'data.frame'), y = structure(list(effsize = c(3.5, 2, 1.7), constraint = c(0.40625, 0.5, 0.882), outdegree = c(4, 2, 2), indegree = c(4, 2, 3), efficiency = c(0.625, 0.5, 0.444444444444444), hierarchy = c(0, 0, 0.333333333333333), centralization = c(0.833333333333333, 1, 0.333333333333333), gden = c(0.5, 0.666666666666667, 0.666666666666667), ego.gden = c(0.166666666666667, 0, 0.5), filename = structure(1:3, .Label = c('q1.csv', 'q2.csv', 'q3.csv'), class = 'factor')), .Names = c('effsize', 'constraint', 'outdegree', 'indegree', 'efficiency', 'hierarchy', 'centralization', 'gden', 'ego.gden', 'filename'), row.names = c('q1.csv', 'q2.csv', 'q3.csv'), class = 'data.frame'), by = 'filename'), .Names = c('x', 'y', 'by'));" + "do.call('merge', argv)"); } + + @Test + public void testExamplesFromHelp() { + String init = "x <- data.frame(k1 = c(NA,NA,3,4,5), k2 = c(1,NA,NA,4,5), data = 1:5);" + + "y <- data.frame(k1 = c(NA,2,NA,4,5), k2 = c(NA,NA,3,4,5), data = 1:5);"; + assertEval(init + "merge(x, y, by = c('k1','k2'))"); + assertEval(init + "merge(x, y, by = 'k1')"); + assertEval(Ignored.ImplementationError, init + "merge(x, y, by = 'k2', incomparables = NA)"); + } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_min.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_min.java index 55338bf8ec5205bbbf23fbd45af1ac3713b12613..6f972e2477b129cd90257c62837e6f93273e2865 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_min.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_min.java @@ -175,7 +175,7 @@ public class TestBuiltin_min extends TestBase { assertEval(Ignored.Unknown, Output.IgnoreWarningContext, "{ min(integer(0)) }"); assertEval(Ignored.Unknown, Output.IgnoreWarningContext, "{ min(integer()) }"); - assertEval(Ignored.Unknown, Output.IgnoreWarningContext, "{ min(as.double(NA), na.rm=TRUE) }"); + assertEval(Output.IgnoreWarningContext, "{ min(as.double(NA), na.rm=TRUE) }"); assertEval(Ignored.Unknown, Output.IgnoreWarningContext, "{ min(as.integer(NA), na.rm=TRUE) }"); assertEval(Ignored.Unknown, Output.IgnoreWarningContext, "{ min(as.integer(NA), as.integer(NA), na.rm=TRUE) }"); } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_operators.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_operators.java index 12ce4e00ee14a6dcc3eca244424e95f16097f0a5..5599bc8cc873e7227e5d34731421625417c49e0b 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_operators.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_operators.java @@ -146,8 +146,7 @@ public class TestBuiltin_operators extends TestBase { @Test public void testoperators26() { - assertEval(Ignored.Unknown, - "argv <- list(structure(c(1+1i, 2+2i, 1.2+10i, 2.4+20i), .Dim = c(2L, 2L), .Dimnames = list(c('x', ''), c('a', 'b'))), 3.14159265358979);`+`(argv[[1]],argv[[2]]);"); + assertEval("argv <- list(structure(c(1+1i, 2+2i, 1.2+10i, 2.4+20i), .Dim = c(2L, 2L), .Dimnames = list(c('x', ''), c('a', 'b'))), 3.14159265358979);`+`(argv[[1]],argv[[2]]);"); } @Test diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_options.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_options.java index 5ada3fbc4176768d9ad2dce3ba538e65ec1d3d72..11e11a775e535e368e58d0be7865da50d817892a 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_options.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_options.java @@ -41,4 +41,11 @@ public class TestBuiltin_options extends TestBase { public void testoptions5() { assertEval(Ignored.Unknown, "argv <- list(NULL); .Internal(options(argv[[1]]))"); } + + @Test + public void testOptions() { + assertEval("{ getOption(NULL) }"); + assertEval("{ getOption(character() }"); + assertEval("{ getOption(c(\"warn\", \"width\") }"); + } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_rep.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_rep.java index 06232e5ec9d69e7a7ec915c0b1e85cdffb102bd6..e15b21ddd44e6d74bbb05bfb1eed47b911f40924 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_rep.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_rep.java @@ -199,5 +199,24 @@ public class TestBuiltin_rep extends TestBase { assertEval("{ x<-factor(c(\"a\", \"b\", \"a\")); rep(x, length=5) }"); assertEval("rep(x<-42)"); + + assertEval(Output.IgnoreErrorContext, "{ rep(function() 42) }"); + assertEval("{ rep(7, times=character()) }"); + assertEval("{ rep(7, times=NULL) }"); + assertEval("{ rep(7, times=\"7\") }"); + assertEval("{ rep(7, length.out=\"7\") }"); + assertEval(Output.IgnoreWarningContext, "{ rep(7, length.out=integer()) }"); + assertEval("{ rep(7, length.out=NA) }"); + assertEval("{ rep(7, length.out=NULL) }"); + assertEval(Output.IgnoreWarningContext, "{ rep(7, length.out=c(7, 42)) }"); + assertEval("{ rep(7, each=\"7\") }"); + assertEval("{ rep(7, each=integer()) }"); + assertEval("{ rep(7, each=NA) }"); + assertEval("{ rep(7, each=NULL) }"); + assertEval("{ rep(7, each=c(7, 42)) }"); + assertEval("{ rep(7, times=NA) }"); + assertEval("{ rep(7, times=-1) }"); + assertEval("{ rep(c(7, 42), times=c(2, NA)) }"); + assertEval(Output.IgnoreWarningContext, "{ rep(7, times=\"foo\") }"); } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_rep_len.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_rep_len.java index 5c4ed8dcecc3b9967b1951f0856a99179846dc0a..a2225e026a21cec3caf2e512d6d5be12bb0a1826 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_rep_len.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_rep_len.java @@ -47,5 +47,13 @@ public class TestBuiltin_rep_len extends TestBase { assertEval("{rep_len(c(\"abcd\", \"efg\"), 0)}"); assertEval("{rep_len(c(\"abcd\", \"efg\"), 1)}"); assertEval("{rep_len(c(\"abcd\", \"efg\"), 2)}"); + + assertEval(Output.IgnoreErrorContext, "{ rep_len(function() 42, 7) }"); + assertEval("{ rep_len(7, \"7\") }"); + assertEval("{ rep_len(7, integer()) }"); + assertEval("{ rep_len(7, NA) }"); + assertEval("{ rep_len(7, NULL) }"); + assertEval("{ rep_len(7, c(7, 42)) }"); + } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_repint.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_repint.java index 95d6a0a9cd40ffe2560e2adff9771087c70da314..814d34bb3a8b387cee833b1dbf5a5297ba6e13bc 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_repint.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_repint.java @@ -165,5 +165,13 @@ public class TestBuiltin_repint extends TestBase { assertEval("{ rep.int(seq_len(2), rep.int(8, 2)) }"); assertEval(Output.IgnoreErrorContext, "{ rep.int(c(1,2,3),c(2,8)) }"); + + assertEval(Output.IgnoreErrorContext, "{ rep.int(function() 42, 7) }"); + assertEval("{ rep.int(7, character()) }"); + assertEval("{ rep.int(7, NULL) }"); + assertEval("{ rep.int(7, \"7\") }"); + assertEval(Output.IgnoreErrorContext, "{ rep.int(7, c(7, 42)) }"); + assertEval("{ rep_int(7, function() 42) }"); + assertEval(Output.IgnoreErrorContext, "{ rep.int(7, NA) }"); } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sink.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sink.java index 9f9e5a254ea9f5cd09bf67750e6e2cb38cf43436..31e19215b72c2789d28c7e4ac8783fcd89448a35 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sink.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sink.java @@ -19,11 +19,11 @@ public class TestBuiltin_sink extends TestBase { @Test public void testsink1() { - assertEval("argv <- list(structure(2L, class = c('terminal', 'connection')), FALSE, FALSE, FALSE); .Internal(sink(argv[[1]], argv[[2]], argv[[3]], argv[[4]]))"); + assertEval(Ignored.SideEffects, "argv <- list(structure(2L, class = c('terminal', 'connection')), FALSE, FALSE, FALSE); .Internal(sink(argv[[1]], argv[[2]], argv[[3]], argv[[4]]))"); } @Test public void testsink3() { - assertEval(Ignored.Unknown, "argv <- list(-1L, FALSE, FALSE, FALSE); .Internal(sink(argv[[1]], argv[[2]], argv[[3]], argv[[4]]))"); + assertEval(Ignored.SideEffects, "argv <- list(-1L, FALSE, FALSE, FALSE); .Internal(sink(argv[[1]], argv[[2]], argv[[3]], argv[[4]]))"); } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_strsplit.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_strsplit.java index 226cefd11491039d9ca2c7fb2d5931cbaee1d702..c9b6ab146bd1d6dfa718c7a08fb23bd5826f9f97 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_strsplit.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_strsplit.java @@ -97,8 +97,7 @@ public class TestBuiltin_strsplit extends TestBase { @Test public void teststrsplit16() { - assertEval(Ignored.Unknown, - "argv <- list(structure(c('1', '2', '3', '4', '5', '1', '2', '3', '4', '5'), .Dim = 10L), '.', TRUE, FALSE, FALSE); .Internal(strsplit(argv[[1]], argv[[2]], argv[[3]], argv[[4]], argv[[5]]))"); + assertEval("argv <- list(structure(c('1', '2', '3', '4', '5', '1', '2', '3', '4', '5'), .Dim = 10L), '.', TRUE, FALSE, FALSE); .Internal(strsplit(argv[[1]], argv[[2]], argv[[3]], argv[[4]], argv[[5]]))"); } @Test diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_tdefault.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_tdefault.java index 7ba058c0bb41bbfb98ca8cf3e0bf115de331587f..6d1687f6aa98c20989125c44c677ebbdf332e29e 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_tdefault.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_tdefault.java @@ -19,69 +19,62 @@ public class TestBuiltin_tdefault extends TestBase { @Test public void testtdefault1() { - assertEval(Ignored.Unknown, "argv <- list(structure(c('D:', 'E:', 'F:', 'G:'), .Dim = c(4L, 1L))); .Internal(t.default(argv[[1]]))"); + assertEval("argv <- list(structure(c('D:', 'E:', 'F:', 'G:'), .Dim = c(4L, 1L))); .Internal(t.default(argv[[1]]))"); } @Test public void testtdefault2() { - assertEval(Ignored.Unknown, - "argv <- list(structure(c(0.63, -0.37, 0.4, -0.6, 0.85, -0.05, 1.02, -1.76, -1.62, -0.46, -0.57, 1.41, 0, -0.65, 0.57, -0.29, 1.22, 0.8, -0.5, 0.44, 1.63, -0.13, 0.17, 1.02, 0.11), .Dim = c(5L, 5L))); .Internal(t.default(argv[[1]]))"); + assertEval("argv <- list(structure(c(0.63, -0.37, 0.4, -0.6, 0.85, -0.05, 1.02, -1.76, -1.62, -0.46, -0.57, 1.41, 0, -0.65, 0.57, -0.29, 1.22, 0.8, -0.5, 0.44, 1.63, -0.13, 0.17, 1.02, 0.11), .Dim = c(5L, 5L))); .Internal(t.default(argv[[1]]))"); } @Test public void testtdefault3() { - assertEval(Ignored.Unknown, "argv <- list(structure(NA, .Dim = c(1L, 1L))); .Internal(t.default(argv[[1]]))"); + assertEval("argv <- list(structure(NA, .Dim = c(1L, 1L))); .Internal(t.default(argv[[1]]))"); } @Test public void testtdefault4() { - assertEval(Ignored.Unknown, - "argv <- list(structure(c(0, 0, -0.51, 0, 0, 0, 0.18, -0.15, 0, 2.62, -2.77555756156289e-16, 0, 8.26162055433954e-17, 0.560000000000001, 0, 0, 0, 0, 0, 0, 1.79, 0, 0.05, 0, 0, 0, 0, 0, 0, -0.18, -1.47, 0, -5.55111512312578e-17, 0, 0, 0.23, 0, 2.206351421008e-17, -2.12, 0), .Dim = c(5L, 8L))); .Internal(t.default(argv[[1]]))"); + assertEval("argv <- list(structure(c(0, 0, -0.51, 0, 0, 0, 0.18, -0.15, 0, 2.62, -2.77555756156289e-16, 0, 8.26162055433954e-17, 0.560000000000001, 0, 0, 0, 0, 0, 0, 1.79, 0, 0.05, 0, 0, 0, 0, 0, 0, -0.18, -1.47, 0, -5.55111512312578e-17, 0, 0, 0.23, 0, 2.206351421008e-17, -2.12, 0), .Dim = c(5L, 8L))); .Internal(t.default(argv[[1]]))"); } @Test public void testtdefault5() { - assertEval(Ignored.Unknown, "argv <- list(structure(c(NA, 0, NA, 0, NA, 0, NA, 0, NA, 0, NA, 0, NA, 0, NA, 0), .Dim = c(4L, 4L))); .Internal(t.default(argv[[1]]))"); + assertEval("argv <- list(structure(c(NA, 0, NA, 0, NA, 0, NA, 0, NA, 0, NA, 0, NA, 0, NA, 0), .Dim = c(4L, 4L))); .Internal(t.default(argv[[1]]))"); } @Test public void testtdefault6() { - assertEval(Ignored.Unknown, - "argv <- list(structure(c(0, 10975969, 8779369, 10080625, 11148921, 7628644, 10732176, 6812100, 20115225, 8862529, 9180900, 20539024, 7579009, 15594601, 8208225, 5207524, 4748041, 9e+06, 667489, 15421329, 3964081, 0, 0, 1737124, 1758276, 1674436, 2244004, 4919524, 644809, 1373584, 4072324, 2220100, 1703025, 416025, 404496, 271441, 1028196, 1863225, 1067089, 2131600, 8225424, 3247204, 0, 0, 0, 41616, 339889, 42436, 933156, 458329, 5089536, 356409, 29584, 4343056, 476100, 2427364, 1022121, 855625, 558009, 81225, 2283121, 2611456, 1380625, 0, 0, 0, 0, 211600, 167281, 1290496, 558009, 4946176, 509796, 108900, 4210704, 546121, 2402500, 1121481, 1159929, 954529, 78400, 2762244, 3189796, 1907161, 0, 0, 0, 0, 0, 616225, 2387025, 727609, 4190209, 1243225, 534361, 3337929, 622521, 1814409, 1212201, 1461681, 1345600, 115600, 3218436, 4822416, 2521744, 0, 0, 0, 0, 0, 0, 577600, 2762244, 5934096, 211600, 72361, 5244100, 509796, 3111696, 1071225, 829921, 339889, 216225, 2241009, 1968409, 877969, 0, 0, 0, 0, 0, 0, 0, 2010724, 10214416, 211600, 72361, 8826841, 2125764, 6240004, 3161284, 2362369, 1218816, 1382976, 4202500, 422500, 2117025, 0, 0, 0, 0, 0, 0, 0, 0, 3900625, 1249924, 801025, 3748096, 24964, 2070721, 180625, 107584, 349281, 263169, 990025, 4276624, 1038361, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8392609, 5895184, 456976, 3301489, 487204, 2866249, 4774225, 6579225, 3884841, 6922161, 15100996, 8844676, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 302500, 7134241, 1343281, 4831204, 2187441, 1532644, 648025, 769129, 3066001, 900601, 1334025, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5198400, 744769, 2992900, 1399489, 1205604, 724201, 208849, 2832489, 2250000, 1452025, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1387684, 446224, 3104644, 5062500, 6285049, 3236401, 7290000, 10439361, 8625969, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1640961, 102400, 107584, 524176, 221841, 1098304, 4443664, 1338649, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1338649, 2972176, 4040100, 1620529, 4397409, 10163344, 5803281, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 381924, 1229881, 627264, 1022121, 5895184, 1857769, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109561, 732736, 343396, 4782969, 806404, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 674041, 894916, 3076516, 183184, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2178576, 3337929, 1560001, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7327849, 1461681, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4431025, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), .Dim = c(21L, 21L))); .Internal(t.default(argv[[1]]))"); + assertEval("argv <- list(structure(c(0, 10975969, 8779369, 10080625, 11148921, 7628644, 10732176, 6812100, 20115225, 8862529, 9180900, 20539024, 7579009, 15594601, 8208225, 5207524, 4748041, 9e+06, 667489, 15421329, 3964081, 0, 0, 1737124, 1758276, 1674436, 2244004, 4919524, 644809, 1373584, 4072324, 2220100, 1703025, 416025, 404496, 271441, 1028196, 1863225, 1067089, 2131600, 8225424, 3247204, 0, 0, 0, 41616, 339889, 42436, 933156, 458329, 5089536, 356409, 29584, 4343056, 476100, 2427364, 1022121, 855625, 558009, 81225, 2283121, 2611456, 1380625, 0, 0, 0, 0, 211600, 167281, 1290496, 558009, 4946176, 509796, 108900, 4210704, 546121, 2402500, 1121481, 1159929, 954529, 78400, 2762244, 3189796, 1907161, 0, 0, 0, 0, 0, 616225, 2387025, 727609, 4190209, 1243225, 534361, 3337929, 622521, 1814409, 1212201, 1461681, 1345600, 115600, 3218436, 4822416, 2521744, 0, 0, 0, 0, 0, 0, 577600, 2762244, 5934096, 211600, 72361, 5244100, 509796, 3111696, 1071225, 829921, 339889, 216225, 2241009, 1968409, 877969, 0, 0, 0, 0, 0, 0, 0, 2010724, 10214416, 211600, 72361, 8826841, 2125764, 6240004, 3161284, 2362369, 1218816, 1382976, 4202500, 422500, 2117025, 0, 0, 0, 0, 0, 0, 0, 0, 3900625, 1249924, 801025, 3748096, 24964, 2070721, 180625, 107584, 349281, 263169, 990025, 4276624, 1038361, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8392609, 5895184, 456976, 3301489, 487204, 2866249, 4774225, 6579225, 3884841, 6922161, 15100996, 8844676, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 302500, 7134241, 1343281, 4831204, 2187441, 1532644, 648025, 769129, 3066001, 900601, 1334025, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5198400, 744769, 2992900, 1399489, 1205604, 724201, 208849, 2832489, 2250000, 1452025, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1387684, 446224, 3104644, 5062500, 6285049, 3236401, 7290000, 10439361, 8625969, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1640961, 102400, 107584, 524176, 221841, 1098304, 4443664, 1338649, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1338649, 2972176, 4040100, 1620529, 4397409, 10163344, 5803281, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 381924, 1229881, 627264, 1022121, 5895184, 1857769, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109561, 732736, 343396, 4782969, 806404, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 674041, 894916, 3076516, 183184, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2178576, 3337929, 1560001, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7327849, 1461681, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4431025, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), .Dim = c(21L, 21L))); .Internal(t.default(argv[[1]]))"); } @Test public void testtdefault7() { - assertEval(Ignored.Unknown, "argv <- list(structure(logical(0), .Dim = c(0L, 0L))); .Internal(t.default(argv[[1]]))"); + assertEval("argv <- list(structure(logical(0), .Dim = c(0L, 0L))); .Internal(t.default(argv[[1]]))"); } @Test public void testtdefault8() { - assertEval(Ignored.Unknown, - "argv <- list(structure(c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE), .Dim = c(4L, 4L), .Dimnames = list(NULL, NULL))); .Internal(t.default(argv[[1]]))"); + assertEval("argv <- list(structure(c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE), .Dim = c(4L, 4L), .Dimnames = list(NULL, NULL))); .Internal(t.default(argv[[1]]))"); } @Test public void testtdefault9() { - assertEval(Ignored.Unknown, - "argv <- list(structure(c(0.589872882227945+0i, 0.193623477236295+0i, 0.66266867945261+0i, 0.140441698505598+0i, -0.394596353845825+0i, 0.168331537203598+0i, 0.293129347035038+0i, -0.481237717889449+0i, 0.7985227152757+0i, -0.128496737541326+0i, -0.0231518691888815+0i, -0.892171028872675+0i, 0.158252886617681+0i, 0.418477841524233+0i, -0.0576815934568704+0i, 0.471807942431513+0i, -0.00978429568549377+0i, 0.0825499722933953+0i, 0.0943143868799564+0i, 0.872692289136496+0i, -0.632910525118973+0i, 0.283760916561723+0i, 0.545364104158516+0i, 0.398269626120626+0i, 0.25072556357658+0i), .Dim = c(5L, 5L))); .Internal(t.default(argv[[1]]))"); + assertEval("argv <- list(structure(c(0.589872882227945+0i, 0.193623477236295+0i, 0.66266867945261+0i, 0.140441698505598+0i, -0.394596353845825+0i, 0.168331537203598+0i, 0.293129347035038+0i, -0.481237717889449+0i, 0.7985227152757+0i, -0.128496737541326+0i, -0.0231518691888815+0i, -0.892171028872675+0i, 0.158252886617681+0i, 0.418477841524233+0i, -0.0576815934568704+0i, 0.471807942431513+0i, -0.00978429568549377+0i, 0.0825499722933953+0i, 0.0943143868799564+0i, 0.872692289136496+0i, -0.632910525118973+0i, 0.283760916561723+0i, 0.545364104158516+0i, 0.398269626120626+0i, 0.25072556357658+0i), .Dim = c(5L, 5L))); .Internal(t.default(argv[[1]]))"); } @Test public void testtdefault10() { - assertEval(Ignored.Unknown, - "argv <- list(structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 74, 68, 56, 57, 60, 74, 53, 61, 57, 57, 67, 70, 63, 57, 67, 50, 58, 72, 60, 70, 53, 74, 73, 48, 61, 65, 74, 70, 68, 74, 63, 74, 63, 68, 58, 59, 62, 57, 48, 73, 69, 68, 68, 67, 63, 74, 40, 81, 73, 59, 55, 42, 44, 71, 61, 72, 63, 70, 66, 72, 69, 71, 64, 56, 63, 59, 66, 67, 55, 69, 44, 80, 76, 49, 68, 66, 80, 75, 72, 70, 66, 50, 64, 53, 47, 67, 56, 54, 56, 74, 76, 57, 71, 54, 82, 70, 60, 55, 69, 62, 63, 69, 63, 64, 46, 61, 65, 61, 56, 53, 56, 60, 39, 58, 64, 53, 72, 52, 50, 64, 71, 70, 64, 60, 73, 62, 69, 67, 69, 65, 65, 76, 67, 76, 77, 39, 66, 1, 0, 0, 1, 0, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 0, 0, 0, 3, 1, 2, 2, 2, 2, 2, 2, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 2, 1, 1, 1, 2, 0, 1, 0, 2, 1, 0, 0, 0, 1, 1, 1, 1, 0, 2, 0, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 0, 1, 1, 2, 2, 2, 2, 1, 0, 2, 0, 1, 1, 1, 1, 0, 0, 2, 1, 0, 1, 2, 1, 0, 1, 0, 1, 0, 2, 2, 2, 1, 2, 1, 1, 0, 1, 0, 1, 1, 1, 2, 0, 0, 0, 1, 0, 1, 2, 1, 1, 1, 0, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 0, 1), .Dim = c(137L, 3L), .Dimnames = list(c('1', '2', '3', '4', '5', '6', '9', '10', '11', '15', '16', '17', '18', '20', '21', '23', '24', '25', '27', '28', '29', '30', '32', '33', '35', '37', '39', '41', '45', '47', '48', '49', '52', '53', '54', '55', '56', '58', '62', '63', '65', '66', '69', '70', '71', '73', '74', '79', '80', '81', '82', '83', '85', '86', '88', '90', '91', '92', '93', '96', '97', '98', '99', '103', '104', '105', '106', '108', '109', '111', '112', '113', '116', '117', '118', '119', '120', '121', '124', '125', '126', '127', '128', '132', '133', '135', '138', '139', '140', '142', '143', '145', '147', '148', '149', '151', '152', '155', '156', '158', '159', '163', '164', '165', '168', '169', '170', '171', '173', '175', '177', '181', '182', '188', '189', '190', '191', '192', '193', '194', '195', '196', '198', '200', '202', '206', '209', '212', '213', '215', '216', '218', '221', '223', '224', '225', '227'), c('(Intercept)', 'age', 'ph.ecog')), assign = 0:2)); .Internal(t.default(argv[[1]]))"); + assertEval("argv <- list(structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 74, 68, 56, 57, 60, 74, 53, 61, 57, 57, 67, 70, 63, 57, 67, 50, 58, 72, 60, 70, 53, 74, 73, 48, 61, 65, 74, 70, 68, 74, 63, 74, 63, 68, 58, 59, 62, 57, 48, 73, 69, 68, 68, 67, 63, 74, 40, 81, 73, 59, 55, 42, 44, 71, 61, 72, 63, 70, 66, 72, 69, 71, 64, 56, 63, 59, 66, 67, 55, 69, 44, 80, 76, 49, 68, 66, 80, 75, 72, 70, 66, 50, 64, 53, 47, 67, 56, 54, 56, 74, 76, 57, 71, 54, 82, 70, 60, 55, 69, 62, 63, 69, 63, 64, 46, 61, 65, 61, 56, 53, 56, 60, 39, 58, 64, 53, 72, 52, 50, 64, 71, 70, 64, 60, 73, 62, 69, 67, 69, 65, 65, 76, 67, 76, 77, 39, 66, 1, 0, 0, 1, 0, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 0, 0, 0, 3, 1, 2, 2, 2, 2, 2, 2, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 2, 1, 1, 1, 2, 0, 1, 0, 2, 1, 0, 0, 0, 1, 1, 1, 1, 0, 2, 0, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 0, 1, 1, 2, 2, 2, 2, 1, 0, 2, 0, 1, 1, 1, 1, 0, 0, 2, 1, 0, 1, 2, 1, 0, 1, 0, 1, 0, 2, 2, 2, 1, 2, 1, 1, 0, 1, 0, 1, 1, 1, 2, 0, 0, 0, 1, 0, 1, 2, 1, 1, 1, 0, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 0, 1), .Dim = c(137L, 3L), .Dimnames = list(c('1', '2', '3', '4', '5', '6', '9', '10', '11', '15', '16', '17', '18', '20', '21', '23', '24', '25', '27', '28', '29', '30', '32', '33', '35', '37', '39', '41', '45', '47', '48', '49', '52', '53', '54', '55', '56', '58', '62', '63', '65', '66', '69', '70', '71', '73', '74', '79', '80', '81', '82', '83', '85', '86', '88', '90', '91', '92', '93', '96', '97', '98', '99', '103', '104', '105', '106', '108', '109', '111', '112', '113', '116', '117', '118', '119', '120', '121', '124', '125', '126', '127', '128', '132', '133', '135', '138', '139', '140', '142', '143', '145', '147', '148', '149', '151', '152', '155', '156', '158', '159', '163', '164', '165', '168', '169', '170', '171', '173', '175', '177', '181', '182', '188', '189', '190', '191', '192', '193', '194', '195', '196', '198', '200', '202', '206', '209', '212', '213', '215', '216', '218', '221', '223', '224', '225', '227'), c('(Intercept)', 'age', 'ph.ecog')), assign = 0:2)); .Internal(t.default(argv[[1]]))"); } @Test public void testtdefault11() { - assertEval(Ignored.Unknown, - "argv <- list(structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), .Dim = c(20L, 20L), .Dimnames = list(c(NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_), c(NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_)))); .Internal(t.default(argv[[1]]))"); + assertEval("argv <- list(structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), .Dim = c(20L, 20L), .Dimnames = list(c(NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_), c(NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_)))); .Internal(t.default(argv[[1]]))"); } @Test public void testtdefault12() { - assertEval(Ignored.Unknown, "argv <- list(structure('foo', .Dim = c(1L, 1L), .Dimnames = list(structure('object', simpleOnly = TRUE), NULL))); .Internal(t.default(argv[[1]]))"); + assertEval("argv <- list(structure('foo', .Dim = c(1L, 1L), .Dimnames = list(structure('object', simpleOnly = TRUE), NULL))); .Internal(t.default(argv[[1]]))"); } @Test @@ -97,54 +90,52 @@ public class TestBuiltin_tdefault extends TestBase { @Test public void testtdefault15() { - assertEval(Ignored.Unknown, "argv <- list(structure(list(3, 3, 3, 3, 3, 'fred'), .Dim = 2:3)); .Internal(t.default(argv[[1]]))"); + assertEval("argv <- list(structure(list(3, 3, 3, 3, 3, 'fred'), .Dim = 2:3)); .Internal(t.default(argv[[1]]))"); } @Test public void testtdefault16() { - assertEval(Ignored.Unknown, "argv <- list(1.28578345790245); .Internal(t.default(argv[[1]]))"); + assertEval("argv <- list(1.28578345790245); .Internal(t.default(argv[[1]]))"); } @Test public void testtdefault17() { - assertEval(Ignored.Unknown, - "argv <- list(structure(c(-0.560475646552213+0i, 0.7424437487+0.205661411508856i, 1.39139505579429-0.26763356813179i, 0.928710764113827-0.221714979045717i, -0.46926798541295+1.18846175213664i, 0.7424437487-0.205661411508856i, 0.460916205989202+0i, -0.452623703774585+0.170604003753717i, -0.094501186832143+0.54302538277632i, -0.331818442379127+0.612232958468282i, 1.39139505579429+0.26763356813179i, -0.452623703774585-0.170604003753717i, 0.400771450594052+0i, -0.927967220342259+0.479716843914174i, -0.790922791530657+0.043092176305418i, 0.928710764113827+0.221714979045717i, -0.094501186832143-0.54302538277632i, -0.927967220342259-0.479716843914174i, 0.701355901563686+0i, -0.600841318509537+0.213998439984336i, -0.46926798541295-1.18846175213664i, -0.331818442379127-0.612232958468282i, -0.790922791530657-0.043092176305418i, -0.600841318509537-0.213998439984336i, -0.625039267849257+0i), .Dim = c(5L, 5L))); .Internal(t.default(argv[[1]]))"); + assertEval("argv <- list(structure(c(-0.560475646552213+0i, 0.7424437487+0.205661411508856i, 1.39139505579429-0.26763356813179i, 0.928710764113827-0.221714979045717i, -0.46926798541295+1.18846175213664i, 0.7424437487-0.205661411508856i, 0.460916205989202+0i, -0.452623703774585+0.170604003753717i, -0.094501186832143+0.54302538277632i, -0.331818442379127+0.612232958468282i, 1.39139505579429+0.26763356813179i, -0.452623703774585-0.170604003753717i, 0.400771450594052+0i, -0.927967220342259+0.479716843914174i, -0.790922791530657+0.043092176305418i, 0.928710764113827+0.221714979045717i, -0.094501186832143-0.54302538277632i, -0.927967220342259-0.479716843914174i, 0.701355901563686+0i, -0.600841318509537+0.213998439984336i, -0.46926798541295-1.18846175213664i, -0.331818442379127-0.612232958468282i, -0.790922791530657-0.043092176305418i, -0.600841318509537-0.213998439984336i, -0.625039267849257+0i), .Dim = c(5L, 5L))); .Internal(t.default(argv[[1]]))"); } @Test public void testtdefault18() { - assertEval(Ignored.Unknown, "argv <- list(structure(c(0, 1954.88214285714, 557.144827586207, 0, 0, 1392.34285714286, 0, 0, 0), .Dim = c(3L, 3L))); .Internal(t.default(argv[[1]]))"); + assertEval("argv <- list(structure(c(0, 1954.88214285714, 557.144827586207, 0, 0, 1392.34285714286, 0, 0, 0), .Dim = c(3L, 3L))); .Internal(t.default(argv[[1]]))"); } @Test public void testtdefault19() { - assertEval(Ignored.Unknown, "argv <- list(c(3, 4)); .Internal(t.default(argv[[1]]))"); + assertEval("argv <- list(c(3, 4)); .Internal(t.default(argv[[1]]))"); } @Test public void testtdefault20() { - assertEval(Ignored.Unknown, - "argv <- list(structure(c(0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 1L), .Dim = c(4L, 4L), .Dimnames = list(c('Y', 'B', 'V', 'N'), c('B', 'V', 'N', 'V:N')))); .Internal(t.default(argv[[1]]))"); + assertEval("argv <- list(structure(c(0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 1L), .Dim = c(4L, 4L), .Dimnames = list(c('Y', 'B', 'V', 'N'), c('B', 'V', 'N', 'V:N')))); .Internal(t.default(argv[[1]]))"); } @Test public void testtdefault21() { - assertEval(Ignored.Unknown, "argv <- list(-3:5); .Internal(t.default(argv[[1]]))"); + assertEval("argv <- list(-3:5); .Internal(t.default(argv[[1]]))"); } @Test public void testtdefault22() { - assertEval(Ignored.Unknown, + assertEval( "argv <- list(structure(c(8.3, 8.6, 8.8, 10.5, 10.7, 10.8, 11, 11, 11.1, 11.2, 11.3, 11.4, 11.4, 11.7, 12, 12.9, 12.9, 13.3, 13.7, 13.8, 14, 14.2, 14.5, 16, 16.3, 17.3, 17.5, 17.9, 18, 18, 20.6, 70, 65, 63, 72, 81, 83, 66, 75, 80, 75, 79, 76, 76, 69, 75, 74, 85, 86, 71, 64, 78, 80, 74, 72, 77, 81, 82, 80, 80, 80, 87, 10.3, 10.3, 10.2, 16.4, 18.8, 19.7, 15.6, 18.2, 22.6, 19.9, 24.2, 21, 21.4, 21.3, 19.1, 22.2, 33.8, 27.4, 25.7, 24.9, 34.5, 31.7, 36.3, 38.3, 42.6, 55.4, 55.7, 58.3, 51.5, 51, 77), .Dim = c(31L, 3L), .Dimnames = list(NULL, c('Girth', 'Height', 'Volume')))); .Internal(t.default(argv[[1]]))"); } @Test public void testtdefault23() { - assertEval(Ignored.Unknown, "argv <- list(structure(list(), .Dim = 0L)); .Internal(t.default(argv[[1]]))"); + assertEval("argv <- list(structure(list(), .Dim = 0L)); .Internal(t.default(argv[[1]]))"); } @Test public void testtdefault24() { - assertEval(Ignored.Unknown, "argv <- list(structure('Seed', .Dim = c(1L, 1L))); .Internal(t.default(argv[[1]]))"); + assertEval("argv <- list(structure('Seed', .Dim = c(1L, 1L))); .Internal(t.default(argv[[1]]))"); } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestMiscBuiltins.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestMiscBuiltins.java index 20a1daf0a17599186f7f7096718a8c55337ebe75..bf97250d46192b180e04e524203f5bca4a4db5c9 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestMiscBuiltins.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestMiscBuiltins.java @@ -269,7 +269,8 @@ public class TestMiscBuiltins extends TestBase { @Test public void testSimpleRm() { assertEval("{ x <- 200 ; rm(\"x\") ; x }"); - assertEval(Output.IgnoreWarningContext, "{ rm(\"ieps\") }"); + assertEval("{ rm(\"ieps\") }"); + assertEval("{ rm(\"sum\", envir=getNamespace(\"stats\")) }"); assertEval("{ x <- 200 ; rm(\"x\") }"); assertEval("{ x<-200; y<-100; rm(\"x\", \"y\"); x }"); assertEval("{ x<-200; y<-100; rm(\"x\", \"y\"); y }"); diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/TestFunctions.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/TestFunctions.java index 202529dcc7d37f277fdc08f97888b135a6926ad3..1d63aeeb26b2c5afc1b95efb1684b89c1e4ae331 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/TestFunctions.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/functions/TestFunctions.java @@ -263,7 +263,7 @@ public class TestFunctions extends TestBase { assertEval("{ f <- function(...) { g <- function() { ..1 } ; g() } ; f(a=2) }"); assertEval("{ f <- function(...) { ..1 <- 2 ; ..1 } ; f(z = 1) }"); assertEval("{ f <- function(...) { ..1 <- 2 ; get(\"..1\") } ; f(1,2,3,4) }"); - assertEval(Output.IgnoreErrorContext, "{ f <- function(...) { get(\"..1\") } ; f(1,2,3,4) }"); + assertEval("{ f <- function(...) { get(\"..1\") } ; f(1,2,3,4) }"); assertEval("{ g <- function(a,b) { a + b } ; f <- function(...) { g(...) } ; f(1,2) }"); assertEval("{ g <- function(a,b,x) { a + b * x } ; f <- function(...) { g(...,x=4) } ; f(b=1,a=2) }"); diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestEnvironments.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestEnvironments.java index 31066d5f1b6466d551d573862b659c17ca64f7a4..44ac9c7cfa00022ca8a01c1cd5293600ad42b13c 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestEnvironments.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestEnvironments.java @@ -56,8 +56,8 @@ public class TestEnvironments extends TestBase { assertEval("{ x <- 3 ; f <- function() { exists(\"x\", inherits=FALSE) } ; f() }"); assertEval("{ x <- 2 ; y <- 3 ; rm(\"y\") ; ls() }"); - assertEval(Output.IgnoreErrorContext, "{ x <- 2 ; rm(\"x\") ; get(\"x\") }"); - assertEval(Output.IgnoreErrorContext, "{ get(\"x\") }"); + assertEval("{ x <- 2 ; rm(\"x\") ; get(\"x\") }"); + assertEval("{ get(\"x\") }"); assertEval("{ f <- function() { assign(\"x\", 1) ; y <- 2 ; ls() } ; sort(f()) }"); assertEval("{ f <- function() { x <- 1 ; y <- 2 ; ls() } ; sort(f()) }"); @@ -238,26 +238,26 @@ public class TestEnvironments extends TestBase { assertEval("{ e<-new.env(); assign(\"a\", 1, e); lockBinding(\"a\", e); bindingIsLocked(\"a\", e) }"); // rm - assertEval(Output.IgnoreErrorContext, "{ rm(\"foo\", envir = baseenv()) }"); - assertEval(Output.IgnoreErrorContext, "{ e<-new.env(); assign(\"a\", 1, e) ; lockEnvironment(e); rm(\"a\",envir = e); }"); + assertEval("{ rm(\"foo\", envir = baseenv()) }"); + assertEval("{ e<-new.env(); assign(\"a\", 1, e) ; lockEnvironment(e); rm(\"a\",envir = e); }"); // ok to removed a locked binding assertEval("{ e<-new.env(); assign(\"a\", 1, e) ; lockBinding(\"a\", e); rm(\"a\",envir = e); ls() }"); assertEval("{ e<-new.env(); assign(\"a\", 1, e) ; rm(\"a\",envir = e); ls() }"); // get - assertEval(Output.IgnoreErrorContext, "{ e<-new.env(); get(\"x\", e) }"); + assertEval("{ e<-new.env(); get(\"x\", e) }"); assertEval("{ e<-new.env(); x<-1; get(\"x\", e) }"); assertEval("{ e<-new.env(); assign(\"x\", 1, e); get(\"x\", e) }"); - assertEval(Output.IgnoreErrorContext, "{ e<-new.env(); x<-1; get(\"x\", e, inherits=FALSE) }"); - assertEval(Output.IgnoreErrorContext, "{ e<-new.env(parent=emptyenv()); x<-1; get(\"x\", e) }"); + assertEval("{ e<-new.env(); x<-1; get(\"x\", e, inherits=FALSE) }"); + assertEval("{ e<-new.env(parent=emptyenv()); x<-1; get(\"x\", e) }"); // misc - assertEval(Output.IgnoreErrorContext, "{ h <- new.env(parent=emptyenv()) ; assign(\"y\", 2, h) ; get(\"z\", h) }"); + assertEval("{ h <- new.env(parent=emptyenv()) ; assign(\"y\", 2, h) ; get(\"z\", h) }"); assertEval("{ plus <- function(x) { function(y) x + y } ; plus_one <- plus(1) ; ls(environment(plus_one)) }"); assertEval("{ ls(.GlobalEnv) }"); assertEval("{ x <- 1 ; ls(.GlobalEnv) }"); - assertEval(Output.IgnoreErrorContext, "{ ph <- new.env(parent=emptyenv()) ; h <- new.env(parent=ph) ; assign(\"x\", 10, h, inherits=TRUE) ; get(\"x\", ph)}"); - assertEval(Output.IgnoreErrorContext, "{ ph <- new.env() ; h <- new.env(parent=ph) ; assign(\"x\", 2, h) ; assign(\"x\", 10, h, inherits=TRUE) ; get(\"x\", ph)}"); + assertEval("{ ph <- new.env(parent=emptyenv()) ; h <- new.env(parent=ph) ; assign(\"x\", 10, h, inherits=TRUE) ; get(\"x\", ph)}"); + assertEval("{ ph <- new.env() ; h <- new.env(parent=ph) ; assign(\"x\", 2, h) ; assign(\"x\", 10, h, inherits=TRUE) ; get(\"x\", ph)}"); assertEval("{ h <- new.env(parent=globalenv()) ; assign(\"x\", 10, h, inherits=TRUE) ; x }"); assertEval("{ ph <- new.env() ; h <- new.env(parent=ph) ; assign(\"x\", 10, h, inherits=TRUE) ; x }"); diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/rpackages/TestRecommendedPackages.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/rpackages/TestRecommendedPackages.java index 805565cf8225137ee12af9ceed4fc19cf296a6cc..a08a9b4baa782de96a497b3cc6c839c520041e58 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/rpackages/TestRecommendedPackages.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/rpackages/TestRecommendedPackages.java @@ -64,6 +64,7 @@ public class TestRecommendedPackages extends TestRPackages { @Test public void testLoad() { - assertEval(Context.NonShared, Context.LongTimeout, TestBase.template("{ library(%1, lib.loc = \"%0\"); detach(\"package:%1\"); }", new String[]{TestRPackages.libLoc()}, OK_PACKAGES)); + assertEval(Ignored.OutputFormatting, Context.NonShared, Context.LongTimeout, + TestBase.template("{ library(%1, lib.loc = \"%0\"); detach(\"package:%1\"); }", new String[]{TestRPackages.libLoc()}, OK_PACKAGES)); } }