aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2018-11-29 16:28:43 +0100
committerEelco Dolstra <edolstra@gmail.com>2019-02-11 11:52:07 +0100
commitaa0e2a2e70a3519a9dcb9b1da000a13c01aa6cc1 (patch)
tree7974ba7f87caac0747691d9ef61bda8e5bae668b
parent01d07b1e92c298f729a73705907b2987da9a4d0c (diff)
Make constant primops lazy
-rw-r--r--src/libexpr/eval.cc13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 2a194d0e0..3891e8666 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -439,14 +439,21 @@ Value * EvalState::addConstant(const string & name, Value & v)
Value * EvalState::addPrimOp(const string & name,
size_t arity, PrimOpFun primOp)
{
+ auto name2 = string(name, 0, 2) == "__" ? string(name, 2) : name;
+ Symbol sym = symbols.create(name2);
+
+ /* Hack to make constants lazy: turn them into a application of
+ the primop to a dummy value. */
if (arity == 0) {
+ auto vPrimOp = allocValue();
+ vPrimOp->type = tPrimOp;
+ vPrimOp->primOp = new PrimOp(primOp, 1, sym);
Value v;
- primOp(*this, noPos, nullptr, v);
+ mkApp(v, *vPrimOp, *vPrimOp);
return addConstant(name, v);
}
+
Value * v = allocValue();
- string name2 = string(name, 0, 2) == "__" ? string(name, 2) : name;
- Symbol sym = symbols.create(name2);
v->type = tPrimOp;
v->primOp = new PrimOp(primOp, arity, sym);
staticBaseEnv.vars[symbols.create(name)] = baseEnvDispl;