selfhost: graduate N_* defs to nkind enum
This commit is contained in:
@@ -22,28 +22,28 @@ fn cgstmt(c: *cgen, n: *node) void = {
|
||||
if (n == nil) { return; };
|
||||
let k: i32 = n.kind;
|
||||
|
||||
if (k == N_BLOCK) { cgblock(c, n); return; };
|
||||
if (k == nkind.N_BLOCK) { cgblock(c, n); return; };
|
||||
|
||||
if (k == N_RETURN) { cgreturn(c, n); return; };
|
||||
if (k == nkind.N_RETURN) { cgreturn(c, n); return; };
|
||||
|
||||
if (k == N_EXPRSTMT) { cgexprstmt(c, n); return; };
|
||||
if (k == nkind.N_EXPRSTMT) { cgexprstmt(c, n); return; };
|
||||
|
||||
if (k == N_LET) { cglet(c, n); return; };
|
||||
if (k == nkind.N_LET) { cglet(c, n); return; };
|
||||
|
||||
if (k == N_IF) { cgif(c, n); return; };
|
||||
if (k == nkind.N_IF) { cgif(c, n); return; };
|
||||
|
||||
if (k == N_FOR) { cgfor(c, n); return; };
|
||||
if (k == nkind.N_FOR) { cgfor(c, n); return; };
|
||||
|
||||
if (k == N_MASSIGN) { cgmassign(c, n); return; };
|
||||
if (k == nkind.N_MASSIGN) { cgmassign(c, n); return; };
|
||||
|
||||
if (k == N_MLET) { cgmlet(c, n); return; };
|
||||
if (k == nkind.N_MLET) { cgmlet(c, n); return; };
|
||||
|
||||
if (k == N_BREAK) { cgbreak(c, n); return; };
|
||||
if (k == N_CONTINUE) { cgcontinue(c, n); return; };
|
||||
if (k == nkind.N_BREAK) { cgbreak(c, n); return; };
|
||||
if (k == nkind.N_CONTINUE) { cgcontinue(c, n); return; };
|
||||
|
||||
if (k == N_YIELD) { cgyield(c, n); return; };
|
||||
if (k == nkind.N_YIELD) { cgyield(c, n); return; };
|
||||
|
||||
if (k == N_DEFER) {
|
||||
if (k == nkind.N_DEFER) {
|
||||
if (c.defertop < DEFER_MAX) {
|
||||
c.deferbuf[c.defertop] = n.lhs;
|
||||
c.defertop += 1;
|
||||
@@ -99,7 +99,7 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
// DX = str.ptr, CX = str.len.
|
||||
// 24B convention mirrors the tagged-union return below; receive
|
||||
// sites destructure off the same regs regardless of position.
|
||||
if (rhs.kind == N_TUPLE) {
|
||||
if (rhs.kind == nkind.N_TUPLE) {
|
||||
let v: *node = rhs.list;
|
||||
if (v != nil) {
|
||||
let v2: *node = v.next;
|
||||
@@ -221,13 +221,13 @@ fn cglet(c: *cgen, n: *node) void = {
|
||||
if (istaggedtype(n.lhs)) {
|
||||
let nullable: bool = isnullabletype(n.lhs);
|
||||
let rhsreturnstagged: bool = false;
|
||||
if (rhs.kind == N_CALL) {
|
||||
if (rhs.kind == nkind.N_CALL) {
|
||||
let callee: *node = rhs.lhs;
|
||||
if (callee != nil) {
|
||||
let calleename: str;
|
||||
calleename.ptr = nil; calleename.len = 0;
|
||||
if (callee.kind == N_IDENT) { calleename = callee.str; };
|
||||
if (callee.kind == N_DOT) { calleename = callee.str; };
|
||||
if (callee.kind == nkind.N_IDENT) { calleename = callee.str; };
|
||||
if (callee.kind == nkind.N_DOT) { calleename = callee.str; };
|
||||
if (calleename.len > 0) {
|
||||
let rt: *node = fnretlookup(c, calleename);
|
||||
if (istaggedtype(rt)) { rhsreturnstagged = true; };
|
||||
@@ -290,7 +290,7 @@ fn cglet(c: *cgen, n: *node) void = {
|
||||
// Layout is positional, so we route each register to the
|
||||
// slot dictated by element type, not by AX/DX position.
|
||||
if (n.lhs != nil) {
|
||||
if (n.lhs.kind == N_TTUPLE) {
|
||||
if (n.lhs.kind == nkind.N_TTUPLE) {
|
||||
let p0: *node = n.lhs.list;
|
||||
let p1: *node = nil;
|
||||
if (p0 != nil) { p1 = p0.next; };
|
||||
@@ -331,13 +331,13 @@ fn cglet(c: *cgen, n: *node) void = {
|
||||
// Array literal init: `let xs: [N]T = [a, b, c];` (or [_]T).
|
||||
// Walk elements in declaration order, store each at off + i*esz
|
||||
// using the right width for the element type. Trailing `...`
|
||||
// after the last value (an N_FIELD with str=="...") fills the
|
||||
// after the last value (an nkind.N_FIELD with str=="...") fills the
|
||||
// remaining slots up to the declared length with that value.
|
||||
if (rhs.kind == N_ARRLIT) {
|
||||
if (rhs.kind == nkind.N_ARRLIT) {
|
||||
let elemn: *node = n.lhs.lhs;
|
||||
let esz: i32 = 8;
|
||||
if (elemn != nil) {
|
||||
if (elemn.kind == N_TNAME) {
|
||||
if (elemn.kind == nkind.N_TNAME) {
|
||||
let ps: i32 = primsize(elemn.str);
|
||||
if (ps > 0) { esz = ps; };
|
||||
};
|
||||
@@ -349,7 +349,7 @@ fn cglet(c: *cgen, n: *node) void = {
|
||||
let repeat: bool = false;
|
||||
let e: *node = rhs.list;
|
||||
for (e != nil) {
|
||||
if (e.kind == N_FIELD) {
|
||||
if (e.kind == nkind.N_FIELD) {
|
||||
if (streq(e.str, "...")) {
|
||||
repeat = true;
|
||||
e = nil;
|
||||
@@ -379,9 +379,9 @@ fn cglet(c: *cgen, n: *node) void = {
|
||||
if (repeat) {
|
||||
let total: i32 = idx;
|
||||
if (n.lhs != nil) {
|
||||
if (n.lhs.kind == N_TARRAY) {
|
||||
if (n.lhs.kind == nkind.N_TARRAY) {
|
||||
if (n.lhs.rhs != nil) {
|
||||
if (n.lhs.rhs.kind == N_INTLIT) {
|
||||
if (n.lhs.rhs.kind == nkind.N_INTLIT) {
|
||||
total = n.lhs.rhs.uval: i32;
|
||||
};
|
||||
};
|
||||
@@ -406,13 +406,13 @@ fn cglet(c: *cgen, n: *node) void = {
|
||||
// op == tkind.TK_ELLIPSIS (autofill marker from the parser), the
|
||||
// entire slot is zero-filled first so unmentioned fields
|
||||
// read as 0.
|
||||
if (rhs.kind == N_STRUCTLIT) {
|
||||
if (rhs.kind == nkind.N_STRUCTLIT) {
|
||||
let trefn: *node = rhs.lhs;
|
||||
let sname: str;
|
||||
sname.ptr = nil; sname.len = 0;
|
||||
if (trefn != nil) {
|
||||
if (trefn.kind == N_IDENT) { sname = trefn.str; }
|
||||
else { if (trefn.kind == N_TNAME) { sname = trefn.str; }; };
|
||||
if (trefn.kind == nkind.N_IDENT) { sname = trefn.str; }
|
||||
else { if (trefn.kind == nkind.N_TNAME) { sname = trefn.str; }; };
|
||||
};
|
||||
let si: *structinfo = structlookup(c, sname);
|
||||
if (si != nil) {
|
||||
@@ -441,7 +441,7 @@ fn cglet(c: *cgen, n: *node) void = {
|
||||
};
|
||||
let fieldnode: *node = rhs.list;
|
||||
for (fieldnode != nil) {
|
||||
if (fieldnode.kind == N_FIELD) {
|
||||
if (fieldnode.kind == nkind.N_FIELD) {
|
||||
let fname: str = fieldnode.str;
|
||||
let fi: *fieldinfo = si.fields;
|
||||
for (fi != nil) {
|
||||
@@ -576,7 +576,7 @@ fn cgmassign(c: *cgen, n: *node) void = {
|
||||
let l1: *node = nil;
|
||||
if (l0 != nil) { l1 = l0.next; };
|
||||
if (l0 != nil) {
|
||||
if (l0.kind == N_IDENT) {
|
||||
if (l0.kind == nkind.N_IDENT) {
|
||||
let off: i32 = localfind(c, l0.str);
|
||||
if (off != 0) {
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
@@ -587,7 +587,7 @@ fn cgmassign(c: *cgen, n: *node) void = {
|
||||
};
|
||||
emitline("\tPOPQ\tDX\n");
|
||||
if (l1 != nil) {
|
||||
if (l1.kind == N_IDENT) {
|
||||
if (l1.kind == nkind.N_IDENT) {
|
||||
let off: i32 = localfind(c, l1.str);
|
||||
if (off != 0) {
|
||||
emitline("\tMOVQ\tDX, ");
|
||||
@@ -605,7 +605,7 @@ fn cgmassign(c: *cgen, n: *node) void = {
|
||||
// type is taken from its explicit annotation (l.lhs) when present
|
||||
// or inferred from the called fn's return-type tuple element.
|
||||
//
|
||||
// Per the AX:DX:CX return convention (mirrors C cgen N_MLET):
|
||||
// Per the AX:DX:CX return convention (mirrors C cgen nkind.N_MLET):
|
||||
// (scalar, scalar) — AX → l0, DX → l1.
|
||||
// (scalar, str) — AX → scalar slot, (DX, CX) → str slot
|
||||
// as (.ptr, .len). Position-agnostic — the
|
||||
@@ -616,17 +616,17 @@ fn cgmlet(c: *cgen, n: *node) void = {
|
||||
|
||||
let p0t: *node = nil;
|
||||
let p1t: *node = nil;
|
||||
if (rhs.kind == N_CALL) {
|
||||
if (rhs.kind == nkind.N_CALL) {
|
||||
let callee: *node = 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; };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user