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

@ -361,6 +361,10 @@ impl Analyzer {
));
}
}
Statement::Scroll(x, y, _) => {
self.check_expr_type(x, &NesType::U8);
self.check_expr_type(y, &NesType::U8);
}
Statement::Break(_)
| Statement::Continue(_)
| Statement::WaitFrame(_)
@ -460,6 +464,7 @@ impl Analyzer {
})
}
Expr::ArrayLiteral(_, _) => Some(NesType::U8), // element type inferred from context
Expr::Cast(_, target, _) => Some(target.clone()),
}
}
}
@ -517,6 +522,10 @@ fn collect_calls_stmt(stmt: &Statement, calls: &mut Vec<String>) {
collect_calls_expr(f, calls);
}
}
Statement::Scroll(x, y, _) => {
collect_calls_expr(x, calls);
collect_calls_expr(y, calls);
}
Statement::Return(None, _)
| Statement::Transition(_, _)
| Statement::WaitFrame(_)
@ -556,6 +565,9 @@ fn collect_calls_expr(expr: &Expr, calls: &mut Vec<String>) {
collect_calls_expr(e, calls);
}
}
Expr::Cast(inner, _, _) => {
collect_calls_expr(inner, calls);
}
Expr::IntLiteral(_, _)
| Expr::BoolLiteral(_, _)
| Expr::Ident(_, _)