diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2018-11-29 16:28:43 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-06-18 13:42:47 +0200 |
commit | 7083d33efee2b4782c52dc04d90f7c08e96b79d1 (patch) | |
tree | 9e00d1f6f7c39011bc4972376784aba542609256 /src/libexpr/eval.cc | |
parent | 25a1be9904b2e541346b26f03c3e73e8759241a5 (diff) |
Make constant primops lazy
(cherry picked from commit aa0e2a2e70a3519a9dcb9b1da000a13c01aa6cc1)
Diffstat (limited to 'src/libexpr/eval.cc')
-rw-r--r-- | src/libexpr/eval.cc | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 8e71db2b8..66f03fe1a 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -471,14 +471,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; |