lib/memio: add Option C parallel vstream API (#94 fold-e2)
Adds lib/memio/vstream.ww with three new constructors — fixed_vstream / dynamic_vstream / dynamicfrom_vstream — that return io.vstream (= *io.vtable, from lib/io/stream.ww) alongside the pre-vtable memio.fixed / dynamic / dynamicfrom shape in memio.ww. Hare's memio::fixed/dynamic return a `stream` whose first field IS io::stream (= *vtable); ww mirrors that intrusively with fixed_ctx + dynamic_ctx structs whose first field is `vt: io.vtable`. A heap-alloc'd *fixed_ctx is castable to vstream via `&c.vt`, and callbacks recover the outer ctx via `s: *fixed_ctx` (same pattern as lib/bufio.stream over io.stream and lib/log.stdlogger over logger). ptr/len/cap kept flat (memio.ww:39 SOP) to dodge the chained-dot-through-pointer-into-slice-subfield miscompile family. Constructor flow: alloc with vt zero-initialised via a local, then chained `c.vt.X = …` field-assigns through the *ctx pointer. Struct-lit init via `vt = local_vt` (with local pre-set) silently drops tagged-union slots past the first — sibling task filed, workaround is the alloc-then-assign route (proven byte-id between both stages). *ctx is a plain pointer-to-struct, not an aliased pointer, so the chained-store path doesn't hit #195. Cast workaround per #206 at each vtable-fn-ptr-slot init (8 sites across the 3 constructors): bare `&fn_name` does not type-check as `(*<alias> | void)`. Same `(&fn): *io.<role>` shape that test/wcc/775_io_vtable_run.c uses. Drops out when #206 closes. OLD memio surface is UNCHANGED. fold-eFinal (task #50) atomically flips the package shape: deletes OLD constructors + callbacks and renames `_vstream` suffix off. Probe test/wcc/776_memio_vstream_run.c: 4 rows (fixed_read_5 / dynamic_write_grow / dynamicfrom_alt_rw / branched_fixed) exercise both vtable flavours through the io.st_read / st_write / st_close dispatchers. Each row drives cs runtime + ww runtime + cs.s == ww.s byte-id — 12 fixtures total, all green. Pre-existing wwstage gap surfaced + documented inline: ww_ww's combined.ww concat order trips the wwstage checker on os.tryread / trywrite / tryopen's bare `return r;` over `(int | oserror)` when os is checked after rt/io. Each probe row places `import os;` FIRST to match the ordering selfhost uses (time → os → rt → …) where the checker resolves cleanly. Sibling task; resolves the ordering-sensitivity in the wwstage checker drops the workaround.
This commit is contained in:
12
Makefile
12
Makefile
@@ -113,7 +113,7 @@ $(BIN)/wwdump_ww: selfhost/cmd/wwdump/main.ww \
|
||||
selfhost/cmd/wcc/cgen.ww selfhost/cmd/wcc/cgenexpr.ww \
|
||||
selfhost/cmd/wcc/cgenstmt.ww selfhost/cmd/wcc/cgenutil.ww \
|
||||
selfhost/cmd/wcc/cgendecl.ww \
|
||||
lib/os/os.ww lib/rt/malloc.ww lib/time/time.ww lib/strconv/strconv.ww lib/strconv/stof_data.ww lib/strconv/decimal.ww lib/strconv/stof.ww lib/strconv/ftos_data.ww lib/strconv/ftos.ww lib/strings/strings.ww lib/bytes/bytes.ww lib/encoding/utf8/utf8.ww lib/ascii/ascii.ww lib/errors/errors.ww lib/io/io.ww lib/io/stream.ww lib/io/types.ww lib/memio/memio.ww lib/fmt/fmt.ww \
|
||||
lib/os/os.ww lib/rt/malloc.ww lib/time/time.ww lib/strconv/strconv.ww lib/strconv/stof_data.ww lib/strconv/decimal.ww lib/strconv/stof.ww lib/strconv/ftos_data.ww lib/strconv/ftos.ww lib/strings/strings.ww lib/bytes/bytes.ww lib/encoding/utf8/utf8.ww lib/ascii/ascii.ww lib/errors/errors.ww lib/io/io.ww lib/io/stream.ww lib/io/types.ww lib/memio/memio.ww lib/memio/vstream.ww lib/fmt/fmt.ww \
|
||||
$(BIN)/ww $(BIN)/w6c $(BIN)/w6a $(BIN)/w6l \
|
||||
$(LIB)/libwwrt.a | $(BIN)
|
||||
@mkdir -p $(BIN)/wwdump_ww.d
|
||||
@@ -135,7 +135,7 @@ $(BIN)/w6c_ww: selfhost/cmd/w6c/main.ww \
|
||||
selfhost/cmd/wcc/cgen.ww selfhost/cmd/wcc/cgenexpr.ww \
|
||||
selfhost/cmd/wcc/cgenstmt.ww selfhost/cmd/wcc/cgenutil.ww \
|
||||
selfhost/cmd/wcc/cgendecl.ww \
|
||||
lib/os/os.ww lib/rt/malloc.ww lib/time/time.ww lib/strconv/strconv.ww lib/strconv/stof_data.ww lib/strconv/decimal.ww lib/strconv/stof.ww lib/strconv/ftos_data.ww lib/strconv/ftos.ww lib/strings/strings.ww lib/bytes/bytes.ww lib/encoding/utf8/utf8.ww lib/ascii/ascii.ww lib/errors/errors.ww lib/io/io.ww lib/io/stream.ww lib/io/types.ww lib/memio/memio.ww lib/fmt/fmt.ww \
|
||||
lib/os/os.ww lib/rt/malloc.ww lib/time/time.ww lib/strconv/strconv.ww lib/strconv/stof_data.ww lib/strconv/decimal.ww lib/strconv/stof.ww lib/strconv/ftos_data.ww lib/strconv/ftos.ww lib/strings/strings.ww lib/bytes/bytes.ww lib/encoding/utf8/utf8.ww lib/ascii/ascii.ww lib/errors/errors.ww lib/io/io.ww lib/io/stream.ww lib/io/types.ww lib/memio/memio.ww lib/memio/vstream.ww lib/fmt/fmt.ww \
|
||||
$(BIN)/ww $(BIN)/w6c $(BIN)/w6a $(BIN)/w6l \
|
||||
$(LIB)/libwwrt.a | $(BIN)
|
||||
@mkdir -p $(BIN)/w6c_ww.d
|
||||
@@ -326,6 +326,7 @@ TESTS = $(BIN)/test_smoke $(BIN)/test_lex $(BIN)/test_parse $(BIN)/test_check \
|
||||
$(BIN)/test_isas_spread_variant \
|
||||
$(BIN)/test_tagged_widen_named_variant \
|
||||
$(BIN)/test_io_vtable_run \
|
||||
$(BIN)/test_memio_vstream_run \
|
||||
$(BIN)/test_use_promote_alias \
|
||||
$(BIN)/test_field_signed $(BIN)/test_frame_argcount \
|
||||
$(BIN)/test_selfhost $(BIN)/test_w6a_ww $(BIN)/test_w6l_ww \
|
||||
@@ -688,6 +689,13 @@ $(BIN)/test_io_vtable_run: test/wcc/775_io_vtable_run.c \
|
||||
$(LIB)/libwwrt.a | $(BIN)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
$(BIN)/test_memio_vstream_run: test/wcc/776_memio_vstream_run.c \
|
||||
$(BIN)/ww $(BIN)/w6c $(BIN)/w6a $(BIN)/w6l \
|
||||
$(BIN)/ww_ww $(BIN)/w6c_ww $(BIN)/w6a_ww $(BIN)/w6l_ww \
|
||||
lib/memio/memio.ww lib/memio/vstream.ww \
|
||||
$(LIB)/libwwrt.a | $(BIN)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
$(BIN)/test_arrlit_str_full: test/wcc/711_arrlit_str_full.c \
|
||||
$(BIN)/ww $(BIN)/w6c $(BIN)/w6a $(BIN)/w6l \
|
||||
$(BIN)/ww_ww $(BIN)/w6c_ww $(BIN)/w6a_ww $(BIN)/w6l_ww \
|
||||
|
||||
Reference in New Issue
Block a user