remove more explicit valmap code

This commit is contained in:
Ben Burdette 2021-08-25 13:18:27 -06:00
parent d8a977a22e
commit 310c689d31
2 changed files with 47 additions and 102 deletions

View file

@ -630,43 +630,43 @@ std::optional<EvalState::Doc> EvalState::getDoc(Value & v)
} }
*/ */
LocalNoInline(valmap * map0()) // LocalNoInline(valmap * map0())
{ // {
return new valmap(); // return new valmap();
} // }
LocalNoInline(valmap * map1(const char *name, Value *v)) // LocalNoInline(valmap * map1(const char *name, Value *v))
{ // {
return new valmap({{name, v}}); // return new valmap({{name, v}});
} // }
LocalNoInline(valmap * map2(const char *name1, Value *v1, const char *name2, Value *v2)) // LocalNoInline(valmap * map2(const char *name1, Value *v1, const char *name2, Value *v2))
{ // {
return new valmap({{name1, v1}, {name2, v2}}); // return new valmap({{name1, v1}, {name2, v2}});
} // }
LocalNoInline(valmap * mapBindings(Bindings &b)) // LocalNoInline(valmap * mapBindings(Bindings &b))
{ // {
auto map = new valmap(); // auto map = new valmap();
for (auto i = b.begin(); i != b.end(); ++i) // for (auto i = b.begin(); i != b.end(); ++i)
{ // {
std::string s = i->name; // std::string s = i->name;
(*map)[s] = i->value; // (*map)[s] = i->value;
} // }
return map; // return map;
} // }
LocalNoInline(void addBindings(string prefix, Bindings &b, valmap &valmap)) // LocalNoInline(void addBindings(string prefix, Bindings &b, valmap &valmap))
{ // {
for (auto i = b.begin(); i != b.end(); ++i) // for (auto i = b.begin(); i != b.end(); ++i)
{ // {
std::string s = prefix; // std::string s = prefix;
s += i->name; // s += i->name;
valmap[s] = i->value; // valmap[s] = i->value;
} // }
} // }
void printEnvBindings(const Env &env, int lv ) void printEnvBindings(const Env &env, int lv )
@ -698,6 +698,7 @@ void mapEnvBindings(const Env &env, valmap & vm)
} }
// merge - and write over - higher level bindings. // merge - and write over - higher level bindings.
// note; skipping HasWithExpr that haven't been evaled yet.
if (env.values[0]->type() == nAttrs) { if (env.values[0]->type() == nAttrs) {
auto map = valmap(); auto map = valmap();
@ -716,18 +717,7 @@ valmap * mapEnvBindings(const Env &env)
{ {
auto vm = new valmap(); auto vm = new valmap();
// segfault!
std::cout << "before mapenv" << std::endl;
if (env.valuemap) {
std::cout << "valuemap" << std::endl;
std::cout << "mapenv count" << env.valuemap->size() << std::endl;
} else
{
std::cout << "novaluemap" << std::endl;
}
mapEnvBindings(env, *vm); mapEnvBindings(env, *vm);
std::cout << "after mapenv" << std::endl;
return vm; return vm;
} }
@ -1270,11 +1260,6 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v)
v.attrs->push_back(Attr(i.first, vAttr, &i.second.pos)); v.attrs->push_back(Attr(i.first, vAttr, &i.second.pos));
} }
// TODO; deal with the below overrides or whatever
if (debuggerHook) {
env2.valuemap.reset(mapBindings(*v.attrs));
}
/* If the rec contains an attribute called `__overrides', then /* If the rec contains an attribute called `__overrides', then
evaluate it, and add the attributes in that set to the rec. evaluate it, and add the attributes in that set to the rec.
This allows overriding of recursive attributes, which is This allows overriding of recursive attributes, which is
@ -1345,18 +1330,6 @@ void ExprLet::eval(EvalState & state, Env & env, Value & v)
for (auto & i : attrs->attrs) for (auto & i : attrs->attrs)
env2.values[displ++] = i.second.e->maybeThunk(state, i.second.inherited ? env : env2); env2.values[displ++] = i.second.e->maybeThunk(state, i.second.inherited ? env : env2);
if (debuggerHook) {
auto map = new valmap();
displ = 0;
for (auto & i : attrs->attrs)
{
// std::string s = i->name;
(*map)[i.first] = env2.values[displ++];
}
env2.valuemap.reset(map);
}
body->eval(state, env2, v); body->eval(state, env2, v);
} }
@ -1579,7 +1552,6 @@ void EvalState::callFunction(Value & fun, Value & arg, Value & v, const Pos & po
there is no matching actual argument but the formal there is no matching actual argument but the formal
argument has a default, use the default. */ argument has a default, use the default. */
size_t attrsUsed = 0; size_t attrsUsed = 0;
if (debuggerHook) {
for (auto & i : lambda.formals->formals) { for (auto & i : lambda.formals->formals) {
Bindings::iterator j = arg.attrs->find(i.name); Bindings::iterator j = arg.attrs->find(i.name);
if (j == arg.attrs->end()) { if (j == arg.attrs->end()) {
@ -1597,33 +1569,7 @@ void EvalState::callFunction(Value & fun, Value & arg, Value & v, const Pos & po
env2.values[displ++] = j->value; env2.values[displ++] = j->value;
} }
} }
}
else {
auto map = new valmap();
for (auto & i : lambda.formals->formals) {
Bindings::iterator j = arg.attrs->find(i.name);
if (j == arg.attrs->end()) {
if (!i.def)
throwTypeError(
pos,
"%1% called without required argument '%2%'",
lambda,
i.name,
*fun.lambda.env);
// map2("fun", &fun, "arg", &arg));
env2.values[displ++] = i.def->maybeThunk(*this, env2);
} else {
attrsUsed++;
env2.values[displ++] = j->value;
// add to debugger name-value map
std::string s = i.name;
(*map)[s] = j->value;
}
}
env2.valuemap.reset(map);
}
/* Check that each actual argument is listed as a formal /* Check that each actual argument is listed as a formal
argument (unless the attribute match specifies a `...'). */ argument (unless the attribute match specifies a `...'). */

View file

@ -40,7 +40,6 @@ struct Env
Env * up; Env * up;
unsigned short prevWith:14; // nr of levels up to next `with' environment unsigned short prevWith:14; // nr of levels up to next `with' environment
enum { Plain = 0, HasWithExpr, HasWithAttrs } type:2; enum { Plain = 0, HasWithExpr, HasWithAttrs } type:2;
std::unique_ptr<valmap> valuemap; // TODO: rename
Value * values[0]; Value * values[0];
}; };