Files
ww/test/wcc/900_stdlib.c
Hojun-Cho d09197af8e lib/strings+test: Hare port (iterator + next)
Forward UTF-8 rune cursor per ref/hare/strings/iter.ha; iterator
flattens Hare's anon-embedded utf8::decoder to explicit
offs/src/reverse fields, next() copy-in/copy-out a local decoder
and aborts on more/invalid per move()'s discipline.

The iterator flattens Hare's anonymous-embedded utf8::decoder
(ref/hare/strings/iter.ha:6-9) to explicit offs/src/reverse
fields because ww has no anon-embed syntax. reverse is retained
on the struct so riter populates it once utf8.prev (reverse DFA)
and strings.prev land.

next() copies the iterator's offs/src into a local utf8.decoder,
delegates to utf8.next, then writes offs back; copy-in/copy-out
is the cost of the flattened layout. more/invalid arms abort with
"strings.next: invalid UTF-8", mirroring Hare's move()
(ref/hare/strings/iter.ha:51-58) which aborts unconditionally
on those arms.

Deferred surface (no in-tree caller; follow-up tasks): prev, riter,
iterstr, slice, position, move. prev specifically needs utf8.prev
(reverse DFA), which isn't on the lib/encoding/utf8 surface yet.

lib/strings/strings.ww moves off test/wcc/900_stdlib.c's
standalone-compile list per the existing bufio/fmt/os precedent:
the iterator's (rune | utf8.done) return type and the local
utf8.decoder reference need cross-module type resolution, which
the standalone w6c path doesn't do. Runtime coverage stays at
966_strings_run, which now exercises 21 signalled cases (was 15).

The iterator's Hare-faithful `reverse: bool` field surfaced #33
(cstage cgen narrow-sret-field copy mis-width) during this port's
pre-flight; that fix landed at 0d96196 ahead of this commit.
Future bisecters tracking a narrow-field-related regression in
lib/strings or sret-aware stdlib growth should consult #33 + this
commit's bracket. The 4-arm match on utf8.next return surfaced
#31 (wwstage fnretlookupmod) earlier in the same chain (b787641).

Tests:
  - 6 new @test fns in stringstest.ww (signalled 16-21): empty,
    ASCII, 2-byte (café), 3-byte (こんにちは), 4-byte (🦀rust),
    mixed-width ("Hello, 世界! 🌍"). Each verifies forward
    iteration, done@EOI, and repeated next-after-done stays done
    (iter_empty). Multibyte literal limitation handled via
    `0xE9u32: rune` cast per existing pattern at stringstest.ww:82.

104/104 ok. 995_self_rebuild stays green (ww2==ww3==ww4 byte-id).
2026-05-18 12:16:22 +09:00

80 lines
2.4 KiB
C

/*
* 900_stdlib — verify each stdlib module parses, type-checks, and
* codegens. We don't link or run them; they exist for downstream
* users to import. As real applications come online they will start
* exercising the bodies through the e2e harness.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static const char *modules[] = {
"lib/types/types.ww",
"lib/ascii/ascii.ww",
"lib/bytes/bytes.ww",
"lib/io/io.ww",
"lib/errors/errors.ww",
"lib/strconv/strconv.ww",
"lib/sort/sort.ww",
"lib/path/path.ww",
"lib/encoding/utf8/utf8.ww",
"lib/encoding/hex/hex.ww",
"lib/encoding/base32/base32.ww",
"lib/encoding/base64/base64.ww",
"lib/hash/fnv/fnv.ww",
"lib/hash/adler32/adler32.ww",
"lib/hash/crc16/crc16.ww",
"lib/hash/crc32/crc32.ww",
"lib/hash/crc64/crc64.ww",
"lib/hash/siphash/siphash.ww",
"lib/math/random/random.ww",
"lib/time/time.ww",
"lib/c/libc/libc.ww",
/* lib/bufio/bufio.ww, lib/fmt/fmt.ww, lib/os/os.ww, and
* lib/strings/strings.ww moved off this list: each has cross-
* module type refs that only resolve once the driver concatenates
* `use`d modules. bufio / fmt graduated to io.stream-based sinks
* (*io.stream, io.closed, io.eof); lib/os carries time.instant in
* filestat post-Commit B; lib/strings.iterator + lib/strings.next
* reference utf8.decoder / utf8.done. Coverage lives at
* lib/bufio/bufiotest.ww + lib/fmt/fmttest.ww + lib/os/stattest.ww
* + lib/strings/stringstest.ww (wired at 998_bufio_run.c,
* 970_fmt_run.c, 976_stat_run.c, 966_strings_run.c), plus the
* bufio.scanline / fmt.println e2e rows in test/wcc/700_e2e.c. */
"lib/net/net.ww",
NULL
};
int
main(void)
{
const char *bin = getenv("BIN");
if (!bin) bin = "out/bin";
char absbin[1024];
if (bin[0] != '/') {
char cwd[1024];
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
snprintf(absbin, sizeof absbin, "%s/%s", cwd, bin);
bin = absbin;
}
char cwd[1024];
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
int n = 0, fail = 0;
for (int i = 0; modules[i]; i++, n++) {
char path[1024], cmd[2048];
snprintf(path, sizeof path, "%s/%s", cwd, modules[i]);
snprintf(cmd, sizeof cmd, "%s/w6c %s > /dev/null 2>&1",
bin, path);
int rc = system(cmd);
if (rc != 0) {
fprintf(stderr, "stdlib FAIL: %s (rc=%d)\n", modules[i], rc);
fail++;
}
}
if (fail) { fprintf(stderr, "%d/%d stdlib modules failed\n", fail, n); return 1; }
printf("stdlib: %d/%d ok\n", n, n);
return 0;
}