diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libcmd/repl.cc | 10 | ||||
-rw-r--r-- | src/libexpr/eval.cc | 70 | ||||
-rw-r--r-- | src/libexpr/eval.hh | 4 |
3 files changed, 62 insertions, 22 deletions
diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index 2e3a3b6df..5de4cdf76 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -511,7 +511,7 @@ bool NixRepl::processLine(string line) ++iter, ++idx) { if (idx == this->debugTraceIndex) { - printStaticEnvBindings(iter->expr); + printEnvBindings(iter->expr, iter->env); break; } } @@ -533,7 +533,7 @@ bool NixRepl::processLine(string line) { std::cout << "\n" << ANSI_BLUE << idx << ANSI_NORMAL << ": "; showDebugTrace(std::cout, *iter); - printStaticEnvBindings(iter->expr); + printEnvBindings(iter->expr, iter->env); loadDebugTraceEnv(*iter); break; } @@ -1010,14 +1010,14 @@ void runRepl( repl->initEnv(); // add 'extra' vars. - std::set<std::string> names; + // std::set<std::string> names; for (auto & [name, value] : extraEnv) { // names.insert(ANSI_BOLD + name + ANSI_NORMAL); - names.insert(name); + // names.insert(name); repl->addVarToScope(repl->state->symbols.create(name), *value); } - printError(hintfmt("The following extra variables are in scope: %s\n", concatStringsSep(", ", names)).str()); + // printError(hintfmt("The following extra variables are in scope: %s\n", concatStringsSep(", ", names)).str()); repl->mainLoop({}); } diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index cc0380d4a..7c67f2ea8 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -699,22 +699,46 @@ std::optional<EvalState::Doc> EvalState::getDoc(Value & v) return {}; } -void printStaticEnvBindings(const StaticEnv &se, int lvl) + +// just for the current level of StaticEnv, not the whole chain. +void printStaticEnvBindings(const StaticEnv &se) { - std::cout << "Env level " << lvl << std::endl; + std::cout << ANSI_MAGENTA; + for (auto i = se.vars.begin(); i != se.vars.end(); ++i) + { + std::cout << i->first << " "; + } + std::cout << ANSI_NORMAL; + std::cout << std::endl; +} - if (se.up) { +// just for the current level of Env, not the whole chain. +void printWithBindings(const Env &env) +{ + if (env.type == Env::HasWithAttrs) + { + std::cout << "with: "; std::cout << ANSI_MAGENTA; - for (auto i = se.vars.begin(); i != se.vars.end(); ++i) - { - std::cout << i->first << " "; + Bindings::iterator j = env.values[0]->attrs->begin(); + while (j != env.values[0]->attrs->end()) { + std::cout << j->name << " "; + ++j; } std::cout << ANSI_NORMAL; - - std::cout << std::endl; std::cout << std::endl; + } +} + +void printEnvBindings(const StaticEnv &se, const Env &env, int lvl) +{ + std::cout << "Env level " << lvl << std::endl; - printStaticEnvBindings(*se.up, ++lvl); + if (se.up && env.up) { + std::cout << "static: "; + printStaticEnvBindings(se); + printWithBindings(env); + std::cout << std::endl; + printEnvBindings(*se.up, *env.up, ++lvl); } else { @@ -727,18 +751,19 @@ void printStaticEnvBindings(const StaticEnv &se, int lvl) } std::cout << ANSI_NORMAL; std::cout << std::endl; + printWithBindings(env); // probably nothing there for the top level. std::cout << std::endl; } - } -void printStaticEnvBindings(const Expr &expr) +// TODO: add accompanying env for With stuff. +void printEnvBindings(const Expr &expr, const Env &env) { // just print the names for now if (expr.staticenv) { - printStaticEnvBindings(*expr.staticenv.get(), 0); + printEnvBindings(*expr.staticenv.get(), env, 0); } } @@ -750,11 +775,26 @@ void mapStaticEnvBindings(const StaticEnv &se, const Env &env, valmap & vm) if (env.up && se.up) { mapStaticEnvBindings(*se.up, *env.up,vm); - // iterate through staticenv bindings and add them. auto map = valmap(); - for (auto iter = se.vars.begin(); iter != se.vars.end(); ++iter) + if (env.type == Env::HasWithAttrs) + { + std::cout << "(env.type == Env::HasWithAttrs)" << std::endl; + Bindings::iterator j = env.values[0]->attrs->begin(); + while (j != env.values[0]->attrs->end()) { + // std::cout << "adding : " << j->name << std::endl; + map[j->name] = j->value; + // if (countCalls) attrSelects[*j->pos]++; + // return j->value; + ++j; + } + } + else { - map[iter->first] = env.values[iter->second]; + // iterate through staticenv bindings and add them. + for (auto iter = se.vars.begin(); iter != se.vars.end(); ++iter) + { + map[iter->first] = env.values[iter->second]; + } } vm.merge(map); diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 9de3475e8..1c569fc36 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -25,8 +25,8 @@ enum RepairFlag : bool; typedef void (* PrimOpFun) (EvalState & state, const Pos & pos, Value * * args, Value & v); -void printStaticEnvBindings(const Expr &expr); -void printStaticEnvBindings(const StaticEnv &se, int lvl = 0); +void printEnvBindings(const Expr &expr, const Env &env); +void printEnvBindings(const StaticEnv &se, const Env &env, int lvl = 0); struct PrimOp { |