Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/grace-integration-338/reviewed-updates.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
36 changes: 20 additions & 16 deletions examples/nanz/30_stream_test.nanz
Original file line number Diff line number Diff line change
@@ -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 ────────────────────────────────────────────────────
Expand Down
Loading