From 11dad67c3b811315a35fc0a2f8b5d7d49ecc085e Mon Sep 17 00:00:00 2001
From: Mick Jordan <mick.jordan@oracle.com>
Date: Sun, 27 Mar 2016 15:18:56 -0700
Subject: [PATCH] refactor/add frame function tests

---
 .../r/nodes/builtin/base/FrameFunctions.java  |   4 +-
 .../truffle/r/test/ExpectedTestOutput.test    | 356 +++++++++++-------
 .../builtins/TestBuiltin_parentframe.java     |  20 +-
 .../r/test/builtins/TestBuiltin_syscall.java  |  46 +++
 .../r/test/builtins/TestBuiltin_syscalls.java |  33 ++
 .../test/builtins/TestBuiltin_sysnframe.java  |  30 ++
 .../test/builtins/TestBuiltin_sysparent.java  |   9 +
 .../test/builtins/TestBuiltin_sysparents.java |  30 ++
 .../r/test/builtins/TestMiscBuiltins.java     |  52 ---
 mx.fastr/copyrights/overrides                 |   4 +
 10 files changed, 390 insertions(+), 194 deletions(-)
 create mode 100644 com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_syscall.java
 create mode 100644 com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_syscalls.java
 create mode 100644 com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sysnframe.java
 create mode 100644 com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sysparents.java

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 61c5c3b0f2..7dccc62c17 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
@@ -592,9 +592,9 @@ public class FrameFunctions {
         @Specialization
         protected REnvironment parentFrame(VirtualFrame frame, int n) {
             controlVisibility();
-            if (n == 0) {
+            if (n <= 0) {
                 errorProfile.enter();
-                throw RError.error(this, RError.Message.INVALID_ARGUMENT, RRuntime.intToString(n));
+                throw RError.error(this, RError.Message.INVALID_VALUE, "n");
             }
             Frame callerFrame = Utils.iterateRFrames(frameAccess(), new Function<Frame, Frame>() {
                 int parentDepth = RArguments.getDepth(frame) - n - 1;
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 e55e9dbeb6..dfa19d88f7 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
@@ -35754,16 +35754,51 @@ integer(0)
 NULL
 
 ##com.oracle.truffle.r.test.builtins.TestBuiltin_parentframe.testParentFrame
+#parent.frame()
+<environment: R_GlobalEnv>
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_parentframe.testParentFrame
+#parent.frame(-1)
+Error in parent.frame(-1) : invalid 'n' value
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_parentframe.testParentFrame
+#parent.frame(0)
+Error in parent.frame(0) : invalid 'n' value
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_parentframe.testParentFrame
+#{ f <- function() parent.frame() ; g <- function() { n <- 100; f() }; r <- g(); ls(r) }
+[1] "n"
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_parentframe.testParentFrame
+#{ f <- function() parent.frame() }
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_parentframe.testParentFrame
+#{ f <- function() parent.frame(2); g <- function() f(); g() }
+<environment: R_GlobalEnv>
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_parentframe.testParentFrame
+#{ f <- function() parent.frame(3); g <- function() f(); g() }
+<environment: R_GlobalEnv>
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_parentframe.testParentFramePromises
+#{ f <- function(frame) frame; g <- function() f(parent.frame()); g() }
+<environment: R_GlobalEnv>
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_parentframe.testParentFramePromises
+#{ f <- function(frame) frame; g <- function() f(parent.frame(3)); g() }
+<environment: R_GlobalEnv>
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_parentframe.testS3ParentFrame
 #a <- 0; f <- function(x) { a <- 1; UseMethod('f') }; f.default <- function(x) { a <- 2; (function(x) get('a', envir = parent.frame(x)))(x) }; f(1); f(2); f(3)
 [1] 2
 [1] 0
 [1] 0
 
-##com.oracle.truffle.r.test.builtins.TestBuiltin_parentframe.testParentFrame
+##com.oracle.truffle.r.test.builtins.TestBuiltin_parentframe.testS3ParentFrame
 #a <- 0; f <- function(x) { a <- 1; UseMethod('f') }; f.default <- function(x) { a <- 2; get('a', envir = parent.frame()) }; f(1)
 [1] 0
 
-##com.oracle.truffle.r.test.builtins.TestBuiltin_parentframe.testParentFrame
+##com.oracle.truffle.r.test.builtins.TestBuiltin_parentframe.testS3ParentFrame
 #a <- 0; f <- function(x) { a <- 1; UseMethod('f') }; f.foo <- function(x) { a <- 2; NextMethod(); };<<<NEWLINE>>>f.default <- function(x) { a <- 3; (function(x) get('a', envir = parent.frame(x)))(x) }; v <- 1; class(v) <- 'foo'; f(v); v <- 2; class(v) <- 'foo'; f(v)
 [1] 3
 [1] 0
@@ -46267,6 +46302,137 @@ Error: duplicate 'switch' defaults: 'v77' and 'v55'
 #argv <- list(2L, TRUE, FALSE, FALSE);do.call('switch', argv)
 [1] FALSE
 
+##com.oracle.truffle.r.test.builtins.TestBuiltin_syscall.testSysCall
+#{ (function() sys.call())() }
+(function() sys.call())()
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_syscall.testSysCall
+#{ f <- function() sys.call() ; f() }
+f()
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_syscall.testSysCall
+#{ f <- function() sys.call() ; g <- function() f() ; h <- function() g() ; h() }
+f()
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_syscall.testSysCall
+#{ f <- function() sys.call() ; typeof(f()[[1]]) }
+[1] "symbol"
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_syscall.testSysCall
+#{ f <- function() sys.call(-1) ; g <- function() f() ; h <- function() g() ; h() }
+g()
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_syscall.testSysCall
+#{ f <- function() sys.call(-2) ; g <- function() f() ; h <- function() g() ; h() }
+h()
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_syscall.testSysCall
+#{ f <- function() sys.call(1) ; g <- function() f() ; g() }
+g()
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_syscall.testSysCall
+#{ f <- function() sys.call(1) ; g <- function() f() ; h <- function() g() ; h() }
+h()
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_syscall.testSysCall
+#{ f <- function() sys.call(2) ; g <- function() f() ; h <- function() g() ; h() }
+g()
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_syscall.testSysCall
+#{ f <- function(x) sys.call() ; f(2) }
+f(2)
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_syscall.testSysCall
+#{ f <- function(x) sys.call() ; f(x = 2) }
+f(x = 2)
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_syscall.testSysCall
+#{ f <- function(x) sys.call() ; g <- function() 23 ; f(g()) }
+f(g())
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_syscall.testSysCall
+#{ f <- function(x) sys.call() ; typeof(f(x = 2)[[1]]) }
+[1] "symbol"
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_syscall.testSysCall
+#{ f <- function(x) sys.call() ; typeof(f(x = 2)[[2]]) }
+[1] "double"
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_syscall.testSysCall
+#{ f <- function(x, y) sys.call() ; f(1, 2) }
+f(1, 2)
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_syscall.testSysCall
+#{ f <- function(x, y) sys.call() ; f(1, y=2) }
+f(1, y = 2)
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_syscall.testSysCall
+#{ f <- function(x, y) sys.call() ; f(x=1, 2) }
+f(x = 1, 2)
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_syscall.testSysCall
+#{ f <- function(x, y) sys.call() ; f(y=1, 2) }
+f(y = 1, 2)
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_syscall.testSysCall
+#{ f <- function(x, y) sys.call() ; f(y=1, x=2) }
+f(y = 1, x = 2)
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_syscalls.testSysCalls
+#sys.calls()
+NULL
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_syscalls.testSysCalls
+#{ f <- function(x) sys.calls(); g <- function() f(x); g() }
+[[1]]
+g()
+
+[[2]]
+f(x)
+
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_syscalls.testSysCalls
+#{ f <- function(x) sys.calls(); g <- function() f(x); length(try(g())) }
+[1] 7
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_syscalls.testSysCallsPromises
+#{ f <- function(x) x; g <- function() f(sys.calls()); g() }
+[[1]]
+g()
+
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_syscalls.testSysCallsPromises
+#{ f <- function(x) x; g <- function() f(sys.calls()); length(try(g())) }
+[1] 6
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_sysnframe.testSysNFrame
+#{ f <- function() sys.nframe() ; f() }
+[1] 1
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_sysnframe.testSysNFrame
+#{ f <- function() sys.nframe() ; g <- function() f() ; g() }
+[1] 2
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_sysnframe.testSysNFrame
+#{ f <- function() sys.nframe() ; g <- function() f() ; h <- function() g() ; h() }
+[1] 3
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_sysnframe.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.builtins.TestBuiltin_sysnframe.testSysNFrame
+#{ f <- function(x=sys.nframe()) x ; g <- function() f() ; h <- function() g() ; h() }
+[1] 3
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_sysnframe.testSysNFrame
+#{ sys.nframe() }
+[1] 0
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_sysnframe.testSysNFrame
+#{ u <- function() sys.nframe() ; f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=u()) g(z) ; h() }
+[1] 4
+
 ##com.oracle.truffle.r.test.builtins.TestBuiltin_sysonexit.testsysonexit1
 # .Internal(sys.on.exit())
 NULL
@@ -46284,18 +46450,34 @@ NULL
 [1] 2
 
 ##com.oracle.truffle.r.test.builtins.TestBuiltin_sysparent.testSysParent
-#{ f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=sys.parent()) g(z) ; h() }
-[1] 0
+#{ f <- function(x) sys.parent(x); f(-4) }
+[1] 1
 
 ##com.oracle.truffle.r.test.builtins.TestBuiltin_sysparent.testSysParent
-#{ f <- function(x=sys.parent()) x ; g <- function() f() ; h <- function() g() ; h() }
-[1] 2
+#{ f <- function(x) sys.parent(x); f(0) }
+[1] 1
 
 ##com.oracle.truffle.r.test.builtins.TestBuiltin_sysparent.testSysParent
-#{ sys.parent() }
+#{ f <- function(x) sys.parent(x); f(4) }
 [1] 0
 
 ##com.oracle.truffle.r.test.builtins.TestBuiltin_sysparent.testSysParent
+#{ sys.parent() }
+[1] 0
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_sysparent.testSysParentPromises
+#{ f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=sys.parent()) g(z) ; h() }
+[1] 0
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_sysparent.testSysParentPromises
+#{ f <- function(x) x; g <- function() f(sys.parent()); h <- function() g(); h() }
+[1] 1
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_sysparent.testSysParentPromises
+#{ f <- function(x=sys.parent()) x ; g <- function() f() ; h <- function() g() ; h() }
+[1] 2
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_sysparent.testSysParentPromises
 #{ u <- function() sys.parent() ; f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=u()) g(z) ; h() }
 [1] 1
 
@@ -46303,6 +46485,34 @@ NULL
 #argv <- list(2); .Internal(sys.parent(argv[[1]]))
 [1] 0
 
+##com.oracle.truffle.r.test.builtins.TestBuiltin_sysparents.testSysParents
+#{ f <- function() sys.parents() ; f() }
+[1] 0
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_sysparents.testSysParents
+#{ f <- function() sys.parents() ; g <- function() f() ; g() }
+[1] 0 1
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_sysparents.testSysParents
+#{ f <- function() sys.parents() ; g <- function() f() ; h <- function() g() ; h() }
+[1] 0 1 2
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_sysparents.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.builtins.TestBuiltin_sysparents.testSysParents
+#{ f <- function(x=sys.parents()) x ; g <- function() f() ; h <- function() g() ; h() }
+[1] 0 1 2
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_sysparents.testSysParents
+#{ sys.parents() }
+integer(0)
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_sysparents.testSysParents
+#{ u <- function() sys.parents() ; f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=u()) g(z) ; h() }
+[1] 0 1 2 1
+
 ##com.oracle.truffle.r.test.builtins.TestBuiltin_t.testTranspose
 #{ m <- double() ; dim(m) <- c(0,4) ; t(m) }
 
@@ -51840,138 +52050,6 @@ Error: object 'x' not found
 #{ x<-200; y<-100; rm("x", "y"); y }
 Error: object 'y' not found
 
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysCall
-#{ (function() sys.call())() }
-(function() sys.call())()
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysCall
-#{ f <- function() sys.call() ; f() }
-f()
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysCall
-#{ f <- function() sys.call() ; g <- function() f() ; h <- function() g() ; h() }
-f()
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysCall
-#{ f <- function() sys.call() ; typeof(f()[[1]]) }
-[1] "symbol"
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysCall
-#{ f <- function() sys.call(-1) ; g <- function() f() ; h <- function() g() ; h() }
-g()
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysCall
-#{ f <- function() sys.call(-2) ; g <- function() f() ; h <- function() g() ; h() }
-h()
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysCall
-#{ f <- function() sys.call(1) ; g <- function() f() ; g() }
-g()
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysCall
-#{ f <- function() sys.call(1) ; g <- function() f() ; h <- function() g() ; h() }
-h()
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysCall
-#{ f <- function() sys.call(2) ; g <- function() f() ; h <- function() g() ; h() }
-g()
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysCall
-#{ f <- function(x) sys.call() ; f(2) }
-f(2)
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysCall
-#{ f <- function(x) sys.call() ; f(x = 2) }
-f(x = 2)
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysCall
-#{ f <- function(x) sys.call() ; g <- function() 23 ; f(g()) }
-f(g())
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysCall
-#{ f <- function(x) sys.call() ; typeof(f(x = 2)[[1]]) }
-[1] "symbol"
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysCall
-#{ f <- function(x) sys.call() ; typeof(f(x = 2)[[2]]) }
-[1] "double"
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysCall
-#{ f <- function(x, y) sys.call() ; f(1, 2) }
-f(1, 2)
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysCall
-#{ f <- function(x, y) sys.call() ; f(1, y=2) }
-f(1, y = 2)
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysCall
-#{ f <- function(x, y) sys.call() ; f(x=1, 2) }
-f(x = 1, 2)
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysCall
-#{ f <- function(x, y) sys.call() ; f(y=1, 2) }
-f(y = 1, 2)
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysCall
-#{ f <- function(x, y) sys.call() ; f(y=1, x=2) }
-f(y = 1, x = 2)
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysNFrame
-#{ f <- function() sys.nframe() ; f() }
-[1] 1
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysNFrame
-#{ f <- function() sys.nframe() ; g <- function() f() ; g() }
-[1] 2
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysNFrame
-#{ f <- function() sys.nframe() ; g <- function() f() ; h <- function() g() ; h() }
-[1] 3
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.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.builtins.TestMiscBuiltins.testSysNFrame
-#{ f <- function(x=sys.nframe()) x ; g <- function() f() ; h <- function() g() ; h() }
-[1] 3
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysNFrame
-#{ sys.nframe() }
-[1] 0
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysNFrame
-#{ u <- function() sys.nframe() ; f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=u()) g(z) ; h() }
-[1] 4
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysParents
-#{ f <- function() sys.parents() ; f() }
-[1] 0
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysParents
-#{ f <- function() sys.parents() ; g <- function() f() ; g() }
-[1] 0 1
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysParents
-#{ f <- function() sys.parents() ; g <- function() f() ; h <- function() g() ; h() }
-[1] 0 1 2
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.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.builtins.TestMiscBuiltins.testSysParents
-#{ f <- function(x=sys.parents()) x ; g <- function() f() ; h <- function() g() ; h() }
-[1] 0 1 2
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysParents
-#{ sys.parents() }
-integer(0)
-
-##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testSysParents
-#{ u <- function() sys.parents() ; f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=u()) g(z) ; h() }
-[1] 0 1 2 1
-
 ##com.oracle.truffle.r.test.builtins.TestMiscBuiltins.testTable
 #{ a<-c("a", "b", "c");  t<-table(a, sample(a)); dimnames(t) }
 $a
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_parentframe.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_parentframe.java
index afd9099dc3..f3b0a6ced7 100644
--- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_parentframe.java
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_parentframe.java
@@ -29,10 +29,28 @@ import com.oracle.truffle.r.test.TestBase;
 public class TestBuiltin_parentframe extends TestBase {
 
     @Test
-    public void testParentFrame() {
+    public void testS3ParentFrame() {
         assertEval("a <- 0; f <- function(x) { a <- 1; UseMethod('f') }; f.default <- function(x) { a <- 2; (function(x) get('a', envir = parent.frame(x)))(x) }; f(1); f(2); f(3)");
         assertEval("a <- 0; f <- function(x) { a <- 1; UseMethod('f') }; f.default <- function(x) { a <- 2; get('a', envir = parent.frame()) }; f(1)");
         assertEval("a <- 0; f <- function(x) { a <- 1; UseMethod('f') }; f.foo <- function(x) { a <- 2; NextMethod(); };\n" +
                         "f.default <- function(x) { a <- 3; (function(x) get('a', envir = parent.frame(x)))(x) }; v <- 1; class(v) <- 'foo'; f(v); v <- 2; class(v) <- 'foo'; f(v)");
     }
+
+    @Test
+    public void testParentFrame() {
+        assertEval("parent.frame()");
+        assertEval("{ f <- function() parent.frame() }");
+        assertEval("{ f <- function() parent.frame() ; g <- function() { n <- 100; f() }; r <- g(); ls(r) }");
+        assertEval("{ f <- function() parent.frame(2); g <- function() f(); g() }");
+        assertEval("{ f <- function() parent.frame(3); g <- function() f(); g() }");
+        assertEval(Output.ContainsError, "parent.frame(0)");
+        assertEval(Output.ContainsError, "parent.frame(-1)");
+    }
+
+    @Test
+    public void testParentFramePromises() {
+        assertEval("{ f <- function(frame) frame; g <- function() f(parent.frame()); g() }");
+        assertEval("{ f <- function(frame) frame; g <- function() f(parent.frame(3)); g() }");
+    }
+
 }
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_syscall.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_syscall.java
new file mode 100644
index 0000000000..aae36aec98
--- /dev/null
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_syscall.java
@@ -0,0 +1,46 @@
+/*
+ * This material is distributed under the GNU General Public License
+ * Version 2. You may review the terms of this license at
+ * http://www.gnu.org/licenses/gpl-2.0.html
+ *
+ * Copyright (c) 2012-2014, Purdue University
+ * Copyright (c) 2013, 2016, Oracle and/or its affiliates
+ *
+ * All rights reserved.
+ */
+package com.oracle.truffle.r.test.builtins;
+
+import org.junit.Test;
+
+import com.oracle.truffle.r.test.TestBase;
+
+public class TestBuiltin_syscall extends TestBase {
+    @Test
+    public void testSysCall() {
+        assertEval("{ f <- function() sys.call() ; f() }");
+        assertEval("{ f <- function(x) sys.call() ; f(x = 2) }");
+        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() }");
+        assertEval("{ f <- function() sys.call(-1) ; g <- function() f() ; h <- function() g() ; h() }");
+        assertEval("{ f <- function() sys.call(-2) ; g <- function() f() ; h <- function() g() ; h() }");
+        assertEval("{ f <- function() sys.call() ; g <- function() f() ; h <- function() g() ; h() }");
+
+        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]]) }");
+
+        assertEval("{ f <- function(x) sys.call() ; f(2) }");
+        assertEval("{ f <- function(x) sys.call() ; g <- function() 23 ; f(g()) }");
+
+        assertEval("{ f <- function(x, y) sys.call() ; f(1, 2) }");
+        assertEval("{ f <- function(x, y) sys.call() ; f(x=1, 2) }");
+        assertEval("{ f <- function(x, y) sys.call() ; f(1, y=2) }");
+        assertEval("{ f <- function(x, y) sys.call() ; f(y=1, 2) }");
+        assertEval("{ f <- function(x, y) sys.call() ; f(y=1, x=2) }");
+
+        // fails because can't parse out the "name"
+        assertEval(Ignored.Unknown, "{ (function() sys.call())() }");
+    }
+
+}
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_syscalls.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_syscalls.java
new file mode 100644
index 0000000000..dafffb3df6
--- /dev/null
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_syscalls.java
@@ -0,0 +1,33 @@
+/*
+ * This material is distributed under the GNU General Public License
+ * Version 2. You may review the terms of this license at
+ * http://www.gnu.org/licenses/gpl-2.0.html
+ *
+ * Copyright (c) 2012-2014, Purdue University
+ * Copyright (c) 2013, 2016, Oracle and/or its affiliates
+ *
+ * All rights reserved.
+ */
+package com.oracle.truffle.r.test.builtins;
+
+import org.junit.Test;
+
+import com.oracle.truffle.r.test.TestBase;
+
+public class TestBuiltin_syscalls extends TestBase {
+
+    @Test
+    public void testSysCalls() {
+        assertEval("sys.calls()");
+        assertEval("{ f <- function(x) sys.calls(); g <- function() f(x); g() }");
+        // Avoid deparse issues in the output of the try code by comparing length
+        assertEval(Ignored.ImplementationError, "{ f <- function(x) sys.calls(); g <- function() f(x); length(try(g())) }");
+    }
+
+    @Test
+    public void testSysCallsPromises() {
+        assertEval("{ f <- function(x) x; g <- function() f(sys.calls()); g() }");
+        assertEval(Ignored.ImplementationError, "{ f <- function(x) x; g <- function() f(sys.calls()); length(try(g())) }");
+    }
+
+}
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sysnframe.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sysnframe.java
new file mode 100644
index 0000000000..7dd2be5aea
--- /dev/null
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sysnframe.java
@@ -0,0 +1,30 @@
+/*
+ * This material is distributed under the GNU General Public License
+ * Version 2. You may review the terms of this license at
+ * http://www.gnu.org/licenses/gpl-2.0.html
+ *
+ * Copyright (c) 2012-2014, Purdue University
+ * Copyright (c) 2013, 2016, Oracle and/or its affiliates
+ *
+ * All rights reserved.
+ */
+package com.oracle.truffle.r.test.builtins;
+
+import org.junit.Test;
+
+import com.oracle.truffle.r.test.TestBase;
+
+public class TestBuiltin_sysnframe extends TestBase {
+    @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() }");
+
+        assertEval(Ignored.Unknown, "{ u <- function() sys.nframe() ; f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=u()) g(z) ; h() }");
+    }
+
+}
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sysparent.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sysparent.java
index 0412bf949c..039eeda0b3 100644
--- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sysparent.java
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sysparent.java
@@ -28,8 +28,17 @@ public class TestBuiltin_sysparent extends TestBase {
         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); f(0) }");
