about summary refs log tree commit diff
path: root/src/libexpr/eval-test.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2010-03-25T12·51+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2010-03-25T12·51+0000
commitf450384ded92cb68cf4b60b5bd9be64556aff339 (patch)
treea25f12194e72587396014c33ed602d47259e357e /src/libexpr/eval-test.cc
parentef8bd919fc8e895df402502ffb1727bad0db07b2 (diff)
* Implement blackholing.
Diffstat (limited to 'src/libexpr/eval-test.cc')
-rw-r--r--src/libexpr/eval-test.cc17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/libexpr/eval-test.cc b/src/libexpr/eval-test.cc
index 432d7887487e..5b85065af0dc 100644
--- a/src/libexpr/eval-test.cc
+++ b/src/libexpr/eval-test.cc
@@ -27,7 +27,8 @@ typedef enum {
     tAttrs,
     tThunk,
     tLambda,
-    tCopy
+    tCopy,
+    tBlackhole
 } ValueType;
 
 
@@ -82,11 +83,16 @@ static void eval(Env * env, Expr e, Value & v);
 
 void forceValue(Value & v)
 {
-    if (v.type == tThunk) eval(v.thunk.env, v.thunk.expr, v);
+    if (v.type == tThunk) {
+        v.type = tBlackhole;
+        eval(v.thunk.env, v.thunk.expr, v);
+    }
     else if (v.type == tCopy) {
         forceValue(*v.val);
         v = *v.val;
     }
+    else if (v.type == tBlackhole)
+        throw EvalError("infinite recursion encountered");
 }
 
 
@@ -240,7 +246,6 @@ static void eval(Env * env, Expr e, Value & v)
                     v.type = tCopy;
                     v.val = &j->second;
                 }
-            
             }
 
             /* Check that each actual argument is listed as a formal
@@ -290,12 +295,8 @@ void run(Strings args)
     doTest("({x ? 1, y ? x}: y) { x = 2; }");
     doTest("({x, y, ...}: x) { x = 1; y = 2; z = 3; }");
     doTest("({x, y, ...}@args: args.z) { x = 1; y = 2; z = 3; }");
+    //doTest("({x ? y, y ? x}: y) { }");
     
-    //Expr e = parseExprFromString(state, "let x = \"a\"; in x + \"b\"", "/");
-    //Expr e = parseExprFromString(state, "(x: x + \"b\") \"a\"", "/");
-    //Expr e = parseExprFromString(state, "\"a\" + \"b\"", "/");
-    //Expr e = parseExprFromString(state, "\"a\" + \"b\"", "/");
-
     printMsg(lvlError, format("alloced %1% values") % nrValues);
     printMsg(lvlError, format("alloced %1% environments") % nrEnvs);
 }