mirror of
https://github.com/imjasonh/nescript
synced 2026-07-08 08:55:38 +00:00
Another batch from the cc65/nesdoug catalogue. All gated on
parser-level opt-in or default-false attributes so existing
programs produce byte-identical ROMs (no committed .nes file
changed).
**§A — `i16` signed 16-bit type:**
- New `KwI16` lexer token, `NesType::I16` AST variant, parser
case in `parse_type`. Type-size and integer-type tables
treat `i16` like `u16` (2 bytes, integer).
- IR lowering accepts `i16` everywhere it accepts `u16` for
wide-load / wide-store / widen-narrow paths.
- New constant fold for `UnaryOp::Negate(IntLiteral(v))` that
emits the wide two's-complement form. Without it, `var vy:
i16 = -10` would zero-extend to `$00F6` (= 246) instead of
sign-extending to `$FFF6` (= -10). Negative literals now
store the right bytes.
- Comparisons reuse the existing unsigned 16-bit compare ops
(matching the existing `i8` behaviour). Documented in the
`NesType::I16` doc comment and in `future-work.md` §A.
- Example `examples/i16_demo.ne` with committed golden.
- Tests cover the literal-fold sign-extension and end-to-end
compile of the example.
**§S — SRAM / battery-backed saves:**
- New `save { var ... }` top-level block. Lexer + parser opt
into a dedicated `KwSave` token. Analyzer allocates save
vars from a separate `next_sram_addr` bump pointer starting
at `$6000`, capped at `$8000` (8 KB cartridge SRAM window).
- Linker reads `analysis.has_battery_saves` and flips iNES
byte-6 bit-1 via the new `RomBuilder::set_battery` /
`Linker::with_battery` chain.
- New `W0111` warning for save-var initializers — SRAM is
preserved across power cycles, so an init expression would
either silently never run or clobber persisted data on
every boot. The warning teaches the user about the
magic-byte sentinel pattern.
- Struct fields in save blocks are explicitly rejected for now
(the field-flattening path uses the main-RAM allocator).
- Example `examples/sram_demo.ne` with committed golden, plus
4 integration tests.
**§D (partial) — inline-asm `.label:` syntax:**
- Codegen-side mangler rewrites `.IDENT` → `__ilab_<N>_IDENT`
per inline-asm block, where `<N>` is the call site's
monotonic suffix. Two `asm { .loop: ... }` blocks in the
same function now coexist without colliding in the linker's
label table.
- Bounds checks on `.` placement: `$2002` and `name.field`
are unaffected; only `.IDENT` in label / branch context
triggers the rewrite. Two integration tests pin the
uniqueness and dollar-vs-dot disambiguation.
**§X follow-up — Mesen trace-log docs:**
- New "Debugger-assisted workflows" section in
`docs/nes-reference.md` walking through the Mesen / FCEUX
log workflows alongside the new `debug_port:` attribute.
**Misc:**
- `future-work.md` updated to mark the shipped items out of
the catalogue and reshuffle the priority ranking. Remaining
niche follow-ups (signedness on Cmp16, struct save fields,
inline-asm format specifiers) documented inline so future
passes know the design.
All 757 tests pass. Clippy clean. 46/46 emulator goldens match.
|
||
|---|---|---|
| .. | ||
| arrays_and_functions.audio.hash | ||
| arrays_and_functions.png | ||
| audio_demo.audio.hash | ||
| audio_demo.png | ||
| auto_chr_background.audio.hash | ||
| auto_chr_background.png | ||
| auto_sprite_flicker.audio.hash | ||
| auto_sprite_flicker.png | ||
| axrom_simple.audio.hash | ||
| axrom_simple.png | ||
| bitwise_ops.audio.hash | ||
| bitwise_ops.png | ||
| bouncing_ball.audio.hash | ||
| bouncing_ball.png | ||
| cnrom_simple.audio.hash | ||
| cnrom_simple.png | ||
| coin_cavern.audio.hash | ||
| coin_cavern.png | ||
| comparisons.audio.hash | ||
| comparisons.png | ||
| edge_input_demo.audio.hash | ||
| edge_input_demo.png | ||
| fade_demo.audio.hash | ||
| fade_demo.png | ||
| feature_canary.audio.hash | ||
| feature_canary.png | ||
| friendly_assets.audio.hash | ||
| friendly_assets.png | ||
| function_chain.audio.hash | ||
| function_chain.png | ||
| gnrom_simple.audio.hash | ||
| gnrom_simple.png | ||
| hello_sprite.audio.hash | ||
| hello_sprite.png | ||
| i16_demo.audio.hash | ||
| i16_demo.png | ||
| inline_asm_demo.audio.hash | ||
| inline_asm_demo.png | ||
| logic_ops.audio.hash | ||
| logic_ops.png | ||
| loop_break_continue.audio.hash | ||
| loop_break_continue.png | ||
| match_demo.audio.hash | ||
| match_demo.png | ||
| metasprite_demo.audio.hash | ||
| metasprite_demo.png | ||
| mmc1_banked.audio.hash | ||
| mmc1_banked.png | ||
| mmc3_per_state_split.audio.hash | ||
| mmc3_per_state_split.png | ||
| nested_structs.audio.hash | ||
| nested_structs.png | ||
| noise_triangle_sfx.audio.hash | ||
| noise_triangle_sfx.png | ||
| palette_and_background.audio.hash | ||
| palette_and_background.png | ||
| palette_brightness_demo.audio.hash | ||
| palette_brightness_demo.png | ||
| platformer.audio.hash | ||
| platformer.png | ||
| pong.audio.hash | ||
| pong.png | ||
| prng_demo.audio.hash | ||
| prng_demo.png | ||
| scanline_split.audio.hash | ||
| scanline_split.png | ||
| sfx_pitch_envelope.audio.hash | ||
| sfx_pitch_envelope.png | ||
| sha256.audio.hash | ||
| sha256.png | ||
| sprite_0_split_demo.audio.hash | ||
| sprite_0_split_demo.png | ||
| sprite_flicker_demo.audio.hash | ||
| sprite_flicker_demo.png | ||
| sprites_and_palettes.audio.hash | ||
| sprites_and_palettes.png | ||
| sram_demo.audio.hash | ||
| sram_demo.png | ||
| state_machine.audio.hash | ||
| state_machine.png | ||
| structs_enums_for.audio.hash | ||
| structs_enums_for.png | ||
| two_player.audio.hash | ||
| two_player.png | ||
| uxrom_banked.audio.hash | ||
| uxrom_banked.png | ||
| uxrom_banked_to_banked.audio.hash | ||
| uxrom_banked_to_banked.png | ||
| uxrom_user_banked.audio.hash | ||
| uxrom_user_banked.png | ||
| war.audio.hash | ||
| war.png | ||