mirror of
https://github.com/imjasonh/nescript
synced 2026-07-17 14:16:11 +00:00
Sprite resolution, asset wiring, shift-assign, unreachable state warning
Sprite/asset pipeline: - Linker::link_with_assets() places sprite CHR data in ROM at correct tile - assets::resolve_sprites() walks Program for inline sprite bytes - CodeGen::with_sprites() maps sprite names to tile indices - gen_draw() uses correct tile index from sprite declarations - main.rs wires the full resolution pipeline Shift-assign operators (<<= and >>=): - AssignOp::ShiftLeftAssign and ShiftRightAssign variants - Parser handles in both statement and array index contexts - Codegen emits ASL A / LSR A - IR lowering maps to ShiftLeft/ShiftRight ops Unreachable state warning (W0104): - BFS from start state finds reachable states via transitions - States not reached produce W0104 warning Error polish helpers: - suggest_var_name() for "did you mean" suggestions - emit_undefined_var() for E0502 with typo hints - Used by analyzer for better diagnostics 242 tests pass, clippy clean. https://claude.ai/code/session_01W6eQFStA66EuMKHUFo2rx3
This commit is contained in:
parent
5d2d242520
commit
6430c3a935
13 changed files with 737 additions and 17 deletions
17
src/main.rs
17
src/main.rs
|
|
@ -1,7 +1,8 @@
|
|||
use clap::Parser;
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use nescript::analyzer;
|
||||
use nescript::assets;
|
||||
use nescript::codegen::CodeGen;
|
||||
use nescript::errors::render_diagnostics;
|
||||
use nescript::ir;
|
||||
|
|
@ -116,17 +117,25 @@ fn compile(input: &PathBuf, _debug: bool, asm_dump: bool) -> Result<Vec<u8>, ()>
|
|||
let mut ir_program = ir::lower(&program, &analysis);
|
||||
optimizer::optimize(&mut ir_program);
|
||||
|
||||
// Resolve sprite assets (CHR data + tile indices) relative to the
|
||||
// source file's directory, so `@binary` / `@chr` paths work naturally.
|
||||
let source_dir = input.parent().unwrap_or_else(|| Path::new("."));
|
||||
let sprites = assets::resolve_sprites(&program, source_dir).map_err(|e| {
|
||||
eprintln!("error: {e}");
|
||||
})?;
|
||||
|
||||
// Code generation (still AST-based for M2; IR codegen comes in M3)
|
||||
let codegen = CodeGen::new(&analysis.var_allocations, &program.constants);
|
||||
let codegen =
|
||||
CodeGen::new(&analysis.var_allocations, &program.constants).with_sprites(&sprites);
|
||||
let instructions = codegen.generate(&program);
|
||||
|
||||
if asm_dump {
|
||||
dump_asm(&instructions);
|
||||
}
|
||||
|
||||
// Link into ROM
|
||||
// Link into ROM with sprite CHR data placed at each sprite's tile index.
|
||||
let linker = Linker::new(program.game.mirroring);
|
||||
let rom = linker.link(&instructions);
|
||||
let rom = linker.link_with_assets(&instructions, &sprites);
|
||||
|
||||
Ok(rom)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue