80184a3acfd7a321cdbacae06367ba1c700a93bb
5 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
| 10cb835f99 |
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). |
|||
| df287846c5 |
lib/fmt: port V-side fprintln/fprintfln/bsprintf/asprintf (#94 fold-e7)
V had vfprint / vfprintf but no compositions over them, so callers needing the newline / printf-newline / bounded-buffer / heap-grow shapes still routed through the OLD io.stream-shaped fprintln / fprintfln / bsprintf / asprintf. Port the four compositions into vstream.ww as the v* twins: vfprintln + vfprintfln chain a "\n" vputbytes after the underlying primitive; vbsprintf threads a caller buffer through memio.fixed_vstream and returns the prefix view; vasprintf grows through memio.dynamic_vstream and shrink-copies to a tight allocation before io.st_close. Bundles the two memio enablers (fixed_string / dynamic_string in lib/memio/vstream.ww) that vbsprintf / vasprintf depend on directly, per drew-approved exception to one-class-one-commit (feedback_refactor_routing_same_class_drops applies — helpers are direct prereqs, not unrelated churn; the bus-routing site lives in v* fmt code, not in memio). They mirror OLD memio.string (memio.ww: 102) over the per-flavour *fixed_ctx / *dynamic_ctx intrusive cast, same shape as the read/write callback split at memio/vstream.ww:144. Mirror sites: vfprintln fmt.ww:240 fprintln ref/hare/fmt/wrappers.ha:48 vfprintfln fmt.ww:740 fprintfln ref/hare/fmt/wrappers.ha:69 vbsprintf fmt.ww:839 bsprintf ref/hare/fmt/wrappers.ha:42 vasprintf fmt.ww:873 asprintf ref/hare/fmt/wrappers.ha:29 Divergence vs Hare on vbsprintf: Hare returns `(const str | nomem)`; ww collapses to `(str | io.error)` so the underlying vfprintf io.error arm stays uniform. The fixed_vstream nomem widens into io.error explicitly (no `memio.fixed_vstream(buf)?`) because #173 (TRY-on- tagged-return both-stages broken) is still open — same shape memio/ vstream.ww adopted at line 87-99 for fixed_vstream itself. vasprintf keeps OLD's bare `str` return (no nomem variant on public surface). ken cs==ww mechanical: additive only, both stages compile identically. fmt is NOT embedded in any selfhost main.combined.ww (grep verified pre-impl: zero `^package fmt;` hits in selfhost/cmd/*/main.combined. ww). memio.vstream.ww IS embedded in w6c + wwdump combined.ww (lib/ ww/cgen.ww uses memio.dynamic for buffer growth); the two memio helpers regen-and-commit via ww build per #110 SSoT. test/wcc/781_fmt_vstream_compositions_run.c (cstage-only per #209): 4 rows pin all four V wrappers — fdprintln_v_run_basic (newline shape), fdprintfln_v_run_fmt ({n}-placeholder + newline), bsprintf_v_basic (fixed buffer + returned view + caller bytes), asprintf_v_basic (owned heap str + os.free roundtrip). Mirror of 777/780 cstage carve- out (#209 wwstage formattable match-arm bail). Byte-id graduates with #209 close. 214 total tests green (was 213). |
|||
| a3f3153943 |
lib/fmt: port V-side modifier formatting (#94 fold-e6)
V's vfprintf parsed mods via scanmods but dropped them after parse — vformatfield routed straight to vwriteone (no width / alignment / pad / sign / base / prec honoured). Port the OLD modifier path (fmt.ww: 443-641 rawlen* / formatraw / formatone) into vstream.ww as the v* twins, widen vformatfield to take *mods, and pass &m through vfprintf at the call site. The v* helpers mirror OLD verbatim (compute body identical; vputbytes + (size | io.error) routing replacing putbytes + (i32 | io.closed)); shared compute helpers (signof / digitsu64 / basenum) and modifier enums (neg / alignment / mods) are reused directly from fmt.ww via package scope. fmt.ww UNCHANGED — fold-eFinal (#50) collapses both surfaces and dedupes the rawlen-family. drew NaN/Inf signoff: strconv.f64tos / f32tos already render "nan"/"infinity" with no leading '-', so the sign-peel in vrawlenf64 + vformatraw f64 arm is a no-op on those views (same OLD path at fmt.ww:520-562). ken cs==ww mechanical: both stages compile the new V-side identically; 990-997 byte-id gates + combined_ww_fresh stay green (fmt is not embedded in any selfhost main.combined.ww — grep verified pre-impl). test/wcc/780_fmt_vstream_mods_run.c (cstage-only per #209): 5 rows covering width / precision / base_hex / sign_plus / zero_pad. STAGE_WW blocked by #209 (wwstage formattable match-arm bail), same carve-out as 777_fmt_vstream_run. |
|||
| d87ee01cdf |
lib/log: add Option C parallel vstream API (#94 fold-e5)
Last per-caller migration before fold-eFinal (#50). Adds the 10 _v variants of OLD log.ww's surface (new_v / lprintln_v / println_v / lprintfln_v / printfln_v / lfatal_v / fatal_v / lfatalf_v / fatalf_v / setlogger_v) alongside a vlogger vtable + vstdlogger over io.vstream. Default sink is a module-static stderrsink_ctx_g with vt FIRST field for the intrusive vstream cast and fd=2 — only scalars/ptrs beyond vt per ken's mandate, no nested aggregates that would bite #18, no f32 per #165b. Zero-init at link time per #129 A.2/A.3 SSoT; ensureinit_v wires vt.reader / vt.writer / fd lazily on first dispatch (mirror of OLD ensureinit at log.ww:122 + lib/temp's rnginit pattern). OLD lib/log/log.ww UNCHANGED. fold-eFinal (#50) atomically retires the OLD logger / stdlogger / globals + the pre-vtable stderrsink and drops the `_v` suffix wholesale to match Hare's bare names. Two `export` bumps on lib/fmt/vstream.ww (vfprint, vfprintf) so log's stdprintln_v / stdprintfln_v dispatch through the existing vstream-side formatters; additive exposure, eFinal collapses fprint over the unified surface. Bootstrap-embed check: log is NOT in any selfhost/cmd/*/main.combined.ww (grep `package log\|import log` returns empty pre-impl). The fmt vstream.ww changes are also non-embedded. 990-997 byte-id gates stay green by virtue of log being test-only and the touched fmt symbols not being embedded. Probe wcc/779_log_vstream_run pins the additive surface across 4 rows (println_v_default_stderr / printfln_v_default_stderr / lprintln_v_custom_sink / branched_lprintln_v) cstage-only per #209 (wwstage formattable match-arm bail; bites OLD log.println identically). Byte-id graduates when #209 lands. Cite refs: ref/hare/log/{logger,funcs,global,silent}.ha; drew acks on module-static stderrsink_ctx + intrusive vt + 10-fn _v parity; ken mandates on bootstrap byte-id mechanical + simple-ctx + #129 static-init. Sibling tasks parked (filed, NOT fixed): eFinal #50; #206 (2 cast sites at ensureinit_v); #173 (stderrwrite_v constructs nomem + widens to io.error); #209 (cstage-only). |
|||
| 2a405a4ad6 |
lib/fmt: add Option C parallel vstream API (#94 fold-e3)
Adds lib/fmt/vstream.ww with four new wrappers — fdprint_v / fdprintln_v / fdprintf_v / fdprintfln_v — that take a raw fd, stack- allocate an fd_ctx whose first field is `vt: io.vtable`, and dispatch through io.st_write on a vstream pointing at &c.vt (intrusive offset-0 cast — same shape as lib/memio/vstream.ww's fixed_ctx / dynamic_ctx in fold-e2). Coexists with the pre-vtable fdprint / fdprintln / fdprintf / fdprintfln in fmt.ww. ken's escape-risk discipline: every wrapper owns the fd_ctx slot for its frame only; the &c.vt vstream pointer is consumed inside the same function (passed through internal vfprint / vfprintf helpers) and never returned. Single tagged field (vt) lets the local default-zero plus chained `c.vt.X = …` assigns sidestep the multi-tagged-field copy drop (sibling #207) — no struct-lit init needed and c is a stack value, not an aliased pointer, so #195's chained-store carve-out doesn't bite either. Drew defer cited at the file head: io.handle (= file | int) is out-of-scope for this fold per fold-d/fold-e3 precedent; Hare's ref/hare/fmt/wrappers.ha:9-25 routes through the handle sum, and fdNNN_v collapses into bare fNNN_v once io fold-2 lands the port (filed inline as "io fold-2 handle port" backlog). Internal vfprint / vfprintf duplicate the per-arg and {n}- placeholder loops from fmt.ww (fprint:177, fprintf:676) because the OLD versions take *io.stream (the legacy struct) and fmt.ww stays UNCHANGED this fold. Shared bits — i64dec, modsinit, scandigits, scanmods, formattable, field, mods, fmtabort — are reused directly from fmt.ww. vformatfield mirrors the inline-per- arm dispatch shape OLD formatfield (fmt.ww:648) uses to dodge #18 silent miscompile of 24B return-by-value in for-loop context. Cast workaround per #206 at each vtable-fn-ptr-slot init (2 sites per wrapper, 8 total): bare `&fn_name` does not type-check as `(*<alias> | void)`. Same `(&fn): *io.<role>` cast shape that lib/memio/vstream.ww uses. Drops out wholesale when #206 closes. #173 workaround at fdsinkwrite_v: constructs nomem and widens to io.error explicitly rather than `os.trywrite(...)?` — same shape memio.vstream.ww line 71-74 note adopted. OLD fmt surface is UNCHANGED. fold-eFinal (task #50) atomically flips the package shape: deletes OLD wrappers + callbacks, renames _v suffix off, and migrates the few callers (with io fold-2's handle sum landing in the same flip). Probe test/wcc/777_fmt_vstream_run.c: 4 rows (fdprintf_v_int / fdprintln_v_multi / fdprint_v_raw / branched_fdprintf_v) open per-row /tmp output files, dispatch one V wrapper per row, reopen the file, read the bytes back, and assert both the exact byte content and a unique row-tagged exit constant. 4/4 fixtures total, all green via cstage. Cstage-only per row (no STAGE_WW, no byte_id) — pre-existing wwstage match-arm bug (sibling of #190, filed inline as #209): the wwstage checker bails `case: not a variant of scrutinee (X)` / `match: variant not handled (formattable)` on the OLD fmt.fdprint's match arms whenever any probe `import fmt;`s the package. The bug bites the OLD surface identically — even `fmt.errorln("hi")` from a probe trips the same trace. 970 fmttest dodges via cstage-only ww run; 995 self-rebuild dodges because no selfhost cmd transitively pulls fmt (err.ww imports fmt but no main.ww in cmd/{ww,w6c,w6a,w6l,wwdump} pulls err.ww in). Byte-id graduates when #209 closes — out-of-scope for the additive fold-e3. Combined.ww regen NO-OP: none of the five tracked combined.ww files (cmd/{ww,w6c,w6a,w6l,wwdump}/main.combined.ww) embed `package fmt;` — fmt is not in the dep graph of any selfhost binary. combined_ww_fresh stays green untouched. 210/210 tests passing (was 209; +1 for 777_fmt_vstream_run). |