env to bindings

This commit is contained in:
Ben Burdette 2021-08-18 21:25:26 -06:00
parent 2272021536
commit 4b5f9b35f0
3 changed files with 28 additions and 3 deletions

View file

@ -99,6 +99,8 @@ EvalCommand::EvalCommand()
// extern std::function<void(const Error & error, const std::map<std::string, Value *> & env)> debuggerHook;
extern std::function<void(const Error & error, const Env & env)> debuggerHook;
ref<EvalState> EvalCommand::getEvalState()
{
std::cout << " EvalCommand::getEvalState()" << startReplOnEvalErrors << std::endl;
@ -107,7 +109,8 @@ ref<EvalState> EvalCommand::getEvalState()
if (startReplOnEvalErrors)
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());
runRepl(evalState, env);
auto vm = mapEnvBindings(env);
runRepl(evalState, *vm);
};
}
return ref<EvalState>(evalState);

View file

@ -668,6 +668,28 @@ LocalNoInline(void addBindings(string prefix, Bindings &b, valmap &valmap))
}
}
void mapEnvBindings(const Env &env, valmap & vm)
{
// add bindings for the next level up first.
if (env.up) {
mapEnvBindings(*env.up, vm);
}
// merge - and write over - higher level bindings.
vm.merge(*env.valuemap);
}
valmap * mapEnvBindings(const Env &env)
{
auto vm = new valmap();
mapEnvBindings(env, *vm);
return vm;
}
// LocalNoInline(valmap * mapEnvBindings(Env &env))
// {
// // NOT going to use this
@ -1508,8 +1530,8 @@ void EvalState::callFunction(Value & fun, Value & arg, Value & v, const Pos & po
/* For each formal argument, get the actual argument. If
there is no matching actual argument but the formal
argument has a default, use the default. */
size_t attrsUsed = 0;
if (debuggerHook) {
size_t attrsUsed = 0;
for (auto & i : lambda.formals->formals) {
Bindings::iterator j = arg.attrs->find(i.name);
if (j == arg.attrs->end()) {
@ -1531,7 +1553,6 @@ void EvalState::callFunction(Value & fun, Value & arg, Value & v, const Pos & po
else {
auto map = new valmap();
size_t attrsUsed = 0;
for (auto & i : lambda.formals->formals) {
Bindings::iterator j = arg.attrs->find(i.name);
if (j == arg.attrs->end()) {

View file

@ -44,6 +44,7 @@ struct Env
Value * values[0];
};
valmap * mapEnvBindings(const Env &env);
Value & mkString(Value & v, std::string_view s, const PathSet & context = PathSet());