ignore-try flag

This commit is contained in:
Ben Burdette 2022-06-02 10:26:46 -06:00
parent 1892355766
commit 9151dbff88
5 changed files with 27 additions and 1 deletions

View file

@ -91,6 +91,12 @@ EvalCommand::EvalCommand()
.description = "start an interactive environment if evaluation fails", .description = "start an interactive environment if evaluation fails",
.handler = {&startReplOnEvalErrors, true}, .handler = {&startReplOnEvalErrors, true},
}); });
addFlag({
.longName = "ignore-try",
.description = "ignore exceptions in try clauses during debug",
.handler = {&ignoreExceptionsDuringTry, true},
});
} }
EvalCommand::~EvalCommand() EvalCommand::~EvalCommand()
@ -122,6 +128,9 @@ ref<EvalState> EvalCommand::getEvalState()
if (startReplOnEvalErrors) { if (startReplOnEvalErrors) {
evalState->debugRepl = &runRepl; evalState->debugRepl = &runRepl;
}; };
if (ignoreExceptionsDuringTry) {
evalState->ignoreTry = ignoreExceptionsDuringTry;
};
} }
return ref<EvalState>(evalState); return ref<EvalState>(evalState);
} }

View file

@ -58,6 +58,7 @@ struct CopyCommand : virtual StoreCommand
struct EvalCommand : virtual StoreCommand, MixEvalArgs struct EvalCommand : virtual StoreCommand, MixEvalArgs
{ {
bool startReplOnEvalErrors = false; bool startReplOnEvalErrors = false;
bool ignoreExceptionsDuringTry = false;
EvalCommand(); EvalCommand();

View file

@ -467,6 +467,7 @@ EvalState::EvalState(
, debugRepl(0) , debugRepl(0)
, debugStop(false) , debugStop(false)
, debugQuit(false) , debugQuit(false)
, ignoreTry(false)
, regexCache(makeRegexCache()) , regexCache(makeRegexCache())
#if HAVE_BOEHMGC #if HAVE_BOEHMGC
, valueAllocCache(std::allocate_shared<void *>(traceable_allocator<void *>(), nullptr)) , valueAllocCache(std::allocate_shared<void *>(traceable_allocator<void *>(), nullptr))

View file

@ -130,6 +130,7 @@ public:
void (* debugRepl)(ref<EvalState> es, const ValMap & extraEnv); void (* debugRepl)(ref<EvalState> es, const ValMap & extraEnv);
bool debugStop; bool debugStop;
bool debugQuit; bool debugQuit;
bool ignoreTry;
std::list<DebugTrace> debugTraces; std::list<DebugTrace> debugTraces;
std::map<const Expr*, const std::shared_ptr<const StaticEnv>> exprEnvs; std::map<const Expr*, const std::shared_ptr<const StaticEnv>> exprEnvs;
const std::shared_ptr<const StaticEnv> getStaticEnv(const Expr & expr) const const std::shared_ptr<const StaticEnv> getStaticEnv(const Expr & expr) const

View file

@ -851,6 +851,15 @@ static RegisterPrimOp primop_floor({
static void prim_tryEval(EvalState & state, const PosIdx pos, Value * * args, Value & v) static void prim_tryEval(EvalState & state, const PosIdx pos, Value * * args, Value & v)
{ {
auto attrs = state.buildBindings(2); auto attrs = state.buildBindings(2);
void (* savedDebugRepl)(ref<EvalState> es, const ValMap & extraEnv) = nullptr;
if (state.debugRepl && state.ignoreTry)
{
// to prevent starting the repl from exceptions withing a tryEval, null it.
savedDebugRepl = state.debugRepl;
state.debugRepl = nullptr;
}
try { try {
state.forceValue(*args[0], pos); state.forceValue(*args[0], pos);
attrs.insert(state.sValue, args[0]); attrs.insert(state.sValue, args[0]);
@ -859,6 +868,11 @@ static void prim_tryEval(EvalState & state, const PosIdx pos, Value * * args, Va
attrs.alloc(state.sValue).mkBool(false); attrs.alloc(state.sValue).mkBool(false);
attrs.alloc("success").mkBool(false); attrs.alloc("success").mkBool(false);
} }
// restore the debugRepl pointer if we saved it earlier.
if (savedDebugRepl)
state.debugRepl = savedDebugRepl;
v.mkAttrs(attrs); v.mkAttrs(attrs);
} }