+        assertEval("{ f <- function(x) sys.parent(x); f(4) }");
+        assertEval(Ignored.ImplementationError, "{ f <- function(x) sys.parent(x); f(-4) }");
+    }
+
+    @Test
+    public void testSysParentPromises() {
+        assertEval("{ f <- function(x) x; g <- function() f(sys.parent()); 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() }");
     }
+
 }
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sysparents.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sysparents.java
new file mode 100644
index 0000000000..973eca52b8
--- /dev/null
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sysparents.java
@@ -0,0 +1,30 @@
+/*
+ * This material is distributed under the GNU General Public License
+ * Version 2. You may review the terms of this license at
+ * http://www.gnu.org/licenses/gpl-2.0.html
+ *
+ * Copyright (c) 2012-2014, Purdue University
+ * Copyright (c) 2013, 2016, Oracle and/or its affiliates
+ *
+ * All rights reserved.
+ */
+package com.oracle.truffle.r.test.builtins;
+
+import org.junit.Test;
+
+import com.oracle.truffle.r.test.TestBase;
+
+public class TestBuiltin_sysparents extends TestBase {
+    @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() }");
+
+        assertEval(Ignored.Unknown, "{ u <- function() sys.parents() ; f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=u()) g(z) ; h() }");
+    }
+
+}
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 28e9612f44..e5805f5569 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
@@ -266,58 +266,6 @@ public class TestMiscBuiltins extends TestBase {
         assertEval("{ cl <- call(\"f\") ; class(cl) }");
     }
 
