1
0
Fork 0
mirror of https://github.com/imjasonh/nescript synced 2026-07-12 10:39:31 +00:00

M4+M5: Optimizer passes, type casting, bank switching, math runtime

Milestone 4 — Optimization & Polish:
- Strength reduction: multiply by power-of-2 → shift left
- Zero-page promotion analysis: rank variables by access frequency
- `as` type casting expression in parser/AST/analyzer
- `scroll(x, y)` statement
- `--asm-dump` flag for viewing generated assembly
- Extended optimizer tests (strength reduction, frequency analysis)

Milestone 5 — Bank Switching & Release:
- Mapper support: MMC1 (1), UxROM (2), MMC3 (4) in parser and ROM builder
- Bank declarations: `bank Name: prg` / `bank Name: chr`
- Linker::with_mapper for mapper-aware ROM generation
- Software multiply (8x8→16, shift-and-add algorithm)
- Software divide (8÷8→8, restoring division algorithm)
- ROM tests for mapper encoding round-trip
- Integration test for MMC1 compilation

210 tests total (18 new), all pre-commit checks pass.

https://claude.ai/code/session_01W6eQFStA66EuMKHUFo2rx3
This commit is contained in:
Claude 2026-04-12 00:22:11 +00:00
parent 058f7a87b6
commit 5434dda114
No known key found for this signature in database
15 changed files with 865 additions and 13 deletions

View file

@ -1,7 +1,7 @@
#[cfg(test)]
mod tests;
use crate::parser::ast::Mirroring;
use crate::parser::ast::{Mapper, Mirroring};
/// iNES header magic bytes
const INES_MAGIC: [u8; 4] = [0x4E, 0x45, 0x53, 0x1A]; // "NES\x1A"
@ -137,3 +137,13 @@ pub struct RomInfo {
pub mapper: u8,
pub mirroring: Mirroring,
}
/// Map a `Mapper` enum variant to its iNES mapper number.
pub fn mapper_number(mapper: Mapper) -> u8 {
match mapper {
Mapper::NROM => 0,
Mapper::MMC1 => 1,
Mapper::UxROM => 2,
Mapper::MMC3 => 4,
}
}