mirror of
https://github.com/imjasonh/nescript
synced 2026-07-13 19:17:54 +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:
parent
6efef6c4c5
commit
45b2b2a279
8 changed files with 199 additions and 3 deletions
|
|
@ -80,7 +80,7 @@ fn dump_asm(instructions: &[nescript::asm::Instruction]) {
|
|||
}
|
||||
}
|
||||
|
||||
fn compile(input: &PathBuf, _debug: bool, asm_dump: bool) -> Result<Vec<u8>, ()> {
|
||||
fn compile(input: &PathBuf, debug: bool, asm_dump: bool) -> Result<Vec<u8>, ()> {
|
||||
let raw_source = std::fs::read_to_string(input).map_err(|e| {
|
||||
eprintln!("error: failed to read {}: {e}", input.display());
|
||||
})?;
|
||||
|
|
@ -130,8 +130,9 @@ fn compile(input: &PathBuf, _debug: bool, asm_dump: bool) -> Result<Vec<u8>, ()>
|
|||
})?;
|
||||
|
||||
// Code generation (still AST-based for M2; IR codegen comes in M3)
|
||||
let codegen =
|
||||
CodeGen::new(&analysis.var_allocations, &program.constants).with_sprites(&sprites);
|
||||
let codegen = CodeGen::new(&analysis.var_allocations, &program.constants)
|
||||
.with_sprites(&sprites)
|
||||
.with_debug(debug);
|
||||
let instructions = codegen.generate(&program);
|
||||
|
||||
if asm_dump {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue