From c7e3d830c1f305797b7a4c8b8199ba913d6b8a02 Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Wed, 22 Sep 2021 16:22:53 -0600 Subject: [PATCH] more debug stuff --- src/libcmd/installables.cc | 4 ++++ src/libexpr/nixexpr.cc | 41 ++++++++++++++++++++++++++++++++++---- src/libexpr/parser.y | 2 +- src/libexpr/primops.cc | 3 +++ 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index fd3e5cbba..bce666de5 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -619,6 +619,10 @@ std::vector> SourceExprCommand::parseInstallables( state->evalFile(lookupFileArg(*state, *file), *vFile); else { auto e = state->parseExprFromString(*expr, absPath(".")); + + int x = 5; + std::cout << "x =" << x << std::endl; + state->eval(e, *vFile); } diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index f8ded2157..6db047bf7 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -315,12 +315,16 @@ void ExprAttrs::bindVars(const std::shared_ptr &env) // auto dynamicEnv(env); if (recursive) { + std::cout << "recursive" << std::endl; // dynamicEnv = newEnv.get(); - auto newEnv = std::shared_ptr(new StaticEnv(false, env.get())); // also make shared_ptr? + // also make shared_ptr? + auto newEnv = std::shared_ptr(new StaticEnv(false, env.get())); unsigned int displ = 0; - for (auto & i : attrs) + for (auto & i : attrs) { + std::cout << "newenvvar: " << i.first << std::endl; newEnv->vars[i.first] = i.second.displ = displ++; + } for (auto & i : attrs) i.second.e->bindVars(i.second.inherited ? env : newEnv); @@ -330,8 +334,8 @@ void ExprAttrs::bindVars(const std::shared_ptr &env) i.valueExpr->bindVars(newEnv); } } - else { + std::cout << "NOT recursive" << std::endl; for (auto & i : attrs) i.second.e->bindVars(env); @@ -409,7 +413,7 @@ void ExprWith::bindVars(const std::shared_ptr &env) body->show(std::cout); std::cout << std::endl; - std::cout << "ExprWith::newenv: " << newEnv->vars.size() << std::endl; + std::cout << "ExprWith::newenv: (iswith, size); (" << newEnv->isWith << ", " << newEnv->vars.size() << ") " << std::endl; for (auto i = newEnv->vars.begin(); i != newEnv->vars.end(); ++i) std::cout << "EvalState::parse newEnv " << i->first << std::endl; @@ -418,6 +422,35 @@ void ExprWith::bindVars(const std::shared_ptr &env) std::cout << " ExprWith::bindVars 3" << std::endl; } +/* +void ExprWith::bindVars(const StaticEnv & env) +{ + // Does this `with' have an enclosing `with'? If so, record its + // level so that `lookupVar' can look up variables in the previous + // `with' if this one doesn't contain the desired attribute. + const StaticEnv * curEnv; + unsigned int level; + prevWith = 0; + for (curEnv = &env, level = 1; curEnv; curEnv = curEnv->up, level++) + if (curEnv->isWith) { + prevWith = level; + break; + } + + attrs->bindVars(env); + std::cout << "ExprWith::bindVars env: " << env.vars.size(); // add std::endl; + for (auto i = env.vars.begin(); i != env.vars.end(); ++i) + { + std::cout << i->first << std::endl; + } + + StaticEnv newEnv(true, &env); + body->bindVars(newEnv); +} +*/ + + + void ExprIf::bindVars(const std::shared_ptr &env) { cond->bindVars(env); diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index a3432eb32..f10e73cda 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -574,7 +574,7 @@ namespace nix { Expr * EvalState::parse(const char * text, FileOrigin origin, const Path & path, const Path & basePath, std::shared_ptr & staticEnv) { - std::cout << "EvalState::parse " << std::endl; + std::cout << "EvalState::parse " << text << std::endl; for (auto i = staticEnv->vars.begin(); i != staticEnv->vars.end(); ++i) std::cout << "EvalState::parse staticEnv " << i->first << std::endl; diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 7a277a7f5..246a3140b 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -110,6 +110,9 @@ static void mkOutputString(EvalState & state, Value & v, argument. */ static void import(EvalState & state, const Pos & pos, Value & vPath, Value * vScope, Value & v) { + std::cout << " IMPORT " << std::endl; + std::cout << " import " << std::endl; + std::cout << " IMPORT " << std::endl; std::cout << " import " << std::endl; PathSet context;