Two cgen/check bugs surfaced by new lib modules, plus the modules
themselves (crc64, siphash, random, base64, base32).
1. `(big_u64): u32` (and `: u16`, `: u8`, `: bool`) didn't truncate.
N_CAST emitted nothing for int↔int; the value stayed in AX with
its upper bits intact and downstream CMPQ/DIVQ misread the slot.
The TK_TILDE path already had clamp logic for the same reason —
N_CAST was the missing case. Both stages now MOVL r,r for u32 and
ANDQ $mask for u8/u16/bool. Signed-narrow (i8/i16/i32) stays
no-op until w6a grows reg-reg MOVSBQ/MOVSWQ/MOVSXD. selfhost
cgcast walks alias chains via aliaslookup before checking
primsize/typenameisunsigned so `(u: random)` where
`type random = u64` still bypasses the clamp.
See cmd/w6c/cgen.c N_CAST and selfhost/cmd/wcc/cgenexpr.ww cgcast.
2. `mod.mod` type refs (`random.random` when the imported module
declares `export type random = u64;`) failed with "unknown type".
The driver concatenates imports into one flat scope, so SK_USE
`random` collided with SK_TYPE `random` and scope_define silently
dropped the use. resolve_typename's leaf lookup required
`kind == SK_USE` and gave up. Adds a `use_alias` flag to Sym; the
pass-1 decl scan now marks colliding syms in both directions
(use-after-type and type-after-use). resolve_typename and the
N_DOT cexpr branch treat `use_alias` like SK_USE for qualified
lookup. selfhost check.ww was already lenient on this path so no
ww-side change was needed; bootstrap fixed point (990-995) holds.
See cmd/wcc/check.c installdecl pass + N_DOT/resolve_typename and
cmd/wcc/ww.h Sym.use_alias.
New modules under lib/, each with @test vectors in *_test.ww and wired
into test/wcc/900_stdlib.c (26 modules → all compile):
- lib/hash/crc64 ECMA, ISO (mirror of crc32 shape)
- lib/hash/siphash SipHash-2-4, buffer-based sum/sum24
- lib/math/random SplitMix64 (init, next, u32n, u64n)
- lib/encoding/base64 RFC 4648 std + url-safe encode/decode + sizes
- lib/encoding/base32 RFC 4648 std + base32hex encode/decode + sizes
73 lines
1.8 KiB
C
73 lines
1.8 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/strings/strings.ww",
|
|
"lib/io/stream.ww",
|
|
"lib/errors/errors.ww",
|
|
"lib/os/os.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/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;
|
|
}
|