forked from lix-project/lix
first whack at passing evalState as an arg to debuggerHook.
This commit is contained in:
parent
86ba0a702c
commit
667074b586
|
@ -119,13 +119,14 @@ ref<EvalState> EvalCommand::getEvalState()
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
if (startReplOnEvalErrors)
|
if (startReplOnEvalErrors)
|
||||||
debuggerHook = [evalState{ref<EvalState>(evalState)}](const Error * error, const Env & env, const Expr & expr) {
|
// debuggerHook = [evalState{ref<EvalState>(evalState)}](const Error * error, const Env & env, const Expr & expr) {
|
||||||
|
debuggerHook = [](const EvalState & evalState, const Error * error, const Env & env, const Expr & expr) {
|
||||||
auto dts =
|
auto dts =
|
||||||
error && expr.getPos()
|
error && expr.getPos()
|
||||||
? std::make_unique<DebugTraceStacker>(
|
? std::make_unique<DebugTraceStacker>(
|
||||||
*evalState,
|
evalState,
|
||||||
DebugTrace {
|
DebugTrace {
|
||||||
.pos = error->info().errPos ? *error->info().errPos : evalState->positions[expr.getPos()],
|
.pos = error->info().errPos ? *error->info().errPos : evalState.positions[expr.getPos()],
|
||||||
.expr = expr,
|
.expr = expr,
|
||||||
.env = env,
|
.env = env,
|
||||||
.hint = error->info().msg,
|
.hint = error->info().msg,
|
||||||
|
@ -137,8 +138,8 @@ ref<EvalState> EvalCommand::getEvalState()
|
||||||
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());
|
||||||
|
|
||||||
if (expr.staticEnv) {
|
if (expr.staticEnv) {
|
||||||
auto vm = mapStaticEnvBindings(evalState->symbols, *expr.staticEnv.get(), env);
|
auto vm = mapStaticEnvBindings(evalState.symbols, *expr.staticEnv.get(), env);
|
||||||
runRepl(evalState, *vm);
|
runRepl(*const_cast<EvalState*>(&evalState), *vm);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -274,7 +274,7 @@ void printClosureDiff(
|
||||||
|
|
||||||
|
|
||||||
void runRepl(
|
void runRepl(
|
||||||
ref<EvalState> evalState,
|
EvalState & evalState,
|
||||||
const ValMap & extraEnv);
|
const ValMap & extraEnv);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1011,7 +1011,7 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
|
||||||
}
|
}
|
||||||
|
|
||||||
void runRepl(
|
void runRepl(
|
||||||
ref<EvalState> evalState,
|
EvalState& evalState,
|
||||||
const ValMap & extraEnv)
|
const ValMap & extraEnv)
|
||||||
{
|
{
|
||||||
auto repl = std::make_unique<NixRepl>(evalState);
|
auto repl = std::make_unique<NixRepl>(evalState);
|
||||||
|
|
|
@ -1044,7 +1044,7 @@ DebugTraceStacker::DebugTraceStacker(EvalState & evalState, DebugTrace t)
|
||||||
{
|
{
|
||||||
evalState.debugTraces.push_front(trace);
|
evalState.debugTraces.push_front(trace);
|
||||||
if (evalState.debugStop && debuggerHook)
|
if (evalState.debugStop && debuggerHook)
|
||||||
debuggerHook(nullptr, trace.env, trace.expr);
|
debuggerHook(evalState, nullptr, trace.env, trace.expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::mkString(std::string_view s)
|
void Value::mkString(std::string_view s)
|
||||||
|
|
|
@ -136,7 +136,7 @@ public:
|
||||||
void debugThrow(const E &error, const Env & env, const Expr & expr) const
|
void debugThrow(const E &error, const Env & env, const Expr & expr) const
|
||||||
{
|
{
|
||||||
if (debuggerHook)
|
if (debuggerHook)
|
||||||
debuggerHook(&error, env, expr);
|
debuggerHook(*this, &error, env, expr);
|
||||||
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ public:
|
||||||
// DebugTrace stack.
|
// DebugTrace stack.
|
||||||
if (debuggerHook && !debugTraces.empty()) {
|
if (debuggerHook && !debugTraces.empty()) {
|
||||||
const DebugTrace & last = debugTraces.front();
|
const DebugTrace & last = debugTraces.front();
|
||||||
debuggerHook(&e, last.env, last.expr);
|
debuggerHook(*this, &e, last.env, last.expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace nix {
|
||||||
|
|
||||||
/* Launch the nix debugger */
|
/* Launch the nix debugger */
|
||||||
|
|
||||||
std::function<void(const Error * error, const Env & env, const Expr & expr)> debuggerHook;
|
std::function<void(const EvalState & evalState,const Error * error, const Env & env, const Expr & expr)> debuggerHook;
|
||||||
|
|
||||||
/* Displaying abstract syntax trees. */
|
/* Displaying abstract syntax trees. */
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ MakeError(UndefinedVarError, Error);
|
||||||
MakeError(MissingArgumentError, EvalError);
|
MakeError(MissingArgumentError, EvalError);
|
||||||
MakeError(RestrictedPathError, Error);
|
MakeError(RestrictedPathError, Error);
|
||||||
|
|
||||||
extern std::function<void(const Error * error, const Env & env, const Expr & expr)> debuggerHook;
|
extern std::function<void(const EvalState & evalState, const Error * error, const Env & env, const Expr & expr)> debuggerHook;
|
||||||
|
|
||||||
/* Position objects. */
|
/* Position objects. */
|
||||||
|
|
||||||
|
|
|
@ -765,7 +765,7 @@ static RegisterPrimOp primop_break({
|
||||||
});
|
});
|
||||||
|
|
||||||
auto & dt = state.debugTraces.front();
|
auto & dt = state.debugTraces.front();
|
||||||
debuggerHook(&error, dt.env, dt.expr);
|
debuggerHook(state, &error, dt.env, dt.expr);
|
||||||
|
|
||||||
if (state.debugQuit) {
|
if (state.debugQuit) {
|
||||||
// If the user elects to quit the repl, throw an exception.
|
// If the user elects to quit the repl, throw an exception.
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
/* A simple non-nullable reference-counted pointer. Actually a wrapper
|
/* A simple non-nullable reference-counted pointer. Actually a wrapper
|
||||||
around std::shared_ptr that prevents non-null constructions. */
|
around std::shared_ptr that prevents null constructions. */
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class ref
|
class ref
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue