lib: fmt fprint family over io.handle; remove the fdsink workaround (#5)

Graduates the fmt fprint family (fprint/fprintf/fprintln/fprintfln + internal putbytes/writeone/format*) from io.stream to io.handle, so a file (fd) prints directly through io.write's file-arm (commit-1). Removes the fdsink placeholder -- the fake-stream-vtable-over-os.write shim that stood in for the missing handle. The 8 stdio wrappers route over os.STD{OUT,ERR}_FILENO (new i32 filenos in lib/os; os is the import floor, so it can't hold an io.file-typed handle like Hare's os::stdout_file -- consumers cast i32 to io.file). Migrates the fd-shim sentinel tests 777/780/781 to fprint-over-handle as their headers designed, cstage-only per the pre-existing #209 (fmt is wwstage-uncompilable). Regenerates the 6 os-embedding combined.ww.
This commit is contained in:
2026-05-31 18:51:12 +09:00
parent 06c00e0e1b
commit 497f1fa0d3
15 changed files with 348 additions and 384 deletions

View File

@@ -1696,7 +1696,7 @@ static const struct row rows[] = {
"fn main() i32 = { return sumtag(1i64, \"hi\", true): i32; };", 42 },
/* Variadic forwarding: `wrap(args...)` passes the local slice
* directly to `sum`, no re-gather. Mirrors Hare's wrapper shape
* (`fn println(args: formattable...) = fdprintln(os.stdout, args...)`). */
* (`fn println(args: formattable...) = fprintln(os.stdout, args...)`). */
{ "fn sum(args: i64...) i64 = {\n"
" let s: i64 = 0i64;\n"
" let i: i32 = 0;\n"
@@ -1711,11 +1711,12 @@ static const struct row rows[] = {
"};", 42 },
/* lib/fmt user-side: `fmt.println(args: formattable...)` gathers
* mixed-type args at the call site. End-to-end exercises the
* lib/fmt graduation: the wrapper-chain `println → fdprintln →
* fdprint` is itself variadic-forwarding, so this validates both
* gather (at main) and `args...` forward (inside lib/fmt). println
* returns Hare's `(size | io.error)` (#94 fold-eFinal); the size
* arm carries bytes printed (`hello 7\n` = 8). */
* lib/fmt graduation: the wrapper-chain `println → fprintln →
* fprint` over an io.handle file arm is itself variadic-forwarding,
* so this validates both gather (at main) and `args...` forward
* (inside lib/fmt). println returns Hare's `(size | io.error)`
* (#94 fold-eFinal); the size arm carries bytes printed
* (`hello 7\n` = 8). */
{ "import fmt;\n"
"import io;\n"
"fn main() i32 = {\n"

View File

@@ -1,86 +1,66 @@
/*
* 777_fmt_vstream_run project #94 fold-eFinal sentinel. Pins the
* single-surface lib/fmt fd shim: stack-resident fd_ctx with
* `vt: io.vtable` as the first field for the intrusive io.stream
* cast, four wrappers (fdprint / fdprintln / fdprintf / fdprintfln)
* that take a raw fd, allocate fd_ctx on their own frame (never
* escapes ken's dispatcher-CONTAINED discipline), and dispatch
* through io.write via the wired fdsinkwrite callback. The fd shim
* has no Hare counterpart; it folds into fNNN-over-handle once io
* fold-2 (#5) ports `handle = (file | int)`.
* 777_fmt_handle_run io fold-2 (#5) commit-2 sentinel. Pins the
* fprint family over an [[io.handle]] sink after the fdsink shim
* removal: fmt's fprint/fprintln/fprintf now take `io.handle =
* (io.file | io.stream)`, so a raw fd (file arm) and a memio vtable
* (stream arm) both flow into the same surface and io.write dispatches
* per arm. Supersedes the pre-#5 fd_ctx workaround (the fake-stream
* vtable around os.write) drew's placeholder for the then-missing
* handle, removed by this commit.
*
* Each row imports fmt + os + io, opens a per-process /tmp output
* file, calls one V wrapper to write through the fd, closes, re-
* opens for read, reads the bytes back, and asserts both (a) the
* exact byte content and (b) a unique row-tagged exit constant.
* The file-arm rows open a per-process /tmp output file, call one
* fprint-family fn with `fd: io.file` (widens to io.handle), close,
* reopen for read, read the bytes back, and assert both (a) the exact
* byte content and (b) a unique row-tagged exit constant. The
* stream-arm row drives the SAME fprintf over a memio.fixed vtable
* (the io.stream arm) and reads back via memio.string the two-arm
* coverage #5 graduated.
*
* Cstage-only per row (no STAGE_WW, no byte_id) pre-existing
* wwstage bug #209 (sibling of #190): the wwstage checker bails
* `case: not a variant of scrutinee (X)` + `match: variant not
* handled (formattable)` on the OLD fmt.fdprint / fdprintf's
* match-on-formattable arms whenever a downstream probe `import
* fmt;`s the package. The bug bites the OLD surface identically
* `fmt.errorln("hi")` from a probe trips the same trace. The
* pre-existing surface (fmt.ww) is fine via cstage because every
* other test that uses fmt is cstage-only (970 fmttest runs the
* @test fixture under cstage `ww run` only). 995 self-rebuild
* dodges it because no selfhost cmd imports fmt transitively
* fmt is consumed by selfhost/cmd/wcc/err.ww but no main.ww in
* cmd/{ww,w6c,w6a,w6l,wwdump} pulls err.ww in. Fix-of-the-bug =
* one-class checker repair, out-of-scope for the additive
* fold-e3; closes the wwstage half here when it lands. Byte-id
* graduates with #209 close.
* Cstage-only per row (no STAGE_WW, no byte_id) pre-existing wwstage
* bug #209 (sibling of #190): the wwstage checker bails `case: not a
* variant of scrutinee (X)` + `match: variant not handled
* (formattable)` on fmt's match-on-formattable arms whenever a
* downstream probe `import fmt;`s the package. The bug bites identically
* `fmt.errorln("hi")` from a probe trips the same trace and is
* pre-existing (reproduces on master). Every fmt test is cstage-only
* (970 fmttest runs the @test fixture under cstage `ww run` only); 995
* self-rebuild dodges it because no selfhost main pulls err.ww
* transitively, so wwstage never compiles fmt in the bootstrap. Fix =
* one-class checker repair, out of #5 commit-2 scope; byte-id graduates
* with #209 close.
*
* row | what it pins
* --------------------------+--------------------------------------
* fdprintf_v_int | fdprintf with `"v={}\n"`-style
* | format + one i64 arg. Asserts the
* | full intrusive shape (stack fd_ctx
* | &c.vt io.write fdsinkwrite
* | os.write) plus the {n}-placeholder
* | parser routed through vformatfield.
* fdprintln_v_multi | fdprintln with three positional
* | args (i64 + str + bool). Asserts the
* | space-separator + trailing newline
* | shape mirrors OLD fdprintln (fmt.ww:
* | 145), routed through io.write.
* fdprint_v_raw | fdprint with one str arg, no
* | format mods (zero-format raw). Pins
* | the per-arg loop without the
* | placeholder parser (fprint code
* | path, fmt.ww).
* branched_fdprintf | branched callee per #105: two
* | distinct format strings runtime-
* | selected from a single fdprintf
* | call site. Catches a constant-fold
* | mistake in the format-string
* | dispatch (mirror of 776's
* | branched_fixed for the format-side).
* row | what it pins
* ---------------------+--------------------------------------
* fprintf_file_int | fprintf(fd: io.file, "v={}\n", 42)
* | over the FILE arm -> io.write -> os.write,
* | plus the {n}-placeholder parser through
* | formatfield.
* fprintln_file_multi | fprintln(fd: io.file, 7, "hi", true)
* | three positional args, space-separator
* | + trailing newline shape over the file arm.
* fprint_file_raw | fprint(fd: io.file, "raw") one str arg,
* | no placeholder parser (bare fprint loop).
* branched_fprintf | branched callee per #105: two distinct
* | format strings runtime-selected from a
* | single fprintf call site.
* fprintf_stream | fprintf over a memio.fixed io.stream
* | (the STREAM arm of io.handle) read back
* | via memio.string the other handle arm.
*
* IMPORT-ORDER WORKAROUND (sibling task #208, pre-existing): every
* row places `import os;` FIRST for the same reason 776 documents
* (wwstage checker ordering-sensitivity on os.tryread/trywrite/
* tryopen's bare `return r;` over a tagged return type).
* IMPORT-ORDER WORKAROUND (sibling task #208, pre-existing): every row
* places `import os;` FIRST for the same reason 776 documents (wwstage
* checker ordering-sensitivity on os.tryread/trywrite/tryopen's bare
* `return r;` over a tagged return type).
*
* DEFERRALS / RELATED (NOT addressed by these rows):
* BOOTSTRAP-EMBED CHECK: fmt is NOT embedded in any selfhost
* combined.ww (grep confirmed), so the #5 fmt graduation does NOT
* require a Makefile regen (#110); 990-997 byte-id gates stay green by
* virtue of fmt being test-only on the bootstrap surface.
*
* - io fold-2 (handle port): drew-deferred. Hare's
* ref/hare/fmt/wrappers.ha:9-25 routes through io::handle; fdNNN
* collapses into bare fNNN once handle = (file | int) lands.
* #5 graduates.
*
* - #206 (bare &fn (*alias|void)): 2 cast sites per wrapper
* vtable wire-up; explicit casts KEPT (ken/#214 cast-drop
* deferred, gated on #214).
*
* - #173 (TRY-on-tagged-return both-stages broken): fdsinkwrite
* constructs nomem and widens to io.error explicitly rather
* than using `os.trywrite(...)?`; same shape memio.ww adopts.
*
* GATE POLARITY: must stay GREEN. A red here means lib/fmt
* regressed, the stack fd_ctx io.stream cast miscomputed offsets,
* the {n}-placeholder dispatch through formatfield regressed, or
* io.vtable's first-field embed lost its offset-0 invariant.
* GATE POLARITY: must stay GREEN. A red here means lib/fmt regressed,
* the file->handle widen miscompiled, io.write's per-arm dispatch broke,
* the {n}-placeholder dispatch through formatfield regressed, or the
* memio stream arm lost its offset-0 vtable invariant.
*/
#include <stdio.h>
#include <stdlib.h>
@@ -109,16 +89,16 @@ struct row {
};
static const struct row rows[] = {
{ "fdprintf_v_int",
{ "fprintf_file_int",
"package main;\n"
"import os;\n"
"import fmt;\n"
"import io;\n"
"export fn main() i32 = {\n"
" let path: str = \"/tmp/wwfmtv_777_a\";\n"
" let path: str = \"/tmp/wwfmth_777_a\";\n"
" let fd: i32 = os.open(path, os.flag.RDWR | os.flag.CREATE | os.flag.TRUNC, 0o644: i32);\n"
" if (fd < 0) { return 90; };\n"
" let wr = fmt.fdprintf(fd, \"v={}\\n\", 42i64);\n"
" let wr = fmt.fprintf(fd: io.file, \"v={}\\n\", 42i64);\n"
" let nw: size = 0;\n"
" match (wr) {\n"
" case let n: size => { nw = n; };\n"
@@ -137,16 +117,16 @@ static const struct row rows[] = {
"};\n",
42,
STAGE_CS, 0 },
{ "fdprintln_v_multi",
{ "fprintln_file_multi",
"package main;\n"
"import os;\n"
"import fmt;\n"
"import io;\n"
"export fn main() i32 = {\n"
" let path: str = \"/tmp/wwfmtv_777_b\";\n"
" let path: str = \"/tmp/wwfmth_777_b\";\n"
" let fd: i32 = os.open(path, os.flag.RDWR | os.flag.CREATE | os.flag.TRUNC, 0o644: i32);\n"
" if (fd < 0) { return 90; };\n"
" let wr = fmt.fdprintln(fd, 7i64, \"hi\", true);\n"
" let wr = fmt.fprintln(fd: io.file, 7i64, \"hi\", true);\n"
" let nw: size = 0;\n"
" match (wr) {\n"
" case let n: size => { nw = n; };\n"
@@ -165,16 +145,16 @@ static const struct row rows[] = {
"};\n",
43,
STAGE_CS, 0 },
{ "fdprint_v_raw",
{ "fprint_file_raw",
"package main;\n"
"import os;\n"
"import fmt;\n"
"import io;\n"
"export fn main() i32 = {\n"
" let path: str = \"/tmp/wwfmtv_777_c\";\n"
" let path: str = \"/tmp/wwfmth_777_c\";\n"
" let fd: i32 = os.open(path, os.flag.RDWR | os.flag.CREATE | os.flag.TRUNC, 0o644: i32);\n"
" if (fd < 0) { return 90; };\n"
" let wr = fmt.fdprint(fd, \"raw\");\n"
" let wr = fmt.fprint(fd: io.file, \"raw\");\n"
" let nw: size = 0;\n"
" match (wr) {\n"
" case let n: size => { nw = n; };\n"
@@ -193,13 +173,13 @@ static const struct row rows[] = {
"};\n",
44,
STAGE_CS, 0 },
{ "branched_fdprintf",
{ "branched_fprintf",
"package main;\n"
"import os;\n"
"import fmt;\n"
"import io;\n"
"export fn main() i32 = {\n"
" let path: str = \"/tmp/wwfmtv_777_d\";\n"
" let path: str = \"/tmp/wwfmth_777_d\";\n"
" let fd: i32 = os.open(path, os.flag.RDWR | os.flag.CREATE | os.flag.TRUNC, 0o644: i32);\n"
" if (fd < 0) { return 90; };\n"
" let sel: i32 = 1;\n"
@@ -207,7 +187,7 @@ static const struct row rows[] = {
" let f2: str = \"B{}\";\n"
" let fmtstr: str = f1;\n"
" if (sel == 0) { fmtstr = f2; };\n"
" let wr = fmt.fdprintf(fd, fmtstr, 9i64);\n"
" let wr = fmt.fprintf(fd: io.file, fmtstr, 9i64);\n"
" let nw: size = 0;\n"
" match (wr) {\n"
" case let n: size => { nw = n; };\n"
@@ -226,6 +206,30 @@ static const struct row rows[] = {
"};\n",
45,
STAGE_CS, 0 },
{ "fprintf_stream",
"package main;\n"
"import os;\n"
"import fmt;\n"
"import io;\n"
"import memio;\n"
"export fn main() i32 = {\n"
" let buf: [16]u8;\n"
" let st: memio.stream = memio.fixed(buf[0:16]);\n"
" let s: io.stream = &st.vt;\n"
" let wr = fmt.fprintf(s, \"v={}\\n\", 42i64);\n"
" let nw: size = 0;\n"
" match (wr) {\n"
" case let n: size => { nw = n; };\n"
" case io.error => { return 91; };\n"
" };\n"
" if (nw != 5: size) { return 94; };\n"
" let view: str = memio.string(&st);\n"
" if (view.len != 5) { return 93; };\n"
" if (view[0] != 118u8 || view[1] != 61u8 || view[2] != 52u8 || view[3] != 50u8 || view[4] != 10u8) { return 95; };\n"
" return 46;\n"
"};\n",
46,
STAGE_CS, 0 },
};
static int
@@ -269,7 +273,7 @@ static int
run_row(const char *driver, const char *cwd, const struct row *r, int seq)
{
char tmpdir[256], src[512], base[64], outbin[768];
snprintf(tmpdir, sizeof tmpdir, "/tmp/fvs_%d_d_%d", getpid(), seq);
snprintf(tmpdir, sizeof tmpdir, "/tmp/fh_%d_d_%d", getpid(), seq);
snprintf(base, sizeof base, "main777");
snprintf(src, sizeof src, "%s/%s.ww", tmpdir, base);
mkdir(tmpdir, 0755);
@@ -288,14 +292,16 @@ run_row(const char *driver, const char *cwd, const struct row *r, int seq)
/* asm_byte_identical — diff cstage vs wwstage .s. Parallel trees so
* ww_ww writing intermediates next to the source doesn't clobber the
* cstage .s (CLAUDE.md rule 14 phase split). Mirror of 776's. */
* cstage .s (CLAUDE.md rule 14 phase split). Mirror of 776's. Unused
* while every row is cstage-only (#209), kept for the byte-id
* graduation once #209 closes. */
static int
asm_byte_identical(const char *cdrv, const char *wdrv, const char *cwd,
const struct row *r, int seq)
{
char src[512], tdc[256], tdw[256], base[64], cs[512], ws[512];
snprintf(tdc, sizeof tdc, "/tmp/fvs_%d_c_%d", getpid(), seq);
snprintf(tdw, sizeof tdw, "/tmp/fvs_%d_w_%d", getpid(), seq);
snprintf(tdc, sizeof tdc, "/tmp/fh_%d_c_%d", getpid(), seq);
snprintf(tdw, sizeof tdw, "/tmp/fh_%d_w_%d", getpid(), seq);
snprintf(base, sizeof base, "main777");
mkdir(tdc, 0755);
mkdir(tdw, 0755);
@@ -350,6 +356,7 @@ main(void)
int total = 0, fail = 0;
int wwpresent = (access(wdrv, X_OK) == 0);
int seq = 0;
(void)asm_byte_identical; /* cstage-only until #209 closes */
for (int i = 0; i < n; i++) {
if (rows[i].stage_mask & STAGE_CS) {
@@ -357,7 +364,7 @@ main(void)
int got = run_row(cdrv, cwd, &rows[i], seq++);
if (got != rows[i].want_exit) {
fprintf(stderr,
"fmt_vstream_run[cs][%s]: exit=%d want=%d\n",
"fmt_handle_run[cs][%s]: exit=%d want=%d\n",
rows[i].label, got, rows[i].want_exit);
fail++;
}
@@ -367,7 +374,7 @@ main(void)
int got = run_row(wdrv, cwd, &rows[i], seq++);
if (got != rows[i].want_exit) {
fprintf(stderr,
"fmt_vstream_run[ww][%s]: exit=%d want=%d\n",
"fmt_handle_run[ww][%s]: exit=%d want=%d\n",
rows[i].label, got, rows[i].want_exit);
fail++;
}
@@ -375,7 +382,7 @@ main(void)
total++;
if (asm_byte_identical(cdrv, wdrv, cwd, &rows[i], seq++) != 0) {
fprintf(stderr,
"fmt_vstream_run[byte-id][%s]: cstage vs wwstage asm differs\n",
"fmt_handle_run[byte-id][%s]: cstage vs wwstage asm differs\n",
rows[i].label);
fail++;
}
@@ -384,13 +391,13 @@ main(void)
}
if (!wwpresent)
fprintf(stderr, "fmt_vstream_run: skip wwstage (no %s)\n", wdrv);
fprintf(stderr, "fmt_handle_run: skip wwstage (no %s)\n", wdrv);
if (fail) {
fprintf(stderr, "fmt_vstream_run: %d/%d fixtures failed\n",
fprintf(stderr, "fmt_handle_run: %d/%d fixtures failed\n",
fail, total);
return 1;
}
printf("fmt_vstream_run: %d/%d ok\n", total, total);
printf("fmt_handle_run: %d/%d ok\n", total, total);
return 0;
}

View File

@@ -1,21 +1,21 @@
/*
* 780_fmt_vstream_mods_run project #94 fold-eFinal sentinel. Pins the
* 780_fmt_mods_run io fold-2 (#5) commit-2 sentinel. Pins the
* modifier-formatting machinery (rawleni64 / rawlenstr / rawlenf64 /
* rawlen / formatraw / formatone) in lib/fmt/fmt.ww: formatfield takes
* `*mods` and routes through formatone so the {:mods} placeholder
* honours width / alignment / pad / sign / base / prec. The fold-eFinal
* FLIP collapsed the dual fmt surface into this one (the former `v*`
* modifier helpers merged into the bare names).
* honours width / alignment / pad / sign / base / prec. #5 graduated
* fprintf's sink io.stream -> io.handle; these rows drive it over the
* FILE arm (`fd: io.file` widens to io.handle).
*
* Each row imports fmt + os + io, opens a per-process /tmp output
* file, calls fdprintf with a {:mods} format string + one arg, and
* asserts the exact byte content read back.
* Each row imports fmt + os + io, opens a per-process /tmp output file,
* calls fprintf with a {:mods} format string + one arg, and asserts the
* exact byte content read back.
*
* Cstage-only per row pre-existing wwstage bug #209 (sibling of
* #190): the wwstage checker bails on fmt.formattable match-arms
* whenever a downstream probe `import fmt;`s the package. Identical
* carve-out to 777_fmt_vstream_run (cited there at line 18-33).
* Byte-id graduates with #209 close.
* carve-out to 777_fmt_handle_run (cited there). Byte-id graduates with
* #209 close.
*
* row | format | arg | expect | exit
* -----------------+------------+--------------+-----------+-----
@@ -25,7 +25,7 @@
* sign_plus | "{:+}" | 7i64 | "+7" | 53
* zero_pad | "{:_05}" | 42i64 | "00042" | 54
*
* Modifier surface exercised (subset of scanmods at fmt.ww:376-405):
* Modifier surface exercised (subset of scanmods at fmt.ww):
*
* width digits 1..9 RIGHT-align pad to N chars
* prec '.' + digits str truncation / int min-digits
@@ -35,31 +35,28 @@
*
* Drew NaN/Inf signoff (carry from task #58): f64 arm not exercised
* here (rows pin i64+str+bool fastpaths); follow-on fold can add f64
* once Drew's strconv.f64tos shortest-G stays static. The fold-e6
* implementation honours the sign-peel in vformatraw f64 arm; an
* end-to-end test lands when a NaN/Inf-aware probe joins the corpus.
* once Drew's strconv.f64tos shortest-G stays static.
*
* IMPORT-ORDER WORKAROUND (sibling task #208, pre-existing): every
* row places `import os;` FIRST for the same reason 776/777 document
* IMPORT-ORDER WORKAROUND (sibling task #208, pre-existing): every row
* places `import os;` FIRST for the same reason 776/777 document
* (wwstage checker ordering-sensitivity on os.tryread/trywrite/
* tryopen's bare `return r;` over a tagged return type).
*
* DEFERRALS / RELATED (NOT addressed by these rows):
*
* - #209 (wwstage formattable match-arm bail): blocks STAGE_WW
* here, same as 777_fmt_vstream_run. Cstage-only until close.
* - #209 (wwstage formattable match-arm bail): blocks STAGE_WW here,
* same as 777_fmt_handle_run. Cstage-only until close.
*
* BOOTSTRAP-EMBED CHECK: fmt is NOT embedded in any selfhost
* combined.ww (grep confirmed), so the fold-eFinal fmt collapse does
* NOT require a Makefile regen (#110); only test paths see the
* machinery. 990-997 byte-id gates stay green by virtue of fmt being
* test-only on the bootstrap surface.
* combined.ww (grep confirmed), so the #5 fmt graduation does NOT
* require a Makefile regen (#110); only test paths see the machinery.
* 990-997 byte-id gates stay green by virtue of fmt being test-only on
* the bootstrap surface.
*
* GATE POLARITY: must stay GREEN. A red here means formatone /
* formatraw / rawlen miscomputed bytes, formatfield regressed its
* *mods route, scanmods/modsinit drifted, or the strconv.u64tos base
* path miscompiled under fdprintf's intrusive io.stream*fd_ctx
* dispatch.
* path miscompiled under fprintf over the io.handle file arm.
*/
#include <stdio.h>
#include <stdlib.h>
@@ -94,10 +91,10 @@ static const struct row rows[] = {
"import fmt;\n"
"import io;\n"
"export fn main() i32 = {\n"
" let path: str = \"/tmp/wwfmtv_780_a\";\n"
" let path: str = \"/tmp/wwfmtm_780_a\";\n"
" let fd: i32 = os.open(path, os.flag.RDWR | os.flag.CREATE | os.flag.TRUNC, 0o644: i32);\n"
" if (fd < 0) { return 90; };\n"
" let wr = fmt.fdprintf(fd, \"{:5}\", 42i64);\n"
" let wr = fmt.fprintf(fd: io.file, \"{:5}\", 42i64);\n"
" let nw: size = 0;\n"
" match (wr) {\n"
" case let n: size => { nw = n; };\n"
@@ -122,10 +119,10 @@ static const struct row rows[] = {
"import fmt;\n"
"import io;\n"
"export fn main() i32 = {\n"
" let path: str = \"/tmp/wwfmtv_780_b\";\n"
" let path: str = \"/tmp/wwfmtm_780_b\";\n"
" let fd: i32 = os.open(path, os.flag.RDWR | os.flag.CREATE | os.flag.TRUNC, 0o644: i32);\n"
" if (fd < 0) { return 90; };\n"
" let wr = fmt.fdprintf(fd, \"{:.3}\", \"hello\");\n"
" let wr = fmt.fprintf(fd: io.file, \"{:.3}\", \"hello\");\n"
" let nw: size = 0;\n"
" match (wr) {\n"
" case let n: size => { nw = n; };\n"
@@ -150,10 +147,10 @@ static const struct row rows[] = {
"import fmt;\n"
"import io;\n"
"export fn main() i32 = {\n"
" let path: str = \"/tmp/wwfmtv_780_c\";\n"
" let path: str = \"/tmp/wwfmtm_780_c\";\n"
" let fd: i32 = os.open(path, os.flag.RDWR | os.flag.CREATE | os.flag.TRUNC, 0o644: i32);\n"
" if (fd < 0) { return 90; };\n"
" let wr = fmt.fdprintf(fd, \"{:x}\", 255i64);\n"
" let wr = fmt.fprintf(fd: io.file, \"{:x}\", 255i64);\n"
" let nw: size = 0;\n"
" match (wr) {\n"
" case let n: size => { nw = n; };\n"
@@ -178,10 +175,10 @@ static const struct row rows[] = {
"import fmt;\n"
"import io;\n"
"export fn main() i32 = {\n"
" let path: str = \"/tmp/wwfmtv_780_d\";\n"
" let path: str = \"/tmp/wwfmtm_780_d\";\n"
" let fd: i32 = os.open(path, os.flag.RDWR | os.flag.CREATE | os.flag.TRUNC, 0o644: i32);\n"
" if (fd < 0) { return 90; };\n"
" let wr = fmt.fdprintf(fd, \"{:+}\", 7i64);\n"
" let wr = fmt.fprintf(fd: io.file, \"{:+}\", 7i64);\n"
" let nw: size = 0;\n"
" match (wr) {\n"
" case let n: size => { nw = n; };\n"
@@ -206,10 +203,10 @@ static const struct row rows[] = {
"import fmt;\n"
"import io;\n"
"export fn main() i32 = {\n"
" let path: str = \"/tmp/wwfmtv_780_e\";\n"
" let path: str = \"/tmp/wwfmtm_780_e\";\n"
" let fd: i32 = os.open(path, os.flag.RDWR | os.flag.CREATE | os.flag.TRUNC, 0o644: i32);\n"
" if (fd < 0) { return 90; };\n"
" let wr = fmt.fdprintf(fd, \"{:_05}\", 42i64);\n"
" let wr = fmt.fprintf(fd: io.file, \"{:_05}\", 42i64);\n"
" let nw: size = 0;\n"
" match (wr) {\n"
" case let n: size => { nw = n; };\n"
@@ -270,7 +267,7 @@ static int
run_row(const char *driver, const char *cwd, const struct row *r, int seq)
{
char tmpdir[256], src[512], base[64], outbin[768];
snprintf(tmpdir, sizeof tmpdir, "/tmp/fvm_%d_d_%d", getpid(), seq);
snprintf(tmpdir, sizeof tmpdir, "/tmp/fhm_%d_d_%d", getpid(), seq);
snprintf(base, sizeof base, "main780");
snprintf(src, sizeof src, "%s/%s.ww", tmpdir, base);
mkdir(tmpdir, 0755);
@@ -315,7 +312,7 @@ main(void)
int got = run_row(cdrv, cwd, &rows[i], seq++);
if (got != rows[i].want_exit) {
fprintf(stderr,
"fmt_vstream_mods_run[cs][%s]: exit=%d want=%d\n",
"fmt_mods_run[cs][%s]: exit=%d want=%d\n",
rows[i].label, got, rows[i].want_exit);
fail++;
}
@@ -325,7 +322,7 @@ main(void)
int got = run_row(wdrv, cwd, &rows[i], seq++);
if (got != rows[i].want_exit) {
fprintf(stderr,
"fmt_vstream_mods_run[ww][%s]: exit=%d want=%d\n",
"fmt_mods_run[ww][%s]: exit=%d want=%d\n",
rows[i].label, got, rows[i].want_exit);
fail++;
}
@@ -333,13 +330,13 @@ main(void)
}
if (!wwpresent)
fprintf(stderr, "fmt_vstream_mods_run: skip wwstage (no %s)\n", wdrv);
fprintf(stderr, "fmt_mods_run: skip wwstage (no %s)\n", wdrv);
if (fail) {
fprintf(stderr, "fmt_vstream_mods_run: %d/%d fixtures failed\n",
fprintf(stderr, "fmt_mods_run: %d/%d fixtures failed\n",
fail, total);
return 1;
}
printf("fmt_vstream_mods_run: %d/%d ok\n", total, total);
printf("fmt_mods_run: %d/%d ok\n", total, total);
return 0;
}

View File

@@ -1,90 +1,69 @@
/*
* 781_fmt_vstream_compositions_run project #94 fold-eFinal sentinel.
* Pins the composition wrappers in lib/fmt/fmt.ww
* fprintln / fprintfln / bsprintf / asprintf plus the memio
* accessor (memio.string in lib/memio/memio.ww) they read back
* through. The fold-eFinal FLIP collapsed the dual fmt + memio
* surfaces into one (the former `v`-suffixed wrappers and the
* fixed_string / dynamic_string accessors merged into the bare names).
* 781_fmt_compositions_run io fold-2 (#5) commit-2 sentinel. Pins the
* composition wrappers in lib/fmt/fmt.ww fprintln / fprintfln /
* bsprintf / asprintf plus the memio accessor (memio.string in
* lib/memio/memio.ww) they read back through. #5 graduated the
* fprint-family sink io.stream -> io.handle; the file-arm rows drive
* fprintln / fprintfln over `fd: io.file`, the stream-arm rows over a
* memio.fixed io.stream both arms of io.handle.
*
* memio.string is the direct enabler: bsprintf reads its written
* prefix via memio.string; asprintf reads its grown buffer via the
* same accessor.
* memio.string is the direct enabler: bsprintf reads its written prefix
* via memio.string; asprintf reads its grown buffer via the same
* accessor.
*
* Each row imports fmt + os + io, drives one of the four V wrappers,
* and asserts the exact bytes / size emitted. Per-row unique exit
* constant lets a failure pinpoint the offending case.
* row | what it pins
* --------------------+--------------------------------------
* fprintln_file_basic | fprintln(fd: io.file, 1, "hi", true)
* | over the file arm space-separator plus
* | trailing newline byte content.
* fprintfln_file_fmt | fprintfln(fd: io.file, "x={}", 7) over the
* | file arm placeholder substitution +
* | trailing newline.
* fprintln_basic | fmt.fprintln dispatched over a memio.fixed
* | io.stream (stream arm) + read back via
* | memio.string. Pins the composition symbol.
* fprintfln_basic | fmt.fprintfln over memio.fixed + memio.string,
* | same stream-arm rationale.
* bsprintf_basic | bsprintf into a caller-supplied [16]u8
* | buffer through memio.fixed; memio.string
* | returns the prefix view. Asserts both the
* | caller-buffer bytes AND the returned str view.
* asprintf_basic | asprintf into a heap-grown str through
* | memio.dynamic; memio.string + shrink-copy +
* | io.close. Asserts the owned str bytes, then
* | frees via os.free.
*
* row | what it pins
* --------------------------+--------------------------------------
* fdprintln_v_run_basic | fdprintln wired vstream sink
* | (inline fprint + vputbytes "\n").
* | One i64 arg + str arg + bool arg;
* | asserts space-separator plus trailing
* | newline byte content.
* fdprintfln_v_run_fmt | fdprintfln wired vstream sink with
* | a {n}-placeholder format string.
* | Asserts placeholder substitution +
* | trailing newline shape (mirror of
* | fmt.fprintfln, fmt.ww:740).
* fprintln_basic | fmt.fprintln dispatched DIRECTLY
* | through memio.fixed + read
* | back via memio.string. Pins
* | the composition symbol itself
* | (fdprintln open-codes the same
* | fprint+putbytes chain rather than
* | calling fprintln, so without this
* | row the symbol ships uncovered).
* fprintfln_basic | fmt.fprintfln direct dispatch via
* | memio.fixed + memio.string,
* | same direct-symbol rationale as
* | fprintln_basic.
* bsprintf_v_basic | bsprintf into a caller-supplied
* | [16]u8 buffer through
* | memio.fixed;
* | memio.string returns the prefix
* | view. Asserts both the bytes in the
* | caller's buffer AND the returned str
* | view (ptr == buf + 0, len == 5).
* asprintf_v_basic | asprintf into a heap-grown str
* | through memio.dynamic;
* | memio.string + shrink-copy +
* | io.close. Asserts the owned str
* | bytes, then frees via os.free.
* Cstage-only per row (no STAGE_WW, no byte_id) pre-existing wwstage
* bug #209 (sibling of #190): the wwstage checker bails `case: not a
* variant of scrutinee (X)` + `match: variant not handled
* (formattable)` on fmt.formattable match-arms whenever a downstream
* probe `import fmt;`s the package. Identical carve-out to
* 777_fmt_handle_run + 780_fmt_mods_run. Byte-id graduates with #209
* close.
*
* Cstage-only per row (no STAGE_WW, no byte_id) pre-existing
* wwstage bug #209 (sibling of #190): the wwstage checker bails
* `case: not a variant of scrutinee (X)` + `match: variant not
* handled (formattable)` on fmt.formattable match-arms whenever a
* downstream probe `import fmt;`s the package. Identical carve-out
* to 777_fmt_vstream_run + 780_fmt_vstream_mods_run (cited there at
* line 18-33 / 18-23). Byte-id graduates with #209 close.
*
* IMPORT-ORDER WORKAROUND (sibling task #208, pre-existing): every
* row places `import os;` FIRST for the same reason 776/777/780
* document (wwstage checker ordering-sensitivity on os.tryread /
* trywrite / tryopen's bare `return r;` over a tagged return type).
* IMPORT-ORDER WORKAROUND (sibling task #208, pre-existing): every row
* places `import os;` FIRST for the same reason 776/777/780 document
* (wwstage checker ordering-sensitivity on os.tryread / trywrite /
* tryopen's bare `return r;` over a tagged return type).
*
* DEFERRALS / RELATED (NOT addressed by these rows):
*
* - #209 (wwstage formattable match-arm bail): blocks STAGE_WW
* here, same as 777/780. Cstage-only until close.
* - #173 (TRY-on-tagged-return both-stages broken): bsprintf
* widens nomem into io.error inline rather than `memio.
* fixed(buf)?` for the same reason memio.ww does.
* - #209 (wwstage formattable match-arm bail): blocks STAGE_WW here,
* same as 777/780. Cstage-only until close.
* - #173 (TRY-on-tagged-return both-stages broken): bsprintf widens
* nomem into io.error inline rather than `memio.fixed(buf)?` for
* the same reason memio.ww does.
*
* BOOTSTRAP-EMBED CHECK: fmt is NOT embedded in any selfhost
* combined.ww (grep verified). memio IS embedded in w6c + wwdump
* combined.ww the fold-eFinal memio collapse rides along via the
* regen committed in this same commit (per #110 SSoT). 990/994/995
* byte-id gates + combined_ww_fresh stay green by virtue of the
* regen.
* combined.ww but is unchanged by #5, so no regen rides along here.
* 990/994/995 byte-id gates stay green.
*
* GATE POLARITY: must stay GREEN. A red here means fprintln /
* fprintfln dropped the newline byte, bsprintf returned a stale
* memio.string view (intrusive cast broke), asprintf failed
* to shrink-copy / close cleanly, or the underlying fprint /
* fprintf primitives regressed.
* memio.string view (intrusive cast broke), asprintf failed to
* shrink-copy / close cleanly, or the underlying fprint / fprintf
* primitives regressed over the io.handle sink.
*/
#include <stdio.h>
#include <stdlib.h>
@@ -113,16 +92,16 @@ struct row {
};
static const struct row rows[] = {
{ "fdprintln_v_run_basic",
{ "fprintln_file_basic",
"package main;\n"
"import os;\n"
"import fmt;\n"
"import io;\n"
"export fn main() i32 = {\n"
" let path: str = \"/tmp/wwfmtv_781_a\";\n"
" let path: str = \"/tmp/wwfmtc_781_a\";\n"
" let fd: i32 = os.open(path, os.flag.RDWR | os.flag.CREATE | os.flag.TRUNC, 0o644: i32);\n"
" if (fd < 0) { return 90; };\n"
" let wr = fmt.fdprintln(fd, 1i64, \"hi\", true);\n"
" let wr = fmt.fprintln(fd: io.file, 1i64, \"hi\", true);\n"
" let nw: size = 0;\n"
" match (wr) {\n"
" case let n: size => { nw = n; };\n"
@@ -145,16 +124,16 @@ static const struct row rows[] = {
"};\n",
60,
STAGE_CS, 0 },
{ "fdprintfln_v_run_fmt",
{ "fprintfln_file_fmt",
"package main;\n"
"import os;\n"
"import fmt;\n"
"import io;\n"
"export fn main() i32 = {\n"
" let path: str = \"/tmp/wwfmtv_781_b\";\n"
" let path: str = \"/tmp/wwfmtc_781_b\";\n"
" let fd: i32 = os.open(path, os.flag.RDWR | os.flag.CREATE | os.flag.TRUNC, 0o644: i32);\n"
" if (fd < 0) { return 90; };\n"
" let wr = fmt.fdprintfln(fd, \"x={}\", 7i64);\n"
" let wr = fmt.fprintfln(fd: io.file, \"x={}\", 7i64);\n"
" let nw: size = 0;\n"
" match (wr) {\n"
" case let n: size => { nw = n; };\n"
@@ -225,7 +204,7 @@ static const struct row rows[] = {
"};\n",
65,
STAGE_CS, 0 },
{ "bsprintf_v_basic",
{ "bsprintf_basic",
"package main;\n"
"import os;\n"
"import fmt;\n"
@@ -246,7 +225,7 @@ static const struct row rows[] = {
"};\n",
62,
STAGE_CS, 0 },
{ "asprintf_v_basic",
{ "asprintf_basic",
"package main;\n"
"import os;\n"
"import fmt;\n"
@@ -304,7 +283,7 @@ static int
run_row(const char *driver, const char *cwd, const struct row *r, int seq)
{
char tmpdir[256], src[512], base[64], outbin[768];
snprintf(tmpdir, sizeof tmpdir, "/tmp/fvc_%d_d_%d", getpid(), seq);
snprintf(tmpdir, sizeof tmpdir, "/tmp/fhc_%d_d_%d", getpid(), seq);
snprintf(base, sizeof base, "main781");
snprintf(src, sizeof src, "%s/%s.ww", tmpdir, base);
mkdir(tmpdir, 0755);
@@ -349,7 +328,7 @@ main(void)
int got = run_row(cdrv, cwd, &rows[i], seq++);
if (got != rows[i].want_exit) {
fprintf(stderr,
"fmt_vstream_compositions_run[cs][%s]: exit=%d want=%d\n",
"fmt_compositions_run[cs][%s]: exit=%d want=%d\n",
rows[i].label, got, rows[i].want_exit);
fail++;
}
@@ -359,7 +338,7 @@ main(void)
int got = run_row(wdrv, cwd, &rows[i], seq++);
if (got != rows[i].want_exit) {
fprintf(stderr,
"fmt_vstream_compositions_run[ww][%s]: exit=%d want=%d\n",
"fmt_compositions_run[ww][%s]: exit=%d want=%d\n",
rows[i].label, got, rows[i].want_exit);
fail++;
}
@@ -367,13 +346,13 @@ main(void)
}
if (!wwpresent)
fprintf(stderr, "fmt_vstream_compositions_run: skip wwstage (no %s)\n", wdrv);
fprintf(stderr, "fmt_compositions_run: skip wwstage (no %s)\n", wdrv);
if (fail) {
fprintf(stderr, "fmt_vstream_compositions_run: %d/%d fixtures failed\n",
fprintf(stderr, "fmt_compositions_run: %d/%d fixtures failed\n",
fail, total);
return 1;
}
printf("fmt_vstream_compositions_run: %d/%d ok\n", total, total);
printf("fmt_compositions_run: %d/%d ok\n", total, total);
return 0;
}