wcc/ww: .wwi separate-compile consumer — w6c -c codegen filter (#22 M3)
New `w6c -c` (both stages): separate-compile / primary-only codegen. Emit code+DATA ONLY for a package's own (imported==0) decls; treat every `.wwi`-sourced (imported==1) dep decl as an external. Pure addition behind the flag — combined.ww stays the LIVE path, `-c` is off on every existing invocation, so the 990-997 byte-id gates + all prior tests are unperturbed. The keystone (rob): a `.wwi` is body-less/init-less prototype source, and cgen already skips body-less fns as externs, so dep fns/types/defs emit NOTHING for free. The single genuinely-new guard is an imported value- global (`export let`): its DATAW would DUPLICATE the dep's own definition (link collision), so it is skipped. The `imported==0` gate is applied at all top-level emit sites for uniformity (close-by-construction): the fn loop, emit_lets/emitletdataw, emit_defs/emitdefconstants, and let_pre_intern/letpreintern — that last one because an imported dep's body initializer interns strlits while its rhs-stripped `.wwi` does not, which would shift the _S_ sequence; gating it keeps the strlit table a pure function of the package's own decls. EXACTLY symmetric with M2's producer `imported==0` filter — same predicate both directions. Driver `--sep` build_one_sep + per-package archives + multi-.a link + cache + BROAD real-target dual-path soak are M3-tail (#46, rob ruling B): M3-core ships the codegen spine + a self-contained gate that proves all codegen correctness without a production driver. Gate 989_m3sep_run: a synth leaf->mid->root fixture carrying all four cross-boundary fact-classes (fn signature, struct LAYOUT, `def` const VALUE, `export let` value-global). Per package, holding `-c` constant: `w6c -c` of (deps-as-bodies) == (deps-as-.wwi) byte-for-byte (the .wwi conveys exactly the dep facts P's codegen needs); cs==ww at the .s AND final-exe level (rule 10); sep-path determinism; the value-global guard (imported origin_tag never re-emits DATAW); and behavioral identity (the linked program's exit code is the real cross-boundary computation). COLD: .wwi materialized fresh every run (no warm cache). combined.ww regen'd for wwdump + w6c (both embed cgen.ww); diff is exactly the four guards + the flag wiring, nothing spurious.
This commit is contained in:
@@ -16348,6 +16348,13 @@ emit_lets(Cg *c, FILE *out, Node *file)
|
||||
for (Node *d = file->list; d; d = d->next) {
|
||||
if (d->kind != N_LET) continue;
|
||||
if (d->str == NULL || d->str[0] == '\0') continue;
|
||||
/* #22 M3 THE ONE REAL GUARD: a `.wwi` dep value-global is
|
||||
* initializer-less; emitting a DATAW for it would DUPLICATE the
|
||||
* definition that lives in the dep's own .o → link collision.
|
||||
* Gate on the explicit imported flag (NOT rhs==NULL: a package's
|
||||
* OWN init-less let must still zero-init). Symmetric with M2's
|
||||
* producer `imported==0` filter — same predicate both ways. */
|
||||
if (c->sep_mode && d->imported) continue;
|
||||
int sz = let_emit_size(d->type);
|
||||
if (sz == 0) continue;
|
||||
if (let_isfloat(d->type)) {
|
||||
@@ -16527,6 +16534,13 @@ emit_defs(Cg *c, FILE *out, Node *file)
|
||||
{
|
||||
for (Node *d = file->list; d; d = d->next) {
|
||||
if (d->kind != N_DEF || d->rhs == NULL) continue;
|
||||
/* #22 M3: a `.wwi` dep def with DATA storage (int-fold / float /
|
||||
* struct / array) must NOT re-emit — the dep's own .o owns the
|
||||
* symbol. Str defs are inline-spliced (sdef_collect), never
|
||||
* emitted here, so they need no gate; the registries
|
||||
* (defstructs/defarrays/defall) stay populated for imported
|
||||
* decls so the target's LOAD paths still resolve the extern. */
|
||||
if (c->sep_mode && d->imported) continue;
|
||||
u64 v;
|
||||
if (fold_int_literal(d->rhs, &v)) {
|
||||
fprintf(out, "DATA %s(SB),\"",
|
||||
@@ -16657,6 +16671,15 @@ let_pre_intern(Cg *c, Node *file)
|
||||
{
|
||||
if (file == NULL) return;
|
||||
for (Node *d = file->list; d; d = d->next) {
|
||||
/* #22 M3: skip imported deps so the strlit table (and its _S_
|
||||
* sequence) is a pure function of THIS package's own decls. A
|
||||
* dep's body initializer would intern here, but its `.wwi`
|
||||
* (init stripped) would not — gating on imported keeps the
|
||||
* bodies-vs-.wwi `.s` byte-identical for P's own symbols. The
|
||||
* dep's own strlits live in the dep's .o; cross-module str-def
|
||||
* splicing rides sdef_collect (interned at the use site, not
|
||||
* here), so it is unaffected. */
|
||||
if (c->sep_mode && d->imported) continue;
|
||||
/* #8/GAP-B: a `def [N]str` needs the SAME element-strlit
|
||||
* pre-interning as the let [N]str arm below (the #18 ordering
|
||||
* contract) so emit_strarray_data's DATAR rows find their _S_
|
||||
@@ -16780,6 +16803,12 @@ cg_file(Cg *c, FILE *out, Node *file)
|
||||
strlit_seq = 0;
|
||||
for (Node *d = file->list; d; d = d->next) {
|
||||
if (d->kind != N_FNDECL) continue;
|
||||
/* #22 M3: emit code ONLY for this package's own decls. A `.wwi`
|
||||
* dep fn is a body-less prototype that already skips (cgfn's
|
||||
* extern-decl early return); the explicit gate also covers a
|
||||
* dep fn that still carries a body in a transitional unit and
|
||||
* keeps the "emit iff imported==0" rule exception-free. */
|
||||
if (c->sep_mode && d->imported) continue;
|
||||
cgfn(c, out, d);
|
||||
}
|
||||
let_pre_intern(c, file);
|
||||
|
||||
@@ -45,6 +45,15 @@ struct Cg {
|
||||
int curoff; /* current top of locals */
|
||||
Scope *locals; /* (name → offset) tracked via Sym */
|
||||
int labelseq;
|
||||
int sep_mode; /* #22 M3 `-c`: separate-compile / primary-only
|
||||
* codegen. Emit code+DATA ONLY for this
|
||||
* package's own (imported==0) decls; treat every
|
||||
* `.wwi`-sourced (imported==1) dep decl as an
|
||||
* external — body-less fns already skip, value
|
||||
* globals/defs are gated so they don't duplicate
|
||||
* the dep's real definition (link collision).
|
||||
* Off on the combined path (every existing
|
||||
* invocation) so M3 is a pure addition. */
|
||||
};
|
||||
|
||||
/* cgen.c */
|
||||
|
||||
@@ -35,6 +35,9 @@ main(int argc, char **argv)
|
||||
const char *out = NULL;
|
||||
const char *wwiout = NULL; /* -I <out.wwi>: M2 export-data producer */
|
||||
int testmode = 0;
|
||||
int sepmode = 0; /* -c: #22 M3 separate-compile / primary-
|
||||
* only codegen (emit imported==0 decls
|
||||
* only; treat `.wwi` deps as external) */
|
||||
for (int i = 1; i < argc; i++) {
|
||||
const char *a = argv[i];
|
||||
if (strcmp(a, "-o") == 0 && i + 1 < argc) {
|
||||
@@ -43,6 +46,8 @@ main(int argc, char **argv)
|
||||
wwiout = argv[++i];
|
||||
} else if (strcmp(a, "-T") == 0) {
|
||||
testmode = 1;
|
||||
} else if (strcmp(a, "-c") == 0) {
|
||||
sepmode = 1;
|
||||
} else if (a[0] == '-') {
|
||||
fprintf(stderr, "w6c: unknown flag %s\n", a);
|
||||
return 2;
|
||||
@@ -54,7 +59,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
if (src == NULL) {
|
||||
fputs("usage: w6c [-T] [-o out.s] file.ww\n", stderr);
|
||||
fputs("usage: w6c [-T] [-c] [-I out.wwi] [-o out.s] file.ww\n", stderr);
|
||||
return 2;
|
||||
}
|
||||
|
||||
@@ -104,6 +109,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
cg_init(&cg, a);
|
||||
cg.sep_mode = sepmode;
|
||||
cg_file(&cg, of, file);
|
||||
|
||||
if (of != stdout) fclose(of);
|
||||
|
||||
Reference in New Issue
Block a user