diff --git a/com.oracle.truffle.r.native/builtinlibs/lib/solaris b/com.oracle.truffle.r.native/builtinlibs/lib/solaris new file mode 120000 index 0000000000000000000000000000000000000000..61bc28ffefa03fe47367c459d5769aacdbd3ba62 --- /dev/null +++ b/com.oracle.truffle.r.native/builtinlibs/lib/solaris @@ -0,0 +1 @@ +sunos \ No newline at end of file diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Call.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Call.java index 238d9a2841c6b16c55707027bed10542df112c12..b092eb8d6d230011d4fe31d1b9e6ab9e01a3e017 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Call.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Call.java @@ -26,12 +26,9 @@ import static com.oracle.truffle.r.runtime.RBuiltinKind.*; import com.oracle.truffle.api.CompilerDirectives.SlowPath; import com.oracle.truffle.api.dsl.*; -import com.oracle.truffle.api.nodes.*; -import com.oracle.truffle.api.source.*; import com.oracle.truffle.r.nodes.*; import com.oracle.truffle.r.nodes.access.*; import com.oracle.truffle.r.nodes.builtin.*; -import com.oracle.truffle.r.nodes.function.*; import com.oracle.truffle.r.runtime.*; import com.oracle.truffle.r.runtime.data.*; @@ -72,12 +69,6 @@ public abstract class Call extends RBuiltinNode { return makeCall0(function, args); } - @SlowPath - protected static RLanguage makeCall(SourceSection src, RFunction function, RArgsValuesAndNames args) { - ConstantNode func = ConstantNode.create(function); - return makeCall0Old(func, src, args); - } - @SlowPath private static RLanguage makeCall0(Object fn, RArgsValuesAndNames args) { int dataLen = args == null ? 1 : args.length() + 1; @@ -100,52 +91,4 @@ public abstract class Call extends RBuiltinNode { return RDataFactory.createLanguage(RDataFactory.createList(data, names == null ? null : RDataFactory.createStringVector(names, RDataFactory.COMPLETE_VECTOR)), RLanguage.Type.FUNCALL); } - @SlowPath - private static RLanguage makeCall0Old(RNode fn, SourceSection src, RArgsValuesAndNames args) { - CallArgumentsNode callArgs; - if (args != null) { - Object[] argValues = args.getValues(); - RNode[] argValueNodes = new RNode[argValues.length]; - for (int i = 0; i < argValues.length; ++i) { - if (argValues[i] instanceof RPromise) { - argValueNodes[i] = NodeUtil.cloneNode((RNode) ((RPromise) argValues[i]).getRep()); - } else { - argValueNodes[i] = ConstantNode.create(argValues[i]); - } - } - callArgs = CallArgumentsNode.create(false, false, argValueNodes, args.getNames()); - } else { - callArgs = CallArgumentsNode.create(false, false, EMTPY_RNODE_ARRAY, null); - } - RCallNode call = RCallNode.createCall(src, fn, callArgs); - // TODO: should we distinguish a different RLanguage type for calls? - return RDataFactory.createLanguage(call); - } - - @SlowPath - private static String makeSource(String name, RArgsValuesAndNames args) { - StringBuilder sb = new StringBuilder(name); - sb.append('('); - if (args != null) { - String[] names = args.getNames(); - Object[] values = args.getValues(); - for (int i = 0; i < args.length(); ++i) { - if (names != null && names[i] != null) { - sb.append(names[i]).append(" = "); - } - // TODO not sure deparse is the right way to do this (might be better to get hold of - // the source sections of the arguments) - if (values[i] instanceof RPromise) { - sb.append(((RNode) ((RPromise) values[i]).getRep()).getSourceSection().getCode()); - } else { - sb.append(RDeparse.deparse(values[i], 60, false, -1)[0]); - } - if (i + 1 < args.length()) { - sb.append(", "); - } - } - } - return RRuntime.toString(sb.append(')')); - } - } 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 f9c19b7caff3c08cc11458e4cf2a4df78ee87d25..abff6826d36442a306c8859830381595e74bd728 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 @@ -24,9 +24,11 @@ package com.oracle.truffle.r.nodes.builtin.base; import static com.oracle.truffle.r.runtime.RBuiltinKind.*; +import com.oracle.truffle.api.CompilerDirectives.SlowPath; import com.oracle.truffle.api.dsl.*; import com.oracle.truffle.api.frame.*; import com.oracle.truffle.api.frame.FrameInstance.FrameAccess; +import com.oracle.truffle.api.source.*; import com.oracle.truffle.r.nodes.builtin.*; import com.oracle.truffle.r.runtime.*; import com.oracle.truffle.r.runtime.data.*; @@ -91,8 +93,9 @@ public class FrameFunctions { for (int i = 0; i < namesLength; ++i) { names[i] = RArguments.getName(cframe, i); } - RFunction function = RArguments.getFunction(cframe); - return Call.makeCall(RArguments.getCallSourceSection(cframe), function, new RArgsValuesAndNames(values, names)); + SourceSection callSource = RArguments.getCallSourceSection(cframe); + String functionName = extractFunctionName(callSource.getCode()); + return Call.makeCall(functionName, new RArgsValuesAndNames(values, names)); } @Specialization @@ -100,6 +103,53 @@ public class FrameFunctions { return sysCall((int) which); } + @SlowPath + private static String extractFunctionName(String callSource) { + // TODO remove the need for this by assembling a proper RLanguage object for the call + return callSource.substring(0, callSource.indexOf('(')); + } + + } + + /** + * Generate a call object in which all of the arguments are fully qualified. + */ + @RBuiltin(name = "match.call", kind = INTERNAL, parameterNames = {"definition", "call", "expand.dots"}) + public abstract static class MatchCall extends FrameHelper { + + @Override + protected final FrameAccess frameAccess() { + return FrameAccess.READ_ONLY; + } + + @Specialization + // TODO support expand.dots argument + protected RLanguage matchCall(@SuppressWarnings("unused") RNull definition, @SuppressWarnings("unused") RLanguage call, @SuppressWarnings("unused") byte expandDots) { + controlVisibility(); + Frame cframe = Utils.getCallerFrame(FrameAccess.READ_ONLY); + Object[] values = new Object[RArguments.getArgumentsLength(cframe)]; + RArguments.copyArgumentsInto(cframe, values); + int namesLength = RArguments.getNamesLength(cframe); + String[] names = new String[namesLength]; + for (int i = 0; i < namesLength; ++i) { + names[i] = RArguments.getName(cframe, i); + } + + // extract the name of the function that was called + // TODO find a better solution for this + String callSource = RArguments.getCallSourceSection(cframe).getCode(); + String functionName = callSource.substring(0, callSource.indexOf('(')); + + return Call.makeCall(functionName, new RArgsValuesAndNames(values, names)); + } + + @Specialization + @SuppressWarnings("unused") + protected RLanguage matchCall(RFunction definition, RLanguage call, byte expandDots) { + controlVisibility(); + throw RInternalError.unimplemented(); + } + } @RBuiltin(name = "sys.nframe", kind = INTERNAL, parameterNames = {}) @@ -145,19 +195,15 @@ public class FrameFunctions { @Specialization protected int sysParent(int nd) { controlVisibility(); - int n = nd; - int d = Utils.stackDepth(); - if (n > d) { - return 0; - } else { - return d - n; - } + int p = Utils.stackDepth() - nd; + return p < 0 ? 0 : p; } @Specialization protected int sysParent(double nd) { return sysParent((int) nd); } + } @RBuiltin(name = "sys.function", kind = INTERNAL, parameterNames = {"which"}) @@ -250,4 +296,5 @@ public class FrameFunctions { } } } + } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/R/match.R b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/R/match.R index 78d6de035ab6dae31ed836a94b0c224e34b546fe..5fa838f78944a69c30c340c035291744b1d8e8d5 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/R/match.R +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/R/match.R @@ -21,6 +21,10 @@ match <- function(x, table, nomatch = NA_integer_, incomparables = NULL) .Internal(match(x, table, nomatch, incomparables)) +match.call <- + function(definition=NULL, call=sys.call(sys.parent()), expand.dots=TRUE) + .Internal(match.call(definition,call,expand.dots)) + pmatch <- function(x, table, nomatch = NA, duplicates.ok = FALSE) .Internal(pmatch(as.character(x), as.character(table), nomatch, duplicates.ok)) diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RDeparse.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RDeparse.java index 7ead06e558f6280dd8b63c3d0e2c1a477613b6c5..238e9a47a20ca4a817457e74abf996b8f6cd355b 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RDeparse.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RDeparse.java @@ -310,7 +310,7 @@ public class RDeparse { state.append(f.getName()); state.append("\\\")"); } else { - throw RInternalError.unimplemented(); + state.append(((RRootNode) f.getTarget().getRootNode()).getSourceCode()); } break; } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/ArgumentMatcher.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/ArgumentMatcher.java index bf31da09e450c064cc4de3f8382473763b3219db..228fa37233c3afe4403cdda9f361404df00525ab 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/ArgumentMatcher.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/ArgumentMatcher.java @@ -301,7 +301,9 @@ public class ArgumentMatcher { int unmatchedNameCount = 0; // The nr of named supplied args that do not match // si = suppliedIndex, fi = formalIndex for (int si = 0; si < suppliedNames.length; si++) { - if (suppliedNames[si] == null) { + if (suppliedNames[si] == null || suppliedNames[si] == "") { + // suppliedNames[si] == "" is OK below as formals' "unmatched" name is specified as + // a literal as well continue; } @@ -323,7 +325,9 @@ public class ArgumentMatcher { for (int fi = 0; fi < resultArgs.length; fi++) { // Unmatched? if (!matchedFormalArgs.get(fi)) { - while (siCursor.hasNext() && siCursor.nextIndex() < suppliedNames.length && suppliedNames[siCursor.nextIndex()] != null) { + // suppliedNames[siCursor.nextIndex()] != "" is OK below as formals' "unmatched" + // name is specified as a literal as well + while (siCursor.hasNext() && siCursor.nextIndex() < suppliedNames.length && suppliedNames[siCursor.nextIndex()] != null && suppliedNames[siCursor.nextIndex()] != "") { // Slide over named parameters and find subsequent location of unnamed parameter siCursor.next(); } @@ -513,7 +517,9 @@ public class ArgumentMatcher { } matchedSuppliedArgs.set(found); break; - } else if (formalName.startsWith(suppliedName)) { + } else if (suppliedName != "" && formalName.startsWith(suppliedName)) { + // suppliedName != "" is OK here as formals' "unmatched" name is specified as a +// literal as well if (found >= 0) { throw RError.error(argsSrc, RError.Message.ARGUMENT_MATCHES_MULTIPLE, 1 + suppliedIndex); } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/Utils.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/Utils.java index c020de29d1db90bd1979e4aeaa5fb4d7e075a175..62ea5d8599bd2feb35360c3672d0377148a45578 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/Utils.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/Utils.java @@ -34,6 +34,7 @@ import com.oracle.truffle.api.frame.FrameInstance.FrameAccess; import com.oracle.truffle.api.nodes.*; import com.oracle.truffle.api.source.*; import com.oracle.truffle.r.runtime.data.*; +import com.oracle.truffle.r.runtime.env.*; public final class Utils { @@ -235,17 +236,49 @@ public final class Utils { } /** - * Return the depth of the stack, excluding the current frame and the pseudo-frame at the base. + * Return the depth of the stack. The "R depth" of the stack is determined by those frames that + * contribute to actual R function execution, hence, FastR-internal frames that are used to, + * e.g., evaluate promises must be left out. The same is true for substituted frames (see + * {@code FunctionDefinitionNode#substituteFrame}). */ public static int stackDepth() { - LongAdder depth = new LongAdder(); - - Truffle.getRuntime().iterateFrames(frameInstance -> { - depth.increment(); + LongAdder n = new LongAdder(); + Object depth = Truffle.getRuntime().iterateFrames(frameInstance -> { + Frame frame = frameInstance.getFrame(FrameAccess.READ_ONLY, false); + if (REnvironment.isGlobalEnvFrame(frame)) { + return n.intValue(); + } + boolean promise = isPromiseEvaluationFrame(frameInstance); + boolean substituted = isSubstitutedFrame(frame); + if (!promise) { + n.increment(); + } else if (!substituted) { + n.decrement(); + } + if (substituted) { + n.decrement(); + } return null; }); + return depth == null ? 0 : (int) depth; + } + + /** + * TODO provide a better way of determining promise evaluation nature of frames than using + * {@code toString()} on the call target. + */ + @SlowPath + private static boolean isPromiseEvaluationFrame(FrameInstance frameInstance) { + String desc = frameInstance.getCallTarget().toString(); + return desc == RPromise.CLOSURE_WRAPPER_NAME; + } - return depth.intValue() - 1; + /** + * An arguments array length of 1 is indicative of a substituted frame. See + * {@code FunctionDefinitionNode.substituteFrame}. + */ + private static boolean isSubstitutedFrame(Frame frame) { + return frame.getArguments().length == 1; } /** @@ -266,8 +299,7 @@ public final class Utils { public static VirtualFrame getActualCurrentFrame() { FrameInstance frameInstance = Truffle.getRuntime().getCurrentFrame(); VirtualFrame frame = (VirtualFrame) frameInstance.getFrame(FrameAccess.MATERIALIZE, true); - if (frame.getArguments().length == 1) { - // an arguments array length of 1 is indicative of a substituted frame + if (isSubstitutedFrame(frame)) { frame = (VirtualFrame) frame.getArguments()[0]; } return frame; diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RPromise.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RPromise.java index df958de33825fd9bcb3852a5653e1648430fe284..dab6ab839a852085d08d32c2934e9317b9f94e12 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RPromise.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RPromise.java @@ -82,7 +82,7 @@ public final class RPromise extends RLanguageRep { NO_ARG; } - private static final String CLOSURE_WRAPPER_NAME = "<promise>"; + public static final String CLOSURE_WRAPPER_NAME = new String("<promise>"); /** * @see EvalPolicy 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 1bf624c7ee725fcb5256ae7bdeb98e7441eab6e2..0098f57dd9f270301dab3cede244c98e011627b3 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 @@ -8712,6 +8712,14 @@ character(0) #{ match(c(1,2,3,4,5),c(1,2,1,2)) } [1] 1 2 NA NA NA +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testMatchCall +#{ f <- function() match.call() ; f() } +f() + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testMatchCall +#{ f <- function(x) match.call() ; f(2) } +f(x = 2) + ##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testMatchFun #{ f <- function(x) { y <- match.fun(x) ; y(3,4) } ; c(f("+"),f("*")) } [1] 7 12 @@ -12172,10 +12180,6 @@ Error in sum(as.raw(42), as.raw(7)) : invalid 'type' (raw) of argument ##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testSwitch #{switch(4,1,2,3)} -##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testSysCall -#{ (function() sys.call())() } -(function() sys.call())() - ##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testSysCall #{ f <- function() sys.call() ; f() } f() @@ -12204,17 +12208,85 @@ h() #{ f <- function() sys.call(2) ; g <- function() f() ; h <- function() g() ; h() } g() -##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testSysCall -#{ f <- function(x) sys.call() ; f(2) } -f(2) - ##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testSysCall #{ f <- function(x) sys.call() ; f(x = 2) } f(x = 2) -##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testSysCall -#{ f <- function(x) sys.call() ; g <- function() 23 ; f(g()) } -f(g()) +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testSysNFrame +#{ f <- function() sys.nframe() ; f() } +[1] 1 + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testSysNFrame +#{ f <- function() sys.nframe() ; g <- function() f() ; g() } +[1] 2 + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testSysNFrame +#{ f <- function() sys.nframe() ; g <- function() f() ; h <- function() g() ; h() } +[1] 3 + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testSysNFrame +#{ f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=sys.nframe()) g(z) ; h() } +[1] 1 + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testSysNFrame +#{ f <- function(x=sys.nframe()) x ; g <- function() f() ; h <- function() g() ; h() } +[1] 3 + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testSysNFrame +#{ sys.nframe() } +[1] 0 + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testSysParent +#{ f <- function() sys.parent() ; f() } +[1] 0 + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testSysParent +#{ f <- function() sys.parent() ; g <- function() f() ; g() } +[1] 1 + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testSysParent +#{ f <- function() sys.parent() ; g <- function() f() ; h <- function() g() ; h() } +[1] 2 + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testSysParent +#{ f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=sys.parent()) g(z) ; h() } +[1] 0 + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testSysParent +#{ f <- function(x=sys.parent()) x ; g <- function() f() ; h <- function() g() ; h() } +[1] 2 + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testSysParent +#{ sys.parent() } +[1] 0 + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testSysParent +#{ u <- function() sys.parent() ; f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=u()) g(z) ; h() } +[1] 1 + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testSysParents +#{ f <- function() sys.parents() ; f() } +[1] 0 + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testSysParents +#{ f <- function() sys.parents() ; g <- function() f() ; g() } +[1] 0 1 + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testSysParents +#{ f <- function() sys.parents() ; g <- function() f() ; h <- function() g() ; h() } +[1] 0 1 2 + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testSysParents +#{ f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=sys.parents()) g(z) ; h() } +[1] 0 + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testSysParents +#{ f <- function(x=sys.parents()) x ; g <- function() f() ; h <- function() g() ; h() } +[1] 0 1 2 + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testSysParents +#{ sys.parents() } +integer(0) ##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testTabulate #{tabulate(c(-2,0,2,3,3,5))} @@ -15004,6 +15076,10 @@ Error in f(a = 1, ...) : #{ f <- function(a, barg) { a + barg } ; g <- function(...) { f(a=1, ...) } ; g(b=2) } [1] 3 +##com.oracle.truffle.r.test.simple.TestSimpleFunctions.testDots +#{ f <- function(a, barg, ...) { a + barg } ; g <- function(...) { f(a=1, ...) } ; g(b=2,3) } +[1] 3 + ##com.oracle.truffle.r.test.simple.TestSimpleFunctions.testDots #{ f <- function(a, barg, bextra) { a + barg } ; g <- function(...) { f(a=1, ...) } ; g(b=2,3) } Error in f(a = 1, ...) : argument 2 matches multiple formal arguments @@ -15017,6 +15093,10 @@ Error in f(a = 1, ...) : argument 2 matches multiple formal arguments Error in f(a = 1, ...) : formal argument "bextra" matched by multiple actual arguments +##com.oracle.truffle.r.test.simple.TestSimpleFunctions.testDots +#{ f <- function(a, barg, bextra, dummy) { a + barg } ; g <- function(...) { f(a=1, ...) } ; g(be=2,du=3, 3) } +[1] 4 + ##com.oracle.truffle.r.test.simple.TestSimpleFunctions.testDots #{ f <- function(a=1,...) a ; f() } [1] 1 diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/all/AllTests.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/all/AllTests.java index 38b5122ef447525271132496bcac40c1b928c6f6..5e59996e441e91586a54404282d49d695203584a 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/all/AllTests.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/all/AllTests.java @@ -9813,6 +9813,16 @@ public class AllTests extends TestBase { assertEval("{ match(\"abc\", c(\"xyz\"), nomatch=-1) }"); } + @Test + public void TestSimpleBuiltins_testMatchCall_a0448ccc47d09e1ad95ea97342b088e9() { + assertEval("{ f <- function() match.call() ; f() }"); + } + + @Test + public void TestSimpleBuiltins_testMatchCall_b16970ba5a0fdc6cac07900fcdcf214b() { + assertEval("{ f <- function(x) match.call() ; f(2) }"); + } + @Test public void TestSimpleBuiltins_testMatchFun_4dc251ff1db19e52f20841e136754b32() { assertEval("{ f <- match.fun(length) ; f(c(1,2,3)) }"); @@ -13918,26 +13928,11 @@ public class AllTests extends TestBase { assertEval("{ f <- function() sys.call() ; f() }"); } - @Test - public void TestSimpleBuiltins_testSysCall_f44ee9a6ea3efb3dd3af1c314ae8b266() { - assertEval("{ (function() sys.call())() }"); - } - - @Test - public void TestSimpleBuiltins_testSysCall_7cbf9b612d6ed31bbb101daf73e590f7() { - assertEval("{ f <- function(x) sys.call() ; f(2) }"); - } - @Test public void TestSimpleBuiltins_testSysCall_72545e399dae6c0c4c65872bc895c67a() { assertEval("{ f <- function(x) sys.call() ; f(x = 2) }"); } - @Test - public void TestSimpleBuiltins_testSysCall_13208aaa10f5c6ede2ca1043542e65d3() { - assertEval("{ f <- function(x) sys.call() ; g <- function() 23 ; f(g()) }"); - } - @Test public void TestSimpleBuiltins_testSysCall_76d487db1e13401e8bbda4051cbde274() { assertEval("{ f <- function() sys.call(1) ; g <- function() f() ; g() }"); @@ -13968,6 +13963,21 @@ public class AllTests extends TestBase { assertEval("{ f <- function() sys.call() ; g <- function() f() ; h <- function() g() ; h() }"); } + @Test + public void TestSimpleBuiltins_testSysCallIgnore_f44ee9a6ea3efb3dd3af1c314ae8b266() { + assertEval("{ (function() sys.call())() }"); + } + + @Test + public void TestSimpleBuiltins_testSysCallIgnore_7cbf9b612d6ed31bbb101daf73e590f7() { + assertEval("{ f <- function(x) sys.call() ; f(2) }"); + } + + @Test + public void TestSimpleBuiltins_testSysCallIgnore_13208aaa10f5c6ede2ca1043542e65d3() { + assertEval("{ f <- function(x) sys.call() ; g <- function() 23 ; f(g()) }"); + } + @Test public void TestSimpleBuiltins_testSysCallIgnore_27098193cb36cf8c763bc06a7cc91a50() { assertEval("{ f <- function() sys.call() ; typeof(f()[[1]]) }"); @@ -13983,6 +13993,111 @@ public class AllTests extends TestBase { assertEval("{ f <- function(x) sys.call() ; typeof(f(x = 2)[[2]]) }"); } + @Test + public void TestSimpleBuiltins_testSysNFrame_c3d97dfd45908c32f8cfe394553f4c63() { + assertEval("{ sys.nframe() }"); + } + + @Test + public void TestSimpleBuiltins_testSysNFrame_30dedef8a0698bff34b4b97a34fdb72e() { + assertEval("{ f <- function() sys.nframe() ; f() }"); + } + + @Test + public void TestSimpleBuiltins_testSysNFrame_2cd412ff707741932dc44f80b9b7b17a() { + assertEval("{ f <- function() sys.nframe() ; g <- function() f() ; g() }"); + } + + @Test + public void TestSimpleBuiltins_testSysNFrame_7f96e07123460e87bc11864977426026() { + assertEval("{ f <- function() sys.nframe() ; g <- function() f() ; h <- function() g() ; h() }"); + } + + @Test + public void TestSimpleBuiltins_testSysNFrame_5eaf283d4cade78ea655f788c8520f1b() { + assertEval("{ f <- function(x=sys.nframe()) x ; g <- function() f() ; h <- function() g() ; h() }"); + } + + @Test + public void TestSimpleBuiltins_testSysNFrame_53dab62970d1a3ec43b1f0ba50f70ed0() { + assertEval("{ f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=sys.nframe()) g(z) ; h() }"); + } + + @Test + public void TestSimpleBuiltins_testSysNFrameIgnore_17d834568c640b6a0227e3d10a88da86() { + assertEval("{ u <- function() sys.nframe() ; f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=u()) g(z) ; h() }"); + } + + @Test + public void TestSimpleBuiltins_testSysParent_dc8281a71f0743a334066df460d5d250() { + assertEval("{ sys.parent() }"); + } + + @Test + public void TestSimpleBuiltins_testSysParent_2a69faf7b4cb3ed979d37dcebbba2b5d() { + assertEval("{ f <- function() sys.parent() ; f() }"); + } + + @Test + public void TestSimpleBuiltins_testSysParent_10ef67d132292ca00886e996eade9514() { + assertEval("{ f <- function() sys.parent() ; g <- function() f() ; g() }"); + } + + @Test + public void TestSimpleBuiltins_testSysParent_addd9a102d0607d5468ae286159e9926() { + assertEval("{ f <- function() sys.parent() ; g <- function() f() ; h <- function() g() ; h() }"); + } + + @Test + public void TestSimpleBuiltins_testSysParent_ec8486194fe801b1b55426331942e705() { + assertEval("{ f <- function(x=sys.parent()) x ; g <- function() f() ; h <- function() g() ; h() }"); + } + + @Test + public void TestSimpleBuiltins_testSysParent_8f717f04a5ba89c5cf2ffeeeab21de0b() { + assertEval("{ f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=sys.parent()) g(z) ; h() }"); + } + + @Test + public void TestSimpleBuiltins_testSysParent_daad3815e7f45995c349db50245808a5() { + assertEval("{ u <- function() sys.parent() ; f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=u()) g(z) ; h() }"); + } + + @Test + public void TestSimpleBuiltins_testSysParents_8a154bf595446ee38981490446bf3dd2() { + assertEval("{ sys.parents() }"); + } + + @Test + public void TestSimpleBuiltins_testSysParents_87513796edf8bb11cbebe94457b9803e() { + assertEval("{ f <- function() sys.parents() ; f() }"); + } + + @Test + public void TestSimpleBuiltins_testSysParents_01cb12e566a9cfb00b0c8d620dfae646() { + assertEval("{ f <- function() sys.parents() ; g <- function() f() ; g() }"); + } + + @Test + public void TestSimpleBuiltins_testSysParents_23a33f023d6a23983b4bca3668923720() { + assertEval("{ f <- function() sys.parents() ; g <- function() f() ; h <- function() g() ; h() }"); + } + + @Test + public void TestSimpleBuiltins_testSysParents_5f3be8dcfca25bcda8b29ff546f7d82c() { + assertEval("{ f <- function(x=sys.parents()) x ; g <- function() f() ; h <- function() g() ; h() }"); + } + + @Test + public void TestSimpleBuiltins_testSysParents_845cdff1d9da4ed2264439f90ae7789c() { + assertEval("{ f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=sys.parents()) g(z) ; h() }"); + } + + @Test + public void TestSimpleBuiltins_testSysParentsIgnore_6117cb26d3f09dce59533ba94919f49a() { + assertEval("{ u <- function() sys.parents() ; f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=u()) g(z) ; h() }"); + } + @Test public void TestSimpleBuiltins_testTabulate_4b7b5ec3ddf837f6040cf4105e954f88() { assertEval("{tabulate(c(2,3,5))}"); @@ -17083,6 +17198,16 @@ public class AllTests extends TestBase { assertEval("{ f <- function(...) g(...); g <- function(a,b) { print(a); print(b) }; f(1,2); f(a=3,b=4); f(a=5,b=6) }"); } + @Test + public void TestSimpleFunctions_testDots_168904965e7c99fe53738eba7ef80c6e() { + assertEval("{ f <- function(a, barg, ...) { a + barg } ; g <- function(...) { f(a=1, ...) } ; g(b=2,3) }"); + } + + @Test + public void TestSimpleFunctions_testDots_446276723386c4e17ee775d34b52759a() { + assertEval("{ f <- function(a, barg, bextra, dummy) { a + barg } ; g <- function(...) { f(a=1, ...) } ; g(be=2,du=3, 3) }"); + } + @Test public void TestSimpleFunctions_testDots_2a99369402e3625a074eafef17085ffa() { assertEvalError("{ f <- function(x) { ..1 } ; f(10) }"); @@ -17148,16 +17273,6 @@ public class AllTests extends TestBase { assertEval("{ f <- function(...) { substitute(..1) } ; f(x+y) }"); } - @Test - public void TestSimpleFunctions_testDotsIgnore_168904965e7c99fe53738eba7ef80c6e() { - assertEval("{ f <- function(a, barg, ...) { a + barg } ; g <- function(...) { f(a=1, ...) } ; g(b=2,3) }"); - } - - @Test - public void TestSimpleFunctions_testDotsIgnore_446276723386c4e17ee775d34b52759a() { - assertEval("{ f <- function(a, barg, bextra, dummy) { a + barg } ; g <- function(...) { f(a=1, ...) } ; g(be=2,du=3, 3) }"); - } - @Test public void TestSimpleFunctions_testDotsIgnore_a3678db1544ef8395deec4ed02acdb3d() { assertEvalError("{ g <- function(a,b,x) { a + b * x } ; f <- function(...) { g(x=4, ..., 10) } ; f(b=1,a=2) }"); diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/failing/FailingTests.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/failing/FailingTests.java index 4793cf83ded9d5a64ed962cbc84ac1f41836bf9f..8798bcc4720d38db65a5df7a299b173ba3481bdb 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/failing/FailingTests.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/failing/FailingTests.java @@ -1773,6 +1773,21 @@ public class FailingTests extends TestBase { assertEval("{answer<-\"no\";switch(as.character(answer), yes=, YES=1, no=, NO=2,3)}"); } + @Ignore + public void TestSimpleBuiltins_testSysCallIgnore_f44ee9a6ea3efb3dd3af1c314ae8b266() { + assertEval("{ (function() sys.call())() }"); + } + + @Ignore + public void TestSimpleBuiltins_testSysCallIgnore_7cbf9b612d6ed31bbb101daf73e590f7() { + assertEval("{ f <- function(x) sys.call() ; f(2) }"); + } + + @Ignore + public void TestSimpleBuiltins_testSysCallIgnore_13208aaa10f5c6ede2ca1043542e65d3() { + assertEval("{ f <- function(x) sys.call() ; g <- function() 23 ; f(g()) }"); + } + @Ignore public void TestSimpleBuiltins_testSysCallIgnore_27098193cb36cf8c763bc06a7cc91a50() { assertEval("{ f <- function() sys.call() ; typeof(f()[[1]]) }"); @@ -1788,6 +1803,16 @@ public class FailingTests extends TestBase { assertEval("{ f <- function(x) sys.call() ; typeof(f(x = 2)[[2]]) }"); } + @Ignore + public void TestSimpleBuiltins_testSysNFrameIgnore_17d834568c640b6a0227e3d10a88da86() { + assertEval("{ u <- function() sys.nframe() ; f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=u()) g(z) ; h() }"); + } + + @Ignore + public void TestSimpleBuiltins_testSysParentsIgnore_6117cb26d3f09dce59533ba94919f49a() { + assertEval("{ u <- function() sys.parents() ; f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=u()) g(z) ; h() }"); + } + @Ignore public void TestSimpleBuiltins_testTriangular_41ca685d92138926005a9f7fb6ca8478() { assertEval("{ m <- { matrix( as.character(1:6), nrow=2 ) } ; diag(m) <- c(1,2) ; m }"); @@ -1948,16 +1973,6 @@ public class FailingTests extends TestBase { assertEval("{ f <- function(...) { substitute(..1) } ; f(x+y) }"); } - @Ignore - public void TestSimpleFunctions_testDotsIgnore_168904965e7c99fe53738eba7ef80c6e() { - assertEval("{ f <- function(a, barg, ...) { a + barg } ; g <- function(...) { f(a=1, ...) } ; g(b=2,3) }"); - } - - @Ignore - public void TestSimpleFunctions_testDotsIgnore_446276723386c4e17ee775d34b52759a() { - assertEval("{ f <- function(a, barg, bextra, dummy) { a + barg } ; g <- function(...) { f(a=1, ...) } ; g(be=2,du=3, 3) }"); - } - @Ignore public void TestSimpleFunctions_testDotsIgnore_a3678db1544ef8395deec4ed02acdb3d() { assertEvalError("{ g <- function(a,b,x) { a + b * x } ; f <- function(...) { g(x=4, ..., 10) } ; f(b=1,a=2) }"); diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/simple/TestSimpleBuiltins.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/simple/TestSimpleBuiltins.java index c92e0ce5dea676ca32ab7adc8fd0f8f2d2fc3b14..bc6552c87561393f9c90b9cc7600275a8b1848f8 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/simple/TestSimpleBuiltins.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/simple/TestSimpleBuiltins.java @@ -2812,10 +2812,7 @@ public class TestSimpleBuiltins extends TestBase { @Test public void testSysCall() { assertEval("{ f <- function() sys.call() ; f() }"); - assertEval("{ (function() sys.call())() }"); - assertEval("{ f <- function(x) sys.call() ; f(2) }"); assertEval("{ f <- function(x) sys.call() ; f(x = 2) }"); - assertEval("{ f <- function(x) sys.call() ; g <- function() 23 ; f(g()) }"); assertEval("{ f <- function() sys.call(1) ; g <- function() f() ; g() }"); assertEval("{ f <- function() sys.call(2) ; g <- function() f() ; h <- function() g() ; h() }"); assertEval("{ f <- function() sys.call(1) ; g <- function() f() ; h <- function() g() ; h() }"); @@ -2827,11 +2824,64 @@ public class TestSimpleBuiltins extends TestBase { @Test @Ignore public void testSysCallIgnore() { + assertEval("{ (function() sys.call())() }"); + assertEval("{ f <- function(x) sys.call() ; f(2) }"); + assertEval("{ f <- function(x) sys.call() ; g <- function() 23 ; f(g()) }"); + assertEval("{ f <- function() sys.call() ; typeof(f()[[1]]) }"); assertEval("{ f <- function(x) sys.call() ; typeof(f(x = 2)[[1]]) }"); assertEval("{ f <- function(x) sys.call() ; typeof(f(x = 2)[[2]]) }"); } + @Test + public void testSysParent() { + assertEval("{ sys.parent() }"); + assertEval("{ f <- function() sys.parent() ; f() }"); + assertEval("{ f <- function() sys.parent() ; g <- function() f() ; g() }"); + assertEval("{ f <- function() sys.parent() ; g <- function() f() ; h <- function() g() ; h() }"); + assertEval("{ f <- function(x=sys.parent()) x ; g <- function() f() ; h <- function() g() ; h() }"); + assertEval("{ f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=sys.parent()) g(z) ; h() }"); + assertEval("{ u <- function() sys.parent() ; f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=u()) g(z) ; h() }"); + } + + @Test + public void testSysParents() { + assertEval("{ sys.parents() }"); + assertEval("{ f <- function() sys.parents() ; f() }"); + assertEval("{ f <- function() sys.parents() ; g <- function() f() ; g() }"); + assertEval("{ f <- function() sys.parents() ; g <- function() f() ; h <- function() g() ; h() }"); + assertEval("{ f <- function(x=sys.parents()) x ; g <- function() f() ; h <- function() g() ; h() }"); + assertEval("{ f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=sys.parents()) g(z) ; h() }"); + } + + @Test + @Ignore + public void testSysParentsIgnore() { + assertEval("{ u <- function() sys.parents() ; f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=u()) g(z) ; h() }"); + } + + @Test + public void testSysNFrame() { + assertEval("{ sys.nframe() }"); + assertEval("{ f <- function() sys.nframe() ; f() }"); + assertEval("{ f <- function() sys.nframe() ; g <- function() f() ; g() }"); + assertEval("{ f <- function() sys.nframe() ; g <- function() f() ; h <- function() g() ; h() }"); + assertEval("{ f <- function(x=sys.nframe()) x ; g <- function() f() ; h <- function() g() ; h() }"); + assertEval("{ f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=sys.nframe()) g(z) ; h() }"); + } + + @Test + @Ignore + public void testSysNFrameIgnore() { + assertEval("{ u <- function() sys.nframe() ; f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=u()) g(z) ; h() }"); + } + + @Test + public void testMatchCall() { + assertEval("{ f <- function() match.call() ; f() }"); + assertEval("{ f <- function(x) match.call() ; f(2) }"); + } + @Test public void testDoCall() { assertEval("{ x<-list(c(1,2)); do.call(\"as.matrix\", x) }"); diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/simple/TestSimpleFunctions.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/simple/TestSimpleFunctions.java index 1505bdba39e555da0f35be7d872bd8f98e8e09e4..d088ac2179bb492d5f917e1da910bf93d14c6fd9 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/simple/TestSimpleFunctions.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/simple/TestSimpleFunctions.java @@ -234,6 +234,9 @@ public class TestSimpleFunctions extends TestBase { assertEval("{ x<-7; y<-42; f<-function(...) { as.list(substitute(g(...))) }; f(x,y) }"); assertEval("{ f <- function(...) g(...); g <- function(a,b) { print(a); print(b) }; f(1,2); f(a=3,b=4); f(a=5,b=6) }"); + + assertEval("{ f <- function(a, barg, ...) { a + barg } ; g <- function(...) { f(a=1, ...) } ; g(b=2,3) }"); + assertEval("{ f <- function(a, barg, bextra, dummy) { a + barg } ; g <- function(...) { f(a=1, ...) } ; g(be=2,du=3, 3) }"); } @Test @@ -244,8 +247,6 @@ public class TestSimpleFunctions extends TestBase { assertEvalError("{ g <- function(a,b,x) { a + b * x } ; f <- function(...) { g(x=4, ..., 10) } ; f(b=1,a=2) }"); assertEvalError("{ lapply(1:3, \"dummy\") }"); - assertEval("{ f <- function(a, barg, ...) { a + barg } ; g <- function(...) { f(a=1, ...) } ; g(b=2,3) }"); - assertEval("{ f <- function(a, barg, bextra, dummy) { a + barg } ; g <- function(...) { f(a=1, ...) } ; g(be=2,du=3, 3) }"); assertEvalError("{ f <- function(a, barg, bextra, dummy) { a + barg } ; g <- function(...) { f(a=1, ..., x=2) } ; g(1) }"); assertEvalError("{ f <- function(a, barg, bextra, dummy) { a + barg } ; g <- function(...) { f(a=1, ..., x=2,z=3) } ; g(1) }"); assertEvalError("{ f <- function(a, barg, bextra, dummy) { a + barg } ; g <- function(...) { f(a=1, ..., xxx=2) } ; g(1) }"); diff --git a/mx.fastr/imports b/mx.fastr/imports index c9e72b2a1439a4bfe98fa238bc5fa09d0f107be9..f6514ed2a359fee576fdcc764a15d24e6ba179dd 100644 --- a/mx.fastr/imports +++ b/mx.fastr/imports @@ -1 +1 @@ -graal,97d0508b7cf1399d55099c15c9389bd43b0b1c75,http://hg.openjdk.java.net/graal/graal +graal,62d7d16b170bbd162b1095a13b4dd4df771ee053,http://hg.openjdk.java.net/graal/graal