The Option-C parallel _v vstream API was scaffolding to bring the io stack up alongside the old surface; carrying both permanently is a rule-9 divergence from ref/hare, which has exactly one io surface. Collapse onto that surface (stream = *vtable, ref/hare/io/stream.ha) and rename the _v symbols to their Hare names (io vstream->stream, fmt vfprint->fprint, bufio/memio/log surfaces, log.new). Deletes the 4 lib/*/vstream.ww scaffold files; regenerates w6c/wwdump combined.ww. cstage and wwstage stay byte-identical and combined_ww_fresh holds; all 220 tests pass.
83 lines
3.1 KiB
Plaintext
83 lines
3.1 KiB
Plaintext
// stream — Hare-shaped vtable surface. Project #94 fold-eFinal.
|
||
//
|
||
// The single io stream surface (the fold-eFinal collapse retired the
|
||
// pre-vtable `stream` struct + `closed` tag). Three exports:
|
||
//
|
||
// vtable a struct of optional fn-pointer slots — reader/writer/
|
||
// closer per ref/hare/io/stream.ha:36-42. Hare spells the
|
||
// nullable as `nullable *T`; ww parser rejects that
|
||
// spelling (#192), so each slot is a `(*T | void)` tagged
|
||
// union (Plan-9-lean per the Nullable kept ruling; opt-in
|
||
// at optionality boundaries only).
|
||
// stream `*vtable` alias matching Hare's `stream = *vtable`
|
||
// (ref/hare/io/stream.ha:33).
|
||
// read /
|
||
// write /
|
||
// close the three dispatchers per ref/hare/io/stream.ha:44-68.
|
||
// Each `match`es the matching vtable slot, returns
|
||
// `errors.unsupported` (widened twice) when the slot is
|
||
// void, otherwise calls through the fn pointer. Hare keeps
|
||
// these private (`st_read` …) behind a `handle`-typed
|
||
// public `read`/`write`/`close`; ww has no `handle` yet
|
||
// (io fold-2, #5), so the dispatchers ARE the public
|
||
// surface and grow the `handle` match when #5 lands.
|
||
//
|
||
// Deferrals (drew-signed): `seeker` lands with io fold-2 (#5) once `off`
|
||
// + `whence` plug into the signature. Hare's `?`-propagating `close`
|
||
// body (`c(s)?;`) collapses to a direct `return (*c)(s);` here because
|
||
// the dispatcher's surface stays Hare-shaped; only the internal
|
||
// try-prop is omitted (#173 history, now closed — kept direct for the
|
||
// void-arm fall-through shape).
|
||
|
||
package io;
|
||
|
||
// ref/hare/io/stream.ha:36-42. Nullable spelling per #192 (ww parser
|
||
// rejects `nullable *T`); each slot is `(*T | void)`.
|
||
export type vtable = struct {
|
||
reader: (*reader | void),
|
||
writer: (*writer | void),
|
||
closer: (*closer | void),
|
||
};
|
||
|
||
// ref/hare/io/stream.ha:33.
|
||
export type stream = *vtable;
|
||
|
||
// ref/hare/io/stream.ha:44-50. The void-arm `return e;` chains two
|
||
// direct widens: `errors.unsupported → error` via #199 α, then
|
||
// `error → (size | eof | error)` via #205. The call-arm spells the
|
||
// fn-ptr call explicitly per #193 (ww requires `(*r)(args)` rather
|
||
// than implicit `r(args)`).
|
||
export fn read(s: stream, buf: []u8) (size | eof | error) = {
|
||
match (s.reader) {
|
||
case void => {
|
||
let u: errors.unsupported;
|
||
let e: error = u;
|
||
return e;
|
||
};
|
||
case let r: *reader => return (*r)(s, buf);
|
||
};
|
||
};
|
||
|
||
// ref/hare/io/stream.ha:53-59.
|
||
export fn write(s: stream, buf: []u8) (size | error) = {
|
||
match (s.writer) {
|
||
case void => {
|
||
let u: errors.unsupported;
|
||
let e: error = u;
|
||
return e;
|
||
};
|
||
case let w: *writer => return (*w)(s, buf);
|
||
};
|
||
};
|
||
|
||
// ref/hare/io/stream.ha:62-68. Hare propagates the close error via
|
||
// `c(s)?;` then falls through to the void arm; ww collapses to a
|
||
// direct return for the void-arm fall-through shape. The surface
|
||
// (void | error) matches.
|
||
export fn close(s: stream) (void | error) = {
|
||
match (s.closer) {
|
||
case void => return void;
|
||
case let c: *closer => return (*c)(s);
|
||
};
|
||
};
|