load debug trace staticenv on 'show'

This commit is contained in:
Ben Burdette 2022-03-28 15:28:59 -06:00
parent 14f515544b
commit 5ab7bdf0b1

View file

@ -78,6 +78,7 @@ struct NixRepl
void addVarToScope(const Symbol & name, Value & v); void addVarToScope(const Symbol & name, Value & v);
Expr * parseString(string s); Expr * parseString(string s);
void evalString(string s, Value & v); void evalString(string s, Value & v);
void loadDebugTraceEnv(DebugTrace &dt);
typedef set<Value *> ValuesSeen; typedef set<Value *> ValuesSeen;
std::ostream & printValue(std::ostream & str, Value & v, unsigned int maxDepth); std::ostream & printValue(std::ostream & str, Value & v, unsigned int maxDepth);
@ -427,6 +428,25 @@ std::ostream& showDebugTrace(std::ostream &out, const DebugTrace &dt)
return out; return out;
} }
void NixRepl::loadDebugTraceEnv(DebugTrace &dt)
{
if (dt.expr.staticenv)
{
initEnv();
auto vm = std::make_unique<valmap>(*(mapStaticEnvBindings(*dt.expr.staticenv.get(), dt.env)));
// add staticenv vars.
for (auto & [name, value] : *(vm.get())) {
this->addVarToScope(this->state->symbols.create(name), *value);
}
}
else
{
initEnv();
}
}
bool NixRepl::processLine(string line) bool NixRepl::processLine(string line)
{ {
if (line == "") return true; if (line == "") return true;
@ -491,31 +511,18 @@ bool NixRepl::processLine(string line)
++iter, ++idx) { ++iter, ++idx) {
if (idx == this->debugTraceIndex) if (idx == this->debugTraceIndex)
{ {
// std::cout << "\n" << ANSI_BLUE << idx << ANSI_NORMAL << ": ";
printStaticEnvBindings(iter->expr); printStaticEnvBindings(iter->expr);
break; break;
} }
// std::cout << "\n" << ANSI_BLUE << idx << ANSI_NORMAL << ": ";
// showDebugTrace(std::cout, *iter);
} }
// auto iter = this->state->debugTraces.begin();
// if (iter != this->state->debugTraces.end()) {
// printStaticEnvBindings(iter->expr);
// }
} }
else if (arg.compare(0,4,"show") == 0) { else if (arg.compare(0,4,"show") == 0) {
try { try {
// change the DebugTrace index. // change the DebugTrace index.
debugTraceIndex = stoi(arg.substr(4)); debugTraceIndex = stoi(arg.substr(4));
// std::cout << "idx: " << idx << std::endl;
// debugTraceIndex = idx;
} }
catch (...) catch (...)
{ {
debugTraceIndex = 0;
} }
int idx = 0; int idx = 0;
@ -526,6 +533,8 @@ bool NixRepl::processLine(string line)
{ {
std::cout << "\n" << ANSI_BLUE << idx << ANSI_NORMAL << ": "; std::cout << "\n" << ANSI_BLUE << idx << ANSI_NORMAL << ": ";
showDebugTrace(std::cout, *iter); showDebugTrace(std::cout, *iter);
printStaticEnvBindings(iter->expr);
loadDebugTraceEnv(*iter);
break; break;
} }
// std::cout << "\n" << ANSI_BLUE << idx << ANSI_NORMAL << ": "; // std::cout << "\n" << ANSI_BLUE << idx << ANSI_NORMAL << ": ";