mirror of
https://github.com/imjasonh/nescript
synced 2026-07-12 10:39:31 +00:00
IR codegen: state dispatch, multi-OAM, and transition support
State machine dispatch: - IrProgram now stores states (Vec<String>) and start_state - Lowering captures state metadata before walking the AST - IR codegen generates a main loop with vblank wait and CMP+BNE+JMP dispatch table, matching the AST codegen's layout - Each frame handler ends with JMP __ir_main_loop - current_state initialized to the start state's index at boot Multi-OAM support: - next_oam_slot counter, reset at the start of each _frame function - Sequential allocation of 4-byte OAM entries at $0200 + slot*4 - Silently drops draws beyond slot 63 (OAM full) Transition codegen: - IrOp::Transition now looks up the target state's index from state_indices, writes it to ZP $03, and JMPs back to main loop - Previously this was a no-op placeholder Shared constants: - ZP_FRAME_FLAG ($00) and ZP_CURRENT_STATE ($03) match AST codegen Tests: 271 total (5 new IR codegen tests + 2 new integration tests) All 7 examples compile through --use-ir, including multi-state games and programs with transitions and functions. https://claude.ai/code/session_01W6eQFStA66EuMKHUFo2rx3
This commit is contained in:
parent
7e94cf37e3
commit
5660a8b7c3
5 changed files with 239 additions and 16 deletions
|
|
@ -33,6 +33,10 @@ pub struct IrProgram {
|
|||
pub functions: Vec<IrFunction>,
|
||||
pub globals: Vec<IrGlobal>,
|
||||
pub rom_data: Vec<IrRomBlock>,
|
||||
/// Ordered list of state names (index = state dispatch number).
|
||||
pub states: Vec<String>,
|
||||
/// Name of the initial state when the ROM boots.
|
||||
pub start_state: String,
|
||||
}
|
||||
|
||||
/// A global variable in the IR.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue