Add versions of IfStmt and StmtList for use in debugger

This commit is contained in:
Tim Wojtulewicz 2025-10-07 21:44:40 -07:00
parent 8c9a35fb73
commit a4cddfbacd
3 changed files with 78 additions and 19 deletions

View file

@ -436,15 +436,7 @@ ValPtr IfStmt::DoExec(Frame* f, Val* v, StmtFlowType& flow) {
f->SetNextStmt(do_stmt);
if ( ! pre_execute_stmt(do_stmt, f) ) { // ### Abort or something
}
auto result = do_stmt->Exec(f, flow);
if ( ! post_execute_stmt(do_stmt, f, result.get(), &flow) ) { // ### Abort or something
}
return result;
return do_stmt->Exec(f, flow);
}
bool IfStmt::IsPure() const { return e->IsPure() && s1->IsPure() && s2->IsPure(); }
@ -488,6 +480,23 @@ TraversalCode IfStmt::Traverse(TraversalCallback* cb) const {
HANDLE_TC_STMT_POST(tc);
}
ValPtr DebugIfStmt::DoExec(Frame* f, Val* v, StmtFlowType& flow) {
// Treat 0 as false, but don't require 1 for true.
Stmt* do_stmt = v->IsZero() ? s2.get() : s1.get();
f->SetNextStmt(do_stmt);
if ( ! pre_execute_stmt(do_stmt, f) ) { // ### Abort or something
}
auto result = do_stmt->Exec(f, flow);
if ( ! post_execute_stmt(do_stmt, f, result.get(), &flow) ) { // ### Abort or something
}
return result;
}
static StmtTag get_last_stmt_tag(const Stmt* stmt) {
if ( ! stmt )
return STMT_NULL;
@ -1409,14 +1418,8 @@ ValPtr StmtList::Exec(Frame* f, StmtFlowType& flow) {
f->SetNextStmt(stmt);
if ( ! pre_execute_stmt(stmt, f) ) { // ### Abort or something
}
auto result = stmt->Exec(f, flow);
if ( ! post_execute_stmt(stmt, f, result.get(), &flow) ) { // ### Abort or something
}
if ( flow != FLOW_NEXT || result || f->HasDelayed() )
return result;
}
@ -1469,6 +1472,30 @@ TraversalCode StmtList::Traverse(TraversalCallback* cb) const {
HANDLE_TC_STMT_POST(tc);
}
ValPtr DebugStmtList::Exec(Frame* f, StmtFlowType& flow) {
RegisterAccess();
flow = FLOW_NEXT;
for ( const auto& stmt_ptr : stmts ) {
auto stmt = stmt_ptr.get();
f->SetNextStmt(stmt);
if ( ! pre_execute_stmt(stmt, f) ) { // ### Abort or something
}
auto result = stmt->Exec(f, flow);
if ( ! post_execute_stmt(stmt, f, result.get(), &flow) ) { // ### Abort or something
}
if ( flow != FLOW_NEXT || result || f->HasDelayed() )
return result;
}
return nullptr;
}
InitStmt::InitStmt(std::vector<IDPtr> arg_inits) : Stmt(STMT_INIT) {
inits = std::move(arg_inits);