w6c+selfhost: codegen for top-level mutable let
Third step toward writable globals. The C cgen and its selfhost
mirror now:
- emit DATAW <name>(SB),"<8 LE bytes>" for every top-level `let`
whose type lands in the scalar set (i8..i64/u8..u64/bool/rune/
int/uint/uintptr/ptr; floats and multi-word types deferred);
- drop the "no writable .data" silent-drop guard at the N_IDENT
store path, replacing it with a RIP-relative MOVQ for `=` and
a load→combine→store sequence for the compound ops; and
- route `&name` through LEAQ name(SB) instead of dropping it.
Type aliases resolve via aliaslookup so `type counter = i32; let c:
counter = 0;` still emits a DATAW slot. Non-literal initialisers
silently skip, which surfaces as a clean undefined-symbol error if
the binding is ever referenced.
The selfhost mirror lands in the same commit because test 990
diffs the C cgen against wwdump_ww -c on err.ww (which has
top-level `let nerrors: i32 = 0; ... nerrors += 1;`). Any drift
between the two cgens makes 990 fail. Bootstrap stays at a fixed
point: ww2 == ww3 == ww4 byte-identical.
This commit is contained in:
@@ -287,6 +287,7 @@ export fn cgfile(c: *cgen, file: *node) void = {
|
||||
collectfnrets(c, file);
|
||||
fficollect(c, file);
|
||||
collectmods(c, file);
|
||||
collectlets(c, file);
|
||||
let d: *node = file.list;
|
||||
for (d != nil) {
|
||||
if (d.kind == nkind.N_FNDECL) {
|
||||
@@ -298,4 +299,5 @@ export fn cgfile(c: *cgen, file: *node) void = {
|
||||
};
|
||||
emitdatasection(c);
|
||||
emitdefconstants(c, file);
|
||||
emitletdataw(c, file);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user