lib: complete the parallel vstream surface to Hare value-return shape (#94 fold-eFinal prep)

The #94 Option-C vstream surface was left incomplete and structurally
divergent from Hare: constructors heap-allocated and returned (X | nomem)
or used out-params instead of Hare's by-value stack ownership; memio lacked
reset/buffer/borrowedread; bufio's scanner was never ported to the vtable.
This is the additive half of the eFinal collapse — OLD surface stays fully
live; the destructive FLIP (delete OLD + drop _v + repoint) is the next
commit.

Reshape all constructors to VALUE-RETURN (field-by-field sret; the heap +
nomem was an unnecessary crutch — wide slice-bearing struct return-by-value
is byte-id-proven, cf 925_sret_struct_return_run). memio fixed/dynamic/
dynamicfrom, bufio init, log new now return the struct by value; the nomem
is gone with the alloc that forced it.

memio: unify the per-flavour ctx structs onto one `stream` (vt at offset 0);
collapse fixed_string + dynamic_string into a single string() over the common
header (bare-str return is the ratified rule-9 frombytes carve-out, cited at
the site per ref/hare/memio/stream.ha:81); port reset/buffer/borrowedread as
single fns over the header.

bufio: collapse the EXISTING scanner subset (newscannerbuf/scanbyte/scanbytes/
scanline/finish + setflush/flush/unread/isbuffered) onto the vtable, with src
now io.vstream so reads go through io.st_read. The Hare scanner functions ww
never implemented (scanrune/scanstring-arbitrary-delim/readtok/readline/
auto-grow newscanner) are out of scope and deferred to #217 — eFinal is a
collapse, not a feature expansion.

Keep the explicit (&fn): *io.T casts on vtable-slot stores (cgen-neutral;
avoids the #214 (X|void) over-acceptance surface; dropping the casts is a
deferred #206 payoff gated on #214).

Self-gate: 776 (memio) 18/18 and 778 (bufio) 27/27, every row carrying a
cs.s == ww.s byte-id check — bufio/fmt/log are not compiler-embedded, so
these rows are their only byte-id coverage. 779/781 stay STAGE_CS-only
pending #209. Regen w6c+wwdump combined.ww (io+memio are the embedded
modules).
This commit is contained in:
2026-05-29 21:14:39 +09:00
parent f9f83faca7
commit 10cb835f99
10 changed files with 1068 additions and 860 deletions

View File

@@ -1,13 +1,17 @@
/*
* 776_memio_vstream_run — project #94 fold-e2 sentinel. Pins the
* additive lib/memio/vstream.ww Option C parallel API: heap-alloc'd
* ctx structs (fixed_ctx / dynamic_ctx) with `vt: io.vtable` as the
* first field for the intrusive cast, three constructors
* (fixed_vstream / dynamic_vstream / dynamicfrom_vstream) that
* return `(io.vstream | nomem)`, and the matching read/write/close
* callbacks that recover the outer ctx via a vstream→*ctx pointer
* cast. Coexists with the pre-vtable memio.fixed/dynamic/dynamicfrom
* surface in memio.ww (fold-eFinal, task #50, retires the latter).
* 776_memio_vstream_run — project #94 fold-eFinal(PREP) sentinel. Pins
* the additive lib/memio/vstream.ww parallel API: a single unified
* `stream` struct with `vt: io.vtable` as the first field for the
* intrusive cast, three constructors (fixed_vstream / dynamic_vstream /
* dynamicfrom_vstream) that return the `stream` BY VALUE (sret —
* field-by-field build then `return r;`, ref/hare/memio/stream.ha:46,
* 58,64), the unified read_v / fixedwrite_v / dynamicwrite_v /
* dynamicclose_v callbacks that recover the outer stream via a
* vstream→*stream pointer cast, and the collapsed single accessors
* (string_v / buffer_v / reset_v / borrowedread_v) over the common
* header. Coexists with the pre-vtable memio.fixed/dynamic/dynamicfrom
* + `state` surface in memio.ww (fold-eFinal FLIP retires the latter
* and drops the `_vstream`/`_v` suffix wholesale).
*
* Each row imports memio + io, calls one or more constructors, drives
* the io.st_read/st_write/st_close dispatchers, and asserts an exit
@@ -19,9 +23,10 @@
* | over an 8-byte source. Asserts the
* | return is `size` and equal to 5, and
* | that out[0]/out[4] mirror the buffer.
* | Pins the full intrusive shape (alloc
* | fixed_ctx → return &c.vt; dispatcher
* | recovers via s: *fixed_ctx).
* | Pins the full intrusive shape (build
* | stream field-by-field → return r (sret);
* | caller takes &st.vt; dispatcher recovers
* | via s: *stream).
* dynamic_write_grow | dynamic_vstream + io.st_write of 3
* | bytes. Asserts the write reports 3
* | and that the dynamicgrow_v path
@@ -67,11 +72,10 @@
* fold-eFinal can graduate once #173 closes.
*
* - #195 (cgassign N_DOT TK_ASSIGN on aliased-ptr receiver):
* would bite if vstream.ww used chained `c.vt.reader = …`
* stores through the alloc'd ctx pointer. We sidestep via a
* local `let vt: io.vtable;` + field-assigns + struct-lit
* `alloc(fixed_ctx{vt=vt, …})`. Mirrors memio.ww:39's flat-
* slice-fields workaround. eFinal can collapse once #195 closes.
* not bitten — the value-return constructor builds the stream in
* a local `let r: stream;` and field-assigns each slot (including
* r.vt.reader) through a plain pointer-to-local, not an aliased-ptr
* receiver. The flat ptr/len/cap fields (memio.ww:39) stay flat.
*
* GATE POLARITY: must stay GREEN. A red here means vstream.ww
* regressed, the alloc-struct-? path miscompiled, the intrusive
@@ -114,12 +118,8 @@ static const struct row rows[] = {
" let buf: [8]u8;\n"
" buf[0] = 65u8; buf[1] = 66u8; buf[2] = 67u8; buf[3] = 68u8;\n"
" buf[4] = 69u8; buf[5] = 70u8; buf[6] = 71u8; buf[7] = 72u8;\n"
" let r = memio.fixed_vstream(buf[0:8]);\n"
" let s: io.vstream = nil: *io.vtable;\n"
" match (r) {\n"
" case let v: io.vstream => { s = v; };\n"
" case nomem => { return 50; };\n"
" };\n"
" let st: memio.stream = memio.fixed_vstream(buf[0:8]);\n"
" let s: io.vstream = &st.vt;\n"
" let out: [5]u8;\n"
" let n: size = 0;\n"
" let rd = io.st_read(s, out[0:5]);\n"
@@ -135,12 +135,8 @@ static const struct row rows[] = {
"import io;\n"
"import os;\n"
"export fn main() i32 = {\n"
" let r = memio.dynamic_vstream();\n"
" let s: io.vstream = nil: *io.vtable;\n"
" match (r) {\n"
" case let v: io.vstream => { s = v; };\n"
" case nomem => { return 50; };\n"
" };\n"
" let st: memio.stream = memio.dynamic_vstream();\n"
" let s: io.vstream = &st.vt;\n"
" let src: [3]u8;\n"
" src[0] = 88u8; src[1] = 89u8; src[2] = 90u8;\n"
" let wr = io.st_write(s, src[0:3]);\n"
@@ -160,12 +156,8 @@ static const struct row rows[] = {
"export fn main() i32 = {\n"
" let seed: [4]u8;\n"
" seed[0] = 1u8; seed[1] = 2u8; seed[2] = 3u8; seed[3] = 4u8;\n"
" let r = memio.dynamicfrom_vstream(seed[0:4]);\n"
" let s: io.vstream = nil: *io.vtable;\n"
" match (r) {\n"
" case let v: io.vstream => { s = v; };\n"
" case nomem => { return 50; };\n"
" };\n"
" let st: memio.stream = memio.dynamicfrom_vstream(seed[0:4]);\n"
" let s: io.vstream = &st.vt;\n"
" let out: [4]u8;\n"
" let rd = io.st_read(s, out[0:4]);\n"
" let rn: size = 0;\n"
@@ -190,18 +182,10 @@ static const struct row rows[] = {
" a[0] = 10u8; a[1] = 11u8; a[2] = 12u8;\n"
" let b: [5]u8;\n"
" b[0] = 20u8; b[1] = 21u8; b[2] = 22u8; b[3] = 23u8; b[4] = 24u8;\n"
" let ra = memio.fixed_vstream(a[0:3]);\n"
" let rb = memio.fixed_vstream(b[0:5]);\n"
" let sa: io.vstream = nil: *io.vtable;\n"
" let sb: io.vstream = nil: *io.vtable;\n"
" match (ra) {\n"
" case let v: io.vstream => { sa = v; };\n"
" case nomem => { return 50; };\n"
" };\n"
" match (rb) {\n"
" case let v: io.vstream => { sb = v; };\n"
" case nomem => { return 51; };\n"
" };\n"
" let sta: memio.stream = memio.fixed_vstream(a[0:3]);\n"
" let stb: memio.stream = memio.fixed_vstream(b[0:5]);\n"
" let sa: io.vstream = &sta.vt;\n"
" let sb: io.vstream = &stb.vt;\n"
" let outa: [3]u8;\n"
" let outb: [5]u8;\n"
" let rda = io.st_read(sa, outa[0:3]);\n"
@@ -215,6 +199,65 @@ static const struct row rows[] = {
"};\n",
45,
STAGE_CS | STAGE_WW, 1 },
/* accessors_string_buffer_reset — fold-eFinal PREP: the collapsed
* single accessors over the common `stream` header (string_v /
* buffer_v / reset_v, ref/hare/memio/stream.ha:81,74,87). Writes 3
* bytes through the value-returned fixed stream, then asserts
* string_v (str view), buffer_v ([]u8 view), and reset_v (rewind to
* 0) all read the flat header correctly. Pins the value-return
* field integrity (st.vt + st.ptr/len/cap/pos survive sret) AND the
* accessor collapse. cs.s == ww.s byte-id. */
{ "accessors_string_buffer_reset",
"package main;\n"
"import memio;\n"
"import io;\n"
"import os;\n"
"export fn main() i32 = {\n"
" let buf: [16]u8;\n"
" let st: memio.stream = memio.fixed_vstream(buf[0:16]);\n"
" let s: io.vstream = &st.vt;\n"
" let payload: [3]u8;\n"
" payload[0] = 65u8; payload[1] = 66u8; payload[2] = 67u8;\n"
" let wr = io.st_write(s, payload[0:3]);\n"
" if (!(wr is size)) { return 90; };\n"
" let v: str = memio.string_v(&st);\n"
" if (v.len != 3 || v[0] != 65u8 || v[2] != 67u8) { return 91; };\n"
" let bv: []u8 = memio.buffer_v(&st);\n"
" if (bv.len != 3 || bv[1] != 66u8) { return 92; };\n"
" memio.reset_v(&st);\n"
" if (memio.string_v(&st).len != 0) { return 93; };\n"
" return 46;\n"
"};\n",
46,
STAGE_CS | STAGE_WW, 1 },
/* borrowedread_view_eof — the collapsed borrowedread_v
* (ref/hare/memio/stream.ha:94): returns an amt-byte borrowed view
* advancing the cursor, eof when fewer remain. Reads 3 of 4 seeded
* bytes (view len 3), then a 2-byte borrowedread over the remaining
* 1 byte returns io.eof. cs.s == ww.s byte-id. */
{ "borrowedread_view_eof",
"package main;\n"
"import memio;\n"
"import io;\n"
"import os;\n"
"export fn main() i32 = {\n"
" let seed: [4]u8;\n"
" seed[0] = 1u8; seed[1] = 2u8; seed[2] = 3u8; seed[3] = 4u8;\n"
" let st: memio.stream = memio.dynamicfrom_vstream(seed[0:4]);\n"
" let br = memio.borrowedread_v(&st, 3);\n"
" match (br) {\n"
" case let b: []u8 => { if (b.len != 3 || b[0] != 1u8 || b[2] != 3u8) { return 91; }; };\n"
" case io.eof => { return 92; };\n"
" };\n"
" let br2 = memio.borrowedread_v(&st, 2);\n"
" match (br2) {\n"
" case let b: []u8 => { return 93; };\n"
" case io.eof => { return 47; };\n"
" };\n"
" return 99;\n"
"};\n",
47,
STAGE_CS | STAGE_WW, 1 },
};
static int

