refactor: Use EvalState::getBuiltins()

This commit is contained in:
Robert Hensing 2024-11-19 18:32:09 +01:00
parent 8a36d2d8a7
commit 5c258d7e25
3 changed files with 6 additions and 5 deletions

View File

@ -448,7 +448,7 @@ void EvalState::addConstant(const std::string & name, Value * v, Constant info)
/* Install value the base environment. */
staticBaseEnv->vars.emplace_back(symbols.create(name), baseEnvDispl);
baseEnv.values[baseEnvDispl++] = v;
baseEnv.values[0]->payload.attrs->push_back(Attr(symbols.create(name2), v));
getBuiltins().payload.attrs->push_back(Attr(symbols.create(name2), v));
}
}
@ -516,7 +516,7 @@ Value * EvalState::addPrimOp(PrimOp && primOp)
else {
staticBaseEnv->vars.emplace_back(envName, baseEnvDispl);
baseEnv.values[baseEnvDispl++] = v;
baseEnv.values[0]->payload.attrs->push_back(Attr(symbols.create(primOp.name), v));
getBuiltins().payload.attrs->push_back(Attr(symbols.create(primOp.name), v));
}
return v;
@ -531,7 +531,7 @@ Value & EvalState::getBuiltins()
Value & EvalState::getBuiltin(const std::string & name)
{
auto it = baseEnv.values[0]->attrs()->get(symbols.create(name));
auto it = getBuiltins().attrs()->get(symbols.create(name));
if (it)
return *it->value;
else

View File

@ -4937,7 +4937,7 @@ void EvalState::createBaseEnv()
/* Now that we've added all primops, sort the `builtins' set,
because attribute lookups expect it to be sorted. */
baseEnv.values[0]->payload.attrs->sort();
getBuiltins().payload.attrs->sort();
staticBaseEnv->sort();

View File

@ -435,7 +435,8 @@ void mainWrapped(int argc, char * * argv)
evalSettings.pureEval = false;
EvalState state({}, openStore("dummy://"), fetchSettings, evalSettings);
auto builtinsJson = nlohmann::json::object();
for (auto & builtin : *state.baseEnv.values[0]->attrs()) {
for (auto & builtinPtr : state.getBuiltins().attrs()->lexicographicOrder(state.symbols)) {
auto & builtin = *builtinPtr;
auto b = nlohmann::json::object();
if (!builtin.value->isPrimOp()) continue;
auto primOp = builtin.value->primOp();