1
0
Fork 0
mirror of https://github.com/imjasonh/nescript synced 2026-07-08 08:55:38 +00:00

Inline asm: {var} placeholder substitution

Within \`asm { ... }\` blocks, \`{name}\` is replaced with the
resolved hex address of the variable at codegen time. The lexer's
asm-body capture now balances nested braces so it doesn't cut off
at the first \`{x}\`. Both IR and AST codegen paths preprocess the
body before passing to the inline parser:

    var counter: u8 = 0
    on frame {
        asm {
            LDA {counter}
            CLC
            ADC #\$01
            STA {counter}
        }
    }

Zero-page addresses become \`\$XX\`, absolute addresses become
\`\$XXXX\`. Unknown names pass through unchanged so the asm parser
can surface the "unknown mnemonic" / "unexpected token" error.

https://claude.ai/code/session_01W6eQFStA66EuMKHUFo2rx3
This commit is contained in:
Claude 2026-04-12 17:30:21 +00:00
parent f95130346a
commit a283f87b79
No known key found for this signature in database
5 changed files with 176 additions and 16 deletions

View file

@ -322,6 +322,26 @@ fn program_with_enums() {
rom::validate_ines(&rom_data).expect("should be valid iNES");
}
#[test]
fn program_with_inline_asm_variable_substitution() {
let source = r#"
game "AsmVar" { mapper: NROM }
var counter: u8 = 0
on frame {
asm {
LDA {counter}
CLC
ADC #$01
STA {counter}
}
wait_frame
}
start Main
"#;
let rom_data = compile(source);
rom::validate_ines(&rom_data).expect("should be valid iNES");
}
#[test]
fn program_with_inline_asm() {
let source = r#"