diff options
author | Guillaume Maudoux <guillaume.maudoux@tweag.io> | 2022-03-05 21:18:30 +0100 |
---|---|---|
committer | Guillaume Maudoux <guillaume.maudoux@tweag.io> | 2022-03-05 21:18:30 +0100 |
commit | 407801592719d77fcdad53b447e909e3ab255086 (patch) | |
tree | 7920b2fc6f8a34b533e7db6a54539163f590bec0 | |
parent | cbbbf368818f147f9ce4562b497536a9e46fd657 (diff) |
DRY addPrimOp
-rw-r--r-- | src/libexpr/eval.cc | 20 |
1 files changed, 1 insertions, 19 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 168b3582a..d3ab5ad08 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -636,25 +636,7 @@ void EvalState::addConstant(const std::string & name, Value * v) Value * EvalState::addPrimOp(const std::string & name, size_t arity, PrimOpFun primOp) { - auto name2 = name.substr(0, 2) == "__" ? name.substr(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->mkPrimOp(new PrimOp { .fun = primOp, .arity = 1, .name = sym }); - Value v; - v.mkApp(vPrimOp, vPrimOp); - return addConstant(name, v); - } - - Value * v = allocValue(); - v->mkPrimOp(new PrimOp { .fun = primOp, .arity = arity, .name = sym }); - staticBaseEnv.vars.emplace_back(symbols.create(name), baseEnvDispl); - baseEnv.values[baseEnvDispl++] = v; - baseEnv.values[0]->attrs->push_back(Attr(sym, v)); - return v; + return addPrimOp(PrimOp { .fun = primOp, .arity = arity, .name = symbols.create(name) }); } |