io.empty (discard+EOF stream, ref/hare/io/empty.ha:4-17) — needed by getopt's two-pass printusage width measurement. Diverges from Hare's `const empty: *stream`: a `let _empty_vt` + `fn empty()` that wires the fn-ptr slots per call, because const-init of a vtable struct with fn-ptr fields is blocked (#118, ruled accept). Co-discovered while making empty() byte-identical across stages: three wwstage-only cgen fixes (cstage was already correct; wwstage aligned down): - #129 sretretsize: consult the same-module pointer-alias before structlookup's any-module struct fallback (io.stream = *vtable was mis-sized as memio's 56B struct -> spurious sret save). - #129 callsretsize: swap curmod to the callee's module before sret-size classification (cross-module callee context). - #130 cgassign global-struct tagged-union field store: add the missing arm (was a 1-word store) mirroring cstage cgen.c:4893-4912. The three are inseparable from io.empty here — splitting them out leaves a divergent-asm intermediate (993/995 red), so they ride one commit per the one-class gate-repair carve-out (#133-expanded precedent). Regenerates the embedded combined.ww; 989_lib_byteid pins bufio + fmt graduated to M_ID. (cgenexpr.ww fix-3 inline comment cites the #129 cluster; narrow to #130 on next touch to avoid a regen for a comment.)
27 lines
1.3 KiB
Plaintext
27 lines
1.3 KiB
Plaintext
// io — stream interface (Plan 9 Bio / Hare io::stream shape).
|
|
//
|
|
// No closures, no methods. A `stream` is a pointer to a `vtable` of
|
|
// function pointers (lib/io/stream.ww); read/write/close dispatch
|
|
// through it. The error channel is the return value — Hare-shaped
|
|
// tagged unions instead of errno-style integer sentinels.
|
|
//
|
|
// This file owns the eof / underread variant tags; lib/io/stream.ww
|
|
// owns the `vtable` + `stream` + read/write/close dispatchers and the
|
|
// [[empty]] singleton, and lib/io/types.ww owns the error union,
|
|
// mode/whence enums, and the reader/writer/closer fn-type aliases.
|
|
// #94 fold-eFinal collapsed the pre-vtable `stream` struct + `closed`
|
|
// tag into the single vtable surface; the dispatchers are read/write/
|
|
// close (over `stream`), final over `handle` at io fold-2 (#5).
|
|
package io;
|
|
|
|
// eof — read past the end of the stream. Hare uses the `done`
|
|
// singleton for EOF; ww doesn't have `done` yet so we ship a
|
|
// named-void variant tag. Lifts to `done` with #93.
|
|
export type eof = void;
|
|
|
|
// underread — an I/O handle hit eof partway through a fixed-size
|
|
// read. Payload is the byte count actually delivered. Mirrors
|
|
// Hare's `io::underread = !size`; ww uses i32 because the
|
|
// underlying buffer-length type is i32 today.
|
|
export type underread = !i32;
|