storing staticenv bindings

This commit is contained in:
Ben Burdette 2021-10-02 13:47:36 -06:00
parent b9d08b98da
commit aad27143c6
3 changed files with 71 additions and 1 deletions

View file

@ -689,6 +689,29 @@ void printEnvBindings(const Env &env, int lv )
} }
} }
void printStaticEnvBindings(const StaticEnv &se, int lvl)
{
for (auto i = se.vars.begin(); i != se.vars.end(); ++i)
{
std::cout << lvl << i->first << std::endl;
}
if (se.up) {
printStaticEnvBindings(*se.up, ++lvl);
}
}
void printStaticEnvBindings(const Expr &expr)
{
// just print the names for now
if (expr.staticenv)
{
printStaticEnvBindings(*expr.staticenv.get(), 0);
}
}
void printEnvPosChain(const Env &env, int lv ) void printEnvPosChain(const Env &env, int lv )
{ {
std::cout << "printEnvPosChain " << lv << std::endl; std::cout << "printEnvPosChain " << lv << std::endl;

View file

@ -244,22 +244,33 @@ void Expr::bindVars(const std::shared_ptr<const StaticEnv> &env)
void ExprInt::bindVars(const std::shared_ptr<const StaticEnv> &env) void ExprInt::bindVars(const std::shared_ptr<const StaticEnv> &env)
{ {
if (debuggerHook)
staticenv = env;
} }
void ExprFloat::bindVars(const std::shared_ptr<const StaticEnv> &env) void ExprFloat::bindVars(const std::shared_ptr<const StaticEnv> &env)
{ {
if (debuggerHook)
staticenv = env;
} }
void ExprString::bindVars(const std::shared_ptr<const StaticEnv> &env) void ExprString::bindVars(const std::shared_ptr<const StaticEnv> &env)
{ {
if (debuggerHook)
staticenv = env;
} }
void ExprPath::bindVars(const std::shared_ptr<const StaticEnv> &env) void ExprPath::bindVars(const std::shared_ptr<const StaticEnv> &env)
{ {
if (debuggerHook)
staticenv = env;
} }
void ExprVar::bindVars(const std::shared_ptr<const StaticEnv> &env) void ExprVar::bindVars(const std::shared_ptr<const StaticEnv> &env)
{ {
if (debuggerHook)
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. */
@ -312,6 +323,9 @@ void ExprVar::bindVars(const std::shared_ptr<const StaticEnv> &env)
void ExprSelect::bindVars(const std::shared_ptr<const StaticEnv> &env) void ExprSelect::bindVars(const std::shared_ptr<const StaticEnv> &env)
{ {
if (debuggerHook)
staticenv = env;
e->bindVars(env); e->bindVars(env);
if (def) def->bindVars(env); if (def) def->bindVars(env);
for (auto & i : attrPath) for (auto & i : attrPath)
@ -321,6 +335,9 @@ void ExprSelect::bindVars(const std::shared_ptr<const StaticEnv> &env)
void ExprOpHasAttr::bindVars(const std::shared_ptr<const StaticEnv> &env) void ExprOpHasAttr::bindVars(const std::shared_ptr<const StaticEnv> &env)
{ {
if (debuggerHook)
staticenv = env;
e->bindVars(env); e->bindVars(env);
for (auto & i : attrPath) for (auto & i : attrPath)
if (!i.symbol.set()) if (!i.symbol.set())
@ -329,6 +346,9 @@ void ExprOpHasAttr::bindVars(const std::shared_ptr<const StaticEnv> &env)
void ExprAttrs::bindVars(const std::shared_ptr<const StaticEnv> &env) void ExprAttrs::bindVars(const std::shared_ptr<const StaticEnv> &env)
{ {
if (debuggerHook)
staticenv = env;
std::cout << "ExprAttrs::bindVars" << std::endl; std::cout << "ExprAttrs::bindVars" << std::endl;
// auto dynamicEnv(env); // auto dynamicEnv(env);
@ -369,12 +389,18 @@ void ExprAttrs::bindVars(const std::shared_ptr<const StaticEnv> &env)
void ExprList::bindVars(const std::shared_ptr<const StaticEnv> &env) void ExprList::bindVars(const std::shared_ptr<const StaticEnv> &env)
{ {
if (debuggerHook)
staticenv = env;
for (auto & i : elems) for (auto & i : elems)
i->bindVars(env); i->bindVars(env);
} }
void ExprLambda::bindVars(const std::shared_ptr<const StaticEnv> &env) void ExprLambda::bindVars(const std::shared_ptr<const StaticEnv> &env)
{ {
if (debuggerHook)
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())); // also make shared_ptr?
unsigned int displ = 0; unsigned int displ = 0;
@ -394,6 +420,9 @@ void ExprLambda::bindVars(const std::shared_ptr<const StaticEnv> &env)
void ExprLet::bindVars(const std::shared_ptr<const StaticEnv> &env) void ExprLet::bindVars(const std::shared_ptr<const StaticEnv> &env)
{ {
if (debuggerHook)
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())); // also make shared_ptr?
unsigned int displ = 0; unsigned int displ = 0;
@ -408,6 +437,9 @@ void ExprLet::bindVars(const std::shared_ptr<const StaticEnv> &env)
void ExprWith::bindVars(const std::shared_ptr<const StaticEnv> &env) void ExprWith::bindVars(const std::shared_ptr<const StaticEnv> &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 /* 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
@ -472,6 +504,9 @@ void ExprWith::bindVars(const StaticEnv & env)
void ExprIf::bindVars(const std::shared_ptr<const StaticEnv> &env) void ExprIf::bindVars(const std::shared_ptr<const StaticEnv> &env)
{ {
if (debuggerHook)
staticenv = env;
cond->bindVars(env); cond->bindVars(env);
then->bindVars(env); then->bindVars(env);
else_->bindVars(env); else_->bindVars(env);
@ -479,23 +514,35 @@ void ExprIf::bindVars(const std::shared_ptr<const StaticEnv> &env)
void ExprAssert::bindVars(const std::shared_ptr<const StaticEnv> &env) void ExprAssert::bindVars(const std::shared_ptr<const StaticEnv> &env)
{ {
if (debuggerHook)
staticenv = env;
cond->bindVars(env); cond->bindVars(env);
body->bindVars(env); body->bindVars(env);
} }
void ExprOpNot::bindVars(const std::shared_ptr<const StaticEnv> &env) void ExprOpNot::bindVars(const std::shared_ptr<const StaticEnv> &env)
{ {
if (debuggerHook)
staticenv = env;
e->bindVars(env); e->bindVars(env);
} }
void ExprConcatStrings::bindVars(const std::shared_ptr<const StaticEnv> &env) void ExprConcatStrings::bindVars(const std::shared_ptr<const StaticEnv> &env)
{ {
if (debuggerHook)
staticenv = env;
for (auto & i : *es) for (auto & i : *es)
i->bindVars(env); i->bindVars(env);
} }
void ExprPos::bindVars(const std::shared_ptr<const StaticEnv> &env) void ExprPos::bindVars(const std::shared_ptr<const StaticEnv> &env)
{ {
if (debuggerHook)
staticenv = env;
} }

View file

@ -85,7 +85,7 @@ struct Expr
virtual Value * maybeThunk(EvalState & state, Env & env); virtual Value * maybeThunk(EvalState & state, Env & env);
virtual void setName(Symbol & name); virtual void setName(Symbol & name);
std::shared_ptr<StaticEnv> staticenv; std::shared_ptr<const StaticEnv> staticenv;
}; };
std::ostream & operator << (std::ostream & str, const Expr & e); std::ostream & operator << (std::ostream & str, const Expr & e);