template-ize debugThrow

This commit is contained in:
Ben Burdette 2022-05-12 13:59:58 -06:00
parent 2c9fafdc9e
commit 1ea13084c9
2 changed files with 22 additions and 26 deletions

View file

@ -802,30 +802,6 @@ std::unique_ptr<ValMap> mapStaticEnvBindings(const SymbolTable & st, const Stati
return vm;
}
void EvalState::debugThrowLastTrace(Error & e) const
{
std::cout << "debugThrowLastTrace(Error & e) const" << (debuggerHook == nullptr) << std::endl;
// Call this in the situation where Expr and Env are inaccessible.
// The debugger will start in the last context that's in the
// DebugTrace stack.
if (debuggerHook && !debugTraces.empty()) {
const DebugTrace & last = debugTraces.front();
debuggerHook(&e, last.env, last.expr);
}
throw e;
}
void EvalState::debugThrow(const Error &error, const Env & env, const Expr & expr) const
{
std::cout << "debugThrow" << (debuggerHook == nullptr) << std::endl;
if (debuggerHook)
debuggerHook(&error, env, expr);
throw error;
}
/* Every "format" object (even temporary) takes up a few hundred bytes
of stack space, which is a real killer in the recursive
evaluator. So here are some helper functions for throwing

View file

@ -128,10 +128,30 @@ public:
bool debugQuit;
std::list<DebugTrace> debugTraces;
template<class E>
[[gnu::noinline, gnu::noreturn]]
void debugThrow(const Error &error, const Env & env, const Expr & expr) const;
void debugThrow(const E &error, const Env & env, const Expr & expr) const
{
if (debuggerHook)
debuggerHook(&error, env, expr);
throw error;
}
template<class E>
[[gnu::noinline, gnu::noreturn]]
void debugThrowLastTrace(Error & e) const;
void debugThrowLastTrace(E & e) const
{
// Call this in the situation where Expr and Env are inaccessible.
// The debugger will start in the last context that's in the
// DebugTrace stack.
if (debuggerHook && !debugTraces.empty()) {
const DebugTrace & last = debugTraces.front();
debuggerHook(&e, last.env, last.expr);
}
throw e;
}
private:
SrcToStore srcToStore;