about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-09-22T12·53+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-09-22T14·05+0200
commita54c263402cf140b6f91e26c02f13cbeeda76583 (patch)
tree0384a5937a2afac49b26639ac31089ca2f828312
parenteff120d1b93b99d6ae61b20e18c31a5324a2be4f (diff)
Add ‘seq’ primop
-rw-r--r--src/libexpr/primops.cc12
-rw-r--r--tests/lang/eval-fail-seq.nix1
-rw-r--r--tests/lang/eval-okay-seq.exp1
-rw-r--r--tests/lang/eval-okay-seq.nix1
4 files changed, 15 insertions, 0 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index c721a5681f3d..2da15b3c53eb 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -383,6 +383,15 @@ static void prim_getEnv(EvalState & state, const Pos & pos, Value * * args, Valu
 }
 
 
+/* Evaluate the first argument, then return the second argument. */
+void prim_seq(EvalState & state, const Pos & pos, Value * * args, Value & v)
+{
+    state.forceValue(*args[0]);
+    state.forceValue(*args[1]);
+    v = *args[1];
+}
+
+
 /* Evaluate the first expression and print it on standard error.  Then
    return the second expression.  Useful for debugging. */
 static void prim_trace(EvalState & state, const Pos & pos, Value * * args, Value & v)
@@ -1424,6 +1433,9 @@ void EvalState::createBaseEnv()
     addPrimOp("__tryEval", 1, prim_tryEval);
     addPrimOp("__getEnv", 1, prim_getEnv);
 
+    // Strictness
+    addPrimOp("__seq", 2, prim_seq);
+
     // Debugging
     addPrimOp("__trace", 2, prim_trace);
     addPrimOp("__gcCanary", 1, prim_gcCanary);
diff --git a/tests/lang/eval-fail-seq.nix b/tests/lang/eval-fail-seq.nix
new file mode 100644
index 000000000000..cddbbfd3261e
--- /dev/null
+++ b/tests/lang/eval-fail-seq.nix
@@ -0,0 +1 @@
+builtins.seq (abort "foo") 2
diff --git a/tests/lang/eval-okay-seq.exp b/tests/lang/eval-okay-seq.exp
new file mode 100644
index 000000000000..0cfbf08886fc
--- /dev/null
+++ b/tests/lang/eval-okay-seq.exp
@@ -0,0 +1 @@
+2
diff --git a/tests/lang/eval-okay-seq.nix b/tests/lang/eval-okay-seq.nix
new file mode 100644
index 000000000000..0a9a21c03b62
--- /dev/null
+++ b/tests/lang/eval-okay-seq.nix
@@ -0,0 +1 @@
+builtins.seq 1 2