selfhost: cgident read path for top-level lets

Mirror the C cgen's N_IDENT load fallback. Reads of a top-level
scalar `let` now emit `MOVQ name(SB), AX` (RIP-relative) instead
of silently dropping. Truly undefined names still fall through to
the silent return, matching the pre-existing defensive behaviour;
the C side's broader unconditional fallback is intentionally not
mirrored here so typos surface as nothing-emitted rather than a
link-time stub.
This commit is contained in:
2026-05-12 12:00:18 +09:00
parent 3c812faa08
commit 4bf1b56872
3 changed files with 33 additions and 0 deletions

View File

@@ -6128,6 +6128,17 @@ fn cgident(c: *cgen, n: *node) void = {
emitline("(SB), AX\n");
return;
};
// Top-level mutable `let` — RIP-relative load from its DATAW
// slot. Mirrors C cgen's catch-all `MOVQ masym(s), AX`. Names
// that aren't lets either (typos, never-defined) flow through
// here too in C; the divergence today is bounded to scalar lets,
// which is what `isletvar` gates on.
if (isletvar(c, nm)) {
emitline("\tMOVQ\t");
emitsymname(c, nm);
emitline("(SB), AX\n");
return;
};
return;
};

View File

@@ -400,6 +400,17 @@ fn cgident(c: *cgen, n: *node) void = {
emitline("(SB), AX\n");
return;
};
// Top-level mutable `let` — RIP-relative load from its DATAW
// slot. Mirrors C cgen's catch-all `MOVQ masym(s), AX`. Names
// that aren't lets either (typos, never-defined) flow through
// here too in C; the divergence today is bounded to scalar lets,
// which is what `isletvar` gates on.
if (isletvar(c, nm)) {
emitline("\tMOVQ\t");
emitsymname(c, nm);
emitline("(SB), AX\n");
return;
};
return;
};

View File

@@ -6128,6 +6128,17 @@ fn cgident(c: *cgen, n: *node) void = {
emitline("(SB), AX\n");
return;
};
// Top-level mutable `let` — RIP-relative load from its DATAW
// slot. Mirrors C cgen's catch-all `MOVQ masym(s), AX`. Names
// that aren't lets either (typos, never-defined) flow through
// here too in C; the divergence today is bounded to scalar lets,
// which is what `isletvar` gates on.
if (isletvar(c, nm)) {
emitline("\tMOVQ\t");
emitsymname(c, nm);
emitline("(SB), AX\n");
return;
};
return;
};