diff options
author | eldritch horrors <pennae@lix.systems> | 2024-03-18 20:03:31 +0100 |
---|---|---|
committer | eldritch horrors <pennae@lix.systems> | 2024-03-18 20:03:31 +0100 |
commit | b3599166ad98c3cad304183bd7cc7bc280522e71 (patch) | |
tree | 2b677f261d77a430358f95f630080f62ced37db4 /src/libexpr/eval.cc | |
parent | 47a237f7ec594c409a7abbbfe0ff0170a9970183 (diff) |
libexpr: sort binding name in debugger
not doing this exposes the binding name order to the annoying
interference of parse order on symbol order, which wouldn't be so bad if
it didn't make the tests less reliable and, importantly, dependent on
linker behavior (due to primop initialization being done in static
initializer, and the order of static initializers being defined only
within a single translation unit).
fixes #143
Change-Id: I3cf417893fbcf19e9ad3ff8986deb7cbcf3ca511
Diffstat (limited to 'src/libexpr/eval.cc')
-rw-r--r-- | src/libexpr/eval.cc | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 7cf33aec4..bef0effb6 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -677,12 +677,21 @@ std::optional<EvalState::Doc> EvalState::getDoc(Value & v) } +static std::set<std::string_view> sortedBindingNames(const SymbolTable & st, const StaticEnv & se) +{ + std::set<std::string_view> bindings; + for (auto [symbol, displ] : se.vars) + bindings.emplace(st[symbol]); + return bindings; +} + + // just for the current level of StaticEnv, not the whole chain. void printStaticEnvBindings(const SymbolTable & st, const StaticEnv & se) { std::cout << ANSI_MAGENTA; - for (auto & i : se.vars) - std::cout << st[i.first] << " "; + for (auto & i : sortedBindingNames(st, se)) + std::cout << i << " "; std::cout << ANSI_NORMAL; std::cout << std::endl; } @@ -691,13 +700,14 @@ void printStaticEnvBindings(const SymbolTable & st, const StaticEnv & se) void printWithBindings(const SymbolTable & st, const Env & env) { if (!env.values[0]->isThunk()) { + std::set<std::string_view> bindings; + for (const auto & attr : *env.values[0]->attrs) + bindings.emplace(st[attr.name]); + std::cout << "with: "; std::cout << ANSI_MAGENTA; - Bindings::iterator j = env.values[0]->attrs->begin(); - while (j != env.values[0]->attrs->end()) { - std::cout << st[j->name] << " "; - ++j; - } + for (auto & i : bindings) + std::cout << i << " "; std::cout << ANSI_NORMAL; std::cout << std::endl; } @@ -718,9 +728,9 @@ void printEnvBindings(const SymbolTable & st, const StaticEnv & se, const Env & std::cout << ANSI_MAGENTA; // for the top level, don't print the double underscore ones; // they are in builtins. - for (auto & i : se.vars) - if (!std::string_view(st[i.first]).starts_with("__")) - std::cout << st[i.first] << " "; + for (auto & i : sortedBindingNames(st, se)) + if (!i.starts_with("__")) + std::cout << i << " "; std::cout << ANSI_NORMAL; std::cout << std::endl; if (se.isWith) |