aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr
diff options
context:
space:
mode:
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/eval.cc8
-rw-r--r--src/libexpr/eval.hh12
-rw-r--r--src/libexpr/nixexpr.cc77
-rw-r--r--src/libexpr/nixexpr.hh7
4 files changed, 57 insertions, 47 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index d9ea92cc0..c9e4a05b7 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -772,12 +772,12 @@ void printEnvBindings(const SymbolTable & st, const StaticEnv & se, const Env &
}
}
-// TODO: add accompanying env for With stuff.
-void printEnvBindings(const SymbolTable & st, const Expr & expr, const Env & env)
+void printEnvBindings(const EvalState &es, const Expr & expr, const Env & env)
{
// just print the names for now
- if (expr.staticEnv)
- printEnvBindings(st, *expr.staticEnv.get(), env, 0);
+ auto se = es.getStaticEnv(expr);
+ if (se)
+ printEnvBindings(es.symbols, *se, env, 0);
}
void mapStaticEnvBindings(const SymbolTable & st, const StaticEnv & se, const Env & env, ValMap & vm)
diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh
index f274278be..0543cb35c 100644
--- a/src/libexpr/eval.hh
+++ b/src/libexpr/eval.hh
@@ -25,7 +25,7 @@ enum RepairFlag : bool;
typedef void (* PrimOpFun) (EvalState & state, const PosIdx pos, Value * * args, Value & v);
-void printEnvBindings(const SymbolTable & st, const Expr & expr, const Env & env);
+void printEnvBindings(const EvalState &es, const Expr & expr, const Env & env);
void printEnvBindings(const SymbolTable & st, const StaticEnv & se, const Env & env, int lvl = 0);
struct PrimOp
@@ -130,6 +130,16 @@ public:
bool debugStop;
bool debugQuit;
std::list<DebugTrace> debugTraces;
+ std::map<const Expr*, const std::shared_ptr<const StaticEnv> > exprEnvs;
+ const std::shared_ptr<const StaticEnv> getStaticEnv(const Expr &expr) const
+ {
+ auto i = exprEnvs.find(&expr);
+ if (i != exprEnvs.end())
+ return i->second;
+ else
+ return std::shared_ptr<const StaticEnv>();;
+ }
+
template<class E>
[[gnu::noinline, gnu::noreturn]]
diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc
index 213cf93fa..4fb43707e 100644
--- a/src/libexpr/nixexpr.cc
+++ b/src/libexpr/nixexpr.cc
@@ -296,38 +296,39 @@ std::string showAttrPath(const SymbolTable & symbols, const AttrPath & attrPath)
/* Computing levels/displacements for variables. */
-void Expr::bindVars(const EvalState & es, const std::shared_ptr<const StaticEnv> & env)
+void Expr::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{
abort();
}
-void ExprInt::bindVars(const EvalState & es, const std::shared_ptr<const StaticEnv> & env)
+void ExprInt::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{
if (debuggerHook)
- staticEnv = env;}
+ es.exprEnvs.insert(std::make_pair(this, env));
+}
-void ExprFloat::bindVars(const EvalState & es, const std::shared_ptr<const StaticEnv> & env)
+void ExprFloat::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{
if (debuggerHook)
- staticEnv = env;
+ es.exprEnvs.insert(std::make_pair(this, env));
}
-void ExprString::bindVars(const EvalState & es, const std::shared_ptr<const StaticEnv> & env)
+void ExprString::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{
if (debuggerHook)
- staticEnv = env;
+ es.exprEnvs.insert(std::make_pair(this, env));
}
-void ExprPath::bindVars(const EvalState & es, const std::shared_ptr<const StaticEnv> & env)
+void ExprPath::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{
if (debuggerHook)
- staticEnv = env;
+ es.exprEnvs.insert(std::make_pair(this, env));
}
-void ExprVar::bindVars(const EvalState & es, const std::shared_ptr<const StaticEnv> & env)
+void ExprVar::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{
if (debuggerHook)
- staticEnv = env;
+ es.exprEnvs.insert(std::make_pair(this, env));
/* Check whether the variable appears in the environment. If so,
set its level and displacement. */
@@ -360,10 +361,10 @@ void ExprVar::bindVars(const EvalState & es, const std::shared_ptr<const StaticE
this->level = withLevel;
}
-void ExprSelect::bindVars(const EvalState & es, const std::shared_ptr<const StaticEnv> & env)
+void ExprSelect::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{
if (debuggerHook)
- staticEnv = env;
+ es.exprEnvs.insert(std::make_pair(this, env));
e->bindVars(es, env);
if (def) def->bindVars(es, env);
@@ -372,10 +373,10 @@ void ExprSelect::bindVars(const EvalState & es, const std::shared_ptr<const Stat
i.expr->bindVars(es, env);
}
-void ExprOpHasAttr::bindVars(const EvalState & es, const std::shared_ptr<const StaticEnv> & env)
+void ExprOpHasAttr::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{
if (debuggerHook)
- staticEnv = env;
+ es.exprEnvs.insert(std::make_pair(this, env));
e->bindVars(es, env);
for (auto & i : attrPath)
@@ -383,10 +384,10 @@ void ExprOpHasAttr::bindVars(const EvalState & es, const std::shared_ptr<const S
i.expr->bindVars(es, env);
}
-void ExprAttrs::bindVars(const EvalState & es, const std::shared_ptr<const StaticEnv> & env)
+void ExprAttrs::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{
if (debuggerHook)
- staticEnv = env;
+ es.exprEnvs.insert(std::make_pair(this, env));
if (recursive) {
auto newEnv = std::make_shared<StaticEnv>(false, env.get(), recursive ? attrs.size() : 0);
@@ -416,19 +417,19 @@ void ExprAttrs::bindVars(const EvalState & es, const std::shared_ptr<const Stati
}
}
-void ExprList::bindVars(const EvalState & es, const std::shared_ptr<const StaticEnv> & env)
+void ExprList::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{
if (debuggerHook)
- staticEnv = env;
+ es.exprEnvs.insert(std::make_pair(this, env));
for (auto & i : elems)
i->bindVars(es, env);
}
-void ExprLambda::bindVars(const EvalState & es, const std::shared_ptr<const StaticEnv> & env)
+void ExprLambda::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{
if (debuggerHook)
- staticEnv = env;
+ es.exprEnvs.insert(std::make_pair(this, env));
auto newEnv = std::make_shared<StaticEnv>(
false, env.get(),
@@ -452,20 +453,20 @@ void ExprLambda::bindVars(const EvalState & es, const std::shared_ptr<const Stat
body->bindVars(es, newEnv);
}
-void ExprCall::bindVars(const EvalState & es, const std::shared_ptr<const StaticEnv> & env)
+void ExprCall::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{
if (debuggerHook)
- staticEnv = env;
+ es.exprEnvs.insert(std::make_pair(this, env));
fun->bindVars(es, env);
for (auto e : args)
e->bindVars(es, env);
}
-void ExprLet::bindVars(const EvalState & es, const std::shared_ptr<const StaticEnv> & env)
+void ExprLet::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{
if (debuggerHook)
- staticEnv = env;
+ es.exprEnvs.insert(std::make_pair(this, env));
auto newEnv = std::make_shared<StaticEnv>(false, env.get(), attrs->attrs.size());
@@ -481,10 +482,10 @@ void ExprLet::bindVars(const EvalState & es, const std::shared_ptr<const StaticE
body->bindVars(es, newEnv);
}
-void ExprWith::bindVars(const EvalState & es, const std::shared_ptr<const StaticEnv> & env)
+void ExprWith::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{
if (debuggerHook)
- staticEnv = env;
+ es.exprEnvs.insert(std::make_pair(this, env));
/* Does this `with' have an enclosing `with'? If so, record its
level so that `lookupVar' can look up variables in the previous
@@ -499,53 +500,53 @@ void ExprWith::bindVars(const EvalState & es, const std::shared_ptr<const Static
}
if (debuggerHook)
- staticEnv = env;
+ es.exprEnvs.insert(std::make_pair(this, env));
attrs->bindVars(es, env);
auto newEnv = std::make_shared<StaticEnv>(true, env.get());
body->bindVars(es, newEnv);
}
-void ExprIf::bindVars(const EvalState & es, const std::shared_ptr<const StaticEnv> & env)
+void ExprIf::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{
if (debuggerHook)
- staticEnv = env;
+ es.exprEnvs.insert(std::make_pair(this, env));
cond->bindVars(es, env);
then->bindVars(es, env);
else_->bindVars(es, env);
}
-void ExprAssert::bindVars(const EvalState & es, const std::shared_ptr<const StaticEnv> & env)
+void ExprAssert::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{
if (debuggerHook)
- staticEnv = env;
+ es.exprEnvs.insert(std::make_pair(this, env));
cond->bindVars(es, env);
body->bindVars(es, env);
}
-void ExprOpNot::bindVars(const EvalState & es, const std::shared_ptr<const StaticEnv> & env)
+void ExprOpNot::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{
if (debuggerHook)
- staticEnv = env;
+ es.exprEnvs.insert(std::make_pair(this, env));
e->bindVars(es, env);
}
-void ExprConcatStrings::bindVars(const EvalState & es, const std::shared_ptr<const StaticEnv> & env)
+void ExprConcatStrings::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{
if (debuggerHook)
- staticEnv = env;
+ es.exprEnvs.insert(std::make_pair(this, env));
for (auto & i : *this->es)
i.second->bindVars(es, env);
}
-void ExprPos::bindVars(const EvalState & es, const std::shared_ptr<const StaticEnv> & env)
+void ExprPos::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{
if (debuggerHook)
- staticEnv = env;
+ es.exprEnvs.insert(std::make_pair(this, env));
}
diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh
index c4a509f31..e923f36a4 100644
--- a/src/libexpr/nixexpr.hh
+++ b/src/libexpr/nixexpr.hh
@@ -144,18 +144,17 @@ struct Expr
{
virtual ~Expr() { };
virtual void show(const SymbolTable & symbols, std::ostream & str) const;
- virtual void bindVars(const EvalState & es, const std::shared_ptr<const StaticEnv> & env);
+ virtual void bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env);
virtual void eval(EvalState & state, Env & env, Value & v);
virtual Value * maybeThunk(EvalState & state, Env & env);
virtual void setName(Symbol name);
- std::shared_ptr<const StaticEnv> staticEnv;
virtual PosIdx getPos() const { return noPos; }
};
#define COMMON_METHODS \
void show(const SymbolTable & symbols, std::ostream & str) const; \
void eval(EvalState & state, Env & env, Value & v); \
- void bindVars(const EvalState & es, const std::shared_ptr<const StaticEnv> & env);
+ void bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env);
struct ExprInt : Expr
{
@@ -402,7 +401,7 @@ struct ExprOpNot : Expr
{ \
str << "("; e1->show(symbols, str); str << " " s " "; e2->show(symbols, str); str << ")"; \
} \
- void bindVars(const EvalState & es, const std::shared_ptr<const StaticEnv> & env) \
+ void bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env) \
{ \
e1->bindVars(es, env); e2->bindVars(es, env); \
} \