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).
This commit is contained in:
9
Makefile
9
Makefile
@@ -329,6 +329,7 @@ TESTS = $(BIN)/test_smoke $(BIN)/test_lex $(BIN)/test_parse $(BIN)/test_check \
|
||||
$(BIN)/test_memio_vstream_run \
|
||||
$(BIN)/test_fmt_vstream_run \
|
||||
$(BIN)/test_fmt_vstream_mods_run \
|
||||
$(BIN)/test_fmt_vstream_compositions_run \
|
||||
$(BIN)/test_bufio_vstream_run \
|
||||
$(BIN)/test_log_vstream_run \
|
||||
$(BIN)/test_use_promote_alias \
|
||||
@@ -714,6 +715,14 @@ $(BIN)/test_fmt_vstream_mods_run: test/wcc/780_fmt_vstream_mods_run.c \
|
||||
$(LIB)/libwwrt.a | $(BIN)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
$(BIN)/test_fmt_vstream_compositions_run: test/wcc/781_fmt_vstream_compositions_run.c \
|
||||
$(BIN)/ww $(BIN)/w6c $(BIN)/w6a $(BIN)/w6l \
|
||||
$(BIN)/ww_ww $(BIN)/w6c_ww $(BIN)/w6a_ww $(BIN)/w6l_ww \
|
||||
lib/fmt/fmt.ww lib/fmt/vstream.ww \
|
||||
lib/memio/memio.ww lib/memio/vstream.ww \
|
||||
$(LIB)/libwwrt.a | $(BIN)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
$(BIN)/test_bufio_vstream_run: test/wcc/778_bufio_vstream_run.c \
|
||||
$(BIN)/ww $(BIN)/w6c $(BIN)/w6a $(BIN)/w6l \
|
||||
$(BIN)/ww_ww $(BIN)/w6c_ww $(BIN)/w6a_ww $(BIN)/w6l_ww \
|
||||
|
||||
Reference in New Issue
Block a user