aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Burdette <bburdette@gmail.com>2021-10-11 16:32:43 -0600
committerBen Burdette <bburdette@gmail.com>2021-10-11 16:32:43 -0600
commit98eb13691a16d9472b822a92f32b439a6ee6e288 (patch)
tree967e4f64933f1bba8b594b86ae631a5ef49a1f54
parent2ee1fa4afd69226f16305e792d5110fd36669c6b (diff)
print staticenv bindings
-rw-r--r--src/libcmd/command.cc12
-rw-r--r--src/libexpr/eval.cc28
-rw-r--r--src/libexpr/eval.hh2
3 files changed, 39 insertions, 3 deletions
diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc
index 705b30d53..d8e79953c 100644
--- a/src/libcmd/command.cc
+++ b/src/libcmd/command.cc
@@ -107,10 +107,16 @@ ref<EvalState> EvalCommand::getEvalState()
if (startReplOnEvalErrors)
debuggerHook = [evalState{ref<EvalState>(evalState)}](const Error & error, const Env & env, const Expr & expr) {
printError("%s\n\n" ANSI_BOLD "Starting REPL to allow you to inspect the current state of the evaluator.\n" ANSI_NORMAL, error.what());
+
+ printStaticEnvBindings(expr);
+
// printEnvPosChain(env);
- printEnvBindings(env);
- auto vm = mapEnvBindings(env);
- runRepl(evalState, *vm);
+ // printEnvBindings(env);
+ if (expr.staticenv)
+ {
+ auto vm = mapStaticEnvBindings(*expr.staticenv.get(), env);
+ runRepl(evalState, *vm);
+ }
};
}
return ref<EvalState>(evalState);
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 76c038593..fba5f5031 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -712,6 +712,34 @@ void printStaticEnvBindings(const Expr &expr)
}
+void mapStaticEnvBindings(const StaticEnv &se, const Env &env, valmap & vm)
+{
+ // add bindings for the next level up first.
+ if (env.up && se.up) {
+ mapStaticEnvBindings( *se.up, *env.up,vm);
+ }
+
+ // iterate through staticenv bindings.
+
+ auto map = valmap();
+ for (auto iter = se.vars.begin(); iter != se.vars.end(); ++iter)
+ {
+ map[iter->first] = env.values[iter->second];
+ }
+
+ vm.merge(map);
+
+}
+
+
+valmap * mapStaticEnvBindings(const StaticEnv &se, const Env &env)
+{
+ auto vm = new valmap();
+ mapStaticEnvBindings(se, env, *vm);
+ return vm;
+}
+
+
void printEnvPosChain(const Env &env, int lv )
{
std::cout << "printEnvPosChain " << lv << std::endl;
diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh
index 553e7861a..29599cc6c 100644
--- a/src/libexpr/eval.hh
+++ b/src/libexpr/eval.hh
@@ -24,6 +24,7 @@ enum RepairFlag : bool;
typedef void (* PrimOpFun) (EvalState & state, const Pos & pos, Value * * args, Value & v);
extern std::function<void(const Error & error, const Env & env, const Expr & expr)> debuggerHook;
+void printStaticEnvBindings(const Expr &expr);
struct PrimOp
{
@@ -47,6 +48,7 @@ struct Env
void printEnvBindings(const Env &env, int lv = 0);
valmap * mapEnvBindings(const Env &env);
void printEnvPosChain(const Env &env, int lv = 0);
+valmap * mapStaticEnvBindings(const StaticEnv &se, const Env &env);
Value & mkString(Value & v, std::string_view s, const PathSet & context = PathSet());