1
0
Fork 0
mirror of https://github.com/imjasonh/nescript synced 2026-07-17 14:16:11 +00:00

Add debug.log and debug.assert statements

Parser:
- debug.log(expr, ...) and debug.assert(cond) syntax
- parse_debug_statement() handles both methods
- New AST variants: Statement::DebugLog and Statement::DebugAssert

Codegen:
- CodeGen::with_debug(bool) to toggle debug instrumentation
- DebugLog writes each expression to $4800 (Mesen debug port)
- DebugAssert evaluates condition; on false, writes $FF to $4800 + BRK
- Both are stripped entirely when debug_mode = false (release builds)

CLI:
- --debug flag now wired through to CodeGen
- Without --debug, all debug statements produce zero bytes

Analyzer:
- Type-checks DebugAssert condition as bool
- Walks DebugLog args for reads (used_vars tracking)

IR lowering:
- DebugLog/DebugAssert are no-ops (codegen handles them directly)

254 tests (5 new: 3 parser + 2 codegen).

https://claude.ai/code/session_01W6eQFStA66EuMKHUFo2rx3
This commit is contained in:
Claude 2026-04-12 10:11:32 +00:00
parent 6efef6c4c5
commit 45b2b2a279
No known key found for this signature in database
8 changed files with 199 additions and 3 deletions

View file

@ -606,6 +606,15 @@ impl Analyzer {
| Statement::Return(None, _)
| Statement::LoadBackground(_, _)
| Statement::SetPalette(_, _) => {}
Statement::DebugLog(args, _) => {
for arg in args {
self.walk_expr_reads(arg);
}
}
Statement::DebugAssert(cond, _) => {
self.walk_expr_reads(cond);
self.check_expr_type(cond, &NesType::Bool);
}
}
}
@ -804,6 +813,14 @@ fn collect_calls_stmt(stmt: &Statement, calls: &mut Vec<String>) {
collect_calls_expr(x, calls);
collect_calls_expr(y, calls);
}
Statement::DebugLog(args, _) => {
for arg in args {
collect_calls_expr(arg, calls);
}
}
Statement::DebugAssert(cond, _) => {
collect_calls_expr(cond, calls);
}
Statement::Return(None, _)
| Statement::Transition(_, _)
| Statement::WaitFrame(_)