Files
ww/lib/io/empty.ww
Hojun-Cho e5379848de lib: split io empty stream into empty.ww per ref/hare/io/empty.ha
Pure file-boundary move of lib/io/stream.ww's single 'empty stream'
banner section (_empty_read, _empty_write, _empty_vt, empty) into
lib/io/empty.ww, mirroring ref/hare/io/empty.ha. No code, name,
signature, or behavior change. Comment-only adjustments: the banner
line is deleted (the file name carries it); the moved block's
'Lives in stream.ww' self-reference now says empty.ww; stream.ww's
head drops its empty bullet (content duplicated by empty.ww's own
comments); io.ww's ownership map gains the empty.ww line; types.ww's
'three files' count becomes four. empty.ww needs no imports (package
io types only).

Makefile: lib/io/empty.ww added beside every lib/io/stream.ww
occurrence (WWFIXTURE_SRC line 75; w6c_ww/wwdump_ww bootstrap prereq
lists at lines 184/204). lib/io has no _test.ww, so no LIBRARY_TESTS
or byteid-roster change; byteid coverage rides the bootstrap gates.

Validation: out/bin/w6c lib/io/io.ww (standalone contract) exit 0;
importer tests green: bufio 26, memio 11, log 11, getopt 12 (calls
io.empty), fmt 49.
2026-08-08 17:17:42 +09:00

34 lines
1.2 KiB
Plaintext

// ref/hare/io/empty.ha:4-17.
//
// Hare uses `const _empty_vt: vtable = { ... }` + `const empty: *stream`.
// ww can't const-init a vtable struct with fn-ptr fields (#118), so the
// vtable is a module-level `let` and [[empty]] is a function that wires
// the fn-ptr slots on every call and returns the stream pointer.
// Single-assignment on the same words: idempotent under re-entry.
// Lives in empty.ww (not io.ww) so io.ww stays standalone without
// referencing the cross-file vtable/reader/writer types.
package io;
fn _empty_read(s: stream, buf: []u8) (size | eof | error) = {
let e: eof;
return e;
};
fn _empty_write(s: stream, buf: []u8) (size | error) = {
return buf.len: size;
};
let _empty_vt: vtable;
// empty — a stream that discards all writes (returning their size) and
// returns EOF on every read. Mirrors ref/hare/io/empty.ha:13.
// #118: const vtable init with fn-ptr fields is unwired (emit_struct_data
// needs a two-pass reloc extension, node_fnptr_sym reusable). Using a
// mutable let + per-call wiring until #118 lands.
export fn empty() stream = {
_empty_vt.reader = (&_empty_read): *reader;
_empty_vt.writer = (&_empty_write): *writer;
return &_empty_vt;
};