diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-11-07T13·33+0100 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-11-12T11·32+0000 |
commit | 273322c7732093a354e86df82cf75d6604b8bce8 (patch) | |
tree | 15a9aa8822b969d677c2c790f4ae9c272552f275 /src/libexpr/eval.cc | |
parent | 4badd7ed17b4628d3a8d96e21c900aa91004daaf (diff) |
Make ifs and asserts tail-recursive
The local Value object prevented g++ from making a tail call. Not clear why. In any case, not using a temporary makes g++ do the tail call.
Diffstat (limited to 'src/libexpr/eval.cc')
-rw-r--r-- | src/libexpr/eval.cc | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 18b7ef701ff4..6dd3803d8c8c 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -480,9 +480,8 @@ void EvalState::eval(Expr * e, Value & v) } -inline bool EvalState::evalBool(Env & env, Expr * e) +inline bool EvalState::evalBool(Env & env, Expr * e, Value & v) { - Value v; e->eval(*this, env, v); if (v.type != tBool) throwTypeError("value is %1% while a Boolean was expected", v); @@ -490,6 +489,13 @@ inline bool EvalState::evalBool(Env & env, Expr * e) } +inline bool EvalState::evalBool(Env & env, Expr * e) +{ + Value v; + return evalBool(env, e, v); +} + + inline void EvalState::evalAttrs(Env & env, Expr * e, Value & v) { e->eval(*this, env, v); @@ -838,13 +844,13 @@ void ExprWith::eval(EvalState & state, Env & env, Value & v) void ExprIf::eval(EvalState & state, Env & env, Value & v) { - (state.evalBool(env, cond) ? then : else_)->eval(state, env, v); + (state.evalBool(env, cond, v) ? then : else_)->eval(state, env, v); } void ExprAssert::eval(EvalState & state, Env & env, Value & v) { - if (!state.evalBool(env, cond)) + if (!state.evalBool(env, cond, v)) throwAssertionError("assertion failed at %1%", pos); body->eval(state, env, v); } |