View File

@@ -1,19 +1,27 @@
/*
* 778_bufio_vstream_run — project #94 fold-e4 sentinel. Pins the
* additive lib/bufio/vstream.ww Option C parallel API: heap-alloc'd
* bufio_ctx with `vt: io.vtable` as the first field for the intrusive
* vstream cast, the bufio_vstream constructor that returns
* `(io.vstream | nomem)` wrapping an underlying *io.stream (OLD
* API; bufio_vstream's `src` parameter type stays OLD until io
* fold-2 lands `handle = (file | int)`), and isbuffered_v as the
* fn-ptr-equality discriminator over the new `_v` callback symbols.
* Coexists with the pre-vtable bufio.init / bufio.isbuffered surface
* in bufio.ww (fold-eFinal, task #50, retires the latter once io
* fold-2 ports `handle = (file | int)`).
* 778_bufio_vstream_run — project #94 fold-eFinal(PREP) sentinel. Pins
* the lib/bufio/vstream.ww parallel API — a COLLAPSE of the OLD bufio
* surface onto the io.vtable, NOT a port of Hare's missing scanner
* features (those are #217, OUT of eFinal). Covers:
* - buffered stream: `bufio_ctx` (vt@offset0 for the intrusive cast),
* `bufio_vstream` (returns the ctx BY VALUE; sret field-by-field)
* over an underlying **io.vstream** src — every underlying read/
* write/close goes through io.st_read/io.st_write/io.st_close (the
* vtable dispatchers), io.error forwards directly (no nomem-widen).
* Plus setflush_v / flush_v (public + internal drain) / unread_v /
* isbuffered_v (fn-ptr-equality discriminator).
* - scanner: `scanner_v` (value-return newscannerbuf_v over an
* io.vstream src) + scanbyte_v / scanbytes_v (single-byte delim) /
* scanline_v / finish_v.
* Coexists with the pre-vtable bufio.init / scanner / isbuffered surface
* in bufio.ww (fold-eFinal FLIP retires the latter + drops the `_v`
* suffix: bufio_ctx→stream, bufio_vstream→init, scanner_v→scanner,
* scanbytes_v→scanbytes, newscannerbuf_v→newscannerbuf, …).
*
* Each row imports os + bufio + memio + io (NOT fmt — bufio doesn't
* transitively pull fmt, so #209's formattable-match bail doesn't
* propagate; both stages run on every row).
* propagate; both stages run on every row, cs.s==ww.s — bufio is NOT
* compiler-embedded, so these byte-id rows are its ONLY byte-id cover).
*
* row | what it pins
* --------------------------+--------------------------------------
@@ -22,7 +30,8 @@
* | io.st_close. Asserts the data
* | reaches the underlying memio buffer
* | after close drains wbuf. Full chain:
* | alloc bufio_ctx → return &c.vt
* | bufio_ctx built field-by-field
* | return r (sret) → caller takes &b.vt →
* | dispatcher recovers via *bufio_ctx →
* | flush_v → io.write(b.src, ...).
* stream_read_unread | bufio_vstream read path: io.st_read
@@ -83,11 +92,10 @@
* than using `io.write(...)?`; same memio.vstream.ww +
* fmt.vstream.ww shape.
*
* - #207 (struct-lit multi-tagged-field copy drops past first):
* alloc-zero-chain pattern (`vt = zero` + post-alloc
* `c.vt.X = ...`) sidesteps; only 1 tagged field in bufio_ctx
* so the workaround is overkill, but stays for idiom
* consistency with memio/vstream.ww.
* - #207 (struct-lit multi-tagged-field copy drops past first) and
* #210 (slice-field struct-lit drop): not reachable from the
* value-return form — bufio_ctx is built field-by-field in a
* local then sret-returned, no `alloc(T{...})` struct-lit.
*
* BOOTSTRAP-EMBED CHECK: bufio is NOT embedded in any selfhost
* combined.ww (grep confirmed). Adding lib/bufio/vstream.ww does
@@ -136,27 +144,22 @@ static const struct row rows[] = {
"import io;\n"
"export fn main() i32 = {\n"
" let raw: [16]u8;\n"
" let mem: memio.state;\n"
" let m: io.stream;\n"
" memio.fixed(&mem, &m, raw[0:16]);\n"
" let mst: memio.stream = memio.fixed_vstream(raw[0:16]);\n"
" let msrc: io.vstream = &mst.vt;\n"
" let rbuf: [8]u8;\n"
" let wbuf: [8]u8;\n"
" let r = bufio.bufio_vstream(&m, rbuf[0:8], wbuf[0:8]);\n"
" let vs: io.vstream = nil: *io.vtable;\n"
" match (r) {\n"
" case let v: io.vstream => { vs = v; };\n"
" case nomem => { return 50; };\n"
" };\n"
" let b: bufio.bufio_ctx = bufio.bufio_vstream(msrc, rbuf[0:8], wbuf[0:8]);\n"
" let vs: io.vstream = &b.vt;\n"
" let payload: [5]u8;\n"
" payload[0] = 104u8; payload[1] = 105u8;\n"
" payload[2] = 33u8; payload[3] = 98u8; payload[4] = 121u8;\n"
" let wr = io.st_write(vs, payload[0:5]);\n"
" let nw: size = 0;\n"
" if (wr is size) { nw = wr as size; };\n"
" if (mem.pos != 0) { return 91; };\n"
" if (mst.pos != 0) { return 91; };\n"
" let cl = io.st_close(vs);\n"
" if (cl is io.error) { return 92; };\n"
" if (mem.pos != 5) { return 93; };\n"
" if (mst.pos != 5) { return 93; };\n"
" if (nw != 5: size) { return 94; };\n"
" if (raw[0] != 104u8 || raw[4] != 121u8) { return 95; };\n"
" return 46;\n"
@@ -173,17 +176,12 @@ static const struct row rows[] = {
" let raw: [8]u8;\n"
" raw[0] = 65u8; raw[1] = 66u8; raw[2] = 67u8; raw[3] = 68u8;\n"
" raw[4] = 69u8; raw[5] = 70u8; raw[6] = 71u8; raw[7] = 72u8;\n"
" let mem: memio.state;\n"
" let m: io.stream;\n"
" memio.fixed(&mem, &m, raw[0:8]);\n"
" let mst: memio.stream = memio.fixed_vstream(raw[0:8]);\n"
" let msrc: io.vstream = &mst.vt;\n"
" let rbuf: [8]u8;\n"
" let wbuf: [4]u8;\n"
" let r = bufio.bufio_vstream(&m, rbuf[0:8], wbuf[0:4]);\n"
" let vs: io.vstream = nil: *io.vtable;\n"
" match (r) {\n"
" case let v: io.vstream => { vs = v; };\n"
" case nomem => { return 50; };\n"
" };\n"
" let b: bufio.bufio_ctx = bufio.bufio_vstream(msrc, rbuf[0:8], wbuf[0:4]);\n"
" let vs: io.vstream = &b.vt;\n"
" let out: [4]u8;\n"
" let rd1 = io.st_read(vs, out[0:3]);\n"
" let n1: size = 0;\n"
@@ -207,24 +205,15 @@ static const struct row rows[] = {
"import io;\n"
"export fn main() i32 = {\n"
" let raw: [8]u8;\n"
" let mem: memio.state;\n"
" let m: io.stream;\n"
" memio.fixed(&mem, &m, raw[0:8]);\n"
" let mst: memio.stream = memio.fixed_vstream(raw[0:8]);\n"
" let msrc: io.vstream = &mst.vt;\n"
" let rbuf: [4]u8;\n"
" let wbuf: [4]u8;\n"
" let r = bufio.bufio_vstream(&m, rbuf[0:4], wbuf[0:4]);\n"
" let vsbuf: io.vstream = nil: *io.vtable;\n"
" match (r) {\n"
" case let v: io.vstream => { vsbuf = v; };\n"
" case nomem => { return 50; };\n"
" };\n"
" let b: bufio.bufio_ctx = bufio.bufio_vstream(msrc, rbuf[0:4], wbuf[0:4]);\n"
" let vsbuf: io.vstream = &b.vt;\n"
" let buf2: [4]u8;\n"
" let r2 = memio.fixed_vstream(buf2[0:4]);\n"
" let vsplain: io.vstream = nil: *io.vtable;\n"
" match (r2) {\n"
" case let v: io.vstream => { vsplain = v; };\n"
" case nomem => { return 51; };\n"
" };\n"
" let st2: memio.stream = memio.fixed_vstream(buf2[0:4]);\n"
" let vsplain: io.vstream = &st2.vt;\n"
" if (!bufio.isbuffered_v(vsbuf)) { return 91; };\n"
" if (bufio.isbuffered_v(vsplain)) { return 92; };\n"
" return 48;\n"
@@ -239,17 +228,12 @@ static const struct row rows[] = {
"import io;\n"
"export fn main() i32 = {\n"
" let raw: [8]u8;\n"
" let mem: memio.state;\n"
" let m: io.stream;\n"
" memio.fixed(&mem, &m, raw[0:8]);\n"
" let mst: memio.stream = memio.fixed_vstream(raw[0:8]);\n"
" let msrc: io.vstream = &mst.vt;\n"
" let rbuf: [4]u8;\n"
" let wbuf: [4]u8;\n"
" let r = bufio.bufio_vstream(&m, rbuf[0:4], wbuf[0:4]);\n"
" let vs: io.vstream = nil: *io.vtable;\n"
" match (r) {\n"
" case let v: io.vstream => { vs = v; };\n"
" case nomem => { return 50; };\n"
" };\n"
" let bc: bufio.bufio_ctx = bufio.bufio_vstream(msrc, rbuf[0:4], wbuf[0:4]);\n"
" let vs: io.vstream = &bc.vt;\n"
" if (!bufio.isbuffered_v(vs)) { return 91; };\n"
" let raw2: u64 = vs: u64;\n"
" let asold: *io.stream = raw2: *io.stream;\n"
@@ -278,23 +262,15 @@ static const struct row rows[] = {
" raA[0] = 10u8; raA[1] = 11u8; raA[2] = 12u8; raA[3] = 13u8;\n"
" let raB: [4]u8;\n"
" raB[0] = 20u8; raB[1] = 21u8; raB[2] = 22u8; raB[3] = 23u8;\n"
" let memA: memio.state;\n"
" let memB: memio.state;\n"
" let mA: io.stream;\n"
" let mB: io.stream;\n"
" memio.fixed(&memA, &mA, raA[0:4]);\n"
" memio.fixed(&memB, &mB, raB[0:4]);\n"
" let mstA: memio.stream = memio.fixed_vstream(raA[0:4]);\n"
" let mstB: memio.stream = memio.fixed_vstream(raB[0:4]);\n"
" let sel: i32 = 1;\n"
" let src: *io.stream = &mA;\n"
" if (sel == 0) { src = &mB; };\n"
" let src: io.vstream = &mstA.vt;\n"
" if (sel == 0) { src = &mstB.vt; };\n"
" let rbuf: [4]u8;\n"
" let wbuf: [4]u8;\n"
" let r = bufio.bufio_vstream(src, rbuf[0:4], wbuf[0:4]);\n"
" let vs: io.vstream = nil: *io.vtable;\n"
" match (r) {\n"
" case let v: io.vstream => { vs = v; };\n"
" case nomem => { return 50; };\n"
" };\n"
" let bc: bufio.bufio_ctx = bufio.bufio_vstream(src, rbuf[0:4], wbuf[0:4]);\n"
" let vs: io.vstream = &bc.vt;\n"
" let out: [4]u8;\n"
" let rd = io.st_read(vs, out[0:4]);\n"
" let n: size = 0;\n"
@@ -305,6 +281,158 @@ static const struct row rows[] = {
"};\n",
51,
STAGE_CS | STAGE_WW, 1 },
/* scanner_lines — fold-eFinal PREP: the value-return scanner over an
* io.vstream src. newscannerbuf_v (Hare newscanner_buf) → scanline_v
* twice ("ab", "c") → trailing "def" with no newline is EOF_DISCARD
* → io.eof → finish_v. Pins the scanner reads through io.st_read
* (vtable dispatch) on the underlying memio stream. cs.s==ww.s. */
{ "scanner_lines",
"package main;\n"
"import os;\n"
"import bufio;\n"
"import memio;\n"
"import io;\n"
"export fn main() i32 = {\n"
" let raw: [8]u8;\n"
" raw[0]=97u8; raw[1]=98u8; raw[2]=10u8;\n"
" raw[3]=99u8; raw[4]=10u8;\n"
" raw[5]=100u8; raw[6]=101u8; raw[7]=102u8;\n"
" let mst: memio.stream = memio.dynamicfrom_vstream(raw[0:8]);\n"
" let vs: io.vstream = &mst.vt;\n"
" let win: [16]u8;\n"
" let sc: bufio.scanner_v = bufio.newscannerbuf_v(vs, win[0:16]);\n"
" let ok: i32 = 0;\n"
" match (bufio.scanline_v(&sc)) {\n"
" case let s: str => { if (s.len == 2 && s[0] == 97u8 && s[1] == 98u8) { ok += 1; }; };\n"
" case io.eof => { return 81; };\n"
" case let e: io.error => { return 82; };\n"
" case bufio.overflow => { return 83; };\n"
" };\n"
" match (bufio.scanline_v(&sc)) {\n"
" case let s: str => { if (s.len == 1 && s[0] == 99u8) { ok += 1; }; };\n"
" case io.eof => { return 84; };\n"
" case let e: io.error => { return 85; };\n"
" case bufio.overflow => { return 86; };\n"
" };\n"
" match (bufio.scanline_v(&sc)) {\n"
" case let s: str => { return 87; };\n"
" case io.eof => { ok += 1; };\n"
" case let e: io.error => { return 88; };\n"
" case bufio.overflow => { return 89; };\n"
" };\n"
" bufio.finish_v(&sc);\n"
" if (ok != 3) { return 90; };\n"
" return 52;\n"
"};\n",
52,
STAGE_CS | STAGE_WW, 1 },
/* scanner_byte_bytes — scanbyte_v pops 'A'; scanbytes_v(',') then
* tokenizes "B" and "CD" from "AB,CD,". Single-byte delim (the OLD
* scantok behaviour; multibyte is #217). cs.s==ww.s. */
{ "scanner_byte_bytes",
"package main;\n"
"import os;\n"
"import bufio;\n"
"import memio;\n"
"import io;\n"
"export fn main() i32 = {\n"
" let raw: [6]u8;\n"
" raw[0]=65u8; raw[1]=66u8; raw[2]=44u8;\n"
" raw[3]=67u8; raw[4]=68u8; raw[5]=44u8;\n"
" let mst: memio.stream = memio.dynamicfrom_vstream(raw[0:6]);\n"
" let vs: io.vstream = &mst.vt;\n"
" let win: [8]u8;\n"
" let sc: bufio.scanner_v = bufio.newscannerbuf_v(vs, win[0:8]);\n"
" let fb: u8 = 0u8;\n"
" match (bufio.scanbyte_v(&sc)) {\n"
" case let b: u8 => { fb = b; };\n"
" case io.eof => { return 81; };\n"
" case let e: io.error => { return 82; };\n"
" };\n"
" if (fb != 65u8) { return 83; };\n"
" match (bufio.scanbytes_v(&sc, 44u8)) {\n"
" case let bs: []u8 => { if (bs.len != 1 || bs[0] != 66u8) { return 84; }; };\n"
" case io.eof => { return 85; };\n"
" case let e: io.error => { return 86; };\n"
" case bufio.overflow => { return 87; };\n"
" };\n"
" match (bufio.scanbytes_v(&sc, 44u8)) {\n"
" case let bs: []u8 => { if (bs.len != 2 || bs[0] != 67u8 || bs[1] != 68u8) { return 88; }; };\n"
" case io.eof => { return 89; };\n"
" case let e: io.error => { return 90; };\n"
" case bufio.overflow => { return 91; };\n"
" };\n"
" return 53;\n"
"};\n",
53,
STAGE_CS | STAGE_WW, 1 },
/* stream_setflush — setflush_v swaps the auto-flush byte-set to ';';
* writing "ab;" auto-flushes (contains ';') so the sink advances to
* 3 with no explicit flush. Pins setflush_v + the flush-scan path.
* cs.s==ww.s. */
{ "stream_setflush",
"package main;\n"
"import os;\n"
"import bufio;\n"
"import memio;\n"
"import io;\n"
"export fn main() i32 = {\n"
" let sinkbuf: [16]u8;\n"
" let sink: memio.stream = memio.fixed_vstream(sinkbuf[0:16]);\n"
" let sinkvs: io.vstream = &sink.vt;\n"
" let rb: [4]u8;\n"
" let wb: [8]u8;\n"
" let b: bufio.bufio_ctx = bufio.bufio_vstream(sinkvs, rb[0:4], wb[0:8]);\n"
" let bvs: io.vstream = &b.vt;\n"
" let semi: [1]u8;\n"
" semi[0] = 59u8;\n"
" bufio.setflush_v(&b, semi[0:1]);\n"
" let payload: [3]u8;\n"
" payload[0]=97u8; payload[1]=98u8; payload[2]=59u8;\n"
" let wr = io.st_write(bvs, payload[0:3]);\n"
" if (!(wr is size)) { return 81; };\n"
" if (sink.pos != 3) { return 82; };\n"
" if (sinkbuf[0] != 97u8 || sinkbuf[2] != 59u8) { return 83; };\n"
" return 54;\n"
"};\n",
54,
STAGE_CS | STAGE_WW, 1 },
/* stream_unread — read "XYZ" then unread_v("XY") pushes the two
* bytes back in front of the read buffer; the next read returns them
* first. Pins unread_v's in-place shift through *bufio_ctx.
* cs.s==ww.s. */
{ "stream_unread",
"package main;\n"
"import os;\n"
"import bufio;\n"
"import memio;\n"
"import io;\n"
"export fn main() i32 = {\n"
" let raw: [4]u8;\n"
" raw[0]=88u8; raw[1]=89u8; raw[2]=90u8;\n"
" let mst: memio.stream = memio.dynamicfrom_vstream(raw[0:3]);\n"
" let vs: io.vstream = &mst.vt;\n"
" let rbuf: [4]u8;\n"
" let wbuf: [4]u8;\n"
" let b: bufio.bufio_ctx = bufio.bufio_vstream(vs, rbuf[0:4], wbuf[0:4]);\n"
" let bvs: io.vstream = &b.vt;\n"
" let out: [4]u8;\n"
" let rd = io.st_read(bvs, out[0:3]);\n"
" let n: size = 0;\n"
" if (rd is size) { n = rd as size; };\n"
" if (n != 3: size || out[0] != 88u8 || out[2] != 90u8) { return 81; };\n"
" let push: [2]u8;\n"
" push[0]=88u8; push[1]=89u8;\n"
" bufio.unread_v(&b, push[0:2]);\n"
" let out2: [2]u8;\n"
" let rd2 = io.st_read(bvs, out2[0:2]);\n"
" let n2: size = 0;\n"
" if (rd2 is size) { n2 = rd2 as size; };\n"
" if (n2 != 2: size || out2[0] != 88u8 || out2[1] != 89u8) { return 82; };\n"
" return 55;\n"
"};\n",
55,
STAGE_CS | STAGE_WW, 1 },
};
static int

