forked from lix-project/lix
moving towards env in exceptions
This commit is contained in:
parent
030271184f
commit
b6eb38016b
|
@ -105,7 +105,7 @@ ref<EvalState> EvalCommand::getEvalState()
|
||||||
if (!evalState) {
|
if (!evalState) {
|
||||||
evalState = std::make_shared<EvalState>(searchPath, getStore());
|
evalState = std::make_shared<EvalState>(searchPath, getStore());
|
||||||
if (startReplOnEvalErrors)
|
if (startReplOnEvalErrors)
|
||||||
debuggerHook = [evalState{ref<EvalState>(evalState)}](const Error & error, const std::map<std::string, Value *> & env) {
|
debuggerHook = [evalState{ref<EvalState>(evalState)}](const Error & error, const Env & env) {
|
||||||
printError("%s\n\n" ANSI_BOLD "Starting REPL to allow you to inspect the current state of the evaluator.\n" ANSI_NORMAL, error.what());
|
printError("%s\n\n" ANSI_BOLD "Starting REPL to allow you to inspect the current state of the evaluator.\n" ANSI_NORMAL, error.what());
|
||||||
runRepl(evalState, env);
|
runRepl(evalState, env);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1172,11 +1172,6 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v)
|
||||||
env2.up = &env;
|
env2.up = &env;
|
||||||
dynamicEnv = &env2;
|
dynamicEnv = &env2;
|
||||||
|
|
||||||
// TODO; deal with the below overrides or whatever
|
|
||||||
if (debuggerHook) {
|
|
||||||
env2.valuemap = mapBindings(attrs);
|
|
||||||
}
|
|
||||||
|
|
||||||
AttrDefs::iterator overrides = attrs.find(state.sOverrides);
|
AttrDefs::iterator overrides = attrs.find(state.sOverrides);
|
||||||
bool hasOverrides = overrides != attrs.end();
|
bool hasOverrides = overrides != attrs.end();
|
||||||
|
|
||||||
|
@ -1195,6 +1190,11 @@ 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
|
||||||
|
@ -1258,9 +1258,6 @@ void ExprLet::eval(EvalState & state, Env & env, Value & v)
|
||||||
Env & env2(state.allocEnv(attrs->attrs.size()));
|
Env & env2(state.allocEnv(attrs->attrs.size()));
|
||||||
env2.up = &env;
|
env2.up = &env;
|
||||||
|
|
||||||
if (debuggerHook) {
|
|
||||||
env2.valuemap = mapBindings(attrs);
|
|
||||||
}
|
|
||||||
/* The recursive attributes are evaluated in the new environment,
|
/* The recursive attributes are evaluated in the new environment,
|
||||||
while the inherited attributes are evaluated in the original
|
while the inherited attributes are evaluated in the original
|
||||||
environment. */
|
environment. */
|
||||||
|
@ -1268,6 +1265,18 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1460,6 +1469,7 @@ void EvalState::callFunction(Value & fun, Value & arg, Value & v, const Pos & po
|
||||||
pos,
|
pos,
|
||||||
"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(),
|
||||||
|
// fun.env);
|
||||||
map2("fun", &fun, "arg", &arg));
|
map2("fun", &fun, "arg", &arg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1498,7 +1508,8 @@ void EvalState::callFunction(Value & fun, Value & arg, Value & v, const Pos & po
|
||||||
"%1% called without required argument '%2%'",
|
"%1% called without required argument '%2%'",
|
||||||
lambda,
|
lambda,
|
||||||
i.name,
|
i.name,
|
||||||
map2("fun", &fun, "arg", &arg));
|
fun.lambda.env);
|
||||||
|
// map2("fun", &fun, "arg", &arg));
|
||||||
env2.values[displ++] = i.def->maybeThunk(*this, env2);
|
env2.values[displ++] = i.def->maybeThunk(*this, env2);
|
||||||
} else {
|
} else {
|
||||||
attrsUsed++;
|
attrsUsed++;
|
||||||
|
@ -1519,18 +1530,19 @@ void EvalState::callFunction(Value & fun, Value & arg, Value & v, const Pos & po
|
||||||
"%1% called without required argument '%2%'",
|
"%1% called without required argument '%2%'",
|
||||||
lambda,
|
lambda,
|
||||||
i.name,
|
i.name,
|
||||||
map2("fun", &fun, "arg", &arg));
|
fun.env);
|
||||||
|
// map2("fun", &fun, "arg", &arg));
|
||||||
env2.values[displ++] = i.def->maybeThunk(*this, env2);
|
env2.values[displ++] = i.def->maybeThunk(*this, env2);
|
||||||
} else {
|
} else {
|
||||||
attrsUsed++;
|
attrsUsed++;
|
||||||
env2.values[displ++] = j->value;
|
env2.values[displ++] = j->value;
|
||||||
|
|
||||||
// add to debugger name-value map
|
// add to debugger name-value map
|
||||||
std::string s = i->name;
|
std::string s = i.name;
|
||||||
(*map)[s] = i->value;
|
(*map)[s] = i.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
env2.valuemap = map;
|
env2.valuemap.reset(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check that each actual argument is listed as a formal
|
/* Check that each actual argument is listed as a formal
|
||||||
|
@ -1544,7 +1556,8 @@ void EvalState::callFunction(Value & fun, Value & arg, Value & v, const Pos & po
|
||||||
"%1% called with unexpected argument '%2%'",
|
"%1% called with unexpected argument '%2%'",
|
||||||
lambda,
|
lambda,
|
||||||
i.name,
|
i.name,
|
||||||
map2("fun", &fun, "arg", &arg));
|
fun.env);
|
||||||
|
// map2("fun", &fun, "arg", &arg));
|
||||||
abort(); // can't happen
|
abort(); // can't happen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1621,7 +1634,7 @@ this case it must have its arguments supplied either by default
|
||||||
values, or passed explicitly with '--arg' or '--argstr'. See
|
values, or passed explicitly with '--arg' or '--argstr'. See
|
||||||
https://nixos.org/manual/nix/stable/#ss-functions.)",
|
https://nixos.org/manual/nix/stable/#ss-functions.)",
|
||||||
i.name,
|
i.name,
|
||||||
fun.lambda.env);
|
*fun.lambda.env);
|
||||||
// mapBindings(args));
|
// mapBindings(args));
|
||||||
// map1("fun", &fun)); // todo add bindings + fun
|
// map1("fun", &fun)); // todo add bindings + fun
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue