1
0
Fork 0
mirror of https://github.com/imjasonh/nescript synced 2026-07-08 17:06:04 +00:00
nescript/examples
Claude 0dc06f7f1a
M2: Wire IR pipeline, add Coin Cavern example and integration tests
Pipeline:
- main.rs now runs IR lowering and optimization before codegen
- IR is built and optimized but output still uses AST-based codegen
  (IR-based codegen is a future improvement)

Coin Cavern example (examples/coin_cavern.ne):
- 3-state game: Title → Playing → GameOver
- Functions (clamp_x), constants, gravity physics, coin collection
- Demonstrates most M2 language features

Integration tests (14 total, 7 new):
- program_with_functions: functions with params and return values
- program_with_while_loop: while loops compile correctly
- program_with_fast_slow_vars: placement hints accepted
- program_with_multi_state_transitions: 3-state cycle
- coin_cavern_compiles: full Coin Cavern example
- ir_pipeline_produces_ir: validates IR lowering + optimizer
- error_test_recursion_detected: E0402 for recursive functions

https://claude.ai/code/session_01W6eQFStA66EuMKHUFo2rx3
2026-04-11 23:34:35 +00:00
..
bouncing_ball.ne Add example builds to CI, document sprite name behavior 2026-04-11 22:55:43 +00:00
coin_cavern.ne M2: Wire IR pipeline, add Coin Cavern example and integration tests 2026-04-11 23:34:35 +00:00
hello_sprite.ne Add example builds to CI, document sprite name behavior 2026-04-11 22:55:43 +00:00
README.md Add example builds to CI, document sprite name behavior 2026-04-11 22:55:43 +00:00

NEScript Examples

Quick Start

1. Build the compiler

cargo build --release

2. Compile an example

cargo run -- build examples/hello_sprite.ne

This produces examples/hello_sprite.nes — a valid iNES ROM file.

3. Run in an emulator

Open the .nes file in any NES emulator:

Use the d-pad (arrow keys in most emulators) to move the sprite.

Examples

File Description
hello_sprite.ne Move a smiley face with the d-pad
bouncing_ball.ne A sprite that bounces around the screen automatically

What you'll see

The ROM displays a small 8x8 smiley-face sprite. This is a default tile built into the compiler's CHR data. In hello_sprite, you control it with the d-pad. In bouncing_ball, it moves on its own and bounces off the screen edges.

About sprite names

In Milestone 1, the name in draw Smiley at: (x, y) is parsed but not resolved to a specific tile — all draws use CHR tile 0 (the built-in smiley). The draw syntax is forward-compatible: when sprite declarations and the asset pipeline arrive in M3, names like Smiley will reference actual sprite definitions with custom tile data from PNGs.

Emulator controls

NES Button Typical Key
D-pad Arrow keys
A Z
B X
Start Enter
Select Right Shift

(Exact mappings vary by emulator — check your emulator's input settings.)

Compiler commands

# Compile to ROM
cargo run -- build examples/hello_sprite.ne

# Compile with custom output path
cargo run -- build examples/hello_sprite.ne --output my_game.nes

# Type-check only (no ROM output)
cargo run -- check examples/hello_sprite.ne