From aad27143c67c863bd4886186bdf68f4796ca26c3 Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Sat, 2 Oct 2021 13:47:36 -0600 Subject: [PATCH] storing staticenv bindings --- src/libexpr/eval.cc | 23 +++++++++++++++++++++ src/libexpr/nixexpr.cc | 47 ++++++++++++++++++++++++++++++++++++++++++ src/libexpr/nixexpr.hh | 2 +- 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 53a5c5bd2..c2b6e7ea8 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -689,6 +689,29 @@ void printEnvBindings(const Env &env, int lv ) } } +void printStaticEnvBindings(const StaticEnv &se, int lvl) +{ + for (auto i = se.vars.begin(); i != se.vars.end(); ++i) + { + std::cout << lvl << i->first << std::endl; + } + + if (se.up) { + printStaticEnvBindings(*se.up, ++lvl); + } + +} + +void printStaticEnvBindings(const Expr &expr) +{ + // just print the names for now + if (expr.staticenv) + { + printStaticEnvBindings(*expr.staticenv.get(), 0); + } + +} + void printEnvPosChain(const Env &env, int lv ) { std::cout << "printEnvPosChain " << lv << std::endl; diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 6ca0de72b..85b1d5e12 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -244,22 +244,33 @@ void Expr::bindVars(const std::shared_ptr &env) void ExprInt::bindVars(const std::shared_ptr &env) { + if (debuggerHook) + staticenv = env; } void ExprFloat::bindVars(const std::shared_ptr &env) { + if (debuggerHook) + staticenv = env; } void ExprString::bindVars(const std::shared_ptr &env) { + if (debuggerHook) + staticenv = env; } void ExprPath::bindVars(const std::shared_ptr &env) { + if (debuggerHook) + staticenv = env; } void ExprVar::bindVars(const std::shared_ptr &env) { + if (debuggerHook) + staticenv = env; + /* Check whether the variable appears in the environment. If so, set its level and displacement. */ @@ -312,6 +323,9 @@ void ExprVar::bindVars(const std::shared_ptr &env) void ExprSelect::bindVars(const std::shared_ptr &env) { + if (debuggerHook) + staticenv = env; + e->bindVars(env); if (def) def->bindVars(env); for (auto & i : attrPath) @@ -321,6 +335,9 @@ void ExprSelect::bindVars(const std::shared_ptr &env) void ExprOpHasAttr::bindVars(const std::shared_ptr &env) { + if (debuggerHook) + staticenv = env; + e->bindVars(env); for (auto & i : attrPath) if (!i.symbol.set()) @@ -329,6 +346,9 @@ void ExprOpHasAttr::bindVars(const std::shared_ptr &env) void ExprAttrs::bindVars(const std::shared_ptr &env) { + if (debuggerHook) + staticenv = env; + std::cout << "ExprAttrs::bindVars" << std::endl; // auto dynamicEnv(env); @@ -369,12 +389,18 @@ void ExprAttrs::bindVars(const std::shared_ptr &env) void ExprList::bindVars(const std::shared_ptr &env) { + if (debuggerHook) + staticenv = env; + for (auto & i : elems) i->bindVars(env); } void ExprLambda::bindVars(const std::shared_ptr &env) { + if (debuggerHook) + staticenv = env; + auto newEnv = std::shared_ptr(new StaticEnv(false, env.get())); // also make shared_ptr? unsigned int displ = 0; @@ -394,6 +420,9 @@ void ExprLambda::bindVars(const std::shared_ptr &env) void ExprLet::bindVars(const std::shared_ptr &env) { + if (debuggerHook) + staticenv = env; + auto newEnv = std::shared_ptr(new StaticEnv(false, env.get())); // also make shared_ptr? unsigned int displ = 0; @@ -408,6 +437,9 @@ void ExprLet::bindVars(const std::shared_ptr &env) void ExprWith::bindVars(const std::shared_ptr &env) { + if (debuggerHook) + staticenv = env; + std::cout << " ExprWith::bindVars " << std::endl; /* Does this `with' have an enclosing `with'? If so, record its level so that `lookupVar' can look up variables in the previous @@ -472,6 +504,9 @@ void ExprWith::bindVars(const StaticEnv & env) void ExprIf::bindVars(const std::shared_ptr &env) { + if (debuggerHook) + staticenv = env; + cond->bindVars(env); then->bindVars(env); else_->bindVars(env); @@ -479,23 +514,35 @@ void ExprIf::bindVars(const std::shared_ptr &env) void ExprAssert::bindVars(const std::shared_ptr &env) { + if (debuggerHook) + staticenv = env; + cond->bindVars(env); body->bindVars(env); } void ExprOpNot::bindVars(const std::shared_ptr &env) { + if (debuggerHook) + staticenv = env; + e->bindVars(env); } void ExprConcatStrings::bindVars(const std::shared_ptr &env) { + if (debuggerHook) + staticenv = env; + for (auto & i : *es) i->bindVars(env); } void ExprPos::bindVars(const std::shared_ptr &env) { + if (debuggerHook) + staticenv = env; + } diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index ce3ee9f4d..341d80b35 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -85,7 +85,7 @@ struct Expr virtual Value * maybeThunk(EvalState & state, Env & env); virtual void setName(Symbol & name); - std::shared_ptr staticenv; + std::shared_ptr staticenv; }; std::ostream & operator << (std::ostream & str, const Expr & e);