From 536dd7117fcded5dcb7504e7d4fecd5fa9597fb8 Mon Sep 17 00:00:00 2001 From: "Alice V." Date: Tue, 1 Dec 2026 10:12:38 +0000 Subject: [PATCH] examples: make 30_stream_test eZ80-portable via pointer-typed descriptor field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The BufStream descriptor kept the buffer address in a u16 cell of a byte array (`var p: ^u16 = s; p[0] = b`). On Z80 that works (16-bit pointers); on eZ80 ADL the 24-bit pointer truncates to bank 0, the writes miss buf, and the asserts at lines 63 and 75 read 0 instead of 42/20. Give the descriptor a struct with a pointer-typed field instead: struct BufStream { data: ^u8, pos: u16, cap: u16 } global stream: BufStream bufstream_init/write_u8/pos now take ^BufStream and use s.data/s.pos/s.cap, so the program is correct on both targets with the same four asserts and expected values. No compiler changes. Oracle evidence: the showcase_stream_oracle_test.go driver needed no change — the packed struct layout on the 16-bit oracle targets is still the 6 bytes [data:2][pos:2][cap:2] it already checked, and the test still verifies the same full 64-byte buffer and relocated-pointer descriptor on VM and native Z80 across all five capacities. The reviewed record in docs/grace-integration-338/reviewed-updates.json gets the new source SHA256 and an accurate boundary describing the struct descriptor. Gates: Z80 asserts 4/4; eZ80 sweep (scripts/agon/ez80_sweep.sh) 4/4 asserts pass, 0 fail (was 2/4); go test ./pkg/pipeline -run Showcase; go test ./pkg/nanz; run_stable_pipeline.py --profile fast (2 shards, exit 0 both). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS --- .../reviewed-updates.json | 4 +-- examples/nanz/30_stream_test.nanz | 36 ++++++++++--------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/docs/grace-integration-338/reviewed-updates.json b/docs/grace-integration-338/reviewed-updates.json index bf7449e6d..a440863f2 100644 --- a/docs/grace-integration-338/reviewed-updates.json +++ b/docs/grace-integration-338/reviewed-updates.json @@ -604,11 +604,11 @@ }, { "path": "examples/nanz/30_stream_test.nanz", - "source_sha256": "c5da58c9e90049f1ac63b9d01dcec856a41bc0a62b111f4a7ffe2c008cb73fc2", + "source_sha256": "1414ea9a8ac57ade32884a299a65cc5a6fdf99cd8ca1435e6628859e876c5ba5", "native_behavior": "executed-independent-vm-z80", "workload": "bufstream_init/write: capacities 0,1,3,63,64; 70 sequential writes each", "independent_model": "All 64 buffer bytes and 6 descriptor bytes; host min(capacity,writes) model with relocated pointer", - "boundary": "HIR driver and explicit initial globals; original source functions unchanged. Does not claim importing stdlib streams or whole source sandbox.", + "boundary": "HIR driver and explicit initial globals; original source functions unchanged. The descriptor is a BufStream struct whose data field is pointer-typed (6 bytes [data:2][pos:2][cap:2] on the 16-bit oracle targets); correctness under the 24-bit eZ80 ADL pointer ABI is a source property, not part of this oracle evidence. Does not claim importing stdlib streams or whole source sandbox.", "evidence": { "minzc/pkg/pipeline/showcase_stream_oracle_test.go": "bc3284dd649caaee3d72b6888ce4b40e315175755f3dd256d52eb89c4ea8bb1e" } diff --git a/examples/nanz/30_stream_test.nanz b/examples/nanz/30_stream_test.nanz index cbc29965c..eaabc573a 100644 --- a/examples/nanz/30_stream_test.nanz +++ b/examples/nanz/30_stream_test.nanz @@ -1,31 +1,35 @@ // Stream abstraction E2E tests — BufStream + NullStream // All tests via mir2 (VM-friendly, no Z80 regalloc issues) +// The descriptor keeps the buffer as a pointer-typed field so the stream is +// correct on both Z80 (16-bit pointers) and eZ80 ADL (24-bit pointers). // ── Inline BufStream (no import yet, self-contained for testing) ───────── +struct BufStream { + data: ^u8, // buffer the stream writes into + pos: u16, // next write index + cap: u16 // buffer capacity in bytes +} + global buf: [u8; 64] -global stream: [u8; 6] // BufStream: [buf_ptr:2][pos:2][cap:2] +global stream: BufStream -fun bufstream_init(s: ^u8, b: ^u8, cap: u16) -> void { - var p: ^u16 = s - p[0] = b - p[1] = 0 - p[2] = cap +fun bufstream_init(s: ^BufStream, b: ^u8, cap: u16) -> void { + s.data = b + s.pos = 0 + s.cap = cap } -fun bufstream_write_u8(s: ^u8, byte: u8) -> void { - var p: ^u16 = s - var pos: u16 = p[1] - if pos < p[2] { - var b: ^u8 = p[0] - b[pos] = byte - p[1] = pos + 1 +fun bufstream_write_u8(s: ^BufStream, byte: u8) -> void { + if s.pos < s.cap { + var b: ^u8 = s.data + b[s.pos] = byte + s.pos = s.pos + 1 } } -fun bufstream_pos(s: ^u8) -> u16 { - var p: ^u16 = s - return p[1] +fun bufstream_pos(s: ^BufStream) -> u16 { + return s.pos } // ── Test: basic write ────────────────────────────────────────────────────