-    @Test
-    public void testSysCall() {
-        assertEval("{ f <- function() sys.call() ; f() }");
-        assertEval("{ f <- function(x) sys.call() ; f(x = 2) }");
-        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() }");
-        assertEval("{ f <- function() sys.call(-1) ; g <- function() f() ; h <- function() g() ; h() }");
-        assertEval("{ f <- function() sys.call(-2) ; g <- function() f() ; h <- function() g() ; h() }");
-        assertEval("{ f <- function() sys.call() ; g <- function() f() ; h <- function() g() ; h() }");
-
-        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]]) }");
-
-        assertEval("{ f <- function(x) sys.call() ; f(2) }");
-        assertEval("{ f <- function(x) sys.call() ; g <- function() 23 ; f(g()) }");
-
-        assertEval("{ f <- function(x, y) sys.call() ; f(1, 2) }");
-        assertEval("{ f <- function(x, y) sys.call() ; f(x=1, 2) }");
-        assertEval("{ f <- function(x, y) sys.call() ; f(1, y=2) }");
-        assertEval("{ f <- function(x, y) sys.call() ; f(y=1, 2) }");
-        assertEval("{ f <- function(x, y) sys.call() ; f(y=1, x=2) }");
-
-        // fails because can't parse out the "name"
-        assertEval(Ignored.Unknown, "{ (function() sys.call())() }");
-    }
-
-    @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() }");
-
-        assertEval(Ignored.Unknown, "{ 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() }");
-
-        assertEval(Ignored.Unknown, "{ u <- function() sys.nframe() ; f <- function(x) x ; g <- function(y) f(y) ; h <- function(z=u()) g(z) ; h() }");
-    }
-
     @Test
     public void testSimpleRm() {
         assertEval("{ x <- 200 ; rm(\"x\") ; x }");
diff --git a/mx.fastr/copyrights/overrides b/mx.fastr/copyrights/overrides
index 0e351563a7..ce287e13ef 100644
--- a/mx.fastr/copyrights/overrides
+++ b/mx.fastr/copyrights/overrides
@@ -626,6 +626,10 @@ com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_Sys
 com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_Sysglob.java,purdue.copyright
 com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sysonexit.java,purdue.copyright
 com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sysparent.java,purdue.copyright
+com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sysparents.java,purdue.copyright
+com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sysnframe.java,purdue.copyright
+com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_syscall.java,purdue.copyright
+com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_syscalls.java,purdue.copyright
 com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_Sysreadlink.java,purdue.copyright
 com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_Syssetenv.java,purdue.copyright
 com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_Syssetlocale.java,purdue.copyright
-- 
GitLab