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:
14
Makefile
14
Makefile
@@ -331,9 +331,9 @@ TESTS = $(BIN)/test_smoke $(BIN)/test_lex $(BIN)/test_parse $(BIN)/test_check \
|
|||||||
$(BIN)/test_io_vtable_run \
|
$(BIN)/test_io_vtable_run \
|
||||||
$(BIN)/test_io_handle_run \
|
$(BIN)/test_io_handle_run \
|
||||||
$(BIN)/test_memio_vstream_run \
|
$(BIN)/test_memio_vstream_run \
|
||||||
$(BIN)/test_fmt_vstream_run \
|
$(BIN)/test_fmt_handle_run \
|
||||||
$(BIN)/test_fmt_vstream_mods_run \
|
$(BIN)/test_fmt_mods_run \
|
||||||
$(BIN)/test_fmt_vstream_compositions_run \
|
$(BIN)/test_fmt_compositions_run \
|
||||||
$(BIN)/test_fieldfn_leaf_collide_run \
|
$(BIN)/test_fieldfn_leaf_collide_run \
|
||||||
$(BIN)/test_amp_fn_assign_run \
|
$(BIN)/test_amp_fn_assign_run \
|
||||||
$(BIN)/test_type_value_shadow_run \
|
$(BIN)/test_type_value_shadow_run \
|
||||||
@@ -721,10 +721,10 @@ $(BIN)/test_memio_vstream_run: test/wcc/776_memio_vstream_run.c \
|
|||||||
$(LIB)/libwwrt.a | $(BIN)
|
$(LIB)/libwwrt.a | $(BIN)
|
||||||
$(CC) $(CFLAGS) -o $@ $<
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
|
|
||||||
$(BIN)/test_fmt_vstream_run: test/wcc/777_fmt_vstream_run.c \
|
$(BIN)/test_fmt_handle_run: test/wcc/777_fmt_handle_run.c \
|
||||||
$(BIN)/ww $(BIN)/w6c $(BIN)/w6a $(BIN)/w6l \
|
$(BIN)/ww $(BIN)/w6c $(BIN)/w6a $(BIN)/w6l \
|
||||||
$(BIN)/ww_ww $(BIN)/w6c_ww $(BIN)/w6a_ww $(BIN)/w6l_ww \
|
$(BIN)/ww_ww $(BIN)/w6c_ww $(BIN)/w6a_ww $(BIN)/w6l_ww \
|
||||||
lib/fmt/fmt.ww \
|
lib/fmt/fmt.ww lib/memio/memio.ww \
|
||||||
$(LIB)/libwwrt.a | $(BIN)
|
$(LIB)/libwwrt.a | $(BIN)
|
||||||
$(CC) $(CFLAGS) -o $@ $<
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
|
|
||||||
@@ -814,14 +814,14 @@ $(BIN)/test_narrow_alias_deref_store: test/wcc/786_narrow_alias_deref_store.c \
|
|||||||
$(LIB)/libwwrt.a | $(BIN)
|
$(LIB)/libwwrt.a | $(BIN)
|
||||||
$(CC) $(CFLAGS) -o $@ $<
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
|
|
||||||
$(BIN)/test_fmt_vstream_mods_run: test/wcc/780_fmt_vstream_mods_run.c \
|
$(BIN)/test_fmt_mods_run: test/wcc/780_fmt_mods_run.c \
|
||||||
$(BIN)/ww $(BIN)/w6c $(BIN)/w6a $(BIN)/w6l \
|
$(BIN)/ww $(BIN)/w6c $(BIN)/w6a $(BIN)/w6l \
|
||||||
$(BIN)/ww_ww $(BIN)/w6c_ww $(BIN)/w6a_ww $(BIN)/w6l_ww \
|
$(BIN)/ww_ww $(BIN)/w6c_ww $(BIN)/w6a_ww $(BIN)/w6l_ww \
|
||||||
lib/fmt/fmt.ww \
|
lib/fmt/fmt.ww \
|
||||||
$(LIB)/libwwrt.a | $(BIN)
|
$(LIB)/libwwrt.a | $(BIN)
|
||||||
$(CC) $(CFLAGS) -o $@ $<
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
|
|
||||||
$(BIN)/test_fmt_vstream_compositions_run: test/wcc/781_fmt_vstream_compositions_run.c \
|
$(BIN)/test_fmt_compositions_run: test/wcc/781_fmt_compositions_run.c \
|
||||||
$(BIN)/ww $(BIN)/w6c $(BIN)/w6a $(BIN)/w6l \
|
$(BIN)/ww $(BIN)/w6c $(BIN)/w6a $(BIN)/w6l \
|
||||||
$(BIN)/ww_ww $(BIN)/w6c_ww $(BIN)/w6a_ww $(BIN)/w6l_ww \
|
$(BIN)/ww_ww $(BIN)/w6c_ww $(BIN)/w6a_ww $(BIN)/w6l_ww \
|
||||||
lib/fmt/fmt.ww \
|
lib/fmt/fmt.ww \
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ Signatures mirror Hare too, modulo:
|
|||||||
- Call-site variadic sugar matches Hare. `fn f(args: T...)` declares
|
- Call-site variadic sugar matches Hare. `fn f(args: T...)` declares
|
||||||
a Hare-style variadic; call sites either gather N args into a
|
a Hare-style variadic; call sites either gather N args into a
|
||||||
fresh `[]T` (`fmt.println(42, "hi", true)`) or forward an existing
|
fresh `[]T` (`fmt.println(42, "hi", true)`) or forward an existing
|
||||||
slice with `xs...` (`fdprintln(fd, args...)`). The bare `T...` form
|
slice with `xs...` (`fprintln(h, args...)`). The bare `T...` form
|
||||||
in tagged unions still means spread-flatten (`(...inner | E)`);
|
in tagged unions still means spread-flatten (`(...inner | E)`);
|
||||||
the two uses don't overlap because `T...` only attaches to a
|
the two uses don't overlap because `T...` only attaches to a
|
||||||
*param* decl. `lib/fmt` ships both the print family (`print` /
|
*param* decl. `lib/fmt` ships both the print family (`print` /
|
||||||
|
|||||||
180
lib/fmt/fmt.ww
180
lib/fmt/fmt.ww
@@ -1,35 +1,23 @@
|
|||||||
// fmt — formatting writers. Mirrors Hare's lib/fmt subset. Project #94
|
// fmt — formatting writers. Mirrors Hare's lib/fmt subset. Project #94
|
||||||
// fold-eFinal.
|
// fold-eFinal; io fold-2 (#5) graduated the sink to [[io.handle]].
|
||||||
//
|
|
||||||
// Two sinks behind one surface, the distinction baked into the name:
|
|
||||||
//
|
//
|
||||||
// fprint / fprintln / fprintf / fprintfln
|
// fprint / fprintln / fprintf / fprintfln
|
||||||
// write to an [[io.stream]] (= `*io.vtable`) —
|
// write to an [[io.handle]] (= `(io.file |
|
||||||
// Hare's primary surface. Errors via [[io.error]].
|
// io.stream)`) — Hare's primary surface
|
||||||
// fdprint / fdprintln / fdprintf / fdprintfln
|
// (ref/hare/fmt/print.ha:13). Errors via
|
||||||
// write to a raw fd via [[os.write]], wrapped in a
|
// [[io.error]]. A file handle (raw fd) and a stream
|
||||||
// stack-resident [[fd_ctx]] vtable. NO Hare
|
// (`*io.vtable`) both flow in; [[io.write]]
|
||||||
// counterpart — a pre-handle shim. Hare routes
|
// dispatches per arm.
|
||||||
// fmt's fd sinks through `io::handle = (io::file
|
|
||||||
// | int)` (ref/hare/fmt/wrappers.ha:9-25); ww has
|
|
||||||
// no handle sum yet, so these stand in until io
|
|
||||||
// fold-2 (#5) lands the handle port, at which
|
|
||||||
// point each fdNNN folds into fNNN-over-handle and
|
|
||||||
// the fd-prefixed names disappear.
|
|
||||||
//
|
//
|
||||||
// The process-stdio wrappers (print/println/errorln/printf/printfln/
|
// The process-stdio wrappers (print/println/errorln/printf/printfln/
|
||||||
// errorfln/fatal/fatalf) route through the fd family on fd 1 / fd 2.
|
// errorfln/fatal/fatalf) route through the fprint family over a file
|
||||||
|
// handle built from os.STD{OUT,ERR}_FILENO. The #5 handle convergence
|
||||||
|
// retired the prior `fd_ctx` shim — the fake-stream vtable around
|
||||||
|
// os.write that stood in before io.write took a handle.
|
||||||
//
|
//
|
||||||
// Call sites take Hare's variadic shape: `fmt.println(42, "hi", true)`
|
// Call sites take Hare's variadic shape: `fmt.println(42, "hi", true)`
|
||||||
// gathers the args into a `[]formattable` slice; wrappers forward via
|
// gathers the args into a `[]formattable` slice; wrappers forward via
|
||||||
// `args...`.
|
// `args...`.
|
||||||
//
|
|
||||||
// Cast workaround per #206-payoff (ken: KEEP the explicit casts; they
|
|
||||||
// are cgen-neutral and sidestep the #214 over-acceptance surface). The
|
|
||||||
// `(&fn_name): *io.<role>` cast at each fd_ctx vtable store is the
|
|
||||||
// Hare-faithful minimum-touch route; the #206 cast-drop is gated on
|
|
||||||
// #214. The fd sinks construct nomem and widen to io.error explicitly
|
|
||||||
// rather than using `os.trywrite(...)?` for the no-handle interim.
|
|
||||||
|
|
||||||
package fmt;
|
package fmt;
|
||||||
|
|
||||||
@@ -87,42 +75,12 @@ fn i64dec(v: i64) str = {
|
|||||||
// arm when the first in-tree caller needs it.
|
// arm when the first in-tree caller needs it.
|
||||||
export type formattable = (i64 | str | bool | rune | f64);
|
export type formattable = (i64 | str | bool | rune | f64);
|
||||||
|
|
||||||
// fd_ctx — vt at offset 0 for the intrusive io.stream→*fd_ctx cast.
|
|
||||||
// Single tagged field (vt) means the multi-tagged-field struct-lit
|
|
||||||
// drop in #207 doesn't bite; every fd wrapper stack-allocates fd_ctx
|
|
||||||
// inside its own frame and dispatches without escaping `&c.vt`.
|
|
||||||
export type fd_ctx = struct {
|
|
||||||
vt: io.vtable,
|
|
||||||
fd: i32,
|
|
||||||
};
|
|
||||||
|
|
||||||
// fdsinkread — eof-only sink; the fd half of fmt is write-only. The
|
|
||||||
// unused-`buf` parameter matches io.reader's signature.
|
|
||||||
fn fdsinkread(s: io.stream, buf: []u8) (size | io.eof | io.error) = {
|
|
||||||
let e: io.eof;
|
|
||||||
return e;
|
|
||||||
};
|
|
||||||
|
|
||||||
// fdsinkwrite — recover fd via intrusive cast, dispatch one os.write.
|
|
||||||
// -errno collapses to a nomem-widened io.error. Construction-then-widen
|
|
||||||
// (vs `os.trywrite(...)?`) for the no-handle interim.
|
|
||||||
fn fdsinkwrite(s: io.stream, buf: []u8) (size | io.error) = {
|
|
||||||
let c: *fd_ctx = s: *fd_ctx;
|
|
||||||
let r: i64 = os.write(c.fd, buf.ptr, buf.len: u64);
|
|
||||||
if (r < 0) {
|
|
||||||
let nm: nomem;
|
|
||||||
let e: io.error = nm;
|
|
||||||
return e;
|
|
||||||
};
|
|
||||||
return r: size;
|
|
||||||
};
|
|
||||||
|
|
||||||
// ---- internal stream formatters --------------------------------------
|
// ---- internal stream formatters --------------------------------------
|
||||||
|
|
||||||
// putbytes — io.write(s, [ptr..ptr+n)). Internal helper; the inline
|
// putbytes — io.write(s, [ptr..ptr+n)). Internal helper; the inline
|
||||||
// `let v` slice synthesis composes the (ptr, len) triple each
|
// `let v` slice synthesis composes the (ptr, len) triple each
|
||||||
// formattable arm carries.
|
// formattable arm carries.
|
||||||
fn putbytes(s: io.stream, p: *u8, n: i32) (size | io.error) = {
|
fn putbytes(s: io.handle, p: *u8, n: i32) (size | io.error) = {
|
||||||
let v: []u8;
|
let v: []u8;
|
||||||
v.ptr = p;
|
v.ptr = p;
|
||||||
v.len = n;
|
v.len = n;
|
||||||
@@ -130,7 +88,7 @@ fn putbytes(s: io.stream, p: *u8, n: i32) (size | io.error) = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// writeone — emit one formattable through io.write.
|
// writeone — emit one formattable through io.write.
|
||||||
fn writeone(s: io.stream, a: formattable) (size | io.error) = {
|
fn writeone(s: io.handle, a: formattable) (size | io.error) = {
|
||||||
match (a) {
|
match (a) {
|
||||||
case let n: i64 => {
|
case let n: i64 => {
|
||||||
let v: str = i64dec(n);
|
let v: str = i64dec(n);
|
||||||
@@ -365,7 +323,7 @@ fn rawlen(arg: formattable, m: *mods) i32 = {
|
|||||||
// shortest-G with no precision knob); base ignored on f64 (Hare too —
|
// shortest-G with no precision knob); base ignored on f64 (Hare too —
|
||||||
// base is int-only). drew NaN/Inf signoff: nan/infinity strings emitted
|
// base is int-only). drew NaN/Inf signoff: nan/infinity strings emitted
|
||||||
// unchanged.
|
// unchanged.
|
||||||
fn formatraw(s: io.stream, arg: formattable, m: *mods) (size | io.error) = {
|
fn formatraw(s: io.handle, arg: formattable, m: *mods) (size | io.error) = {
|
||||||
match (arg) {
|
match (arg) {
|
||||||
case let v: i64 => {
|
case let v: i64 => {
|
||||||
let neg_flag: bool = v < 0;
|
let neg_flag: bool = v < 0;
|
||||||
@@ -459,7 +417,7 @@ fn formatraw(s: io.stream, arg: formattable, m: *mods) (size | io.error) = {
|
|||||||
// counter because putbytes over memio.fixed reports a full buffer as a
|
// counter because putbytes over memio.fixed reports a full buffer as a
|
||||||
// 0-byte partial write, not io.error — looping on `total < m.width`
|
// 0-byte partial write, not io.error — looping on `total < m.width`
|
||||||
// would spin on bsprintf when the sink runs out.
|
// would spin on bsprintf when the sink runs out.
|
||||||
fn formatone(s: io.stream, arg: formattable, m: *mods) (size | io.error) = {
|
fn formatone(s: io.handle, arg: formattable, m: *mods) (size | io.error) = {
|
||||||
let start: i32 = 0;
|
let start: i32 = 0;
|
||||||
if (m.width > 0 && m.alignment != alignment.LEFT) {
|
if (m.width > 0 && m.alignment != alignment.LEFT) {
|
||||||
let raw: i32 = rawlen(arg, m);
|
let raw: i32 = rawlen(arg, m);
|
||||||
@@ -505,7 +463,7 @@ fn formatone(s: io.stream, arg: formattable, m: *mods) (size | io.error) = {
|
|||||||
// for-loop would trip #18 (silent miscompile of 24B return-by-value in
|
// for-loop would trip #18 (silent miscompile of 24B return-by-value in
|
||||||
// for-loop context); inline-per-arm sidesteps it. `*mods` arm aborts
|
// for-loop context); inline-per-arm sidesteps it. `*mods` arm aborts
|
||||||
// (parametric '%' form not implemented). Mirror print.ha:648.
|
// (parametric '%' form not implemented). Mirror print.ha:648.
|
||||||
fn formatfield(s: io.stream, f: field, m: *mods) (size | io.error) = {
|
fn formatfield(s: io.handle, f: field, m: *mods) (size | io.error) = {
|
||||||
match (f) {
|
match (f) {
|
||||||
case let v: i64 => {
|
case let v: i64 => {
|
||||||
let a: formattable = v;
|
let a: formattable = v;
|
||||||
@@ -541,7 +499,7 @@ fn formatfield(s: io.stream, f: field, m: *mods) (size | io.error) = {
|
|||||||
// the returned count, not as an error — matches [[io.write]]'s contract
|
// the returned count, not as an error — matches [[io.write]]'s contract
|
||||||
// per [[memio.fixed]]. Callers that need write-all semantics layer it
|
// per [[memio.fixed]]. Callers that need write-all semantics layer it
|
||||||
// on top, the same way they do over raw [[io.write]].
|
// on top, the same way they do over raw [[io.write]].
|
||||||
export fn fprint(s: io.stream, args: formattable...) (size | io.error) = {
|
export fn fprint(s: io.handle, args: formattable...) (size | io.error) = {
|
||||||
let total: size = 0;
|
let total: size = 0;
|
||||||
let i: i32 = 0;
|
let i: i32 = 0;
|
||||||
for (i < args.len) {
|
for (i < args.len) {
|
||||||
@@ -564,7 +522,7 @@ export fn fprint(s: io.stream, args: formattable...) (size | io.error) = {
|
|||||||
|
|
||||||
// fprintf — Hare's primary printf-family surface. Mirrors print.ha:26.
|
// fprintf — Hare's primary printf-family surface. Mirrors print.ha:26.
|
||||||
// Returns total bytes written or io.error on the first sink failure.
|
// Returns total bytes written or io.error on the first sink failure.
|
||||||
export fn fprintf(s: io.stream, fmt: str, args: field...) (size | io.error) = {
|
export fn fprintf(s: io.handle, fmt: str, args: field...) (size | io.error) = {
|
||||||
let total: size = 0;
|
let total: size = 0;
|
||||||
let i: i32 = 0;
|
let i: i32 = 0;
|
||||||
let nextimpl: i32 = 0;
|
let nextimpl: i32 = 0;
|
||||||
@@ -629,7 +587,7 @@ export fn fprintf(s: io.stream, fmt: str, args: field...) (size | io.error) = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// fprintln — fprint plus a trailing newline. Mirrors wrappers.ha.
|
// fprintln — fprint plus a trailing newline. Mirrors wrappers.ha.
|
||||||
export fn fprintln(s: io.stream, args: formattable...) (size | io.error) = {
|
export fn fprintln(s: io.handle, args: formattable...) (size | io.error) = {
|
||||||
let total: size = 0;
|
let total: size = 0;
|
||||||
match (fprint(s, args...)) {
|
match (fprint(s, args...)) {
|
||||||
case let n: size => { total = n; };
|
case let n: size => { total = n; };
|
||||||
@@ -643,7 +601,7 @@ export fn fprintln(s: io.stream, args: formattable...) (size | io.error) = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// fprintfln — fprintf plus a trailing newline. Mirrors wrappers.ha:69.
|
// fprintfln — fprintf plus a trailing newline. Mirrors wrappers.ha:69.
|
||||||
export fn fprintfln(s: io.stream, fmt: str, args: field...) (size | io.error) = {
|
export fn fprintfln(s: io.handle, fmt: str, args: field...) (size | io.error) = {
|
||||||
let total: size = 0;
|
let total: size = 0;
|
||||||
match (fprintf(s, fmt, args...)) {
|
match (fprintf(s, fmt, args...)) {
|
||||||
case let n: size => { total = n; };
|
case let n: size => { total = n; };
|
||||||
@@ -712,113 +670,55 @@ export fn asprintf(fmt: str, args: field...) str = {
|
|||||||
return strings.frombytes(tight);
|
return strings.frombytes(tight);
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---- fd sinks (pre-handle shim, NO Hare counterpart; #5) -------------
|
|
||||||
|
|
||||||
// fdprint — fdprint over a stack-resident fd_ctx io.stream. The &c.vt
|
|
||||||
// io.stream never escapes this frame.
|
|
||||||
export fn fdprint(fd: i32, args: formattable...) (size | io.error) = {
|
|
||||||
let c: fd_ctx;
|
|
||||||
c.fd = fd;
|
|
||||||
c.vt.reader = (&fdsinkread): *io.reader;
|
|
||||||
c.vt.writer = (&fdsinkwrite): *io.writer;
|
|
||||||
let s: io.stream = &c.vt;
|
|
||||||
return fprint(s, args...);
|
|
||||||
};
|
|
||||||
|
|
||||||
// fdprintln — fdprint + trailing newline.
|
|
||||||
export fn fdprintln(fd: i32, args: formattable...) (size | io.error) = {
|
|
||||||
let c: fd_ctx;
|
|
||||||
c.fd = fd;
|
|
||||||
c.vt.reader = (&fdsinkread): *io.reader;
|
|
||||||
c.vt.writer = (&fdsinkwrite): *io.writer;
|
|
||||||
let s: io.stream = &c.vt;
|
|
||||||
let total: size = 0;
|
|
||||||
match (fprint(s, args...)) {
|
|
||||||
case let n: size => { total = n; };
|
|
||||||
case let e: io.error => return e;
|
|
||||||
};
|
|
||||||
match (putbytes(s, "\n".ptr, 1)) {
|
|
||||||
case let n: size => { total += n; };
|
|
||||||
case let e: io.error => return e;
|
|
||||||
};
|
|
||||||
return total;
|
|
||||||
};
|
|
||||||
|
|
||||||
// fdprintf — fdprintf over a fd_ctx io.stream.
|
|
||||||
export fn fdprintf(fd: i32, fmt: str, args: field...) (size | io.error) = {
|
|
||||||
let c: fd_ctx;
|
|
||||||
c.fd = fd;
|
|
||||||
c.vt.reader = (&fdsinkread): *io.reader;
|
|
||||||
c.vt.writer = (&fdsinkwrite): *io.writer;
|
|
||||||
let s: io.stream = &c.vt;
|
|
||||||
return fprintf(s, fmt, args...);
|
|
||||||
};
|
|
||||||
|
|
||||||
// fdprintfln — fdprintf + trailing newline. Mirrors wrappers.ha:69.
|
|
||||||
export fn fdprintfln(fd: i32, fmt: str, args: field...) (size | io.error) = {
|
|
||||||
let c: fd_ctx;
|
|
||||||
c.fd = fd;
|
|
||||||
c.vt.reader = (&fdsinkread): *io.reader;
|
|
||||||
c.vt.writer = (&fdsinkwrite): *io.writer;
|
|
||||||
let s: io.stream = &c.vt;
|
|
||||||
let total: size = 0;
|
|
||||||
match (fprintf(s, fmt, args...)) {
|
|
||||||
case let n: size => { total = n; };
|
|
||||||
case let e: io.error => return e;
|
|
||||||
};
|
|
||||||
match (putbytes(s, "\n".ptr, 1)) {
|
|
||||||
case let n: size => { total += n; };
|
|
||||||
case let e: io.error => return e;
|
|
||||||
};
|
|
||||||
return total;
|
|
||||||
};
|
|
||||||
|
|
||||||
// ---- process-stdio wrappers -----------------------------------------
|
// ---- process-stdio wrappers -----------------------------------------
|
||||||
//
|
//
|
||||||
// Hare routes these through os::stdout / os::stderr (io::handle); ww
|
// Mirror ref/hare/fmt/wrappers.ha. Hare routes these through
|
||||||
// has no fd-backed handle yet, so they route through the fd shim on
|
// os::stdout / os::stderr (io::handle); ww's os plays the sys role and
|
||||||
// fd 1 / fd 2 (io fold-2, #5, collapses the fd shim). errorf / asprint /
|
// can't import io (import floor), so it exports the std fd NUMBERS
|
||||||
// bsprint omitted: the bare `error` name collides with strconv.error
|
// (os.STD{OUT,ERR}_FILENO) and the io.file binding is cast at the call
|
||||||
// under the driver's flat-scope concat; ship the -ln forms only.
|
// site — `os.STDOUT_FILENO: io.file` widens into the fprint handle param
|
||||||
|
// (io fold-2, #5). errorf / asprint / bsprint omitted: the bare `error`
|
||||||
|
// name collides with strconv.error under the driver's flat-scope concat;
|
||||||
|
// ship the -ln forms only.
|
||||||
|
|
||||||
// print / println — wrappers.ha:78/:84 on fd 1.
|
// print / println — wrappers.ha:78/:84 on stdout.
|
||||||
export fn print(args: formattable...) (size | io.error) = {
|
export fn print(args: formattable...) (size | io.error) = {
|
||||||
return fdprint(1, args...);
|
return fprint(os.STDOUT_FILENO: io.file, args...);
|
||||||
};
|
};
|
||||||
|
|
||||||
export fn println(args: formattable...) (size | io.error) = {
|
export fn println(args: formattable...) (size | io.error) = {
|
||||||
return fdprintln(1, args...);
|
return fprintln(os.STDOUT_FILENO: io.file, args...);
|
||||||
};
|
};
|
||||||
|
|
||||||
// errorln — wrappers.ha:96 on fd 2.
|
// errorln — wrappers.ha:96 on stderr.
|
||||||
export fn errorln(args: formattable...) (size | io.error) = {
|
export fn errorln(args: formattable...) (size | io.error) = {
|
||||||
return fdprintln(2, args...);
|
return fprintln(os.STDERR_FILENO: io.file, args...);
|
||||||
};
|
};
|
||||||
|
|
||||||
// fatal — errorln then exit(255). `never` return marks the bottom type
|
// fatal — errorln then exit(255). `never` return marks the bottom type
|
||||||
// so flow-control checks treat callers as terminated. Mirrors
|
// so flow-control checks treat callers as terminated. Mirrors
|
||||||
// wrappers.ha:63.
|
// wrappers.ha:63.
|
||||||
export fn fatal(args: formattable...) never = {
|
export fn fatal(args: formattable...) never = {
|
||||||
fdprintln(2, args...);
|
fprintln(os.STDERR_FILENO: io.file, args...);
|
||||||
os.exit(255);
|
os.exit(255);
|
||||||
};
|
};
|
||||||
|
|
||||||
// printf / printfln — wrappers.ha:10/:15 on fd 1.
|
// printf / printfln — wrappers.ha:10/:15 on stdout.
|
||||||
export fn printf(fmt: str, args: field...) (size | io.error) = {
|
export fn printf(fmt: str, args: field...) (size | io.error) = {
|
||||||
return fdprintf(1, fmt, args...);
|
return fprintf(os.STDOUT_FILENO: io.file, fmt, args...);
|
||||||
};
|
};
|
||||||
|
|
||||||
export fn printfln(fmt: str, args: field...) (size | io.error) = {
|
export fn printfln(fmt: str, args: field...) (size | io.error) = {
|
||||||
return fdprintfln(1, fmt, args...);
|
return fprintfln(os.STDOUT_FILENO: io.file, fmt, args...);
|
||||||
};
|
};
|
||||||
|
|
||||||
// errorfln — wrappers.ha:24 on fd 2.
|
// errorfln — wrappers.ha:24 on stderr.
|
||||||
export fn errorfln(fmt: str, args: field...) (size | io.error) = {
|
export fn errorfln(fmt: str, args: field...) (size | io.error) = {
|
||||||
return fdprintfln(2, fmt, args...);
|
return fprintfln(os.STDERR_FILENO: io.file, fmt, args...);
|
||||||
};
|
};
|
||||||
|
|
||||||
// fatalf — errorfln then exit(255). Mirrors wrappers.ha:54.
|
// fatalf — errorfln then exit(255). Mirrors wrappers.ha:54.
|
||||||
export fn fatalf(fmt: str, args: field...) never = {
|
export fn fatalf(fmt: str, args: field...) never = {
|
||||||
fdprintfln(2, fmt, args...);
|
fprintfln(os.STDERR_FILENO: io.file, fmt, args...);
|
||||||
os.exit(255);
|
os.exit(255);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -41,10 +41,12 @@
|
|||||||
// an imported module name; `use fmt; fn x(fmt: T)` is structurally
|
// an imported module name; `use fmt; fn x(fmt: T)` is structurally
|
||||||
// ambiguous under ww's `.`-for-both rule.
|
// ambiguous under ww's `.`-for-both rule.
|
||||||
//
|
//
|
||||||
// Sink today is an [[io.stream]] only — lib/io has no fd-backed handle
|
// Sink today is an [[io.stream]] only. io fold-2 (#5) landed
|
||||||
// yet (Hare's `io::handle = file | int`, io fold-2 #5). The default
|
// [[io.handle]] = (io.file | io.stream) and graduated lib/fmt onto it,
|
||||||
// logger writes to stderr via a private fd_ctx whose write callback
|
// but lib/log's sink graduation is a separate follow-up; until then the
|
||||||
// forwards to [[os.write]] on fd 2.
|
// default logger writes to stderr via a private fd-backed stream shim
|
||||||
|
// ([[stderrsink_ctx]]) whose write callback forwards to [[os.write]] on
|
||||||
|
// os.STDERR_FILENO.
|
||||||
//
|
//
|
||||||
// Cast workaround per #206-payoff (ken: KEEP the explicit casts; they
|
// Cast workaround per #206-payoff (ken: KEEP the explicit casts; they
|
||||||
// are cgen-neutral and sidestep the #214 over-acceptance surface). The
|
// are cgen-neutral and sidestep the #214 over-acceptance surface). The
|
||||||
@@ -85,7 +87,8 @@ export type stdlogger = struct {
|
|||||||
|
|
||||||
// stderrsink_ctx — module-static state for the default logger's stderr
|
// stderrsink_ctx — module-static state for the default logger's stderr
|
||||||
// sink. vt FIRST field for the intrusive io.stream→*stderrsink_ctx cast
|
// sink. vt FIRST field for the intrusive io.stream→*stderrsink_ctx cast
|
||||||
// in stderrwrite. Mirrors fmt.fd_ctx; only scalars/ptrs beyond vt.
|
// in stderrwrite (the same vtable-first-field shape lib/fmt used before
|
||||||
|
// #5 graduated it onto io.handle); only scalars/ptrs beyond vt.
|
||||||
type stderrsink_ctx = struct {
|
type stderrsink_ctx = struct {
|
||||||
vt: io.vtable,
|
vt: io.vtable,
|
||||||
fd: i32,
|
fd: i32,
|
||||||
@@ -113,7 +116,7 @@ let initdone: i32 = 0;
|
|||||||
|
|
||||||
fn ensureinit() void = {
|
fn ensureinit() void = {
|
||||||
if (initdone != 0) { return; };
|
if (initdone != 0) { return; };
|
||||||
stderrsink_ctx_g.fd = 2;
|
stderrsink_ctx_g.fd = os.STDERR_FILENO;
|
||||||
stderrsink_ctx_g.vt.reader = (&stderrread): *io.reader;
|
stderrsink_ctx_g.vt.reader = (&stderrread): *io.reader;
|
||||||
stderrsink_ctx_g.vt.writer = (&stderrwrite): *io.writer;
|
stderrsink_ctx_g.vt.writer = (&stderrwrite): *io.writer;
|
||||||
|
|
||||||
|
|||||||
11
lib/os/os.ww
11
lib/os/os.ww
@@ -91,6 +91,17 @@ export fn exit(code: i32) void = {
|
|||||||
export def PATH_MAX: i32 = 4096;
|
export def PATH_MAX: i32 = 4096;
|
||||||
let pathbuf: [4096]u8;
|
let pathbuf: [4096]u8;
|
||||||
|
|
||||||
|
// ref/hare/sys/+linux/types.ha:886-888. ww folds `sys` into `os`, so the
|
||||||
|
// std fd NUMBERS live here (the sys role). Typed i32, NOT io.file as in
|
||||||
|
// Hare's os::stdout_file (ref/hare/os/+linux/stdfd.ha:28): Hare's `os`
|
||||||
|
// imports `io`, but ww's `os` is the import floor and must never import
|
||||||
|
// io (lib/CLAUDE.md) — so the io.file/io.handle binding can't live here.
|
||||||
|
// Consumers (lib/fmt's stdio wrappers) cast i32→io.file at the use site,
|
||||||
|
// where the handle layer is already in scope.
|
||||||
|
export def STDIN_FILENO: i32 = 0;
|
||||||
|
export def STDOUT_FILENO: i32 = 1;
|
||||||
|
export def STDERR_FILENO: i32 = 2;
|
||||||
|
|
||||||
fn kpath(p: str) *u8 = {
|
fn kpath(p: str) *u8 = {
|
||||||
if (p.len + 1 >= PATH_MAX) { return nil: *u8; }; // ENAMETOOLONG
|
if (p.len + 1 >= PATH_MAX) { return nil: *u8; }; // ENAMETOOLONG
|
||||||
let i: i32 = 0;
|
let i: i32 = 0;
|
||||||
|
|||||||
@@ -189,6 +189,17 @@ export fn exit(code: i32) void = {
|
|||||||
export def PATH_MAX: i32 = 4096;
|
export def PATH_MAX: i32 = 4096;
|
||||||
let pathbuf: [4096]u8;
|
let pathbuf: [4096]u8;
|
||||||
|
|
||||||
|
// ref/hare/sys/+linux/types.ha:886-888. ww folds `sys` into `os`, so the
|
||||||
|
// std fd NUMBERS live here (the sys role). Typed i32, NOT io.file as in
|
||||||
|
// Hare's os::stdout_file (ref/hare/os/+linux/stdfd.ha:28): Hare's `os`
|
||||||
|
// imports `io`, but ww's `os` is the import floor and must never import
|
||||||
|
// io (lib/CLAUDE.md) — so the io.file/io.handle binding can't live here.
|
||||||
|
// Consumers (lib/fmt's stdio wrappers) cast i32→io.file at the use site,
|
||||||
|
// where the handle layer is already in scope.
|
||||||
|
export def STDIN_FILENO: i32 = 0;
|
||||||
|
export def STDOUT_FILENO: i32 = 1;
|
||||||
|
export def STDERR_FILENO: i32 = 2;
|
||||||
|
|
||||||
fn kpath(p: str) *u8 = {
|
fn kpath(p: str) *u8 = {
|
||||||
if (p.len + 1 >= PATH_MAX) { return nil: *u8; }; // ENAMETOOLONG
|
if (p.len + 1 >= PATH_MAX) { return nil: *u8; }; // ENAMETOOLONG
|
||||||
let i: i32 = 0;
|
let i: i32 = 0;
|
||||||
|
|||||||
@@ -189,6 +189,17 @@ export fn exit(code: i32) void = {
|
|||||||
export def PATH_MAX: i32 = 4096;
|
export def PATH_MAX: i32 = 4096;
|
||||||
let pathbuf: [4096]u8;
|
let pathbuf: [4096]u8;
|
||||||
|
|
||||||
|
// ref/hare/sys/+linux/types.ha:886-888. ww folds `sys` into `os`, so the
|
||||||
|
// std fd NUMBERS live here (the sys role). Typed i32, NOT io.file as in
|
||||||
|
// Hare's os::stdout_file (ref/hare/os/+linux/stdfd.ha:28): Hare's `os`
|
||||||
|
// imports `io`, but ww's `os` is the import floor and must never import
|
||||||
|
// io (lib/CLAUDE.md) — so the io.file/io.handle binding can't live here.
|
||||||
|
// Consumers (lib/fmt's stdio wrappers) cast i32→io.file at the use site,
|
||||||
|
// where the handle layer is already in scope.
|
||||||
|
export def STDIN_FILENO: i32 = 0;
|
||||||
|
export def STDOUT_FILENO: i32 = 1;
|
||||||
|
export def STDERR_FILENO: i32 = 2;
|
||||||
|
|
||||||
fn kpath(p: str) *u8 = {
|
fn kpath(p: str) *u8 = {
|
||||||
if (p.len + 1 >= PATH_MAX) { return nil: *u8; }; // ENAMETOOLONG
|
if (p.len + 1 >= PATH_MAX) { return nil: *u8; }; // ENAMETOOLONG
|
||||||
let i: i32 = 0;
|
let i: i32 = 0;
|
||||||
|
|||||||
@@ -189,6 +189,17 @@ export fn exit(code: i32) void = {
|
|||||||
export def PATH_MAX: i32 = 4096;
|
export def PATH_MAX: i32 = 4096;
|
||||||
let pathbuf: [4096]u8;
|
let pathbuf: [4096]u8;
|
||||||
|
|
||||||
|
// ref/hare/sys/+linux/types.ha:886-888. ww folds `sys` into `os`, so the
|
||||||
|
// std fd NUMBERS live here (the sys role). Typed i32, NOT io.file as in
|
||||||
|
// Hare's os::stdout_file (ref/hare/os/+linux/stdfd.ha:28): Hare's `os`
|
||||||
|
// imports `io`, but ww's `os` is the import floor and must never import
|
||||||
|
// io (lib/CLAUDE.md) — so the io.file/io.handle binding can't live here.
|
||||||
|
// Consumers (lib/fmt's stdio wrappers) cast i32→io.file at the use site,
|
||||||
|
// where the handle layer is already in scope.
|
||||||
|
export def STDIN_FILENO: i32 = 0;
|
||||||
|
export def STDOUT_FILENO: i32 = 1;
|
||||||
|
export def STDERR_FILENO: i32 = 2;
|
||||||
|
|
||||||
fn kpath(p: str) *u8 = {
|
fn kpath(p: str) *u8 = {
|
||||||
if (p.len + 1 >= PATH_MAX) { return nil: *u8; }; // ENAMETOOLONG
|
if (p.len + 1 >= PATH_MAX) { return nil: *u8; }; // ENAMETOOLONG
|
||||||
let i: i32 = 0;
|
let i: i32 = 0;
|
||||||
|
|||||||
@@ -189,6 +189,17 @@ export fn exit(code: i32) void = {
|
|||||||
export def PATH_MAX: i32 = 4096;
|
export def PATH_MAX: i32 = 4096;
|
||||||
let pathbuf: [4096]u8;
|
let pathbuf: [4096]u8;
|
||||||
|
|
||||||
|
// ref/hare/sys/+linux/types.ha:886-888. ww folds `sys` into `os`, so the
|
||||||
|
// std fd NUMBERS live here (the sys role). Typed i32, NOT io.file as in
|
||||||
|
// Hare's os::stdout_file (ref/hare/os/+linux/stdfd.ha:28): Hare's `os`
|
||||||
|
// imports `io`, but ww's `os` is the import floor and must never import
|
||||||
|
// io (lib/CLAUDE.md) — so the io.file/io.handle binding can't live here.
|
||||||
|
// Consumers (lib/fmt's stdio wrappers) cast i32→io.file at the use site,
|
||||||
|
// where the handle layer is already in scope.
|
||||||
|
export def STDIN_FILENO: i32 = 0;
|
||||||
|
export def STDOUT_FILENO: i32 = 1;
|
||||||
|
export def STDERR_FILENO: i32 = 2;
|
||||||
|
|
||||||
fn kpath(p: str) *u8 = {
|
fn kpath(p: str) *u8 = {
|
||||||
if (p.len + 1 >= PATH_MAX) { return nil: *u8; }; // ENAMETOOLONG
|
if (p.len + 1 >= PATH_MAX) { return nil: *u8; }; // ENAMETOOLONG
|
||||||
let i: i32 = 0;
|
let i: i32 = 0;
|
||||||
|
|||||||
@@ -189,6 +189,17 @@ export fn exit(code: i32) void = {
|
|||||||
export def PATH_MAX: i32 = 4096;
|
export def PATH_MAX: i32 = 4096;
|
||||||
let pathbuf: [4096]u8;
|
let pathbuf: [4096]u8;
|
||||||
|
|
||||||
|
// ref/hare/sys/+linux/types.ha:886-888. ww folds `sys` into `os`, so the
|
||||||
|
// std fd NUMBERS live here (the sys role). Typed i32, NOT io.file as in
|
||||||
|
// Hare's os::stdout_file (ref/hare/os/+linux/stdfd.ha:28): Hare's `os`
|
||||||
|
// imports `io`, but ww's `os` is the import floor and must never import
|
||||||
|
// io (lib/CLAUDE.md) — so the io.file/io.handle binding can't live here.
|
||||||
|
// Consumers (lib/fmt's stdio wrappers) cast i32→io.file at the use site,
|
||||||
|
// where the handle layer is already in scope.
|
||||||
|
export def STDIN_FILENO: i32 = 0;
|
||||||
|
export def STDOUT_FILENO: i32 = 1;
|
||||||
|
export def STDERR_FILENO: i32 = 2;
|
||||||
|
|
||||||
fn kpath(p: str) *u8 = {
|
fn kpath(p: str) *u8 = {
|
||||||
if (p.len + 1 >= PATH_MAX) { return nil: *u8; }; // ENAMETOOLONG
|
if (p.len + 1 >= PATH_MAX) { return nil: *u8; }; // ENAMETOOLONG
|
||||||
let i: i32 = 0;
|
let i: i32 = 0;
|
||||||
|
|||||||
@@ -189,6 +189,17 @@ export fn exit(code: i32) void = {
|
|||||||
export def PATH_MAX: i32 = 4096;
|
export def PATH_MAX: i32 = 4096;
|
||||||
let pathbuf: [4096]u8;
|
let pathbuf: [4096]u8;
|
||||||
|
|
||||||
|
// ref/hare/sys/+linux/types.ha:886-888. ww folds `sys` into `os`, so the
|
||||||
|
// std fd NUMBERS live here (the sys role). Typed i32, NOT io.file as in
|
||||||
|
// Hare's os::stdout_file (ref/hare/os/+linux/stdfd.ha:28): Hare's `os`
|
||||||
|
// imports `io`, but ww's `os` is the import floor and must never import
|
||||||
|
// io (lib/CLAUDE.md) — so the io.file/io.handle binding can't live here.
|
||||||
|
// Consumers (lib/fmt's stdio wrappers) cast i32→io.file at the use site,
|
||||||
|
// where the handle layer is already in scope.
|
||||||
|
export def STDIN_FILENO: i32 = 0;
|
||||||
|
export def STDOUT_FILENO: i32 = 1;
|
||||||
|
export def STDERR_FILENO: i32 = 2;
|
||||||
|
|
||||||
fn kpath(p: str) *u8 = {
|
fn kpath(p: str) *u8 = {
|
||||||
if (p.len + 1 >= PATH_MAX) { return nil: *u8; }; // ENAMETOOLONG
|
if (p.len + 1 >= PATH_MAX) { return nil: *u8; }; // ENAMETOOLONG
|
||||||
let i: i32 = 0;
|
let i: i32 = 0;
|
||||||
|
|||||||
@@ -1696,7 +1696,7 @@ static const struct row rows[] = {
|
|||||||
"fn main() i32 = { return sumtag(1i64, \"hi\", true): i32; };", 42 },
|
"fn main() i32 = { return sumtag(1i64, \"hi\", true): i32; };", 42 },
|
||||||
/* Variadic forwarding: `wrap(args...)` passes the local slice
|
/* Variadic forwarding: `wrap(args...)` passes the local slice
|
||||||
* directly to `sum`, no re-gather. Mirrors Hare's wrapper shape
|
* 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"
|
{ "fn sum(args: i64...) i64 = {\n"
|
||||||
" let s: i64 = 0i64;\n"
|
" let s: i64 = 0i64;\n"
|
||||||
" let i: i32 = 0;\n"
|
" let i: i32 = 0;\n"
|
||||||
@@ -1711,11 +1711,12 @@ static const struct row rows[] = {
|
|||||||
"};", 42 },
|
"};", 42 },
|
||||||
/* lib/fmt user-side: `fmt.println(args: formattable...)` gathers
|
/* lib/fmt user-side: `fmt.println(args: formattable...)` gathers
|
||||||
* mixed-type args at the call site. End-to-end exercises the
|
* mixed-type args at the call site. End-to-end exercises the
|
||||||
* lib/fmt graduation: the wrapper-chain `println → fdprintln →
|
* lib/fmt graduation: the wrapper-chain `println → fprintln →
|
||||||
* fdprint` is itself variadic-forwarding, so this validates both
|
* fprint` over an io.handle file arm is itself variadic-forwarding,
|
||||||
* gather (at main) and `args...` forward (inside lib/fmt). println
|
* so this validates both gather (at main) and `args...` forward
|
||||||
* returns Hare's `(size | io.error)` (#94 fold-eFinal); the size
|
* (inside lib/fmt). println returns Hare's `(size | io.error)`
|
||||||
* arm carries bytes printed (`hello 7\n` = 8). */
|
* (#94 fold-eFinal); the size arm carries bytes printed
|
||||||
|
* (`hello 7\n` = 8). */
|
||||||
{ "import fmt;\n"
|
{ "import fmt;\n"
|
||||||
"import io;\n"
|
"import io;\n"
|
||||||
"fn main() i32 = {\n"
|
"fn main() i32 = {\n"
|
||||||
|
|||||||
@@ -1,86 +1,66 @@
|
|||||||
/*
|
/*
|
||||||
* 777_fmt_vstream_run — project #94 fold-eFinal sentinel. Pins the
|
* 777_fmt_handle_run — io fold-2 (#5) commit-2 sentinel. Pins the
|
||||||
* single-surface lib/fmt fd shim: stack-resident fd_ctx with
|
* fprint family over an [[io.handle]] sink after the fdsink shim
|
||||||
* `vt: io.vtable` as the first field for the intrusive io.stream
|
* removal: fmt's fprint/fprintln/fprintf now take `io.handle =
|
||||||
* cast, four wrappers (fdprint / fdprintln / fdprintf / fdprintfln)
|
* (io.file | io.stream)`, so a raw fd (file arm) and a memio vtable
|
||||||
* that take a raw fd, allocate fd_ctx on their own frame (never
|
* (stream arm) both flow into the same surface and io.write dispatches
|
||||||
* escapes — ken's dispatcher-CONTAINED discipline), and dispatch
|
* per arm. Supersedes the pre-#5 fd_ctx workaround (the fake-stream
|
||||||
* through io.write via the wired fdsinkwrite callback. The fd shim
|
* vtable around os.write) — drew's placeholder for the then-missing
|
||||||
* has no Hare counterpart; it folds into fNNN-over-handle once io
|
* handle, removed by this commit.
|
||||||
* fold-2 (#5) ports `handle = (file | int)`.
|
|
||||||
*
|
*
|
||||||
* Each row imports fmt + os + io, opens a per-process /tmp output
|
* The file-arm rows open a per-process /tmp output file, call one
|
||||||
* file, calls one V wrapper to write through the fd, closes, re-
|
* fprint-family fn with `fd: io.file` (widens to io.handle), close,
|
||||||
* opens for read, reads the bytes back, and asserts both (a) the
|
* reopen for read, read the bytes back, and assert both (a) the exact
|
||||||
* exact byte content and (b) a unique row-tagged exit constant.
|
* 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
|
* Cstage-only per row (no STAGE_WW, no byte_id) — pre-existing wwstage
|
||||||
* wwstage bug #209 (sibling of #190): the wwstage checker bails
|
* bug #209 (sibling of #190): the wwstage checker bails `case: not a
|
||||||
* `case: not a variant of scrutinee (X)` + `match: variant not
|
* variant of scrutinee (X)` + `match: variant not handled
|
||||||
* handled (formattable)` on the OLD fmt.fdprint / fdprintf's
|
* (formattable)` on fmt's match-on-formattable arms whenever a
|
||||||
* match-on-formattable arms whenever a downstream probe `import
|
* downstream probe `import fmt;`s the package. The bug bites identically
|
||||||
* fmt;`s the package. The bug bites the OLD surface identically
|
* — `fmt.errorln("hi")` from a probe trips the same trace — and is
|
||||||
* — `fmt.errorln("hi")` from a probe trips the same trace. The
|
* pre-existing (reproduces on master). Every fmt test is cstage-only
|
||||||
* pre-existing surface (fmt.ww) is fine via cstage because every
|
* (970 fmttest runs the @test fixture under cstage `ww run` only); 995
|
||||||
* other test that uses fmt is cstage-only (970 fmttest runs the
|
* self-rebuild dodges it because no selfhost main pulls err.ww
|
||||||
* @test fixture under cstage `ww run` only). 995 self-rebuild
|
* transitively, so wwstage never compiles fmt in the bootstrap. Fix =
|
||||||
* dodges it because no selfhost cmd imports fmt transitively —
|
* one-class checker repair, out of #5 commit-2 scope; byte-id graduates
|
||||||
* fmt is consumed by selfhost/cmd/wcc/err.ww but no main.ww in
|
* with #209 close.
|
||||||
* 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.
|
|
||||||
*
|
*
|
||||||
* row | what it pins
|
* row | what it pins
|
||||||
* --------------------------+--------------------------------------
|
* ---------------------+--------------------------------------
|
||||||
* fdprintf_v_int | fdprintf with `"v={}\n"`-style
|
* fprintf_file_int | fprintf(fd: io.file, "v={}\n", 42)
|
||||||
* | format + one i64 arg. Asserts the
|
* | over the FILE arm -> io.write -> os.write,
|
||||||
* | full intrusive shape (stack fd_ctx →
|
* | plus the {n}-placeholder parser through
|
||||||
* | &c.vt → io.write → fdsinkwrite
|
* | formatfield.
|
||||||
* | → os.write) plus the {n}-placeholder
|
* fprintln_file_multi | fprintln(fd: io.file, 7, "hi", true) —
|
||||||
* | parser routed through vformatfield.
|
* | three positional args, space-separator
|
||||||
* fdprintln_v_multi | fdprintln with three positional
|
* | + trailing newline shape over the file arm.
|
||||||
* | args (i64 + str + bool). Asserts the
|
* fprint_file_raw | fprint(fd: io.file, "raw") — one str arg,
|
||||||
* | space-separator + trailing newline
|
* | no placeholder parser (bare fprint loop).
|
||||||
* | shape mirrors OLD fdprintln (fmt.ww:
|
* branched_fprintf | branched callee per #105: two distinct
|
||||||
* | 145), routed through io.write.
|
* | format strings runtime-selected from a
|
||||||
* fdprint_v_raw | fdprint with one str arg, no
|
* | single fprintf call site.
|
||||||
* | format mods (zero-format raw). Pins
|
* fprintf_stream | fprintf over a memio.fixed io.stream
|
||||||
* | the per-arg loop without the
|
* | (the STREAM arm of io.handle) read back
|
||||||
* | placeholder parser (fprint code
|
* | via memio.string — the other handle arm.
|
||||||
* | 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).
|
|
||||||
*
|
*
|
||||||
* IMPORT-ORDER WORKAROUND (sibling task #208, pre-existing): every
|
* IMPORT-ORDER WORKAROUND (sibling task #208, pre-existing): every row
|
||||||
* row places `import os;` FIRST for the same reason 776 documents
|
* places `import os;` FIRST for the same reason 776 documents (wwstage
|
||||||
* (wwstage checker ordering-sensitivity on os.tryread/trywrite/
|
* checker ordering-sensitivity on os.tryread/trywrite/tryopen's bare
|
||||||
* tryopen's bare `return r;` over a tagged return type).
|
* `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
|
* GATE POLARITY: must stay GREEN. A red here means lib/fmt regressed,
|
||||||
* ref/hare/fmt/wrappers.ha:9-25 routes through io::handle; fdNNN
|
* the file->handle widen miscompiled, io.write's per-arm dispatch broke,
|
||||||
* collapses into bare fNNN once handle = (file | int) lands.
|
* the {n}-placeholder dispatch through formatfield regressed, or the
|
||||||
* #5 graduates.
|
* memio stream arm lost its offset-0 vtable invariant.
|
||||||
*
|
|
||||||
* - #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.
|
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -109,16 +89,16 @@ struct row {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const struct row rows[] = {
|
static const struct row rows[] = {
|
||||||
{ "fdprintf_v_int",
|
{ "fprintf_file_int",
|
||||||
"package main;\n"
|
"package main;\n"
|
||||||
"import os;\n"
|
"import os;\n"
|
||||||
"import fmt;\n"
|
"import fmt;\n"
|
||||||
"import io;\n"
|
"import io;\n"
|
||||||
"export fn main() i32 = {\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"
|
" let fd: i32 = os.open(path, os.flag.RDWR | os.flag.CREATE | os.flag.TRUNC, 0o644: i32);\n"
|
||||||
" if (fd < 0) { return 90; };\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"
|
" let nw: size = 0;\n"
|
||||||
" match (wr) {\n"
|
" match (wr) {\n"
|
||||||
" case let n: size => { nw = n; };\n"
|
" case let n: size => { nw = n; };\n"
|
||||||
@@ -137,16 +117,16 @@ static const struct row rows[] = {
|
|||||||
"};\n",
|
"};\n",
|
||||||
42,
|
42,
|
||||||
STAGE_CS, 0 },
|
STAGE_CS, 0 },
|
||||||
{ "fdprintln_v_multi",
|
{ "fprintln_file_multi",
|
||||||
"package main;\n"
|
"package main;\n"
|
||||||
"import os;\n"
|
"import os;\n"
|
||||||
"import fmt;\n"
|
"import fmt;\n"
|
||||||
"import io;\n"
|
"import io;\n"
|
||||||
"export fn main() i32 = {\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"
|
" let fd: i32 = os.open(path, os.flag.RDWR | os.flag.CREATE | os.flag.TRUNC, 0o644: i32);\n"
|
||||||
" if (fd < 0) { return 90; };\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"
|
" let nw: size = 0;\n"
|
||||||
" match (wr) {\n"
|
" match (wr) {\n"
|
||||||
" case let n: size => { nw = n; };\n"
|
" case let n: size => { nw = n; };\n"
|
||||||
@@ -165,16 +145,16 @@ static const struct row rows[] = {
|
|||||||
"};\n",
|
"};\n",
|
||||||
43,
|
43,
|
||||||
STAGE_CS, 0 },
|
STAGE_CS, 0 },
|
||||||
{ "fdprint_v_raw",
|
{ "fprint_file_raw",
|
||||||
"package main;\n"
|
"package main;\n"
|
||||||
"import os;\n"
|
"import os;\n"
|
||||||
"import fmt;\n"
|
"import fmt;\n"
|
||||||
"import io;\n"
|
"import io;\n"
|
||||||
"export fn main() i32 = {\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"
|
" let fd: i32 = os.open(path, os.flag.RDWR | os.flag.CREATE | os.flag.TRUNC, 0o644: i32);\n"
|
||||||
" if (fd < 0) { return 90; };\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"
|
" let nw: size = 0;\n"
|
||||||
" match (wr) {\n"
|
" match (wr) {\n"
|
||||||
" case let n: size => { nw = n; };\n"
|
" case let n: size => { nw = n; };\n"
|
||||||
@@ -193,13 +173,13 @@ static const struct row rows[] = {
|
|||||||
"};\n",
|
"};\n",
|
||||||
44,
|
44,
|
||||||
STAGE_CS, 0 },
|
STAGE_CS, 0 },
|
||||||
{ "branched_fdprintf",
|
{ "branched_fprintf",
|
||||||
"package main;\n"
|
"package main;\n"
|
||||||
"import os;\n"
|
"import os;\n"
|
||||||
"import fmt;\n"
|
"import fmt;\n"
|
||||||
"import io;\n"
|
"import io;\n"
|
||||||
"export fn main() i32 = {\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"
|
" let fd: i32 = os.open(path, os.flag.RDWR | os.flag.CREATE | os.flag.TRUNC, 0o644: i32);\n"
|
||||||
" if (fd < 0) { return 90; };\n"
|
" if (fd < 0) { return 90; };\n"
|
||||||
" let sel: i32 = 1;\n"
|
" let sel: i32 = 1;\n"
|
||||||
@@ -207,7 +187,7 @@ static const struct row rows[] = {
|
|||||||
" let f2: str = \"B{}\";\n"
|
" let f2: str = \"B{}\";\n"
|
||||||
" let fmtstr: str = f1;\n"
|
" let fmtstr: str = f1;\n"
|
||||||
" if (sel == 0) { fmtstr = f2; };\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"
|
" let nw: size = 0;\n"
|
||||||
" match (wr) {\n"
|
" match (wr) {\n"
|
||||||
" case let n: size => { nw = n; };\n"
|
" case let n: size => { nw = n; };\n"
|
||||||
@@ -226,6 +206,30 @@ static const struct row rows[] = {
|
|||||||
"};\n",
|
"};\n",
|
||||||
45,
|
45,
|
||||||
STAGE_CS, 0 },
|
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
|
static int
|
||||||
@@ -269,7 +273,7 @@ static int
|
|||||||
run_row(const char *driver, const char *cwd, const struct row *r, int seq)
|
run_row(const char *driver, const char *cwd, const struct row *r, int seq)
|
||||||
{
|
{
|
||||||
char tmpdir[256], src[512], base[64], outbin[768];
|
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(base, sizeof base, "main777");
|
||||||
snprintf(src, sizeof src, "%s/%s.ww", tmpdir, base);
|
snprintf(src, sizeof src, "%s/%s.ww", tmpdir, base);
|
||||||
mkdir(tmpdir, 0755);
|
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
|
/* asm_byte_identical — diff cstage vs wwstage .s. Parallel trees so
|
||||||
* ww_ww writing intermediates next to the source doesn't clobber the
|
* 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
|
static int
|
||||||
asm_byte_identical(const char *cdrv, const char *wdrv, const char *cwd,
|
asm_byte_identical(const char *cdrv, const char *wdrv, const char *cwd,
|
||||||
const struct row *r, int seq)
|
const struct row *r, int seq)
|
||||||
{
|
{
|
||||||
char src[512], tdc[256], tdw[256], base[64], cs[512], ws[512];
|
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(tdc, sizeof tdc, "/tmp/fh_%d_c_%d", getpid(), seq);
|
||||||
snprintf(tdw, sizeof tdw, "/tmp/fvs_%d_w_%d", getpid(), seq);
|
snprintf(tdw, sizeof tdw, "/tmp/fh_%d_w_%d", getpid(), seq);
|
||||||
snprintf(base, sizeof base, "main777");
|
snprintf(base, sizeof base, "main777");
|
||||||
mkdir(tdc, 0755);
|
mkdir(tdc, 0755);
|
||||||
mkdir(tdw, 0755);
|
mkdir(tdw, 0755);
|
||||||
@@ -350,6 +356,7 @@ main(void)
|
|||||||
int total = 0, fail = 0;
|
int total = 0, fail = 0;
|
||||||
int wwpresent = (access(wdrv, X_OK) == 0);
|
int wwpresent = (access(wdrv, X_OK) == 0);
|
||||||
int seq = 0;
|
int seq = 0;
|
||||||
|
(void)asm_byte_identical; /* cstage-only until #209 closes */
|
||||||
|
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
if (rows[i].stage_mask & STAGE_CS) {
|
if (rows[i].stage_mask & STAGE_CS) {
|
||||||
@@ -357,7 +364,7 @@ main(void)
|
|||||||
int got = run_row(cdrv, cwd, &rows[i], seq++);
|
int got = run_row(cdrv, cwd, &rows[i], seq++);
|
||||||
if (got != rows[i].want_exit) {
|
if (got != rows[i].want_exit) {
|
||||||
fprintf(stderr,
|
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);
|
rows[i].label, got, rows[i].want_exit);
|
||||||
fail++;
|
fail++;
|
||||||
}
|
}
|
||||||
@@ -367,7 +374,7 @@ main(void)
|
|||||||
int got = run_row(wdrv, cwd, &rows[i], seq++);
|
int got = run_row(wdrv, cwd, &rows[i], seq++);
|
||||||
if (got != rows[i].want_exit) {
|
if (got != rows[i].want_exit) {
|
||||||
fprintf(stderr,
|
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);
|
rows[i].label, got, rows[i].want_exit);
|
||||||
fail++;
|
fail++;
|
||||||
}
|
}
|
||||||
@@ -375,7 +382,7 @@ main(void)
|
|||||||
total++;
|
total++;
|
||||||
if (asm_byte_identical(cdrv, wdrv, cwd, &rows[i], seq++) != 0) {
|
if (asm_byte_identical(cdrv, wdrv, cwd, &rows[i], seq++) != 0) {
|
||||||
fprintf(stderr,
|
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);
|
rows[i].label);
|
||||||
fail++;
|
fail++;
|
||||||
}
|
}
|
||||||
@@ -384,13 +391,13 @@ main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!wwpresent)
|
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) {
|
if (fail) {
|
||||||
fprintf(stderr, "fmt_vstream_run: %d/%d fixtures failed\n",
|
fprintf(stderr, "fmt_handle_run: %d/%d fixtures failed\n",
|
||||||
fail, total);
|
fail, total);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
printf("fmt_vstream_run: %d/%d ok\n", total, total);
|
printf("fmt_handle_run: %d/%d ok\n", total, total);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -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 /
|
* modifier-formatting machinery (rawleni64 / rawlenstr / rawlenf64 /
|
||||||
* rawlen / formatraw / formatone) in lib/fmt/fmt.ww: formatfield takes
|
* rawlen / formatraw / formatone) in lib/fmt/fmt.ww: formatfield takes
|
||||||
* `*mods` and routes through formatone so the {:mods} placeholder
|
* `*mods` and routes through formatone so the {:mods} placeholder
|
||||||
* honours width / alignment / pad / sign / base / prec. The fold-eFinal
|
* honours width / alignment / pad / sign / base / prec. #5 graduated
|
||||||
* FLIP collapsed the dual fmt surface into this one (the former `v*`
|
* fprintf's sink io.stream -> io.handle; these rows drive it over the
|
||||||
* modifier helpers merged into the bare names).
|
* FILE arm (`fd: io.file` widens to io.handle).
|
||||||
*
|
*
|
||||||
* Each row imports fmt + os + io, opens a per-process /tmp output
|
* Each row imports fmt + os + io, opens a per-process /tmp output file,
|
||||||
* file, calls fdprintf with a {:mods} format string + one arg, and
|
* calls fprintf with a {:mods} format string + one arg, and asserts the
|
||||||
* asserts the exact byte content read back.
|
* exact byte content read back.
|
||||||
*
|
*
|
||||||
* Cstage-only per row — pre-existing wwstage bug #209 (sibling of
|
* Cstage-only per row — pre-existing wwstage bug #209 (sibling of
|
||||||
* #190): the wwstage checker bails on fmt.formattable match-arms
|
* #190): the wwstage checker bails on fmt.formattable match-arms
|
||||||
* whenever a downstream probe `import fmt;`s the package. Identical
|
* whenever a downstream probe `import fmt;`s the package. Identical
|
||||||
* carve-out to 777_fmt_vstream_run (cited there at line 18-33).
|
* carve-out to 777_fmt_handle_run (cited there). Byte-id graduates with
|
||||||
* Byte-id graduates with #209 close.
|
* #209 close.
|
||||||
*
|
*
|
||||||
* row | format | arg | expect | exit
|
* row | format | arg | expect | exit
|
||||||
* -----------------+------------+--------------+-----------+-----
|
* -----------------+------------+--------------+-----------+-----
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
* sign_plus | "{:+}" | 7i64 | "+7" | 53
|
* sign_plus | "{:+}" | 7i64 | "+7" | 53
|
||||||
* zero_pad | "{:_05}" | 42i64 | "00042" | 54
|
* 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
|
* width digits 1..9 — RIGHT-align pad to N chars
|
||||||
* prec '.' + digits — str truncation / int min-digits
|
* prec '.' + digits — str truncation / int min-digits
|
||||||
@@ -35,31 +35,28 @@
|
|||||||
*
|
*
|
||||||
* Drew NaN/Inf signoff (carry from task #58): f64 arm not exercised
|
* 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
|
* 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
|
* once Drew's strconv.f64tos shortest-G stays static.
|
||||||
* implementation honours the sign-peel in vformatraw f64 arm; an
|
|
||||||
* end-to-end test lands when a NaN/Inf-aware probe joins the corpus.
|
|
||||||
*
|
*
|
||||||
* IMPORT-ORDER WORKAROUND (sibling task #208, pre-existing): every
|
* IMPORT-ORDER WORKAROUND (sibling task #208, pre-existing): every row
|
||||||
* row places `import os;` FIRST for the same reason 776/777 document
|
* places `import os;` FIRST for the same reason 776/777 document
|
||||||
* (wwstage checker ordering-sensitivity on os.tryread/trywrite/
|
* (wwstage checker ordering-sensitivity on os.tryread/trywrite/
|
||||||
* tryopen's bare `return r;` over a tagged return type).
|
* tryopen's bare `return r;` over a tagged return type).
|
||||||
*
|
*
|
||||||
* DEFERRALS / RELATED (NOT addressed by these rows):
|
* DEFERRALS / RELATED (NOT addressed by these rows):
|
||||||
*
|
*
|
||||||
* - #209 (wwstage formattable match-arm bail): blocks STAGE_WW
|
* - #209 (wwstage formattable match-arm bail): blocks STAGE_WW here,
|
||||||
* here, same as 777_fmt_vstream_run. Cstage-only until close.
|
* same as 777_fmt_handle_run. Cstage-only until close.
|
||||||
*
|
*
|
||||||
* BOOTSTRAP-EMBED CHECK: fmt is NOT embedded in any selfhost
|
* BOOTSTRAP-EMBED CHECK: fmt is NOT embedded in any selfhost
|
||||||
* combined.ww (grep confirmed), so the fold-eFinal fmt collapse does
|
* combined.ww (grep confirmed), so the #5 fmt graduation does NOT
|
||||||
* NOT require a Makefile regen (#110); only test paths see the
|
* require a Makefile regen (#110); only test paths see the machinery.
|
||||||
* machinery. 990-997 byte-id gates stay green by virtue of fmt being
|
* 990-997 byte-id gates stay green by virtue of fmt being test-only on
|
||||||
* test-only on the bootstrap surface.
|
* the bootstrap surface.
|
||||||
*
|
*
|
||||||
* GATE POLARITY: must stay GREEN. A red here means formatone /
|
* GATE POLARITY: must stay GREEN. A red here means formatone /
|
||||||
* formatraw / rawlen miscomputed bytes, formatfield regressed its
|
* formatraw / rawlen miscomputed bytes, formatfield regressed its
|
||||||
* *mods route, scanmods/modsinit drifted, or the strconv.u64tos base
|
* *mods route, scanmods/modsinit drifted, or the strconv.u64tos base
|
||||||
* path miscompiled under fdprintf's intrusive io.stream→*fd_ctx
|
* path miscompiled under fprintf over the io.handle file arm.
|
||||||
* dispatch.
|
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -94,10 +91,10 @@ static const struct row rows[] = {
|
|||||||
"import fmt;\n"
|
"import fmt;\n"
|
||||||
"import io;\n"
|
"import io;\n"
|
||||||
"export fn main() i32 = {\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"
|
" let fd: i32 = os.open(path, os.flag.RDWR | os.flag.CREATE | os.flag.TRUNC, 0o644: i32);\n"
|
||||||
" if (fd < 0) { return 90; };\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"
|
" let nw: size = 0;\n"
|
||||||
" match (wr) {\n"
|
" match (wr) {\n"
|
||||||
" case let n: size => { nw = n; };\n"
|
" case let n: size => { nw = n; };\n"
|
||||||
@@ -122,10 +119,10 @@ static const struct row rows[] = {
|
|||||||
"import fmt;\n"
|
"import fmt;\n"
|
||||||
"import io;\n"
|
"import io;\n"
|
||||||
"export fn main() i32 = {\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"
|
" let fd: i32 = os.open(path, os.flag.RDWR | os.flag.CREATE | os.flag.TRUNC, 0o644: i32);\n"
|
||||||
" if (fd < 0) { return 90; };\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"
|
" let nw: size = 0;\n"
|
||||||
" match (wr) {\n"
|
" match (wr) {\n"
|
||||||
" case let n: size => { nw = n; };\n"
|
" case let n: size => { nw = n; };\n"
|
||||||
@@ -150,10 +147,10 @@ static const struct row rows[] = {
|
|||||||
"import fmt;\n"
|
"import fmt;\n"
|
||||||
"import io;\n"
|
"import io;\n"
|
||||||
"export fn main() i32 = {\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"
|
" let fd: i32 = os.open(path, os.flag.RDWR | os.flag.CREATE | os.flag.TRUNC, 0o644: i32);\n"
|
||||||
" if (fd < 0) { return 90; };\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"
|
" let nw: size = 0;\n"
|
||||||
" match (wr) {\n"
|
" match (wr) {\n"
|
||||||
" case let n: size => { nw = n; };\n"
|
" case let n: size => { nw = n; };\n"
|
||||||
@@ -178,10 +175,10 @@ static const struct row rows[] = {
|
|||||||
"import fmt;\n"
|
"import fmt;\n"
|
||||||
"import io;\n"
|
"import io;\n"
|
||||||
"export fn main() i32 = {\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"
|
" let fd: i32 = os.open(path, os.flag.RDWR | os.flag.CREATE | os.flag.TRUNC, 0o644: i32);\n"
|
||||||
" if (fd < 0) { return 90; };\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"
|
" let nw: size = 0;\n"
|
||||||
" match (wr) {\n"
|
" match (wr) {\n"
|
||||||
" case let n: size => { nw = n; };\n"
|
" case let n: size => { nw = n; };\n"
|
||||||
@@ -206,10 +203,10 @@ static const struct row rows[] = {
|
|||||||
"import fmt;\n"
|
"import fmt;\n"
|
||||||
"import io;\n"
|
"import io;\n"
|
||||||
"export fn main() i32 = {\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"
|
" let fd: i32 = os.open(path, os.flag.RDWR | os.flag.CREATE | os.flag.TRUNC, 0o644: i32);\n"
|
||||||
" if (fd < 0) { return 90; };\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"
|
" let nw: size = 0;\n"
|
||||||
" match (wr) {\n"
|
" match (wr) {\n"
|
||||||
" case let n: size => { nw = n; };\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)
|
run_row(const char *driver, const char *cwd, const struct row *r, int seq)
|
||||||
{
|
{
|
||||||
char tmpdir[256], src[512], base[64], outbin[768];
|
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(base, sizeof base, "main780");
|
||||||
snprintf(src, sizeof src, "%s/%s.ww", tmpdir, base);
|
snprintf(src, sizeof src, "%s/%s.ww", tmpdir, base);
|
||||||
mkdir(tmpdir, 0755);
|
mkdir(tmpdir, 0755);
|
||||||
@@ -315,7 +312,7 @@ main(void)
|
|||||||
int got = run_row(cdrv, cwd, &rows[i], seq++);
|
int got = run_row(cdrv, cwd, &rows[i], seq++);
|
||||||
if (got != rows[i].want_exit) {
|
if (got != rows[i].want_exit) {
|
||||||
fprintf(stderr,
|
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);
|
rows[i].label, got, rows[i].want_exit);
|
||||||
fail++;
|
fail++;
|
||||||
}
|
}
|
||||||
@@ -325,7 +322,7 @@ main(void)
|
|||||||
int got = run_row(wdrv, cwd, &rows[i], seq++);
|
int got = run_row(wdrv, cwd, &rows[i], seq++);
|
||||||
if (got != rows[i].want_exit) {
|
if (got != rows[i].want_exit) {
|
||||||
fprintf(stderr,
|
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);
|
rows[i].label, got, rows[i].want_exit);
|
||||||
fail++;
|
fail++;
|
||||||
}
|
}
|
||||||
@@ -333,13 +330,13 @@ main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!wwpresent)
|
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) {
|
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);
|
fail, total);
|
||||||
return 1;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1,90 +1,69 @@
|
|||||||
/*
|
/*
|
||||||
* 781_fmt_vstream_compositions_run — project #94 fold-eFinal sentinel.
|
* 781_fmt_compositions_run — io fold-2 (#5) commit-2 sentinel. Pins the
|
||||||
* Pins the composition wrappers in lib/fmt/fmt.ww —
|
* composition wrappers in lib/fmt/fmt.ww — fprintln / fprintfln /
|
||||||
* fprintln / fprintfln / bsprintf / asprintf — plus the memio
|
* bsprintf / asprintf — plus the memio accessor (memio.string in
|
||||||
* accessor (memio.string in lib/memio/memio.ww) they read back
|
* lib/memio/memio.ww) they read back through. #5 graduated the
|
||||||
* through. The fold-eFinal FLIP collapsed the dual fmt + memio
|
* fprint-family sink io.stream -> io.handle; the file-arm rows drive
|
||||||
* surfaces into one (the former `v`-suffixed wrappers and the
|
* fprintln / fprintfln over `fd: io.file`, the stream-arm rows over a
|
||||||
* fixed_string / dynamic_string accessors merged into the bare names).
|
* memio.fixed io.stream — both arms of io.handle.
|
||||||
*
|
*
|
||||||
* memio.string is the direct enabler: bsprintf reads its written
|
* memio.string is the direct enabler: bsprintf reads its written prefix
|
||||||
* prefix via memio.string; asprintf reads its grown buffer via the
|
* via memio.string; asprintf reads its grown buffer via the same
|
||||||
* same accessor.
|
* accessor.
|
||||||
*
|
*
|
||||||
* Each row imports fmt + os + io, drives one of the four V wrappers,
|
* row | what it pins
|
||||||
* and asserts the exact bytes / size emitted. Per-row unique exit
|
* --------------------+--------------------------------------
|
||||||
* constant lets a failure pinpoint the offending case.
|
* 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
|
* 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
|
||||||
* fdprintln_v_run_basic | fdprintln wired vstream sink
|
* variant of scrutinee (X)` + `match: variant not handled
|
||||||
* | (inline fprint + vputbytes "\n").
|
* (formattable)` on fmt.formattable match-arms whenever a downstream
|
||||||
* | One i64 arg + str arg + bool arg;
|
* probe `import fmt;`s the package. Identical carve-out to
|
||||||
* | asserts space-separator plus trailing
|
* 777_fmt_handle_run + 780_fmt_mods_run. Byte-id graduates with #209
|
||||||
* | newline byte content.
|
* close.
|
||||||
* 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
|
* IMPORT-ORDER WORKAROUND (sibling task #208, pre-existing): every row
|
||||||
* wwstage bug #209 (sibling of #190): the wwstage checker bails
|
* places `import os;` FIRST for the same reason 776/777/780 document
|
||||||
* `case: not a variant of scrutinee (X)` + `match: variant not
|
* (wwstage checker ordering-sensitivity on os.tryread / trywrite /
|
||||||
* handled (formattable)` on fmt.formattable match-arms whenever a
|
* tryopen's bare `return r;` over a tagged return type).
|
||||||
* 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).
|
|
||||||
*
|
*
|
||||||
* DEFERRALS / RELATED (NOT addressed by these rows):
|
* DEFERRALS / RELATED (NOT addressed by these rows):
|
||||||
*
|
*
|
||||||
* - #209 (wwstage formattable match-arm bail): blocks STAGE_WW
|
* - #209 (wwstage formattable match-arm bail): blocks STAGE_WW here,
|
||||||
* here, same as 777/780. Cstage-only until close.
|
* same as 777/780. Cstage-only until close.
|
||||||
* - #173 (TRY-on-tagged-return both-stages broken): bsprintf
|
* - #173 (TRY-on-tagged-return both-stages broken): bsprintf widens
|
||||||
* widens nomem into io.error inline rather than `memio.
|
* nomem into io.error inline rather than `memio.fixed(buf)?` for
|
||||||
* fixed(buf)?` for the same reason memio.ww does.
|
* the same reason memio.ww does.
|
||||||
*
|
*
|
||||||
* BOOTSTRAP-EMBED CHECK: fmt is NOT embedded in any selfhost
|
* BOOTSTRAP-EMBED CHECK: fmt is NOT embedded in any selfhost
|
||||||
* combined.ww (grep verified). memio IS embedded in w6c + wwdump
|
* combined.ww (grep verified). memio IS embedded in w6c + wwdump
|
||||||
* combined.ww — the fold-eFinal memio collapse rides along via the
|
* combined.ww but is unchanged by #5, so no regen rides along here.
|
||||||
* regen committed in this same commit (per #110 SSoT). 990/994/995
|
* 990/994/995 byte-id gates stay green.
|
||||||
* byte-id gates + combined_ww_fresh stay green by virtue of the
|
|
||||||
* regen.
|
|
||||||
*
|
*
|
||||||
* GATE POLARITY: must stay GREEN. A red here means fprintln /
|
* GATE POLARITY: must stay GREEN. A red here means fprintln /
|
||||||
* fprintfln dropped the newline byte, bsprintf returned a stale
|
* fprintfln dropped the newline byte, bsprintf returned a stale
|
||||||
* memio.string view (intrusive cast broke), asprintf failed
|
* memio.string view (intrusive cast broke), asprintf failed to
|
||||||
* to shrink-copy / close cleanly, or the underlying fprint /
|
* shrink-copy / close cleanly, or the underlying fprint / fprintf
|
||||||
* fprintf primitives regressed.
|
* primitives regressed over the io.handle sink.
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -113,16 +92,16 @@ struct row {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const struct row rows[] = {
|
static const struct row rows[] = {
|
||||||
{ "fdprintln_v_run_basic",
|
{ "fprintln_file_basic",
|
||||||
"package main;\n"
|
"package main;\n"
|
||||||
"import os;\n"
|
"import os;\n"
|
||||||
"import fmt;\n"
|
"import fmt;\n"
|
||||||
"import io;\n"
|
"import io;\n"
|
||||||
"export fn main() i32 = {\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"
|
" let fd: i32 = os.open(path, os.flag.RDWR | os.flag.CREATE | os.flag.TRUNC, 0o644: i32);\n"
|
||||||
" if (fd < 0) { return 90; };\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"
|
" let nw: size = 0;\n"
|
||||||
" match (wr) {\n"
|
" match (wr) {\n"
|
||||||
" case let n: size => { nw = n; };\n"
|
" case let n: size => { nw = n; };\n"
|
||||||
@@ -145,16 +124,16 @@ static const struct row rows[] = {
|
|||||||
"};\n",
|
"};\n",
|
||||||
60,
|
60,
|
||||||
STAGE_CS, 0 },
|
STAGE_CS, 0 },
|
||||||
{ "fdprintfln_v_run_fmt",
|
{ "fprintfln_file_fmt",
|
||||||
"package main;\n"
|
"package main;\n"
|
||||||
"import os;\n"
|
"import os;\n"
|
||||||
"import fmt;\n"
|
"import fmt;\n"
|
||||||
"import io;\n"
|
"import io;\n"
|
||||||
"export fn main() i32 = {\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"
|
" let fd: i32 = os.open(path, os.flag.RDWR | os.flag.CREATE | os.flag.TRUNC, 0o644: i32);\n"
|
||||||
" if (fd < 0) { return 90; };\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"
|
" let nw: size = 0;\n"
|
||||||
" match (wr) {\n"
|
" match (wr) {\n"
|
||||||
" case let n: size => { nw = n; };\n"
|
" case let n: size => { nw = n; };\n"
|
||||||
@@ -225,7 +204,7 @@ static const struct row rows[] = {
|
|||||||
"};\n",
|
"};\n",
|
||||||
65,
|
65,
|
||||||
STAGE_CS, 0 },
|
STAGE_CS, 0 },
|
||||||
{ "bsprintf_v_basic",
|
{ "bsprintf_basic",
|
||||||
"package main;\n"
|
"package main;\n"
|
||||||
"import os;\n"
|
"import os;\n"
|
||||||
"import fmt;\n"
|
"import fmt;\n"
|
||||||
@@ -246,7 +225,7 @@ static const struct row rows[] = {
|
|||||||
"};\n",
|
"};\n",
|
||||||
62,
|
62,
|
||||||
STAGE_CS, 0 },
|
STAGE_CS, 0 },
|
||||||
{ "asprintf_v_basic",
|
{ "asprintf_basic",
|
||||||
"package main;\n"
|
"package main;\n"
|
||||||
"import os;\n"
|
"import os;\n"
|
||||||
"import fmt;\n"
|
"import fmt;\n"
|
||||||
@@ -304,7 +283,7 @@ static int
|
|||||||
run_row(const char *driver, const char *cwd, const struct row *r, int seq)
|
run_row(const char *driver, const char *cwd, const struct row *r, int seq)
|
||||||
{
|
{
|
||||||
char tmpdir[256], src[512], base[64], outbin[768];
|
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(base, sizeof base, "main781");
|
||||||
snprintf(src, sizeof src, "%s/%s.ww", tmpdir, base);
|
snprintf(src, sizeof src, "%s/%s.ww", tmpdir, base);
|
||||||
mkdir(tmpdir, 0755);
|
mkdir(tmpdir, 0755);
|
||||||
@@ -349,7 +328,7 @@ main(void)
|
|||||||
int got = run_row(cdrv, cwd, &rows[i], seq++);
|
int got = run_row(cdrv, cwd, &rows[i], seq++);
|
||||||
if (got != rows[i].want_exit) {
|
if (got != rows[i].want_exit) {
|
||||||
fprintf(stderr,
|
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);
|
rows[i].label, got, rows[i].want_exit);
|
||||||
fail++;
|
fail++;
|
||||||
}
|
}
|
||||||
@@ -359,7 +338,7 @@ main(void)
|
|||||||
int got = run_row(wdrv, cwd, &rows[i], seq++);
|
int got = run_row(wdrv, cwd, &rows[i], seq++);
|
||||||
if (got != rows[i].want_exit) {
|
if (got != rows[i].want_exit) {
|
||||||
fprintf(stderr,
|
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);
|
rows[i].label, got, rows[i].want_exit);
|
||||||
fail++;
|
fail++;
|
||||||
}
|
}
|
||||||
@@ -367,13 +346,13 @@ main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!wwpresent)
|
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) {
|
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);
|
fail, total);
|
||||||
return 1;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user