Merge pull request #57 from jsoo1/refactor-top-level-value-finding

Refactor top-level value finding.
This commit is contained in:
adisbladis 2022-04-22 13:29:26 +07:00 committed by GitHub
commit 55d91140be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -116,16 +116,19 @@ struct MyArgs : MixEvalArgs, MixCommonArgs
static MyArgs myArgs;
static void worker(
EvalState & state,
Bindings & autoArgs,
AutoCloseFD & to,
AutoCloseFD & from,
const Path &gcRootsDir)
{
static Value* releaseExprTopLevelValue(EvalState & state, Bindings & autoArgs) {
Value vTop;
if (myArgs.flake) {
state.evalFile(lookupFileArg(state, myArgs.releaseExpr), vTop);
auto vRoot = state.allocValue();
state.autoCallFunction(autoArgs, vTop, *vRoot);
return vRoot;
}
static Value* flakeTopLevelValue(EvalState & state, Bindings & autoArgs) {
using namespace flake;
auto [flakeRef, fragment] = parseFlakeRefWithFragment(myArgs.releaseExpr, absPath("."));
@ -143,7 +146,7 @@ static void worker(
auto vOutputs = vFlake->attrs->get(state.symbols.create("outputs"))->value;
state.forceValue(*vOutputs, noPos);
vTop = *vOutputs;
auto vTop = *vOutputs;
if (fragment.length() > 0) {
Bindings & bindings(*state.allocBindings(0));
@ -153,13 +156,27 @@ static void worker(
vTop = *nTop;
}
} else {
state.evalFile(lookupFileArg(state, myArgs.releaseExpr), vTop);
}
auto vRoot = state.allocValue();
state.autoCallFunction(autoArgs, vTop, *vRoot);
return vRoot;
}
Value * topLevelValue(EvalState & state, Bindings & autoArgs) {
return myArgs.flake
? flakeTopLevelValue(state, autoArgs)
: releaseExprTopLevelValue(state, autoArgs);
}
static void worker(
EvalState & state,
Bindings & autoArgs,
AutoCloseFD & to,
AutoCloseFD & from,
const Path &gcRootsDir)
{
auto vRoot = topLevelValue(state, autoArgs);
while (true) {
/* Wait for the master to send us a job name. */
writeLine(to.get(), "next");