Additive: keeps lib/io/io.ww's pre-vtable `stream` struct + `read`/`write`/`close` wrappers (fold-e2-eN migrates the legacy surface to vtable-backed implementations and retires it). lib/io/stream.ww — vtable struct (reader/writer/closer slots, spelled `(*T | void)` per #192 — ww parser rejects `nullable *T`), vstream = *vtable, and the st_read/st_write/st_close dispatchers per ref/hare/io/stream.ha:33-68. Void-arm `return e;` chains two direct widens: concrete `errors.unsupported` → `error` (#199 α) then `error` → (size|eof|error) (#205 NAMED-variant nominal at tagged→tagged subset). Hare's `?`-propagating st_close collapses to a direct `return (*c)(s);` because #173 is still open; the surface stays Hare-shaped. lib/io/types.ww — retarget reader/writer/closer fn-aliases from *stream to vstream. Extend `error` union to include `errors.unsupported` explicitly (no spread — per ken's #204-block the wrapper-vs-flatten layout asymmetry would mis-widen; the deferred fix is filed as #199b layout-extension). test/wcc/775_io_vtable_run.c — 7-row sentinel: reader/writer/ closer × {set, void} happy paths + branched-callee runtime. Rows verify the call runs + the constant exit; the void-arm rows do NOT inspect the resulting variant tag (deferred #199b wrapped-slot tag-remap mis-routes to dst tag 0). Cstage and wwstage emit byte-identical asm on every row. test/wcc/768_io_types_run.c — track the alias retarget; rows now build a vtable, pass `&vt` (= vstream), and call through the fn-VALUE param shape. Combined.ww regen for w6c + wwdump per #110: lib/errors lands transitively via the new `import errors;` in types.ww. Sibling filed inline (NOT fixed): the checker rejects bare `&fn_name` / `let p: *alias = &fn` assignment to a `(*alias | void)` field — the structural `*fn(...)` value isn't accepted as the `*alias` NAMED variant. Both stages reject. Probes route around via explicit `(&fn): *io.reader` cast at each vtable-field assignment.
63 lines
2.6 KiB
Plaintext
63 lines
2.6 KiB
Plaintext
// types — error union, mode/whence enums, reader/writer/closer
|
|
// fn-type aliases. Project #94 fold-1 step (d) (drew Fold D); the
|
|
// fn-aliases re-targeted from *stream → vstream as part of fold-e1
|
|
// (vtable port in stream.ww).
|
|
//
|
|
// Hare splits the io module across stream.ha + types.ha and ww does
|
|
// the same: lib/io/io.ww owns the (pre-vtable) `stream`, `eof`, and
|
|
// `underread` shapes; lib/io/stream.ww owns the Hare vtable port
|
|
// (`vtable`, `vstream`, `st_read`/`st_write`/`st_close` dispatch);
|
|
// this file owns the surrounding port. The three files share
|
|
// `package io;` so cross-file refs resolve via the dir-enum concat
|
|
// order (io.ww < stream.ww < types.ww — `vstream` lands before the
|
|
// reader/writer/closer aliases below).
|
|
//
|
|
// Deferrals (drew-signed): `handle`, `seeker`, `copier`, `strerror`
|
|
// land with fold-e2+ (need the `handle` sum). Hare's `EOF = done`
|
|
// stays as `io.eof` until the `done` singleton ships (#93).
|
|
|
|
package io;
|
|
|
|
import errors;
|
|
|
|
// ref/hare/io/types.ha:29-34. RDWR is spelled `3` rather than Hare's
|
|
// `READ | WRITE` because the ww parser doesn't fold expressions in
|
|
// enum value positions; the value SSoT stays the same bitfield.
|
|
export type mode = enum u8 {
|
|
NONE = 0,
|
|
READ = 1,
|
|
WRITE = 2,
|
|
RDWR = 3,
|
|
};
|
|
|
|
// ref/hare/io/types.ha:37-41. Hare leaves the underlying implicit;
|
|
// ww requires one. i32 matches the off type that fold-e2 will plug
|
|
// into the seeker signature.
|
|
export type whence = enum i32 {
|
|
SET = 0,
|
|
CUR = 1,
|
|
END = 2,
|
|
};
|
|
|
|
// ref/hare/io/types.ha:11 spreads `...errors::error` into the union;
|
|
// ww enumerates the tags explicitly (ken's #204-block — spread of an
|
|
// errors-side tagged into this union triggers a wrapper-vs-flatten
|
|
// layout mismatch; #199b layout-extension is the deferred fix). The
|
|
// st_read/st_write dispatchers in stream.ww return
|
|
// `errors.unsupported` when the matching vtable slot is unset, so the
|
|
// variant lands here directly.
|
|
export type error = !(errors.unsupported | underread | nomem);
|
|
|
|
// ref/hare/io/types.ha:46. `eof` (not Hare's `done`) per the io.ww:8
|
|
// rationale; lifts to `done` with #93. `vstream` forward-refs the
|
|
// `*vtable` alias in stream.ww — the dispatcher receives the vtable
|
|
// pointer directly (Hare's stream.ha:33 + types.ha:46 collapse).
|
|
export type reader = fn(s: vstream, buf: []u8) (size | eof | error);
|
|
|
|
// ref/hare/io/types.ha:51. No `const` qualifier — ww has none, and
|
|
// lib/io/io.ww:30 + lib/sort/sort.ww:18 drop it the same way.
|
|
export type writer = fn(s: vstream, buf: []u8) (size | error);
|
|
|
|
// ref/hare/io/types.ha:55.
|
|
export type closer = fn(s: vstream) (void | error);
|