Files
ww/test/wcc/900_stdlib.c
Hojun-Cho 3daf134395 lib: retire os.assert/abort shims — assert/abort are builtins (#58 respell)
The flat checker scope makes ANY decl named assert/abort anywhere in
the combined unit disable the builtin unit-wide (the #45 shadow shape:
scope_lookup_prefer's cross-module fallback finds it). lib carried
three colliding @symbol("rt_abort") shims (os, time, strconv/stof)
plus the os.assert wrapper, so a bare assert(cond) in ANY program
importing os mis-bound os.assert and failed arity — a hard blocker for
regex fold-5 (regex.ha:660/670 bring builtin-assert mass). Ruled
respell-now per the recurrence test (#45 -> #58).

Delete the shims and the os.assert wrapper; every bare abort(msg)
caller (regex, strings, utf8, hash, getopt, encoding/*, time, stof)
now lands on the builtin, and the ~40 os.assert(c, m) sites respell to
the builtin assert(c, m) — restoring the exact Hare spelling the lib
ports diverged from (e.g. ref/hare/bytes/tokenize.ha:23). os.assert
had no Hare counterpart (Hare's assert is a language builtin); rule-9
wrapper removed. temp/dirs/bufio already use the non-colliding rtabort
spelling and keep it.

Now-dead 'import os;' lines kept (pre-existing precedent:
lib/strconv/strconv.ww carries one); a tree-wide dead-import sweep is
a separate concern. regex.ww's if+abort workarounds citing #58 stay
for the fold-5 owner to fold back into assert.

combined.ww regenerated for all five selfhost tools + the smoke
fixture via make.
2026-06-04 22:42:47 +09:00

87 lines
3.0 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/io/io.ww",
"lib/strconv/strconv.ww",
"lib/sort/sort.ww",
"lib/path/path.ww",
"lib/encoding/utf8/utf8.ww",
"lib/encoding/base32/base32.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/bytes/bytes.ww, lib/errors/errors.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.vtable,
* io.eof, io.error); lib/os carries time.instant in filestat
* post-Commit B; lib/errors.errno references os.errno / os.E* /
* os.strerror (ww folds Hare's sys role into os); lib/strings.iterator
* + lib/strings.next reference utf8.decoder / utf8.done;
* lib/bytes.tokenize references the assert builtin + types.I64_MAX/MIN per
* ref/hare/bytes/tokenize.ha:23-24,42-43; lib/encoding/hex and
* lib/encoding/base64 graduated to Hare's io-streaming surface
* (hex references io.handle / fmt.fprint / memio.dynamic / strconv /
* errors.invalid; base64 references io.handle / memio.dynamic /
* bytes.zero / strings.frombytes / errors.invalid). Coverage lives at
* lib/bufio/bufiotest.ww + lib/bytes/bytestest.ww +
* lib/errors/errnotest.ww + lib/fmt/fmttest.ww + lib/os/stattest.ww
* + lib/strings/stringstest.ww + lib/encoding/hex/hextest.ww +
* lib/encoding/base64/base64_test.ww (wired at 998_bufio_run.c,
* 967_bytes_run.c, 902_errno_run.c, 970_fmt_run.c, 976_stat_run.c,
* 966_strings_run.c, 979_hex_run.c, 984_base64_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;
}