forked from lix-project/lix
debugRepl ftn pointer
This commit is contained in:
parent
0600df86b8
commit
884d591787
|
@ -120,7 +120,34 @@ ref<EvalState> EvalCommand::getEvalState()
|
|||
;
|
||||
|
||||
evalState->debugMode = startReplOnEvalErrors;
|
||||
|
||||
// TODO move this somewhere else. Its only here to get the evalState ptr!
|
||||
if (startReplOnEvalErrors) {
|
||||
evalState->debugRepl = &runRepl;
|
||||
};
|
||||
// // debuggerHook = [evalState{ref<EvalState>(evalState)}](const Error * error, const Env & env, const Expr & expr) {
|
||||
// debuggerHook = [](EvalState & evalState, const Error * error, const Env & env, const Expr & expr) {
|
||||
// auto dts =
|
||||
// error && expr.getPos()
|
||||
// ? std::make_unique<DebugTraceStacker>(
|
||||
// evalState,
|
||||
// DebugTrace {
|
||||
// .pos = error->info().errPos ? *error->info().errPos : evalState.positions[expr.getPos()],
|
||||
// .expr = expr,
|
||||
// .env = env,
|
||||
// .hint = error->info().msg,
|
||||
// .isError = true
|
||||
// })
|
||||
// : nullptr;
|
||||
|
||||
// if (error)
|
||||
// printError("%s\n\n" ANSI_BOLD "Starting REPL to allow you to inspect the current state of the evaluator.\n" ANSI_NORMAL, error->what());
|
||||
|
||||
// auto se = evalState.getStaticEnv(expr);
|
||||
// if (se) {
|
||||
// auto vm = mapStaticEnvBindings(evalState.symbols, *se.get(), env);
|
||||
// runRepl(evalState, *vm);
|
||||
// }
|
||||
// if (startReplOnEvalErrors)
|
||||
|
||||
// // debuggerHook = [evalState{ref<EvalState>(evalState)}](const Error * error, const Env & env, const Expr & expr) {
|
||||
|
|
|
@ -463,7 +463,7 @@ EvalState::EvalState(
|
|||
, emptyBindings(0)
|
||||
, store(store)
|
||||
, buildStore(buildStore ? buildStore : store)
|
||||
, debugMode(false)
|
||||
, debugRepl(0)
|
||||
, debugStop(false)
|
||||
, debugQuit(false)
|
||||
, regexCache(makeRegexCache())
|
||||
|
@ -811,8 +811,12 @@ std::unique_ptr<ValMap> mapStaticEnvBindings(const SymbolTable & st, const Stati
|
|||
return vm;
|
||||
}
|
||||
|
||||
void EvalState::debugRepl(const Error * error, const Env & env, const Expr & expr)
|
||||
void EvalState::runDebugRepl(const Error * error, const Env & env, const Expr & expr)
|
||||
{
|
||||
// double check we've got the debugRepl ftn pointer.
|
||||
if (!debugRepl)
|
||||
return;
|
||||
|
||||
auto dts =
|
||||
error && expr.getPos()
|
||||
? std::make_unique<DebugTraceStacker>(
|
||||
|
@ -832,7 +836,7 @@ void EvalState::debugRepl(const Error * error, const Env & env, const Expr & exp
|
|||
auto se = getStaticEnv(expr);
|
||||
if (se) {
|
||||
auto vm = mapStaticEnvBindings(symbols, *se.get(), env);
|
||||
runRepl(*this, *vm);
|
||||
(debugRepl)(*this, *vm);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1070,7 +1074,7 @@ DebugTraceStacker::DebugTraceStacker(EvalState & evalState, DebugTrace t)
|
|||
{
|
||||
evalState.debugTraces.push_front(trace);
|
||||
if (evalState.debugStop && evalState.debugMode)
|
||||
evalState.debugRepl(nullptr, trace.env, trace.expr);
|
||||
evalState.runDebugRepl(nullptr, trace.env, trace.expr);
|
||||
}
|
||||
|
||||
void Value::mkString(std::string_view s)
|
||||
|
|
|
@ -48,8 +48,6 @@ struct Env
|
|||
Value * values[0];
|
||||
};
|
||||
|
||||
extern void runRepl(ref<EvalState> evalState, const ValMap & extraEnv);
|
||||
|
||||
void printEnvBindings(const EvalState &es, const Expr & expr, const Env & env);
|
||||
void printEnvBindings(const SymbolTable & st, const StaticEnv & se, const Env & env, int lvl = 0);
|
||||
|
||||
|
@ -129,6 +127,8 @@ public:
|
|||
RootValue vImportedDrvToDerivation = nullptr;
|
||||
|
||||
/* Debugger */
|
||||
void (* debugRepl)(EvalState & es, const ValMap & extraEnv);
|
||||
|
||||
bool debugMode;
|
||||
bool debugStop;
|
||||
bool debugQuit;
|
||||
|
@ -143,14 +143,14 @@ public:
|
|||
return std::shared_ptr<const StaticEnv>();;
|
||||
}
|
||||
|
||||
void debugRepl(const Error * error, const Env & env, const Expr & expr);
|
||||
void runDebugRepl(const Error * error, const Env & env, const Expr & expr);
|
||||
|
||||
template<class E>
|
||||
[[gnu::noinline, gnu::noreturn]]
|
||||
void debugThrow(const E &error, const Env & env, const Expr & expr)
|
||||
{
|
||||
if (debugMode)
|
||||
debugRepl(&error, env, expr);
|
||||
runDebugRepl(&error, env, expr);
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ public:
|
|||
// DebugTrace stack.
|
||||
if (debugMode && !debugTraces.empty()) {
|
||||
const DebugTrace & last = debugTraces.front();
|
||||
debugRepl(&e, last.env, last.expr);
|
||||
runDebugRepl(&e, last.env, last.expr);
|
||||
}
|
||||
|
||||
throw e;
|
||||
|
|
|
@ -765,7 +765,7 @@ static RegisterPrimOp primop_break({
|
|||
});
|
||||
|
||||
auto & dt = state.debugTraces.front();
|
||||
state.debugRepl(&error, dt.env, dt.expr);
|
||||
state.runDebugRepl(&error, dt.env, dt.expr);
|
||||
|
||||
if (state.debugQuit) {
|
||||
// If the user elects to quit the repl, throw an exception.
|
||||
|
|
Loading…
Reference in a new issue