wcc/ww: .wwi export-data producer + check_exported_type (#22 M2)
New `w6c -I <out.wwi>` flag (both stages) writes a re-parseable ww-prototype rendering of a package's EXPORTED surface. M2 dead-code: nothing consumes .wwi yet (combined.ww stays the live path); the flag is off on every existing invocation, so the 990-997 byte-id gates and all prior tests are unperturbed. The unparse walks the AST type-expr subtree (N_T* nodes), not the tinfo Type* (which collapses nominal pkg.Name identity). Deterministic output: package line, byte-sorted imports, byte-sorted decls — a pure function of the exported API. cmd/w6c/wwi.c + selfhost/cmd/wcc/wwi.ww emit byte-identical .wwi (new cross-stage byte-id substrate, rule 10). check_exported_type (drew) rides the producer entry, flag-gated: an exported signature naming a non-exported nominal is loud-rejected before any byte is written, identically on both stages. Ports harec check.c:4092-4168, recursing the type-AST and gating on the resolved SK_TYPE sym's decl export flag (Sym.exported is vestigial in both stages; the predeclared synthetic `nomem` decl carries no source position and is treated as a builtin leaf — cstage parity). Two wwstage checker AST-mutations are normalized to cstage's pristine view for byte-id: the N_TPARAM tuple-element wrapper (unwrapped) and the variadic `T...`→`[]T` param desugar (peeled). Gate 989_m2wwi_run: ascii/strings/getopt each produce a .wwi that re-parses (wwdump -a) and is cs==ww byte-identical; a private-type-leak fixture is rejected identically by both stages (non-vacuous check).
This commit is contained in:
@@ -23,6 +23,7 @@ import typ;
|
||||
import sym;
|
||||
import check;
|
||||
import cgen;
|
||||
import wwi;
|
||||
|
||||
fn cstreq(a: *u8, lit: str) bool = {
|
||||
let n: u64 = lit.len: u64;
|
||||
@@ -79,6 +80,7 @@ fn slurp(path: *u8) (*u8, u64) = {
|
||||
export fn main(argc: i32, argv: **u8) i32 = {
|
||||
let src: *u8 = nil;
|
||||
let out: *u8 = nil;
|
||||
let wwiout: *u8 = nil; // -I <out.wwi>: M2 export-data producer
|
||||
let testmode: i32 = 0i32; // #15: `-T` test-mode
|
||||
|
||||
let i: i32 = 1;
|
||||
@@ -92,6 +94,14 @@ export fn main(argc: i32, argv: **u8) i32 = {
|
||||
return 2;
|
||||
};
|
||||
out = argv[i];
|
||||
} else { if (cstreq(a, "-I")) {
|
||||
i += 1;
|
||||
if (i >= argc) {
|
||||
let m: str = "w6c: -I requires arg\n";
|
||||
os.write(2, m.ptr, m.len: u64);
|
||||
return 2;
|
||||
};
|
||||
wwiout = argv[i];
|
||||
} else { if (cstreq(a, "-T")) {
|
||||
testmode = 1i32;
|
||||
} else { if (a[0u64] == 45u8) {
|
||||
@@ -105,7 +115,7 @@ export fn main(argc: i32, argv: **u8) i32 = {
|
||||
return 2;
|
||||
};
|
||||
src = a;
|
||||
}; }; };
|
||||
}; }; }; };
|
||||
i += 1;
|
||||
};
|
||||
|
||||
@@ -175,6 +185,13 @@ export fn main(argc: i32, argv: **u8) i32 = {
|
||||
checkfile(&ck, f);
|
||||
if (ck.errs > 0) { return 1; };
|
||||
|
||||
// M2 export-data: write the `.wwi` after a clean check, before cgen.
|
||||
// Dead on the live path (no existing invocation passes -I); the
|
||||
// producer's check_exported_type may reject a dangling export.
|
||||
if (wwiout != nil) {
|
||||
if (wwiemit(&ck, f, pathstr(wwiout)) != 0) { return 1; };
|
||||
};
|
||||
|
||||
let cg: cgen;
|
||||
cgeninit(&cg);
|
||||
cgfile(&cg, f);
|
||||
|
||||
Reference in New Issue
Block a user