diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2010-05-12 11:23:44 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2010-05-12 11:23:44 +0000 |
commit | 81a4b4e49bf82f17eef20d78c4f505874cf5532e (patch) | |
tree | e5fa0c53c248cc341b964332911f4a44be4a0127 /src/libexpr | |
parent | 1a8eb6e3ec9329ee7b61ac2345c6e1d994905813 (diff) |
* Implemented tryEval, the last missing primop in the fast-eval
branch. Also added a test for tryEval.
Diffstat (limited to 'src/libexpr')
-rw-r--r-- | src/libexpr/primops.cc | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index a7e7bcdc8..9d36fb6a0 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); |