Skip to content

Commit c39cc00

Browse files
committed
libexpr: Factor out Payload union to a default implementation of ValueStorage
This factors out most of the value representation into a mixin class. `finishValue` is now gone for good and replaced with a simple template function `setStorage` which derives the type information/disriminator from the type of the argument. Likewise, reading of the value goes through function template `getStorage`. An empty type `Null` is introduced to make the bijection InternalType <-> C++ type complete.
1 parent 810455f commit c39cc00

File tree

3 files changed

+252
-158
lines changed

3 files changed

+252
-158
lines changed

src/libexpr/eval.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ void EvalState::addConstant(const std::string & name, Value * v, Constant info)
502502
/* Install value the base environment. */
503503
staticBaseEnv->vars.emplace_back(symbols.create(name), baseEnvDispl);
504504
baseEnv.values[baseEnvDispl++] = v;
505-
getBuiltins().payload.attrs->push_back(Attr(symbols.create(name2), v));
505+
const_cast<Bindings *>(getBuiltins().attrs())->push_back(Attr(symbols.create(name2), v));
506506
}
507507
}
508508

@@ -540,7 +540,7 @@ const PrimOp * Value::primOpAppPrimOp() const
540540
void Value::mkPrimOp(PrimOp * p)
541541
{
542542
p->check();
543-
finishValue(tPrimOp, { .primOp = p });
543+
setStorage(p);
544544
}
545545

546546

@@ -572,7 +572,7 @@ Value * EvalState::addPrimOp(PrimOp && primOp)
572572
else {
573573
staticBaseEnv->vars.emplace_back(envName, baseEnvDispl);
574574
baseEnv.values[baseEnvDispl++] = v;
575-
getBuiltins().payload.attrs->push_back(Attr(symbols.create(primOp.name), v));
575+
const_cast<Bindings *>(getBuiltins().attrs())->push_back(Attr(symbols.create(primOp.name), v));
576576
}
577577

578578
return v;

0 commit comments

Comments
 (0)