more code cleanup

This commit is contained in:
Ben Burdette 2021-10-22 14:49:58 -06:00
parent 71da988d47
commit fb8377547b
3 changed files with 33 additions and 108 deletions

View file

@ -912,6 +912,9 @@ Env & EvalState::allocEnv(size_t size)
nrValuesInEnvs += size; nrValuesInEnvs += size;
Env * env = (Env *) allocBytes(sizeof(Env) + size * sizeof(Value *)); Env * env = (Env *) allocBytes(sizeof(Env) + size * sizeof(Value *));
env->type = Env::Plain; env->type = Env::Plain;
/* We assume that env->values has been cleared by the allocator; maybeThunk() and lookupVar fromWith expect this. */
return *env; return *env;
} }
@ -925,7 +928,6 @@ Env & fakeEnv(size_t size)
return *env; return *env;
} }
void EvalState::mkList(Value & v, size_t size) void EvalState::mkList(Value & v, size_t size)
{ {
v.mkList(size); v.mkList(size);
@ -1291,7 +1293,6 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v)
state.forceAttrs(*vAttrs, pos); state.forceAttrs(*vAttrs, pos);
if ((j = vAttrs->attrs->find(name)) == vAttrs->attrs->end()) if ((j = vAttrs->attrs->find(name)) == vAttrs->attrs->end())
throwEvalError(pos, "attribute '%1%' missing", name, env, this); throwEvalError(pos, "attribute '%1%' missing", name, env, this);
// mapBindings(*vAttrs->attrs));
} }
vAttrs = j->value; vAttrs = j->value;
pos2 = j->pos; pos2 = j->pos;
@ -1419,8 +1420,6 @@ void EvalState::callFunction(Value & fun, Value & arg, Value & v, const Pos & po
"attempt to call something which is not a function but %1%", "attempt to call something which is not a function but %1%",
showType(fun).c_str(), showType(fun).c_str(),
fakeEnv(1), 0); fakeEnv(1), 0);
// fun.env);
// map2("fun", &fun, "arg", &arg));
} }
ExprLambda & lambda(*fun.lambda.fun); ExprLambda & lambda(*fun.lambda.fun);

View file

@ -273,20 +273,6 @@ void ExprVar::bindVars(const std::shared_ptr<const StaticEnv> &env)
/* Check whether the variable appears in the environment. If so, /* Check whether the variable appears in the environment. If so,
set its level and displacement. */ 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; const StaticEnv * curEnv;
unsigned int level; unsigned int level;
int withLevel = -1; int withLevel = -1;
@ -304,7 +290,6 @@ void ExprVar::bindVars(const std::shared_ptr<const StaticEnv> &env)
} }
} }
/* Otherwise, the variable must be obtained from the nearest /* Otherwise, the variable must be obtained from the nearest
enclosing `with'. If there is no `with', then we can issue an enclosing `with'. If there is no `with', then we can issue an
"undefined variable" error now. */ "undefined variable" error now. */
@ -319,7 +304,6 @@ void ExprVar::bindVars(const std::shared_ptr<const StaticEnv> &env)
fromWith = true; fromWith = true;
this->level = withLevel; this->level = withLevel;
} }
}
void ExprSelect::bindVars(const std::shared_ptr<const StaticEnv> &env) void ExprSelect::bindVars(const std::shared_ptr<const StaticEnv> &env)
{ {
@ -349,18 +333,11 @@ void ExprAttrs::bindVars(const std::shared_ptr<const StaticEnv> &env)
if (debuggerHook) if (debuggerHook)
staticenv = env; staticenv = env;
// std::cout << "ExprAttrs::bindVars" << std::endl;
// auto dynamicEnv(env);
if (recursive) { if (recursive) {
// std::cout << "recursive" << std::endl;
// dynamicEnv = newEnv.get();
// also make shared_ptr?
auto newEnv = std::shared_ptr<StaticEnv>(new StaticEnv(false, env.get())); auto newEnv = std::shared_ptr<StaticEnv>(new StaticEnv(false, env.get()));
unsigned int displ = 0; 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++; newEnv->vars[i.first] = i.second.displ = displ++;
} }
@ -373,7 +350,6 @@ void ExprAttrs::bindVars(const std::shared_ptr<const StaticEnv> &env)
} }
} }
else { else {
// std::cout << "NOT recursive" << std::endl;
for (auto & i : attrs) for (auto & i : attrs)
i.second.e->bindVars(env); i.second.e->bindVars(env);
@ -382,9 +358,6 @@ void ExprAttrs::bindVars(const std::shared_ptr<const StaticEnv> &env)
i.valueExpr->bindVars(env); i.valueExpr->bindVars(env);
} }
} }
// std::cout << "ExprAttrs::bindVars end" << std::endl;
} }
void ExprList::bindVars(const std::shared_ptr<const StaticEnv> &env) void ExprList::bindVars(const std::shared_ptr<const StaticEnv> &env)
@ -401,7 +374,7 @@ void ExprLambda::bindVars(const std::shared_ptr<const StaticEnv> &env)
if (debuggerHook) if (debuggerHook)
staticenv = env; staticenv = env;
auto newEnv = std::shared_ptr<StaticEnv>(new StaticEnv(false, env.get())); // also make shared_ptr? auto newEnv = std::shared_ptr<StaticEnv>(new StaticEnv(false, env.get()));
unsigned int displ = 0; unsigned int displ = 0;
@ -423,7 +396,7 @@ void ExprLet::bindVars(const std::shared_ptr<const StaticEnv> &env)
if (debuggerHook) if (debuggerHook)
staticenv = env; staticenv = env;
auto newEnv = std::shared_ptr<StaticEnv>(new StaticEnv(false, env.get())); // also make shared_ptr? auto newEnv = std::shared_ptr<StaticEnv>(new StaticEnv(false, env.get()));
unsigned int displ = 0; unsigned int displ = 0;
for (auto & i : attrs->attrs) for (auto & i : attrs->attrs)
@ -440,7 +413,6 @@ void ExprWith::bindVars(const std::shared_ptr<const StaticEnv> &env)
if (debuggerHook) if (debuggerHook)
staticenv = env; staticenv = env;
// std::cout << " ExprWith::bindVars " << std::endl;
/* Does this `with' have an enclosing `with'? If so, record its /* Does this `with' have an enclosing `with'? If so, record its
level so that `lookupVar' can look up variables in the previous level so that `lookupVar' can look up variables in the previous
`with' if this one doesn't contain the desired attribute. */ `with' if this one doesn't contain the desired attribute. */
@ -453,54 +425,10 @@ void ExprWith::bindVars(const std::shared_ptr<const StaticEnv> &env)
break; break;
} }
// std::cout << " ExprWith::bindVars 1" << std::endl;
// attrs->show(std::cout);
// std::cout << std::endl;
attrs->bindVars(env); attrs->bindVars(env);
auto newEnv = std::shared_ptr<StaticEnv>(new StaticEnv(true, env.get())); // also make shared_ptr? auto newEnv = std::shared_ptr<StaticEnv>(new StaticEnv(true, env.get()));
// 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;
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); body->bindVars(newEnv);
} }
*/
void ExprIf::bindVars(const std::shared_ptr<const StaticEnv> &env) void ExprIf::bindVars(const std::shared_ptr<const StaticEnv> &env)
{ {

View file

@ -22,8 +22,6 @@
#include "eval.hh" #include "eval.hh"
#include "globals.hh" #include "globals.hh"
#include <iostream>
namespace nix { namespace nix {
struct ParseData struct ParseData