diff options
author | Ben Burdette <bburdette@gmail.com> | 2021-08-17 14:39:50 -0600 |
---|---|---|
committer | Ben Burdette <bburdette@gmail.com> | 2021-08-17 14:39:50 -0600 |
commit | b6eb38016b9d16cf206f3f2b0cd4bce4dea40345 (patch) | |
tree | 3df3fa0cfe9cbe4d9e458a842f05977181f4c908 | |
parent | 030271184fecbbe9dd871b71d92c61e163254646 (diff) |
moving towards env in exceptions
-rw-r--r-- | src/libcmd/command.cc | 2 | ||||
-rw-r--r-- | src/libexpr/eval.cc | 43 |
2 files changed, 29 insertions, 16 deletions
diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 86b6f37f8..59ab1f874 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -105,7 +105,7 @@ ref<EvalState> EvalCommand::getEvalState() if (!evalState) { evalState = std::make_shared<EvalState>(searchPath, getStore()); if (startReplOnEvalErrors) - debuggerHook = [evalState{ref<EvalState>(evalState)}](const Error & error, const std::map<std::string, Value *> & env) { + debuggerHook = [evalState{ref<EvalState>(evalState)}](const Error & error, const Env & env) { printError("%s\n\n" ANSI_BOLD "Starting REPL to allow you to inspect the current state of the evaluator.\n" ANSI_NORMAL, error.what()); runRepl(evalState, env); }; diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 464022372..f799ee7db 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -1172,11 +1172,6 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v) env2.up = &env; dynamicEnv = &env2; - // TODO; deal with the below overrides or whatever - if (debuggerHook) { - env2.valuemap = mapBindings(attrs); - } - AttrDefs::iterator overrides = attrs.find(state.sOverrides); bool hasOverrides = overrides != attrs.end(); @@ -1195,6 +1190,11 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v) v.attrs->push_back(Attr(i.first, vAttr, &i.second.pos)); } + // TODO; deal with the below overrides or whatever + if (debuggerHook) { + env2.valuemap.reset(mapBindings(*v.attrs)); + } + /* If the rec contains an attribute called `__overrides', then evaluate it, and add the attributes in that set to the rec. This allows overriding of recursive attributes, which is @@ -1258,9 +1258,6 @@ void ExprLet::eval(EvalState & state, Env & env, Value & v) Env & env2(state.allocEnv(attrs->attrs.size())); env2.up = &env; - if (debuggerHook) { - env2.valuemap = mapBindings(attrs); - } /* The recursive attributes are evaluated in the new environment, while the inherited attributes are evaluated in the original environment. */ @@ -1268,6 +1265,18 @@ void ExprLet::eval(EvalState & state, Env & env, Value & v) for (auto & i : attrs->attrs) env2.values[displ++] = i.second.e->maybeThunk(state, i.second.inherited ? env : env2); + if (debuggerHook) { + auto map = new valmap(); + + displ = 0; + for (auto & i : attrs->attrs) + { + // std::string s = i->name; + (*map)[i.first] = env2.values[displ++]; + } + env2.valuemap.reset(map); + } + body->eval(state, env2, v); } @@ -1460,6 +1469,7 @@ void EvalState::callFunction(Value & fun, Value & arg, Value & v, const Pos & po pos, "attempt to call something which is not a function but %1%", showType(fun).c_str(), + // fun.env); map2("fun", &fun, "arg", &arg)); } @@ -1498,7 +1508,8 @@ void EvalState::callFunction(Value & fun, Value & arg, Value & v, const Pos & po "%1% called without required argument '%2%'", lambda, i.name, - map2("fun", &fun, "arg", &arg)); + fun.lambda.env); + // map2("fun", &fun, "arg", &arg)); env2.values[displ++] = i.def->maybeThunk(*this, env2); } else { attrsUsed++; @@ -1519,18 +1530,19 @@ void EvalState::callFunction(Value & fun, Value & arg, Value & v, const Pos & po "%1% called without required argument '%2%'", lambda, i.name, - map2("fun", &fun, "arg", &arg)); + fun.env); + // map2("fun", &fun, "arg", &arg)); env2.values[displ++] = i.def->maybeThunk(*this, env2); } else { attrsUsed++; env2.values[displ++] = j->value; // add to debugger name-value map - std::string s = i->name; - (*map)[s] = i->value; + std::string s = i.name; + (*map)[s] = i.value; } } - env2.valuemap = map; + env2.valuemap.reset(map); } /* Check that each actual argument is listed as a formal @@ -1544,7 +1556,8 @@ void EvalState::callFunction(Value & fun, Value & arg, Value & v, const Pos & po "%1% called with unexpected argument '%2%'", lambda, i.name, - map2("fun", &fun, "arg", &arg)); + fun.env); + // map2("fun", &fun, "arg", &arg)); abort(); // can't happen } } @@ -1621,7 +1634,7 @@ this case it must have its arguments supplied either by default values, or passed explicitly with '--arg' or '--argstr'. See https://nixos.org/manual/nix/stable/#ss-functions.)", i.name, - fun.lambda.env); + *fun.lambda.env); // mapBindings(args)); // map1("fun", &fun)); // todo add bindings + fun } |