about summary refs log tree commit diff
path: root/src/libexpr/primops.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2010-05-12T11·23+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2010-05-12T11·23+0000
commit81a4b4e49bf82f17eef20d78c4f505874cf5532e (patch)
treee5fa0c53c248cc341b964332911f4a44be4a0127 /src/libexpr/primops.cc
parent1a8eb6e3ec9329ee7b61ac2345c6e1d994905813 (diff)
* Implemented tryEval, the last missing primop in the fast-eval
  branch.  Also added a test for tryEval.

Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r--src/libexpr/primops.cc18
1 files changed, 6 insertions, 12 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index a7e7bcdc8615..9d36fb6a05d7 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -202,24 +202,20 @@ static void prim_addErrorContext(EvalState & state, Value * * args, Value & v)
 }
 
 
-#if 0
 /* Try evaluating the argument. Success => {success=true; value=something;}, 
  * else => {success=false; value=false;} */
 static void prim_tryEval(EvalState & state, Value * * args, Value & v)
 {
-    ATermMap res = ATermMap();
+    state.mkAttrs(v);
     try {
-        Expr val = evalExpr(state, args[0]);
-        res.set(toATerm("value"), makeAttrRHS(val, makeNoPos()));
-        res.set(toATerm("success"), makeAttrRHS(eTrue, makeNoPos()));
+        state.forceValue(*args[0]);
+        (*v.attrs)[state.symbols.create("value")].value = *args[0];
+        mkBool((*v.attrs)[state.symbols.create("success")].value, true);
     } catch (AssertionError & e) {
-        printMsg(lvlDebug, format("tryEval caught an error: %1%: %2%") % e.prefix() % e.msg());
-        res.set(toATerm("value"), makeAttrRHS(eFalse, makeNoPos()));
-        res.set(toATerm("success"), makeAttrRHS(eFalse, makeNoPos()));
+        mkBool((*v.attrs)[state.symbols.create("value")].value, false);
+        mkBool((*v.attrs)[state.symbols.create("success")].value, false);
     }
-    return makeAttrs(res);
 }
-#endif
 
 
 /* Return an environment variable.  Use with care. */
@@ -1062,9 +1058,7 @@ void EvalState::createBaseEnv()
     addPrimOp("abort", 1, prim_abort);
     addPrimOp("throw", 1, prim_throw);
     addPrimOp("__addErrorContext", 2, prim_addErrorContext);
-#if 0
     addPrimOp("__tryEval", 1, prim_tryEval);
-#endif
     addPrimOp("__getEnv", 1, prim_getEnv);
     addPrimOp("__trace", 2, prim_trace);