View File

@@ -151,14 +151,9 @@ static const struct row rows[] = {
"import io;\n"
"export fn main() i32 = {\n"
" let buf: [16]u8;\n"
" let r = memio.fixed_vstream(buf[0:16]);\n"
" let vs: io.vstream = nil: *io.vtable;\n"
" match (r) {\n"
" case let v: io.vstream => { vs = v; };\n"
" case nomem => { return 50; };\n"
" };\n"
" let sl: log.vstdlogger;\n"
" log.new_v(&sl, vs);\n"
" let st: memio.stream = memio.fixed_vstream(buf[0:16]);\n"
" let vs: io.vstream = &st.vt;\n"
" let sl: log.vstdlogger = log.new_v(vs);\n"
" log.lprintln_v(&sl.logger, \"hi\", 7i64);\n"
" if (buf[0] != 104u8) { return 91; };\n"
" if (buf[1] != 105u8) { return 92; };\n"
@@ -178,22 +173,12 @@ static const struct row rows[] = {
"export fn main() i32 = {\n"
" let bufA: [16]u8;\n"
" let bufB: [16]u8;\n"
" let rA = memio.fixed_vstream(bufA[0:16]);\n"
" let vsA: io.vstream = nil: *io.vtable;\n"
" match (rA) {\n"
" case let v: io.vstream => { vsA = v; };\n"
" case nomem => { return 50; };\n"
" };\n"
" let rB = memio.fixed_vstream(bufB[0:16]);\n"
" let vsB: io.vstream = nil: *io.vtable;\n"
" match (rB) {\n"
" case let v: io.vstream => { vsB = v; };\n"
" case nomem => { return 51; };\n"
" };\n"
" let slA: log.vstdlogger;\n"
" let slB: log.vstdlogger;\n"
" log.new_v(&slA, vsA);\n"
" log.new_v(&slB, vsB);\n"
" let stA: memio.stream = memio.fixed_vstream(bufA[0:16]);\n"
" let vsA: io.vstream = &stA.vt;\n"
" let stB: memio.stream = memio.fixed_vstream(bufB[0:16]);\n"
" let vsB: io.vstream = &stB.vt;\n"
" let slA: log.vstdlogger = log.new_v(vsA);\n"
" let slB: log.vstdlogger = log.new_v(vsB);\n"
" let sel: i32 = 1;\n"
" let chosen: *log.vlogger = &slA.logger;\n"
" if (sel == 0) { chosen = &slB.logger; };\n"

View File

@@ -190,12 +190,8 @@ static const struct row rows[] = {
"import memio;\n"
"export fn main() i32 = {\n"
" let buf: [16]u8;\n"
" let r: (io.vstream | nomem) = memio.fixed_vstream(buf[0:16]);\n"
" let vs: io.vstream = nil: *io.vtable;\n"
" match (r) {\n"
" case let v: io.vstream => { vs = v; };\n"
" case nomem => { return 90; };\n"
" };\n"
" let st: memio.stream = memio.fixed_vstream(buf[0:16]);\n"
" let vs: io.vstream = &st.vt;\n"
" let wr = fmt.vfprintln(vs, 1i64, \"hi\", true);\n"
" let nw: size = 0;\n"
" match (wr) {\n"
@@ -203,7 +199,7 @@ static const struct row rows[] = {
" case io.error => { return 91; };\n"
" };\n"
" if (nw != 10: size) { return 92; };\n"
" let view: str = memio.fixed_string(vs);\n"
" let view: str = memio.string_v(&st);\n"
" if (view.len != 10) { return 93; };\n"
" if (view[0] != 49u8) { return 94; };\n"
" if (view[1] != 32u8) { return 95; };\n"
@@ -221,12 +217,8 @@ static const struct row rows[] = {
"import memio;\n"
"export fn main() i32 = {\n"
" let buf: [16]u8;\n"
" let r: (io.vstream | nomem) = memio.fixed_vstream(buf[0:16]);\n"
" let vs: io.vstream = nil: *io.vtable;\n"
" match (r) {\n"
" case let v: io.vstream => { vs = v; };\n"
" case nomem => { return 90; };\n"
" };\n"
" let st: memio.stream = memio.fixed_vstream(buf[0:16]);\n"
" let vs: io.vstream = &st.vt;\n"
" let wr = fmt.vfprintfln(vs, \"x={}\", 7i64);\n"
" let nw: size = 0;\n"
" match (wr) {\n"
@@ -234,7 +226,7 @@ static const struct row rows[] = {
" case io.error => { return 91; };\n"
" };\n"
" if (nw != 4: size) { return 92; };\n"
" let view: str = memio.fixed_string(vs);\n"
" let view: str = memio.string_v(&st);\n"
" if (view.len != 4) { return 93; };\n"
" if (view[0] != 120u8 || view[1] != 61u8) { return 94; };\n"
" if (view[2] != 55u8 || view[3] != 10u8) { return 95; };\n"