wcc: -T test-mode collects @test fns + synthesizes entry, both stages (#15)

@test was parsed then dropped (no consumer); `ww test` needed a hand-written
main listing each test by hand, so adding a @test and forgetting the call
silently skipped it. -T makes the checker collect @test N_FNDECLs in source
order, loud-reject a user main, and append a synthetic
`export fn main() i32 { t0(); ...; return 0; }` at the install->body-check seam;
the existing cgfn emits it (cgen untouched) -> byte-identical by construction.
Mirrors harec's checker-side is_test placement.

Plan-9-lean reduction (user-sanctioned, reinstatable post-CSP): sequential,
abort/nonzero=fail; no setjmp isolation, no fnmatch filter, no file:line.

910/997 rewired from a regex scanner to driving `w6c -T` directly (thin trusted
drivers; the @test content stays ww), with a cross-stage byte-id assert on the
-T output. attest_userman/attest_badsig pin the user-main and bad-signature
rejects.
This commit is contained in:
2026-06-10 02:01:20 +09:00
parent fddd167ce8
commit b795c320c9
12 changed files with 693 additions and 267 deletions

View File

@@ -79,6 +79,7 @@ fn slurp(path: *u8) (*u8, u64) = {
export fn main(argc: i32, argv: **u8) i32 = {
let src: *u8 = nil;
let out: *u8 = nil;
let testmode: i32 = 0i32; // #15: `-T` test-mode
let i: i32 = 1;
for (i < argc) {
@@ -91,6 +92,8 @@ export fn main(argc: i32, argv: **u8) i32 = {
return 2;
};
out = argv[i];
} else { if (cstreq(a, "-T")) {
testmode = 1i32;
} else { if (a[0u64] == 45u8) {
let m: str = "w6c: unknown flag\n";
os.write(2, m.ptr, m.len: u64);
@@ -102,12 +105,12 @@ export fn main(argc: i32, argv: **u8) i32 = {
return 2;
};
src = a;
}; };
}; }; };
i += 1;
};
if (src == nil) {
let m: str = "usage: w6c_ww [-o out.s] file.ww\n";
let m: str = "usage: w6c_ww [-T] [-o out.s] file.ww\n";
os.write(2, m.ptr, m.len: u64);
return 2;
};
@@ -168,6 +171,7 @@ export fn main(argc: i32, argv: **u8) i32 = {
typesinit(&tc);
let ck: checker;
checkinit(&ck, &tc);
ck.istest = testmode;
checkfile(&ck, f);
if (ck.errs > 0) { return 1; };