aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Burdette <bburdette@gmail.com>2021-09-23 13:02:39 -0600
committerBen Burdette <bburdette@gmail.com>2021-09-23 13:02:39 -0600
commitb9d08b98da4ab18f0c1c8bee30bd4ad934a5cdcf (patch)
tree7ec780a2e64ae3b7bc7764f11c1a60567eaf9217
parentc07edb1932b0f747b563aceaecc5550f5ce192fb (diff)
ok was unconditoinally throwing on any With var
-rw-r--r--src/libcmd/installables.cc4
-rw-r--r--src/libexpr/nixexpr.cc69
2 files changed, 46 insertions, 27 deletions
diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc
index bce666de5..f85bd4c13 100644
--- a/src/libcmd/installables.cc
+++ b/src/libcmd/installables.cc
@@ -618,10 +618,10 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
if (file)
state->evalFile(lookupFileArg(*state, *file), *vFile);
else {
+ std::cout << "pre parseExprFromString" << std::endl;
auto e = state->parseExprFromString(*expr, absPath("."));
- int x = 5;
- std::cout << "x =" << x << std::endl;
+ std::cout << "pre eval" << std::endl;
state->eval(e, *vFile);
}
diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc
index 8b883e185..6ca0de72b 100644
--- a/src/libexpr/nixexpr.cc
+++ b/src/libexpr/nixexpr.cc
@@ -262,34 +262,52 @@ void ExprVar::bindVars(const std::shared_ptr<const StaticEnv> &env)
{
/* Check whether the variable appears in the environment. If so,
set its level and displacement. */
- const StaticEnv * curEnv;
- unsigned int level;
- int withLevel = -1;
- for (curEnv = env.get(), level = 0; curEnv; curEnv = curEnv->up, level++) {
- if (curEnv->isWith) {
- if (withLevel == -1) withLevel = level;
- } else {
- StaticEnv::Vars::const_iterator i = curEnv->vars.find(name);
- if (i != curEnv->vars.end()) {
- fromWith = false;
- this->level = level;
- displ = i->second;
- return;
+
+ std::cout << "ExprVar::bindVars " << name << std::endl;
+
+ int a = 10;
+ if (name == "callPackage") {
+ a++; // try to make code that I can put a breakpoint on...
+ std::cout << "meh" << a + 10 << std::endl;
+ int withLevel = -1;
+ fromWith = true;
+ // this->level = withLevel;
+ }
+
+ {
+
+ const StaticEnv * curEnv;
+ unsigned int level;
+ int withLevel = -1;
+ for (curEnv = env.get(), level = 0; curEnv; curEnv = curEnv->up, level++) {
+ if (curEnv->isWith) {
+ if (withLevel == -1) withLevel = level;
+ } else {
+ StaticEnv::Vars::const_iterator i = curEnv->vars.find(name);
+ if (i != curEnv->vars.end()) {
+ fromWith = false;
+ this->level = level;
+ displ = i->second;
+ return;
+ }
}
}
+
+
+ /* Otherwise, the variable must be obtained from the nearest
+ enclosing `with'. If there is no `with', then we can issue an
+ "undefined variable" error now. */
+ if (withLevel == -1)
+ {
+ std::cout << " throw UndefinedVarError({" << std::endl;
+ throw UndefinedVarError({
+ .msg = hintfmt("undefined variable (ExprVar bindvars) '%1%'", name),
+ .errPos = pos
+ });
+ }
+ fromWith = true;
+ this->level = withLevel;
}
-
- /* Otherwise, the variable must be obtained from the nearest
- enclosing `with'. If there is no `with', then we can issue an
- "undefined variable" error now. */
- if (withLevel == -1)
- std::cout << " throw UndefinedVarError({" << std::endl;
- throw UndefinedVarError({
- .msg = hintfmt("undefined variable '%1%'", name),
- .errPos = pos
- });
- fromWith = true;
- this->level = withLevel;
}
void ExprSelect::bindVars(const std::shared_ptr<const StaticEnv> &env)
@@ -418,6 +436,7 @@ void ExprWith::bindVars(const std::shared_ptr<const StaticEnv> &env)
std::cout << "EvalState::parse newEnv " << i->first << std::endl;
+ std::cout << " body->bindVars(newEnv), iswith: " << newEnv->isWith << std::endl;
body->bindVars(newEnv);
std::cout << " ExprWith::bindVars 3" << std::endl;
}