From 21071bfdeb0a5bc2b75018c91a4c2f138f233e33 Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Tue, 14 Sep 2021 10:49:22 -0600 Subject: shared_ptr for StaticEnv --- src/libexpr/nixexpr.cc | 64 +++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'src/libexpr/nixexpr.cc') diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 492b819e7..218e35f33 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -237,35 +237,35 @@ Pos noPos; /* Computing levels/displacements for variables. */ -void Expr::bindVars(const StaticEnv & env) +void Expr::bindVars(const std::shared_ptr &env) { abort(); } -void ExprInt::bindVars(const StaticEnv & env) +void ExprInt::bindVars(const std::shared_ptr &env) { } -void ExprFloat::bindVars(const StaticEnv & env) +void ExprFloat::bindVars(const std::shared_ptr &env) { } -void ExprString::bindVars(const StaticEnv & env) +void ExprString::bindVars(const std::shared_ptr &env) { } -void ExprPath::bindVars(const StaticEnv & env) +void ExprPath::bindVars(const std::shared_ptr &env) { } -void ExprVar::bindVars(const StaticEnv & env) +void ExprVar::bindVars(const std::shared_ptr &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, level = 0; curEnv; curEnv = curEnv->up, level++) { + for (curEnv = env.get(), level = 0; curEnv; curEnv = curEnv->up, level++) { if (curEnv->isWith) { if (withLevel == -1) withLevel = level; } else { @@ -291,7 +291,7 @@ void ExprVar::bindVars(const StaticEnv & env) this->level = withLevel; } -void ExprSelect::bindVars(const StaticEnv & env) +void ExprSelect::bindVars(const std::shared_ptr &env) { e->bindVars(env); if (def) def->bindVars(env); @@ -300,7 +300,7 @@ void ExprSelect::bindVars(const StaticEnv & env) i.expr->bindVars(env); } -void ExprOpHasAttr::bindVars(const StaticEnv & env) +void ExprOpHasAttr::bindVars(const std::shared_ptr &env) { e->bindVars(env); for (auto & i : attrPath) @@ -308,17 +308,17 @@ void ExprOpHasAttr::bindVars(const StaticEnv & env) i.expr->bindVars(env); } -void ExprAttrs::bindVars(const StaticEnv & env) +void ExprAttrs::bindVars(const std::shared_ptr &env) { - const StaticEnv * dynamicEnv = &env; - StaticEnv newEnv(false, &env); + const StaticEnv * dynamicEnv = env.get(); + auto newEnv = std::shared_ptr(new StaticEnv(false, env.get())); // also make shared_ptr? if (recursive) { - dynamicEnv = &newEnv; + dynamicEnv = newEnv.get(); unsigned int displ = 0; for (auto & i : attrs) - newEnv.vars[i.first] = i.second.displ = displ++; + newEnv->vars[i.first] = i.second.displ = displ++; for (auto & i : attrs) i.second.e->bindVars(i.second.inherited ? env : newEnv); @@ -329,28 +329,28 @@ void ExprAttrs::bindVars(const StaticEnv & env) i.second.e->bindVars(env); for (auto & i : dynamicAttrs) { - i.nameExpr->bindVars(*dynamicEnv); - i.valueExpr->bindVars(*dynamicEnv); + i.nameExpr->bindVars(newEnv); + i.valueExpr->bindVars(newEnv); } } -void ExprList::bindVars(const StaticEnv & env) +void ExprList::bindVars(const std::shared_ptr &env) { for (auto & i : elems) i->bindVars(env); } -void ExprLambda::bindVars(const StaticEnv & env) +void ExprLambda::bindVars(const std::shared_ptr &env) { - StaticEnv newEnv(false, &env); + auto newEnv = std::shared_ptr(new StaticEnv(false, env.get())); // also make shared_ptr? unsigned int displ = 0; - if (!arg.empty()) newEnv.vars[arg] = displ++; + if (!arg.empty()) newEnv->vars[arg] = displ++; if (matchAttrs) { for (auto & i : formals->formals) - newEnv.vars[i.name] = displ++; + newEnv->vars[i.name] = displ++; for (auto & i : formals->formals) if (i.def) i.def->bindVars(newEnv); @@ -359,13 +359,13 @@ void ExprLambda::bindVars(const StaticEnv & env) body->bindVars(newEnv); } -void ExprLet::bindVars(const StaticEnv & env) +void ExprLet::bindVars(const std::shared_ptr &env) { - StaticEnv newEnv(false, &env); + auto newEnv = std::shared_ptr(new StaticEnv(false, env.get())); // also make shared_ptr? unsigned int displ = 0; for (auto & i : attrs->attrs) - newEnv.vars[i.first] = i.second.displ = displ++; + newEnv->vars[i.first] = i.second.displ = displ++; for (auto & i : attrs->attrs) i.second.e->bindVars(i.second.inherited ? env : newEnv); @@ -373,7 +373,7 @@ void ExprLet::bindVars(const StaticEnv & env) body->bindVars(newEnv); } -void ExprWith::bindVars(const StaticEnv & env) +void ExprWith::bindVars(const std::shared_ptr &env) { /* Does this `with' have an enclosing `with'? If so, record its level so that `lookupVar' can look up variables in the previous @@ -381,42 +381,42 @@ void ExprWith::bindVars(const StaticEnv & env) const StaticEnv * curEnv; unsigned int level; prevWith = 0; - for (curEnv = &env, level = 1; curEnv; curEnv = curEnv->up, level++) + for (curEnv = env.get(), level = 1; curEnv; curEnv = curEnv->up, level++) if (curEnv->isWith) { prevWith = level; break; } attrs->bindVars(env); - StaticEnv newEnv(true, &env); + auto newEnv = std::shared_ptr(new StaticEnv(false, env.get())); // also make shared_ptr? body->bindVars(newEnv); } -void ExprIf::bindVars(const StaticEnv & env) +void ExprIf::bindVars(const std::shared_ptr &env) { cond->bindVars(env); then->bindVars(env); else_->bindVars(env); } -void ExprAssert::bindVars(const StaticEnv & env) +void ExprAssert::bindVars(const std::shared_ptr &env) { cond->bindVars(env); body->bindVars(env); } -void ExprOpNot::bindVars(const StaticEnv & env) +void ExprOpNot::bindVars(const std::shared_ptr &env) { e->bindVars(env); } -void ExprConcatStrings::bindVars(const StaticEnv & env) +void ExprConcatStrings::bindVars(const std::shared_ptr &env) { for (auto & i : *es) i->bindVars(env); } -void ExprPos::bindVars(const StaticEnv & env) +void ExprPos::bindVars(const std::shared_ptr &env) { } -- cgit v1.2.3 From cd8c232b554776031f61cee5f70a8825c60fbfdb Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Wed, 15 Sep 2021 16:16:53 -0600 Subject: add cout debugging --- src/libexpr/nixexpr.cc | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) (limited to 'src/libexpr/nixexpr.cc') diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 218e35f33..f8ded2157 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -3,7 +3,7 @@ #include "util.hh" #include - +#include namespace nix { @@ -283,6 +283,7 @@ void ExprVar::bindVars(const std::shared_ptr &env) 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 @@ -310,11 +311,12 @@ void ExprOpHasAttr::bindVars(const std::shared_ptr &env) void ExprAttrs::bindVars(const std::shared_ptr &env) { - const StaticEnv * dynamicEnv = env.get(); - auto newEnv = std::shared_ptr(new StaticEnv(false, env.get())); // also make shared_ptr? + std::cout << "ExprAttrs::bindVars" << std::endl; + // auto dynamicEnv(env); if (recursive) { - dynamicEnv = newEnv.get(); + // dynamicEnv = newEnv.get(); + auto newEnv = std::shared_ptr(new StaticEnv(false, env.get())); // also make shared_ptr? unsigned int displ = 0; for (auto & i : attrs) @@ -322,16 +324,25 @@ void ExprAttrs::bindVars(const std::shared_ptr &env) for (auto & i : attrs) i.second.e->bindVars(i.second.inherited ? env : newEnv); + + for (auto & i : dynamicAttrs) { + i.nameExpr->bindVars(newEnv); + i.valueExpr->bindVars(newEnv); + } } - else + else { for (auto & i : attrs) i.second.e->bindVars(env); - for (auto & i : dynamicAttrs) { - i.nameExpr->bindVars(newEnv); - i.valueExpr->bindVars(newEnv); + for (auto & i : dynamicAttrs) { + i.nameExpr->bindVars(env); + i.valueExpr->bindVars(env); + } } + + std::cout << "ExprAttrs::bindVars end" << std::endl; + } void ExprList::bindVars(const std::shared_ptr &env) @@ -375,6 +386,7 @@ void ExprLet::bindVars(const std::shared_ptr &env) void ExprWith::bindVars(const std::shared_ptr &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 `with' if this one doesn't contain the desired attribute. */ @@ -387,9 +399,23 @@ void ExprWith::bindVars(const std::shared_ptr &env) break; } + std::cout << " ExprWith::bindVars 1" << std::endl; + attrs->show(std::cout); + std::cout << std::endl; attrs->bindVars(env); auto newEnv = std::shared_ptr(new StaticEnv(false, env.get())); // also make shared_ptr? + std::cout << " ExprWith::bindVars 2" << std::endl; + std::cout << " body: " << std::endl; + body->show(std::cout); + std::cout << std::endl; + + std::cout << "ExprWith::newenv: " << 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; + + body->bindVars(newEnv); + std::cout << " ExprWith::bindVars 3" << std::endl; } void ExprIf::bindVars(const std::shared_ptr &env) -- cgit v1.2.3 From c7e3d830c1f305797b7a4c8b8199ba913d6b8a02 Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Wed, 22 Sep 2021 16:22:53 -0600 Subject: more debug stuff --- src/libexpr/nixexpr.cc | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'src/libexpr/nixexpr.cc') 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); -- cgit v1.2.3 From c07edb1932b0f747b563aceaecc5550f5ce192fb Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Wed, 22 Sep 2021 18:14:57 -0600 Subject: staticenv should be With --- src/libexpr/nixexpr.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libexpr/nixexpr.cc') diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 6db047bf7..8b883e185 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -407,7 +407,7 @@ void ExprWith::bindVars(const std::shared_ptr &env) attrs->show(std::cout); std::cout << std::endl; attrs->bindVars(env); - auto newEnv = std::shared_ptr(new StaticEnv(false, env.get())); // also make shared_ptr? + auto newEnv = std::shared_ptr(new StaticEnv(true, env.get())); // also make shared_ptr? std::cout << " ExprWith::bindVars 2" << std::endl; std::cout << " body: " << std::endl; body->show(std::cout); -- cgit v1.2.3 From b9d08b98da4ab18f0c1c8bee30bd4ad934a5cdcf Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Thu, 23 Sep 2021 13:02:39 -0600 Subject: ok was unconditoinally throwing on any With var --- src/libexpr/nixexpr.cc | 69 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 25 deletions(-) (limited to 'src/libexpr/nixexpr.cc') 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 &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 &env) @@ -418,6 +436,7 @@ void ExprWith::bindVars(const std::shared_ptr &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; } -- cgit v1.2.3 From aad27143c67c863bd4886186bdf68f4796ca26c3 Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Sat, 2 Oct 2021 13:47:36 -0600 Subject: storing staticenv bindings --- src/libexpr/nixexpr.cc | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/libexpr/nixexpr.cc') 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; + } -- cgit v1.2.3 From 427fb8d1581d7b20b0f5205cc59f3857275860c1 Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Mon, 11 Oct 2021 16:48:10 -0600 Subject: comment out debugs --- src/libexpr/nixexpr.cc | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'src/libexpr/nixexpr.cc') diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 85b1d5e12..8f88eabd5 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -274,12 +274,12 @@ void ExprVar::bindVars(const std::shared_ptr &env) /* Check whether the variable appears in the environment. If so, set its level and displacement. */ - std::cout << "ExprVar::bindVars " << name << std::endl; + // 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; + // std::cout << "meh" << a + 10 << std::endl; int withLevel = -1; fromWith = true; // this->level = withLevel; @@ -310,7 +310,7 @@ void ExprVar::bindVars(const std::shared_ptr &env) "undefined variable" error now. */ if (withLevel == -1) { - std::cout << " throw UndefinedVarError({" << std::endl; + // std::cout << " throw UndefinedVarError({" << std::endl; throw UndefinedVarError({ .msg = hintfmt("undefined variable (ExprVar bindvars) '%1%'", name), .errPos = pos @@ -349,18 +349,18 @@ void ExprAttrs::bindVars(const std::shared_ptr &env) if (debuggerHook) staticenv = env; - std::cout << "ExprAttrs::bindVars" << std::endl; + // std::cout << "ExprAttrs::bindVars" << std::endl; // auto dynamicEnv(env); if (recursive) { - std::cout << "recursive" << std::endl; + // std::cout << "recursive" << std::endl; // dynamicEnv = newEnv.get(); // also make shared_ptr? auto newEnv = std::shared_ptr(new StaticEnv(false, env.get())); unsigned int displ = 0; for (auto & i : attrs) { - std::cout << "newenvvar: " << i.first << std::endl; + // std::cout << "newenvvar: " << i.first << std::endl; newEnv->vars[i.first] = i.second.displ = displ++; } @@ -373,7 +373,7 @@ void ExprAttrs::bindVars(const std::shared_ptr &env) } } else { - std::cout << "NOT recursive" << std::endl; + // std::cout << "NOT recursive" << std::endl; for (auto & i : attrs) i.second.e->bindVars(env); @@ -383,7 +383,7 @@ void ExprAttrs::bindVars(const std::shared_ptr &env) } } - std::cout << "ExprAttrs::bindVars end" << std::endl; + // std::cout << "ExprAttrs::bindVars end" << std::endl; } @@ -440,7 +440,7 @@ void ExprWith::bindVars(const std::shared_ptr &env) if (debuggerHook) staticenv = env; - std::cout << " ExprWith::bindVars " << std::endl; + // 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 `with' if this one doesn't contain the desired attribute. */ @@ -453,24 +453,24 @@ void ExprWith::bindVars(const std::shared_ptr &env) break; } - std::cout << " ExprWith::bindVars 1" << std::endl; - attrs->show(std::cout); - std::cout << std::endl; + // std::cout << " ExprWith::bindVars 1" << std::endl; + // attrs->show(std::cout); + // std::cout << std::endl; attrs->bindVars(env); auto newEnv = std::shared_ptr(new StaticEnv(true, env.get())); // also make shared_ptr? - std::cout << " ExprWith::bindVars 2" << std::endl; - std::cout << " body: " << std::endl; - body->show(std::cout); - std::cout << std::endl; + // std::cout << " ExprWith::bindVars 2" << std::endl; + // std::cout << " body: " << std::endl; + // body->show(std::cout); + // std::cout << 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; + // 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; - std::cout << " body->bindVars(newEnv), iswith: " << newEnv->isWith << std::endl; + // std::cout << " body->bindVars(newEnv), iswith: " << newEnv->isWith << std::endl; body->bindVars(newEnv); - std::cout << " ExprWith::bindVars 3" << std::endl; + // std::cout << " ExprWith::bindVars 3" << std::endl; } /* -- cgit v1.2.3 From fb8377547bcb6d4dc6464ca34c0fe433e1cfda44 Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Fri, 22 Oct 2021 14:49:58 -0600 Subject: more code cleanup --- src/libexpr/nixexpr.cc | 130 +++++++++++-------------------------------------- 1 file changed, 29 insertions(+), 101 deletions(-) (limited to 'src/libexpr/nixexpr.cc') diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 8f88eabd5..65c7cac1d 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -273,52 +273,36 @@ void ExprVar::bindVars(const std::shared_ptr &env) /* Check whether the variable appears in the environment. If so, set its level and displacement. */ - - // 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) { - - 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; + // std::cout << " throw UndefinedVarError({" << std::endl; + throw UndefinedVarError({ + .msg = hintfmt("undefined variable (ExprVar bindvars) '%1%'", name), + .errPos = pos + }); } + fromWith = true; + this->level = withLevel; } void ExprSelect::bindVars(const std::shared_ptr &env) @@ -349,18 +333,11 @@ void ExprAttrs::bindVars(const std::shared_ptr &env) if (debuggerHook) staticenv = env; - // std::cout << "ExprAttrs::bindVars" << std::endl; - // auto dynamicEnv(env); - if (recursive) { - // std::cout << "recursive" << std::endl; - // dynamicEnv = newEnv.get(); - // also make shared_ptr? auto newEnv = std::shared_ptr(new StaticEnv(false, env.get())); unsigned int displ = 0; for (auto & i : attrs) { - // std::cout << "newenvvar: " << i.first << std::endl; newEnv->vars[i.first] = i.second.displ = displ++; } @@ -373,7 +350,6 @@ void ExprAttrs::bindVars(const std::shared_ptr &env) } } else { - // std::cout << "NOT recursive" << std::endl; for (auto & i : attrs) i.second.e->bindVars(env); @@ -382,9 +358,6 @@ void ExprAttrs::bindVars(const std::shared_ptr &env) i.valueExpr->bindVars(env); } } - - // std::cout << "ExprAttrs::bindVars end" << std::endl; - } void ExprList::bindVars(const std::shared_ptr &env) @@ -401,7 +374,7 @@ 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? + auto newEnv = std::shared_ptr(new StaticEnv(false, env.get())); unsigned int displ = 0; @@ -423,7 +396,7 @@ 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? + auto newEnv = std::shared_ptr(new StaticEnv(false, env.get())); unsigned int displ = 0; for (auto & i : attrs->attrs) @@ -440,7 +413,6 @@ 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 `with' if this one doesn't contain the desired attribute. */ @@ -453,55 +425,11 @@ void ExprWith::bindVars(const std::shared_ptr &env) break; } - // std::cout << " ExprWith::bindVars 1" << std::endl; - // attrs->show(std::cout); - // std::cout << std::endl; attrs->bindVars(env); - auto newEnv = std::shared_ptr(new StaticEnv(true, env.get())); // also make shared_ptr? - // std::cout << " ExprWith::bindVars 2" << std::endl; - // std::cout << " body: " << std::endl; - // body->show(std::cout); - // std::cout << 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; - - - // std::cout << " body->bindVars(newEnv), iswith: " << newEnv->isWith << std::endl; + auto newEnv = std::shared_ptr(new StaticEnv(true, env.get())); body->bindVars(newEnv); - // 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) { if (debuggerHook) -- cgit v1.2.3 From 7e2a3db4eb663aa99aec7ebcc83d75cb948a2cb3 Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Tue, 9 Nov 2021 13:14:49 -0700 Subject: cleanup --- src/libexpr/nixexpr.cc | 1 - 1 file changed, 1 deletion(-) (limited to 'src/libexpr/nixexpr.cc') diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 65c7cac1d..9ccecca55 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -295,7 +295,6 @@ void ExprVar::bindVars(const std::shared_ptr &env) "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 -- cgit v1.2.3 From 69e26c5c4ba106bd16f60bfaac88ccf888b4383f Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Thu, 25 Nov 2021 08:23:07 -0700 Subject: more cleanup --- src/libexpr/nixexpr.cc | 1 - 1 file changed, 1 deletion(-) (limited to 'src/libexpr/nixexpr.cc') diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 9ccecca55..3e42789a2 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -3,7 +3,6 @@ #include "util.hh" #include -#include namespace nix { -- cgit v1.2.3 From e82aec4efcd06cbd60d57f401fb7e93ab595128c Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Tue, 30 Nov 2021 14:15:02 -0700 Subject: fix merge issues --- src/libexpr/nixexpr.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/libexpr/nixexpr.cc') diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 696b149e3..dd0031a7c 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -346,7 +346,7 @@ void ExprAttrs::bindVars(const std::shared_ptr &env) Displacement displ = 0; for (auto & i : attrs) - newEnv.vars.emplace_back(i.first, i.second.displ = displ++); + newEnv->vars.emplace_back(i.first, i.second.displ = displ++); // No need to sort newEnv since attrs is in sorted order. @@ -391,13 +391,13 @@ void ExprLambda::bindVars(const std::shared_ptr &env) Displacement displ = 0; - if (!arg.empty()) newEnv.vars.emplace_back(arg, displ++); + if (!arg.empty()) newEnv->vars.emplace_back(arg, displ++); if (hasFormals()) { for (auto & i : formals->formals) - newEnv.vars.emplace_back(i.name, displ++); + newEnv->vars.emplace_back(i.name, displ++); - newEnv.sort(); + newEnv->sort(); for (auto & i : formals->formals) if (i.def) i.def->bindVars(newEnv); @@ -406,7 +406,7 @@ void ExprLambda::bindVars(const std::shared_ptr &env) body->bindVars(newEnv); } -void ExprCall::bindVars(const StaticEnv & env) +void ExprCall::bindVars(const std::shared_ptr &env) { if (debuggerHook) staticenv = env; @@ -416,7 +416,7 @@ void ExprCall::bindVars(const StaticEnv & env) e->bindVars(env); } -void ExprLet::bindVars(const StaticEnv & env) +void ExprLet::bindVars(const std::shared_ptr &env) { if (debuggerHook) staticenv = env; @@ -425,7 +425,7 @@ void ExprLet::bindVars(const StaticEnv & env) Displacement displ = 0; for (auto & i : attrs->attrs) - newEnv.vars.emplace_back(i.first, i.second.displ = displ++); + newEnv->vars.emplace_back(i.first, i.second.displ = displ++); // No need to sort newEnv since attrs->attrs is in sorted order. -- cgit v1.2.3 From 4cffb130e385bc3f4c5ca0482ad8c4dd22229cfe Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Fri, 11 Feb 2022 14:14:25 -0700 Subject: for primops, enter the debugger at the last DebugTrace in the stack --- src/libexpr/nixexpr.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libexpr/nixexpr.cc') diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 41ee92d27..e09bd9484 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -305,7 +305,7 @@ void ExprVar::bindVars(const std::shared_ptr &env) if (withLevel == -1) { throw UndefinedVarError({ - .msg = hintfmt("undefined variable (ExprVar bindvars) '%1%'", name), + .msg = hintfmt("undefined variable '%1%'", name), .errPos = pos }); } -- cgit v1.2.3 From 3dfab6e534e0a1cf71c000a4d2a74e050ba576ce Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Mon, 14 Mar 2022 11:58:11 -0600 Subject: have only one debuggerHook declaration --- src/libexpr/nixexpr.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/libexpr/nixexpr.cc') diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index e09bd9484..add65c1a2 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -6,6 +6,9 @@ namespace nix { +/* Launch the nix debugger */ + +std::function debuggerHook; /* Displaying abstract syntax trees. */ -- cgit v1.2.3 From 2a5632c70dcb686a7764c23a5f330fcb9a33c8a1 Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Fri, 29 Apr 2022 10:02:17 -0600 Subject: incorporate PosIdx changes, symbol changes. --- src/libexpr/nixexpr.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/libexpr/nixexpr.cc') diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index efaeba7c6..c6e545729 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -437,11 +437,11 @@ void ExprLambda::bindVars(const EvalState & es, const std::shared_ptrformals.size() : 0) + - (!arg ? 0 : 1)); + (!arg ? 0 : 1))); Displacement displ = 0; - if (arg) newEnv.vars.emplace_back(arg, displ++); + if (arg) newEnv->vars.emplace_back(arg, displ++); if (hasFormals()) { for (auto & i : formals->formals) @@ -506,7 +506,7 @@ void ExprWith::bindVars(const EvalState & es, const std::shared_ptrbindVars(es, env); - StaticEnv newEnv(true, &env); + auto newEnv = std::shared_ptr(new StaticEnv(true, env.get())); body->bindVars(es, newEnv); } -- cgit v1.2.3 From 172a83d22a3c984b6b569b5528d2338059bb748b Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Fri, 29 Apr 2022 11:24:54 -0600 Subject: line endings --- src/libexpr/nixexpr.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libexpr/nixexpr.cc') diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index c6e545729..5624c4780 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -352,7 +352,7 @@ void ExprVar::bindVars(const EvalState & es, const std::shared_ptr(new StaticEnv(false, env.get(), recursive ? attrs.size() : 0)); + auto newEnv = std::shared_ptr(new StaticEnv(false, env.get(), recursive ? attrs.size() : 0)); Displacement displ = 0; for (auto & i : attrs) -- cgit v1.2.3 From dd8b91eebc0d31c9f8016609b36d89f58d8c4d19 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 5 May 2022 12:29:14 +0200 Subject: Style fixes In particular, use std::make_shared and enumerate(). Also renamed some fields to fit naming conventions. --- src/libexpr/nixexpr.cc | 95 ++++++++++++++++++++++++-------------------------- 1 file changed, 45 insertions(+), 50 deletions(-) (limited to 'src/libexpr/nixexpr.cc') diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 5624c4780..213cf93fa 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -296,39 +296,38 @@ std::string showAttrPath(const SymbolTable & symbols, const AttrPath & attrPath) /* Computing levels/displacements for variables. */ -void Expr::bindVars(const EvalState & es, const std::shared_ptr &env) +void Expr::bindVars(const EvalState & es, const std::shared_ptr & env) { abort(); } -void ExprInt::bindVars(const EvalState & es, const std::shared_ptr &env) +void ExprInt::bindVars(const EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticenv = env; -} + staticEnv = env;} -void ExprFloat::bindVars(const EvalState & es, const std::shared_ptr &env) +void ExprFloat::bindVars(const EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticenv = env; + staticEnv = env; } -void ExprString::bindVars(const EvalState & es, const std::shared_ptr &env) +void ExprString::bindVars(const EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticenv = env; + staticEnv = env; } -void ExprPath::bindVars(const EvalState & es, const std::shared_ptr &env) +void ExprPath::bindVars(const EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticenv = env; + staticEnv = env; } -void ExprVar::bindVars(const EvalState & es, const std::shared_ptr &env) +void ExprVar::bindVars(const EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticenv = env; + staticEnv = env; /* Check whether the variable appears in the environment. If so, set its level and displacement. */ @@ -353,20 +352,18 @@ void ExprVar::bindVars(const EvalState & es, const std::shared_ptrlevel = withLevel; } -void ExprSelect::bindVars(const EvalState & es, const std::shared_ptr &env) +void ExprSelect::bindVars(const EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticenv = env; + staticEnv = env; e->bindVars(es, env); if (def) def->bindVars(es, env); @@ -375,10 +372,10 @@ void ExprSelect::bindVars(const EvalState & es, const std::shared_ptrbindVars(es, env); } -void ExprOpHasAttr::bindVars(const EvalState & es, const std::shared_ptr &env) +void ExprOpHasAttr::bindVars(const EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticenv = env; + staticEnv = env; e->bindVars(es, env); for (auto & i : attrPath) @@ -386,13 +383,13 @@ void ExprOpHasAttr::bindVars(const EvalState & es, const std::shared_ptrbindVars(es, env); } -void ExprAttrs::bindVars(const EvalState & es, const std::shared_ptr &env) +void ExprAttrs::bindVars(const EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticenv = env; + staticEnv = env; if (recursive) { - auto newEnv = std::shared_ptr(new StaticEnv(false, env.get(), recursive ? attrs.size() : 0)); + auto newEnv = std::make_shared(false, env.get(), recursive ? attrs.size() : 0); Displacement displ = 0; for (auto & i : attrs) @@ -419,25 +416,24 @@ void ExprAttrs::bindVars(const EvalState & es, const std::shared_ptr &env) +void ExprList::bindVars(const EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticenv = env; + staticEnv = env; for (auto & i : elems) i->bindVars(es, env); } -void ExprLambda::bindVars(const EvalState & es, const std::shared_ptr &env) +void ExprLambda::bindVars(const EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticenv = env; + staticEnv = env; - auto newEnv = std::shared_ptr( - new StaticEnv( - false, env.get(), - (hasFormals() ? formals->formals.size() : 0) + - (!arg ? 0 : 1))); + auto newEnv = std::make_shared( + false, env.get(), + (hasFormals() ? formals->formals.size() : 0) + + (!arg ? 0 : 1)); Displacement displ = 0; @@ -456,22 +452,22 @@ void ExprLambda::bindVars(const EvalState & es, const std::shared_ptrbindVars(es, newEnv); } -void ExprCall::bindVars(const EvalState & es, const std::shared_ptr &env) +void ExprCall::bindVars(const EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticenv = env; + staticEnv = env; fun->bindVars(es, env); for (auto e : args) e->bindVars(es, env); } -void ExprLet::bindVars(const EvalState & es, const std::shared_ptr &env) +void ExprLet::bindVars(const EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticenv = env; + staticEnv = env; - auto newEnv = std::shared_ptr(new StaticEnv(false, env.get(), attrs->attrs.size())); + auto newEnv = std::make_shared(false, env.get(), attrs->attrs.size()); Displacement displ = 0; for (auto & i : attrs->attrs) @@ -485,10 +481,10 @@ void ExprLet::bindVars(const EvalState & es, const std::shared_ptrbindVars(es, newEnv); } -void ExprWith::bindVars(const EvalState & es, const std::shared_ptr &env) +void ExprWith::bindVars(const EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticenv = env; + staticEnv = env; /* Does this `with' have an enclosing `with'? If so, record its level so that `lookupVar' can look up variables in the previous @@ -503,54 +499,53 @@ void ExprWith::bindVars(const EvalState & es, const std::shared_ptrbindVars(es, env); - auto newEnv = std::shared_ptr(new StaticEnv(true, env.get())); + auto newEnv = std::make_shared(true, env.get()); body->bindVars(es, newEnv); } -void ExprIf::bindVars(const EvalState & es, const std::shared_ptr &env) +void ExprIf::bindVars(const EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticenv = env; + staticEnv = env; cond->bindVars(es, env); then->bindVars(es, env); else_->bindVars(es, env); } -void ExprAssert::bindVars(const EvalState & es, const std::shared_ptr &env) +void ExprAssert::bindVars(const EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticenv = env; + staticEnv = env; cond->bindVars(es, env); body->bindVars(es, env); } -void ExprOpNot::bindVars(const EvalState & es, const std::shared_ptr &env) +void ExprOpNot::bindVars(const EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticenv = env; + staticEnv = env; e->bindVars(es, env); } -void ExprConcatStrings::bindVars(const EvalState & es, const std::shared_ptr &env) +void ExprConcatStrings::bindVars(const EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticenv = env; + staticEnv = env; for (auto & i : *this->es) i.second->bindVars(es, env); } -void ExprPos::bindVars(const EvalState & es, const std::shared_ptr &env) +void ExprPos::bindVars(const EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticenv = env; - + staticEnv = env; } -- cgit v1.2.3 From 667074b5867ffe40e3f1c59bd8e4ebf259f86aaa Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Mon, 16 May 2022 09:20:51 -0600 Subject: first whack at passing evalState as an arg to debuggerHook. --- src/libexpr/nixexpr.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libexpr/nixexpr.cc') diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 213cf93fa..a7b7b8aad 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -10,7 +10,7 @@ namespace nix { /* Launch the nix debugger */ -std::function debuggerHook; +std::function debuggerHook; /* Displaying abstract syntax trees. */ -- cgit v1.2.3 From 357fb84dbaad0b056704915c6a43764cda63ee7f Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Thu, 19 May 2022 10:48:10 -0600 Subject: use an expr->StaticEnv table in evalState --- src/libexpr/nixexpr.cc | 77 +++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 38 deletions(-) (limited to 'src/libexpr/nixexpr.cc') 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 & env) +void Expr::bindVars(EvalState & es, const std::shared_ptr & env) { abort(); } -void ExprInt::bindVars(const EvalState & es, const std::shared_ptr & env) +void ExprInt::bindVars(EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticEnv = env;} + es.exprEnvs.insert(std::make_pair(this, env)); +} -void ExprFloat::bindVars(const EvalState & es, const std::shared_ptr & env) +void ExprFloat::bindVars(EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticEnv = env; + es.exprEnvs.insert(std::make_pair(this, env)); } -void ExprString::bindVars(const EvalState & es, const std::shared_ptr & env) +void ExprString::bindVars(EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticEnv = env; + es.exprEnvs.insert(std::make_pair(this, env)); } -void ExprPath::bindVars(const EvalState & es, const std::shared_ptr & env) +void ExprPath::bindVars(EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticEnv = env; + es.exprEnvs.insert(std::make_pair(this, env)); } -void ExprVar::bindVars(const EvalState & es, const std::shared_ptr & env) +void ExprVar::bindVars(EvalState & es, const std::shared_ptr & 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_ptrlevel = withLevel; } -void ExprSelect::bindVars(const EvalState & es, const std::shared_ptr & env) +void ExprSelect::bindVars(EvalState & es, const std::shared_ptr & 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_ptrbindVars(es, env); } -void ExprOpHasAttr::bindVars(const EvalState & es, const std::shared_ptr & env) +void ExprOpHasAttr::bindVars(EvalState & es, const std::shared_ptr & 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_ptrbindVars(es, env); } -void ExprAttrs::bindVars(const EvalState & es, const std::shared_ptr & env) +void ExprAttrs::bindVars(EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticEnv = env; + es.exprEnvs.insert(std::make_pair(this, env)); if (recursive) { auto newEnv = std::make_shared(false, env.get(), recursive ? attrs.size() : 0); @@ -416,19 +417,19 @@ void ExprAttrs::bindVars(const EvalState & es, const std::shared_ptr & env) +void ExprList::bindVars(EvalState & es, const std::shared_ptr & 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 & env) +void ExprLambda::bindVars(EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticEnv = env; + es.exprEnvs.insert(std::make_pair(this, env)); auto newEnv = std::make_shared( false, env.get(), @@ -452,20 +453,20 @@ void ExprLambda::bindVars(const EvalState & es, const std::shared_ptrbindVars(es, newEnv); } -void ExprCall::bindVars(const EvalState & es, const std::shared_ptr & env) +void ExprCall::bindVars(EvalState & es, const std::shared_ptr & 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 & env) +void ExprLet::bindVars(EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticEnv = env; + es.exprEnvs.insert(std::make_pair(this, env)); auto newEnv = std::make_shared(false, env.get(), attrs->attrs.size()); @@ -481,10 +482,10 @@ void ExprLet::bindVars(const EvalState & es, const std::shared_ptrbindVars(es, newEnv); } -void ExprWith::bindVars(const EvalState & es, const std::shared_ptr & env) +void ExprWith::bindVars(EvalState & es, const std::shared_ptr & 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_ptrbindVars(es, env); auto newEnv = std::make_shared(true, env.get()); body->bindVars(es, newEnv); } -void ExprIf::bindVars(const EvalState & es, const std::shared_ptr & env) +void ExprIf::bindVars(EvalState & es, const std::shared_ptr & 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 & env) +void ExprAssert::bindVars(EvalState & es, const std::shared_ptr & 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 & env) +void ExprOpNot::bindVars(EvalState & es, const std::shared_ptr & 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 & env) +void ExprConcatStrings::bindVars(EvalState & es, const std::shared_ptr & 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 & env) +void ExprPos::bindVars(EvalState & es, const std::shared_ptr & env) { if (debuggerHook) - staticEnv = env; + es.exprEnvs.insert(std::make_pair(this, env)); } -- cgit v1.2.3 From 7ddef73d026d79adc0c4f3fd1518d88d1331c38c Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Thu, 19 May 2022 12:44:40 -0600 Subject: de-const evalState exceptions --- src/libexpr/nixexpr.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libexpr/nixexpr.cc') diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index cb5e1c3f2..21b71d7c9 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -10,7 +10,7 @@ namespace nix { /* Launch the nix debugger */ -std::function debuggerHook; +std::function debuggerHook; /* Displaying abstract syntax trees. */ -- cgit v1.2.3 From 0600df86b8bc59633457f7ceb79e84c8ea3fed17 Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Thu, 19 May 2022 17:01:23 -0600 Subject: 'debugMode' --- src/libexpr/nixexpr.cc | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src/libexpr/nixexpr.cc') diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 21b71d7c9..b40791694 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -10,7 +10,7 @@ namespace nix { /* Launch the nix debugger */ -std::function debuggerHook; +// std::function debuggerHook; /* Displaying abstract syntax trees. */ @@ -303,31 +303,31 @@ void Expr::bindVars(EvalState & es, const std::shared_ptr & env void ExprInt::bindVars(EvalState & es, const std::shared_ptr & env) { - if (debuggerHook) + if (es.debugMode) es.exprEnvs.insert(std::make_pair(this, env)); } void ExprFloat::bindVars(EvalState & es, const std::shared_ptr & env) { - if (debuggerHook) + if (es.debugMode) es.exprEnvs.insert(std::make_pair(this, env)); } void ExprString::bindVars(EvalState & es, const std::shared_ptr & env) { - if (debuggerHook) + if (es.debugMode) es.exprEnvs.insert(std::make_pair(this, env)); } void ExprPath::bindVars(EvalState & es, const std::shared_ptr & env) { - if (debuggerHook) + if (es.debugMode) es.exprEnvs.insert(std::make_pair(this, env)); } void ExprVar::bindVars(EvalState & es, const std::shared_ptr & env) { - if (debuggerHook) + if (es.debugMode) es.exprEnvs.insert(std::make_pair(this, env)); /* Check whether the variable appears in the environment. If so, @@ -363,7 +363,7 @@ void ExprVar::bindVars(EvalState & es, const std::shared_ptr & void ExprSelect::bindVars(EvalState & es, const std::shared_ptr & env) { - if (debuggerHook) + if (es.debugMode) es.exprEnvs.insert(std::make_pair(this, env)); e->bindVars(es, env); @@ -375,7 +375,7 @@ void ExprSelect::bindVars(EvalState & es, const std::shared_ptr void ExprOpHasAttr::bindVars(EvalState & es, const std::shared_ptr & env) { - if (debuggerHook) + if (es.debugMode) es.exprEnvs.insert(std::make_pair(this, env)); e->bindVars(es, env); @@ -386,7 +386,7 @@ void ExprOpHasAttr::bindVars(EvalState & es, const std::shared_ptr & env) { - if (debuggerHook) + if (es.debugMode) es.exprEnvs.insert(std::make_pair(this, env)); if (recursive) { @@ -419,7 +419,7 @@ void ExprAttrs::bindVars(EvalState & es, const std::shared_ptr void ExprList::bindVars(EvalState & es, const std::shared_ptr & env) { - if (debuggerHook) + if (es.debugMode) es.exprEnvs.insert(std::make_pair(this, env)); for (auto & i : elems) @@ -428,7 +428,7 @@ void ExprList::bindVars(EvalState & es, const std::shared_ptr & void ExprLambda::bindVars(EvalState & es, const std::shared_ptr & env) { - if (debuggerHook) + if (es.debugMode) es.exprEnvs.insert(std::make_pair(this, env)); auto newEnv = std::make_shared( @@ -455,7 +455,7 @@ void ExprLambda::bindVars(EvalState & es, const std::shared_ptr void ExprCall::bindVars(EvalState & es, const std::shared_ptr & env) { - if (debuggerHook) + if (es.debugMode) es.exprEnvs.insert(std::make_pair(this, env)); fun->bindVars(es, env); @@ -465,7 +465,7 @@ void ExprCall::bindVars(EvalState & es, const std::shared_ptr & void ExprLet::bindVars(EvalState & es, const std::shared_ptr & env) { - if (debuggerHook) + if (es.debugMode) es.exprEnvs.insert(std::make_pair(this, env)); auto newEnv = std::make_shared(false, env.get(), attrs->attrs.size()); @@ -484,7 +484,7 @@ void ExprLet::bindVars(EvalState & es, const std::shared_ptr & void ExprWith::bindVars(EvalState & es, const std::shared_ptr & env) { - if (debuggerHook) + if (es.debugMode) es.exprEnvs.insert(std::make_pair(this, env)); /* Does this `with' have an enclosing `with'? If so, record its @@ -499,7 +499,7 @@ void ExprWith::bindVars(EvalState & es, const std::shared_ptr & break; } - if (debuggerHook) + if (es.debugMode) es.exprEnvs.insert(std::make_pair(this, env)); attrs->bindVars(es, env); @@ -509,7 +509,7 @@ void ExprWith::bindVars(EvalState & es, const std::shared_ptr & void ExprIf::bindVars(EvalState & es, const std::shared_ptr & env) { - if (debuggerHook) + if (es.debugMode) es.exprEnvs.insert(std::make_pair(this, env)); cond->bindVars(es, env); @@ -519,7 +519,7 @@ void ExprIf::bindVars(EvalState & es, const std::shared_ptr & e void ExprAssert::bindVars(EvalState & es, const std::shared_ptr & env) { - if (debuggerHook) + if (es.debugMode) es.exprEnvs.insert(std::make_pair(this, env)); cond->bindVars(es, env); @@ -528,7 +528,7 @@ void ExprAssert::bindVars(EvalState & es, const std::shared_ptr void ExprOpNot::bindVars(EvalState & es, const std::shared_ptr & env) { - if (debuggerHook) + if (es.debugMode) es.exprEnvs.insert(std::make_pair(this, env)); e->bindVars(es, env); @@ -536,7 +536,7 @@ void ExprOpNot::bindVars(EvalState & es, const std::shared_ptr void ExprConcatStrings::bindVars(EvalState & es, const std::shared_ptr & env) { - if (debuggerHook) + if (es.debugMode) es.exprEnvs.insert(std::make_pair(this, env)); for (auto & i : *this->es) @@ -545,7 +545,7 @@ void ExprConcatStrings::bindVars(EvalState & es, const std::shared_ptr & env) { - if (debuggerHook) + if (es.debugMode) es.exprEnvs.insert(std::make_pair(this, env)); } -- cgit v1.2.3 From 7ccb2700c0401c553631e07aeb49e08f976274a3 Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Sun, 22 May 2022 19:15:58 -0600 Subject: comments --- src/libexpr/nixexpr.cc | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/libexpr/nixexpr.cc') diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index b40791694..52d48122c 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -8,10 +8,6 @@ namespace nix { -/* Launch the nix debugger */ - -// std::function debuggerHook; - /* Displaying abstract syntax trees. */ static void showString(std::ostream & str, std::string_view s) -- cgit v1.2.3 From 13d02af0799f5d2f7a53825936d587e22edcacb6 Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Sun, 22 May 2022 21:45:24 -0600 Subject: remove redundant 'debugMode' flag --- src/libexpr/nixexpr.cc | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'src/libexpr/nixexpr.cc') diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 52d48122c..7c623a07d 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -299,31 +299,31 @@ void Expr::bindVars(EvalState & es, const std::shared_ptr & env void ExprInt::bindVars(EvalState & es, const std::shared_ptr & env) { - if (es.debugMode) + if (es.debugRepl) es.exprEnvs.insert(std::make_pair(this, env)); } void ExprFloat::bindVars(EvalState & es, const std::shared_ptr & env) { - if (es.debugMode) + if (es.debugRepl) es.exprEnvs.insert(std::make_pair(this, env)); } void ExprString::bindVars(EvalState & es, const std::shared_ptr & env) { - if (es.debugMode) + if (es.debugRepl) es.exprEnvs.insert(std::make_pair(this, env)); } void ExprPath::bindVars(EvalState & es, const std::shared_ptr & env) { - if (es.debugMode) + if (es.debugRepl) es.exprEnvs.insert(std::make_pair(this, env)); } void ExprVar::bindVars(EvalState & es, const std::shared_ptr & env) { - if (es.debugMode) + if (es.debugRepl) es.exprEnvs.insert(std::make_pair(this, env)); /* Check whether the variable appears in the environment. If so, @@ -359,7 +359,7 @@ void ExprVar::bindVars(EvalState & es, const std::shared_ptr & void ExprSelect::bindVars(EvalState & es, const std::shared_ptr & env) { - if (es.debugMode) + if (es.debugRepl) es.exprEnvs.insert(std::make_pair(this, env)); e->bindVars(es, env); @@ -371,7 +371,7 @@ void ExprSelect::bindVars(EvalState & es, const std::shared_ptr void ExprOpHasAttr::bindVars(EvalState & es, const std::shared_ptr & env) { - if (es.debugMode) + if (es.debugRepl) es.exprEnvs.insert(std::make_pair(this, env)); e->bindVars(es, env); @@ -382,7 +382,7 @@ void ExprOpHasAttr::bindVars(EvalState & es, const std::shared_ptr & env) { - if (es.debugMode) + if (es.debugRepl) es.exprEnvs.insert(std::make_pair(this, env)); if (recursive) { @@ -415,7 +415,7 @@ void ExprAttrs::bindVars(EvalState & es, const std::shared_ptr void ExprList::bindVars(EvalState & es, const std::shared_ptr & env) { - if (es.debugMode) + if (es.debugRepl) es.exprEnvs.insert(std::make_pair(this, env)); for (auto & i : elems) @@ -424,7 +424,7 @@ void ExprList::bindVars(EvalState & es, const std::shared_ptr & void ExprLambda::bindVars(EvalState & es, const std::shared_ptr & env) { - if (es.debugMode) + if (es.debugRepl) es.exprEnvs.insert(std::make_pair(this, env)); auto newEnv = std::make_shared( @@ -451,7 +451,7 @@ void ExprLambda::bindVars(EvalState & es, const std::shared_ptr void ExprCall::bindVars(EvalState & es, const std::shared_ptr & env) { - if (es.debugMode) + if (es.debugRepl) es.exprEnvs.insert(std::make_pair(this, env)); fun->bindVars(es, env); @@ -461,7 +461,7 @@ void ExprCall::bindVars(EvalState & es, const std::shared_ptr & void ExprLet::bindVars(EvalState & es, const std::shared_ptr & env) { - if (es.debugMode) + if (es.debugRepl) es.exprEnvs.insert(std::make_pair(this, env)); auto newEnv = std::make_shared(false, env.get(), attrs->attrs.size()); @@ -480,7 +480,7 @@ void ExprLet::bindVars(EvalState & es, const std::shared_ptr & void ExprWith::bindVars(EvalState & es, const std::shared_ptr & env) { - if (es.debugMode) + if (es.debugRepl) es.exprEnvs.insert(std::make_pair(this, env)); /* Does this `with' have an enclosing `with'? If so, record its @@ -495,7 +495,7 @@ void ExprWith::bindVars(EvalState & es, const std::shared_ptr & break; } - if (es.debugMode) + if (es.debugRepl) es.exprEnvs.insert(std::make_pair(this, env)); attrs->bindVars(es, env); @@ -505,7 +505,7 @@ void ExprWith::bindVars(EvalState & es, const std::shared_ptr & void ExprIf::bindVars(EvalState & es, const std::shared_ptr & env) { - if (es.debugMode) + if (es.debugRepl) es.exprEnvs.insert(std::make_pair(this, env)); cond->bindVars(es, env); @@ -515,7 +515,7 @@ void ExprIf::bindVars(EvalState & es, const std::shared_ptr & e void ExprAssert::bindVars(EvalState & es, const std::shared_ptr & env) { - if (es.debugMode) + if (es.debugRepl) es.exprEnvs.insert(std::make_pair(this, env)); cond->bindVars(es, env); @@ -524,7 +524,7 @@ void ExprAssert::bindVars(EvalState & es, const std::shared_ptr void ExprOpNot::bindVars(EvalState & es, const std::shared_ptr & env) { - if (es.debugMode) + if (es.debugRepl) es.exprEnvs.insert(std::make_pair(this, env)); e->bindVars(es, env); @@ -532,7 +532,7 @@ void ExprOpNot::bindVars(EvalState & es, const std::shared_ptr void ExprConcatStrings::bindVars(EvalState & es, const std::shared_ptr & env) { - if (es.debugMode) + if (es.debugRepl) es.exprEnvs.insert(std::make_pair(this, env)); for (auto & i : *this->es) @@ -541,7 +541,7 @@ void ExprConcatStrings::bindVars(EvalState & es, const std::shared_ptr & env) { - if (es.debugMode) + if (es.debugRepl) es.exprEnvs.insert(std::make_pair(this, env)); } -- cgit v1.2.3