1
0
Fork 0
mirror of https://github.com/imjasonh/nescript synced 2026-07-10 17:52:51 +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

@ -239,6 +239,12 @@ pub enum Statement {
LoadBackground(String, Span),
SetPalette(String, Span),
Scroll(Expr, Expr, Span),
/// debug.log(expr, ...) — writes values to the emulator debug port.
/// Stripped in release mode.
DebugLog(Vec<Expr>, Span),
/// debug.assert(cond) — runtime check, halts on failure.
/// Stripped in release mode.
DebugAssert(Expr, Span),
}
#[derive(Debug, Clone)]