selfhost: graduate N_* defs to nkind enum

This commit is contained in:
2026-05-12 04:54:23 +09:00
parent d20674a5ad
commit 3affe01705
13 changed files with 2007 additions and 1995 deletions

View File

@@ -25,7 +25,7 @@ use strconv;
fn scanlocals(c: *cgen, n: *node) i32 = {
if (n == nil) { return 0; };
let total: i32 = 0;
if (n.kind == N_LET) {
if (n.kind == nkind.N_LET) {
// Match localadd's rounding: < 8 bumps to 8, then 8-align.
// scanlocals must agree with localadd or the prologue
// SUBQ undersizes the frame and lets overflow into the
@@ -44,21 +44,21 @@ fn scanlocals(c: *cgen, n: *node) i32 = {
// the rhs call's return-tuple element type. Marking via
// scanseenmark also dedupes the recursive descent into n.list
// so each child isn't counted again at the default 8B.
if (n.kind == N_MLET) {
if (n.kind == nkind.N_MLET) {
let p0t: *node = nil;
let p1t: *node = nil;
if (n.rhs != nil) {
if (n.rhs.kind == N_CALL) {
if (n.rhs.kind == nkind.N_CALL) {
let callee: *node = n.rhs.lhs;
if (callee != nil) {
let cnm: str;
cnm.ptr = nil; cnm.len = 0;
if (callee.kind == N_IDENT) { cnm = callee.str; };
if (callee.kind == N_DOT) { cnm = callee.str; };
if (callee.kind == nkind.N_IDENT) { cnm = callee.str; };
if (callee.kind == nkind.N_DOT) { cnm = callee.str; };
if (cnm.len > 0) {
let rt: *node = fnretlookup(c, cnm);
if (rt != nil) {
if (rt.kind == N_TTUPLE) {
if (rt.kind == nkind.N_TTUPLE) {
p0t = rt.list;
if (p0t != nil) { p1t = p0t.next; };
};
@@ -93,7 +93,7 @@ fn scanlocals(c: *cgen, n: *node) i32 = {
// so two separate matches in the same function each allocate
// their `v`/`e` slots fresh. Treating these as deduped would
// shrink the frame below what localadd then bumps it to.
if (n.kind == N_MCASE) {
if (n.kind == nkind.N_MCASE) {
let bn: str = n.str;
if (bn.len > 0) {
let pat: *node = n.lhs;
@@ -125,7 +125,7 @@ fn cgfnparams(c: *cgen, params: *node) void = {
let p: *node = params;
let idx: i32 = 0;
for (p != nil) {
if (p.kind == N_PARAM) {
if (p.kind == nkind.N_PARAM) {
let nm: str = p.str;
if (istaggedtype(p.lhs)) {
// tagged-union param: spill size/8 registers
@@ -205,7 +205,7 @@ fn cgfn(c: *cgen, fn_: *node) void = {
let isffi: bool = false;
let a: *node = fn_.attr;
for (a != nil) {
if (a.kind == N_ATTR) {
if (a.kind == nkind.N_ATTR) {
let an: str = a.str;
if (streq(an, "symbol")) { isffi = true; };
};
@@ -229,7 +229,7 @@ fn cgfn(c: *cgen, fn_: *node) void = {
let scanp: *node = fn_.list;
let frame: i32 = 0;
for (scanp != nil) {
if (scanp.kind == N_PARAM) {
if (scanp.kind == nkind.N_PARAM) {
if (istaggedtype(scanp.lhs)) { frame += 24; }
else { if (isslicetype(c, scanp.lhs)) { frame += 24; }
else { if (isstrtype(c, scanp.lhs)) { frame += 16; }
@@ -286,7 +286,7 @@ export fn cgfile(c: *cgen, file: *node) void = {
collectmods(c, file);
let d: *node = file.list;
for (d != nil) {
if (d.kind == N_FNDECL) {
if (d.kind == nkind.N_FNDECL) {
if (d.body != nil) {
cgfn(c, d);
};