wcc/ww: round-trip @symbol in the .wwi producer (#47)
The M2 .wwi producer rendered an exported fn carrying @symbol("...")
as a bare prototype, dropping the FFI link-symbol binding. A
sep-compiled consumer reading the .wwi then emitted `CALL malloc`
instead of `CALL rt_malloc` for `@symbol("rt_malloc") export fn
malloc`, breaking the bodies-vs-.wwi byte-id and the link. Affects
every package whose closure reaches rt/os.
Emit codegen/link-relevant attributes through a single named
predicate (wwi_attr_relevant / wwiattrrelevant), today true iff the
name is "symbol" — the only such attribute that exists. @align/@offset
are NOT field attributes in ww (the parser parses no field attrs, the
N_TFIELD node has no attr slot); the predicate is named for the class
so they slot in if ww ever grows them (#51). attr is assigned at
exactly one site per stage (parse.c:1351 / decl.ww:168), both inside
parsefn, so only N_FNDECL carries attrs and the fn-decl render path
covers the whole class.
Both stages, byte-identical (rule 10). 989_m2wwi_run synth gate gains
an @symbol fn + a content assertion that the .wwi carries it verbatim.
This commit is contained in:
@@ -45676,8 +45676,42 @@ fn wwitype(fd: i32, t: *node) void = {
|
||||
};};};};};};};};};};};
|
||||
};
|
||||
|
||||
// Only codegen/link-relevant attributes round-trip into the `.wwi`. Today
|
||||
// that is exactly @symbol (the FFI link-symbol override, read back at cgen
|
||||
// fficollect — dropping it makes sep-compile emit `CALL malloc` for a
|
||||
// `@symbol("rt_malloc")` fn). Named for the class so @align/@offset would
|
||||
// slot in here IF ww ever grows field-layout attributes — it has none
|
||||
// today (task #47 report). @test never reaches a `.wwi` (test fns are not
|
||||
// export-marked), so it needs no exclusion arm.
|
||||
fn wwiattrrelevant(nm: str) bool = {
|
||||
return streq(nm, "symbol");
|
||||
};
|
||||
|
||||
fn wwiattrs(fd: i32, d: *node) void = {
|
||||
let a: *node = d.attr;
|
||||
for (a != nil) {
|
||||
if (a.kind == nkind.N_ATTR && wwiattrrelevant(a.str)) {
|
||||
wputb(fd, '@');
|
||||
wputs(fd, a.str);
|
||||
if (a.list != nil) {
|
||||
wputb(fd, '(');
|
||||
let arg: *node = a.list;
|
||||
for (arg != nil) {
|
||||
if (arg != a.list) { wputs(fd, ", "); };
|
||||
wwiexpr(fd, arg);
|
||||
arg = arg.next;
|
||||
};
|
||||
wputb(fd, ')');
|
||||
};
|
||||
wputb(fd, 32u8);
|
||||
};
|
||||
a = a.next;
|
||||
};
|
||||
};
|
||||
|
||||
fn wwidecl(fd: i32, d: *node) void = {
|
||||
if (d.kind == nkind.N_FNDECL) {
|
||||
wwiattrs(fd, d);
|
||||
wputs(fd, "export fn ");
|
||||
wputs(fd, d.str);
|
||||
wputb(fd, '(');
|
||||
|
||||
@@ -349,8 +349,42 @@ fn wwitype(fd: i32, t: *node) void = {
|
||||
};};};};};};};};};};};
|
||||
};
|
||||
|
||||
// Only codegen/link-relevant attributes round-trip into the `.wwi`. Today
|
||||
// that is exactly @symbol (the FFI link-symbol override, read back at cgen
|
||||
// fficollect — dropping it makes sep-compile emit `CALL malloc` for a
|
||||
// `@symbol("rt_malloc")` fn). Named for the class so @align/@offset would
|
||||
// slot in here IF ww ever grows field-layout attributes — it has none
|
||||
// today (task #47 report). @test never reaches a `.wwi` (test fns are not
|
||||
// export-marked), so it needs no exclusion arm.
|
||||
fn wwiattrrelevant(nm: str) bool = {
|
||||
return streq(nm, "symbol");
|
||||
};
|
||||
|
||||
fn wwiattrs(fd: i32, d: *node) void = {
|
||||
let a: *node = d.attr;
|
||||
for (a != nil) {
|
||||
if (a.kind == nkind.N_ATTR && wwiattrrelevant(a.str)) {
|
||||
wputb(fd, '@');
|
||||
wputs(fd, a.str);
|
||||
if (a.list != nil) {
|
||||
wputb(fd, '(');
|
||||
let arg: *node = a.list;
|
||||
for (arg != nil) {
|
||||
if (arg != a.list) { wputs(fd, ", "); };
|
||||
wwiexpr(fd, arg);
|
||||
arg = arg.next;
|
||||
};
|
||||
wputb(fd, ')');
|
||||
};
|
||||
wputb(fd, 32u8);
|
||||
};
|
||||
a = a.next;
|
||||
};
|
||||
};
|
||||
|
||||
fn wwidecl(fd: i32, d: *node) void = {
|
||||
if (d.kind == nkind.N_FNDECL) {
|
||||
wwiattrs(fd, d);
|
||||
wputs(fd, "export fn ");
|
||||
wputs(fd, d.str);
|
||||
wputb(fd, '(');
|
||||
|
||||
Reference in New Issue
Block a user