From 6204c4cd27b127a30781336b861324faf2555258 Mon Sep 17 00:00:00 2001 From: Hojun-Cho Date: Mon, 11 May 2026 14:37:45 +0900 Subject: [PATCH] selfhost/cmd/wcc: drop snake_case from 119 cross-cutting identifiers --- selfhost/cmd/w6c/main.combined.ww | 2506 ++++++++++++------------- selfhost/cmd/w6c/main.ww | 6 +- selfhost/cmd/wcc/cgen.ww | 1866 +++++++++---------- selfhost/cmd/wcc/check.ww | 134 +- selfhost/cmd/wcc/lex.ww | 180 +- selfhost/cmd/wcc/parse.ww | 166 +- selfhost/cmd/wcc/sym.ww | 10 +- selfhost/cmd/wcc/tok.ww | 94 +- selfhost/cmd/wcc/typ.ww | 50 +- selfhost/cmd/wwdump/main.combined.ww | 2508 +++++++++++++------------- selfhost/cmd/wwdump/main.ww | 8 +- selfhost/test/sym_link.ww | 12 +- 12 files changed, 3770 insertions(+), 3770 deletions(-) diff --git a/selfhost/cmd/w6c/main.combined.ww b/selfhost/cmd/w6c/main.combined.ww index fb0bcbb0..89d8e10c 100644 --- a/selfhost/cmd/w6c/main.combined.ww +++ b/selfhost/cmd/w6c/main.combined.ww @@ -570,7 +570,7 @@ type tok = struct { // ---- keyword lookup --------------------------------------------------- -fn streq_n(a: *u8, b: str, n: i32) bool = { +fn streqn(a: *u8, b: str, n: i32) bool = { if (b.len != n) { return false; }; let i: i32 = 0; for (i < n) { @@ -584,30 +584,30 @@ fn streq_n(a: *u8, b: str, n: i32) bool = { // or TK_NONE if it's an ordinary identifier. Linear search over a // small alphabetised list, matching cmd/wcc/tok.c. export fn kwlookup(p: *u8, n: i32) i32 = { - if (streq_n(p, "as", n)) { return TK_AS; }; - if (streq_n(p, "break", n)) { return TK_BREAK; }; - if (streq_n(p, "case", n)) { return TK_CASE; }; - if (streq_n(p, "chan", n)) { return TK_CHAN; }; - if (streq_n(p, "continue", n)) { return TK_CONTINUE; }; - if (streq_n(p, "def", n)) { return TK_DEF; }; - if (streq_n(p, "defer", n)) { return TK_DEFER; }; - if (streq_n(p, "else", n)) { return TK_ELSE; }; - if (streq_n(p, "export", n)) { return TK_EXPORT; }; - if (streq_n(p, "false", n)) { return TK_FALSE; }; - if (streq_n(p, "fn", n)) { return TK_FN; }; - if (streq_n(p, "for", n)) { return TK_FOR; }; - if (streq_n(p, "if", n)) { return TK_IF; }; - if (streq_n(p, "let", n)) { return TK_LET; }; - if (streq_n(p, "match", n)) { return TK_MATCH; }; - if (streq_n(p, "nil", n)) { return TK_NIL; }; - if (streq_n(p, "proc", n)) { return TK_PROC; }; - if (streq_n(p, "return", n)) { return TK_RETURN; }; - if (streq_n(p, "static", n)) { return TK_STATIC; }; - if (streq_n(p, "struct", n)) { return TK_STRUCT; }; - if (streq_n(p, "switch", n)) { return TK_SWITCH; }; - if (streq_n(p, "true", n)) { return TK_TRUE; }; - if (streq_n(p, "type", n)) { return TK_TYPE; }; - if (streq_n(p, "use", n)) { return TK_USE; }; + if (streqn(p, "as", n)) { return TK_AS; }; + if (streqn(p, "break", n)) { return TK_BREAK; }; + if (streqn(p, "case", n)) { return TK_CASE; }; + if (streqn(p, "chan", n)) { return TK_CHAN; }; + if (streqn(p, "continue", n)) { return TK_CONTINUE; }; + if (streqn(p, "def", n)) { return TK_DEF; }; + if (streqn(p, "defer", n)) { return TK_DEFER; }; + if (streqn(p, "else", n)) { return TK_ELSE; }; + if (streqn(p, "export", n)) { return TK_EXPORT; }; + if (streqn(p, "false", n)) { return TK_FALSE; }; + if (streqn(p, "fn", n)) { return TK_FN; }; + if (streqn(p, "for", n)) { return TK_FOR; }; + if (streqn(p, "if", n)) { return TK_IF; }; + if (streqn(p, "let", n)) { return TK_LET; }; + if (streqn(p, "match", n)) { return TK_MATCH; }; + if (streqn(p, "nil", n)) { return TK_NIL; }; + if (streqn(p, "proc", n)) { return TK_PROC; }; + if (streqn(p, "return", n)) { return TK_RETURN; }; + if (streqn(p, "static", n)) { return TK_STATIC; }; + if (streqn(p, "struct", n)) { return TK_STRUCT; }; + if (streqn(p, "switch", n)) { return TK_SWITCH; }; + if (streqn(p, "true", n)) { return TK_TRUE; }; + if (streqn(p, "type", n)) { return TK_TYPE; }; + if (streqn(p, "use", n)) { return TK_USE; }; return TK_NONE; }; @@ -714,13 +714,13 @@ export fn tokname(k: i32) str = { // fputq mirrors cmd/wcc/tok.c:fputq — quote the string with C-style // escapes for \, ", \n, \t, \r and \xNN for other non-printables. -fn fputc_byte(fd: i32, b: u8) void = { +fn fputcbyte(fd: i32, b: u8) void = { let buf: [1]u8; buf[0] = b; os.write(fd, buf.ptr, 1u64); }; -fn fputs_str(fd: i32, s: str) void = { +fn fputsstr(fd: i32, s: str) void = { os.write(fd, s.ptr, s.len: u64); }; @@ -739,24 +739,24 @@ fn fputhex2(fd: i32, b: u8) void = { }; fn fputq(fd: i32, p: *u8, n: i32) void = { - fputc_byte(fd, 34u8); // '"' + fputcbyte(fd, 34u8); // '"' let i: i32 = 0; for (i < n) { let c: u8 = p[i]; if (c == 92u8) { // '\\' - fputs_str(fd, "\\\\"); + fputsstr(fd, "\\\\"); } else { if (c == 34u8) { // '"' - fputs_str(fd, "\\\""); + fputsstr(fd, "\\\""); } else { if (c == 10u8) { // '\n' - fputs_str(fd, "\\n"); + fputsstr(fd, "\\n"); } else { if (c == 9u8) { // '\t' - fputs_str(fd, "\\t"); + fputsstr(fd, "\\t"); } else { if (c == 13u8) { // '\r' - fputs_str(fd, "\\r"); + fputsstr(fd, "\\r"); } else { if (c < 32u8) { fputhex2(fd, c); @@ -764,7 +764,7 @@ fn fputq(fd: i32, p: *u8, n: i32) void = { if (c == 127u8) { fputhex2(fd, c); } else { - fputc_byte(fd, c); + fputcbyte(fd, c); }; }; }; @@ -774,7 +774,7 @@ fn fputq(fd: i32, p: *u8, n: i32) void = { }; i += 1; }; - fputc_byte(fd, 34u8); + fputcbyte(fd, 34u8); }; // tokprint — write one token line to fd. Format must match @@ -790,35 +790,35 @@ export fn tokprint(fd: i32, t: *tok) void = { let tfile: str = t.file; let ttext: str = t.text; if (tfile.len > 0) { - fputs_str(fd, tfile); + fputsstr(fd, tfile); } else { - fputs_str(fd, ""); + fputsstr(fd, ""); }; - fputc_byte(fd, 58u8); // ':' + fputcbyte(fd, 58u8); // ':' let buf: [32]u8; let n: i32 = strconv.i64toa(buf[0:32], t.line: i64); os.write(fd, buf.ptr, n: u64); - fputc_byte(fd, 58u8); + fputcbyte(fd, 58u8); n = strconv.i64toa(buf[0:32], t.col: i64); os.write(fd, buf.ptr, n: u64); - fputc_byte(fd, 32u8); // ' ' - fputs_str(fd, tokname(t.kind)); + fputcbyte(fd, 32u8); // ' ' + fputsstr(fd, tokname(t.kind)); if (t.kind == TK_IDENT) { - fputc_byte(fd, 32u8); + fputcbyte(fd, 32u8); fputq(fd, ttext.ptr, ttext.len); } else { if (t.kind == TK_STR) { - fputc_byte(fd, 32u8); + fputcbyte(fd, 32u8); fputq(fd, ttext.ptr, ttext.len); } else { if (t.kind == TK_ERR) { - fputc_byte(fd, 32u8); + fputcbyte(fd, 32u8); fputq(fd, ttext.ptr, ttext.len); } else { if (t.kind == TK_INT) { - fputc_byte(fd, 32u8); + fputcbyte(fd, 32u8); n = strconv.u64toa(buf[0:32], t.uval); os.write(fd, buf.ptr, n: u64); } else { if (t.kind == TK_RUNE) { - fputc_byte(fd, 32u8); + fputcbyte(fd, 32u8); n = strconv.u64toa(buf[0:32], t.uval); os.write(fd, buf.ptr, n: u64); };};};};}; @@ -826,7 +826,7 @@ export fn tokprint(fd: i32, t: *tok) void = { // won't byte-match across implementations. Diff fixtures must // be float-free until we implement a stable float formatter. - fputc_byte(fd, 10u8); // '\n' + fputcbyte(fd, 10u8); // '\n' }; // ascii — byte-class predicates and case folding for the ASCII range. @@ -988,14 +988,14 @@ fn lget(l: *lex) i32 = { return c; }; -fn cur_pos(l: *lex, out: *pos) void = { +fn curpos(l: *lex, out: *pos) void = { out.file = l.file; out.line = l.line; out.col = l.col; }; // putuint — write `v` (signed, but always non-negative here) to fd 2 -// in decimal. Standalone so err_at doesn't drag in fmt and create a +// in decimal. Standalone so errat doesn't drag in fmt and create a // dependency cycle with strconv. fn putuint(fd: i32, v: i32) void = { let tmp: [16]u8; @@ -1013,7 +1013,7 @@ fn putuint(fd: i32, v: i32) void = { os.write(fd, buf.ptr, m: u64); }; -fn err_at(l: *lex, p: *pos, msg: str) void = { +fn errat(l: *lex, p: *pos, msg: str) void = { let pf: str = p.file; os.write(2, pf.ptr, pf.len: u64); os.write(2, ":".ptr, 1u64); @@ -1052,8 +1052,8 @@ fn skipws(l: *lex) bool = { let x: i32 = lget(l); if (x < 0) { let cp: pos; - cur_pos(l, &cp); - err_at(l, &cp, "unterminated /* comment"); + curpos(l, &cp); + errat(l, &cp, "unterminated /* comment"); return false; }; if (prev == 42) { @@ -1124,13 +1124,13 @@ fn escape(l: *lex, out: *i32) bool = { if (hi < 0) { return false; }; if (lo < 0) { return false; }; if (!ascii.ishex(hi: u8)) { - let cp: pos; cur_pos(l, &cp); - err_at(l, &cp, "bad \\x escape"); + let cp: pos; curpos(l, &cp); + errat(l, &cp, "bad \\x escape"); return false; }; if (!ascii.ishex(lo: u8)) { - let cp: pos; cur_pos(l, &cp); - err_at(l, &cp, "bad \\x escape"); + let cp: pos; curpos(l, &cp); + errat(l, &cp, "bad \\x escape"); return false; }; let h: i32 = ascii.digitval(hi: u8); @@ -1138,13 +1138,13 @@ fn escape(l: *lex, out: *i32) bool = { *out = (h << 4) | lv; return true; }; - let cp: pos; cur_pos(l, &cp); - err_at(l, &cp, "bad escape"); + let cp: pos; curpos(l, &cp); + errat(l, &cp, "bad escape"); return false; }; -// scan_decimal_run — consume a run of decimal digits and underscores. -fn scan_decimal_run(l: *lex) void = { +// scandecimalrun — consume a run of decimal digits and underscores. +fn scandecimalrun(l: *lex) void = { for (true) { let c: i32 = lpeek(l, 0u64); if (c < 0) { break; }; @@ -1155,7 +1155,7 @@ fn scan_decimal_run(l: *lex) void = { }; }; -fn scan_hex_run(l: *lex) void = { +fn scanhexrun(l: *lex) void = { for (true) { let c: i32 = lpeek(l, 0u64); if (c < 0) { break; }; @@ -1166,7 +1166,7 @@ fn scan_hex_run(l: *lex) void = { }; }; -fn scan_bin_run(l: *lex) void = { +fn scanbinrun(l: *lex) void = { for (true) { let c: i32 = lpeek(l, 0u64); if (c == 48) { lget(l); continue; }; @@ -1176,7 +1176,7 @@ fn scan_bin_run(l: *lex) void = { }; }; -fn scan_oct_run(l: *lex) void = { +fn scanoctrun(l: *lex) void = { for (true) { let c: i32 = lpeek(l, 0u64); if (c < 48) { break; }; @@ -1187,8 +1187,8 @@ fn scan_oct_run(l: *lex) void = { }; }; -// scan_exp — consume the [eE][+-]?[0-9]+ tail of a float, if present. -fn scan_exp(l: *lex) void = { +// scanexp — consume the [eE][+-]?[0-9]+ tail of a float, if present. +fn scanexp(l: *lex) void = { let e: i32 = lpeek(l, 0u64); if (e != 101) { if (e != 69) { return; }; }; // 'e' or 'E' lget(l); @@ -1217,41 +1217,41 @@ fn lexnum(l: *lex, start: *pos, out: *tok) void = { if (c0 == 48) { // '0' if (c1 == 120) { // 'x' - lget(l); lget(l); base = 16; scan_hex_run(l); + lget(l); lget(l); base = 16; scanhexrun(l); } else { if (c1 == 88) { // 'X' - lget(l); lget(l); base = 16; scan_hex_run(l); + lget(l); lget(l); base = 16; scanhexrun(l); } else { if (c1 == 98) { // 'b' - lget(l); lget(l); base = 2; scan_bin_run(l); + lget(l); lget(l); base = 2; scanbinrun(l); } else { if (c1 == 66) { // 'B' - lget(l); lget(l); base = 2; scan_bin_run(l); + lget(l); lget(l); base = 2; scanbinrun(l); } else { if (c1 == 111) { // 'o' - lget(l); lget(l); base = 8; scan_oct_run(l); + lget(l); lget(l); base = 8; scanoctrun(l); } else { if (c1 == 79) { // 'O' - lget(l); lget(l); base = 8; scan_oct_run(l); + lget(l); lget(l); base = 8; scanoctrun(l); } else { - scan_decimal_run(l); + scandecimalrun(l); if (lpeek(l, 0u64) == 46) { let after: i32 = lpeek(l, 1u64); if (after >= 48) { if (after <= 57) { isfloat = true; lget(l); - scan_decimal_run(l); - scan_exp(l); + scandecimalrun(l); + scanexp(l); }; }; }; };};};};};}; } else { - scan_decimal_run(l); + scandecimalrun(l); if (lpeek(l, 0u64) == 46) { let after: i32 = lpeek(l, 1u64); if (after >= 48) { if (after <= 57) { isfloat = true; lget(l); - scan_decimal_run(l); - scan_exp(l); + scandecimalrun(l); + scanexp(l); }; }; }; @@ -1276,7 +1276,7 @@ fn lexnum(l: *lex, start: *pos, out: *tok) void = { let ok: bool = false; out.uval = parseint(digs, dn, base, &ok); if (!ok) { - err_at(l, start, "bad integer literal"); + errat(l, start, "bad integer literal"); out.kind = TK_ERR; }; }; @@ -1356,7 +1356,7 @@ fn lexstr(l: *lex, start: *pos, out: *tok) void = { for (true) { let c: i32 = lpeek(l, 0u64); if (c < 0) { - err_at(l, start, "unterminated string"); + errat(l, start, "unterminated string"); out.kind = TK_ERR; out.file = start.file; out.line = start.line; @@ -1401,7 +1401,7 @@ fn lexstr(l: *lex, start: *pos, out: *tok) void = { fn lexrune(l: *lex, start: *pos, out: *tok) void = { let c: i32 = lpeek(l, 0u64); if (c < 0) { - err_at(l, start, "unterminated rune"); + errat(l, start, "unterminated rune"); out.kind = TK_ERR; out.file = start.file; out.line = start.line; @@ -1417,7 +1417,7 @@ fn lexrune(l: *lex, start: *pos, out: *tok) void = { ch = lget(l); }; if (lpeek(l, 0u64) != 39) { - err_at(l, start, "rune literal missing closing '"); + errat(l, start, "rune literal missing closing '"); out.kind = TK_ERR; out.file = start.file; out.line = start.line; @@ -1433,16 +1433,16 @@ fn lexrune(l: *lex, start: *pos, out: *tok) void = { out.uval = ch: u64; }; -fn emit_simple(start: *pos, k: i32, out: *tok) void = { +fn emitsimple(start: *pos, k: i32, out: *tok) void = { out.kind = k; out.file = start.file; out.line = start.line; out.col = start.col; }; -// set_pos_from — copy file/line/col from a *pos into a tok. Used by +// setposfrom — copy file/line/col from a *pos into a tok. Used by // the err-token path where we already have a pos. -fn set_pos_from(out: *tok, p: *pos) void = { +fn setposfrom(out: *tok, p: *pos) void = { out.file = p.file; out.line = p.line; out.col = p.col; @@ -1465,11 +1465,11 @@ export fn lexnext(l: *lex, out: *tok) void = { out.tsuffix = empty; if (!skipws(l)) { - let p: pos; cur_pos(l, &p); - emit_simple(&p, TK_EOF, out); + let p: pos; curpos(l, &p); + emitsimple(&p, TK_EOF, out); return; }; - let start: pos; cur_pos(l, &start); + let start: pos; curpos(l, &start); let c: i32 = lpeek(l, 0u64); if (c >= 0) { @@ -1482,98 +1482,98 @@ export fn lexnext(l: *lex, out: *tok) void = { lget(l); - if (c == 40) { emit_simple(&start, TK_LPAREN, out); return; }; - if (c == 41) { emit_simple(&start, TK_RPAREN, out); return; }; - if (c == 123) { emit_simple(&start, TK_LBRACE, out); return; }; - if (c == 125) { emit_simple(&start, TK_RBRACE, out); return; }; - if (c == 91) { emit_simple(&start, TK_LBRACK, out); return; }; - if (c == 93) { emit_simple(&start, TK_RBRACK, out); return; }; - if (c == 44) { emit_simple(&start, TK_COMMA, out); return; }; - if (c == 59) { emit_simple(&start, TK_SEMI, out); return; }; - if (c == 58) { emit_simple(&start, TK_COLON, out); return; }; - if (c == 64) { emit_simple(&start, TK_AT, out); return; }; - if (c == 63) { emit_simple(&start, TK_QUESTION, out); return; }; - if (c == 126) { emit_simple(&start, TK_TILDE, out); return; }; + if (c == 40) { emitsimple(&start, TK_LPAREN, out); return; }; + if (c == 41) { emitsimple(&start, TK_RPAREN, out); return; }; + if (c == 123) { emitsimple(&start, TK_LBRACE, out); return; }; + if (c == 125) { emitsimple(&start, TK_RBRACE, out); return; }; + if (c == 91) { emitsimple(&start, TK_LBRACK, out); return; }; + if (c == 93) { emitsimple(&start, TK_RBRACK, out); return; }; + if (c == 44) { emitsimple(&start, TK_COMMA, out); return; }; + if (c == 59) { emitsimple(&start, TK_SEMI, out); return; }; + if (c == 58) { emitsimple(&start, TK_COLON, out); return; }; + if (c == 64) { emitsimple(&start, TK_AT, out); return; }; + if (c == 63) { emitsimple(&start, TK_QUESTION, out); return; }; + if (c == 126) { emitsimple(&start, TK_TILDE, out); return; }; if (c == 46) { // '.' if (lpeek(l, 0u64) == 46) { if (lpeek(l, 1u64) == 46) { lget(l); lget(l); - emit_simple(&start, TK_ELLIPSIS, out); return; + emitsimple(&start, TK_ELLIPSIS, out); return; }; lget(l); - emit_simple(&start, TK_DOTDOT, out); return; + emitsimple(&start, TK_DOTDOT, out); return; }; - emit_simple(&start, TK_DOT, out); return; + emitsimple(&start, TK_DOT, out); return; }; if (c == 43) { - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_PLUSEQ, out); return; }; - emit_simple(&start, TK_PLUS, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_PLUSEQ, out); return; }; + emitsimple(&start, TK_PLUS, out); return; }; if (c == 45) { - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_MINUSEQ, out); return; }; - if (lpeek(l, 0u64) == 62) { lget(l); emit_simple(&start, TK_ARROW, out); return; }; - emit_simple(&start, TK_MINUS, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_MINUSEQ, out); return; }; + if (lpeek(l, 0u64) == 62) { lget(l); emitsimple(&start, TK_ARROW, out); return; }; + emitsimple(&start, TK_MINUS, out); return; }; if (c == 42) { - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_STAREQ, out); return; }; - emit_simple(&start, TK_STAR, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_STAREQ, out); return; }; + emitsimple(&start, TK_STAR, out); return; }; if (c == 47) { - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_SLASHEQ, out); return; }; - emit_simple(&start, TK_SLASH, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_SLASHEQ, out); return; }; + emitsimple(&start, TK_SLASH, out); return; }; if (c == 37) { - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_PERCENTEQ, out); return; }; - emit_simple(&start, TK_PERCENT, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_PERCENTEQ, out); return; }; + emitsimple(&start, TK_PERCENT, out); return; }; if (c == 38) { - if (lpeek(l, 0u64) == 38) { lget(l); emit_simple(&start, TK_AND, out); return; }; - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_AMPEQ, out); return; }; - emit_simple(&start, TK_AMP, out); return; + if (lpeek(l, 0u64) == 38) { lget(l); emitsimple(&start, TK_AND, out); return; }; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_AMPEQ, out); return; }; + emitsimple(&start, TK_AMP, out); return; }; if (c == 124) { - if (lpeek(l, 0u64) == 124) { lget(l); emit_simple(&start, TK_OR, out); return; }; - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_PIPEEQ, out); return; }; - emit_simple(&start, TK_PIPE, out); return; + if (lpeek(l, 0u64) == 124) { lget(l); emitsimple(&start, TK_OR, out); return; }; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_PIPEEQ, out); return; }; + emitsimple(&start, TK_PIPE, out); return; }; if (c == 94) { - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_CARETEQ, out); return; }; - emit_simple(&start, TK_CARET, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_CARETEQ, out); return; }; + emitsimple(&start, TK_CARET, out); return; }; if (c == 61) { - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_EQ, out); return; }; - if (lpeek(l, 0u64) == 62) { lget(l); emit_simple(&start, TK_FATARROW, out); return; }; - emit_simple(&start, TK_ASSIGN, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_EQ, out); return; }; + if (lpeek(l, 0u64) == 62) { lget(l); emitsimple(&start, TK_FATARROW, out); return; }; + emitsimple(&start, TK_ASSIGN, out); return; }; if (c == 33) { - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_NEQ, out); return; }; - emit_simple(&start, TK_NOT, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_NEQ, out); return; }; + emitsimple(&start, TK_NOT, out); return; }; if (c == 60) { if (lpeek(l, 0u64) == 60) { lget(l); - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_LSHIFTEQ, out); return; }; - emit_simple(&start, TK_LSHIFT, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_LSHIFTEQ, out); return; }; + emitsimple(&start, TK_LSHIFT, out); return; }; - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_LE, out); return; }; - if (lpeek(l, 0u64) == 45) { lget(l); emit_simple(&start, TK_LARROW, out); return; }; - emit_simple(&start, TK_LT, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_LE, out); return; }; + if (lpeek(l, 0u64) == 45) { lget(l); emitsimple(&start, TK_LARROW, out); return; }; + emitsimple(&start, TK_LT, out); return; }; if (c == 62) { if (lpeek(l, 0u64) == 62) { lget(l); - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_RSHIFTEQ, out); return; }; - emit_simple(&start, TK_RSHIFT, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_RSHIFTEQ, out); return; }; + emitsimple(&start, TK_RSHIFT, out); return; }; - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_GE, out); return; }; - emit_simple(&start, TK_GT, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_GE, out); return; }; + emitsimple(&start, TK_GT, out); return; }; - err_at(l, &start, "unexpected character"); + errat(l, &start, "unexpected character"); out.kind = TK_ERR; - set_pos_from(out, &start); + setposfrom(out, &start); let one: [1]u8; one[0] = c: u8; out.text = astrndup(l.a, one.ptr, 1u64); @@ -1973,12 +1973,12 @@ export fn parserinit(p: *parser, a: *arena, l: *lex) void = { fn advance(p: *parser) void = { refill(p); }; -fn accept_tok(p: *parser, k: i32) bool = { +fn accepttok(p: *parser, k: i32) bool = { if (p.cur_kind == k) { advance(p); return true; }; return false; }; -fn err_msg(p: *parser, msg: str) void = { +fn errmsg(p: *parser, msg: str) void = { let pre: str = "parse: "; os.write(2, pre.ptr, pre.len: u64); os.write(2, msg.ptr, msg.len: u64); @@ -1986,9 +1986,9 @@ fn err_msg(p: *parser, msg: str) void = { p.errs += 1; }; -fn expect_tok(p: *parser, k: i32, what: str) bool = { +fn expecttok(p: *parser, k: i32, what: str) bool = { if (p.cur_kind == k) { advance(p); return true; }; - err_msg(p, what); + errmsg(p, what); return false; }; @@ -1996,7 +1996,7 @@ fn expect_tok(p: *parser, k: i32, what: str) bool = { // Returns the empty str on error (and advances to make progress). fn expectident(p: *parser, into: *str) bool = { if (p.cur_kind != TK_IDENT) { - err_msg(p, "expected identifier"); + errmsg(p, "expected identifier"); advance(p); return false; }; @@ -2033,14 +2033,14 @@ fn parsetype(p: *parser) *node = { }; let n: *node = newnode(p.a, N_TARRAY, pf, pl, pc); n.rhs = parseexpr(p); - expect_tok(p, TK_RBRACK, "expected ']' in array type"); + expecttok(p, TK_RBRACK, "expected ']' in array type"); n.lhs = parsetype(p); return n; }; if (p.cur_kind == TK_STRUCT) { advance(p); - expect_tok(p, TK_LBRACE, "expected '{' after struct"); + expecttok(p, TK_LBRACE, "expected '{' after struct"); let n: *node = newnode(p.a, N_TSTRUCT, pf, pl, pc); let fhead: *node = nil; let ftail: *node = nil; @@ -2053,13 +2053,13 @@ fn parsetype(p: *parser) *node = { let fid: str; expectident(p, &fid); f.str = fid; - expect_tok(p, TK_COLON, "expected ':' in field"); + expecttok(p, TK_COLON, "expected ':' in field"); f.lhs = parsetype(p); if (fhead == nil) { fhead = f; ftail = f; } else { ftail.next = f; ftail = f; }; - if (!accept_tok(p, TK_COMMA)) { break; }; + if (!accepttok(p, TK_COMMA)) { break; }; }; - expect_tok(p, TK_RBRACE, "expected '}' after struct fields"); + expecttok(p, TK_RBRACE, "expected '}' after struct fields"); n.list = fhead; return n; }; @@ -2077,7 +2077,7 @@ fn parsetype(p: *parser) *node = { // (T) or (T, T, ...) or (T | T | ...) advance(p); let first: *node = parsetype(p); - if (accept_tok(p, TK_PIPE)) { + if (accepttok(p, TK_PIPE)) { let n: *node = newnode(p.a, N_TTAGGED, pf, pl, pc); let head: *node = first; let tail: *node = first; @@ -2085,14 +2085,14 @@ fn parsetype(p: *parser) *node = { let e: *node = parsetype(p); tail.next = e; tail = e; - if (!accept_tok(p, TK_PIPE)) { break; }; + if (!accepttok(p, TK_PIPE)) { break; }; }; - expect_tok(p, TK_RPAREN, "expected ')' in tagged-union type"); + expecttok(p, TK_RPAREN, "expected ')' in tagged-union type"); n.list = head; return n; }; - if (!accept_tok(p, TK_COMMA)) { - expect_tok(p, TK_RPAREN, "expected ')' after parenthesised type"); + if (!accepttok(p, TK_COMMA)) { + expecttok(p, TK_RPAREN, "expected ')' after parenthesised type"); return first; }; let n: *node = newnode(p.a, N_TTUPLE, pf, pl, pc); @@ -2102,28 +2102,28 @@ fn parsetype(p: *parser) *node = { let e: *node = parsetype(p); tail.next = e; tail = e; - if (!accept_tok(p, TK_COMMA)) { break; }; + if (!accepttok(p, TK_COMMA)) { break; }; if (p.cur_kind == TK_RPAREN) { break; }; }; - expect_tok(p, TK_RPAREN, "expected ')' in tuple type"); + expecttok(p, TK_RPAREN, "expected ')' in tuple type"); n.list = head; return n; }; if (p.cur_kind == TK_FN) { advance(p); - expect_tok(p, TK_LPAREN, "expected '(' after fn in type"); + expecttok(p, TK_LPAREN, "expected '(' after fn in type"); let n: *node = newnode(p.a, N_TFN, pf, pl, pc); // Anonymous-or-named params: parseparams handles named only; // for fn-type expressions the C parser allows IDENT-less // (anonymous) params. Stub: only named params for now. n.list = parseparams(p); - expect_tok(p, TK_RPAREN, "expected ')' after fn type params"); + expecttok(p, TK_RPAREN, "expected ')' after fn type params"); n.lhs = parsetype(p); return n; }; - err_msg(p, "expected type"); + errmsg(p, "expected type"); advance(p); return newnode(p.a, N_TNAME, pf, pl, pc); }; @@ -2215,7 +2215,7 @@ fn parseprimary(p: *parser) *node = { advance(p); let e: *node = parseexpr(p); // Tuple literal: (a, b, ...) - if (accept_tok(p, TK_COMMA)) { + if (accepttok(p, TK_COMMA)) { let t: *node = newnode(p.a, N_TUPLE, pf, pl, pc); t.list = e; let tail: *node = e; @@ -2224,12 +2224,12 @@ fn parseprimary(p: *parser) *node = { let en: *node = parseexpr(p); tail.next = en; tail = en; - if (!accept_tok(p, TK_COMMA)) { break; }; + if (!accepttok(p, TK_COMMA)) { break; }; }; - expect_tok(p, TK_RPAREN, "expected ')' in tuple"); + expecttok(p, TK_RPAREN, "expected ')' in tuple"); return t; }; - expect_tok(p, TK_RPAREN, "expected ')'"); + expecttok(p, TK_RPAREN, "expected ')'"); return e; }; if (p.cur_kind == TK_IDENT) { @@ -2255,16 +2255,16 @@ fn parseprimary(p: *parser) *node = { let fpc: i32 = p.cur_col; let id: str; expectident(p, &id); - expect_tok(p, TK_ASSIGN, "expected '=' in struct lit field"); + expecttok(p, TK_ASSIGN, "expected '=' in struct lit field"); let v: *node = parseexpr(p); let f: *node = newnode(p.a, N_FIELD, fpf, fpl, fpc); f.str = id; f.lhs = v; if (head == nil) { head = f; tail = f; } else { tail.next = f; tail = f; }; - if (!accept_tok(p, TK_COMMA)) { break; }; + if (!accepttok(p, TK_COMMA)) { break; }; }; - expect_tok(p, TK_RBRACE, "expected '}' after struct literal"); + expecttok(p, TK_RBRACE, "expected '}' after struct literal"); s.list = head; return s; }; @@ -2273,11 +2273,11 @@ fn parseprimary(p: *parser) *node = { if (p.cur_kind == TK_MATCH) { // match (e) { case let v: T => stmt; case T => stmt; case => stmt; }; advance(p); - expect_tok(p, TK_LPAREN, "expected '(' after match"); + expecttok(p, TK_LPAREN, "expected '(' after match"); let m: *node = newnode(p.a, N_MATCH, pf, pl, pc); m.lhs = parseexpr(p); - expect_tok(p, TK_RPAREN, "expected ')' after match scrutinee"); - expect_tok(p, TK_LBRACE, "expected '{' to open match body"); + expecttok(p, TK_RPAREN, "expected ')' after match scrutinee"); + expecttok(p, TK_LBRACE, "expected '{' to open match body"); let head: *node = nil; let tail: *node = nil; for (p.cur_kind == TK_CASE) { @@ -2291,21 +2291,21 @@ fn parseprimary(p: *parser) *node = { let id: str; expectident(p, &id); mc.str = id; - expect_tok(p, TK_COLON, "expected ':' after match binding"); + expecttok(p, TK_COLON, "expected ':' after match binding"); mc.lhs = parsetype(p); } else { if (p.cur_kind != TK_FATARROW) { mc.lhs = parsetype(p); };}; - expect_tok(p, TK_FATARROW, "expected '=>' in match arm"); + expecttok(p, TK_FATARROW, "expected '=>' in match arm"); mc.body = parsestmt(p); if (head == nil) { head = mc; tail = mc; } else { tail.next = mc; tail = mc; }; }; - expect_tok(p, TK_RBRACE, "expected '}' after match body"); + expecttok(p, TK_RBRACE, "expected '}' after match body"); m.list = head; return m; }; - err_msg(p, "expected expression"); + errmsg(p, "expected expression"); advance(p); return newnode(p.a, N_NONE, pf, pl, pc); }; @@ -2319,7 +2319,7 @@ fn parsearglist(p: *parser, close_kind: i32, head_out: **node) void = { let e: *node = parseexpr(p); if (head == nil) { head = e; tail = e; } else { tail.next = e; tail = e; }; - if (!accept_tok(p, TK_COMMA)) { break; }; + if (!accepttok(p, TK_COMMA)) { break; }; if (p.cur_kind == close_kind) { break; }; }; *head_out = head; @@ -2338,7 +2338,7 @@ fn parsepostfix(p: *parser, lhs: *node) *node = { let arghead: *node = nil; parsearglist(p, TK_RPAREN, &arghead); n.list = arghead; - expect_tok(p, TK_RPAREN, "expected ')' after args"); + expecttok(p, TK_RPAREN, "expected ')' after args"); cur = n; continue; }; @@ -2352,7 +2352,7 @@ fn parsepostfix(p: *parser, lhs: *node) *node = { if (p.cur_kind != TK_RBRACK) { n.cond = parseexpr(p); }; - expect_tok(p, TK_RBRACK, "expected ']' in slice"); + expecttok(p, TK_RBRACK, "expected ']' in slice"); cur = n; continue; }; @@ -2370,14 +2370,14 @@ fn parsepostfix(p: *parser, lhs: *node) *node = { if (p.cur_kind != TK_RBRACK) { n.cond = parseexpr(p); }; - expect_tok(p, TK_RBRACK, "expected ']' in slice"); + expecttok(p, TK_RBRACK, "expected ']' in slice"); cur = n; continue; }; let n: *node = newnode(p.a, N_INDEX, pf, pl, pc); n.lhs = cur; n.rhs = e; - expect_tok(p, TK_RBRACK, "expected ']' after index"); + expecttok(p, TK_RBRACK, "expected ']' after index"); cur = n; continue; }; @@ -2498,7 +2498,7 @@ fn parseexpr(p: *parser) *node = { // (single-cond C-style), expr-stmt, defer, break, continue. Switch // and match arms are not yet wired; tuple-let / multi-let neither. -fn parselet_local(p: *parser) *node = { +fn parseletlocal(p: *parser) *node = { let pf: str = p.cur_file; let pl: i32 = p.cur_line; let pc: i32 = p.cur_col; @@ -2507,13 +2507,13 @@ fn parselet_local(p: *parser) *node = { let id: str; expectident(p, &id); n.str = id; - if (accept_tok(p, TK_COLON)) { + if (accepttok(p, TK_COLON)) { n.lhs = parsetype(p); }; - if (accept_tok(p, TK_ASSIGN)) { + if (accepttok(p, TK_ASSIGN)) { n.rhs = parseexpr(p); }; - expect_tok(p, TK_SEMI, "expected ';' after let"); + expecttok(p, TK_SEMI, "expected ';' after let"); return n; }; @@ -2521,7 +2521,7 @@ fn parseblock(p: *parser) *node = { let pf: str = p.cur_file; let pl: i32 = p.cur_line; let pc: i32 = p.cur_col; - expect_tok(p, TK_LBRACE, "expected '{' to open block"); + expecttok(p, TK_LBRACE, "expected '{' to open block"); let blk: *node = newnode(p.a, N_BLOCK, pf, pl, pc); let head: *node = nil; let tail: *node = nil; @@ -2533,7 +2533,7 @@ fn parseblock(p: *parser) *node = { else { tail.next = s; tail = s; }; }; }; - expect_tok(p, TK_RBRACE, "expected '}' to close block"); + expecttok(p, TK_RBRACE, "expected '}' to close block"); blk.list = head; return blk; }; @@ -2543,12 +2543,12 @@ fn parseif(p: *parser) *node = { let pl: i32 = p.cur_line; let pc: i32 = p.cur_col; advance(p); // past `if` - expect_tok(p, TK_LPAREN, "expected '(' after if"); + expecttok(p, TK_LPAREN, "expected '(' after if"); let n: *node = newnode(p.a, N_IF, pf, pl, pc); n.cond = parseexpr(p); - expect_tok(p, TK_RPAREN, "expected ')' after if condition"); + expecttok(p, TK_RPAREN, "expected ')' after if condition"); n.body = parseblock(p); - if (accept_tok(p, TK_ELSE)) { + if (accepttok(p, TK_ELSE)) { if (p.cur_kind == TK_IF) { n.els = parseif(p); } else { @@ -2563,7 +2563,7 @@ fn parsefor(p: *parser) *node = { let pl: i32 = p.cur_line; let pc: i32 = p.cur_col; advance(p); // past `for` - expect_tok(p, TK_LPAREN, "expected '(' after for"); + expecttok(p, TK_LPAREN, "expected '(' after for"); let n: *node = newnode(p.a, N_FOR, pf, pl, pc); // Three forms (matching C parser): // for (cond) — only cond @@ -2574,14 +2574,14 @@ fn parsefor(p: *parser) *node = { // ';' it was cond. If we see two ';' total after init, post is // next. Simpler: peek for `let` to decide init form. if (p.cur_kind == TK_LET) { - n.lhs = parselet_local(p); // init (consumes its own ';') + n.lhs = parseletlocal(p); // init (consumes its own ';') n.cond = parseexpr(p); - expect_tok(p, TK_SEMI, "expected ';' after for cond"); + expecttok(p, TK_SEMI, "expected ';' after for cond"); n.rhs = parseexpr(p); } else { // Parse one expr. If next is ';', it's a 3-clause without init. let first: *node = parseexpr(p); - if (accept_tok(p, TK_SEMI)) { + if (accepttok(p, TK_SEMI)) { // cond ; post n.cond = first; n.rhs = parseexpr(p); @@ -2590,7 +2590,7 @@ fn parsefor(p: *parser) *node = { n.cond = first; }; }; - expect_tok(p, TK_RPAREN, "expected ')' after for"); + expecttok(p, TK_RPAREN, "expected ')' after for"); n.body = parseblock(p); return n; }; @@ -2606,18 +2606,18 @@ fn parsestmt(p: *parser) *node = { if (p.cur_kind == TK_LBRACE) { let b: *node = parseblock(p); - expect_tok(p, TK_SEMI, "expected ';' after block"); + expecttok(p, TK_SEMI, "expected ';' after block"); return b; }; - if (p.cur_kind == TK_LET) { return parselet_local(p); }; + if (p.cur_kind == TK_LET) { return parseletlocal(p); }; if (p.cur_kind == TK_IF) { let n: *node = parseif(p); - expect_tok(p, TK_SEMI, "expected ';' after if"); + expecttok(p, TK_SEMI, "expected ';' after if"); return n; }; if (p.cur_kind == TK_FOR) { let n: *node = parsefor(p); - expect_tok(p, TK_SEMI, "expected ';' after for"); + expecttok(p, TK_SEMI, "expected ';' after for"); return n; }; if (p.cur_kind == TK_RETURN) { @@ -2631,7 +2631,7 @@ fn parsestmt(p: *parser) *node = { let t: *node = newnode(p.a, N_TUPLE, pf, pl, pc); t.list = first; let tail: *node = first; - for (accept_tok(p, TK_COMMA)) { + for (accepttok(p, TK_COMMA)) { let e: *node = parseexpr(p); tail.next = e; tail = e; @@ -2641,24 +2641,24 @@ fn parsestmt(p: *parser) *node = { n.lhs = first; }; }; - expect_tok(p, TK_SEMI, "expected ';' after return"); + expecttok(p, TK_SEMI, "expected ';' after return"); return n; }; if (p.cur_kind == TK_DEFER) { advance(p); let n: *node = newnode(p.a, N_DEFER, pf, pl, pc); n.lhs = parseexpr(p); - expect_tok(p, TK_SEMI, "expected ';' after defer"); + expecttok(p, TK_SEMI, "expected ';' after defer"); return n; }; if (p.cur_kind == TK_BREAK) { advance(p); - expect_tok(p, TK_SEMI, "expected ';' after break"); + expecttok(p, TK_SEMI, "expected ';' after break"); return newnode(p.a, N_BREAK, pf, pl, pc); }; if (p.cur_kind == TK_CONTINUE) { advance(p); - expect_tok(p, TK_SEMI, "expected ';' after continue"); + expecttok(p, TK_SEMI, "expected ';' after continue"); return newnode(p.a, N_CONTINUE, pf, pl, pc); }; // expression statement, or tuple-destructure multi-assign: @@ -2678,15 +2678,15 @@ fn parsestmt(p: *parser) *node = { tail.next = lv; tail = lv; }; - expect_tok(p, TK_ASSIGN, "expected '=' after multi-assign lvalues"); + expecttok(p, TK_ASSIGN, "expected '=' after multi-assign lvalues"); m.rhs = parseexpr(p); m.list = head; - expect_tok(p, TK_SEMI, "expected ';' after multi-assign"); + expecttok(p, TK_SEMI, "expected ';' after multi-assign"); return m; }; let n: *node = newnode(p.a, N_EXPRSTMT, pf, pl, pc); n.lhs = e; - expect_tok(p, TK_SEMI, "expected ';' after expression statement"); + expecttok(p, TK_SEMI, "expected ';' after expression statement"); return n; }; @@ -2701,7 +2701,7 @@ fn parseuse(p: *parser) *node = { let id: str; expectident(p, &id); n.str = id; - expect_tok(p, TK_SEMI, "expected ';' after use"); + expecttok(p, TK_SEMI, "expected ';' after use"); return n; }; @@ -2714,11 +2714,11 @@ fn parsedef(p: *parser, exported: i32) *node = { let id: str; expectident(p, &id); n.str = id; - expect_tok(p, TK_COLON, "expected ':' in def"); + expecttok(p, TK_COLON, "expected ':' in def"); n.lhs = parsetype(p); - expect_tok(p, TK_ASSIGN, "expected '=' in def"); + expecttok(p, TK_ASSIGN, "expected '=' in def"); n.rhs = parseexpr(p); - expect_tok(p, TK_SEMI, "expected ';' after def"); + expecttok(p, TK_SEMI, "expected ';' after def"); n.exported = exported; return n; }; @@ -2732,13 +2732,13 @@ fn parselet(p: *parser, exported: i32) *node = { let id: str; expectident(p, &id); n.str = id; - if (accept_tok(p, TK_COLON)) { + if (accepttok(p, TK_COLON)) { n.lhs = parsetype(p); }; - if (accept_tok(p, TK_ASSIGN)) { + if (accepttok(p, TK_ASSIGN)) { n.rhs = parseexpr(p); }; - expect_tok(p, TK_SEMI, "expected ';' after let"); + expecttok(p, TK_SEMI, "expected ';' after let"); n.exported = exported; return n; }; @@ -2755,11 +2755,11 @@ fn parseattrs(p: *parser) *node = { let id: str; expectident(p, &id); a.str = id; - expect_tok(p, TK_LPAREN, "expected '(' after attribute name"); + expecttok(p, TK_LPAREN, "expected '(' after attribute name"); let arghead: *node = nil; parsearglist(p, TK_RPAREN, &arghead); a.list = arghead; - expect_tok(p, TK_RPAREN, "expected ')' after attribute args"); + expecttok(p, TK_RPAREN, "expected ')' after attribute args"); if (head == nil) { head = a; tail = a; } else { tail.next = a; tail = a; }; }; @@ -2780,11 +2780,11 @@ fn parseparams(p: *parser) *node = { let id: str; expectident(p, &id); n.str = id; - expect_tok(p, TK_COLON, "expected ':' in parameter"); + expecttok(p, TK_COLON, "expected ':' in parameter"); n.lhs = parsetype(p); if (head == nil) { head = n; tail = n; } else { tail.next = n; tail = n; }; - if (!accept_tok(p, TK_COMMA)) { break; }; + if (!accepttok(p, TK_COMMA)) { break; }; if (p.cur_kind == TK_RPAREN) { break; }; }; return head; @@ -2799,20 +2799,20 @@ fn parsefn(p: *parser, exported: i32, attrs: *node) *node = { let id: str; expectident(p, &id); n.str = id; - expect_tok(p, TK_LPAREN, "expected '(' after fn name"); + expecttok(p, TK_LPAREN, "expected '(' after fn name"); n.list = parseparams(p); - expect_tok(p, TK_RPAREN, "expected ')' after params"); + expecttok(p, TK_RPAREN, "expected ')' after params"); if (p.cur_kind != TK_ASSIGN) { if (p.cur_kind != TK_SEMI) { n.lhs = parsetype(p); }; }; - if (accept_tok(p, TK_ASSIGN)) { + if (accepttok(p, TK_ASSIGN)) { n.body = parseblock(p); - expect_tok(p, TK_SEMI, "expected ';' after fn body"); + expecttok(p, TK_SEMI, "expected ';' after fn body"); } else { // Body-less fn: FFI declaration (`fn name(args) ret;`). - expect_tok(p, TK_SEMI, "expected ';' after fn header"); + expecttok(p, TK_SEMI, "expected ';' after fn header"); }; n.exported = exported; n.attr = attrs; @@ -2828,9 +2828,9 @@ fn parsetypedecl(p: *parser, exported: i32) *node = { let id: str; expectident(p, &id); n.str = id; - expect_tok(p, TK_ASSIGN, "expected '=' in type decl"); + expecttok(p, TK_ASSIGN, "expected '=' in type decl"); n.lhs = parsetype(p); - expect_tok(p, TK_SEMI, "expected ';' after type decl"); + expecttok(p, TK_SEMI, "expected ';' after type decl"); n.exported = exported; return n; }; @@ -3053,7 +3053,7 @@ export fn typesinit(c: *tctx, a: *arena) void = { c.ty_untyped_nil = prim(a, TY_UNTYPED_NIL, "untyped_nil", 0u64, 1u64); }; -export fn type_ptr(a: *arena, sub: *tinfo) *tinfo = { +export fn typeptr(a: *arena, sub: *tinfo) *tinfo = { let t: *tinfo = newtype(a, TY_PTR); t.sub = sub; t.size = 8u64; @@ -3061,7 +3061,7 @@ export fn type_ptr(a: *arena, sub: *tinfo) *tinfo = { return t; }; -export fn type_slice(a: *arena, sub: *tinfo) *tinfo = { +export fn typeslice(a: *arena, sub: *tinfo) *tinfo = { let t: *tinfo = newtype(a, TY_SLICE); t.sub = sub; t.size = 24u64; @@ -3069,7 +3069,7 @@ export fn type_slice(a: *arena, sub: *tinfo) *tinfo = { return t; }; -export fn type_array(a: *arena, sub: *tinfo, n: u64) *tinfo = { +export fn typearray(a: *arena, sub: *tinfo, n: u64) *tinfo = { let t: *tinfo = newtype(a, TY_ARRAY); t.sub = sub; t.alen = n; @@ -3082,7 +3082,7 @@ export fn type_array(a: *arena, sub: *tinfo, n: u64) *tinfo = { return t; }; -export fn type_chan(a: *arena, sub: *tinfo) *tinfo = { +export fn typechan(a: *arena, sub: *tinfo) *tinfo = { let t: *tinfo = newtype(a, TY_CHAN); t.sub = sub; t.size = 8u64; @@ -3090,7 +3090,7 @@ export fn type_chan(a: *arena, sub: *tinfo) *tinfo = { return t; }; -export fn type_named(a: *arena, name: str, under: *tinfo) *tinfo = { +export fn typenamed(a: *arena, name: str, under: *tinfo) *tinfo = { let t: *tinfo = newtype(a, TY_NAMED); t.name = name; t.under = under; @@ -3103,7 +3103,7 @@ export fn type_named(a: *arena, name: str, under: *tinfo) *tinfo = { // ---- predicates ------------------------------------------------------- -export fn type_isint(t: *tinfo) bool = { +export fn typeisint(t: *tinfo) bool = { if (t == nil) { return false; }; let k: i32 = t.kind; if (k == TY_I8) { return true; }; @@ -3120,26 +3120,26 @@ export fn type_isint(t: *tinfo) bool = { if (k == TY_RUNE){ return true; }; if (k == TY_UNTYPED_INT) { return true; }; if (k == TY_UNTYPED_RUNE) { return true; }; - if (k == TY_NAMED) { return type_isint(t.under); }; + if (k == TY_NAMED) { return typeisint(t.under); }; return false; }; -export fn type_isfloat(t: *tinfo) bool = { +export fn typeisfloat(t: *tinfo) bool = { if (t == nil) { return false; }; let k: i32 = t.kind; if (k == TY_F32) { return true; }; if (k == TY_F64) { return true; }; if (k == TY_UNTYPED_FLOAT) { return true; }; - if (k == TY_NAMED) { return type_isfloat(t.under); }; + if (k == TY_NAMED) { return typeisfloat(t.under); }; return false; }; -export fn type_isnum(t: *tinfo) bool = { - if (type_isint(t)) { return true; }; - return type_isfloat(t); +export fn typeisnum(t: *tinfo) bool = { + if (typeisint(t)) { return true; }; + return typeisfloat(t); }; -export fn type_isunsigned(t: *tinfo) bool = { +export fn typeisunsigned(t: *tinfo) bool = { if (t == nil) { return false; }; let k: i32 = t.kind; if (k == TY_U8) { return true; }; @@ -3148,11 +3148,11 @@ export fn type_isunsigned(t: *tinfo) bool = { if (k == TY_U64) { return true; }; if (k == TY_UINT){ return true; }; if (k == TY_UINTPTR) { return true; }; - if (k == TY_NAMED) { return type_isunsigned(t.under); }; + if (k == TY_NAMED) { return typeisunsigned(t.under); }; return false; }; -export fn type_isuntyped(t: *tinfo) bool = { +export fn typeisuntyped(t: *tinfo) bool = { if (t == nil) { return false; }; let k: i32 = t.kind; if (k == TY_UNTYPED_INT) { return true; }; @@ -3164,29 +3164,29 @@ export fn type_isuntyped(t: *tinfo) bool = { return false; }; -// type_eq — structural equality. Named types compare nominally. -export fn type_eq(a: *tinfo, b: *tinfo) bool = { +// typeeq — structural equality. Named types compare nominally. +export fn typeeq(a: *tinfo, b: *tinfo) bool = { if (a == b) { return true; }; if (a == nil) { return false; }; if (b == nil) { return false; }; if (a.kind != b.kind) { return false; }; let k: i32 = a.kind; - if (k == TY_PTR) { return type_eq(a.sub, b.sub); }; - if (k == TY_SLICE) { return type_eq(a.sub, b.sub); }; - if (k == TY_CHAN) { return type_eq(a.sub, b.sub); }; + if (k == TY_PTR) { return typeeq(a.sub, b.sub); }; + if (k == TY_SLICE) { return typeeq(a.sub, b.sub); }; + if (k == TY_CHAN) { return typeeq(a.sub, b.sub); }; if (k == TY_ARRAY) { if (a.alen != b.alen) { return false; }; - return type_eq(a.sub, b.sub); + return typeeq(a.sub, b.sub); }; if (k == TY_FN) { if (a.variadic != b.variadic) { return false; }; - if (!type_eq(a.ret, b.ret)) { return false; }; + if (!typeeq(a.ret, b.ret)) { return false; }; let pa: *tparam = a.params; let pb: *tparam = b.params; for (true) { if (pa == nil) { if (pb == nil) { return true; }; return false; }; if (pb == nil) { return false; }; - if (!type_eq(pa.type_, pb.type_)) { return false; }; + if (!typeeq(pa.type_, pb.type_)) { return false; }; pa = pa.tnext; pb = pb.tnext; }; @@ -3206,7 +3206,7 @@ export fn type_eq(a: *tinfo, b: *tinfo) bool = { if (na[i] != nb[i]) { return false; }; i += 1; }; - if (!type_eq(fa.type_, fb.type_)) { return false; }; + if (!typeeq(fa.type_, fb.type_)) { return false; }; fa = fa.tnext; fb = fb.tnext; }; @@ -3219,7 +3219,7 @@ export fn type_eq(a: *tinfo, b: *tinfo) bool = { for (true) { if (pa == nil) { if (pb == nil) { return true; }; return false; }; if (pb == nil) { return false; }; - if (!type_eq(pa.type_, pb.type_)) { return false; }; + if (!typeeq(pa.type_, pb.type_)) { return false; }; pa = pa.tnext; pb = pb.tnext; }; @@ -3303,7 +3303,7 @@ export fn streq(a: str, b: str) bool = { return true; }; -export fn scope_lookup_local(s: *scope, name: str) *sym = { +export fn scopelookuplocal(s: *scope, name: str) *sym = { if (s == nil) { return nil; }; let h: u64 = hashstr(name); let bi: i32 = (h % (s.nbuckets: u64)): i32; @@ -3316,17 +3316,17 @@ export fn scope_lookup_local(s: *scope, name: str) *sym = { return nil; }; -export fn scope_lookup(s: *scope, name: str) *sym = { +export fn scopelookup(s: *scope, name: str) *sym = { for (s != nil) { - let r: *sym = scope_lookup_local(s, name); + let r: *sym = scopelookuplocal(s, name); if (r != nil) { return r; }; s = s.parent; }; return nil; }; -export fn scope_define(s: *scope, name: str, k: i32, t: *tinfo, decl: *node) *sym = { - if (scope_lookup_local(s, name) != nil) { return nil; }; +export fn scopedefine(s: *scope, name: str, k: i32, t: *tinfo, decl: *node) *sym = { + if (scopelookuplocal(s, name) != nil) { return nil; }; let sy: *sym = amalloc(s.a, 80u64): *sym; sy.name = name; sy.skind = k; @@ -3376,56 +3376,56 @@ type checker = struct { verbose: i32, // when non-zero, log each unresolved name }; -// seed_primitives — install the built-in type names so `i32`, `str`, +// seedprimitives — install the built-in type names so `i32`, `str`, // etc. can be looked up like ordinary symbols. -fn seed_primitives(c: *checker) void = { - scope_define(c.top, "void", SK_TYPE, c.tc.ty_void, nil); - scope_define(c.top, "bool", SK_TYPE, c.tc.ty_bool, nil); - scope_define(c.top, "rune", SK_TYPE, c.tc.ty_rune, nil); - scope_define(c.top, "i8", SK_TYPE, c.tc.ty_i8, nil); - scope_define(c.top, "i16", SK_TYPE, c.tc.ty_i16, nil); - scope_define(c.top, "i32", SK_TYPE, c.tc.ty_i32, nil); - scope_define(c.top, "i64", SK_TYPE, c.tc.ty_i64, nil); - scope_define(c.top, "u8", SK_TYPE, c.tc.ty_u8, nil); - scope_define(c.top, "u16", SK_TYPE, c.tc.ty_u16, nil); - scope_define(c.top, "u32", SK_TYPE, c.tc.ty_u32, nil); - scope_define(c.top, "u64", SK_TYPE, c.tc.ty_u64, nil); - scope_define(c.top, "int", SK_TYPE, c.tc.ty_int, nil); - scope_define(c.top, "uint", SK_TYPE, c.tc.ty_uint, nil); - scope_define(c.top, "uintptr", SK_TYPE, c.tc.ty_uintptr, nil); - scope_define(c.top, "f32", SK_TYPE, c.tc.ty_f32, nil); - scope_define(c.top, "f64", SK_TYPE, c.tc.ty_f64, nil); - scope_define(c.top, "str", SK_TYPE, c.tc.ty_str, nil); +fn seedprimitives(c: *checker) void = { + scopedefine(c.top, "void", SK_TYPE, c.tc.ty_void, nil); + scopedefine(c.top, "bool", SK_TYPE, c.tc.ty_bool, nil); + scopedefine(c.top, "rune", SK_TYPE, c.tc.ty_rune, nil); + scopedefine(c.top, "i8", SK_TYPE, c.tc.ty_i8, nil); + scopedefine(c.top, "i16", SK_TYPE, c.tc.ty_i16, nil); + scopedefine(c.top, "i32", SK_TYPE, c.tc.ty_i32, nil); + scopedefine(c.top, "i64", SK_TYPE, c.tc.ty_i64, nil); + scopedefine(c.top, "u8", SK_TYPE, c.tc.ty_u8, nil); + scopedefine(c.top, "u16", SK_TYPE, c.tc.ty_u16, nil); + scopedefine(c.top, "u32", SK_TYPE, c.tc.ty_u32, nil); + scopedefine(c.top, "u64", SK_TYPE, c.tc.ty_u64, nil); + scopedefine(c.top, "int", SK_TYPE, c.tc.ty_int, nil); + scopedefine(c.top, "uint", SK_TYPE, c.tc.ty_uint, nil); + scopedefine(c.top, "uintptr", SK_TYPE, c.tc.ty_uintptr, nil); + scopedefine(c.top, "f32", SK_TYPE, c.tc.ty_f32, nil); + scopedefine(c.top, "f64", SK_TYPE, c.tc.ty_f64, nil); + scopedefine(c.top, "str", SK_TYPE, c.tc.ty_str, nil); // `nil`, `true`, `false` are keywords — handled at the lex/parser // level, no symbol needed. - // `len`, `alloc`, `free` are pseudo-builtins; scope_define them so + // `len`, `alloc`, `free` are pseudo-builtins; scopedefine them so // their use sites resolve. The actual semantics live in cgen. - scope_define(c.top, "len", SK_FN, nil, nil); - scope_define(c.top, "alloc", SK_FN, nil, nil); - scope_define(c.top, "free", SK_FN, nil, nil); + scopedefine(c.top, "len", SK_FN, nil, nil); + scopedefine(c.top, "alloc", SK_FN, nil, nil); + scopedefine(c.top, "free", SK_FN, nil, nil); }; -// install_decl — install the top-level decl's name into the top scope. +// installdecl — install the top-level decl's name into the top scope. // We don't compute its type yet (that's the resolve pass) — just bind // the name so forward references resolve. -fn install_decl(c: *checker, d: *node) void = { +fn installdecl(c: *checker, d: *node) void = { if (d == nil) { return; }; let k: i32 = d.kind; let nm: str = d.str; - if (k == N_USE) { scope_define(c.top, nm, SK_USE, nil, d); return; }; - if (k == N_DEF) { scope_define(c.top, nm, SK_DEF, nil, d); return; }; - if (k == N_TYPEDECL) { scope_define(c.top, nm, SK_TYPE, nil, d); return; }; - if (k == N_FNDECL) { scope_define(c.top, nm, SK_FN, nil, d); return; }; - if (k == N_LET) { scope_define(c.top, nm, SK_VAR, nil, d); return; }; + if (k == N_USE) { scopedefine(c.top, nm, SK_USE, nil, d); return; }; + if (k == N_DEF) { scopedefine(c.top, nm, SK_DEF, nil, d); return; }; + if (k == N_TYPEDECL) { scopedefine(c.top, nm, SK_TYPE, nil, d); return; }; + if (k == N_FNDECL) { scopedefine(c.top, nm, SK_FN, nil, d); return; }; + if (k == N_LET) { scopedefine(c.top, nm, SK_VAR, nil, d); return; }; }; -// resolve_walk — recursive AST walk that, for every N_IDENT and +// resolvewalk — recursive AST walk that, for every N_IDENT and // N_TNAME seen, looks up the name and bumps the resolved/unresolved // counters. Local lets are installed in the current scope as soon as // their init/type expressions have been walked (forward use of a let // before its declaration would resolve to nothing — same semantics as // the C checker's collect-then-resolve flow within a function). -fn resolve_walk(c: *checker, n: *node) void = { +fn resolvewalk(c: *checker, n: *node) void = { if (n == nil) { return; }; let k: i32 = n.kind; @@ -3435,7 +3435,7 @@ fn resolve_walk(c: *checker, n: *node) void = { if (k == N_IDENT) { let nm: str = n.str; if (nm.len > 0) { - let s: *sym = scope_lookup(c.cur, nm); + let s: *sym = scopelookup(c.cur, nm); if (s == nil) { c.nunresolved += 1; if (c.verbose != 0) { @@ -3450,7 +3450,7 @@ fn resolve_walk(c: *checker, n: *node) void = { if (k == N_TNAME) { let nm: str = n.str; if (nm.len > 0) { - let s: *sym = scope_lookup(c.cur, nm); + let s: *sym = scopelookup(c.cur, nm); if (s == nil) { c.nunresolved += 1; if (c.verbose != 0) { @@ -3465,89 +3465,89 @@ fn resolve_walk(c: *checker, n: *node) void = { // `match (e) { case let v: T => stmt; ... }` — the binding `v` // is declared by the case arm and visible inside its body. if (k == N_MCASE) { - if (n.lhs != nil) { resolve_walk(c, n.lhs); }; + if (n.lhs != nil) { resolvewalk(c, n.lhs); }; let nm: str = n.str; if (nm.len > 0) { - scope_define(c.cur, nm, SK_VAR, nil, n); + scopedefine(c.cur, nm, SK_VAR, nil, n); }; - if (n.body != nil) { resolve_walk(c, n.body); }; + if (n.body != nil) { resolvewalk(c, n.body); }; return; }; if (k == N_DOT) { // Walk only the base; the .field name is a member, not a // free identifier. - if (n.lhs != nil) { resolve_walk(c, n.lhs); }; + if (n.lhs != nil) { resolvewalk(c, n.lhs); }; return; }; if (k == N_FIELD) { - if (n.lhs != nil) { resolve_walk(c, n.lhs); }; + if (n.lhs != nil) { resolvewalk(c, n.lhs); }; return; }; if (k == N_TFIELD) { - if (n.lhs != nil) { resolve_walk(c, n.lhs); }; + if (n.lhs != nil) { resolvewalk(c, n.lhs); }; return; }; // Walk children (mirroring ast.ww's printer descent order). - if (n.attr != nil) { resolve_walk(c, n.attr); }; - if (n.lhs != nil) { resolve_walk(c, n.lhs); }; - if (n.rhs != nil) { resolve_walk(c, n.rhs); }; - if (n.cond != nil) { resolve_walk(c, n.cond); }; - if (n.body != nil) { resolve_walk(c, n.body); }; - if (n.els != nil) { resolve_walk(c, n.els); }; + if (n.attr != nil) { resolvewalk(c, n.attr); }; + if (n.lhs != nil) { resolvewalk(c, n.lhs); }; + if (n.rhs != nil) { resolvewalk(c, n.rhs); }; + if (n.cond != nil) { resolvewalk(c, n.cond); }; + if (n.body != nil) { resolvewalk(c, n.body); }; + if (n.els != nil) { resolvewalk(c, n.els); }; if (n.list != nil) { let m: *node = n.list; for (m != nil) { - resolve_walk(c, m); + resolvewalk(c, m); m = m.next; }; }; // After walking children: a local `let X: T = init;` registers // `X` so subsequent statements can resolve it. Top-level lets - // are installed in install_decl, so this duplicate install at - // the file scope just no-ops (scope_define returns nil on dup). + // are installed in installdecl, so this duplicate install at + // the file scope just no-ops (scopedefine returns nil on dup). if (k == N_LET) { let nm: str = n.str; if (nm.len > 0) { - scope_define(c.cur, nm, SK_VAR, nil, n); + scopedefine(c.cur, nm, SK_VAR, nil, n); }; }; }; // install_param — when entering a fn body, define its params in a // fresh local scope. -fn install_params(c: *checker, params: *node) void = { +fn installparams(c: *checker, params: *node) void = { let p: *node = params; for (p != nil) { if (p.kind == N_PARAM) { let nm: str = p.str; if (nm.len > 0) { - scope_define(c.cur, nm, SK_PARAM, nil, p); + scopedefine(c.cur, nm, SK_PARAM, nil, p); }; }; p = p.next; }; }; -// resolve_fnbody — open a child scope for the fn, install its params, +// resolvefnbody — open a child scope for the fn, install its params, // then walk the body. Local lets installed by walk_stmt (a future // extension); for the current pass we just resolve-walk without // per-statement scopes. -fn resolve_fnbody(c: *checker, fnnode: *node) void = { +fn resolvefnbody(c: *checker, fnnode: *node) void = { let outer: *scope = c.cur; c.cur = newscope(c.a, c.cur); - install_params(c, fnnode.list); + installparams(c, fnnode.list); if (fnnode.body != nil) { - resolve_walk(c, fnnode.body); + resolvewalk(c, fnnode.body); }; c.cur = outer; }; -export fn check_init(c: *checker, a: *arena, tc: *tctx) void = { +export fn checkinit(c: *checker, a: *arena, tc: *tctx) void = { c.a = a; c.tc = tc; c.top = newscope(a, nil); @@ -3556,17 +3556,17 @@ export fn check_init(c: *checker, a: *arena, tc: *tctx) void = { c.nunresolved = 0; c.errs = 0; c.verbose = 0; - seed_primitives(c); + seedprimitives(c); }; -export fn check_file(c: *checker, file: *node) void = { +export fn checkfile(c: *checker, file: *node) void = { if (file == nil) { return; }; if (file.kind != N_FILE) { return; }; // Pass 1: install all top-level names. let d: *node = file.list; for (d != nil) { - install_decl(c, d); + installdecl(c, d); d = d.next; }; @@ -3575,16 +3575,16 @@ export fn check_file(c: *checker, file: *node) void = { for (d != nil) { let k: i32 = d.kind; if (k == N_FNDECL) { - if (d.lhs != nil) { resolve_walk(c, d.lhs); }; // return type - resolve_fnbody(c, d); + if (d.lhs != nil) { resolvewalk(c, d.lhs); }; // return type + resolvefnbody(c, d); } else { if (k == N_DEF) { - if (d.lhs != nil) { resolve_walk(c, d.lhs); }; - if (d.rhs != nil) { resolve_walk(c, d.rhs); }; + if (d.lhs != nil) { resolvewalk(c, d.lhs); }; + if (d.rhs != nil) { resolvewalk(c, d.rhs); }; } else { if (k == N_TYPEDECL) { - if (d.lhs != nil) { resolve_walk(c, d.lhs); }; + if (d.lhs != nil) { resolvewalk(c, d.lhs); }; } else { if (k == N_LET) { - if (d.lhs != nil) { resolve_walk(c, d.lhs); }; - if (d.rhs != nil) { resolve_walk(c, d.rhs); }; + if (d.lhs != nil) { resolvewalk(c, d.lhs); }; + if (d.rhs != nil) { resolvewalk(c, d.rhs); }; };};};}; d = d.next; }; @@ -3625,17 +3625,17 @@ use strconv; // ---- typedef alias registry ----------------------------------------- // // `type error = str;` makes `error` a struct-shape alias. We track -// alias→target so is_str_type / is_slice_type / struct_lookup can +// alias→target so isstrtype / isslicetype / structlookup can // resolve through the chain. Only direct N_TNAME aliases are mapped; -// `type p = struct {...}` is handled by collect_structs. +// `type p = struct {...}` is handled by collectstructs. -type alias_ent = struct { +type aliasent = struct { aname: str, target: *node, // the rhs type expr - aanext: *alias_ent, + aanext: *aliasent, }; -fn collect_aliases(c: *cgen, file: *node) void = { +fn collectaliases(c: *cgen, file: *node) void = { c.aliases = nil; let d: *node = file.list; for (d != nil) { @@ -3643,7 +3643,7 @@ fn collect_aliases(c: *cgen, file: *node) void = { let body: *node = d.lhs; if (body != nil) { if (body.kind != N_TSTRUCT) { - let a: *alias_ent = amalloc(c.a, 32u64): *alias_ent; + let a: *aliasent = amalloc(c.a, 32u64): *aliasent; a.aname = d.str; a.target = body; a.aanext = c.aliases; @@ -3655,8 +3655,8 @@ fn collect_aliases(c: *cgen, file: *node) void = { }; }; -fn alias_lookup(c: *cgen, name: str) *node = { - let a: *alias_ent = c.aliases; +fn aliaslookup(c: *cgen, name: str) *node = { + let a: *aliasent = c.aliases; for (a != nil) { let an: str = a.aname; if (streq(an, name)) { return a.target; }; @@ -3665,16 +3665,16 @@ fn alias_lookup(c: *cgen, name: str) *node = { return nil; }; -// resolve_type — follow typedef alias chains to a "canonical" type +// resolvetype — follow typedef alias chains to a "canonical" type // expr (str/slice/array/struct/...). Stops on cycles via depth limit. -fn resolve_type(c: *cgen, t: *node) *node = { +fn resolvetype(c: *cgen, t: *node) *node = { let cur: *node = t; let depth: i32 = 0; for (depth < 16) { if (cur == nil) { return nil; }; if (cur.kind != N_TNAME) { return cur; }; let nm: str = cur.str; - let next: *node = alias_lookup(c, nm); + let next: *node = aliaslookup(c, nm); if (next == nil) { return cur; }; cur = next; depth += 1; @@ -3685,23 +3685,23 @@ fn resolve_type(c: *cgen, t: *node) *node = { // ---- struct registry ------------------------------------------------ // // Per-file map from struct name → list of fields with computed offsets -// and sizes. Built when cg_file walks N_TYPEDECL with N_TSTRUCT lhs. +// and sizes. Built when cgfile walks N_TYPEDECL with N_TSTRUCT lhs. // N_DOT and N_ASSIGN consult this to resolve `s.field` for struct or // *struct bases. -type field_info = struct { +type fieldinfo = struct { fname: str, foff: i32, fsz: i32, tnode: *node, // the field type expr, for nested struct lookups - finext: *field_info, + finext: *fieldinfo, }; -type struct_info = struct { +type structinfo = struct { sname: str, - fields: *field_info, + fields: *fieldinfo, tot_size: i32, - sinext: *struct_info, + sinext: *structinfo, }; // ---- locals / frame -------------------------------------------------- @@ -3740,10 +3740,10 @@ type cgen = struct { strlit_seq: i32, strlits: *strlit, ffis: *ffi, - defs: *def_ent, + defs: *defent, fnrets: *fnret, - aliases: *alias_ent, - structs: *struct_info, + aliases: *aliasent, + structs: *structinfo, fn_name: str, fn_ret: *node, // declared return type of current fn (or nil) loop_top: i32, @@ -3751,26 +3751,26 @@ type cgen = struct { loop_cont_buf: *str, // stack of cont labels for continue }; -fn cgen_init(c: *cgen, a: *arena) void = { +fn cgeninit(c: *cgen, a: *arena) void = { c.a = a; c.locals = nil; c.frame = 0; c.last_was_return = 0; c.labelseq = 0; // Note: strlit_seq, strlits, ffis are *not* reset here; they - // persist across cgfn calls within one file. cg_file resets them + // persist across cgfn calls within one file. cgfile resets them // at the start of each compilation unit. c.loop_top = 0; c.loop_end_buf = amalloc(a, (LOOP_MAX: u64) * 16u64): *str; c.loop_cont_buf = amalloc(a, (LOOP_MAX: u64) * 16u64): *str; }; -// local_alloc — append a slot for `name` without dedup. Used for +// localalloc — append a slot for `name` without dedup. Used for // match-arm bindings, which C cgen allocates via cgexpr's by-value // `locals` list — so two separate matches each get fresh slots even -// when their bind names collide. scan_locals follows the same rule +// when their bind names collide. scanlocals follows the same rule // for N_MCASE. -fn local_alloc(c: *cgen, name: str, sz: i32, tnode: *node) i32 = { +fn localalloc(c: *cgen, name: str, sz: i32, tnode: *node) i32 = { let asz: i32 = sz; if (asz < 8) { asz = 8; }; if ((asz & 7) != 0) { asz = (asz + 7) & ~7; }; @@ -3785,13 +3785,13 @@ fn local_alloc(c: *cgen, name: str, sz: i32, tnode: *node) i32 = { return off; }; -fn local_add(c: *cgen, name: str, sz: i32, tnode: *node) i32 = { +fn localadd(c: *cgen, name: str, sz: i32, tnode: *node) i32 = { // Name-based slot reuse for N_LETs and params: if `name` is // already declared in this function, return its existing // offset. Mirrors C cgen (cmd/w6c/cgen.c:localoff). Two // disjoint scopes that declare the same name share one slot — // so `escape` in wwdump (three `let cp: pos;` across separate - // branches) reserves one slot, not three. scan_locals does + // branches) reserves one slot, not three. scanlocals does // the matching dedup at prologue time so the SUBQ stays in // sync. // @@ -3810,16 +3810,16 @@ fn local_add(c: *cgen, name: str, sz: i32, tnode: *node) i32 = { }; cur = cur.lnext; }; - return local_alloc(c, name, sz, tnode); + return localalloc(c, name, sz, tnode); }; -// scan_seen_mark — called by scan_locals on every let / match-bind +// scanseenmark — called by scanlocals on every let / match-bind // site. Returns true if `name` is already tracked in c.locals (so // the slot will be shared at emission time — no new frame bump). // Otherwise appends a name-only stub and returns false. Stubs are // thrown away when cgfn resets c.locals before emission. -fn scan_seen_mark(c: *cgen, name: str) bool = { - if (local_find_node(c, name) != nil) { return true; }; +fn scanseenmark(c: *cgen, name: str) bool = { + if (localfindnode(c, name) != nil) { return true; }; let l: *local = amalloc(c.a, 48u64): *local; l.name = name; l.off = 0; @@ -3829,7 +3829,7 @@ fn scan_seen_mark(c: *cgen, name: str) bool = { return false; }; -fn local_find_node(c: *cgen, name: str) *local = { +fn localfindnode(c: *cgen, name: str) *local = { let l: *local = c.locals; for (l != nil) { let ln: str = l.name; @@ -3839,7 +3839,7 @@ fn local_find_node(c: *cgen, name: str) *local = { return nil; }; -fn local_find(c: *cgen, name: str) i32 = { +fn localfind(c: *cgen, name: str) i32 = { let l: *local = c.locals; for (l != nil) { let ln: str = l.name; @@ -3859,34 +3859,34 @@ fn local_find(c: *cgen, name: str) i32 = { // ---- emit helpers --------------------------------------------------- -fn emit_line(s: str) void = { os.write(1, s.ptr, s.len: u64); }; +fn emitline(s: str) void = { os.write(1, s.ptr, s.len: u64); }; -fn emit_int(v: i64) void = { +fn emitint(v: i64) void = { let buf: [32]u8; let n: i32 = strconv.i64toa(buf[0:32], v); os.write(1, buf.ptr, n: u64); }; -fn emit_uint(v: u64) void = { +fn emituint(v: u64) void = { let buf: [32]u8; let n: i32 = strconv.u64toa(buf[0:32], v); os.write(1, buf.ptr, n: u64); }; -// emit_disp_reg — print "disp(reg)" or "(reg)" when disp == 0, the +// emitdispreg — print "disp(reg)" or "(reg)" when disp == 0, the // way Plan 9 6c/6a do. -fn emit_disp_reg(off: i64, reg: str) void = { - if (off != 0i64) { emit_int(off); }; - emit_line("("); - emit_line(reg); - emit_line(")"); +fn emitdispreg(off: i64, reg: str) void = { + if (off != 0i64) { emitint(off); }; + emitline("("); + emitline(reg); + emitline(")"); }; -// emit_off — print an integer offset, suppressing it entirely when 0. -// Use before any emit_line("(BP)...") or emit_line("(SB)...") sequence. +// emitoff — print an integer offset, suppressing it entirely when 0. +// Use before any emitline("(BP)...") or emitline("(SB)...") sequence. // Plan 9 cc convention: "(BP)" not "0(BP)". -fn emit_off(v: i64) void = { - if (v != 0i64) { emit_int(v); }; +fn emitoff(v: i64) void = { + if (v != 0i64) { emitint(v); }; }; // mklabel — fresh label "__". Returns an @@ -3923,18 +3923,18 @@ fn mklabel(c: *cgen, base: str) str = { return r; }; -fn emit_label(s: str) void = { +fn emitlabel(s: str) void = { os.write(1, s.ptr, s.len: u64); - emit_line(":\n"); + emitline(":\n"); }; // ---- string interning ------------------------------------------------ // // streq is provided by sym.ww and reused here. -// intern_strlit — return a stable label for `bytes`. Dedups by content +// internstrlit — return a stable label for `bytes`. Dedups by content // so identical literals share storage. -fn intern_strlit(c: *cgen, bytes: str) str = { +fn internstrlit(c: *cgen, bytes: str) str = { let s: *strlit = c.strlits; for (s != nil) { let bs: str = s.bytes; @@ -3964,9 +3964,9 @@ fn intern_strlit(c: *cgen, bytes: str) str = { return lab; }; -// emit_def_constants — DATA directive per top-level int-literal `def`. +// emitdefconstants — DATA directive per top-level int-literal `def`. // 8 bytes little-endian to match what the C cgen emits. -fn emit_def_constants(c: *cgen, file: *node) void = { +fn emitdefconstants(c: *cgen, file: *node) void = { let d: *node = file.list; for (d != nil) { if (d.kind == N_DEF) { @@ -3981,10 +3981,10 @@ fn emit_def_constants(c: *cgen, file: *node) void = { if (r.kind == N_NIL) { v = 0u64; ok = true; }; }; if (ok) { - emit_line("DATA "); + emitline("DATA "); let nm: str = d.str; os.write(1, nm.ptr, nm.len: u64); - emit_line("(SB),\""); + emitline("(SB),\""); let i: i32 = 0; let n: u64 = v; for (i < 8) { @@ -3992,11 +3992,11 @@ fn emit_def_constants(c: *cgen, file: *node) void = { n = n >> 8u64; // C emit_defs only special-cases " and \; // every other non-printable goes as \xHH. - if (b == 34u8) { emit_line("\\\""); } - else { if (b == 92u8) { emit_line("\\\\"); } + if (b == 34u8) { emitline("\\\""); } + else { if (b == 92u8) { emitline("\\\\"); } else { if (b < 32u8) { - emit_line("\\x"); + emitline("\\x"); let hi: u8 = b >> 4u8; let lo: u8 = b & 15u8; let bb: [2]u8; @@ -4007,7 +4007,7 @@ fn emit_def_constants(c: *cgen, file: *node) void = { os.write(1, bb.ptr, 2u64); } else { if (b >= 127u8) { - emit_line("\\x"); + emitline("\\x"); let hi: u8 = b >> 4u8; let lo: u8 = b & 15u8; let bb: [2]u8; @@ -4025,34 +4025,34 @@ fn emit_def_constants(c: *cgen, file: *node) void = { };}; i += 1; }; - emit_line("\"\n"); + emitline("\"\n"); }; }; d = d.next; }; }; -// emit_data_section — DATA directives for every interned strlit. +// emitdatasection — DATA directives for every interned strlit. // Trailing NUL appended so .ptr can be used as a C string by syscalls. -fn emit_data_section(c: *cgen) void = { +fn emitdatasection(c: *cgen) void = { let s: *strlit = c.strlits; for (s != nil) { - emit_line("DATA "); + emitline("DATA "); let lab: str = s.label; os.write(1, lab.ptr, lab.len: u64); - emit_line("(SB),\""); + emitline("(SB),\""); let bs: str = s.bytes; let i: i32 = 0; for (i < bs.len) { let b: u8 = bs[i]; - if (b == 34u8) { emit_line("\\\""); } // " - else { if (b == 92u8) { emit_line("\\\\"); } // \ - else { if (b == 10u8) { emit_line("\\n"); } - else { if (b == 9u8) { emit_line("\\t"); } - else { if (b == 13u8) { emit_line("\\r"); } + if (b == 34u8) { emitline("\\\""); } // " + else { if (b == 92u8) { emitline("\\\\"); } // \ + else { if (b == 10u8) { emitline("\\n"); } + else { if (b == 9u8) { emitline("\\t"); } + else { if (b == 13u8) { emitline("\\r"); } else { if (b < 32u8) { - emit_line("\\x"); + emitline("\\x"); let hi: u8 = b >> 4u8; let lo: u8 = b & 15u8; let bb: [2]u8; @@ -4063,7 +4063,7 @@ fn emit_data_section(c: *cgen) void = { os.write(1, bb.ptr, 2u64); } else { if (b >= 127u8) { - emit_line("\\x"); + emitline("\\x"); let hi: u8 = b >> 4u8; let lo: u8 = b & 15u8; let bb: [2]u8; @@ -4081,7 +4081,7 @@ fn emit_data_section(c: *cgen) void = { };};};};}; i += 1; }; - emit_line("\\x00\"\n"); + emitline("\\x00\"\n"); s = s.slnext; }; }; @@ -4098,7 +4098,7 @@ type fnret = struct { frnext: *fnret, }; -fn collect_fnrets(c: *cgen, file: *node) void = { +fn collectfnrets(c: *cgen, file: *node) void = { c.fnrets = nil; let d: *node = file.list; for (d != nil) { @@ -4113,7 +4113,7 @@ fn collect_fnrets(c: *cgen, file: *node) void = { }; }; -fn fnret_lookup(c: *cgen, name: str) *node = { +fn fnretlookup(c: *cgen, name: str) *node = { let f: *fnret = c.fnrets; for (f != nil) { let fn_: str = f.fname; @@ -4129,17 +4129,17 @@ fn fnret_lookup(c: *cgen, name: str) *node = { // ident reference loads it via `MOVQ NAME(SB), AX`. We collect them at // file load and consult on N_IDENT lookup. -type def_ent = struct { +type defent = struct { dname: str, - dnext: *def_ent, + dnext: *defent, }; -fn collect_defs(c: *cgen, file: *node) void = { +fn collectdefs(c: *cgen, file: *node) void = { c.defs = nil; let d: *node = file.list; for (d != nil) { if (d.kind == N_DEF) { - let e: *def_ent = amalloc(c.a, 32u64): *def_ent; + let e: *defent = amalloc(c.a, 32u64): *defent; e.dname = d.str; e.dnext = c.defs; c.defs = e; @@ -4148,8 +4148,8 @@ fn collect_defs(c: *cgen, file: *node) void = { }; }; -fn def_lookup(c: *cgen, name: str) bool = { - let e: *def_ent = c.defs; +fn deflookup(c: *cgen, name: str) bool = { + let e: *defent = c.defs; for (e != nil) { let dn: str = e.dname; if (streq(dn, name)) { return true; }; @@ -4160,7 +4160,7 @@ fn def_lookup(c: *cgen, name: str) bool = { // ---- FFI map --------------------------------------------------------- -fn ffi_collect(c: *cgen, file: *node) void = { +fn fficollect(c: *cgen, file: *node) void = { c.ffis = nil; if (file == nil) { return; }; let d: *node = file.list; @@ -4171,12 +4171,12 @@ fn ffi_collect(c: *cgen, file: *node) void = { if (a.kind == N_ATTR) { let aname: str = a.str; if (streq(aname, "symbol")) { - let sym_node: *node = a.list; - if (sym_node != nil) { - if (sym_node.kind == N_STRLIT) { + let symnode: *node = a.list; + if (symnode != nil) { + if (symnode.kind == N_STRLIT) { let f: *ffi = amalloc(c.a, 48u64): *ffi; f.ident = d.str; - f.symbol = sym_node.str; + f.symbol = symnode.str; f.fnext = c.ffis; c.ffis = f; }; @@ -4190,7 +4190,7 @@ fn ffi_collect(c: *cgen, file: *node) void = { }; }; -fn ffi_resolve(c: *cgen, ident: str) str = { +fn ffiresolve(c: *cgen, ident: str) str = { let f: *ffi = c.ffis; for (f != nil) { let id: str = f.ident; @@ -4202,7 +4202,7 @@ fn ffi_resolve(c: *cgen, ident: str) str = { // ---- ABI argreg helpers --------------------------------------------- -fn argreg_name(i: i32) str = { +fn argregname(i: i32) str = { if (i == 0) { return "DI"; }; if (i == 1) { return "SI"; }; if (i == 2) { return "DX"; }; @@ -4214,14 +4214,14 @@ fn argreg_name(i: i32) str = { // ---- expression cgen ------------------------------------------------- -// push_args_rev — recursively walks the arg list, evaluates rightmost +// pushargsrev — recursively walks the arg list, evaluates rightmost // first, and pushes. str args take two slots (ptr in AX, len in BX); // the order on the stack so a left-to-right pop into argregs lands // (ptr, len) correctly is: PUSHQ BX (top), PUSHQ AX (above) — the // pop sequence then yields AX, then BX. -fn push_args_rev(c: *cgen, arg: *node) i32 = { +fn pushargsrev(c: *cgen, arg: *node) i32 = { if (arg == nil) { return 0; }; - let rest: i32 = push_args_rev(c, arg.next); + let rest: i32 = pushargsrev(c, arg.next); // N_SLICE expression as arg: `buf[lo:hi]` builds a slice header // on the stack matching C cgen's sequence — push base, push hi, // compute lo, pop into BX/CX, derive len/ptr, push (cap, len, ptr). @@ -4229,77 +4229,77 @@ fn push_args_rev(c: *cgen, arg: *node) i32 = { let base: *node = arg.lhs; let lo: *node = arg.rhs; let hi: *node = arg.cond; - let base_local: *local = nil; + let baselocal: *local = nil; if (base != nil) { if (base.kind == N_IDENT) { let bn: str = base.str; - base_local = local_find_node(c, bn); + baselocal = localfindnode(c, bn); }; }; // base address → push - if (base_local != nil) { - let tn: *node = base_local.tnode; + if (baselocal != nil) { + let tn: *node = baselocal.tnode; if (tn != nil) { if (tn.kind == N_TARRAY) { - emit_line("\tLEAQ\t"); - emit_off(base_local.off: i64); - emit_line("(BP), AX\n"); + emitline("\tLEAQ\t"); + emitoff(baselocal.off: i64); + emitline("(BP), AX\n"); } else { - emit_line("\tMOVQ\t"); - emit_off(base_local.off: i64); - emit_line("(BP), AX\n"); + emitline("\tMOVQ\t"); + emitoff(baselocal.off: i64); + emitline("(BP), AX\n"); }; } else { - emit_line("\tMOVQ\t"); - emit_off(base_local.off: i64); - emit_line("(BP), AX\n"); + emitline("\tMOVQ\t"); + emitoff(baselocal.off: i64); + emitline("(BP), AX\n"); }; } else { cgexpr(c, base); }; - emit_line("\tPUSHQ\tAX\n"); + emitline("\tPUSHQ\tAX\n"); // hi (default base length) → push if (hi != nil) { cgexpr(c, hi); - } else { if (base_local != nil) { - let tn: *node = base_local.tnode; + } else { if (baselocal != nil) { + let tn: *node = baselocal.tnode; if (tn != nil) { if (tn.kind == N_TARRAY) { - let len_n: *node = tn.rhs; - if (len_n != nil) { - if (len_n.kind == N_INTLIT) { - emit_line("\tMOVQ\t$"); - emit_uint(len_n.uval); - emit_line(", AX\n"); + let lenn: *node = tn.rhs; + if (lenn != nil) { + if (lenn.kind == N_INTLIT) { + emitline("\tMOVQ\t$"); + emituint(lenn.uval); + emitline(", AX\n"); }; }; } else { if (tn.kind == N_TSLICE) { - emit_line("\tMOVQ\t"); - emit_off((base_local.off + 8): i64); - emit_line("(BP), AX\n"); + emitline("\tMOVQ\t"); + emitoff((baselocal.off + 8): i64); + emitline("(BP), AX\n"); } else { if (tn.kind == N_TNAME) { if (streq(tn.str, "str")) { - emit_line("\tMOVQ\t"); - emit_off((base_local.off + 8): i64); - emit_line("(BP), AX\n"); + emitline("\tMOVQ\t"); + emitoff((baselocal.off + 8): i64); + emitline("(BP), AX\n"); }; };};}; }; } else { - emit_line("\tMOVQ\t$0, AX\n"); + emitline("\tMOVQ\t$0, AX\n"); };}; - emit_line("\tPUSHQ\tAX\n"); + emitline("\tPUSHQ\tAX\n"); // lo (default 0) → AX if (lo != nil) { cgexpr(c, lo); } - else { emit_line("\tMOVQ\t$0, AX\n"); }; - emit_line("\tPOPQ\tBX\n"); // hi - emit_line("\tPOPQ\tCX\n"); // base - emit_line("\tMOVQ\tBX, DX\n"); // DX = hi - emit_line("\tSUBQ\tAX, DX\n"); // DX = hi - lo = len - emit_line("\tADDQ\tAX, CX\n"); // CX = base + lo = ptr - emit_line("\tPUSHQ\tDX\n"); // cap - emit_line("\tPUSHQ\tDX\n"); // len - emit_line("\tPUSHQ\tCX\n"); // ptr (top) + else { emitline("\tMOVQ\t$0, AX\n"); }; + emitline("\tPOPQ\tBX\n"); // hi + emitline("\tPOPQ\tCX\n"); // base + emitline("\tMOVQ\tBX, DX\n"); // DX = hi + emitline("\tSUBQ\tAX, DX\n"); // DX = hi - lo = len + emitline("\tADDQ\tAX, CX\n"); // CX = base + lo = ptr + emitline("\tPUSHQ\tDX\n"); // cap + emitline("\tPUSHQ\tDX\n"); // len + emitline("\tPUSHQ\tCX\n"); // ptr (top) return rest + 3; }; // Slice/tagged ident args: emit per-register MOVQ+PUSHQ pairs in @@ -4307,65 +4307,65 @@ fn push_args_rev(c: *cgen, arg: *node) i32 = { // into argregs lands the canonical (ptr/tag, len/v0, cap/v1). if (arg.kind == N_IDENT) { let nm: str = arg.str; - let lc: *local = local_find_node(c, nm); + let lc: *local = localfindnode(c, nm); if (lc != nil) { let off: i32 = lc.off; - if (is_slice_type(c, lc.tnode) || is_tagged_type(lc.tnode)) { - emit_line("\tMOVQ\t"); - emit_off((off + 16): i64); - emit_line("(BP), AX\n"); - emit_line("\tPUSHQ\tAX\n"); - emit_line("\tMOVQ\t"); - emit_off((off + 8): i64); - emit_line("(BP), AX\n"); - emit_line("\tPUSHQ\tAX\n"); - emit_line("\tMOVQ\t"); - emit_off(off: i64); - emit_line("(BP), AX\n"); - emit_line("\tPUSHQ\tAX\n"); + if (isslicetype(c, lc.tnode) || istaggedtype(lc.tnode)) { + emitline("\tMOVQ\t"); + emitoff((off + 16): i64); + emitline("(BP), AX\n"); + emitline("\tPUSHQ\tAX\n"); + emitline("\tMOVQ\t"); + emitoff((off + 8): i64); + emitline("(BP), AX\n"); + emitline("\tPUSHQ\tAX\n"); + emitline("\tMOVQ\t"); + emitoff(off: i64); + emitline("(BP), AX\n"); + emitline("\tPUSHQ\tAX\n"); return rest + 3; }; }; }; cgexpr(c, arg); - if (node_isslice(c, arg)) { - emit_line("\tPUSHQ\tCX\n"); - emit_line("\tPUSHQ\tBX\n"); - emit_line("\tPUSHQ\tAX\n"); + if (nodeisslice(c, arg)) { + emitline("\tPUSHQ\tCX\n"); + emitline("\tPUSHQ\tBX\n"); + emitline("\tPUSHQ\tAX\n"); return rest + 3; }; - if (node_isstr(c, arg)) { - emit_line("\tPUSHQ\tBX\n"); - emit_line("\tPUSHQ\tAX\n"); + if (nodeisstr(c, arg)) { + emitline("\tPUSHQ\tBX\n"); + emitline("\tPUSHQ\tAX\n"); return rest + 2; }; - emit_line("\tPUSHQ\tAX\n"); + emitline("\tPUSHQ\tAX\n"); return rest + 1; }; -fn node_isslice(c: *cgen, n: *node) bool = { +fn nodeisslice(c: *cgen, n: *node) bool = { if (n == nil) { return false; }; let k: i32 = n.kind; if (k == N_IDENT) { let nm: str = n.str; - let lc: *local = local_find_node(c, nm); - if (lc != nil) { return is_slice_type(c, lc.tnode); }; + let lc: *local = localfindnode(c, nm); + if (lc != nil) { return isslicetype(c, lc.tnode); }; return false; }; if (k == N_SLICE) { return true; }; return false; }; -// node_isstr — best-effort surface check: does this expression +// nodeisstr — best-effort surface check: does this expression // evaluate to a str value? Used to drive the call-arg push convention // (str args take two slots: ptr + len). -fn node_isstr(c: *cgen, n: *node) bool = { +fn nodeisstr(c: *cgen, n: *node) bool = { if (n == nil) { return false; }; let k: i32 = n.kind; if (k == N_STRLIT) { return true; }; if (k == N_IDENT) { let nm: str = n.str; - let lc: *local = local_find_node(c, nm); + let lc: *local = localfindnode(c, nm); if (lc != nil) { let tn: *node = lc.tnode; if (tn != nil) { @@ -4382,8 +4382,8 @@ fn node_isstr(c: *cgen, n: *node) bool = { if (callee != nil) { if (callee.kind == N_IDENT) { let cnm: str = callee.str; - let rt: *node = fnret_lookup(c, cnm); - return is_str_type(c, rt); + let rt: *node = fnretlookup(c, cnm); + return isstrtype(c, rt); }; }; return false; @@ -4399,7 +4399,7 @@ fn node_isstr(c: *cgen, n: *node) bool = { let sname: str; sname.ptr = nil; sname.len = 0; if (base.kind == N_IDENT) { - let lc: *local = local_find_node(c, base.str); + let lc: *local = localfindnode(c, base.str); if (lc != nil) { let tn: *node = lc.tnode; let lkind: i32 = -1; @@ -4413,23 +4413,23 @@ fn node_isstr(c: *cgen, n: *node) bool = { }; }; }; - // Chained dot (`p.foo.bar`): use dot_inner_struct_ptr + // Chained dot (`p.foo.bar`): use dotinnerstructptr // to resolve the inner chain to the *struct it lands // on, then look up `fld` in that struct. if (base.kind == N_DOT) { - let inner_t: *node = dot_inner_struct_ptr(c, base); - if (inner_t != nil) { - if (inner_t.kind == N_TNAME) { sname = inner_t.str; }; + let innert: *node = dotinnerstructptr(c, base); + if (innert != nil) { + if (innert.kind == N_TNAME) { sname = innert.str; }; }; }; if (sname.len > 0) { - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fld)) { - return is_str_type(c, fi.tnode); + return isstrtype(c, fi.tnode); }; fi = fi.finext; }; @@ -4439,13 +4439,13 @@ fn node_isstr(c: *cgen, n: *node) bool = { return false; }; if (k == N_CAST) { - return is_str_type(c, n.rhs); + return isstrtype(c, n.rhs); }; return false; }; -// type_name_isunsigned — true for u8/u16/u32/u64/uint/uintptr. -fn type_name_isunsigned(nm: str) bool = { +// typenameisunsigned — true for u8/u16/u32/u64/uint/uintptr. +fn typenameisunsigned(nm: str) bool = { if (streq(nm, "u8")) { return true; }; if (streq(nm, "u16")) { return true; }; if (streq(nm, "u32")) { return true; }; @@ -4455,21 +4455,21 @@ fn type_name_isunsigned(nm: str) bool = { return false; }; -// type_node_isunsigned — recurse through TNAME / TPTR / TSLICE etc. -fn type_node_isunsigned(t: *node) bool = { +// typenodeisunsigned — recurse through TNAME / TPTR / TSLICE etc. +fn typenodeisunsigned(t: *node) bool = { if (t == nil) { return false; }; - if (t.kind == N_TNAME) { return type_name_isunsigned(t.str); }; + if (t.kind == N_TNAME) { return typenameisunsigned(t.str); }; return false; }; -// type_is_8byte_primitive — does this type take exactly one 8-byte +// typeis8byteprimitive — does this type take exactly one 8-byte // slot (pointer / fn-ptr / 64-bit int / chan / scalar primitive // padded up to 8) rather than a wider aggregate? Used by N_LET // zero-init to mirror C cgen's "only zero if sz == 8 at the type // level" rule. Strings (16), slices (24), tagged unions (>=16), // tuples (16), structs (varies), arrays — all fall through to // false here even when their *slot* rounds up to 8. -fn type_is_8byte_primitive(c: *cgen, t: *node) bool = { +fn typeis8byteprimitive(c: *cgen, t: *node) bool = { if (t == nil) { return false; }; let k: i32 = t.kind; if (k == N_TPTR) { return true; }; @@ -4483,17 +4483,17 @@ fn type_is_8byte_primitive(c: *cgen, t: *node) bool = { let nm: str = t.str; if (streq(nm, "str")) { return false; }; // Struct alias: not a primitive even if the slot is 8B. - if (struct_lookup(c, nm) != nil) { return false; }; + if (structlookup(c, nm) != nil) { return false; }; // Primitive (i8/u8/.../i64/u64/bool/rune/f32/f64/int/...). // All of these get slot-padded to 8 and zero-init in C. - if (prim_size(nm) > 0) { return true; }; + if (primsize(nm) > 0) { return true; }; return false; }; return false; }; -// type_name_issigned — true for i8/i16/i32/i64/int/rune. -fn type_name_issigned(nm: str) bool = { +// typenameissigned — true for i8/i16/i32/i64/int/rune. +fn typenameissigned(nm: str) bool = { if (streq(nm, "i8")) { return true; }; if (streq(nm, "i16")) { return true; }; if (streq(nm, "i32")) { return true; }; @@ -4503,11 +4503,11 @@ fn type_name_issigned(nm: str) bool = { return false; }; -// field_load_op — pick the load instruction for a non-str struct +// fieldloadop — pick the load instruction for a non-str struct // field by its declared size + signedness. Mirrors the C cgen op // dispatch (MOVZBQ for u8/bool/i8, MOVSXD for i32, MOVL for u32, MOVQ // for 8-byte). f might be nil for fields outside our struct registry. -fn field_load_op(f: *field_info) str = { +fn fieldloadop(f: *fieldinfo) str = { if (f == nil) { return "MOVQ"; }; let sz: i32 = f.fsz; if (sz == 1) { return "MOVZBQ"; }; @@ -4515,7 +4515,7 @@ fn field_load_op(f: *field_info) str = { let t: *node = f.tnode; if (t != nil) { if (t.kind == N_TNAME) { - if (type_name_issigned(t.str)) { return "MOVSXD"; }; + if (typenameissigned(t.str)) { return "MOVSXD"; }; }; }; return "MOVL"; @@ -4523,9 +4523,9 @@ fn field_load_op(f: *field_info) str = { return "MOVQ"; }; -// field_store_op — pick the store instruction for a non-str struct +// fieldstoreop — pick the store instruction for a non-str struct // field by its declared size. MOVB for 1, MOVL for 4, MOVQ for 8. -fn field_store_op(f: *field_info) str = { +fn fieldstoreop(f: *fieldinfo) str = { if (f == nil) { return "MOVQ"; }; let sz: i32 = f.fsz; if (sz == 1) { return "MOVB"; }; @@ -4533,11 +4533,11 @@ fn field_store_op(f: *field_info) str = { return "MOVQ"; }; -// index_base_esz — element size for `arr[i]` where the base is a +// indexbaseesz — element size for `arr[i]` where the base is a // chained-dot pseudo-field `s.ptr` (s being str/*str/slice/*slice). // For str the element is one byte; for `[]T` / `*[]T` we drill into // the slice element type. -fn index_base_esz(c: *cgen, base: *node) i32 = { +fn indexbaseesz(c: *cgen, base: *node) i32 = { if (base == nil) { return 8; }; if (base.kind != N_DOT) { return 8; }; let fld: str = base.str; @@ -4545,20 +4545,20 @@ fn index_base_esz(c: *cgen, base: *node) i32 = { if (inner == nil) { return 8; }; if (inner.kind != N_IDENT) { return 8; }; let nm: str = inner.str; - let lc: *local = local_find_node(c, nm); + let lc: *local = localfindnode(c, nm); if (lc == nil) { return 8; }; let tn: *node = lc.tnode; if (tn == nil) { return 8; }; // `.ptr` pseudo-field on str/slice → element of the str/slice. if (streq(fld, "ptr")) { - let inner_t: *node = tn; - if (tn.kind == N_TPTR) { inner_t = tn.lhs; }; - if (inner_t == nil) { return 8; }; - if (inner_t.kind == N_TNAME) { - if (streq(inner_t.str, "str")) { return 1; }; + let innert: *node = tn; + if (tn.kind == N_TPTR) { innert = tn.lhs; }; + if (innert == nil) { return 8; }; + if (innert.kind == N_TNAME) { + if (streq(innert.str, "str")) { return 1; }; }; - if (inner_t.kind == N_TSLICE) { return elem_size_of(inner_t); }; + if (innert.kind == N_TSLICE) { return elemsizeof(innert); }; return 8; }; @@ -4574,9 +4574,9 @@ fn index_base_esz(c: *cgen, base: *node) i32 = { }; }; if (sname.len == 0) { return 8; }; - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si == nil) { return 8; }; - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fld)) { @@ -4587,13 +4587,13 @@ fn index_base_esz(c: *cgen, base: *node) i32 = { if (elem != nil) { if (elem.kind == N_TNAME) { if (streq(elem.str, "str")) { return 16; }; - let ps: i32 = prim_size(elem.str); + let ps: i32 = primsize(elem.str); if (ps > 0) { return ps; }; }; }; return 8; }; - if (ft.kind == N_TSLICE) { return elem_size_of(ft); }; + if (ft.kind == N_TSLICE) { return elemsizeof(ft); }; // str-typed field: indexing yields one byte // (`n.s[i]` where .s is str — matches C cgen's // MOVZBQ for byte indexing). @@ -4607,7 +4607,7 @@ fn index_base_esz(c: *cgen, base: *node) i32 = { return 8; }; -// dot_inner_struct_ptr — for an N_DOT whose lhs is a chain of dots +// dotinnerstructptr — for an N_DOT whose lhs is a chain of dots // or an N_IDENT, walk the chain and return the N_TNAME tnode of the // struct that the chain dereferences to (i.e., for `r.sym` where // .sym is *lsym, return N_TNAME("lsym")). Returns nil if the chain @@ -4615,7 +4615,7 @@ fn index_base_esz(c: *cgen, base: *node) i32 = { // // Used by the chained-DOT cgen path so `r.sym.val` knows the outer // is a field of `lsym`. -fn dot_inner_struct_ptr(c: *cgen, n: *node) *node = { +fn dotinnerstructptr(c: *cgen, n: *node) *node = { if (n == nil) { return nil; }; if (n.kind != N_DOT) { return nil; }; let base: *node = n.lhs; @@ -4623,25 +4623,25 @@ fn dot_inner_struct_ptr(c: *cgen, n: *node) *node = { if (base == nil) { return nil; }; // Resolve base's struct tnode. - let base_t: *node = nil; + let baset: *node = nil; if (base.kind == N_IDENT) { - let lc: *local = local_find_node(c, base.str); + let lc: *local = localfindnode(c, base.str); if (lc == nil) { return nil; }; let tn: *node = lc.tnode; if (tn == nil) { return nil; }; // base could be either struct-by-value (N_TNAME) or *struct (N_TPTR). - if (tn.kind == N_TNAME) { base_t = tn; }; - if (tn.kind == N_TPTR) { base_t = tn.lhs; }; + if (tn.kind == N_TNAME) { baset = tn; }; + if (tn.kind == N_TPTR) { baset = tn.lhs; }; } else { if (base.kind == N_DOT) { - base_t = dot_inner_struct_ptr(c, base); + baset = dotinnerstructptr(c, base); };}; - if (base_t == nil) { return nil; }; - if (base_t.kind != N_TNAME) { return nil; }; + if (baset == nil) { return nil; }; + if (baset.kind != N_TNAME) { return nil; }; // Look up the struct, find the field, return the field's *struct. - let si: *struct_info = struct_lookup(c, base_t.str); + let si: *structinfo = structlookup(c, baset.str); if (si == nil) { return nil; }; - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { if (streq(fi.fname, fld)) { let ft: *node = fi.tnode; @@ -4657,10 +4657,10 @@ fn dot_inner_struct_ptr(c: *cgen, n: *node) *node = { return nil; }; -// elem_size_of — given the type node of an indexable (`*T`, `[]T`, +// elemsizeof — given the type node of an indexable (`*T`, `[]T`, // `[N]T`, `str`), return the byte size of one element (1 for u8/i8/ // bool/str-byte, 8 otherwise — same shape as C cgen's esz fallback). -fn elem_size_of(t: *node) i32 = { +fn elemsizeof(t: *node) i32 = { if (t == nil) { return 1; }; let k: i32 = t.kind; let elem: *node = nil; @@ -4671,22 +4671,22 @@ fn elem_size_of(t: *node) i32 = { let nm: str = t.str; if (streq(nm, "str")) { return 1; }; // Indexing a primitive name (rare): element size = the prim. - let ps: i32 = prim_size(nm); + let ps: i32 = primsize(nm); if (ps > 0) { return ps; }; return 1; }; if (elem == nil) { return 1; }; if (elem.kind == N_TNAME) { let nm: str = elem.str; - // str element is 16B (ptr+len). prim_size returns 0 for it. + // str element is 16B (ptr+len). primsize returns 0 for it. if (streq(nm, "str")) { return 16; }; - let ps: i32 = prim_size(nm); + let ps: i32 = primsize(nm); if (ps > 0) { return ps; }; }; return 8; }; -// node_isunsigned — best-effort cgen-time inference from the AST. We +// nodeisunsigned — best-effort cgen-time inference from the AST. We // don't have a typed AST yet, so we walk surface nodes: // N_INTLIT — never marked unsigned (no tsuffix plumbing yet) // N_IDENT — look up the local's declared type @@ -4696,13 +4696,13 @@ fn elem_size_of(t: *node) i32 = { // // Conservative: if we can't tell, return false (signed). The cost of // being wrong here is byte-different asm vs C, not bad runtime. -fn node_isunsigned(c: *cgen, n: *node) bool = { +fn nodeisunsigned(c: *cgen, n: *node) bool = { if (n == nil) { return false; }; let k: i32 = n.kind; if (k == N_IDENT) { let nm: str = n.str; - let lc: *local = local_find_node(c, nm); - if (lc != nil) { return type_node_isunsigned(lc.tnode); }; + let lc: *local = localfindnode(c, nm); + if (lc != nil) { return typenodeisunsigned(lc.tnode); }; return false; }; if (k == N_DOT) { @@ -4711,7 +4711,7 @@ fn node_isunsigned(c: *cgen, n: *node) bool = { if (base != nil) { if (base.kind == N_IDENT) { let bn: str = base.str; - let lc: *local = local_find_node(c, bn); + let lc: *local = localfindnode(c, bn); if (lc != nil) { let tn: *node = lc.tnode; let lkind: i32 = -1; @@ -4726,13 +4726,13 @@ fn node_isunsigned(c: *cgen, n: *node) bool = { }; if (lkind == N_TNAME) { sname = tn.str; }; if (sname.len > 0) { - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fld)) { - return type_node_isunsigned(fi.tnode); + return typenodeisunsigned(fi.tnode); }; fi = fi.finext; }; @@ -4743,12 +4743,12 @@ fn node_isunsigned(c: *cgen, n: *node) bool = { }; return false; }; - if (k == N_CAST) { return type_node_isunsigned(n.rhs); }; + if (k == N_CAST) { return typenodeisunsigned(n.rhs); }; if (k == N_BIN) { - if (node_isunsigned(c, n.lhs)) { return true; }; - return node_isunsigned(c, n.rhs); + if (nodeisunsigned(c, n.lhs)) { return true; }; + return nodeisunsigned(c, n.rhs); }; - if (k == N_UN) { return node_isunsigned(c, n.lhs); }; + if (k == N_UN) { return nodeisunsigned(c, n.lhs); }; // N_INDEX: `p[i]` is unsigned iff p's element type is unsigned. // Walks the base local's declared type and pulls the element // out — *u8 → u8, [N]u32 → u32, []u64 → u64. Without this the @@ -4758,7 +4758,7 @@ fn node_isunsigned(c: *cgen, n: *node) bool = { let base: *node = n.lhs; if (base != nil) { if (base.kind == N_IDENT) { - let lc: *local = local_find_node(c, base.str); + let lc: *local = localfindnode(c, base.str); if (lc != nil) { let tn: *node = lc.tnode; if (tn != nil) { @@ -4767,7 +4767,7 @@ fn node_isunsigned(c: *cgen, n: *node) bool = { if (tn.kind == N_TARRAY) { elem = tn.lhs; }; if (tn.kind == N_TSLICE) { elem = tn.lhs; }; if (elem != nil) { - return type_node_isunsigned(elem); + return typenodeisunsigned(elem); }; }; }; @@ -4787,86 +4787,86 @@ fn cgexpr(c: *cgen, n: *node) void = { // `$%lld` so 64-bit constants with bit 63 set show up as // negative — e.g. FNV-1a's offset basis prints as // $-3750763034362895579, not $14695981039346656037. - emit_line("\tMOVQ\t$"); - emit_int(n.uval: i64); - emit_line(", AX\n"); + emitline("\tMOVQ\t$"); + emitint(n.uval: i64); + emitline(", AX\n"); return; }; if (k == N_RUNELIT) { - emit_line("\tMOVQ\t$"); - emit_int(n.uval: i64); - emit_line(", AX\n"); + emitline("\tMOVQ\t$"); + emitint(n.uval: i64); + emitline(", AX\n"); return; }; if (k == N_STRLIT) { // Result is the (ptr, len) pair: ptr in AX, len in BX. Call // sites that expect a str arg pick these up directly. let nstr: str = n.str; - let lab: str = intern_strlit(c, nstr); - emit_line("\tLEAQ\t"); + let lab: str = internstrlit(c, nstr); + emitline("\tLEAQ\t"); os.write(1, lab.ptr, lab.len: u64); - emit_line("(SB), AX\n"); - emit_line("\tMOVQ\t$"); - emit_int(nstr.len: i64); - emit_line(", BX\n"); + emitline("(SB), AX\n"); + emitline("\tMOVQ\t$"); + emitint(nstr.len: i64); + emitline(", BX\n"); return; }; if (k == N_TRUE) { - emit_line("\tMOVQ\t$1, AX\n"); + emitline("\tMOVQ\t$1, AX\n"); return; }; if (k == N_FALSE) { - emit_line("\tMOVQ\t$0, AX\n"); + emitline("\tMOVQ\t$0, AX\n"); return; }; if (k == N_NIL) { - emit_line("\tMOVQ\t$0, AX\n"); + emitline("\tMOVQ\t$0, AX\n"); return; }; if (k == N_IDENT) { let nm: str = n.str; - let lc: *local = local_find_node(c, nm); + let lc: *local = localfindnode(c, nm); if (lc != nil) { let off: i32 = lc.off; - emit_line("\tMOVQ\t"); - emit_off(off: i64); - emit_line("(BP), AX\n"); + emitline("\tMOVQ\t"); + emitoff(off: i64); + emitline("(BP), AX\n"); // str local: also load the len half into BX. - if (is_str_type(c, lc.tnode)) { - emit_line("\tMOVQ\t"); - emit_off((off + 8): i64); - emit_line("(BP), BX\n"); + if (isstrtype(c, lc.tnode)) { + emitline("\tMOVQ\t"); + emitoff((off + 8): i64); + emitline("(BP), BX\n"); }; // slice local: load (ptr, len, cap) into (AX, BX, CX). - if (is_slice_type(c, lc.tnode)) { - emit_line("\tMOVQ\t"); - emit_off((off + 8): i64); - emit_line("(BP), BX\n"); - emit_line("\tMOVQ\t"); - emit_off((off + 16): i64); - emit_line("(BP), CX\n"); + if (isslicetype(c, lc.tnode)) { + emitline("\tMOVQ\t"); + emitoff((off + 8): i64); + emitline("(BP), BX\n"); + emitline("\tMOVQ\t"); + emitoff((off + 16): i64); + emitline("(BP), CX\n"); }; return; }; // Top-level `def` constant — load from its DATA symbol. - if (def_lookup(c, nm)) { - emit_line("\tMOVQ\t"); + if (deflookup(c, nm)) { + emitline("\tMOVQ\t"); os.write(1, nm.ptr, nm.len: u64); - emit_line("(SB), AX\n"); + emitline("(SB), AX\n"); return; }; // Fn-name used as a value (e.g. `let f = some_fn;` or // `... = some_fn;`). LEAQ the symbol address into AX — - // resolved through ffi_resolve so a body-less FFI binding + // resolved through ffiresolve so a body-less FFI binding // emits the C symbol it was declared with via @symbol(), // not the ww-side ident. - let rt: *node = fnret_lookup(c, nm); + let rt: *node = fnretlookup(c, nm); if (rt != nil) { - let resolved: str = ffi_resolve(c, nm); - emit_line("\tLEAQ\t"); + let resolved: str = ffiresolve(c, nm); + emitline("\tLEAQ\t"); os.write(1, resolved.ptr, resolved.len: u64); - emit_line("(SB), AX\n"); + emitline("(SB), AX\n"); return; }; return; @@ -4879,61 +4879,61 @@ fn cgexpr(c: *cgen, n: *node) void = { let base: *node = n.lhs; let idx: *node = n.rhs; let esz: i32 = 8; - let base_local: *local = nil; + let baselocal: *local = nil; if (base != nil) { if (base.kind == N_IDENT) { let bn: str = base.str; - base_local = local_find_node(c, bn); - if (base_local != nil) { esz = elem_size_of(base_local.tnode); }; + baselocal = localfindnode(c, bn); + if (baselocal != nil) { esz = elemsizeof(baselocal.tnode); }; } else { if (base.kind == N_DOT) { - esz = index_base_esz(c, base); + esz = indexbaseesz(c, base); };}; }; cgexpr(c, idx); if (esz > 1) { - emit_line("\tMOVQ\t$"); - emit_int(esz: i64); - emit_line(", CX\n"); - emit_line("\tIMULQ\tCX, AX\n"); + emitline("\tMOVQ\t$"); + emitint(esz: i64); + emitline(", CX\n"); + emitline("\tIMULQ\tCX, AX\n"); }; - if (base_local != nil) { - let tn: *node = base_local.tnode; - let is_array: bool = false; - if (tn != nil) { if (tn.kind == N_TARRAY) { is_array = true; }; }; - if (is_array) { - emit_line("\tLEAQ\t"); - emit_off(base_local.off: i64); - emit_line("(BP), BX\n"); + if (baselocal != nil) { + let tn: *node = baselocal.tnode; + let isarray: bool = false; + if (tn != nil) { if (tn.kind == N_TARRAY) { isarray = true; }; }; + if (isarray) { + emitline("\tLEAQ\t"); + emitoff(baselocal.off: i64); + emitline("(BP), BX\n"); } else { - emit_line("\tMOVQ\t"); - emit_off(base_local.off: i64); - emit_line("(BP), BX\n"); + emitline("\tMOVQ\t"); + emitoff(baselocal.off: i64); + emitline("(BP), BX\n"); }; - emit_line("\tADDQ\tAX, BX\n"); + emitline("\tADDQ\tAX, BX\n"); // str element (16B): load (ptr, len) into (AX, BX) so // the value flows through the str-rhs convention. if (esz == 16) { - emit_line("\tMOVQ\t8(BX), CX\n"); - emit_line("\tMOVQ\t(BX), AX\n"); - emit_line("\tMOVQ\tCX, BX\n"); + emitline("\tMOVQ\t8(BX), CX\n"); + emitline("\tMOVQ\t(BX), AX\n"); + emitline("\tMOVQ\tCX, BX\n"); return; }; - if (esz == 1) { emit_line("\tMOVZBQ\t(BX), AX\n"); } - else { emit_line("\tMOVQ\t(BX), AX\n"); }; + if (esz == 1) { emitline("\tMOVZBQ\t(BX), AX\n"); } + else { emitline("\tMOVQ\t(BX), AX\n"); }; return; }; // Generic fallback when base isn't a plain ident. - emit_line("\tPUSHQ\tAX\n"); + emitline("\tPUSHQ\tAX\n"); cgexpr(c, base); - emit_line("\tPOPQ\tBX\n"); - emit_line("\tADDQ\tBX, AX\n"); + emitline("\tPOPQ\tBX\n"); + emitline("\tADDQ\tBX, AX\n"); if (esz == 16) { - emit_line("\tMOVQ\t8(AX), BX\n"); - emit_line("\tMOVQ\t(AX), AX\n"); + emitline("\tMOVQ\t8(AX), BX\n"); + emitline("\tMOVQ\t(AX), AX\n"); return; }; - if (esz == 1) { emit_line("\tMOVZBQ\t(AX), AX\n"); } - else { emit_line("\tMOVQ\t(AX), AX\n"); }; + if (esz == 1) { emitline("\tMOVZBQ\t(AX), AX\n"); } + else { emitline("\tMOVQ\t(AX), AX\n"); }; return; }; @@ -4945,14 +4945,14 @@ fn cgexpr(c: *cgen, n: *node) void = { // (`case let v: T =>`) get a fresh local slot loaded from // slot+8 (and slot+16 for str-typed payload). let scrut: *node = n.lhs; - let scrut_off: i32 = 0; - let scrut_t: *node = nil; + let scrutoff: i32 = 0; + let scrutt: *node = nil; if (scrut != nil) { if (scrut.kind == N_IDENT) { - let lc: *local = local_find_node(c, scrut.str); + let lc: *local = localfindnode(c, scrut.str); if (lc != nil) { - scrut_off = lc.off; - scrut_t = resolve_type(c, lc.tnode); + scrutoff = lc.off; + scrutt = resolvetype(c, lc.tnode); }; }; }; @@ -4965,17 +4965,17 @@ fn cgexpr(c: *cgen, n: *node) void = { // (no pattern) skips the tag check. if (pat != nil) { let want: i32 = 0; - if (scrut_t != nil) { - if (scrut_t.kind == N_TTAGGED) { - let pat_name: str; - pat_name.ptr = nil; pat_name.len = 0; - if (pat.kind == N_TNAME) { pat_name = pat.str; }; - let v: *node = scrut_t.list; + if (scrutt != nil) { + if (scrutt.kind == N_TTAGGED) { + let patname: str; + patname.ptr = nil; patname.len = 0; + if (pat.kind == N_TNAME) { patname = pat.str; }; + let v: *node = scrutt.list; let idx: i32 = 0; let found: bool = false; for (v != nil) { if (v.kind == N_TNAME) { - if (streq(v.str, pat_name)) { + if (streq(v.str, patname)) { want = idx; found = true; v = nil; @@ -4989,52 +4989,52 @@ fn cgexpr(c: *cgen, n: *node) void = { if (!found) { want = 0; }; }; }; - emit_line("\tMOVQ\t"); - emit_off(scrut_off: i64); - emit_line("(BP), AX\n"); - emit_line("\tCMPQ\t$"); - emit_int(want: i64); - emit_line(", AX\n"); - emit_line("\tJNE\t"); - emit_line(nxt); - emit_line("\n"); + emitline("\tMOVQ\t"); + emitoff(scrutoff: i64); + emitline("(BP), AX\n"); + emitline("\tCMPQ\t$"); + emitint(want: i64); + emitline(", AX\n"); + emitline("\tJNE\t"); + emitline(nxt); + emitline("\n"); }; // Bind `let v: T` from the slot, if requested. let bn: str = cs.str; if (bn.len > 0) { if (pat != nil) { let bsz: i32 = 8; - if (is_str_type(c, pat)) { bsz = 16; }; - // local_alloc (not local_add): match-arm + if (isstrtype(c, pat)) { bsz = 16; }; + // localalloc (not localadd): match-arm // binds don't dedup with same-named binds // in *other* matches, since C's cgexpr // allocates a fresh slot per match expr. - let voff: i32 = local_alloc(c, bn, bsz, pat); - emit_line("\tMOVQ\t"); - emit_off((scrut_off + 8): i64); - emit_line("(BP), AX\n"); - emit_line("\tMOVQ\tAX, "); - emit_off(voff: i64); - emit_line("(BP)\n"); + let voff: i32 = localalloc(c, bn, bsz, pat); + emitline("\tMOVQ\t"); + emitoff((scrutoff + 8): i64); + emitline("(BP), AX\n"); + emitline("\tMOVQ\tAX, "); + emitoff(voff: i64); + emitline("(BP)\n"); if (bsz == 16) { - emit_line("\tMOVQ\t"); - emit_off((scrut_off + 16): i64); - emit_line("(BP), AX\n"); - emit_line("\tMOVQ\tAX, "); - emit_off((voff + 8): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\t"); + emitoff((scrutoff + 16): i64); + emitline("(BP), AX\n"); + emitline("\tMOVQ\tAX, "); + emitoff((voff + 8): i64); + emitline("(BP)\n"); }; }; }; // Body. Match arms are statements; we cgstmt them. if (cs.body != nil) { cgstmt(c, cs.body); }; - emit_line("\tJMP\t"); - emit_line(endl); - emit_line("\n"); - emit_label(nxt); + emitline("\tJMP\t"); + emitline(endl); + emitline("\n"); + emitlabel(nxt); cs = cs.next; }; - emit_label(endl); + emitlabel(endl); return; }; @@ -5054,7 +5054,7 @@ fn cgexpr(c: *cgen, n: *node) void = { if (lhs != nil) { if (lhs.kind == N_IDENT) { let nm: str = lhs.str; - let lc: *local = local_find_node(c, nm); + let lc: *local = localfindnode(c, nm); if (lc != nil) { let tn: *node = lc.tnode; let lkind: i32 = -1; @@ -5070,33 +5070,33 @@ fn cgexpr(c: *cgen, n: *node) void = { }; }; if (sname.len > 0) { - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fld)) { // str field via *struct: load len into a // scratch first (so loading ptr into AX // last leaves (AX=ptr, BX=len)). - emit_line("\tMOVQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), BX\n"); - if (is_str_type(c, fi.tnode)) { - emit_line("\tMOVQ\t"); - emit_disp_reg((fi.foff + 8): i64, "BX"); - emit_line(", CX\n"); - emit_line("\tMOVQ\t"); - emit_disp_reg(fi.foff: i64, "BX"); - emit_line(", AX\n"); - emit_line("\tMOVQ\tCX, BX\n"); + emitline("\tMOVQ\t"); + emitoff(lc.off: i64); + emitline("(BP), BX\n"); + if (isstrtype(c, fi.tnode)) { + emitline("\tMOVQ\t"); + emitdispreg((fi.foff + 8): i64, "BX"); + emitline(", CX\n"); + emitline("\tMOVQ\t"); + emitdispreg(fi.foff: i64, "BX"); + emitline(", AX\n"); + emitline("\tMOVQ\tCX, BX\n"); } else { - let op: str = field_load_op(fi); - emit_line("\t"); - emit_line(op); - emit_line("\t"); - emit_disp_reg(fi.foff: i64, "BX"); - emit_line(", AX\n"); + let op: str = fieldloadop(fi); + emitline("\t"); + emitline(op); + emitline("\t"); + emitdispreg(fi.foff: i64, "BX"); + emitline(", AX\n"); }; return; }; @@ -5108,28 +5108,28 @@ fn cgexpr(c: *cgen, n: *node) void = { // Direct struct local: field load at off+foff. if (lkind == N_TNAME) { let sname: str = tn.str; - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fld)) { // str field: load both halves so chained // `.ptr` / `.len` see (AX=ptr, BX=len). - if (is_str_type(c, fi.tnode)) { - emit_line("\tMOVQ\t"); - emit_off((lc.off + fi.foff): i64); - emit_line("(BP), AX\n"); - emit_line("\tMOVQ\t"); - emit_off((lc.off + fi.foff + 8): i64); - emit_line("(BP), BX\n"); + if (isstrtype(c, fi.tnode)) { + emitline("\tMOVQ\t"); + emitoff((lc.off + fi.foff): i64); + emitline("(BP), AX\n"); + emitline("\tMOVQ\t"); + emitoff((lc.off + fi.foff + 8): i64); + emitline("(BP), BX\n"); } else { - let op: str = field_load_op(fi); - emit_line("\t"); - emit_line(op); - emit_line("\t"); - emit_off((lc.off + fi.foff): i64); - emit_line("(BP), AX\n"); + let op: str = fieldloadop(fi); + emitline("\t"); + emitline(op); + emitline("\t"); + emitoff((lc.off + fi.foff): i64); + emitline("(BP), AX\n"); }; return; }; @@ -5142,20 +5142,20 @@ fn cgexpr(c: *cgen, n: *node) void = { // count (immediate). if (lkind == N_TARRAY) { if (streq(fld, "ptr")) { - emit_line("\tLEAQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), AX\n"); + emitline("\tLEAQ\t"); + emitoff(lc.off: i64); + emitline("(BP), AX\n"); return; }; if (streq(fld, "len")) { - let len_n: *node = tn.rhs; + let lenn: *node = tn.rhs; let alen: i64 = 0i64; - if (len_n != nil) { - if (len_n.kind == N_INTLIT) { alen = len_n.uval: i64; }; + if (lenn != nil) { + if (lenn.kind == N_INTLIT) { alen = lenn.uval: i64; }; }; - emit_line("\tMOVQ\t$"); - emit_int(alen); - emit_line(", AX\n"); + emitline("\tMOVQ\t$"); + emitint(alen); + emitline(", AX\n"); return; }; }; @@ -5171,26 +5171,26 @@ fn cgexpr(c: *cgen, n: *node) void = { // pointed-to header. C cgen does the same. if (lkind == N_TPTR) { let inner: *node = tn.lhs; - let inner_kind: i32 = -1; - if (inner != nil) { inner_kind = inner.kind; }; - let inner_str: bool = false; - if (inner_kind == N_TNAME) { - if (streq(inner.str, "str")) { inner_str = true; }; + let innerkind: i32 = -1; + if (inner != nil) { innerkind = inner.kind; }; + let innerstr: bool = false; + if (innerkind == N_TNAME) { + if (streq(inner.str, "str")) { innerstr = true; }; }; - if (inner_kind == N_TSLICE) { inner_str = true; }; - if (inner_str) { - emit_line("\tMOVQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), BX\n"); - emit_line("\tMOVQ\t"); - emit_disp_reg(delta: i64, "BX"); - emit_line(", AX\n"); + if (innerkind == N_TSLICE) { innerstr = true; }; + if (innerstr) { + emitline("\tMOVQ\t"); + emitoff(lc.off: i64); + emitline("(BP), BX\n"); + emitline("\tMOVQ\t"); + emitdispreg(delta: i64, "BX"); + emitline(", AX\n"); return; }; }; - emit_line("\tMOVQ\t"); - emit_off((lc.off + delta): i64); - emit_line("(BP), AX\n"); + emitline("\tMOVQ\t"); + emitoff((lc.off + delta): i64); + emitline("(BP), AX\n"); return; }; }; @@ -5202,9 +5202,9 @@ fn cgexpr(c: *cgen, n: *node) void = { // the C cgen takes when bt is NULL/ty_err. if (lhs != nil) { if (lhs.kind == N_IDENT) { - emit_line("\tMOVQ\t"); - emit_line(fld); - emit_line("(SB), AX\n"); + emitline("\tMOVQ\t"); + emitline(fld); + emitline("(SB), AX\n"); return; }; }; @@ -5216,7 +5216,7 @@ fn cgexpr(c: *cgen, n: *node) void = { if (streq(fld, "ptr")) { cgexpr(c, lhs); return; }; if (streq(fld, "len")) { cgexpr(c, lhs); - emit_line("\tMOVQ\tBX, AX\n"); + emitline("\tMOVQ\tBX, AX\n"); return; }; // Chained struct-field-via-ptr-via-ptr access: @@ -5229,31 +5229,31 @@ fn cgexpr(c: *cgen, n: *node) void = { // the field. (Showed up porting w6l/pass.ww.) if (lhs != nil) { if (lhs.kind == N_DOT) { - let inner_t: *node = dot_inner_struct_ptr(c, lhs); - if (inner_t != nil) { - let sname: str = inner_t.str; - let si: *struct_info = struct_lookup(c, sname); + let innert: *node = dotinnerstructptr(c, lhs); + if (innert != nil) { + let sname: str = innert.str; + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { if (streq(fi.fname, fld)) { cgexpr(c, lhs); // AX = ptr to inner struct - let lop: str = field_load_op(fi); + let lop: str = fieldloadop(fi); // str field: load both halves. - if (is_str_type(c, fi.tnode)) { - emit_line("\tMOVQ\t"); - emit_disp_reg((fi.foff + 8): i64, "AX"); - emit_line(", BX\n"); - emit_line("\tMOVQ\t"); - emit_disp_reg(fi.foff: i64, "AX"); - emit_line(", AX\n"); + if (isstrtype(c, fi.tnode)) { + emitline("\tMOVQ\t"); + emitdispreg((fi.foff + 8): i64, "AX"); + emitline(", BX\n"); + emitline("\tMOVQ\t"); + emitdispreg(fi.foff: i64, "AX"); + emitline(", AX\n"); return; }; - emit_line("\t"); - emit_line(lop); - emit_line("\t"); - emit_disp_reg(fi.foff: i64, "AX"); - emit_line(", AX\n"); + emitline("\t"); + emitline(lop); + emitline("\t"); + emitdispreg(fi.foff: i64, "AX"); + emitline(", AX\n"); return; }; fi = fi.finext; @@ -5271,19 +5271,19 @@ fn cgexpr(c: *cgen, n: *node) void = { // address / deref. The wasted load before AMP keeps our asm // byte-identical to the C version. cgexpr(c, n.lhs); - if (n.op == TK_MINUS) { emit_line("\tNEGQ\tAX\n"); return; }; - if (n.op == TK_TILDE) { emit_line("\tNOTQ\tAX\n"); return; }; - if (n.op == TK_STAR) { emit_line("\tMOVQ\t(AX), AX\n"); return; }; + if (n.op == TK_MINUS) { emitline("\tNEGQ\tAX\n"); return; }; + if (n.op == TK_TILDE) { emitline("\tNOTQ\tAX\n"); return; }; + if (n.op == TK_STAR) { emitline("\tMOVQ\t(AX), AX\n"); return; }; if (n.op == TK_AMP) { let opnd: *node = n.lhs; if (opnd != nil) { if (opnd.kind == N_IDENT) { let nm: str = opnd.str; - let off: i32 = local_find(c, nm); + let off: i32 = localfind(c, nm); if (off != 0) { - emit_line("\tLEAQ\t"); - emit_off(off: i64); - emit_line("(BP), AX\n"); + emitline("\tLEAQ\t"); + emitoff(off: i64); + emitline("(BP), AX\n"); return; }; }; @@ -5293,95 +5293,95 @@ fn cgexpr(c: *cgen, n: *node) void = { if (n.op == TK_NOT) { let t: str = mklabel(c, "tt"); let e: str = mklabel(c, "te"); - emit_line("\tCMPQ\t$0, AX\n"); - emit_line("\tJE\t"); emit_line(t); emit_line("\n"); - emit_line("\tMOVQ\t$0, AX\n"); - emit_line("\tJMP\t"); emit_line(e); emit_line("\n"); - emit_label(t); - emit_line("\tMOVQ\t$1, AX\n"); - emit_label(e); + emitline("\tCMPQ\t$0, AX\n"); + emitline("\tJE\t"); emitline(t); emitline("\n"); + emitline("\tMOVQ\t$0, AX\n"); + emitline("\tJMP\t"); emitline(e); emitline("\n"); + emitlabel(t); + emitline("\tMOVQ\t$1, AX\n"); + emitlabel(e); return; }; return; }; if (k == N_BIN) { - let unsignd: bool = node_isunsigned(c, n.lhs); - if (!unsignd) { unsignd = node_isunsigned(c, n.rhs); }; + let unsignd: bool = nodeisunsigned(c, n.lhs); + if (!unsignd) { unsignd = nodeisunsigned(c, n.rhs); }; cgexpr(c, n.rhs); - emit_line("\tPUSHQ\tAX\n"); + emitline("\tPUSHQ\tAX\n"); cgexpr(c, n.lhs); - emit_line("\tPOPQ\tBX\n"); - if (n.op == TK_PLUS) { emit_line("\tADDQ\tBX, AX\n"); return; }; - if (n.op == TK_MINUS) { emit_line("\tSUBQ\tBX, AX\n"); return; }; - if (n.op == TK_STAR) { emit_line("\tIMULQ\tBX, AX\n"); return; }; + emitline("\tPOPQ\tBX\n"); + if (n.op == TK_PLUS) { emitline("\tADDQ\tBX, AX\n"); return; }; + if (n.op == TK_MINUS) { emitline("\tSUBQ\tBX, AX\n"); return; }; + if (n.op == TK_STAR) { emitline("\tIMULQ\tBX, AX\n"); return; }; if (n.op == TK_SLASH) { - emit_line("\tMOVQ\t$0, DX\n"); - if (unsignd) { emit_line("\tDIVQ\tBX\n"); } - else { emit_line("\tIDIVQ\tBX\n"); }; + emitline("\tMOVQ\t$0, DX\n"); + if (unsignd) { emitline("\tDIVQ\tBX\n"); } + else { emitline("\tIDIVQ\tBX\n"); }; return; }; if (n.op == TK_PERCENT) { - emit_line("\tMOVQ\t$0, DX\n"); - if (unsignd) { emit_line("\tDIVQ\tBX\n"); } - else { emit_line("\tIDIVQ\tBX\n"); }; - emit_line("\tMOVQ\tDX, AX\n"); + emitline("\tMOVQ\t$0, DX\n"); + if (unsignd) { emitline("\tDIVQ\tBX\n"); } + else { emitline("\tIDIVQ\tBX\n"); }; + emitline("\tMOVQ\tDX, AX\n"); return; }; - if (n.op == TK_AMP) { emit_line("\tANDQ\tBX, AX\n"); return; }; - if (n.op == TK_PIPE) { emit_line("\tORQ\tBX, AX\n"); return; }; - if (n.op == TK_CARET) { emit_line("\tXORQ\tBX, AX\n"); return; }; + if (n.op == TK_AMP) { emitline("\tANDQ\tBX, AX\n"); return; }; + if (n.op == TK_PIPE) { emitline("\tORQ\tBX, AX\n"); return; }; + if (n.op == TK_CARET) { emitline("\tXORQ\tBX, AX\n"); return; }; if (n.op == TK_LSHIFT) { - emit_line("\tMOVQ\tBX, CX\n"); - emit_line("\tSHLQ\tCX, AX\n"); + emitline("\tMOVQ\tBX, CX\n"); + emitline("\tSHLQ\tCX, AX\n"); return; }; if (n.op == TK_RSHIFT) { - emit_line("\tMOVQ\tBX, CX\n"); - emit_line("\tSHRQ\tCX, AX\n"); + emitline("\tMOVQ\tBX, CX\n"); + emitline("\tSHRQ\tCX, AX\n"); return; }; - if (n.op == TK_AND) { emit_line("\tANDQ\tBX, AX\n"); return; }; - if (n.op == TK_OR) { emit_line("\tORQ\tBX, AX\n"); return; }; + if (n.op == TK_AND) { emitline("\tANDQ\tBX, AX\n"); return; }; + if (n.op == TK_OR) { emitline("\tORQ\tBX, AX\n"); return; }; // Comparison: emit CMPQ, jump on signed/unsigned variant, // materialise 0/1 in AX. Same shape as the C cgen. - let is_cmp: bool = false; + let iscmp: bool = false; let jcc: str = ""; - if (n.op == TK_EQ) { is_cmp = true; jcc = "JE"; }; - if (n.op == TK_NEQ) { is_cmp = true; jcc = "JNE"; }; - if (n.op == TK_LT) { is_cmp = true; if (unsignd) { jcc = "JB"; } else { jcc = "JL"; }; }; - if (n.op == TK_LE) { is_cmp = true; if (unsignd) { jcc = "JBE"; } else { jcc = "JLE"; }; }; - if (n.op == TK_GT) { is_cmp = true; if (unsignd) { jcc = "JA"; } else { jcc = "JG"; }; }; - if (n.op == TK_GE) { is_cmp = true; if (unsignd) { jcc = "JAE"; } else { jcc = "JGE"; }; }; - if (is_cmp) { + if (n.op == TK_EQ) { iscmp = true; jcc = "JE"; }; + if (n.op == TK_NEQ) { iscmp = true; jcc = "JNE"; }; + if (n.op == TK_LT) { iscmp = true; if (unsignd) { jcc = "JB"; } else { jcc = "JL"; }; }; + if (n.op == TK_LE) { iscmp = true; if (unsignd) { jcc = "JBE"; } else { jcc = "JLE"; }; }; + if (n.op == TK_GT) { iscmp = true; if (unsignd) { jcc = "JA"; } else { jcc = "JG"; }; }; + if (n.op == TK_GE) { iscmp = true; if (unsignd) { jcc = "JAE"; } else { jcc = "JGE"; }; }; + if (iscmp) { let t: str = mklabel(c, "ct"); let e: str = mklabel(c, "ce"); - emit_line("\tCMPQ\tBX, AX\n"); - emit_line("\t"); emit_line(jcc); emit_line("\t"); emit_line(t); emit_line("\n"); - emit_line("\tMOVQ\t$0, AX\n"); - emit_line("\tJMP\t"); emit_line(e); emit_line("\n"); - emit_label(t); - emit_line("\tMOVQ\t$1, AX\n"); - emit_label(e); + emitline("\tCMPQ\tBX, AX\n"); + emitline("\t"); emitline(jcc); emitline("\t"); emitline(t); emitline("\n"); + emitline("\tMOVQ\t$0, AX\n"); + emitline("\tJMP\t"); emitline(e); emitline("\n"); + emitlabel(t); + emitline("\tMOVQ\t$1, AX\n"); + emitlabel(e); return; }; return; }; if (k == N_CALL) { - let nargs: i32 = push_args_rev(c, n.list); + let nargs: i32 = pushargsrev(c, n.list); let i: i32 = 0; for (i < nargs) { - emit_line("\tPOPQ\t"); - emit_line(argreg_name(i)); - emit_line("\n"); + emitline("\tPOPQ\t"); + emitline(argregname(i)); + emitline("\n"); i += 1; }; let callee: *node = n.lhs; - let callee_name: str; - callee_name.ptr = nil; callee_name.len = 0; + let calleename: str; + calleename.ptr = nil; calleename.len = 0; // Detect fn-pointer field call: `w.emit(args)` where `w` is // a struct local and `emit` is an N_TFN field. Load the // field value into AX and CALL through it. Also detect a @@ -5389,12 +5389,12 @@ fn cgexpr(c: *cgen, n: *node) void = { // pointer — mirror C cgen's localfind dispatch (commit // 635818e). Without this the call emits `CALL fp(SB)` and // the linker rightly fails. - let is_fnptr_call: bool = false; + let isfnptrcall: bool = false; if (callee != nil) { if (callee.kind == N_IDENT) { let cn: str = callee.str; - if (local_find_node(c, cn) != nil) { - is_fnptr_call = true; + if (localfindnode(c, cn) != nil) { + isfnptrcall = true; }; }; if (callee.kind == N_DOT) { @@ -5403,7 +5403,7 @@ fn cgexpr(c: *cgen, n: *node) void = { if (base != nil) { if (base.kind == N_IDENT) { let bn: str = base.str; - let lc: *local = local_find_node(c, bn); + let lc: *local = localfindnode(c, bn); if (lc != nil) { let tn: *node = lc.tnode; if (tn != nil) { @@ -5418,16 +5418,16 @@ fn cgexpr(c: *cgen, n: *node) void = { }; }; if (sname.len > 0) { - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fld)) { let ft: *node = fi.tnode; if (ft != nil) { if (ft.kind == N_TFN) { - is_fnptr_call = true; + isfnptrcall = true; }; }; fi = nil; @@ -5443,34 +5443,34 @@ fn cgexpr(c: *cgen, n: *node) void = { }; }; }; - if (is_fnptr_call) { + if (isfnptrcall) { // Load fn-ptr field value into AX; CALL AX. We emit the // load AFTER the args have been popped (so AX/BX/etc // don't get clobbered by the field load before the pops). // `popped args` left DI/SI/etc set; AX is free. cgexpr(c, callee); - emit_line("\tCALL\tAX\n"); + emitline("\tCALL\tAX\n"); } else { - emit_line("\tCALL\t"); + emitline("\tCALL\t"); if (callee != nil) { if (callee.kind == N_IDENT) { - callee_name = callee.str; - let resolved: str = ffi_resolve(c, callee_name); + calleename = callee.str; + let resolved: str = ffiresolve(c, calleename); os.write(1, resolved.ptr, resolved.len: u64); } else { if (callee.kind == N_DOT) { - callee_name = callee.str; - let resolved: str = ffi_resolve(c, callee_name); + calleename = callee.str; + let resolved: str = ffiresolve(c, calleename); os.write(1, resolved.ptr, resolved.len: u64); };}; }; - emit_line("(SB)\n"); + emitline("(SB)\n"); }; // SysV returns 16-byte aggregates in (AX, DX). Our str // convention is (AX, BX), so shuffle for str-returning calls. - if (callee_name.len > 0) { - let rt: *node = fnret_lookup(c, callee_name); - if (is_str_type(c, rt)) { - emit_line("\tMOVQ\tDX, BX\n"); + if (calleename.len > 0) { + let rt: *node = fnretlookup(c, calleename); + if (isstrtype(c, rt)) { + emitline("\tMOVQ\tDX, BX\n"); }; }; return; @@ -5488,11 +5488,11 @@ fn cgexpr(c: *cgen, n: *node) void = { if (lhs.op == TK_STAR) { if (n.op == TK_ASSIGN) { let inner: *node = lhs.lhs; - let elem_str: bool = false; - let store_op: str = "MOVQ"; + let elemstr: bool = false; + let storeop: str = "MOVQ"; if (inner != nil) { if (inner.kind == N_IDENT) { - let lc: *local = local_find_node(c, inner.str); + let lc: *local = localfindnode(c, inner.str); if (lc != nil) { let tn: *node = lc.tnode; if (tn != nil) { @@ -5500,11 +5500,11 @@ fn cgexpr(c: *cgen, n: *node) void = { let pe: *node = tn.lhs; if (pe != nil) { if (pe.kind == N_TNAME) { - if (streq(pe.str, "str")) { elem_str = true; } + if (streq(pe.str, "str")) { elemstr = true; } else { - let ps: i32 = prim_size(pe.str); - if (ps == 1) { store_op = "MOVB"; } - else { if (ps == 4) { store_op = "MOVL"; }; }; + let ps: i32 = primsize(pe.str); + if (ps == 1) { storeop = "MOVB"; } + else { if (ps == 4) { storeop = "MOVL"; }; }; }; }; }; @@ -5520,21 +5520,21 @@ fn cgexpr(c: *cgen, n: *node) void = { // str, so the pop sequence is POP CX // (len) → POP AX (ptr) → MOVQ AX, // (BX) → MOVQ CX, 8(BX). - emit_line("\tPUSHQ\tAX\n"); - if (elem_str) { emit_line("\tPUSHQ\tBX\n"); }; + emitline("\tPUSHQ\tAX\n"); + if (elemstr) { emitline("\tPUSHQ\tBX\n"); }; cgexpr(c, inner); - emit_line("\tMOVQ\tAX, BX\n"); - if (elem_str) { - emit_line("\tPOPQ\tCX\n"); - emit_line("\tPOPQ\tAX\n"); - emit_line("\tMOVQ\tAX, (BX)\n"); - emit_line("\tMOVQ\tCX, 8(BX)\n"); + emitline("\tMOVQ\tAX, BX\n"); + if (elemstr) { + emitline("\tPOPQ\tCX\n"); + emitline("\tPOPQ\tAX\n"); + emitline("\tMOVQ\tAX, (BX)\n"); + emitline("\tMOVQ\tCX, 8(BX)\n"); return; }; - emit_line("\tPOPQ\tAX\n"); - emit_line("\t"); - emit_line(store_op); - emit_line("\tAX, (BX)\n"); + emitline("\tPOPQ\tAX\n"); + emitline("\t"); + emitline(storeop); + emitline("\tAX, (BX)\n"); return; }; }; @@ -5548,57 +5548,57 @@ fn cgexpr(c: *cgen, n: *node) void = { let base: *node = lhs.lhs; let idx: *node = lhs.rhs; let esz: i32 = 8; - let base_local: *local = nil; + let baselocal: *local = nil; if (base != nil) { if (base.kind == N_IDENT) { let bn: str = base.str; - base_local = local_find_node(c, bn); - if (base_local != nil) { - esz = elem_size_of(base_local.tnode); + baselocal = localfindnode(c, bn); + if (baselocal != nil) { + esz = elemsizeof(baselocal.tnode); }; } else { if (base.kind == N_DOT) { - esz = index_base_esz(c, base); + esz = indexbaseesz(c, base); };}; }; cgexpr(c, n.rhs); // value → AX - if (esz == 16) { emit_line("\tPUSHQ\tBX\n"); }; - emit_line("\tPUSHQ\tAX\n"); + if (esz == 16) { emitline("\tPUSHQ\tBX\n"); }; + emitline("\tPUSHQ\tAX\n"); cgexpr(c, idx); // idx → AX if (esz > 1) { - emit_line("\tMOVQ\t$"); - emit_int(esz: i64); - emit_line(", CX\n"); - emit_line("\tIMULQ\tCX, AX\n"); + emitline("\tMOVQ\t$"); + emitint(esz: i64); + emitline(", CX\n"); + emitline("\tIMULQ\tCX, AX\n"); }; - emit_line("\tPUSHQ\tAX\n"); // scaled idx - if (base_local != nil) { - let tn: *node = base_local.tnode; - let is_array: bool = false; - if (tn != nil) { if (tn.kind == N_TARRAY) { is_array = true; }; }; - if (is_array) { - emit_line("\tLEAQ\t"); - emit_off(base_local.off: i64); - emit_line("(BP), BX\n"); + emitline("\tPUSHQ\tAX\n"); // scaled idx + if (baselocal != nil) { + let tn: *node = baselocal.tnode; + let isarray: bool = false; + if (tn != nil) { if (tn.kind == N_TARRAY) { isarray = true; }; }; + if (isarray) { + emitline("\tLEAQ\t"); + emitoff(baselocal.off: i64); + emitline("(BP), BX\n"); } else { - emit_line("\tMOVQ\t"); - emit_off(base_local.off: i64); - emit_line("(BP), BX\n"); + emitline("\tMOVQ\t"); + emitoff(baselocal.off: i64); + emitline("(BP), BX\n"); }; } else { cgexpr(c, base); - emit_line("\tMOVQ\tAX, BX\n"); + emitline("\tMOVQ\tAX, BX\n"); }; - emit_line("\tPOPQ\tAX\n"); // scaled idx - emit_line("\tADDQ\tAX, BX\n"); - emit_line("\tPOPQ\tAX\n"); // value + emitline("\tPOPQ\tAX\n"); // scaled idx + emitline("\tADDQ\tAX, BX\n"); + emitline("\tPOPQ\tAX\n"); // value if (esz == 16) { - emit_line("\tMOVQ\tAX, (BX)\n"); - emit_line("\tPOPQ\tCX\n"); - emit_line("\tMOVQ\tCX, 8(BX)\n"); + emitline("\tMOVQ\tAX, (BX)\n"); + emitline("\tPOPQ\tCX\n"); + emitline("\tMOVQ\tCX, 8(BX)\n"); return; }; - if (esz == 1) { emit_line("\tMOVB\tAX, (BX)\n"); } - else { emit_line("\tMOVQ\tAX, (BX)\n"); }; + if (esz == 1) { emitline("\tMOVB\tAX, (BX)\n"); } + else { emitline("\tMOVQ\tAX, (BX)\n"); }; return; }; }; @@ -5613,7 +5613,7 @@ fn cgexpr(c: *cgen, n: *node) void = { if (base != nil) { if (base.kind == N_IDENT) { let bn: str = base.str; - let lc: *local = local_find_node(c, bn); + let lc: *local = localfindnode(c, bn); if (lc != nil) { let tn: *node = lc.tnode; let lkind: i32 = -1; @@ -5627,35 +5627,35 @@ fn cgexpr(c: *cgen, n: *node) void = { if (inner.kind == N_TNAME) { sname = inner.str; }; }; if (sname.len > 0) { - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fld)) { if (n.op != TK_ASSIGN) { // compound: load current value - emit_line("\tMOVQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), BX\n"); - let lop: str = field_load_op(fi); - emit_line("\t"); - emit_line(lop); - emit_line("\t"); - emit_disp_reg(fi.foff: i64, "BX"); - emit_line(", BX\n"); - emit_line("\tPUSHQ\tBX\n"); + emitline("\tMOVQ\t"); + emitoff(lc.off: i64); + emitline("(BP), BX\n"); + let lop: str = fieldloadop(fi); + emitline("\t"); + emitline(lop); + emitline("\t"); + emitdispreg(fi.foff: i64, "BX"); + emitline(", BX\n"); + emitline("\tPUSHQ\tBX\n"); }; cgexpr(c, n.rhs); if (n.op != TK_ASSIGN) { - emit_line("\tPOPQ\tBX\n"); + emitline("\tPOPQ\tBX\n"); // PLUSEQ is commutative; MINUSEQ // needs lhs - rhs (BX is old lhs, // AX is rhs). - if (n.op == TK_PLUSEQ) { emit_line("\tADDQ\tBX, AX\n"); }; + if (n.op == TK_PLUSEQ) { emitline("\tADDQ\tBX, AX\n"); }; if (n.op == TK_MINUSEQ) { - emit_line("\tSUBQ\tAX, BX\n"); - emit_line("\tMOVQ\tBX, AX\n"); + emitline("\tSUBQ\tAX, BX\n"); + emitline("\tMOVQ\tBX, AX\n"); }; }; // str field via *struct: rhs left @@ -5663,28 +5663,28 @@ fn cgexpr(c: *cgen, n: *node) void = { // address scratch so we don't clobber // the len half before storing it. if (n.op == TK_ASSIGN) { - if (is_str_type(c, fi.tnode)) { - emit_line("\tMOVQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), CX\n"); - emit_line("\tMOVQ\tAX, "); - emit_disp_reg(fi.foff: i64, "CX"); - emit_line("\n"); - emit_line("\tMOVQ\tBX, "); - emit_disp_reg((fi.foff + 8): i64, "CX"); - emit_line("\n"); + if (isstrtype(c, fi.tnode)) { + emitline("\tMOVQ\t"); + emitoff(lc.off: i64); + emitline("(BP), CX\n"); + emitline("\tMOVQ\tAX, "); + emitdispreg(fi.foff: i64, "CX"); + emitline("\n"); + emitline("\tMOVQ\tBX, "); + emitdispreg((fi.foff + 8): i64, "CX"); + emitline("\n"); return; }; }; - emit_line("\tMOVQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), BX\n"); - let sop: str = field_store_op(fi); - emit_line("\t"); - emit_line(sop); - emit_line("\tAX, "); - emit_disp_reg(fi.foff: i64, "BX"); - emit_line("\n"); + emitline("\tMOVQ\t"); + emitoff(lc.off: i64); + emitline("(BP), BX\n"); + let sop: str = fieldstoreop(fi); + emitline("\t"); + emitline(sop); + emitline("\tAX, "); + emitdispreg(fi.foff: i64, "BX"); + emitline("\n"); return; }; fi = fi.finext; @@ -5695,19 +5695,19 @@ fn cgexpr(c: *cgen, n: *node) void = { // Direct struct local: store at off+foff. if (lkind == N_TNAME) { let sname: str = tn.str; - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fld)) { cgexpr(c, n.rhs); - let sop: str = field_store_op(fi); - emit_line("\t"); - emit_line(sop); - emit_line("\tAX, "); - emit_off((lc.off + fi.foff): i64); - emit_line("(BP)\n"); + let sop: str = fieldstoreop(fi); + emitline("\t"); + emitline(sop); + emitline("\tAX, "); + emitoff((lc.off + fi.foff): i64); + emitline("(BP)\n"); return; }; fi = fi.finext; @@ -5722,55 +5722,55 @@ fn cgexpr(c: *cgen, n: *node) void = { if (delta >= 0) { if (lkind == N_TPTR) { let inner: *node = tn.lhs; - let inner_kind: i32 = -1; - if (inner != nil) { inner_kind = inner.kind; }; - let inner_str: bool = false; - if (inner_kind == N_TNAME) { - if (streq(inner.str, "str")) { inner_str = true; }; + let innerkind: i32 = -1; + if (inner != nil) { innerkind = inner.kind; }; + let innerstr: bool = false; + if (innerkind == N_TNAME) { + if (streq(inner.str, "str")) { innerstr = true; }; }; - if (inner_kind == N_TSLICE) { inner_str = true; }; - if (inner_str) { + if (innerkind == N_TSLICE) { innerstr = true; }; + if (innerstr) { if (n.op != TK_ASSIGN) { // Compound on `(*str|*slice).field`: load // current → push → eval rhs → combine → store. - emit_line("\tMOVQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), BX\n"); - emit_line("\tMOVQ\t"); - emit_disp_reg(delta: i64, "BX"); - emit_line(", BX\n"); - emit_line("\tPUSHQ\tBX\n"); + emitline("\tMOVQ\t"); + emitoff(lc.off: i64); + emitline("(BP), BX\n"); + emitline("\tMOVQ\t"); + emitdispreg(delta: i64, "BX"); + emitline(", BX\n"); + emitline("\tPUSHQ\tBX\n"); cgexpr(c, n.rhs); - emit_line("\tPOPQ\tBX\n"); + emitline("\tPOPQ\tBX\n"); // PLUSEQ is commutative; MINUSEQ // needs lhs - rhs. - if (n.op == TK_PLUSEQ) { emit_line("\tADDQ\tBX, AX\n"); }; + if (n.op == TK_PLUSEQ) { emitline("\tADDQ\tBX, AX\n"); }; if (n.op == TK_MINUSEQ) { - emit_line("\tSUBQ\tAX, BX\n"); - emit_line("\tMOVQ\tBX, AX\n"); + emitline("\tSUBQ\tAX, BX\n"); + emitline("\tMOVQ\tBX, AX\n"); }; - emit_line("\tMOVQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), BX\n"); - emit_line("\tMOVQ\tAX, "); - emit_disp_reg(delta: i64, "BX"); - emit_line("\n"); + emitline("\tMOVQ\t"); + emitoff(lc.off: i64); + emitline("(BP), BX\n"); + emitline("\tMOVQ\tAX, "); + emitdispreg(delta: i64, "BX"); + emitline("\n"); return; }; cgexpr(c, n.rhs); - emit_line("\tMOVQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), BX\n"); - emit_line("\tMOVQ\tAX, "); - emit_disp_reg(delta: i64, "BX"); - emit_line("\n"); + emitline("\tMOVQ\t"); + emitoff(lc.off: i64); + emitline("(BP), BX\n"); + emitline("\tMOVQ\tAX, "); + emitdispreg(delta: i64, "BX"); + emitline("\n"); return; }; }; cgexpr(c, n.rhs); - emit_line("\tMOVQ\tAX, "); - emit_off((lc.off + delta): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tAX, "); + emitoff((lc.off + delta): i64); + emitline("(BP)\n"); return; }; }; @@ -5784,56 +5784,56 @@ fn cgexpr(c: *cgen, n: *node) void = { if (lhs != nil) { if (lhs.kind == N_IDENT) { let nm: str = lhs.str; - let off: i32 = local_find(c, nm); + let off: i32 = localfind(c, nm); if (off == 0) { return; }; // Detect str-typed local — assignment must store both // halves (AX=ptr at +0, BX=len at +8). - let lc_str: bool = false; - let lcn: *local = local_find_node(c, nm); - if (lcn != nil) { lc_str = is_str_type(c, lcn.tnode); }; + let lcstr: bool = false; + let lcn: *local = localfindnode(c, nm); + if (lcn != nil) { lcstr = isstrtype(c, lcn.tnode); }; cgexpr(c, n.rhs); if (n.op == TK_ASSIGN) { - emit_line("\tMOVQ\tAX, "); - emit_off(off: i64); - emit_line("(BP)\n"); - if (lc_str) { - emit_line("\tMOVQ\tBX, "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tAX, "); + emitoff(off: i64); + emitline("(BP)\n"); + if (lcstr) { + emitline("\tMOVQ\tBX, "); + emitoff((off + 8): i64); + emitline("(BP)\n"); }; return; }; if (n.op == TK_PLUSEQ) { - emit_line("\tADDQ\tAX, "); - emit_off(off: i64); - emit_line("(BP)\n"); + emitline("\tADDQ\tAX, "); + emitoff(off: i64); + emitline("(BP)\n"); return; }; if (n.op == TK_MINUSEQ) { - emit_line("\tSUBQ\tAX, "); - emit_off(off: i64); - emit_line("(BP)\n"); + emitline("\tSUBQ\tAX, "); + emitoff(off: i64); + emitline("(BP)\n"); return; }; // Generic compound: load → combine in BX → store. - emit_line("\tMOVQ\t"); - emit_off(off: i64); - emit_line("(BP), BX\n"); - if (n.op == TK_STAREQ) { emit_line("\tIMULQ\tAX, BX\n"); }; - if (n.op == TK_AMPEQ) { emit_line("\tANDQ\tAX, BX\n"); }; - if (n.op == TK_PIPEEQ) { emit_line("\tORQ\tAX, BX\n"); }; - if (n.op == TK_CARETEQ) { emit_line("\tXORQ\tAX, BX\n"); }; + emitline("\tMOVQ\t"); + emitoff(off: i64); + emitline("(BP), BX\n"); + if (n.op == TK_STAREQ) { emitline("\tIMULQ\tAX, BX\n"); }; + if (n.op == TK_AMPEQ) { emitline("\tANDQ\tAX, BX\n"); }; + if (n.op == TK_PIPEEQ) { emitline("\tORQ\tAX, BX\n"); }; + if (n.op == TK_CARETEQ) { emitline("\tXORQ\tAX, BX\n"); }; if (n.op == TK_LSHIFTEQ) { - emit_line("\tMOVQ\tAX, CX\n"); - emit_line("\tSHLQ\tCX, BX\n"); + emitline("\tMOVQ\tAX, CX\n"); + emitline("\tSHLQ\tCX, BX\n"); }; if (n.op == TK_RSHIFTEQ) { - emit_line("\tMOVQ\tAX, CX\n"); - emit_line("\tSHRQ\tCX, BX\n"); + emitline("\tMOVQ\tAX, CX\n"); + emitline("\tSHRQ\tCX, BX\n"); }; - emit_line("\tMOVQ\tBX, "); - emit_off(off: i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tBX, "); + emitoff(off: i64); + emitline("(BP)\n"); return; }; }; @@ -5843,8 +5843,8 @@ fn cgexpr(c: *cgen, n: *node) void = { // ---- type-driven slot sizing ---------------------------------------- -fn struct_lookup(c: *cgen, name: str) *struct_info = { - let s: *struct_info = c.structs; +fn structlookup(c: *cgen, name: str) *structinfo = { + let s: *structinfo = c.structs; for (s != nil) { let sn: str = s.sname; if (streq(sn, name)) { return s; }; @@ -5853,9 +5853,9 @@ fn struct_lookup(c: *cgen, name: str) *struct_info = { return nil; }; -// prim_size — size in bytes of a primitive type name (or 0 if not +// primsize — size in bytes of a primitive type name (or 0 if not // recognised as a primitive — the caller falls back to other paths). -fn prim_size(name: str) i32 = { +fn primsize(name: str) i32 = { if (streq(name, "u8")) { return 1; }; if (streq(name, "i8")) { return 1; }; if (streq(name, "bool")) { return 1; }; @@ -5875,7 +5875,7 @@ fn prim_size(name: str) i32 = { return 0; }; -fn slot_size(c: *cgen, typ_n: *node) i32 = { +fn slotsize(c: *cgen, typ_n: *node) i32 = { if (typ_n == nil) { return 8; }; let k: i32 = typ_n.kind; if (k == N_TPTR) { return 8; }; @@ -5887,29 +5887,29 @@ fn slot_size(c: *cgen, typ_n: *node) i32 = { if (k == N_TNAME) { let nm: str = typ_n.str; if (streq(nm, "str")) { return 16; }; - let ps: i32 = prim_size(nm); + let ps: i32 = primsize(nm); if (ps > 0) { // Pad to 8 for stack slots — matches C cgen which spills // every primitive into an 8-byte slot. return 8; }; // Named struct lookup. - let si: *struct_info = struct_lookup(c, nm); + let si: *structinfo = structlookup(c, nm); if (si != nil) { return si.tot_size; }; return 8; }; if (k == N_TARRAY) { - let len_n: *node = typ_n.rhs; - let elem_n: *node = typ_n.lhs; + let lenn: *node = typ_n.rhs; + let elemn: *node = typ_n.lhs; let elen: i64 = 1i64; - if (len_n != nil) { - if (len_n.kind == N_INTLIT) { elen = len_n.uval: i64; }; + if (lenn != nil) { + if (lenn.kind == N_INTLIT) { elen = lenn.uval: i64; }; }; let esz: i32 = 8; - if (elem_n != nil) { - if (elem_n.kind == N_TNAME) { - let en: str = elem_n.str; - let ps: i32 = prim_size(en); + if (elemn != nil) { + if (elemn.kind == N_TNAME) { + let en: str = elemn.str; + let ps: i32 = primsize(en); if (ps > 0) { esz = ps; }; }; }; @@ -5921,7 +5921,7 @@ fn slot_size(c: *cgen, typ_n: *node) i32 = { let total: i32 = 0; for (f != nil) { if (f.kind == N_TFIELD) { - total += slot_size(c, f.lhs); + total += slotsize(c, f.lhs); }; f = f.next; }; @@ -5930,50 +5930,50 @@ fn slot_size(c: *cgen, typ_n: *node) i32 = { return 8; }; -// register_struct — compute field offsets + total size for a struct +// registerstruct — compute field offsets + total size for a struct // type-decl, store in c.structs. Field type sizes use the same -// slot_size logic (with primitives kept at their natural width — we +// slotsize logic (with primitives kept at their natural width — we // only round to 8 for stack slots, not struct interiors). -fn field_size(c: *cgen, tnode: *node) i32 = { +fn fieldsize(c: *cgen, tnode: *node) i32 = { if (tnode == nil) { return 8; }; let k: i32 = tnode.kind; if (k == N_TNAME) { let nm: str = tnode.str; if (streq(nm, "str")) { return 16; }; - let ps: i32 = prim_size(nm); + let ps: i32 = primsize(nm); if (ps > 0) { return ps; }; - let si: *struct_info = struct_lookup(c, nm); + let si: *structinfo = structlookup(c, nm); if (si != nil) { return si.tot_size; }; return 8; }; if (k == N_TPTR) { return 8; }; if (k == N_TSLICE) { return 24; }; if (k == N_TARRAY) { - // Same shape as slot_size's TARRAY branch. - let len_n: *node = tnode.rhs; - let elem_n: *node = tnode.lhs; + // Same shape as slotsize's TARRAY branch. + let lenn: *node = tnode.rhs; + let elemn: *node = tnode.lhs; let elen: i64 = 1i64; - if (len_n != nil) { - if (len_n.kind == N_INTLIT) { elen = len_n.uval: i64; }; + if (lenn != nil) { + if (lenn.kind == N_INTLIT) { elen = lenn.uval: i64; }; }; - let esz: i32 = field_size(c, elem_n); + let esz: i32 = fieldsize(c, elemn); return (esz: i64 * elen): i32; }; return 8; }; -fn register_struct(c: *cgen, name: str, tstruct: *node) void = { - let si: *struct_info = amalloc(c.a, 64u64): *struct_info; +fn registerstruct(c: *cgen, name: str, tstruct: *node) void = { + let si: *structinfo = amalloc(c.a, 64u64): *structinfo; si.sname = name; si.fields = nil; si.tot_size = 0; - let head: *field_info = nil; - let tail: *field_info = nil; + let head: *fieldinfo = nil; + let tail: *fieldinfo = nil; let off: i32 = 0; let f: *node = tstruct.list; for (f != nil) { if (f.kind == N_TFIELD) { - let sz: i32 = field_size(c, f.lhs); + let sz: i32 = fieldsize(c, f.lhs); // Align to 8 for any field >= 4 bytes (matches our other // cgen choices). i8/u8/bool may sit on odd byte offsets; // the C cgen does similar best-effort packing. @@ -5984,7 +5984,7 @@ fn register_struct(c: *cgen, name: str, tstruct: *node) void = { if ((off & (aln - 1)) != 0) { off = (off + aln - 1) & ~(aln - 1); }; - let fi: *field_info = amalloc(c.a, 48u64): *field_info; + let fi: *fieldinfo = amalloc(c.a, 48u64): *fieldinfo; fi.fname = f.str; fi.foff = off; fi.fsz = sz; @@ -6003,7 +6003,7 @@ fn register_struct(c: *cgen, name: str, tstruct: *node) void = { c.structs = si; }; -fn collect_structs(c: *cgen, file: *node) void = { +fn collectstructs(c: *cgen, file: *node) void = { c.structs = nil; if (file == nil) { return; }; let d: *node = file.list; @@ -6012,7 +6012,7 @@ fn collect_structs(c: *cgen, file: *node) void = { let body: *node = d.lhs; if (body != nil) { if (body.kind == N_TSTRUCT) { - register_struct(c, d.str, body); + registerstruct(c, d.str, body); }; }; }; @@ -6023,21 +6023,21 @@ fn collect_structs(c: *cgen, file: *node) void = { // ---- frame pre-scan -------------------------------------------------- // // Recursively walks the body to count every local `let`. Each gets a -// slot sized by slot_size(typ); 8-byte default. Match-bindings + for- +// slot sized by slotsize(typ); 8-byte default. Match-bindings + for- // init lets count too. Params are added by the cgfn driver. -fn scan_locals(c: *cgen, n: *node) i32 = { +fn scanlocals(c: *cgen, n: *node) i32 = { if (n == nil) { return 0; }; let total: i32 = 0; if (n.kind == N_LET) { - // Match local_add's rounding: < 8 bumps to 8, then 8-align. - // scan_locals must agree with local_add or the prologue + // 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 // caller's stack — corrupting whatever's at -frameSize..-1 // of the caller. Same-name re-declarations share the first - // slot (see scan_seen_mark / local_add). - if (!scan_seen_mark(c, n.str)) { - let sz: i32 = slot_size(c, n.lhs); + // slot (see scanseenmark / localadd). + if (!scanseenmark(c, n.str)) { + let sz: i32 = slotsize(c, n.lhs); if (sz < 8) { sz = 8; }; if ((sz & 7) != 0) { sz = (sz + 7) & ~7; }; total += sz; @@ -6048,26 +6048,26 @@ fn scan_locals(c: *cgen, n: *node) i32 = { // handles a match as an expression with a by-value locals copy, // 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 local_add then bumps it to. + // shrink the frame below what localadd then bumps it to. if (n.kind == N_MCASE) { let bn: str = n.str; if (bn.len > 0) { let pat: *node = n.lhs; if (pat != nil) { - if (is_str_type(c, pat)) { total += 16; } + if (isstrtype(c, pat)) { total += 16; } else { total += 8; }; }; }; }; - if (n.lhs != nil) { total += scan_locals(c, n.lhs); }; - if (n.rhs != nil) { total += scan_locals(c, n.rhs); }; - if (n.cond != nil) { total += scan_locals(c, n.cond); }; - if (n.body != nil) { total += scan_locals(c, n.body); }; - if (n.els != nil) { total += scan_locals(c, n.els); }; + if (n.lhs != nil) { total += scanlocals(c, n.lhs); }; + if (n.rhs != nil) { total += scanlocals(c, n.rhs); }; + if (n.cond != nil) { total += scanlocals(c, n.cond); }; + if (n.body != nil) { total += scanlocals(c, n.body); }; + if (n.els != nil) { total += scanlocals(c, n.els); }; if (n.list != nil) { let m: *node = n.list; for (m != nil) { - total += scan_locals(c, m); + total += scanlocals(c, m); m = m.next; }; }; @@ -6101,16 +6101,16 @@ fn cgstmt(c: *cgen, n: *node) void = { let v2: *node = v.next; if (v2 != nil) { cgexpr(c, v2); - emit_line("\tPUSHQ\tAX\n"); + emitline("\tPUSHQ\tAX\n"); cgexpr(c, v); - emit_line("\tPOPQ\tDX\n"); + emitline("\tPOPQ\tDX\n"); } else { cgexpr(c, v); }; }; - emit_line("\tMOVQ\tBP, SP\n"); - emit_line("\tPOPQ\tBP\n"); - emit_line("\tRET\n"); + emitline("\tMOVQ\tBP, SP\n"); + emitline("\tPOPQ\tBP\n"); + emitline("\tRET\n"); c.last_was_return = 1; return; }; @@ -6118,22 +6118,22 @@ fn cgstmt(c: *cgen, n: *node) void = { // For str variant, cgexpr leaves (AX=ptr, BX=len), so we // shuffle DX←AX (ptr) and CX←BX (len), then load tag. // For other variants, cgexpr leaves AX, shuffle DX←AX. - if (is_tagged_type(c.fn_ret)) { + if (istaggedtype(c.fn_ret)) { cgexpr(c, rhs); - let idx: i32 = tagged_variant_index(c, c.fn_ret, rhs); - if (node_isstr(c, rhs)) { - emit_line("\tMOVQ\tBX, CX\n"); - emit_line("\tMOVQ\tAX, DX\n"); + let idx: i32 = taggedvariantindex(c, c.fn_ret, rhs); + if (nodeisstr(c, rhs)) { + emitline("\tMOVQ\tBX, CX\n"); + emitline("\tMOVQ\tAX, DX\n"); } else { - emit_line("\tMOVQ\tAX, DX\n"); + emitline("\tMOVQ\tAX, DX\n"); }; - emit_line("\tMOVQ\t$"); + emitline("\tMOVQ\t$"); if (idx < 0) { idx = 0; }; - emit_int(idx: i64); - emit_line(", AX\n"); - emit_line("\tMOVQ\tBP, SP\n"); - emit_line("\tPOPQ\tBP\n"); - emit_line("\tRET\n"); + emitint(idx: i64); + emitline(", AX\n"); + emitline("\tMOVQ\tBP, SP\n"); + emitline("\tPOPQ\tBP\n"); + emitline("\tRET\n"); c.last_was_return = 1; return; }; @@ -6142,16 +6142,16 @@ fn cgstmt(c: *cgen, n: *node) void = { // Bare `return;` in a void fn — zero AX so the caller // sees a deterministic value (matches C cgen, which // always falls through to `cgexpr_int(c, 0)`). - emit_line("\tMOVQ\t$0, AX\n"); + emitline("\tMOVQ\t$0, AX\n"); }; // SysV: 16-byte aggregates (str, 2-tuple) return in (AX, DX). // cgexpr leaves str in (AX, BX); shuffle BX→DX. - if (is_str_type(c, c.fn_ret)) { - emit_line("\tMOVQ\tBX, DX\n"); + if (isstrtype(c, c.fn_ret)) { + emitline("\tMOVQ\tBX, DX\n"); }; - emit_line("\tMOVQ\tBP, SP\n"); - emit_line("\tPOPQ\tBP\n"); - emit_line("\tRET\n"); + emitline("\tMOVQ\tBP, SP\n"); + emitline("\tPOPQ\tBP\n"); + emitline("\tRET\n"); c.last_was_return = 1; return; }; @@ -6164,8 +6164,8 @@ fn cgstmt(c: *cgen, n: *node) void = { if (k == N_LET) { let nm: str = n.str; - let sz: i32 = slot_size(c, n.lhs); - let off: i32 = local_add(c, nm, sz, n.lhs); + let sz: i32 = slotsize(c, n.lhs); + let off: i32 = localadd(c, nm, sz, n.lhs); if (n.rhs != nil) { let rhs: *node = n.rhs; // Tagged-union init: `let r: (T | E) = expr;`. @@ -6174,54 +6174,54 @@ fn cgstmt(c: *cgen, n: *node) void = { // just spill all three. // - Otherwise rhs is a bare variant value: pack tag + // value(s). - if (is_tagged_type(n.lhs)) { - let rhs_returns_tagged: bool = false; + if (istaggedtype(n.lhs)) { + let rhsreturnstagged: bool = false; if (rhs.kind == N_CALL) { let callee: *node = rhs.lhs; if (callee != nil) { - let callee_name: str; - callee_name.ptr = nil; callee_name.len = 0; - if (callee.kind == N_IDENT) { callee_name = callee.str; }; - if (callee.kind == N_DOT) { callee_name = callee.str; }; - if (callee_name.len > 0) { - let rt: *node = fnret_lookup(c, callee_name); - if (is_tagged_type(rt)) { rhs_returns_tagged = true; }; + 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 (calleename.len > 0) { + let rt: *node = fnretlookup(c, calleename); + if (istaggedtype(rt)) { rhsreturnstagged = true; }; }; }; }; cgexpr(c, rhs); - if (rhs_returns_tagged) { - emit_line("\tMOVQ\tAX, "); - emit_off(off: i64); - emit_line("(BP)\n"); - emit_line("\tMOVQ\tDX, "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); - emit_line("\tMOVQ\tCX, "); - emit_off((off + 16): i64); - emit_line("(BP)\n"); + if (rhsreturnstagged) { + emitline("\tMOVQ\tAX, "); + emitoff(off: i64); + emitline("(BP)\n"); + emitline("\tMOVQ\tDX, "); + emitoff((off + 8): i64); + emitline("(BP)\n"); + emitline("\tMOVQ\tCX, "); + emitoff((off + 16): i64); + emitline("(BP)\n"); c.last_was_return = 0; return; }; - let tag_idx: i32 = tagged_variant_index(c, n.lhs, rhs); - if (tag_idx < 0) { tag_idx = 0; }; - if (node_isstr(c, rhs)) { - emit_line("\tMOVQ\tAX, "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); - emit_line("\tMOVQ\tBX, "); - emit_off((off + 16): i64); - emit_line("(BP)\n"); + let tagidx: i32 = taggedvariantindex(c, n.lhs, rhs); + if (tagidx < 0) { tagidx = 0; }; + if (nodeisstr(c, rhs)) { + emitline("\tMOVQ\tAX, "); + emitoff((off + 8): i64); + emitline("(BP)\n"); + emitline("\tMOVQ\tBX, "); + emitoff((off + 16): i64); + emitline("(BP)\n"); } else { - emit_line("\tMOVQ\tAX, "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tAX, "); + emitoff((off + 8): i64); + emitline("(BP)\n"); }; - emit_line("\tMOVQ\t$"); - emit_int(tag_idx: i64); - emit_line(", "); - emit_off(off: i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\t$"); + emitint(tagidx: i64); + emitline(", "); + emitoff(off: i64); + emitline("(BP)\n"); c.last_was_return = 0; return; }; @@ -6237,53 +6237,53 @@ fn cgstmt(c: *cgen, n: *node) void = { if (trefn.kind == N_IDENT) { sname = trefn.str; } else { if (trefn.kind == N_TNAME) { sname = trefn.str; }; }; }; - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let field_node: *node = rhs.list; - for (field_node != nil) { - if (field_node.kind == N_FIELD) { - let fname: str = field_node.str; - let fi: *field_info = si.fields; + let fieldnode: *node = rhs.list; + for (fieldnode != nil) { + if (fieldnode.kind == N_FIELD) { + let fname: str = fieldnode.str; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fname)) { - cgexpr(c, field_node.lhs); - let sop: str = field_store_op(fi); - emit_line("\t"); - emit_line(sop); - emit_line("\tAX, "); - emit_off((off + fi.foff): i64); - emit_line("(BP)\n"); + cgexpr(c, fieldnode.lhs); + let sop: str = fieldstoreop(fi); + emitline("\t"); + emitline(sop); + emitline("\tAX, "); + emitoff((off + fi.foff): i64); + emitline("(BP)\n"); fi = nil; } else { fi = fi.finext; }; }; }; - field_node = field_node.next; + fieldnode = fieldnode.next; }; c.last_was_return = 0; return; }; }; cgexpr(c, rhs); - emit_line("\tMOVQ\tAX, "); - emit_off(off: i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tAX, "); + emitoff(off: i64); + emitline("(BP)\n"); // str init: cgexpr also leaves len in BX; store both. if (sz == 16) { - emit_line("\tMOVQ\tBX, "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tBX, "); + emitoff((off + 8): i64); + emitline("(BP)\n"); }; // slice init: ptr/len/cap in AX/BX/CX. if (sz == 24) { - emit_line("\tMOVQ\tBX, "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); - emit_line("\tMOVQ\tCX, "); - emit_off((off + 16): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tBX, "); + emitoff((off + 8): i64); + emitline("(BP)\n"); + emitline("\tMOVQ\tCX, "); + emitoff((off + 16): i64); + emitline("(BP)\n"); }; } else { // Bare `let x: T;` with no initializer. C cgen @@ -6291,13 +6291,13 @@ fn cgstmt(c: *cgen, n: *node) void = { // the underlying type's natural size is 8 — pointers, // i64/u64, function pointers, ints. Structs/arrays/ // slices/strings/tagged/tuples are left for per-field - // writes. ww's slot_size pads struct slots up to 8, + // writes. ww's slotsize pads struct slots up to 8, // so we can't just check sz == 8: walk the type AST // directly to make the same call. - if (type_is_8byte_primitive(c, n.lhs)) { - emit_line("\tMOVQ\t$0, "); - emit_off(off: i64); - emit_line("(BP)\n"); + if (typeis8byteprimitive(c, n.lhs)) { + emitline("\tMOVQ\t$0, "); + emitoff(off: i64); + emitline("(BP)\n"); }; }; c.last_was_return = 0; @@ -6308,18 +6308,18 @@ fn cgstmt(c: *cgen, n: *node) void = { let els: str = mklabel(c, "else"); let endl: str = mklabel(c, "end"); cgexpr(c, n.cond); - emit_line("\tCMPQ\t$0, AX\n"); - emit_line("\tJE\t"); - if (n.els != nil) { emit_line(els); } - else { emit_line(endl); }; - emit_line("\n"); + emitline("\tCMPQ\t$0, AX\n"); + emitline("\tJE\t"); + if (n.els != nil) { emitline(els); } + else { emitline(endl); }; + emitline("\n"); if (n.body != nil) { cgstmt(c, n.body); }; if (n.els != nil) { - emit_line("\tJMP\t"); emit_line(endl); emit_line("\n"); - emit_label(els); + emitline("\tJMP\t"); emitline(endl); emitline("\n"); + emitlabel(els); cgstmt(c, n.els); }; - emit_label(endl); + emitlabel(endl); c.last_was_return = 0; return; }; @@ -6333,11 +6333,11 @@ fn cgstmt(c: *cgen, n: *node) void = { if (n.lhs != nil) { cgstmt(c, n.lhs); }; - emit_label(topl); + emitlabel(topl); if (n.cond != nil) { cgexpr(c, n.cond); - emit_line("\tCMPQ\t$0, AX\n"); - emit_line("\tJE\t"); emit_line(endl); emit_line("\n"); + emitline("\tCMPQ\t$0, AX\n"); + emitline("\tJE\t"); emitline(endl); emitline("\n"); }; c.loop_end_buf[c.loop_top] = endl; @@ -6349,8 +6349,8 @@ fn cgstmt(c: *cgen, n: *node) void = { c.loop_top -= 1; if (n.rhs != nil) { cgexpr(c, n.rhs); }; - emit_line("\tJMP\t"); emit_line(topl); emit_line("\n"); - emit_label(endl); + emitline("\tJMP\t"); emitline(topl); emitline("\n"); + emitlabel(endl); c.last_was_return = 0; return; }; @@ -6362,28 +6362,28 @@ fn cgstmt(c: *cgen, n: *node) void = { // as C — no fixture uses >2 today). if (k == N_MASSIGN) { if (n.rhs != nil) { cgexpr(c, n.rhs); }; - emit_line("\tPUSHQ\tDX\n"); + emitline("\tPUSHQ\tDX\n"); let l0: *node = n.list; let l1: *node = nil; if (l0 != nil) { l1 = l0.next; }; if (l0 != nil) { if (l0.kind == N_IDENT) { - let off: i32 = local_find(c, l0.str); + let off: i32 = localfind(c, l0.str); if (off != 0) { - emit_line("\tMOVQ\tAX, "); - emit_off(off: i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tAX, "); + emitoff(off: i64); + emitline("(BP)\n"); }; }; }; - emit_line("\tPOPQ\tDX\n"); + emitline("\tPOPQ\tDX\n"); if (l1 != nil) { if (l1.kind == N_IDENT) { - let off: i32 = local_find(c, l1.str); + let off: i32 = localfind(c, l1.str); if (off != 0) { - emit_line("\tMOVQ\tDX, "); - emit_off(off: i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tDX, "); + emitoff(off: i64); + emitline("(BP)\n"); }; }; }; @@ -6394,7 +6394,7 @@ fn cgstmt(c: *cgen, n: *node) void = { if (k == N_BREAK) { if (c.loop_top > 0) { let lbl: str = c.loop_end_buf[c.loop_top - 1]; - emit_line("\tJMP\t"); emit_line(lbl); emit_line("\n"); + emitline("\tJMP\t"); emitline(lbl); emitline("\n"); }; c.last_was_return = 0; return; @@ -6402,7 +6402,7 @@ fn cgstmt(c: *cgen, n: *node) void = { if (k == N_CONTINUE) { if (c.loop_top > 0) { let lbl: str = c.loop_cont_buf[c.loop_top - 1]; - emit_line("\tJMP\t"); emit_line(lbl); emit_line("\n"); + emitline("\tJMP\t"); emitline(lbl); emitline("\n"); }; c.last_was_return = 0; return; @@ -6413,10 +6413,10 @@ fn cgstmt(c: *cgen, n: *node) void = { // ---- function-level cgen --------------------------------------------- -// is_str_type — true when the type expr resolves (through any +// isstrtype — true when the type expr resolves (through any // `type X = str;` aliases) to `str`. Takes *cgen so it can walk the // alias chain registered at file load. -fn is_str_type_raw(t: *node) bool = { +fn isstrtyperaw(t: *node) bool = { if (t == nil) { return false; }; if (t.kind == N_TNAME) { let nm: str = t.str; @@ -6425,36 +6425,36 @@ fn is_str_type_raw(t: *node) bool = { return false; }; -fn is_str_type(c: *cgen, t: *node) bool = { - if (is_str_type_raw(t)) { return true; }; +fn isstrtype(c: *cgen, t: *node) bool = { + if (isstrtyperaw(t)) { return true; }; if (c == nil) { return false; }; - let r: *node = resolve_type(c, t); - return is_str_type_raw(r); + let r: *node = resolvetype(c, t); + return isstrtyperaw(r); }; -fn is_slice_type_raw(t: *node) bool = { +fn isslicetyperaw(t: *node) bool = { if (t == nil) { return false; }; if (t.kind == N_TSLICE) { return true; }; return false; }; -fn is_slice_type(c: *cgen, t: *node) bool = { - if (is_slice_type_raw(t)) { return true; }; +fn isslicetype(c: *cgen, t: *node) bool = { + if (isslicetyperaw(t)) { return true; }; if (c == nil) { return false; }; - let r: *node = resolve_type(c, t); - return is_slice_type_raw(r); + let r: *node = resolvetype(c, t); + return isslicetyperaw(r); }; -fn is_tagged_type(t: *node) bool = { +fn istaggedtype(t: *node) bool = { if (t == nil) { return false; }; if (t.kind == N_TTAGGED) { return true; }; return false; }; -// rhs_target_name — for a returned value, what's its declared (or +// rhstargetname — for a returned value, what's its declared (or // surface-inferred) type name? `expr: T` casts dictate T directly; // bare strlit/intlit fall back to a primitive name. -fn rhs_target_name(c: *cgen, rhs: *node) str = { +fn rhstargetname(c: *cgen, rhs: *node) str = { let nm: str; nm.ptr = nil; nm.len = 0; if (rhs == nil) { return nm; }; @@ -6467,7 +6467,7 @@ fn rhs_target_name(c: *cgen, rhs: *node) str = { }; if (rhs.kind == N_STRLIT) { return "str"; }; if (rhs.kind == N_IDENT) { - let lc: *local = local_find_node(c, rhs.str); + let lc: *local = localfindnode(c, rhs.str); if (lc != nil) { let tn: *node = lc.tnode; if (tn != nil) { @@ -6478,113 +6478,113 @@ fn rhs_target_name(c: *cgen, rhs: *node) str = { return nm; }; -// tagged_variant_index — given the tagged-union type expr and the +// taggedvariantindex — given the tagged-union type expr and the // returned value's surface type, find the matching variant's 0-based // index. Compare by exact type name first; if no match, fall back to // "any str-shape variant matches an str-typed value". -fn tagged_variant_index(c: *cgen, tagged: *node, rhs: *node) i32 = { +fn taggedvariantindex(c: *cgen, tagged: *node, rhs: *node) i32 = { if (tagged == nil) { return -1; }; if (rhs == nil) { return -1; }; - let want_name: str = rhs_target_name(c, rhs); - if (want_name.len > 0) { + let wantname: str = rhstargetname(c, rhs); + if (wantname.len > 0) { let v: *node = tagged.list; let idx: i32 = 0; for (v != nil) { if (v.kind == N_TNAME) { - if (streq(v.str, want_name)) { return idx; }; + if (streq(v.str, wantname)) { return idx; }; }; v = v.next; idx += 1; }; }; // Fallback: by str-shape (resolves aliases). - let want_str: bool = node_isstr(c, rhs); + let wantstr: bool = nodeisstr(c, rhs); let v: *node = tagged.list; let idx: i32 = 0; for (v != nil) { - let v_is_str: bool = false; + let visstr: bool = false; if (v.kind == N_TNAME) { - if (is_str_type(c, v)) { v_is_str = true; }; + if (isstrtype(c, v)) { visstr = true; }; }; - if (v_is_str == want_str) { return idx; }; + if (visstr == wantstr) { return idx; }; v = v.next; idx += 1; }; return -1; }; -fn cgfn_params(c: *cgen, params: *node) void = { +fn cgfnparams(c: *cgen, params: *node) void = { let p: *node = params; let idx: i32 = 0; for (p != nil) { if (p.kind == N_PARAM) { let nm: str = p.str; - if (is_tagged_type(p.lhs)) { + if (istaggedtype(p.lhs)) { // tagged-union param: passed in 3 regs (tag, v0, v1), // 24-byte slot. - let off: i32 = local_add(c, nm, 24, p.lhs); - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off(off: i64); - emit_line("(BP)\n"); + let off: i32 = localadd(c, nm, 24, p.lhs); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff(off: i64); + emitline("(BP)\n"); idx += 1; - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff((off + 8): i64); + emitline("(BP)\n"); idx += 1; - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off((off + 16): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff((off + 16): i64); + emitline("(BP)\n"); idx += 1; - } else { if (is_slice_type(c, p.lhs)) { + } else { if (isslicetype(c, p.lhs)) { // slice param: 3 regs (ptr, len, cap), 24-byte slot. - let off: i32 = local_add(c, nm, 24, p.lhs); - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off(off: i64); - emit_line("(BP)\n"); + let off: i32 = localadd(c, nm, 24, p.lhs); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff(off: i64); + emitline("(BP)\n"); idx += 1; - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff((off + 8): i64); + emitline("(BP)\n"); idx += 1; - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off((off + 16): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff((off + 16): i64); + emitline("(BP)\n"); idx += 1; - } else { if (is_str_type(c, p.lhs)) { + } else { if (isstrtype(c, p.lhs)) { // str param: passed in two regs (ptr, len). // Slot is 16 bytes; ptr at off+0, len at off+8. - let off: i32 = local_add(c, nm, 16, p.lhs); - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off(off: i64); - emit_line("(BP)\n"); + let off: i32 = localadd(c, nm, 16, p.lhs); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff(off: i64); + emitline("(BP)\n"); idx += 1; - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff((off + 8): i64); + emitline("(BP)\n"); idx += 1; } else { - let off: i32 = local_add(c, nm, 8, p.lhs); - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off(off: i64); - emit_line("(BP)\n"); + let off: i32 = localadd(c, nm, 8, p.lhs); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff(off: i64); + emitline("(BP)\n"); idx += 1; };};}; }; @@ -6593,48 +6593,48 @@ fn cgfn_params(c: *cgen, params: *node) void = { }; fn cgfn(c: *cgen, fn_: *node) void = { - cgen_init(c, c.a); + cgeninit(c, c.a); c.fn_name = fn_.str; c.fn_ret = fn_.lhs; - emit_line("TEXT "); + emitline("TEXT "); let nm: str = fn_.str; os.write(1, nm.ptr, nm.len: u64); - emit_line(",$"); + emitline(",$"); // Pre-scan total frame: 24 bytes per slice param, 16 per str - // param, 8 per other param, plus per-let from scan_locals. - // Seed c.locals with param-name stubs so scan_locals dedups a + // param, 8 per other param, plus per-let from scanlocals. + // Seed c.locals with param-name stubs so scanlocals dedups a // re-declared `let ` in the body against the param's // slot (matches C cgen). Stubs get cleared before emission. - let scan_p: *node = fn_.list; + let scanp: *node = fn_.list; let frame: i32 = 0; - for (scan_p != nil) { - if (scan_p.kind == N_PARAM) { - if (is_tagged_type(scan_p.lhs)) { frame += 24; } - else { if (is_slice_type(c, scan_p.lhs)) { frame += 24; } - else { if (is_str_type(c, scan_p.lhs)) { frame += 16; } + for (scanp != nil) { + if (scanp.kind == N_PARAM) { + if (istaggedtype(scanp.lhs)) { frame += 24; } + else { if (isslicetype(c, scanp.lhs)) { frame += 24; } + else { if (isstrtype(c, scanp.lhs)) { frame += 16; } else { frame += 8; }; }; }; - scan_seen_mark(c, scan_p.str); + scanseenmark(c, scanp.str); }; - scan_p = scan_p.next; + scanp = scanp.next; }; - if (fn_.body != nil) { frame += scan_locals(c, fn_.body); }; + if (fn_.body != nil) { frame += scanlocals(c, fn_.body); }; // Drop the stubs so emission rebuilds c.locals with real offsets. c.locals = nil; if ((frame & 15) != 0) { frame = (frame + 15) & ~15; }; - emit_int(frame: i64); - emit_line("\n"); + emitint(frame: i64); + emitline("\n"); - emit_line("\tPUSHQ\tBP\n"); - emit_line("\tMOVQ\tSP, BP\n"); - emit_line("\tSUBQ\t$"); - emit_int(frame: i64); - emit_line(", SP\n"); + emitline("\tPUSHQ\tBP\n"); + emitline("\tMOVQ\tSP, BP\n"); + emitline("\tSUBQ\t$"); + emitint(frame: i64); + emitline(", SP\n"); - cgfn_params(c, fn_.list); + cgfnparams(c, fn_.list); c.last_was_return = 0; if (fn_.body != nil) { cgstmt(c, fn_.body); }; @@ -6642,24 +6642,24 @@ fn cgfn(c: *cgen, fn_: *node) void = { // Zero AX before the fall-through return — matches C cgen, // which always emits this so void-returning fns don't leak // a stale callee value to their caller. - emit_line("\tMOVQ\t$0, AX\n"); - emit_line("\tMOVQ\tBP, SP\n"); - emit_line("\tPOPQ\tBP\n"); - emit_line("\tRET\n"); + emitline("\tMOVQ\t$0, AX\n"); + emitline("\tMOVQ\tBP, SP\n"); + emitline("\tPOPQ\tBP\n"); + emitline("\tRET\n"); }; }; // ---- file-level entry ------------------------------------------------ -export fn cg_file(c: *cgen, file: *node) void = { +export fn cgfile(c: *cgen, file: *node) void = { if (file == nil) { return; }; c.strlits = nil; c.strlit_seq = 0; - collect_aliases(c, file); - collect_structs(c, file); - collect_defs(c, file); - collect_fnrets(c, file); - ffi_collect(c, file); + collectaliases(c, file); + collectstructs(c, file); + collectdefs(c, file); + collectfnrets(c, file); + fficollect(c, file); let d: *node = file.list; for (d != nil) { if (d.kind == N_FNDECL) { @@ -6669,8 +6669,8 @@ export fn cg_file(c: *cgen, file: *node) void = { }; d = d.next; }; - emit_data_section(c); - emit_def_constants(c, file); + emitdatasection(c); + emitdefconstants(c, file); }; // selfhost/cmd/w6c/main.ww — port of cmd/w6c/main.c. @@ -6682,7 +6682,7 @@ export fn cg_file(c: *cgen, file: *node) void = { // // The cgen routines in selfhost/cmd/wcc/cgen.ww write directly to // fd 1 via os.write(1, ...). For -o, we open the output file and -// dup2 it onto fd 1 before invoking cg_file. This is the same trick +// dup2 it onto fd 1 before invoking cgfile. This is the same trick // the bootstrap uses with shell redirection, just in-process. use os; @@ -6798,8 +6798,8 @@ export fn main(argc: i32, argv: **u8) i32 = { let f: *node = parsefile(&ps); let cg: cgen; - cgen_init(&cg, ar); - cg_file(&cg, f); + cgeninit(&cg, ar); + cgfile(&cg, f); if (l.errs > 0) { return 1; }; return 0; diff --git a/selfhost/cmd/w6c/main.ww b/selfhost/cmd/w6c/main.ww index cc638e6e..905eaf99 100644 --- a/selfhost/cmd/w6c/main.ww +++ b/selfhost/cmd/w6c/main.ww @@ -7,7 +7,7 @@ // // The cgen routines in selfhost/cmd/wcc/cgen.ww write directly to // fd 1 via os.write(1, ...). For -o, we open the output file and -// dup2 it onto fd 1 before invoking cg_file. This is the same trick +// dup2 it onto fd 1 before invoking cgfile. This is the same trick // the bootstrap uses with shell redirection, just in-process. use os; @@ -123,8 +123,8 @@ export fn main(argc: i32, argv: **u8) i32 = { let f: *node = parsefile(&ps); let cg: cgen; - cgen_init(&cg, ar); - cg_file(&cg, f); + cgeninit(&cg, ar); + cgfile(&cg, f); if (l.errs > 0) { return 1; }; return 0; diff --git a/selfhost/cmd/wcc/cgen.ww b/selfhost/cmd/wcc/cgen.ww index b63e64cf..cb79a866 100644 --- a/selfhost/cmd/wcc/cgen.ww +++ b/selfhost/cmd/wcc/cgen.ww @@ -33,17 +33,17 @@ use strconv; // ---- typedef alias registry ----------------------------------------- // // `type error = str;` makes `error` a struct-shape alias. We track -// alias→target so is_str_type / is_slice_type / struct_lookup can +// alias→target so isstrtype / isslicetype / structlookup can // resolve through the chain. Only direct N_TNAME aliases are mapped; -// `type p = struct {...}` is handled by collect_structs. +// `type p = struct {...}` is handled by collectstructs. -type alias_ent = struct { +type aliasent = struct { aname: str, target: *node, // the rhs type expr - aanext: *alias_ent, + aanext: *aliasent, }; -fn collect_aliases(c: *cgen, file: *node) void = { +fn collectaliases(c: *cgen, file: *node) void = { c.aliases = nil; let d: *node = file.list; for (d != nil) { @@ -51,7 +51,7 @@ fn collect_aliases(c: *cgen, file: *node) void = { let body: *node = d.lhs; if (body != nil) { if (body.kind != N_TSTRUCT) { - let a: *alias_ent = amalloc(c.a, 32u64): *alias_ent; + let a: *aliasent = amalloc(c.a, 32u64): *aliasent; a.aname = d.str; a.target = body; a.aanext = c.aliases; @@ -63,8 +63,8 @@ fn collect_aliases(c: *cgen, file: *node) void = { }; }; -fn alias_lookup(c: *cgen, name: str) *node = { - let a: *alias_ent = c.aliases; +fn aliaslookup(c: *cgen, name: str) *node = { + let a: *aliasent = c.aliases; for (a != nil) { let an: str = a.aname; if (streq(an, name)) { return a.target; }; @@ -73,16 +73,16 @@ fn alias_lookup(c: *cgen, name: str) *node = { return nil; }; -// resolve_type — follow typedef alias chains to a "canonical" type +// resolvetype — follow typedef alias chains to a "canonical" type // expr (str/slice/array/struct/...). Stops on cycles via depth limit. -fn resolve_type(c: *cgen, t: *node) *node = { +fn resolvetype(c: *cgen, t: *node) *node = { let cur: *node = t; let depth: i32 = 0; for (depth < 16) { if (cur == nil) { return nil; }; if (cur.kind != N_TNAME) { return cur; }; let nm: str = cur.str; - let next: *node = alias_lookup(c, nm); + let next: *node = aliaslookup(c, nm); if (next == nil) { return cur; }; cur = next; depth += 1; @@ -93,23 +93,23 @@ fn resolve_type(c: *cgen, t: *node) *node = { // ---- struct registry ------------------------------------------------ // // Per-file map from struct name → list of fields with computed offsets -// and sizes. Built when cg_file walks N_TYPEDECL with N_TSTRUCT lhs. +// and sizes. Built when cgfile walks N_TYPEDECL with N_TSTRUCT lhs. // N_DOT and N_ASSIGN consult this to resolve `s.field` for struct or // *struct bases. -type field_info = struct { +type fieldinfo = struct { fname: str, foff: i32, fsz: i32, tnode: *node, // the field type expr, for nested struct lookups - finext: *field_info, + finext: *fieldinfo, }; -type struct_info = struct { +type structinfo = struct { sname: str, - fields: *field_info, + fields: *fieldinfo, tot_size: i32, - sinext: *struct_info, + sinext: *structinfo, }; // ---- locals / frame -------------------------------------------------- @@ -148,10 +148,10 @@ type cgen = struct { strlit_seq: i32, strlits: *strlit, ffis: *ffi, - defs: *def_ent, + defs: *defent, fnrets: *fnret, - aliases: *alias_ent, - structs: *struct_info, + aliases: *aliasent, + structs: *structinfo, fn_name: str, fn_ret: *node, // declared return type of current fn (or nil) loop_top: i32, @@ -159,26 +159,26 @@ type cgen = struct { loop_cont_buf: *str, // stack of cont labels for continue }; -fn cgen_init(c: *cgen, a: *arena) void = { +fn cgeninit(c: *cgen, a: *arena) void = { c.a = a; c.locals = nil; c.frame = 0; c.last_was_return = 0; c.labelseq = 0; // Note: strlit_seq, strlits, ffis are *not* reset here; they - // persist across cgfn calls within one file. cg_file resets them + // persist across cgfn calls within one file. cgfile resets them // at the start of each compilation unit. c.loop_top = 0; c.loop_end_buf = amalloc(a, (LOOP_MAX: u64) * 16u64): *str; c.loop_cont_buf = amalloc(a, (LOOP_MAX: u64) * 16u64): *str; }; -// local_alloc — append a slot for `name` without dedup. Used for +// localalloc — append a slot for `name` without dedup. Used for // match-arm bindings, which C cgen allocates via cgexpr's by-value // `locals` list — so two separate matches each get fresh slots even -// when their bind names collide. scan_locals follows the same rule +// when their bind names collide. scanlocals follows the same rule // for N_MCASE. -fn local_alloc(c: *cgen, name: str, sz: i32, tnode: *node) i32 = { +fn localalloc(c: *cgen, name: str, sz: i32, tnode: *node) i32 = { let asz: i32 = sz; if (asz < 8) { asz = 8; }; if ((asz & 7) != 0) { asz = (asz + 7) & ~7; }; @@ -193,13 +193,13 @@ fn local_alloc(c: *cgen, name: str, sz: i32, tnode: *node) i32 = { return off; }; -fn local_add(c: *cgen, name: str, sz: i32, tnode: *node) i32 = { +fn localadd(c: *cgen, name: str, sz: i32, tnode: *node) i32 = { // Name-based slot reuse for N_LETs and params: if `name` is // already declared in this function, return its existing // offset. Mirrors C cgen (cmd/w6c/cgen.c:localoff). Two // disjoint scopes that declare the same name share one slot — // so `escape` in wwdump (three `let cp: pos;` across separate - // branches) reserves one slot, not three. scan_locals does + // branches) reserves one slot, not three. scanlocals does // the matching dedup at prologue time so the SUBQ stays in // sync. // @@ -218,16 +218,16 @@ fn local_add(c: *cgen, name: str, sz: i32, tnode: *node) i32 = { }; cur = cur.lnext; }; - return local_alloc(c, name, sz, tnode); + return localalloc(c, name, sz, tnode); }; -// scan_seen_mark — called by scan_locals on every let / match-bind +// scanseenmark — called by scanlocals on every let / match-bind // site. Returns true if `name` is already tracked in c.locals (so // the slot will be shared at emission time — no new frame bump). // Otherwise appends a name-only stub and returns false. Stubs are // thrown away when cgfn resets c.locals before emission. -fn scan_seen_mark(c: *cgen, name: str) bool = { - if (local_find_node(c, name) != nil) { return true; }; +fn scanseenmark(c: *cgen, name: str) bool = { + if (localfindnode(c, name) != nil) { return true; }; let l: *local = amalloc(c.a, 48u64): *local; l.name = name; l.off = 0; @@ -237,7 +237,7 @@ fn scan_seen_mark(c: *cgen, name: str) bool = { return false; }; -fn local_find_node(c: *cgen, name: str) *local = { +fn localfindnode(c: *cgen, name: str) *local = { let l: *local = c.locals; for (l != nil) { let ln: str = l.name; @@ -247,7 +247,7 @@ fn local_find_node(c: *cgen, name: str) *local = { return nil; }; -fn local_find(c: *cgen, name: str) i32 = { +fn localfind(c: *cgen, name: str) i32 = { let l: *local = c.locals; for (l != nil) { let ln: str = l.name; @@ -267,34 +267,34 @@ fn local_find(c: *cgen, name: str) i32 = { // ---- emit helpers --------------------------------------------------- -fn emit_line(s: str) void = { os.write(1, s.ptr, s.len: u64); }; +fn emitline(s: str) void = { os.write(1, s.ptr, s.len: u64); }; -fn emit_int(v: i64) void = { +fn emitint(v: i64) void = { let buf: [32]u8; let n: i32 = strconv.i64toa(buf[0:32], v); os.write(1, buf.ptr, n: u64); }; -fn emit_uint(v: u64) void = { +fn emituint(v: u64) void = { let buf: [32]u8; let n: i32 = strconv.u64toa(buf[0:32], v); os.write(1, buf.ptr, n: u64); }; -// emit_disp_reg — print "disp(reg)" or "(reg)" when disp == 0, the +// emitdispreg — print "disp(reg)" or "(reg)" when disp == 0, the // way Plan 9 6c/6a do. -fn emit_disp_reg(off: i64, reg: str) void = { - if (off != 0i64) { emit_int(off); }; - emit_line("("); - emit_line(reg); - emit_line(")"); +fn emitdispreg(off: i64, reg: str) void = { + if (off != 0i64) { emitint(off); }; + emitline("("); + emitline(reg); + emitline(")"); }; -// emit_off — print an integer offset, suppressing it entirely when 0. -// Use before any emit_line("(BP)...") or emit_line("(SB)...") sequence. +// emitoff — print an integer offset, suppressing it entirely when 0. +// Use before any emitline("(BP)...") or emitline("(SB)...") sequence. // Plan 9 cc convention: "(BP)" not "0(BP)". -fn emit_off(v: i64) void = { - if (v != 0i64) { emit_int(v); }; +fn emitoff(v: i64) void = { + if (v != 0i64) { emitint(v); }; }; // mklabel — fresh label "__". Returns an @@ -331,18 +331,18 @@ fn mklabel(c: *cgen, base: str) str = { return r; }; -fn emit_label(s: str) void = { +fn emitlabel(s: str) void = { os.write(1, s.ptr, s.len: u64); - emit_line(":\n"); + emitline(":\n"); }; // ---- string interning ------------------------------------------------ // // streq is provided by sym.ww and reused here. -// intern_strlit — return a stable label for `bytes`. Dedups by content +// internstrlit — return a stable label for `bytes`. Dedups by content // so identical literals share storage. -fn intern_strlit(c: *cgen, bytes: str) str = { +fn internstrlit(c: *cgen, bytes: str) str = { let s: *strlit = c.strlits; for (s != nil) { let bs: str = s.bytes; @@ -372,9 +372,9 @@ fn intern_strlit(c: *cgen, bytes: str) str = { return lab; }; -// emit_def_constants — DATA directive per top-level int-literal `def`. +// emitdefconstants — DATA directive per top-level int-literal `def`. // 8 bytes little-endian to match what the C cgen emits. -fn emit_def_constants(c: *cgen, file: *node) void = { +fn emitdefconstants(c: *cgen, file: *node) void = { let d: *node = file.list; for (d != nil) { if (d.kind == N_DEF) { @@ -389,10 +389,10 @@ fn emit_def_constants(c: *cgen, file: *node) void = { if (r.kind == N_NIL) { v = 0u64; ok = true; }; }; if (ok) { - emit_line("DATA "); + emitline("DATA "); let nm: str = d.str; os.write(1, nm.ptr, nm.len: u64); - emit_line("(SB),\""); + emitline("(SB),\""); let i: i32 = 0; let n: u64 = v; for (i < 8) { @@ -400,11 +400,11 @@ fn emit_def_constants(c: *cgen, file: *node) void = { n = n >> 8u64; // C emit_defs only special-cases " and \; // every other non-printable goes as \xHH. - if (b == 34u8) { emit_line("\\\""); } - else { if (b == 92u8) { emit_line("\\\\"); } + if (b == 34u8) { emitline("\\\""); } + else { if (b == 92u8) { emitline("\\\\"); } else { if (b < 32u8) { - emit_line("\\x"); + emitline("\\x"); let hi: u8 = b >> 4u8; let lo: u8 = b & 15u8; let bb: [2]u8; @@ -415,7 +415,7 @@ fn emit_def_constants(c: *cgen, file: *node) void = { os.write(1, bb.ptr, 2u64); } else { if (b >= 127u8) { - emit_line("\\x"); + emitline("\\x"); let hi: u8 = b >> 4u8; let lo: u8 = b & 15u8; let bb: [2]u8; @@ -433,34 +433,34 @@ fn emit_def_constants(c: *cgen, file: *node) void = { };}; i += 1; }; - emit_line("\"\n"); + emitline("\"\n"); }; }; d = d.next; }; }; -// emit_data_section — DATA directives for every interned strlit. +// emitdatasection — DATA directives for every interned strlit. // Trailing NUL appended so .ptr can be used as a C string by syscalls. -fn emit_data_section(c: *cgen) void = { +fn emitdatasection(c: *cgen) void = { let s: *strlit = c.strlits; for (s != nil) { - emit_line("DATA "); + emitline("DATA "); let lab: str = s.label; os.write(1, lab.ptr, lab.len: u64); - emit_line("(SB),\""); + emitline("(SB),\""); let bs: str = s.bytes; let i: i32 = 0; for (i < bs.len) { let b: u8 = bs[i]; - if (b == 34u8) { emit_line("\\\""); } // " - else { if (b == 92u8) { emit_line("\\\\"); } // \ - else { if (b == 10u8) { emit_line("\\n"); } - else { if (b == 9u8) { emit_line("\\t"); } - else { if (b == 13u8) { emit_line("\\r"); } + if (b == 34u8) { emitline("\\\""); } // " + else { if (b == 92u8) { emitline("\\\\"); } // \ + else { if (b == 10u8) { emitline("\\n"); } + else { if (b == 9u8) { emitline("\\t"); } + else { if (b == 13u8) { emitline("\\r"); } else { if (b < 32u8) { - emit_line("\\x"); + emitline("\\x"); let hi: u8 = b >> 4u8; let lo: u8 = b & 15u8; let bb: [2]u8; @@ -471,7 +471,7 @@ fn emit_data_section(c: *cgen) void = { os.write(1, bb.ptr, 2u64); } else { if (b >= 127u8) { - emit_line("\\x"); + emitline("\\x"); let hi: u8 = b >> 4u8; let lo: u8 = b & 15u8; let bb: [2]u8; @@ -489,7 +489,7 @@ fn emit_data_section(c: *cgen) void = { };};};};}; i += 1; }; - emit_line("\\x00\"\n"); + emitline("\\x00\"\n"); s = s.slnext; }; }; @@ -506,7 +506,7 @@ type fnret = struct { frnext: *fnret, }; -fn collect_fnrets(c: *cgen, file: *node) void = { +fn collectfnrets(c: *cgen, file: *node) void = { c.fnrets = nil; let d: *node = file.list; for (d != nil) { @@ -521,7 +521,7 @@ fn collect_fnrets(c: *cgen, file: *node) void = { }; }; -fn fnret_lookup(c: *cgen, name: str) *node = { +fn fnretlookup(c: *cgen, name: str) *node = { let f: *fnret = c.fnrets; for (f != nil) { let fn_: str = f.fname; @@ -537,17 +537,17 @@ fn fnret_lookup(c: *cgen, name: str) *node = { // ident reference loads it via `MOVQ NAME(SB), AX`. We collect them at // file load and consult on N_IDENT lookup. -type def_ent = struct { +type defent = struct { dname: str, - dnext: *def_ent, + dnext: *defent, }; -fn collect_defs(c: *cgen, file: *node) void = { +fn collectdefs(c: *cgen, file: *node) void = { c.defs = nil; let d: *node = file.list; for (d != nil) { if (d.kind == N_DEF) { - let e: *def_ent = amalloc(c.a, 32u64): *def_ent; + let e: *defent = amalloc(c.a, 32u64): *defent; e.dname = d.str; e.dnext = c.defs; c.defs = e; @@ -556,8 +556,8 @@ fn collect_defs(c: *cgen, file: *node) void = { }; }; -fn def_lookup(c: *cgen, name: str) bool = { - let e: *def_ent = c.defs; +fn deflookup(c: *cgen, name: str) bool = { + let e: *defent = c.defs; for (e != nil) { let dn: str = e.dname; if (streq(dn, name)) { return true; }; @@ -568,7 +568,7 @@ fn def_lookup(c: *cgen, name: str) bool = { // ---- FFI map --------------------------------------------------------- -fn ffi_collect(c: *cgen, file: *node) void = { +fn fficollect(c: *cgen, file: *node) void = { c.ffis = nil; if (file == nil) { return; }; let d: *node = file.list; @@ -579,12 +579,12 @@ fn ffi_collect(c: *cgen, file: *node) void = { if (a.kind == N_ATTR) { let aname: str = a.str; if (streq(aname, "symbol")) { - let sym_node: *node = a.list; - if (sym_node != nil) { - if (sym_node.kind == N_STRLIT) { + let symnode: *node = a.list; + if (symnode != nil) { + if (symnode.kind == N_STRLIT) { let f: *ffi = amalloc(c.a, 48u64): *ffi; f.ident = d.str; - f.symbol = sym_node.str; + f.symbol = symnode.str; f.fnext = c.ffis; c.ffis = f; }; @@ -598,7 +598,7 @@ fn ffi_collect(c: *cgen, file: *node) void = { }; }; -fn ffi_resolve(c: *cgen, ident: str) str = { +fn ffiresolve(c: *cgen, ident: str) str = { let f: *ffi = c.ffis; for (f != nil) { let id: str = f.ident; @@ -610,7 +610,7 @@ fn ffi_resolve(c: *cgen, ident: str) str = { // ---- ABI argreg helpers --------------------------------------------- -fn argreg_name(i: i32) str = { +fn argregname(i: i32) str = { if (i == 0) { return "DI"; }; if (i == 1) { return "SI"; }; if (i == 2) { return "DX"; }; @@ -622,14 +622,14 @@ fn argreg_name(i: i32) str = { // ---- expression cgen ------------------------------------------------- -// push_args_rev — recursively walks the arg list, evaluates rightmost +// pushargsrev — recursively walks the arg list, evaluates rightmost // first, and pushes. str args take two slots (ptr in AX, len in BX); // the order on the stack so a left-to-right pop into argregs lands // (ptr, len) correctly is: PUSHQ BX (top), PUSHQ AX (above) — the // pop sequence then yields AX, then BX. -fn push_args_rev(c: *cgen, arg: *node) i32 = { +fn pushargsrev(c: *cgen, arg: *node) i32 = { if (arg == nil) { return 0; }; - let rest: i32 = push_args_rev(c, arg.next); + let rest: i32 = pushargsrev(c, arg.next); // N_SLICE expression as arg: `buf[lo:hi]` builds a slice header // on the stack matching C cgen's sequence — push base, push hi, // compute lo, pop into BX/CX, derive len/ptr, push (cap, len, ptr). @@ -637,77 +637,77 @@ fn push_args_rev(c: *cgen, arg: *node) i32 = { let base: *node = arg.lhs; let lo: *node = arg.rhs; let hi: *node = arg.cond; - let base_local: *local = nil; + let baselocal: *local = nil; if (base != nil) { if (base.kind == N_IDENT) { let bn: str = base.str; - base_local = local_find_node(c, bn); + baselocal = localfindnode(c, bn); }; }; // base address → push - if (base_local != nil) { - let tn: *node = base_local.tnode; + if (baselocal != nil) { + let tn: *node = baselocal.tnode; if (tn != nil) { if (tn.kind == N_TARRAY) { - emit_line("\tLEAQ\t"); - emit_off(base_local.off: i64); - emit_line("(BP), AX\n"); + emitline("\tLEAQ\t"); + emitoff(baselocal.off: i64); + emitline("(BP), AX\n"); } else { - emit_line("\tMOVQ\t"); - emit_off(base_local.off: i64); - emit_line("(BP), AX\n"); + emitline("\tMOVQ\t"); + emitoff(baselocal.off: i64); + emitline("(BP), AX\n"); }; } else { - emit_line("\tMOVQ\t"); - emit_off(base_local.off: i64); - emit_line("(BP), AX\n"); + emitline("\tMOVQ\t"); + emitoff(baselocal.off: i64); + emitline("(BP), AX\n"); }; } else { cgexpr(c, base); }; - emit_line("\tPUSHQ\tAX\n"); + emitline("\tPUSHQ\tAX\n"); // hi (default base length) → push if (hi != nil) { cgexpr(c, hi); - } else { if (base_local != nil) { - let tn: *node = base_local.tnode; + } else { if (baselocal != nil) { + let tn: *node = baselocal.tnode; if (tn != nil) { if (tn.kind == N_TARRAY) { - let len_n: *node = tn.rhs; - if (len_n != nil) { - if (len_n.kind == N_INTLIT) { - emit_line("\tMOVQ\t$"); - emit_uint(len_n.uval); - emit_line(", AX\n"); + let lenn: *node = tn.rhs; + if (lenn != nil) { + if (lenn.kind == N_INTLIT) { + emitline("\tMOVQ\t$"); + emituint(lenn.uval); + emitline(", AX\n"); }; }; } else { if (tn.kind == N_TSLICE) { - emit_line("\tMOVQ\t"); - emit_off((base_local.off + 8): i64); - emit_line("(BP), AX\n"); + emitline("\tMOVQ\t"); + emitoff((baselocal.off + 8): i64); + emitline("(BP), AX\n"); } else { if (tn.kind == N_TNAME) { if (streq(tn.str, "str")) { - emit_line("\tMOVQ\t"); - emit_off((base_local.off + 8): i64); - emit_line("(BP), AX\n"); + emitline("\tMOVQ\t"); + emitoff((baselocal.off + 8): i64); + emitline("(BP), AX\n"); }; };};}; }; } else { - emit_line("\tMOVQ\t$0, AX\n"); + emitline("\tMOVQ\t$0, AX\n"); };}; - emit_line("\tPUSHQ\tAX\n"); + emitline("\tPUSHQ\tAX\n"); // lo (default 0) → AX if (lo != nil) { cgexpr(c, lo); } - else { emit_line("\tMOVQ\t$0, AX\n"); }; - emit_line("\tPOPQ\tBX\n"); // hi - emit_line("\tPOPQ\tCX\n"); // base - emit_line("\tMOVQ\tBX, DX\n"); // DX = hi - emit_line("\tSUBQ\tAX, DX\n"); // DX = hi - lo = len - emit_line("\tADDQ\tAX, CX\n"); // CX = base + lo = ptr - emit_line("\tPUSHQ\tDX\n"); // cap - emit_line("\tPUSHQ\tDX\n"); // len - emit_line("\tPUSHQ\tCX\n"); // ptr (top) + else { emitline("\tMOVQ\t$0, AX\n"); }; + emitline("\tPOPQ\tBX\n"); // hi + emitline("\tPOPQ\tCX\n"); // base + emitline("\tMOVQ\tBX, DX\n"); // DX = hi + emitline("\tSUBQ\tAX, DX\n"); // DX = hi - lo = len + emitline("\tADDQ\tAX, CX\n"); // CX = base + lo = ptr + emitline("\tPUSHQ\tDX\n"); // cap + emitline("\tPUSHQ\tDX\n"); // len + emitline("\tPUSHQ\tCX\n"); // ptr (top) return rest + 3; }; // Slice/tagged ident args: emit per-register MOVQ+PUSHQ pairs in @@ -715,65 +715,65 @@ fn push_args_rev(c: *cgen, arg: *node) i32 = { // into argregs lands the canonical (ptr/tag, len/v0, cap/v1). if (arg.kind == N_IDENT) { let nm: str = arg.str; - let lc: *local = local_find_node(c, nm); + let lc: *local = localfindnode(c, nm); if (lc != nil) { let off: i32 = lc.off; - if (is_slice_type(c, lc.tnode) || is_tagged_type(lc.tnode)) { - emit_line("\tMOVQ\t"); - emit_off((off + 16): i64); - emit_line("(BP), AX\n"); - emit_line("\tPUSHQ\tAX\n"); - emit_line("\tMOVQ\t"); - emit_off((off + 8): i64); - emit_line("(BP), AX\n"); - emit_line("\tPUSHQ\tAX\n"); - emit_line("\tMOVQ\t"); - emit_off(off: i64); - emit_line("(BP), AX\n"); - emit_line("\tPUSHQ\tAX\n"); + if (isslicetype(c, lc.tnode) || istaggedtype(lc.tnode)) { + emitline("\tMOVQ\t"); + emitoff((off + 16): i64); + emitline("(BP), AX\n"); + emitline("\tPUSHQ\tAX\n"); + emitline("\tMOVQ\t"); + emitoff((off + 8): i64); + emitline("(BP), AX\n"); + emitline("\tPUSHQ\tAX\n"); + emitline("\tMOVQ\t"); + emitoff(off: i64); + emitline("(BP), AX\n"); + emitline("\tPUSHQ\tAX\n"); return rest + 3; }; }; }; cgexpr(c, arg); - if (node_isslice(c, arg)) { - emit_line("\tPUSHQ\tCX\n"); - emit_line("\tPUSHQ\tBX\n"); - emit_line("\tPUSHQ\tAX\n"); + if (nodeisslice(c, arg)) { + emitline("\tPUSHQ\tCX\n"); + emitline("\tPUSHQ\tBX\n"); + emitline("\tPUSHQ\tAX\n"); return rest + 3; }; - if (node_isstr(c, arg)) { - emit_line("\tPUSHQ\tBX\n"); - emit_line("\tPUSHQ\tAX\n"); + if (nodeisstr(c, arg)) { + emitline("\tPUSHQ\tBX\n"); + emitline("\tPUSHQ\tAX\n"); return rest + 2; }; - emit_line("\tPUSHQ\tAX\n"); + emitline("\tPUSHQ\tAX\n"); return rest + 1; }; -fn node_isslice(c: *cgen, n: *node) bool = { +fn nodeisslice(c: *cgen, n: *node) bool = { if (n == nil) { return false; }; let k: i32 = n.kind; if (k == N_IDENT) { let nm: str = n.str; - let lc: *local = local_find_node(c, nm); - if (lc != nil) { return is_slice_type(c, lc.tnode); }; + let lc: *local = localfindnode(c, nm); + if (lc != nil) { return isslicetype(c, lc.tnode); }; return false; }; if (k == N_SLICE) { return true; }; return false; }; -// node_isstr — best-effort surface check: does this expression +// nodeisstr — best-effort surface check: does this expression // evaluate to a str value? Used to drive the call-arg push convention // (str args take two slots: ptr + len). -fn node_isstr(c: *cgen, n: *node) bool = { +fn nodeisstr(c: *cgen, n: *node) bool = { if (n == nil) { return false; }; let k: i32 = n.kind; if (k == N_STRLIT) { return true; }; if (k == N_IDENT) { let nm: str = n.str; - let lc: *local = local_find_node(c, nm); + let lc: *local = localfindnode(c, nm); if (lc != nil) { let tn: *node = lc.tnode; if (tn != nil) { @@ -790,8 +790,8 @@ fn node_isstr(c: *cgen, n: *node) bool = { if (callee != nil) { if (callee.kind == N_IDENT) { let cnm: str = callee.str; - let rt: *node = fnret_lookup(c, cnm); - return is_str_type(c, rt); + let rt: *node = fnretlookup(c, cnm); + return isstrtype(c, rt); }; }; return false; @@ -807,7 +807,7 @@ fn node_isstr(c: *cgen, n: *node) bool = { let sname: str; sname.ptr = nil; sname.len = 0; if (base.kind == N_IDENT) { - let lc: *local = local_find_node(c, base.str); + let lc: *local = localfindnode(c, base.str); if (lc != nil) { let tn: *node = lc.tnode; let lkind: i32 = -1; @@ -821,23 +821,23 @@ fn node_isstr(c: *cgen, n: *node) bool = { }; }; }; - // Chained dot (`p.foo.bar`): use dot_inner_struct_ptr + // Chained dot (`p.foo.bar`): use dotinnerstructptr // to resolve the inner chain to the *struct it lands // on, then look up `fld` in that struct. if (base.kind == N_DOT) { - let inner_t: *node = dot_inner_struct_ptr(c, base); - if (inner_t != nil) { - if (inner_t.kind == N_TNAME) { sname = inner_t.str; }; + let innert: *node = dotinnerstructptr(c, base); + if (innert != nil) { + if (innert.kind == N_TNAME) { sname = innert.str; }; }; }; if (sname.len > 0) { - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fld)) { - return is_str_type(c, fi.tnode); + return isstrtype(c, fi.tnode); }; fi = fi.finext; }; @@ -847,13 +847,13 @@ fn node_isstr(c: *cgen, n: *node) bool = { return false; }; if (k == N_CAST) { - return is_str_type(c, n.rhs); + return isstrtype(c, n.rhs); }; return false; }; -// type_name_isunsigned — true for u8/u16/u32/u64/uint/uintptr. -fn type_name_isunsigned(nm: str) bool = { +// typenameisunsigned — true for u8/u16/u32/u64/uint/uintptr. +fn typenameisunsigned(nm: str) bool = { if (streq(nm, "u8")) { return true; }; if (streq(nm, "u16")) { return true; }; if (streq(nm, "u32")) { return true; }; @@ -863,21 +863,21 @@ fn type_name_isunsigned(nm: str) bool = { return false; }; -// type_node_isunsigned — recurse through TNAME / TPTR / TSLICE etc. -fn type_node_isunsigned(t: *node) bool = { +// typenodeisunsigned — recurse through TNAME / TPTR / TSLICE etc. +fn typenodeisunsigned(t: *node) bool = { if (t == nil) { return false; }; - if (t.kind == N_TNAME) { return type_name_isunsigned(t.str); }; + if (t.kind == N_TNAME) { return typenameisunsigned(t.str); }; return false; }; -// type_is_8byte_primitive — does this type take exactly one 8-byte +// typeis8byteprimitive — does this type take exactly one 8-byte // slot (pointer / fn-ptr / 64-bit int / chan / scalar primitive // padded up to 8) rather than a wider aggregate? Used by N_LET // zero-init to mirror C cgen's "only zero if sz == 8 at the type // level" rule. Strings (16), slices (24), tagged unions (>=16), // tuples (16), structs (varies), arrays — all fall through to // false here even when their *slot* rounds up to 8. -fn type_is_8byte_primitive(c: *cgen, t: *node) bool = { +fn typeis8byteprimitive(c: *cgen, t: *node) bool = { if (t == nil) { return false; }; let k: i32 = t.kind; if (k == N_TPTR) { return true; }; @@ -891,17 +891,17 @@ fn type_is_8byte_primitive(c: *cgen, t: *node) bool = { let nm: str = t.str; if (streq(nm, "str")) { return false; }; // Struct alias: not a primitive even if the slot is 8B. - if (struct_lookup(c, nm) != nil) { return false; }; + if (structlookup(c, nm) != nil) { return false; }; // Primitive (i8/u8/.../i64/u64/bool/rune/f32/f64/int/...). // All of these get slot-padded to 8 and zero-init in C. - if (prim_size(nm) > 0) { return true; }; + if (primsize(nm) > 0) { return true; }; return false; }; return false; }; -// type_name_issigned — true for i8/i16/i32/i64/int/rune. -fn type_name_issigned(nm: str) bool = { +// typenameissigned — true for i8/i16/i32/i64/int/rune. +fn typenameissigned(nm: str) bool = { if (streq(nm, "i8")) { return true; }; if (streq(nm, "i16")) { return true; }; if (streq(nm, "i32")) { return true; }; @@ -911,11 +911,11 @@ fn type_name_issigned(nm: str) bool = { return false; }; -// field_load_op — pick the load instruction for a non-str struct +// fieldloadop — pick the load instruction for a non-str struct // field by its declared size + signedness. Mirrors the C cgen op // dispatch (MOVZBQ for u8/bool/i8, MOVSXD for i32, MOVL for u32, MOVQ // for 8-byte). f might be nil for fields outside our struct registry. -fn field_load_op(f: *field_info) str = { +fn fieldloadop(f: *fieldinfo) str = { if (f == nil) { return "MOVQ"; }; let sz: i32 = f.fsz; if (sz == 1) { return "MOVZBQ"; }; @@ -923,7 +923,7 @@ fn field_load_op(f: *field_info) str = { let t: *node = f.tnode; if (t != nil) { if (t.kind == N_TNAME) { - if (type_name_issigned(t.str)) { return "MOVSXD"; }; + if (typenameissigned(t.str)) { return "MOVSXD"; }; }; }; return "MOVL"; @@ -931,9 +931,9 @@ fn field_load_op(f: *field_info) str = { return "MOVQ"; }; -// field_store_op — pick the store instruction for a non-str struct +// fieldstoreop — pick the store instruction for a non-str struct // field by its declared size. MOVB for 1, MOVL for 4, MOVQ for 8. -fn field_store_op(f: *field_info) str = { +fn fieldstoreop(f: *fieldinfo) str = { if (f == nil) { return "MOVQ"; }; let sz: i32 = f.fsz; if (sz == 1) { return "MOVB"; }; @@ -941,11 +941,11 @@ fn field_store_op(f: *field_info) str = { return "MOVQ"; }; -// index_base_esz — element size for `arr[i]` where the base is a +// indexbaseesz — element size for `arr[i]` where the base is a // chained-dot pseudo-field `s.ptr` (s being str/*str/slice/*slice). // For str the element is one byte; for `[]T` / `*[]T` we drill into // the slice element type. -fn index_base_esz(c: *cgen, base: *node) i32 = { +fn indexbaseesz(c: *cgen, base: *node) i32 = { if (base == nil) { return 8; }; if (base.kind != N_DOT) { return 8; }; let fld: str = base.str; @@ -953,20 +953,20 @@ fn index_base_esz(c: *cgen, base: *node) i32 = { if (inner == nil) { return 8; }; if (inner.kind != N_IDENT) { return 8; }; let nm: str = inner.str; - let lc: *local = local_find_node(c, nm); + let lc: *local = localfindnode(c, nm); if (lc == nil) { return 8; }; let tn: *node = lc.tnode; if (tn == nil) { return 8; }; // `.ptr` pseudo-field on str/slice → element of the str/slice. if (streq(fld, "ptr")) { - let inner_t: *node = tn; - if (tn.kind == N_TPTR) { inner_t = tn.lhs; }; - if (inner_t == nil) { return 8; }; - if (inner_t.kind == N_TNAME) { - if (streq(inner_t.str, "str")) { return 1; }; + let innert: *node = tn; + if (tn.kind == N_TPTR) { innert = tn.lhs; }; + if (innert == nil) { return 8; }; + if (innert.kind == N_TNAME) { + if (streq(innert.str, "str")) { return 1; }; }; - if (inner_t.kind == N_TSLICE) { return elem_size_of(inner_t); }; + if (innert.kind == N_TSLICE) { return elemsizeof(innert); }; return 8; }; @@ -982,9 +982,9 @@ fn index_base_esz(c: *cgen, base: *node) i32 = { }; }; if (sname.len == 0) { return 8; }; - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si == nil) { return 8; }; - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fld)) { @@ -995,13 +995,13 @@ fn index_base_esz(c: *cgen, base: *node) i32 = { if (elem != nil) { if (elem.kind == N_TNAME) { if (streq(elem.str, "str")) { return 16; }; - let ps: i32 = prim_size(elem.str); + let ps: i32 = primsize(elem.str); if (ps > 0) { return ps; }; }; }; return 8; }; - if (ft.kind == N_TSLICE) { return elem_size_of(ft); }; + if (ft.kind == N_TSLICE) { return elemsizeof(ft); }; // str-typed field: indexing yields one byte // (`n.s[i]` where .s is str — matches C cgen's // MOVZBQ for byte indexing). @@ -1015,7 +1015,7 @@ fn index_base_esz(c: *cgen, base: *node) i32 = { return 8; }; -// dot_inner_struct_ptr — for an N_DOT whose lhs is a chain of dots +// dotinnerstructptr — for an N_DOT whose lhs is a chain of dots // or an N_IDENT, walk the chain and return the N_TNAME tnode of the // struct that the chain dereferences to (i.e., for `r.sym` where // .sym is *lsym, return N_TNAME("lsym")). Returns nil if the chain @@ -1023,7 +1023,7 @@ fn index_base_esz(c: *cgen, base: *node) i32 = { // // Used by the chained-DOT cgen path so `r.sym.val` knows the outer // is a field of `lsym`. -fn dot_inner_struct_ptr(c: *cgen, n: *node) *node = { +fn dotinnerstructptr(c: *cgen, n: *node) *node = { if (n == nil) { return nil; }; if (n.kind != N_DOT) { return nil; }; let base: *node = n.lhs; @@ -1031,25 +1031,25 @@ fn dot_inner_struct_ptr(c: *cgen, n: *node) *node = { if (base == nil) { return nil; }; // Resolve base's struct tnode. - let base_t: *node = nil; + let baset: *node = nil; if (base.kind == N_IDENT) { - let lc: *local = local_find_node(c, base.str); + let lc: *local = localfindnode(c, base.str); if (lc == nil) { return nil; }; let tn: *node = lc.tnode; if (tn == nil) { return nil; }; // base could be either struct-by-value (N_TNAME) or *struct (N_TPTR). - if (tn.kind == N_TNAME) { base_t = tn; }; - if (tn.kind == N_TPTR) { base_t = tn.lhs; }; + if (tn.kind == N_TNAME) { baset = tn; }; + if (tn.kind == N_TPTR) { baset = tn.lhs; }; } else { if (base.kind == N_DOT) { - base_t = dot_inner_struct_ptr(c, base); + baset = dotinnerstructptr(c, base); };}; - if (base_t == nil) { return nil; }; - if (base_t.kind != N_TNAME) { return nil; }; + if (baset == nil) { return nil; }; + if (baset.kind != N_TNAME) { return nil; }; // Look up the struct, find the field, return the field's *struct. - let si: *struct_info = struct_lookup(c, base_t.str); + let si: *structinfo = structlookup(c, baset.str); if (si == nil) { return nil; }; - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { if (streq(fi.fname, fld)) { let ft: *node = fi.tnode; @@ -1065,10 +1065,10 @@ fn dot_inner_struct_ptr(c: *cgen, n: *node) *node = { return nil; }; -// elem_size_of — given the type node of an indexable (`*T`, `[]T`, +// elemsizeof — given the type node of an indexable (`*T`, `[]T`, // `[N]T`, `str`), return the byte size of one element (1 for u8/i8/ // bool/str-byte, 8 otherwise — same shape as C cgen's esz fallback). -fn elem_size_of(t: *node) i32 = { +fn elemsizeof(t: *node) i32 = { if (t == nil) { return 1; }; let k: i32 = t.kind; let elem: *node = nil; @@ -1079,22 +1079,22 @@ fn elem_size_of(t: *node) i32 = { let nm: str = t.str; if (streq(nm, "str")) { return 1; }; // Indexing a primitive name (rare): element size = the prim. - let ps: i32 = prim_size(nm); + let ps: i32 = primsize(nm); if (ps > 0) { return ps; }; return 1; }; if (elem == nil) { return 1; }; if (elem.kind == N_TNAME) { let nm: str = elem.str; - // str element is 16B (ptr+len). prim_size returns 0 for it. + // str element is 16B (ptr+len). primsize returns 0 for it. if (streq(nm, "str")) { return 16; }; - let ps: i32 = prim_size(nm); + let ps: i32 = primsize(nm); if (ps > 0) { return ps; }; }; return 8; }; -// node_isunsigned — best-effort cgen-time inference from the AST. We +// nodeisunsigned — best-effort cgen-time inference from the AST. We // don't have a typed AST yet, so we walk surface nodes: // N_INTLIT — never marked unsigned (no tsuffix plumbing yet) // N_IDENT — look up the local's declared type @@ -1104,13 +1104,13 @@ fn elem_size_of(t: *node) i32 = { // // Conservative: if we can't tell, return false (signed). The cost of // being wrong here is byte-different asm vs C, not bad runtime. -fn node_isunsigned(c: *cgen, n: *node) bool = { +fn nodeisunsigned(c: *cgen, n: *node) bool = { if (n == nil) { return false; }; let k: i32 = n.kind; if (k == N_IDENT) { let nm: str = n.str; - let lc: *local = local_find_node(c, nm); - if (lc != nil) { return type_node_isunsigned(lc.tnode); }; + let lc: *local = localfindnode(c, nm); + if (lc != nil) { return typenodeisunsigned(lc.tnode); }; return false; }; if (k == N_DOT) { @@ -1119,7 +1119,7 @@ fn node_isunsigned(c: *cgen, n: *node) bool = { if (base != nil) { if (base.kind == N_IDENT) { let bn: str = base.str; - let lc: *local = local_find_node(c, bn); + let lc: *local = localfindnode(c, bn); if (lc != nil) { let tn: *node = lc.tnode; let lkind: i32 = -1; @@ -1134,13 +1134,13 @@ fn node_isunsigned(c: *cgen, n: *node) bool = { }; if (lkind == N_TNAME) { sname = tn.str; }; if (sname.len > 0) { - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fld)) { - return type_node_isunsigned(fi.tnode); + return typenodeisunsigned(fi.tnode); }; fi = fi.finext; }; @@ -1151,12 +1151,12 @@ fn node_isunsigned(c: *cgen, n: *node) bool = { }; return false; }; - if (k == N_CAST) { return type_node_isunsigned(n.rhs); }; + if (k == N_CAST) { return typenodeisunsigned(n.rhs); }; if (k == N_BIN) { - if (node_isunsigned(c, n.lhs)) { return true; }; - return node_isunsigned(c, n.rhs); + if (nodeisunsigned(c, n.lhs)) { return true; }; + return nodeisunsigned(c, n.rhs); }; - if (k == N_UN) { return node_isunsigned(c, n.lhs); }; + if (k == N_UN) { return nodeisunsigned(c, n.lhs); }; // N_INDEX: `p[i]` is unsigned iff p's element type is unsigned. // Walks the base local's declared type and pulls the element // out — *u8 → u8, [N]u32 → u32, []u64 → u64. Without this the @@ -1166,7 +1166,7 @@ fn node_isunsigned(c: *cgen, n: *node) bool = { let base: *node = n.lhs; if (base != nil) { if (base.kind == N_IDENT) { - let lc: *local = local_find_node(c, base.str); + let lc: *local = localfindnode(c, base.str); if (lc != nil) { let tn: *node = lc.tnode; if (tn != nil) { @@ -1175,7 +1175,7 @@ fn node_isunsigned(c: *cgen, n: *node) bool = { if (tn.kind == N_TARRAY) { elem = tn.lhs; }; if (tn.kind == N_TSLICE) { elem = tn.lhs; }; if (elem != nil) { - return type_node_isunsigned(elem); + return typenodeisunsigned(elem); }; }; }; @@ -1195,86 +1195,86 @@ fn cgexpr(c: *cgen, n: *node) void = { // `$%lld` so 64-bit constants with bit 63 set show up as // negative — e.g. FNV-1a's offset basis prints as // $-3750763034362895579, not $14695981039346656037. - emit_line("\tMOVQ\t$"); - emit_int(n.uval: i64); - emit_line(", AX\n"); + emitline("\tMOVQ\t$"); + emitint(n.uval: i64); + emitline(", AX\n"); return; }; if (k == N_RUNELIT) { - emit_line("\tMOVQ\t$"); - emit_int(n.uval: i64); - emit_line(", AX\n"); + emitline("\tMOVQ\t$"); + emitint(n.uval: i64); + emitline(", AX\n"); return; }; if (k == N_STRLIT) { // Result is the (ptr, len) pair: ptr in AX, len in BX. Call // sites that expect a str arg pick these up directly. let nstr: str = n.str; - let lab: str = intern_strlit(c, nstr); - emit_line("\tLEAQ\t"); + let lab: str = internstrlit(c, nstr); + emitline("\tLEAQ\t"); os.write(1, lab.ptr, lab.len: u64); - emit_line("(SB), AX\n"); - emit_line("\tMOVQ\t$"); - emit_int(nstr.len: i64); - emit_line(", BX\n"); + emitline("(SB), AX\n"); + emitline("\tMOVQ\t$"); + emitint(nstr.len: i64); + emitline(", BX\n"); return; }; if (k == N_TRUE) { - emit_line("\tMOVQ\t$1, AX\n"); + emitline("\tMOVQ\t$1, AX\n"); return; }; if (k == N_FALSE) { - emit_line("\tMOVQ\t$0, AX\n"); + emitline("\tMOVQ\t$0, AX\n"); return; }; if (k == N_NIL) { - emit_line("\tMOVQ\t$0, AX\n"); + emitline("\tMOVQ\t$0, AX\n"); return; }; if (k == N_IDENT) { let nm: str = n.str; - let lc: *local = local_find_node(c, nm); + let lc: *local = localfindnode(c, nm); if (lc != nil) { let off: i32 = lc.off; - emit_line("\tMOVQ\t"); - emit_off(off: i64); - emit_line("(BP), AX\n"); + emitline("\tMOVQ\t"); + emitoff(off: i64); + emitline("(BP), AX\n"); // str local: also load the len half into BX. - if (is_str_type(c, lc.tnode)) { - emit_line("\tMOVQ\t"); - emit_off((off + 8): i64); - emit_line("(BP), BX\n"); + if (isstrtype(c, lc.tnode)) { + emitline("\tMOVQ\t"); + emitoff((off + 8): i64); + emitline("(BP), BX\n"); }; // slice local: load (ptr, len, cap) into (AX, BX, CX). - if (is_slice_type(c, lc.tnode)) { - emit_line("\tMOVQ\t"); - emit_off((off + 8): i64); - emit_line("(BP), BX\n"); - emit_line("\tMOVQ\t"); - emit_off((off + 16): i64); - emit_line("(BP), CX\n"); + if (isslicetype(c, lc.tnode)) { + emitline("\tMOVQ\t"); + emitoff((off + 8): i64); + emitline("(BP), BX\n"); + emitline("\tMOVQ\t"); + emitoff((off + 16): i64); + emitline("(BP), CX\n"); }; return; }; // Top-level `def` constant — load from its DATA symbol. - if (def_lookup(c, nm)) { - emit_line("\tMOVQ\t"); + if (deflookup(c, nm)) { + emitline("\tMOVQ\t"); os.write(1, nm.ptr, nm.len: u64); - emit_line("(SB), AX\n"); + emitline("(SB), AX\n"); return; }; // Fn-name used as a value (e.g. `let f = some_fn;` or // `... = some_fn;`). LEAQ the symbol address into AX — - // resolved through ffi_resolve so a body-less FFI binding + // resolved through ffiresolve so a body-less FFI binding // emits the C symbol it was declared with via @symbol(), // not the ww-side ident. - let rt: *node = fnret_lookup(c, nm); + let rt: *node = fnretlookup(c, nm); if (rt != nil) { - let resolved: str = ffi_resolve(c, nm); - emit_line("\tLEAQ\t"); + let resolved: str = ffiresolve(c, nm); + emitline("\tLEAQ\t"); os.write(1, resolved.ptr, resolved.len: u64); - emit_line("(SB), AX\n"); + emitline("(SB), AX\n"); return; }; return; @@ -1287,61 +1287,61 @@ fn cgexpr(c: *cgen, n: *node) void = { let base: *node = n.lhs; let idx: *node = n.rhs; let esz: i32 = 8; - let base_local: *local = nil; + let baselocal: *local = nil; if (base != nil) { if (base.kind == N_IDENT) { let bn: str = base.str; - base_local = local_find_node(c, bn); - if (base_local != nil) { esz = elem_size_of(base_local.tnode); }; + baselocal = localfindnode(c, bn); + if (baselocal != nil) { esz = elemsizeof(baselocal.tnode); }; } else { if (base.kind == N_DOT) { - esz = index_base_esz(c, base); + esz = indexbaseesz(c, base); };}; }; cgexpr(c, idx); if (esz > 1) { - emit_line("\tMOVQ\t$"); - emit_int(esz: i64); - emit_line(", CX\n"); - emit_line("\tIMULQ\tCX, AX\n"); + emitline("\tMOVQ\t$"); + emitint(esz: i64); + emitline(", CX\n"); + emitline("\tIMULQ\tCX, AX\n"); }; - if (base_local != nil) { - let tn: *node = base_local.tnode; - let is_array: bool = false; - if (tn != nil) { if (tn.kind == N_TARRAY) { is_array = true; }; }; - if (is_array) { - emit_line("\tLEAQ\t"); - emit_off(base_local.off: i64); - emit_line("(BP), BX\n"); + if (baselocal != nil) { + let tn: *node = baselocal.tnode; + let isarray: bool = false; + if (tn != nil) { if (tn.kind == N_TARRAY) { isarray = true; }; }; + if (isarray) { + emitline("\tLEAQ\t"); + emitoff(baselocal.off: i64); + emitline("(BP), BX\n"); } else { - emit_line("\tMOVQ\t"); - emit_off(base_local.off: i64); - emit_line("(BP), BX\n"); + emitline("\tMOVQ\t"); + emitoff(baselocal.off: i64); + emitline("(BP), BX\n"); }; - emit_line("\tADDQ\tAX, BX\n"); + emitline("\tADDQ\tAX, BX\n"); // str element (16B): load (ptr, len) into (AX, BX) so // the value flows through the str-rhs convention. if (esz == 16) { - emit_line("\tMOVQ\t8(BX), CX\n"); - emit_line("\tMOVQ\t(BX), AX\n"); - emit_line("\tMOVQ\tCX, BX\n"); + emitline("\tMOVQ\t8(BX), CX\n"); + emitline("\tMOVQ\t(BX), AX\n"); + emitline("\tMOVQ\tCX, BX\n"); return; }; - if (esz == 1) { emit_line("\tMOVZBQ\t(BX), AX\n"); } - else { emit_line("\tMOVQ\t(BX), AX\n"); }; + if (esz == 1) { emitline("\tMOVZBQ\t(BX), AX\n"); } + else { emitline("\tMOVQ\t(BX), AX\n"); }; return; }; // Generic fallback when base isn't a plain ident. - emit_line("\tPUSHQ\tAX\n"); + emitline("\tPUSHQ\tAX\n"); cgexpr(c, base); - emit_line("\tPOPQ\tBX\n"); - emit_line("\tADDQ\tBX, AX\n"); + emitline("\tPOPQ\tBX\n"); + emitline("\tADDQ\tBX, AX\n"); if (esz == 16) { - emit_line("\tMOVQ\t8(AX), BX\n"); - emit_line("\tMOVQ\t(AX), AX\n"); + emitline("\tMOVQ\t8(AX), BX\n"); + emitline("\tMOVQ\t(AX), AX\n"); return; }; - if (esz == 1) { emit_line("\tMOVZBQ\t(AX), AX\n"); } - else { emit_line("\tMOVQ\t(AX), AX\n"); }; + if (esz == 1) { emitline("\tMOVZBQ\t(AX), AX\n"); } + else { emitline("\tMOVQ\t(AX), AX\n"); }; return; }; @@ -1353,14 +1353,14 @@ fn cgexpr(c: *cgen, n: *node) void = { // (`case let v: T =>`) get a fresh local slot loaded from // slot+8 (and slot+16 for str-typed payload). let scrut: *node = n.lhs; - let scrut_off: i32 = 0; - let scrut_t: *node = nil; + let scrutoff: i32 = 0; + let scrutt: *node = nil; if (scrut != nil) { if (scrut.kind == N_IDENT) { - let lc: *local = local_find_node(c, scrut.str); + let lc: *local = localfindnode(c, scrut.str); if (lc != nil) { - scrut_off = lc.off; - scrut_t = resolve_type(c, lc.tnode); + scrutoff = lc.off; + scrutt = resolvetype(c, lc.tnode); }; }; }; @@ -1373,17 +1373,17 @@ fn cgexpr(c: *cgen, n: *node) void = { // (no pattern) skips the tag check. if (pat != nil) { let want: i32 = 0; - if (scrut_t != nil) { - if (scrut_t.kind == N_TTAGGED) { - let pat_name: str; - pat_name.ptr = nil; pat_name.len = 0; - if (pat.kind == N_TNAME) { pat_name = pat.str; }; - let v: *node = scrut_t.list; + if (scrutt != nil) { + if (scrutt.kind == N_TTAGGED) { + let patname: str; + patname.ptr = nil; patname.len = 0; + if (pat.kind == N_TNAME) { patname = pat.str; }; + let v: *node = scrutt.list; let idx: i32 = 0; let found: bool = false; for (v != nil) { if (v.kind == N_TNAME) { - if (streq(v.str, pat_name)) { + if (streq(v.str, patname)) { want = idx; found = true; v = nil; @@ -1397,52 +1397,52 @@ fn cgexpr(c: *cgen, n: *node) void = { if (!found) { want = 0; }; }; }; - emit_line("\tMOVQ\t"); - emit_off(scrut_off: i64); - emit_line("(BP), AX\n"); - emit_line("\tCMPQ\t$"); - emit_int(want: i64); - emit_line(", AX\n"); - emit_line("\tJNE\t"); - emit_line(nxt); - emit_line("\n"); + emitline("\tMOVQ\t"); + emitoff(scrutoff: i64); + emitline("(BP), AX\n"); + emitline("\tCMPQ\t$"); + emitint(want: i64); + emitline(", AX\n"); + emitline("\tJNE\t"); + emitline(nxt); + emitline("\n"); }; // Bind `let v: T` from the slot, if requested. let bn: str = cs.str; if (bn.len > 0) { if (pat != nil) { let bsz: i32 = 8; - if (is_str_type(c, pat)) { bsz = 16; }; - // local_alloc (not local_add): match-arm + if (isstrtype(c, pat)) { bsz = 16; }; + // localalloc (not localadd): match-arm // binds don't dedup with same-named binds // in *other* matches, since C's cgexpr // allocates a fresh slot per match expr. - let voff: i32 = local_alloc(c, bn, bsz, pat); - emit_line("\tMOVQ\t"); - emit_off((scrut_off + 8): i64); - emit_line("(BP), AX\n"); - emit_line("\tMOVQ\tAX, "); - emit_off(voff: i64); - emit_line("(BP)\n"); + let voff: i32 = localalloc(c, bn, bsz, pat); + emitline("\tMOVQ\t"); + emitoff((scrutoff + 8): i64); + emitline("(BP), AX\n"); + emitline("\tMOVQ\tAX, "); + emitoff(voff: i64); + emitline("(BP)\n"); if (bsz == 16) { - emit_line("\tMOVQ\t"); - emit_off((scrut_off + 16): i64); - emit_line("(BP), AX\n"); - emit_line("\tMOVQ\tAX, "); - emit_off((voff + 8): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\t"); + emitoff((scrutoff + 16): i64); + emitline("(BP), AX\n"); + emitline("\tMOVQ\tAX, "); + emitoff((voff + 8): i64); + emitline("(BP)\n"); }; }; }; // Body. Match arms are statements; we cgstmt them. if (cs.body != nil) { cgstmt(c, cs.body); }; - emit_line("\tJMP\t"); - emit_line(endl); - emit_line("\n"); - emit_label(nxt); + emitline("\tJMP\t"); + emitline(endl); + emitline("\n"); + emitlabel(nxt); cs = cs.next; }; - emit_label(endl); + emitlabel(endl); return; }; @@ -1462,7 +1462,7 @@ fn cgexpr(c: *cgen, n: *node) void = { if (lhs != nil) { if (lhs.kind == N_IDENT) { let nm: str = lhs.str; - let lc: *local = local_find_node(c, nm); + let lc: *local = localfindnode(c, nm); if (lc != nil) { let tn: *node = lc.tnode; let lkind: i32 = -1; @@ -1478,33 +1478,33 @@ fn cgexpr(c: *cgen, n: *node) void = { }; }; if (sname.len > 0) { - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fld)) { // str field via *struct: load len into a // scratch first (so loading ptr into AX // last leaves (AX=ptr, BX=len)). - emit_line("\tMOVQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), BX\n"); - if (is_str_type(c, fi.tnode)) { - emit_line("\tMOVQ\t"); - emit_disp_reg((fi.foff + 8): i64, "BX"); - emit_line(", CX\n"); - emit_line("\tMOVQ\t"); - emit_disp_reg(fi.foff: i64, "BX"); - emit_line(", AX\n"); - emit_line("\tMOVQ\tCX, BX\n"); + emitline("\tMOVQ\t"); + emitoff(lc.off: i64); + emitline("(BP), BX\n"); + if (isstrtype(c, fi.tnode)) { + emitline("\tMOVQ\t"); + emitdispreg((fi.foff + 8): i64, "BX"); + emitline(", CX\n"); + emitline("\tMOVQ\t"); + emitdispreg(fi.foff: i64, "BX"); + emitline(", AX\n"); + emitline("\tMOVQ\tCX, BX\n"); } else { - let op: str = field_load_op(fi); - emit_line("\t"); - emit_line(op); - emit_line("\t"); - emit_disp_reg(fi.foff: i64, "BX"); - emit_line(", AX\n"); + let op: str = fieldloadop(fi); + emitline("\t"); + emitline(op); + emitline("\t"); + emitdispreg(fi.foff: i64, "BX"); + emitline(", AX\n"); }; return; }; @@ -1516,28 +1516,28 @@ fn cgexpr(c: *cgen, n: *node) void = { // Direct struct local: field load at off+foff. if (lkind == N_TNAME) { let sname: str = tn.str; - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fld)) { // str field: load both halves so chained // `.ptr` / `.len` see (AX=ptr, BX=len). - if (is_str_type(c, fi.tnode)) { - emit_line("\tMOVQ\t"); - emit_off((lc.off + fi.foff): i64); - emit_line("(BP), AX\n"); - emit_line("\tMOVQ\t"); - emit_off((lc.off + fi.foff + 8): i64); - emit_line("(BP), BX\n"); + if (isstrtype(c, fi.tnode)) { + emitline("\tMOVQ\t"); + emitoff((lc.off + fi.foff): i64); + emitline("(BP), AX\n"); + emitline("\tMOVQ\t"); + emitoff((lc.off + fi.foff + 8): i64); + emitline("(BP), BX\n"); } else { - let op: str = field_load_op(fi); - emit_line("\t"); - emit_line(op); - emit_line("\t"); - emit_off((lc.off + fi.foff): i64); - emit_line("(BP), AX\n"); + let op: str = fieldloadop(fi); + emitline("\t"); + emitline(op); + emitline("\t"); + emitoff((lc.off + fi.foff): i64); + emitline("(BP), AX\n"); }; return; }; @@ -1550,20 +1550,20 @@ fn cgexpr(c: *cgen, n: *node) void = { // count (immediate). if (lkind == N_TARRAY) { if (streq(fld, "ptr")) { - emit_line("\tLEAQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), AX\n"); + emitline("\tLEAQ\t"); + emitoff(lc.off: i64); + emitline("(BP), AX\n"); return; }; if (streq(fld, "len")) { - let len_n: *node = tn.rhs; + let lenn: *node = tn.rhs; let alen: i64 = 0i64; - if (len_n != nil) { - if (len_n.kind == N_INTLIT) { alen = len_n.uval: i64; }; + if (lenn != nil) { + if (lenn.kind == N_INTLIT) { alen = lenn.uval: i64; }; }; - emit_line("\tMOVQ\t$"); - emit_int(alen); - emit_line(", AX\n"); + emitline("\tMOVQ\t$"); + emitint(alen); + emitline(", AX\n"); return; }; }; @@ -1579,26 +1579,26 @@ fn cgexpr(c: *cgen, n: *node) void = { // pointed-to header. C cgen does the same. if (lkind == N_TPTR) { let inner: *node = tn.lhs; - let inner_kind: i32 = -1; - if (inner != nil) { inner_kind = inner.kind; }; - let inner_str: bool = false; - if (inner_kind == N_TNAME) { - if (streq(inner.str, "str")) { inner_str = true; }; + let innerkind: i32 = -1; + if (inner != nil) { innerkind = inner.kind; }; + let innerstr: bool = false; + if (innerkind == N_TNAME) { + if (streq(inner.str, "str")) { innerstr = true; }; }; - if (inner_kind == N_TSLICE) { inner_str = true; }; - if (inner_str) { - emit_line("\tMOVQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), BX\n"); - emit_line("\tMOVQ\t"); - emit_disp_reg(delta: i64, "BX"); - emit_line(", AX\n"); + if (innerkind == N_TSLICE) { innerstr = true; }; + if (innerstr) { + emitline("\tMOVQ\t"); + emitoff(lc.off: i64); + emitline("(BP), BX\n"); + emitline("\tMOVQ\t"); + emitdispreg(delta: i64, "BX"); + emitline(", AX\n"); return; }; }; - emit_line("\tMOVQ\t"); - emit_off((lc.off + delta): i64); - emit_line("(BP), AX\n"); + emitline("\tMOVQ\t"); + emitoff((lc.off + delta): i64); + emitline("(BP), AX\n"); return; }; }; @@ -1610,9 +1610,9 @@ fn cgexpr(c: *cgen, n: *node) void = { // the C cgen takes when bt is NULL/ty_err. if (lhs != nil) { if (lhs.kind == N_IDENT) { - emit_line("\tMOVQ\t"); - emit_line(fld); - emit_line("(SB), AX\n"); + emitline("\tMOVQ\t"); + emitline(fld); + emitline("(SB), AX\n"); return; }; }; @@ -1624,7 +1624,7 @@ fn cgexpr(c: *cgen, n: *node) void = { if (streq(fld, "ptr")) { cgexpr(c, lhs); return; }; if (streq(fld, "len")) { cgexpr(c, lhs); - emit_line("\tMOVQ\tBX, AX\n"); + emitline("\tMOVQ\tBX, AX\n"); return; }; // Chained struct-field-via-ptr-via-ptr access: @@ -1637,31 +1637,31 @@ fn cgexpr(c: *cgen, n: *node) void = { // the field. (Showed up porting w6l/pass.ww.) if (lhs != nil) { if (lhs.kind == N_DOT) { - let inner_t: *node = dot_inner_struct_ptr(c, lhs); - if (inner_t != nil) { - let sname: str = inner_t.str; - let si: *struct_info = struct_lookup(c, sname); + let innert: *node = dotinnerstructptr(c, lhs); + if (innert != nil) { + let sname: str = innert.str; + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { if (streq(fi.fname, fld)) { cgexpr(c, lhs); // AX = ptr to inner struct - let lop: str = field_load_op(fi); + let lop: str = fieldloadop(fi); // str field: load both halves. - if (is_str_type(c, fi.tnode)) { - emit_line("\tMOVQ\t"); - emit_disp_reg((fi.foff + 8): i64, "AX"); - emit_line(", BX\n"); - emit_line("\tMOVQ\t"); - emit_disp_reg(fi.foff: i64, "AX"); - emit_line(", AX\n"); + if (isstrtype(c, fi.tnode)) { + emitline("\tMOVQ\t"); + emitdispreg((fi.foff + 8): i64, "AX"); + emitline(", BX\n"); + emitline("\tMOVQ\t"); + emitdispreg(fi.foff: i64, "AX"); + emitline(", AX\n"); return; }; - emit_line("\t"); - emit_line(lop); - emit_line("\t"); - emit_disp_reg(fi.foff: i64, "AX"); - emit_line(", AX\n"); + emitline("\t"); + emitline(lop); + emitline("\t"); + emitdispreg(fi.foff: i64, "AX"); + emitline(", AX\n"); return; }; fi = fi.finext; @@ -1679,19 +1679,19 @@ fn cgexpr(c: *cgen, n: *node) void = { // address / deref. The wasted load before AMP keeps our asm // byte-identical to the C version. cgexpr(c, n.lhs); - if (n.op == TK_MINUS) { emit_line("\tNEGQ\tAX\n"); return; }; - if (n.op == TK_TILDE) { emit_line("\tNOTQ\tAX\n"); return; }; - if (n.op == TK_STAR) { emit_line("\tMOVQ\t(AX), AX\n"); return; }; + if (n.op == TK_MINUS) { emitline("\tNEGQ\tAX\n"); return; }; + if (n.op == TK_TILDE) { emitline("\tNOTQ\tAX\n"); return; }; + if (n.op == TK_STAR) { emitline("\tMOVQ\t(AX), AX\n"); return; }; if (n.op == TK_AMP) { let opnd: *node = n.lhs; if (opnd != nil) { if (opnd.kind == N_IDENT) { let nm: str = opnd.str; - let off: i32 = local_find(c, nm); + let off: i32 = localfind(c, nm); if (off != 0) { - emit_line("\tLEAQ\t"); - emit_off(off: i64); - emit_line("(BP), AX\n"); + emitline("\tLEAQ\t"); + emitoff(off: i64); + emitline("(BP), AX\n"); return; }; }; @@ -1701,95 +1701,95 @@ fn cgexpr(c: *cgen, n: *node) void = { if (n.op == TK_NOT) { let t: str = mklabel(c, "tt"); let e: str = mklabel(c, "te"); - emit_line("\tCMPQ\t$0, AX\n"); - emit_line("\tJE\t"); emit_line(t); emit_line("\n"); - emit_line("\tMOVQ\t$0, AX\n"); - emit_line("\tJMP\t"); emit_line(e); emit_line("\n"); - emit_label(t); - emit_line("\tMOVQ\t$1, AX\n"); - emit_label(e); + emitline("\tCMPQ\t$0, AX\n"); + emitline("\tJE\t"); emitline(t); emitline("\n"); + emitline("\tMOVQ\t$0, AX\n"); + emitline("\tJMP\t"); emitline(e); emitline("\n"); + emitlabel(t); + emitline("\tMOVQ\t$1, AX\n"); + emitlabel(e); return; }; return; }; if (k == N_BIN) { - let unsignd: bool = node_isunsigned(c, n.lhs); - if (!unsignd) { unsignd = node_isunsigned(c, n.rhs); }; + let unsignd: bool = nodeisunsigned(c, n.lhs); + if (!unsignd) { unsignd = nodeisunsigned(c, n.rhs); }; cgexpr(c, n.rhs); - emit_line("\tPUSHQ\tAX\n"); + emitline("\tPUSHQ\tAX\n"); cgexpr(c, n.lhs); - emit_line("\tPOPQ\tBX\n"); - if (n.op == TK_PLUS) { emit_line("\tADDQ\tBX, AX\n"); return; }; - if (n.op == TK_MINUS) { emit_line("\tSUBQ\tBX, AX\n"); return; }; - if (n.op == TK_STAR) { emit_line("\tIMULQ\tBX, AX\n"); return; }; + emitline("\tPOPQ\tBX\n"); + if (n.op == TK_PLUS) { emitline("\tADDQ\tBX, AX\n"); return; }; + if (n.op == TK_MINUS) { emitline("\tSUBQ\tBX, AX\n"); return; }; + if (n.op == TK_STAR) { emitline("\tIMULQ\tBX, AX\n"); return; }; if (n.op == TK_SLASH) { - emit_line("\tMOVQ\t$0, DX\n"); - if (unsignd) { emit_line("\tDIVQ\tBX\n"); } - else { emit_line("\tIDIVQ\tBX\n"); }; + emitline("\tMOVQ\t$0, DX\n"); + if (unsignd) { emitline("\tDIVQ\tBX\n"); } + else { emitline("\tIDIVQ\tBX\n"); }; return; }; if (n.op == TK_PERCENT) { - emit_line("\tMOVQ\t$0, DX\n"); - if (unsignd) { emit_line("\tDIVQ\tBX\n"); } - else { emit_line("\tIDIVQ\tBX\n"); }; - emit_line("\tMOVQ\tDX, AX\n"); + emitline("\tMOVQ\t$0, DX\n"); + if (unsignd) { emitline("\tDIVQ\tBX\n"); } + else { emitline("\tIDIVQ\tBX\n"); }; + emitline("\tMOVQ\tDX, AX\n"); return; }; - if (n.op == TK_AMP) { emit_line("\tANDQ\tBX, AX\n"); return; }; - if (n.op == TK_PIPE) { emit_line("\tORQ\tBX, AX\n"); return; }; - if (n.op == TK_CARET) { emit_line("\tXORQ\tBX, AX\n"); return; }; + if (n.op == TK_AMP) { emitline("\tANDQ\tBX, AX\n"); return; }; + if (n.op == TK_PIPE) { emitline("\tORQ\tBX, AX\n"); return; }; + if (n.op == TK_CARET) { emitline("\tXORQ\tBX, AX\n"); return; }; if (n.op == TK_LSHIFT) { - emit_line("\tMOVQ\tBX, CX\n"); - emit_line("\tSHLQ\tCX, AX\n"); + emitline("\tMOVQ\tBX, CX\n"); + emitline("\tSHLQ\tCX, AX\n"); return; }; if (n.op == TK_RSHIFT) { - emit_line("\tMOVQ\tBX, CX\n"); - emit_line("\tSHRQ\tCX, AX\n"); + emitline("\tMOVQ\tBX, CX\n"); + emitline("\tSHRQ\tCX, AX\n"); return; }; - if (n.op == TK_AND) { emit_line("\tANDQ\tBX, AX\n"); return; }; - if (n.op == TK_OR) { emit_line("\tORQ\tBX, AX\n"); return; }; + if (n.op == TK_AND) { emitline("\tANDQ\tBX, AX\n"); return; }; + if (n.op == TK_OR) { emitline("\tORQ\tBX, AX\n"); return; }; // Comparison: emit CMPQ, jump on signed/unsigned variant, // materialise 0/1 in AX. Same shape as the C cgen. - let is_cmp: bool = false; + let iscmp: bool = false; let jcc: str = ""; - if (n.op == TK_EQ) { is_cmp = true; jcc = "JE"; }; - if (n.op == TK_NEQ) { is_cmp = true; jcc = "JNE"; }; - if (n.op == TK_LT) { is_cmp = true; if (unsignd) { jcc = "JB"; } else { jcc = "JL"; }; }; - if (n.op == TK_LE) { is_cmp = true; if (unsignd) { jcc = "JBE"; } else { jcc = "JLE"; }; }; - if (n.op == TK_GT) { is_cmp = true; if (unsignd) { jcc = "JA"; } else { jcc = "JG"; }; }; - if (n.op == TK_GE) { is_cmp = true; if (unsignd) { jcc = "JAE"; } else { jcc = "JGE"; }; }; - if (is_cmp) { + if (n.op == TK_EQ) { iscmp = true; jcc = "JE"; }; + if (n.op == TK_NEQ) { iscmp = true; jcc = "JNE"; }; + if (n.op == TK_LT) { iscmp = true; if (unsignd) { jcc = "JB"; } else { jcc = "JL"; }; }; + if (n.op == TK_LE) { iscmp = true; if (unsignd) { jcc = "JBE"; } else { jcc = "JLE"; }; }; + if (n.op == TK_GT) { iscmp = true; if (unsignd) { jcc = "JA"; } else { jcc = "JG"; }; }; + if (n.op == TK_GE) { iscmp = true; if (unsignd) { jcc = "JAE"; } else { jcc = "JGE"; }; }; + if (iscmp) { let t: str = mklabel(c, "ct"); let e: str = mklabel(c, "ce"); - emit_line("\tCMPQ\tBX, AX\n"); - emit_line("\t"); emit_line(jcc); emit_line("\t"); emit_line(t); emit_line("\n"); - emit_line("\tMOVQ\t$0, AX\n"); - emit_line("\tJMP\t"); emit_line(e); emit_line("\n"); - emit_label(t); - emit_line("\tMOVQ\t$1, AX\n"); - emit_label(e); + emitline("\tCMPQ\tBX, AX\n"); + emitline("\t"); emitline(jcc); emitline("\t"); emitline(t); emitline("\n"); + emitline("\tMOVQ\t$0, AX\n"); + emitline("\tJMP\t"); emitline(e); emitline("\n"); + emitlabel(t); + emitline("\tMOVQ\t$1, AX\n"); + emitlabel(e); return; }; return; }; if (k == N_CALL) { - let nargs: i32 = push_args_rev(c, n.list); + let nargs: i32 = pushargsrev(c, n.list); let i: i32 = 0; for (i < nargs) { - emit_line("\tPOPQ\t"); - emit_line(argreg_name(i)); - emit_line("\n"); + emitline("\tPOPQ\t"); + emitline(argregname(i)); + emitline("\n"); i += 1; }; let callee: *node = n.lhs; - let callee_name: str; - callee_name.ptr = nil; callee_name.len = 0; + let calleename: str; + calleename.ptr = nil; calleename.len = 0; // Detect fn-pointer field call: `w.emit(args)` where `w` is // a struct local and `emit` is an N_TFN field. Load the // field value into AX and CALL through it. Also detect a @@ -1797,12 +1797,12 @@ fn cgexpr(c: *cgen, n: *node) void = { // pointer — mirror C cgen's localfind dispatch (commit // 635818e). Without this the call emits `CALL fp(SB)` and // the linker rightly fails. - let is_fnptr_call: bool = false; + let isfnptrcall: bool = false; if (callee != nil) { if (callee.kind == N_IDENT) { let cn: str = callee.str; - if (local_find_node(c, cn) != nil) { - is_fnptr_call = true; + if (localfindnode(c, cn) != nil) { + isfnptrcall = true; }; }; if (callee.kind == N_DOT) { @@ -1811,7 +1811,7 @@ fn cgexpr(c: *cgen, n: *node) void = { if (base != nil) { if (base.kind == N_IDENT) { let bn: str = base.str; - let lc: *local = local_find_node(c, bn); + let lc: *local = localfindnode(c, bn); if (lc != nil) { let tn: *node = lc.tnode; if (tn != nil) { @@ -1826,16 +1826,16 @@ fn cgexpr(c: *cgen, n: *node) void = { }; }; if (sname.len > 0) { - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fld)) { let ft: *node = fi.tnode; if (ft != nil) { if (ft.kind == N_TFN) { - is_fnptr_call = true; + isfnptrcall = true; }; }; fi = nil; @@ -1851,34 +1851,34 @@ fn cgexpr(c: *cgen, n: *node) void = { }; }; }; - if (is_fnptr_call) { + if (isfnptrcall) { // Load fn-ptr field value into AX; CALL AX. We emit the // load AFTER the args have been popped (so AX/BX/etc // don't get clobbered by the field load before the pops). // `popped args` left DI/SI/etc set; AX is free. cgexpr(c, callee); - emit_line("\tCALL\tAX\n"); + emitline("\tCALL\tAX\n"); } else { - emit_line("\tCALL\t"); + emitline("\tCALL\t"); if (callee != nil) { if (callee.kind == N_IDENT) { - callee_name = callee.str; - let resolved: str = ffi_resolve(c, callee_name); + calleename = callee.str; + let resolved: str = ffiresolve(c, calleename); os.write(1, resolved.ptr, resolved.len: u64); } else { if (callee.kind == N_DOT) { - callee_name = callee.str; - let resolved: str = ffi_resolve(c, callee_name); + calleename = callee.str; + let resolved: str = ffiresolve(c, calleename); os.write(1, resolved.ptr, resolved.len: u64); };}; }; - emit_line("(SB)\n"); + emitline("(SB)\n"); }; // SysV returns 16-byte aggregates in (AX, DX). Our str // convention is (AX, BX), so shuffle for str-returning calls. - if (callee_name.len > 0) { - let rt: *node = fnret_lookup(c, callee_name); - if (is_str_type(c, rt)) { - emit_line("\tMOVQ\tDX, BX\n"); + if (calleename.len > 0) { + let rt: *node = fnretlookup(c, calleename); + if (isstrtype(c, rt)) { + emitline("\tMOVQ\tDX, BX\n"); }; }; return; @@ -1896,11 +1896,11 @@ fn cgexpr(c: *cgen, n: *node) void = { if (lhs.op == TK_STAR) { if (n.op == TK_ASSIGN) { let inner: *node = lhs.lhs; - let elem_str: bool = false; - let store_op: str = "MOVQ"; + let elemstr: bool = false; + let storeop: str = "MOVQ"; if (inner != nil) { if (inner.kind == N_IDENT) { - let lc: *local = local_find_node(c, inner.str); + let lc: *local = localfindnode(c, inner.str); if (lc != nil) { let tn: *node = lc.tnode; if (tn != nil) { @@ -1908,11 +1908,11 @@ fn cgexpr(c: *cgen, n: *node) void = { let pe: *node = tn.lhs; if (pe != nil) { if (pe.kind == N_TNAME) { - if (streq(pe.str, "str")) { elem_str = true; } + if (streq(pe.str, "str")) { elemstr = true; } else { - let ps: i32 = prim_size(pe.str); - if (ps == 1) { store_op = "MOVB"; } - else { if (ps == 4) { store_op = "MOVL"; }; }; + let ps: i32 = primsize(pe.str); + if (ps == 1) { storeop = "MOVB"; } + else { if (ps == 4) { storeop = "MOVL"; }; }; }; }; }; @@ -1928,21 +1928,21 @@ fn cgexpr(c: *cgen, n: *node) void = { // str, so the pop sequence is POP CX // (len) → POP AX (ptr) → MOVQ AX, // (BX) → MOVQ CX, 8(BX). - emit_line("\tPUSHQ\tAX\n"); - if (elem_str) { emit_line("\tPUSHQ\tBX\n"); }; + emitline("\tPUSHQ\tAX\n"); + if (elemstr) { emitline("\tPUSHQ\tBX\n"); }; cgexpr(c, inner); - emit_line("\tMOVQ\tAX, BX\n"); - if (elem_str) { - emit_line("\tPOPQ\tCX\n"); - emit_line("\tPOPQ\tAX\n"); - emit_line("\tMOVQ\tAX, (BX)\n"); - emit_line("\tMOVQ\tCX, 8(BX)\n"); + emitline("\tMOVQ\tAX, BX\n"); + if (elemstr) { + emitline("\tPOPQ\tCX\n"); + emitline("\tPOPQ\tAX\n"); + emitline("\tMOVQ\tAX, (BX)\n"); + emitline("\tMOVQ\tCX, 8(BX)\n"); return; }; - emit_line("\tPOPQ\tAX\n"); - emit_line("\t"); - emit_line(store_op); - emit_line("\tAX, (BX)\n"); + emitline("\tPOPQ\tAX\n"); + emitline("\t"); + emitline(storeop); + emitline("\tAX, (BX)\n"); return; }; }; @@ -1956,57 +1956,57 @@ fn cgexpr(c: *cgen, n: *node) void = { let base: *node = lhs.lhs; let idx: *node = lhs.rhs; let esz: i32 = 8; - let base_local: *local = nil; + let baselocal: *local = nil; if (base != nil) { if (base.kind == N_IDENT) { let bn: str = base.str; - base_local = local_find_node(c, bn); - if (base_local != nil) { - esz = elem_size_of(base_local.tnode); + baselocal = localfindnode(c, bn); + if (baselocal != nil) { + esz = elemsizeof(baselocal.tnode); }; } else { if (base.kind == N_DOT) { - esz = index_base_esz(c, base); + esz = indexbaseesz(c, base); };}; }; cgexpr(c, n.rhs); // value → AX - if (esz == 16) { emit_line("\tPUSHQ\tBX\n"); }; - emit_line("\tPUSHQ\tAX\n"); + if (esz == 16) { emitline("\tPUSHQ\tBX\n"); }; + emitline("\tPUSHQ\tAX\n"); cgexpr(c, idx); // idx → AX if (esz > 1) { - emit_line("\tMOVQ\t$"); - emit_int(esz: i64); - emit_line(", CX\n"); - emit_line("\tIMULQ\tCX, AX\n"); + emitline("\tMOVQ\t$"); + emitint(esz: i64); + emitline(", CX\n"); + emitline("\tIMULQ\tCX, AX\n"); }; - emit_line("\tPUSHQ\tAX\n"); // scaled idx - if (base_local != nil) { - let tn: *node = base_local.tnode; - let is_array: bool = false; - if (tn != nil) { if (tn.kind == N_TARRAY) { is_array = true; }; }; - if (is_array) { - emit_line("\tLEAQ\t"); - emit_off(base_local.off: i64); - emit_line("(BP), BX\n"); + emitline("\tPUSHQ\tAX\n"); // scaled idx + if (baselocal != nil) { + let tn: *node = baselocal.tnode; + let isarray: bool = false; + if (tn != nil) { if (tn.kind == N_TARRAY) { isarray = true; }; }; + if (isarray) { + emitline("\tLEAQ\t"); + emitoff(baselocal.off: i64); + emitline("(BP), BX\n"); } else { - emit_line("\tMOVQ\t"); - emit_off(base_local.off: i64); - emit_line("(BP), BX\n"); + emitline("\tMOVQ\t"); + emitoff(baselocal.off: i64); + emitline("(BP), BX\n"); }; } else { cgexpr(c, base); - emit_line("\tMOVQ\tAX, BX\n"); + emitline("\tMOVQ\tAX, BX\n"); }; - emit_line("\tPOPQ\tAX\n"); // scaled idx - emit_line("\tADDQ\tAX, BX\n"); - emit_line("\tPOPQ\tAX\n"); // value + emitline("\tPOPQ\tAX\n"); // scaled idx + emitline("\tADDQ\tAX, BX\n"); + emitline("\tPOPQ\tAX\n"); // value if (esz == 16) { - emit_line("\tMOVQ\tAX, (BX)\n"); - emit_line("\tPOPQ\tCX\n"); - emit_line("\tMOVQ\tCX, 8(BX)\n"); + emitline("\tMOVQ\tAX, (BX)\n"); + emitline("\tPOPQ\tCX\n"); + emitline("\tMOVQ\tCX, 8(BX)\n"); return; }; - if (esz == 1) { emit_line("\tMOVB\tAX, (BX)\n"); } - else { emit_line("\tMOVQ\tAX, (BX)\n"); }; + if (esz == 1) { emitline("\tMOVB\tAX, (BX)\n"); } + else { emitline("\tMOVQ\tAX, (BX)\n"); }; return; }; }; @@ -2021,7 +2021,7 @@ fn cgexpr(c: *cgen, n: *node) void = { if (base != nil) { if (base.kind == N_IDENT) { let bn: str = base.str; - let lc: *local = local_find_node(c, bn); + let lc: *local = localfindnode(c, bn); if (lc != nil) { let tn: *node = lc.tnode; let lkind: i32 = -1; @@ -2035,35 +2035,35 @@ fn cgexpr(c: *cgen, n: *node) void = { if (inner.kind == N_TNAME) { sname = inner.str; }; }; if (sname.len > 0) { - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fld)) { if (n.op != TK_ASSIGN) { // compound: load current value - emit_line("\tMOVQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), BX\n"); - let lop: str = field_load_op(fi); - emit_line("\t"); - emit_line(lop); - emit_line("\t"); - emit_disp_reg(fi.foff: i64, "BX"); - emit_line(", BX\n"); - emit_line("\tPUSHQ\tBX\n"); + emitline("\tMOVQ\t"); + emitoff(lc.off: i64); + emitline("(BP), BX\n"); + let lop: str = fieldloadop(fi); + emitline("\t"); + emitline(lop); + emitline("\t"); + emitdispreg(fi.foff: i64, "BX"); + emitline(", BX\n"); + emitline("\tPUSHQ\tBX\n"); }; cgexpr(c, n.rhs); if (n.op != TK_ASSIGN) { - emit_line("\tPOPQ\tBX\n"); + emitline("\tPOPQ\tBX\n"); // PLUSEQ is commutative; MINUSEQ // needs lhs - rhs (BX is old lhs, // AX is rhs). - if (n.op == TK_PLUSEQ) { emit_line("\tADDQ\tBX, AX\n"); }; + if (n.op == TK_PLUSEQ) { emitline("\tADDQ\tBX, AX\n"); }; if (n.op == TK_MINUSEQ) { - emit_line("\tSUBQ\tAX, BX\n"); - emit_line("\tMOVQ\tBX, AX\n"); + emitline("\tSUBQ\tAX, BX\n"); + emitline("\tMOVQ\tBX, AX\n"); }; }; // str field via *struct: rhs left @@ -2071,28 +2071,28 @@ fn cgexpr(c: *cgen, n: *node) void = { // address scratch so we don't clobber // the len half before storing it. if (n.op == TK_ASSIGN) { - if (is_str_type(c, fi.tnode)) { - emit_line("\tMOVQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), CX\n"); - emit_line("\tMOVQ\tAX, "); - emit_disp_reg(fi.foff: i64, "CX"); - emit_line("\n"); - emit_line("\tMOVQ\tBX, "); - emit_disp_reg((fi.foff + 8): i64, "CX"); - emit_line("\n"); + if (isstrtype(c, fi.tnode)) { + emitline("\tMOVQ\t"); + emitoff(lc.off: i64); + emitline("(BP), CX\n"); + emitline("\tMOVQ\tAX, "); + emitdispreg(fi.foff: i64, "CX"); + emitline("\n"); + emitline("\tMOVQ\tBX, "); + emitdispreg((fi.foff + 8): i64, "CX"); + emitline("\n"); return; }; }; - emit_line("\tMOVQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), BX\n"); - let sop: str = field_store_op(fi); - emit_line("\t"); - emit_line(sop); - emit_line("\tAX, "); - emit_disp_reg(fi.foff: i64, "BX"); - emit_line("\n"); + emitline("\tMOVQ\t"); + emitoff(lc.off: i64); + emitline("(BP), BX\n"); + let sop: str = fieldstoreop(fi); + emitline("\t"); + emitline(sop); + emitline("\tAX, "); + emitdispreg(fi.foff: i64, "BX"); + emitline("\n"); return; }; fi = fi.finext; @@ -2103,19 +2103,19 @@ fn cgexpr(c: *cgen, n: *node) void = { // Direct struct local: store at off+foff. if (lkind == N_TNAME) { let sname: str = tn.str; - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fld)) { cgexpr(c, n.rhs); - let sop: str = field_store_op(fi); - emit_line("\t"); - emit_line(sop); - emit_line("\tAX, "); - emit_off((lc.off + fi.foff): i64); - emit_line("(BP)\n"); + let sop: str = fieldstoreop(fi); + emitline("\t"); + emitline(sop); + emitline("\tAX, "); + emitoff((lc.off + fi.foff): i64); + emitline("(BP)\n"); return; }; fi = fi.finext; @@ -2130,55 +2130,55 @@ fn cgexpr(c: *cgen, n: *node) void = { if (delta >= 0) { if (lkind == N_TPTR) { let inner: *node = tn.lhs; - let inner_kind: i32 = -1; - if (inner != nil) { inner_kind = inner.kind; }; - let inner_str: bool = false; - if (inner_kind == N_TNAME) { - if (streq(inner.str, "str")) { inner_str = true; }; + let innerkind: i32 = -1; + if (inner != nil) { innerkind = inner.kind; }; + let innerstr: bool = false; + if (innerkind == N_TNAME) { + if (streq(inner.str, "str")) { innerstr = true; }; }; - if (inner_kind == N_TSLICE) { inner_str = true; }; - if (inner_str) { + if (innerkind == N_TSLICE) { innerstr = true; }; + if (innerstr) { if (n.op != TK_ASSIGN) { // Compound on `(*str|*slice).field`: load // current → push → eval rhs → combine → store. - emit_line("\tMOVQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), BX\n"); - emit_line("\tMOVQ\t"); - emit_disp_reg(delta: i64, "BX"); - emit_line(", BX\n"); - emit_line("\tPUSHQ\tBX\n"); + emitline("\tMOVQ\t"); + emitoff(lc.off: i64); + emitline("(BP), BX\n"); + emitline("\tMOVQ\t"); + emitdispreg(delta: i64, "BX"); + emitline(", BX\n"); + emitline("\tPUSHQ\tBX\n"); cgexpr(c, n.rhs); - emit_line("\tPOPQ\tBX\n"); + emitline("\tPOPQ\tBX\n"); // PLUSEQ is commutative; MINUSEQ // needs lhs - rhs. - if (n.op == TK_PLUSEQ) { emit_line("\tADDQ\tBX, AX\n"); }; + if (n.op == TK_PLUSEQ) { emitline("\tADDQ\tBX, AX\n"); }; if (n.op == TK_MINUSEQ) { - emit_line("\tSUBQ\tAX, BX\n"); - emit_line("\tMOVQ\tBX, AX\n"); + emitline("\tSUBQ\tAX, BX\n"); + emitline("\tMOVQ\tBX, AX\n"); }; - emit_line("\tMOVQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), BX\n"); - emit_line("\tMOVQ\tAX, "); - emit_disp_reg(delta: i64, "BX"); - emit_line("\n"); + emitline("\tMOVQ\t"); + emitoff(lc.off: i64); + emitline("(BP), BX\n"); + emitline("\tMOVQ\tAX, "); + emitdispreg(delta: i64, "BX"); + emitline("\n"); return; }; cgexpr(c, n.rhs); - emit_line("\tMOVQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), BX\n"); - emit_line("\tMOVQ\tAX, "); - emit_disp_reg(delta: i64, "BX"); - emit_line("\n"); + emitline("\tMOVQ\t"); + emitoff(lc.off: i64); + emitline("(BP), BX\n"); + emitline("\tMOVQ\tAX, "); + emitdispreg(delta: i64, "BX"); + emitline("\n"); return; }; }; cgexpr(c, n.rhs); - emit_line("\tMOVQ\tAX, "); - emit_off((lc.off + delta): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tAX, "); + emitoff((lc.off + delta): i64); + emitline("(BP)\n"); return; }; }; @@ -2192,56 +2192,56 @@ fn cgexpr(c: *cgen, n: *node) void = { if (lhs != nil) { if (lhs.kind == N_IDENT) { let nm: str = lhs.str; - let off: i32 = local_find(c, nm); + let off: i32 = localfind(c, nm); if (off == 0) { return; }; // Detect str-typed local — assignment must store both // halves (AX=ptr at +0, BX=len at +8). - let lc_str: bool = false; - let lcn: *local = local_find_node(c, nm); - if (lcn != nil) { lc_str = is_str_type(c, lcn.tnode); }; + let lcstr: bool = false; + let lcn: *local = localfindnode(c, nm); + if (lcn != nil) { lcstr = isstrtype(c, lcn.tnode); }; cgexpr(c, n.rhs); if (n.op == TK_ASSIGN) { - emit_line("\tMOVQ\tAX, "); - emit_off(off: i64); - emit_line("(BP)\n"); - if (lc_str) { - emit_line("\tMOVQ\tBX, "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tAX, "); + emitoff(off: i64); + emitline("(BP)\n"); + if (lcstr) { + emitline("\tMOVQ\tBX, "); + emitoff((off + 8): i64); + emitline("(BP)\n"); }; return; }; if (n.op == TK_PLUSEQ) { - emit_line("\tADDQ\tAX, "); - emit_off(off: i64); - emit_line("(BP)\n"); + emitline("\tADDQ\tAX, "); + emitoff(off: i64); + emitline("(BP)\n"); return; }; if (n.op == TK_MINUSEQ) { - emit_line("\tSUBQ\tAX, "); - emit_off(off: i64); - emit_line("(BP)\n"); + emitline("\tSUBQ\tAX, "); + emitoff(off: i64); + emitline("(BP)\n"); return; }; // Generic compound: load → combine in BX → store. - emit_line("\tMOVQ\t"); - emit_off(off: i64); - emit_line("(BP), BX\n"); - if (n.op == TK_STAREQ) { emit_line("\tIMULQ\tAX, BX\n"); }; - if (n.op == TK_AMPEQ) { emit_line("\tANDQ\tAX, BX\n"); }; - if (n.op == TK_PIPEEQ) { emit_line("\tORQ\tAX, BX\n"); }; - if (n.op == TK_CARETEQ) { emit_line("\tXORQ\tAX, BX\n"); }; + emitline("\tMOVQ\t"); + emitoff(off: i64); + emitline("(BP), BX\n"); + if (n.op == TK_STAREQ) { emitline("\tIMULQ\tAX, BX\n"); }; + if (n.op == TK_AMPEQ) { emitline("\tANDQ\tAX, BX\n"); }; + if (n.op == TK_PIPEEQ) { emitline("\tORQ\tAX, BX\n"); }; + if (n.op == TK_CARETEQ) { emitline("\tXORQ\tAX, BX\n"); }; if (n.op == TK_LSHIFTEQ) { - emit_line("\tMOVQ\tAX, CX\n"); - emit_line("\tSHLQ\tCX, BX\n"); + emitline("\tMOVQ\tAX, CX\n"); + emitline("\tSHLQ\tCX, BX\n"); }; if (n.op == TK_RSHIFTEQ) { - emit_line("\tMOVQ\tAX, CX\n"); - emit_line("\tSHRQ\tCX, BX\n"); + emitline("\tMOVQ\tAX, CX\n"); + emitline("\tSHRQ\tCX, BX\n"); }; - emit_line("\tMOVQ\tBX, "); - emit_off(off: i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tBX, "); + emitoff(off: i64); + emitline("(BP)\n"); return; }; }; @@ -2251,8 +2251,8 @@ fn cgexpr(c: *cgen, n: *node) void = { // ---- type-driven slot sizing ---------------------------------------- -fn struct_lookup(c: *cgen, name: str) *struct_info = { - let s: *struct_info = c.structs; +fn structlookup(c: *cgen, name: str) *structinfo = { + let s: *structinfo = c.structs; for (s != nil) { let sn: str = s.sname; if (streq(sn, name)) { return s; }; @@ -2261,9 +2261,9 @@ fn struct_lookup(c: *cgen, name: str) *struct_info = { return nil; }; -// prim_size — size in bytes of a primitive type name (or 0 if not +// primsize — size in bytes of a primitive type name (or 0 if not // recognised as a primitive — the caller falls back to other paths). -fn prim_size(name: str) i32 = { +fn primsize(name: str) i32 = { if (streq(name, "u8")) { return 1; }; if (streq(name, "i8")) { return 1; }; if (streq(name, "bool")) { return 1; }; @@ -2283,7 +2283,7 @@ fn prim_size(name: str) i32 = { return 0; }; -fn slot_size(c: *cgen, typ_n: *node) i32 = { +fn slotsize(c: *cgen, typ_n: *node) i32 = { if (typ_n == nil) { return 8; }; let k: i32 = typ_n.kind; if (k == N_TPTR) { return 8; }; @@ -2295,29 +2295,29 @@ fn slot_size(c: *cgen, typ_n: *node) i32 = { if (k == N_TNAME) { let nm: str = typ_n.str; if (streq(nm, "str")) { return 16; }; - let ps: i32 = prim_size(nm); + let ps: i32 = primsize(nm); if (ps > 0) { // Pad to 8 for stack slots — matches C cgen which spills // every primitive into an 8-byte slot. return 8; }; // Named struct lookup. - let si: *struct_info = struct_lookup(c, nm); + let si: *structinfo = structlookup(c, nm); if (si != nil) { return si.tot_size; }; return 8; }; if (k == N_TARRAY) { - let len_n: *node = typ_n.rhs; - let elem_n: *node = typ_n.lhs; + let lenn: *node = typ_n.rhs; + let elemn: *node = typ_n.lhs; let elen: i64 = 1i64; - if (len_n != nil) { - if (len_n.kind == N_INTLIT) { elen = len_n.uval: i64; }; + if (lenn != nil) { + if (lenn.kind == N_INTLIT) { elen = lenn.uval: i64; }; }; let esz: i32 = 8; - if (elem_n != nil) { - if (elem_n.kind == N_TNAME) { - let en: str = elem_n.str; - let ps: i32 = prim_size(en); + if (elemn != nil) { + if (elemn.kind == N_TNAME) { + let en: str = elemn.str; + let ps: i32 = primsize(en); if (ps > 0) { esz = ps; }; }; }; @@ -2329,7 +2329,7 @@ fn slot_size(c: *cgen, typ_n: *node) i32 = { let total: i32 = 0; for (f != nil) { if (f.kind == N_TFIELD) { - total += slot_size(c, f.lhs); + total += slotsize(c, f.lhs); }; f = f.next; }; @@ -2338,50 +2338,50 @@ fn slot_size(c: *cgen, typ_n: *node) i32 = { return 8; }; -// register_struct — compute field offsets + total size for a struct +// registerstruct — compute field offsets + total size for a struct // type-decl, store in c.structs. Field type sizes use the same -// slot_size logic (with primitives kept at their natural width — we +// slotsize logic (with primitives kept at their natural width — we // only round to 8 for stack slots, not struct interiors). -fn field_size(c: *cgen, tnode: *node) i32 = { +fn fieldsize(c: *cgen, tnode: *node) i32 = { if (tnode == nil) { return 8; }; let k: i32 = tnode.kind; if (k == N_TNAME) { let nm: str = tnode.str; if (streq(nm, "str")) { return 16; }; - let ps: i32 = prim_size(nm); + let ps: i32 = primsize(nm); if (ps > 0) { return ps; }; - let si: *struct_info = struct_lookup(c, nm); + let si: *structinfo = structlookup(c, nm); if (si != nil) { return si.tot_size; }; return 8; }; if (k == N_TPTR) { return 8; }; if (k == N_TSLICE) { return 24; }; if (k == N_TARRAY) { - // Same shape as slot_size's TARRAY branch. - let len_n: *node = tnode.rhs; - let elem_n: *node = tnode.lhs; + // Same shape as slotsize's TARRAY branch. + let lenn: *node = tnode.rhs; + let elemn: *node = tnode.lhs; let elen: i64 = 1i64; - if (len_n != nil) { - if (len_n.kind == N_INTLIT) { elen = len_n.uval: i64; }; + if (lenn != nil) { + if (lenn.kind == N_INTLIT) { elen = lenn.uval: i64; }; }; - let esz: i32 = field_size(c, elem_n); + let esz: i32 = fieldsize(c, elemn); return (esz: i64 * elen): i32; }; return 8; }; -fn register_struct(c: *cgen, name: str, tstruct: *node) void = { - let si: *struct_info = amalloc(c.a, 64u64): *struct_info; +fn registerstruct(c: *cgen, name: str, tstruct: *node) void = { + let si: *structinfo = amalloc(c.a, 64u64): *structinfo; si.sname = name; si.fields = nil; si.tot_size = 0; - let head: *field_info = nil; - let tail: *field_info = nil; + let head: *fieldinfo = nil; + let tail: *fieldinfo = nil; let off: i32 = 0; let f: *node = tstruct.list; for (f != nil) { if (f.kind == N_TFIELD) { - let sz: i32 = field_size(c, f.lhs); + let sz: i32 = fieldsize(c, f.lhs); // Align to 8 for any field >= 4 bytes (matches our other // cgen choices). i8/u8/bool may sit on odd byte offsets; // the C cgen does similar best-effort packing. @@ -2392,7 +2392,7 @@ fn register_struct(c: *cgen, name: str, tstruct: *node) void = { if ((off & (aln - 1)) != 0) { off = (off + aln - 1) & ~(aln - 1); }; - let fi: *field_info = amalloc(c.a, 48u64): *field_info; + let fi: *fieldinfo = amalloc(c.a, 48u64): *fieldinfo; fi.fname = f.str; fi.foff = off; fi.fsz = sz; @@ -2411,7 +2411,7 @@ fn register_struct(c: *cgen, name: str, tstruct: *node) void = { c.structs = si; }; -fn collect_structs(c: *cgen, file: *node) void = { +fn collectstructs(c: *cgen, file: *node) void = { c.structs = nil; if (file == nil) { return; }; let d: *node = file.list; @@ -2420,7 +2420,7 @@ fn collect_structs(c: *cgen, file: *node) void = { let body: *node = d.lhs; if (body != nil) { if (body.kind == N_TSTRUCT) { - register_struct(c, d.str, body); + registerstruct(c, d.str, body); }; }; }; @@ -2431,21 +2431,21 @@ fn collect_structs(c: *cgen, file: *node) void = { // ---- frame pre-scan -------------------------------------------------- // // Recursively walks the body to count every local `let`. Each gets a -// slot sized by slot_size(typ); 8-byte default. Match-bindings + for- +// slot sized by slotsize(typ); 8-byte default. Match-bindings + for- // init lets count too. Params are added by the cgfn driver. -fn scan_locals(c: *cgen, n: *node) i32 = { +fn scanlocals(c: *cgen, n: *node) i32 = { if (n == nil) { return 0; }; let total: i32 = 0; if (n.kind == N_LET) { - // Match local_add's rounding: < 8 bumps to 8, then 8-align. - // scan_locals must agree with local_add or the prologue + // 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 // caller's stack — corrupting whatever's at -frameSize..-1 // of the caller. Same-name re-declarations share the first - // slot (see scan_seen_mark / local_add). - if (!scan_seen_mark(c, n.str)) { - let sz: i32 = slot_size(c, n.lhs); + // slot (see scanseenmark / localadd). + if (!scanseenmark(c, n.str)) { + let sz: i32 = slotsize(c, n.lhs); if (sz < 8) { sz = 8; }; if ((sz & 7) != 0) { sz = (sz + 7) & ~7; }; total += sz; @@ -2456,26 +2456,26 @@ fn scan_locals(c: *cgen, n: *node) i32 = { // handles a match as an expression with a by-value locals copy, // 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 local_add then bumps it to. + // shrink the frame below what localadd then bumps it to. if (n.kind == N_MCASE) { let bn: str = n.str; if (bn.len > 0) { let pat: *node = n.lhs; if (pat != nil) { - if (is_str_type(c, pat)) { total += 16; } + if (isstrtype(c, pat)) { total += 16; } else { total += 8; }; }; }; }; - if (n.lhs != nil) { total += scan_locals(c, n.lhs); }; - if (n.rhs != nil) { total += scan_locals(c, n.rhs); }; - if (n.cond != nil) { total += scan_locals(c, n.cond); }; - if (n.body != nil) { total += scan_locals(c, n.body); }; - if (n.els != nil) { total += scan_locals(c, n.els); }; + if (n.lhs != nil) { total += scanlocals(c, n.lhs); }; + if (n.rhs != nil) { total += scanlocals(c, n.rhs); }; + if (n.cond != nil) { total += scanlocals(c, n.cond); }; + if (n.body != nil) { total += scanlocals(c, n.body); }; + if (n.els != nil) { total += scanlocals(c, n.els); }; if (n.list != nil) { let m: *node = n.list; for (m != nil) { - total += scan_locals(c, m); + total += scanlocals(c, m); m = m.next; }; }; @@ -2509,16 +2509,16 @@ fn cgstmt(c: *cgen, n: *node) void = { let v2: *node = v.next; if (v2 != nil) { cgexpr(c, v2); - emit_line("\tPUSHQ\tAX\n"); + emitline("\tPUSHQ\tAX\n"); cgexpr(c, v); - emit_line("\tPOPQ\tDX\n"); + emitline("\tPOPQ\tDX\n"); } else { cgexpr(c, v); }; }; - emit_line("\tMOVQ\tBP, SP\n"); - emit_line("\tPOPQ\tBP\n"); - emit_line("\tRET\n"); + emitline("\tMOVQ\tBP, SP\n"); + emitline("\tPOPQ\tBP\n"); + emitline("\tRET\n"); c.last_was_return = 1; return; }; @@ -2526,22 +2526,22 @@ fn cgstmt(c: *cgen, n: *node) void = { // For str variant, cgexpr leaves (AX=ptr, BX=len), so we // shuffle DX←AX (ptr) and CX←BX (len), then load tag. // For other variants, cgexpr leaves AX, shuffle DX←AX. - if (is_tagged_type(c.fn_ret)) { + if (istaggedtype(c.fn_ret)) { cgexpr(c, rhs); - let idx: i32 = tagged_variant_index(c, c.fn_ret, rhs); - if (node_isstr(c, rhs)) { - emit_line("\tMOVQ\tBX, CX\n"); - emit_line("\tMOVQ\tAX, DX\n"); + let idx: i32 = taggedvariantindex(c, c.fn_ret, rhs); + if (nodeisstr(c, rhs)) { + emitline("\tMOVQ\tBX, CX\n"); + emitline("\tMOVQ\tAX, DX\n"); } else { - emit_line("\tMOVQ\tAX, DX\n"); + emitline("\tMOVQ\tAX, DX\n"); }; - emit_line("\tMOVQ\t$"); + emitline("\tMOVQ\t$"); if (idx < 0) { idx = 0; }; - emit_int(idx: i64); - emit_line(", AX\n"); - emit_line("\tMOVQ\tBP, SP\n"); - emit_line("\tPOPQ\tBP\n"); - emit_line("\tRET\n"); + emitint(idx: i64); + emitline(", AX\n"); + emitline("\tMOVQ\tBP, SP\n"); + emitline("\tPOPQ\tBP\n"); + emitline("\tRET\n"); c.last_was_return = 1; return; }; @@ -2550,16 +2550,16 @@ fn cgstmt(c: *cgen, n: *node) void = { // Bare `return;` in a void fn — zero AX so the caller // sees a deterministic value (matches C cgen, which // always falls through to `cgexpr_int(c, 0)`). - emit_line("\tMOVQ\t$0, AX\n"); + emitline("\tMOVQ\t$0, AX\n"); }; // SysV: 16-byte aggregates (str, 2-tuple) return in (AX, DX). // cgexpr leaves str in (AX, BX); shuffle BX→DX. - if (is_str_type(c, c.fn_ret)) { - emit_line("\tMOVQ\tBX, DX\n"); + if (isstrtype(c, c.fn_ret)) { + emitline("\tMOVQ\tBX, DX\n"); }; - emit_line("\tMOVQ\tBP, SP\n"); - emit_line("\tPOPQ\tBP\n"); - emit_line("\tRET\n"); + emitline("\tMOVQ\tBP, SP\n"); + emitline("\tPOPQ\tBP\n"); + emitline("\tRET\n"); c.last_was_return = 1; return; }; @@ -2572,8 +2572,8 @@ fn cgstmt(c: *cgen, n: *node) void = { if (k == N_LET) { let nm: str = n.str; - let sz: i32 = slot_size(c, n.lhs); - let off: i32 = local_add(c, nm, sz, n.lhs); + let sz: i32 = slotsize(c, n.lhs); + let off: i32 = localadd(c, nm, sz, n.lhs); if (n.rhs != nil) { let rhs: *node = n.rhs; // Tagged-union init: `let r: (T | E) = expr;`. @@ -2582,54 +2582,54 @@ fn cgstmt(c: *cgen, n: *node) void = { // just spill all three. // - Otherwise rhs is a bare variant value: pack tag + // value(s). - if (is_tagged_type(n.lhs)) { - let rhs_returns_tagged: bool = false; + if (istaggedtype(n.lhs)) { + let rhsreturnstagged: bool = false; if (rhs.kind == N_CALL) { let callee: *node = rhs.lhs; if (callee != nil) { - let callee_name: str; - callee_name.ptr = nil; callee_name.len = 0; - if (callee.kind == N_IDENT) { callee_name = callee.str; }; - if (callee.kind == N_DOT) { callee_name = callee.str; }; - if (callee_name.len > 0) { - let rt: *node = fnret_lookup(c, callee_name); - if (is_tagged_type(rt)) { rhs_returns_tagged = true; }; + 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 (calleename.len > 0) { + let rt: *node = fnretlookup(c, calleename); + if (istaggedtype(rt)) { rhsreturnstagged = true; }; }; }; }; cgexpr(c, rhs); - if (rhs_returns_tagged) { - emit_line("\tMOVQ\tAX, "); - emit_off(off: i64); - emit_line("(BP)\n"); - emit_line("\tMOVQ\tDX, "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); - emit_line("\tMOVQ\tCX, "); - emit_off((off + 16): i64); - emit_line("(BP)\n"); + if (rhsreturnstagged) { + emitline("\tMOVQ\tAX, "); + emitoff(off: i64); + emitline("(BP)\n"); + emitline("\tMOVQ\tDX, "); + emitoff((off + 8): i64); + emitline("(BP)\n"); + emitline("\tMOVQ\tCX, "); + emitoff((off + 16): i64); + emitline("(BP)\n"); c.last_was_return = 0; return; }; - let tag_idx: i32 = tagged_variant_index(c, n.lhs, rhs); - if (tag_idx < 0) { tag_idx = 0; }; - if (node_isstr(c, rhs)) { - emit_line("\tMOVQ\tAX, "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); - emit_line("\tMOVQ\tBX, "); - emit_off((off + 16): i64); - emit_line("(BP)\n"); + let tagidx: i32 = taggedvariantindex(c, n.lhs, rhs); + if (tagidx < 0) { tagidx = 0; }; + if (nodeisstr(c, rhs)) { + emitline("\tMOVQ\tAX, "); + emitoff((off + 8): i64); + emitline("(BP)\n"); + emitline("\tMOVQ\tBX, "); + emitoff((off + 16): i64); + emitline("(BP)\n"); } else { - emit_line("\tMOVQ\tAX, "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tAX, "); + emitoff((off + 8): i64); + emitline("(BP)\n"); }; - emit_line("\tMOVQ\t$"); - emit_int(tag_idx: i64); - emit_line(", "); - emit_off(off: i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\t$"); + emitint(tagidx: i64); + emitline(", "); + emitoff(off: i64); + emitline("(BP)\n"); c.last_was_return = 0; return; }; @@ -2645,53 +2645,53 @@ fn cgstmt(c: *cgen, n: *node) void = { if (trefn.kind == N_IDENT) { sname = trefn.str; } else { if (trefn.kind == N_TNAME) { sname = trefn.str; }; }; }; - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let field_node: *node = rhs.list; - for (field_node != nil) { - if (field_node.kind == N_FIELD) { - let fname: str = field_node.str; - let fi: *field_info = si.fields; + let fieldnode: *node = rhs.list; + for (fieldnode != nil) { + if (fieldnode.kind == N_FIELD) { + let fname: str = fieldnode.str; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fname)) { - cgexpr(c, field_node.lhs); - let sop: str = field_store_op(fi); - emit_line("\t"); - emit_line(sop); - emit_line("\tAX, "); - emit_off((off + fi.foff): i64); - emit_line("(BP)\n"); + cgexpr(c, fieldnode.lhs); + let sop: str = fieldstoreop(fi); + emitline("\t"); + emitline(sop); + emitline("\tAX, "); + emitoff((off + fi.foff): i64); + emitline("(BP)\n"); fi = nil; } else { fi = fi.finext; }; }; }; - field_node = field_node.next; + fieldnode = fieldnode.next; }; c.last_was_return = 0; return; }; }; cgexpr(c, rhs); - emit_line("\tMOVQ\tAX, "); - emit_off(off: i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tAX, "); + emitoff(off: i64); + emitline("(BP)\n"); // str init: cgexpr also leaves len in BX; store both. if (sz == 16) { - emit_line("\tMOVQ\tBX, "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tBX, "); + emitoff((off + 8): i64); + emitline("(BP)\n"); }; // slice init: ptr/len/cap in AX/BX/CX. if (sz == 24) { - emit_line("\tMOVQ\tBX, "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); - emit_line("\tMOVQ\tCX, "); - emit_off((off + 16): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tBX, "); + emitoff((off + 8): i64); + emitline("(BP)\n"); + emitline("\tMOVQ\tCX, "); + emitoff((off + 16): i64); + emitline("(BP)\n"); }; } else { // Bare `let x: T;` with no initializer. C cgen @@ -2699,13 +2699,13 @@ fn cgstmt(c: *cgen, n: *node) void = { // the underlying type's natural size is 8 — pointers, // i64/u64, function pointers, ints. Structs/arrays/ // slices/strings/tagged/tuples are left for per-field - // writes. ww's slot_size pads struct slots up to 8, + // writes. ww's slotsize pads struct slots up to 8, // so we can't just check sz == 8: walk the type AST // directly to make the same call. - if (type_is_8byte_primitive(c, n.lhs)) { - emit_line("\tMOVQ\t$0, "); - emit_off(off: i64); - emit_line("(BP)\n"); + if (typeis8byteprimitive(c, n.lhs)) { + emitline("\tMOVQ\t$0, "); + emitoff(off: i64); + emitline("(BP)\n"); }; }; c.last_was_return = 0; @@ -2716,18 +2716,18 @@ fn cgstmt(c: *cgen, n: *node) void = { let els: str = mklabel(c, "else"); let endl: str = mklabel(c, "end"); cgexpr(c, n.cond); - emit_line("\tCMPQ\t$0, AX\n"); - emit_line("\tJE\t"); - if (n.els != nil) { emit_line(els); } - else { emit_line(endl); }; - emit_line("\n"); + emitline("\tCMPQ\t$0, AX\n"); + emitline("\tJE\t"); + if (n.els != nil) { emitline(els); } + else { emitline(endl); }; + emitline("\n"); if (n.body != nil) { cgstmt(c, n.body); }; if (n.els != nil) { - emit_line("\tJMP\t"); emit_line(endl); emit_line("\n"); - emit_label(els); + emitline("\tJMP\t"); emitline(endl); emitline("\n"); + emitlabel(els); cgstmt(c, n.els); }; - emit_label(endl); + emitlabel(endl); c.last_was_return = 0; return; }; @@ -2741,11 +2741,11 @@ fn cgstmt(c: *cgen, n: *node) void = { if (n.lhs != nil) { cgstmt(c, n.lhs); }; - emit_label(topl); + emitlabel(topl); if (n.cond != nil) { cgexpr(c, n.cond); - emit_line("\tCMPQ\t$0, AX\n"); - emit_line("\tJE\t"); emit_line(endl); emit_line("\n"); + emitline("\tCMPQ\t$0, AX\n"); + emitline("\tJE\t"); emitline(endl); emitline("\n"); }; c.loop_end_buf[c.loop_top] = endl; @@ -2757,8 +2757,8 @@ fn cgstmt(c: *cgen, n: *node) void = { c.loop_top -= 1; if (n.rhs != nil) { cgexpr(c, n.rhs); }; - emit_line("\tJMP\t"); emit_line(topl); emit_line("\n"); - emit_label(endl); + emitline("\tJMP\t"); emitline(topl); emitline("\n"); + emitlabel(endl); c.last_was_return = 0; return; }; @@ -2770,28 +2770,28 @@ fn cgstmt(c: *cgen, n: *node) void = { // as C — no fixture uses >2 today). if (k == N_MASSIGN) { if (n.rhs != nil) { cgexpr(c, n.rhs); }; - emit_line("\tPUSHQ\tDX\n"); + emitline("\tPUSHQ\tDX\n"); let l0: *node = n.list; let l1: *node = nil; if (l0 != nil) { l1 = l0.next; }; if (l0 != nil) { if (l0.kind == N_IDENT) { - let off: i32 = local_find(c, l0.str); + let off: i32 = localfind(c, l0.str); if (off != 0) { - emit_line("\tMOVQ\tAX, "); - emit_off(off: i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tAX, "); + emitoff(off: i64); + emitline("(BP)\n"); }; }; }; - emit_line("\tPOPQ\tDX\n"); + emitline("\tPOPQ\tDX\n"); if (l1 != nil) { if (l1.kind == N_IDENT) { - let off: i32 = local_find(c, l1.str); + let off: i32 = localfind(c, l1.str); if (off != 0) { - emit_line("\tMOVQ\tDX, "); - emit_off(off: i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tDX, "); + emitoff(off: i64); + emitline("(BP)\n"); }; }; }; @@ -2802,7 +2802,7 @@ fn cgstmt(c: *cgen, n: *node) void = { if (k == N_BREAK) { if (c.loop_top > 0) { let lbl: str = c.loop_end_buf[c.loop_top - 1]; - emit_line("\tJMP\t"); emit_line(lbl); emit_line("\n"); + emitline("\tJMP\t"); emitline(lbl); emitline("\n"); }; c.last_was_return = 0; return; @@ -2810,7 +2810,7 @@ fn cgstmt(c: *cgen, n: *node) void = { if (k == N_CONTINUE) { if (c.loop_top > 0) { let lbl: str = c.loop_cont_buf[c.loop_top - 1]; - emit_line("\tJMP\t"); emit_line(lbl); emit_line("\n"); + emitline("\tJMP\t"); emitline(lbl); emitline("\n"); }; c.last_was_return = 0; return; @@ -2821,10 +2821,10 @@ fn cgstmt(c: *cgen, n: *node) void = { // ---- function-level cgen --------------------------------------------- -// is_str_type — true when the type expr resolves (through any +// isstrtype — true when the type expr resolves (through any // `type X = str;` aliases) to `str`. Takes *cgen so it can walk the // alias chain registered at file load. -fn is_str_type_raw(t: *node) bool = { +fn isstrtyperaw(t: *node) bool = { if (t == nil) { return false; }; if (t.kind == N_TNAME) { let nm: str = t.str; @@ -2833,36 +2833,36 @@ fn is_str_type_raw(t: *node) bool = { return false; }; -fn is_str_type(c: *cgen, t: *node) bool = { - if (is_str_type_raw(t)) { return true; }; +fn isstrtype(c: *cgen, t: *node) bool = { + if (isstrtyperaw(t)) { return true; }; if (c == nil) { return false; }; - let r: *node = resolve_type(c, t); - return is_str_type_raw(r); + let r: *node = resolvetype(c, t); + return isstrtyperaw(r); }; -fn is_slice_type_raw(t: *node) bool = { +fn isslicetyperaw(t: *node) bool = { if (t == nil) { return false; }; if (t.kind == N_TSLICE) { return true; }; return false; }; -fn is_slice_type(c: *cgen, t: *node) bool = { - if (is_slice_type_raw(t)) { return true; }; +fn isslicetype(c: *cgen, t: *node) bool = { + if (isslicetyperaw(t)) { return true; }; if (c == nil) { return false; }; - let r: *node = resolve_type(c, t); - return is_slice_type_raw(r); + let r: *node = resolvetype(c, t); + return isslicetyperaw(r); }; -fn is_tagged_type(t: *node) bool = { +fn istaggedtype(t: *node) bool = { if (t == nil) { return false; }; if (t.kind == N_TTAGGED) { return true; }; return false; }; -// rhs_target_name — for a returned value, what's its declared (or +// rhstargetname — for a returned value, what's its declared (or // surface-inferred) type name? `expr: T` casts dictate T directly; // bare strlit/intlit fall back to a primitive name. -fn rhs_target_name(c: *cgen, rhs: *node) str = { +fn rhstargetname(c: *cgen, rhs: *node) str = { let nm: str; nm.ptr = nil; nm.len = 0; if (rhs == nil) { return nm; }; @@ -2875,7 +2875,7 @@ fn rhs_target_name(c: *cgen, rhs: *node) str = { }; if (rhs.kind == N_STRLIT) { return "str"; }; if (rhs.kind == N_IDENT) { - let lc: *local = local_find_node(c, rhs.str); + let lc: *local = localfindnode(c, rhs.str); if (lc != nil) { let tn: *node = lc.tnode; if (tn != nil) { @@ -2886,113 +2886,113 @@ fn rhs_target_name(c: *cgen, rhs: *node) str = { return nm; }; -// tagged_variant_index — given the tagged-union type expr and the +// taggedvariantindex — given the tagged-union type expr and the // returned value's surface type, find the matching variant's 0-based // index. Compare by exact type name first; if no match, fall back to // "any str-shape variant matches an str-typed value". -fn tagged_variant_index(c: *cgen, tagged: *node, rhs: *node) i32 = { +fn taggedvariantindex(c: *cgen, tagged: *node, rhs: *node) i32 = { if (tagged == nil) { return -1; }; if (rhs == nil) { return -1; }; - let want_name: str = rhs_target_name(c, rhs); - if (want_name.len > 0) { + let wantname: str = rhstargetname(c, rhs); + if (wantname.len > 0) { let v: *node = tagged.list; let idx: i32 = 0; for (v != nil) { if (v.kind == N_TNAME) { - if (streq(v.str, want_name)) { return idx; }; + if (streq(v.str, wantname)) { return idx; }; }; v = v.next; idx += 1; }; }; // Fallback: by str-shape (resolves aliases). - let want_str: bool = node_isstr(c, rhs); + let wantstr: bool = nodeisstr(c, rhs); let v: *node = tagged.list; let idx: i32 = 0; for (v != nil) { - let v_is_str: bool = false; + let visstr: bool = false; if (v.kind == N_TNAME) { - if (is_str_type(c, v)) { v_is_str = true; }; + if (isstrtype(c, v)) { visstr = true; }; }; - if (v_is_str == want_str) { return idx; }; + if (visstr == wantstr) { return idx; }; v = v.next; idx += 1; }; return -1; }; -fn cgfn_params(c: *cgen, params: *node) void = { +fn cgfnparams(c: *cgen, params: *node) void = { let p: *node = params; let idx: i32 = 0; for (p != nil) { if (p.kind == N_PARAM) { let nm: str = p.str; - if (is_tagged_type(p.lhs)) { + if (istaggedtype(p.lhs)) { // tagged-union param: passed in 3 regs (tag, v0, v1), // 24-byte slot. - let off: i32 = local_add(c, nm, 24, p.lhs); - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off(off: i64); - emit_line("(BP)\n"); + let off: i32 = localadd(c, nm, 24, p.lhs); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff(off: i64); + emitline("(BP)\n"); idx += 1; - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff((off + 8): i64); + emitline("(BP)\n"); idx += 1; - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off((off + 16): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff((off + 16): i64); + emitline("(BP)\n"); idx += 1; - } else { if (is_slice_type(c, p.lhs)) { + } else { if (isslicetype(c, p.lhs)) { // slice param: 3 regs (ptr, len, cap), 24-byte slot. - let off: i32 = local_add(c, nm, 24, p.lhs); - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off(off: i64); - emit_line("(BP)\n"); + let off: i32 = localadd(c, nm, 24, p.lhs); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff(off: i64); + emitline("(BP)\n"); idx += 1; - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff((off + 8): i64); + emitline("(BP)\n"); idx += 1; - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off((off + 16): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff((off + 16): i64); + emitline("(BP)\n"); idx += 1; - } else { if (is_str_type(c, p.lhs)) { + } else { if (isstrtype(c, p.lhs)) { // str param: passed in two regs (ptr, len). // Slot is 16 bytes; ptr at off+0, len at off+8. - let off: i32 = local_add(c, nm, 16, p.lhs); - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off(off: i64); - emit_line("(BP)\n"); + let off: i32 = localadd(c, nm, 16, p.lhs); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff(off: i64); + emitline("(BP)\n"); idx += 1; - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff((off + 8): i64); + emitline("(BP)\n"); idx += 1; } else { - let off: i32 = local_add(c, nm, 8, p.lhs); - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off(off: i64); - emit_line("(BP)\n"); + let off: i32 = localadd(c, nm, 8, p.lhs); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff(off: i64); + emitline("(BP)\n"); idx += 1; };};}; }; @@ -3001,48 +3001,48 @@ fn cgfn_params(c: *cgen, params: *node) void = { }; fn cgfn(c: *cgen, fn_: *node) void = { - cgen_init(c, c.a); + cgeninit(c, c.a); c.fn_name = fn_.str; c.fn_ret = fn_.lhs; - emit_line("TEXT "); + emitline("TEXT "); let nm: str = fn_.str; os.write(1, nm.ptr, nm.len: u64); - emit_line(",$"); + emitline(",$"); // Pre-scan total frame: 24 bytes per slice param, 16 per str - // param, 8 per other param, plus per-let from scan_locals. - // Seed c.locals with param-name stubs so scan_locals dedups a + // param, 8 per other param, plus per-let from scanlocals. + // Seed c.locals with param-name stubs so scanlocals dedups a // re-declared `let ` in the body against the param's // slot (matches C cgen). Stubs get cleared before emission. - let scan_p: *node = fn_.list; + let scanp: *node = fn_.list; let frame: i32 = 0; - for (scan_p != nil) { - if (scan_p.kind == N_PARAM) { - if (is_tagged_type(scan_p.lhs)) { frame += 24; } - else { if (is_slice_type(c, scan_p.lhs)) { frame += 24; } - else { if (is_str_type(c, scan_p.lhs)) { frame += 16; } + for (scanp != nil) { + if (scanp.kind == N_PARAM) { + if (istaggedtype(scanp.lhs)) { frame += 24; } + else { if (isslicetype(c, scanp.lhs)) { frame += 24; } + else { if (isstrtype(c, scanp.lhs)) { frame += 16; } else { frame += 8; }; }; }; - scan_seen_mark(c, scan_p.str); + scanseenmark(c, scanp.str); }; - scan_p = scan_p.next; + scanp = scanp.next; }; - if (fn_.body != nil) { frame += scan_locals(c, fn_.body); }; + if (fn_.body != nil) { frame += scanlocals(c, fn_.body); }; // Drop the stubs so emission rebuilds c.locals with real offsets. c.locals = nil; if ((frame & 15) != 0) { frame = (frame + 15) & ~15; }; - emit_int(frame: i64); - emit_line("\n"); + emitint(frame: i64); + emitline("\n"); - emit_line("\tPUSHQ\tBP\n"); - emit_line("\tMOVQ\tSP, BP\n"); - emit_line("\tSUBQ\t$"); - emit_int(frame: i64); - emit_line(", SP\n"); + emitline("\tPUSHQ\tBP\n"); + emitline("\tMOVQ\tSP, BP\n"); + emitline("\tSUBQ\t$"); + emitint(frame: i64); + emitline(", SP\n"); - cgfn_params(c, fn_.list); + cgfnparams(c, fn_.list); c.last_was_return = 0; if (fn_.body != nil) { cgstmt(c, fn_.body); }; @@ -3050,24 +3050,24 @@ fn cgfn(c: *cgen, fn_: *node) void = { // Zero AX before the fall-through return — matches C cgen, // which always emits this so void-returning fns don't leak // a stale callee value to their caller. - emit_line("\tMOVQ\t$0, AX\n"); - emit_line("\tMOVQ\tBP, SP\n"); - emit_line("\tPOPQ\tBP\n"); - emit_line("\tRET\n"); + emitline("\tMOVQ\t$0, AX\n"); + emitline("\tMOVQ\tBP, SP\n"); + emitline("\tPOPQ\tBP\n"); + emitline("\tRET\n"); }; }; // ---- file-level entry ------------------------------------------------ -export fn cg_file(c: *cgen, file: *node) void = { +export fn cgfile(c: *cgen, file: *node) void = { if (file == nil) { return; }; c.strlits = nil; c.strlit_seq = 0; - collect_aliases(c, file); - collect_structs(c, file); - collect_defs(c, file); - collect_fnrets(c, file); - ffi_collect(c, file); + collectaliases(c, file); + collectstructs(c, file); + collectdefs(c, file); + collectfnrets(c, file); + fficollect(c, file); let d: *node = file.list; for (d != nil) { if (d.kind == N_FNDECL) { @@ -3077,6 +3077,6 @@ export fn cg_file(c: *cgen, file: *node) void = { }; d = d.next; }; - emit_data_section(c); - emit_def_constants(c, file); + emitdatasection(c); + emitdefconstants(c, file); }; diff --git a/selfhost/cmd/wcc/check.ww b/selfhost/cmd/wcc/check.ww index 4132ddb5..82353c68 100644 --- a/selfhost/cmd/wcc/check.ww +++ b/selfhost/cmd/wcc/check.ww @@ -32,56 +32,56 @@ type checker = struct { verbose: i32, // when non-zero, log each unresolved name }; -// seed_primitives — install the built-in type names so `i32`, `str`, +// seedprimitives — install the built-in type names so `i32`, `str`, // etc. can be looked up like ordinary symbols. -fn seed_primitives(c: *checker) void = { - scope_define(c.top, "void", SK_TYPE, c.tc.ty_void, nil); - scope_define(c.top, "bool", SK_TYPE, c.tc.ty_bool, nil); - scope_define(c.top, "rune", SK_TYPE, c.tc.ty_rune, nil); - scope_define(c.top, "i8", SK_TYPE, c.tc.ty_i8, nil); - scope_define(c.top, "i16", SK_TYPE, c.tc.ty_i16, nil); - scope_define(c.top, "i32", SK_TYPE, c.tc.ty_i32, nil); - scope_define(c.top, "i64", SK_TYPE, c.tc.ty_i64, nil); - scope_define(c.top, "u8", SK_TYPE, c.tc.ty_u8, nil); - scope_define(c.top, "u16", SK_TYPE, c.tc.ty_u16, nil); - scope_define(c.top, "u32", SK_TYPE, c.tc.ty_u32, nil); - scope_define(c.top, "u64", SK_TYPE, c.tc.ty_u64, nil); - scope_define(c.top, "int", SK_TYPE, c.tc.ty_int, nil); - scope_define(c.top, "uint", SK_TYPE, c.tc.ty_uint, nil); - scope_define(c.top, "uintptr", SK_TYPE, c.tc.ty_uintptr, nil); - scope_define(c.top, "f32", SK_TYPE, c.tc.ty_f32, nil); - scope_define(c.top, "f64", SK_TYPE, c.tc.ty_f64, nil); - scope_define(c.top, "str", SK_TYPE, c.tc.ty_str, nil); +fn seedprimitives(c: *checker) void = { + scopedefine(c.top, "void", SK_TYPE, c.tc.ty_void, nil); + scopedefine(c.top, "bool", SK_TYPE, c.tc.ty_bool, nil); + scopedefine(c.top, "rune", SK_TYPE, c.tc.ty_rune, nil); + scopedefine(c.top, "i8", SK_TYPE, c.tc.ty_i8, nil); + scopedefine(c.top, "i16", SK_TYPE, c.tc.ty_i16, nil); + scopedefine(c.top, "i32", SK_TYPE, c.tc.ty_i32, nil); + scopedefine(c.top, "i64", SK_TYPE, c.tc.ty_i64, nil); + scopedefine(c.top, "u8", SK_TYPE, c.tc.ty_u8, nil); + scopedefine(c.top, "u16", SK_TYPE, c.tc.ty_u16, nil); + scopedefine(c.top, "u32", SK_TYPE, c.tc.ty_u32, nil); + scopedefine(c.top, "u64", SK_TYPE, c.tc.ty_u64, nil); + scopedefine(c.top, "int", SK_TYPE, c.tc.ty_int, nil); + scopedefine(c.top, "uint", SK_TYPE, c.tc.ty_uint, nil); + scopedefine(c.top, "uintptr", SK_TYPE, c.tc.ty_uintptr, nil); + scopedefine(c.top, "f32", SK_TYPE, c.tc.ty_f32, nil); + scopedefine(c.top, "f64", SK_TYPE, c.tc.ty_f64, nil); + scopedefine(c.top, "str", SK_TYPE, c.tc.ty_str, nil); // `nil`, `true`, `false` are keywords — handled at the lex/parser // level, no symbol needed. - // `len`, `alloc`, `free` are pseudo-builtins; scope_define them so + // `len`, `alloc`, `free` are pseudo-builtins; scopedefine them so // their use sites resolve. The actual semantics live in cgen. - scope_define(c.top, "len", SK_FN, nil, nil); - scope_define(c.top, "alloc", SK_FN, nil, nil); - scope_define(c.top, "free", SK_FN, nil, nil); + scopedefine(c.top, "len", SK_FN, nil, nil); + scopedefine(c.top, "alloc", SK_FN, nil, nil); + scopedefine(c.top, "free", SK_FN, nil, nil); }; -// install_decl — install the top-level decl's name into the top scope. +// installdecl — install the top-level decl's name into the top scope. // We don't compute its type yet (that's the resolve pass) — just bind // the name so forward references resolve. -fn install_decl(c: *checker, d: *node) void = { +fn installdecl(c: *checker, d: *node) void = { if (d == nil) { return; }; let k: i32 = d.kind; let nm: str = d.str; - if (k == N_USE) { scope_define(c.top, nm, SK_USE, nil, d); return; }; - if (k == N_DEF) { scope_define(c.top, nm, SK_DEF, nil, d); return; }; - if (k == N_TYPEDECL) { scope_define(c.top, nm, SK_TYPE, nil, d); return; }; - if (k == N_FNDECL) { scope_define(c.top, nm, SK_FN, nil, d); return; }; - if (k == N_LET) { scope_define(c.top, nm, SK_VAR, nil, d); return; }; + if (k == N_USE) { scopedefine(c.top, nm, SK_USE, nil, d); return; }; + if (k == N_DEF) { scopedefine(c.top, nm, SK_DEF, nil, d); return; }; + if (k == N_TYPEDECL) { scopedefine(c.top, nm, SK_TYPE, nil, d); return; }; + if (k == N_FNDECL) { scopedefine(c.top, nm, SK_FN, nil, d); return; }; + if (k == N_LET) { scopedefine(c.top, nm, SK_VAR, nil, d); return; }; }; -// resolve_walk — recursive AST walk that, for every N_IDENT and +// resolvewalk — recursive AST walk that, for every N_IDENT and // N_TNAME seen, looks up the name and bumps the resolved/unresolved // counters. Local lets are installed in the current scope as soon as // their init/type expressions have been walked (forward use of a let // before its declaration would resolve to nothing — same semantics as // the C checker's collect-then-resolve flow within a function). -fn resolve_walk(c: *checker, n: *node) void = { +fn resolvewalk(c: *checker, n: *node) void = { if (n == nil) { return; }; let k: i32 = n.kind; @@ -91,7 +91,7 @@ fn resolve_walk(c: *checker, n: *node) void = { if (k == N_IDENT) { let nm: str = n.str; if (nm.len > 0) { - let s: *sym = scope_lookup(c.cur, nm); + let s: *sym = scopelookup(c.cur, nm); if (s == nil) { c.nunresolved += 1; if (c.verbose != 0) { @@ -106,7 +106,7 @@ fn resolve_walk(c: *checker, n: *node) void = { if (k == N_TNAME) { let nm: str = n.str; if (nm.len > 0) { - let s: *sym = scope_lookup(c.cur, nm); + let s: *sym = scopelookup(c.cur, nm); if (s == nil) { c.nunresolved += 1; if (c.verbose != 0) { @@ -121,89 +121,89 @@ fn resolve_walk(c: *checker, n: *node) void = { // `match (e) { case let v: T => stmt; ... }` — the binding `v` // is declared by the case arm and visible inside its body. if (k == N_MCASE) { - if (n.lhs != nil) { resolve_walk(c, n.lhs); }; + if (n.lhs != nil) { resolvewalk(c, n.lhs); }; let nm: str = n.str; if (nm.len > 0) { - scope_define(c.cur, nm, SK_VAR, nil, n); + scopedefine(c.cur, nm, SK_VAR, nil, n); }; - if (n.body != nil) { resolve_walk(c, n.body); }; + if (n.body != nil) { resolvewalk(c, n.body); }; return; }; if (k == N_DOT) { // Walk only the base; the .field name is a member, not a // free identifier. - if (n.lhs != nil) { resolve_walk(c, n.lhs); }; + if (n.lhs != nil) { resolvewalk(c, n.lhs); }; return; }; if (k == N_FIELD) { - if (n.lhs != nil) { resolve_walk(c, n.lhs); }; + if (n.lhs != nil) { resolvewalk(c, n.lhs); }; return; }; if (k == N_TFIELD) { - if (n.lhs != nil) { resolve_walk(c, n.lhs); }; + if (n.lhs != nil) { resolvewalk(c, n.lhs); }; return; }; // Walk children (mirroring ast.ww's printer descent order). - if (n.attr != nil) { resolve_walk(c, n.attr); }; - if (n.lhs != nil) { resolve_walk(c, n.lhs); }; - if (n.rhs != nil) { resolve_walk(c, n.rhs); }; - if (n.cond != nil) { resolve_walk(c, n.cond); }; - if (n.body != nil) { resolve_walk(c, n.body); }; - if (n.els != nil) { resolve_walk(c, n.els); }; + if (n.attr != nil) { resolvewalk(c, n.attr); }; + if (n.lhs != nil) { resolvewalk(c, n.lhs); }; + if (n.rhs != nil) { resolvewalk(c, n.rhs); }; + if (n.cond != nil) { resolvewalk(c, n.cond); }; + if (n.body != nil) { resolvewalk(c, n.body); }; + if (n.els != nil) { resolvewalk(c, n.els); }; if (n.list != nil) { let m: *node = n.list; for (m != nil) { - resolve_walk(c, m); + resolvewalk(c, m); m = m.next; }; }; // After walking children: a local `let X: T = init;` registers // `X` so subsequent statements can resolve it. Top-level lets - // are installed in install_decl, so this duplicate install at - // the file scope just no-ops (scope_define returns nil on dup). + // are installed in installdecl, so this duplicate install at + // the file scope just no-ops (scopedefine returns nil on dup). if (k == N_LET) { let nm: str = n.str; if (nm.len > 0) { - scope_define(c.cur, nm, SK_VAR, nil, n); + scopedefine(c.cur, nm, SK_VAR, nil, n); }; }; }; // install_param — when entering a fn body, define its params in a // fresh local scope. -fn install_params(c: *checker, params: *node) void = { +fn installparams(c: *checker, params: *node) void = { let p: *node = params; for (p != nil) { if (p.kind == N_PARAM) { let nm: str = p.str; if (nm.len > 0) { - scope_define(c.cur, nm, SK_PARAM, nil, p); + scopedefine(c.cur, nm, SK_PARAM, nil, p); }; }; p = p.next; }; }; -// resolve_fnbody — open a child scope for the fn, install its params, +// resolvefnbody — open a child scope for the fn, install its params, // then walk the body. Local lets installed by walk_stmt (a future // extension); for the current pass we just resolve-walk without // per-statement scopes. -fn resolve_fnbody(c: *checker, fnnode: *node) void = { +fn resolvefnbody(c: *checker, fnnode: *node) void = { let outer: *scope = c.cur; c.cur = newscope(c.a, c.cur); - install_params(c, fnnode.list); + installparams(c, fnnode.list); if (fnnode.body != nil) { - resolve_walk(c, fnnode.body); + resolvewalk(c, fnnode.body); }; c.cur = outer; }; -export fn check_init(c: *checker, a: *arena, tc: *tctx) void = { +export fn checkinit(c: *checker, a: *arena, tc: *tctx) void = { c.a = a; c.tc = tc; c.top = newscope(a, nil); @@ -212,17 +212,17 @@ export fn check_init(c: *checker, a: *arena, tc: *tctx) void = { c.nunresolved = 0; c.errs = 0; c.verbose = 0; - seed_primitives(c); + seedprimitives(c); }; -export fn check_file(c: *checker, file: *node) void = { +export fn checkfile(c: *checker, file: *node) void = { if (file == nil) { return; }; if (file.kind != N_FILE) { return; }; // Pass 1: install all top-level names. let d: *node = file.list; for (d != nil) { - install_decl(c, d); + installdecl(c, d); d = d.next; }; @@ -231,16 +231,16 @@ export fn check_file(c: *checker, file: *node) void = { for (d != nil) { let k: i32 = d.kind; if (k == N_FNDECL) { - if (d.lhs != nil) { resolve_walk(c, d.lhs); }; // return type - resolve_fnbody(c, d); + if (d.lhs != nil) { resolvewalk(c, d.lhs); }; // return type + resolvefnbody(c, d); } else { if (k == N_DEF) { - if (d.lhs != nil) { resolve_walk(c, d.lhs); }; - if (d.rhs != nil) { resolve_walk(c, d.rhs); }; + if (d.lhs != nil) { resolvewalk(c, d.lhs); }; + if (d.rhs != nil) { resolvewalk(c, d.rhs); }; } else { if (k == N_TYPEDECL) { - if (d.lhs != nil) { resolve_walk(c, d.lhs); }; + if (d.lhs != nil) { resolvewalk(c, d.lhs); }; } else { if (k == N_LET) { - if (d.lhs != nil) { resolve_walk(c, d.lhs); }; - if (d.rhs != nil) { resolve_walk(c, d.rhs); }; + if (d.lhs != nil) { resolvewalk(c, d.lhs); }; + if (d.rhs != nil) { resolvewalk(c, d.rhs); }; };};};}; d = d.next; }; diff --git a/selfhost/cmd/wcc/lex.ww b/selfhost/cmd/wcc/lex.ww index ed94518d..2f14df36 100644 --- a/selfhost/cmd/wcc/lex.ww +++ b/selfhost/cmd/wcc/lex.ww @@ -64,14 +64,14 @@ fn lget(l: *lex) i32 = { return c; }; -fn cur_pos(l: *lex, out: *pos) void = { +fn curpos(l: *lex, out: *pos) void = { out.file = l.file; out.line = l.line; out.col = l.col; }; // putuint — write `v` (signed, but always non-negative here) to fd 2 -// in decimal. Standalone so err_at doesn't drag in fmt and create a +// in decimal. Standalone so errat doesn't drag in fmt and create a // dependency cycle with strconv. fn putuint(fd: i32, v: i32) void = { let tmp: [16]u8; @@ -89,7 +89,7 @@ fn putuint(fd: i32, v: i32) void = { os.write(fd, buf.ptr, m: u64); }; -fn err_at(l: *lex, p: *pos, msg: str) void = { +fn errat(l: *lex, p: *pos, msg: str) void = { let pf: str = p.file; os.write(2, pf.ptr, pf.len: u64); os.write(2, ":".ptr, 1u64); @@ -128,8 +128,8 @@ fn skipws(l: *lex) bool = { let x: i32 = lget(l); if (x < 0) { let cp: pos; - cur_pos(l, &cp); - err_at(l, &cp, "unterminated /* comment"); + curpos(l, &cp); + errat(l, &cp, "unterminated /* comment"); return false; }; if (prev == 42) { @@ -200,13 +200,13 @@ fn escape(l: *lex, out: *i32) bool = { if (hi < 0) { return false; }; if (lo < 0) { return false; }; if (!ascii.ishex(hi: u8)) { - let cp: pos; cur_pos(l, &cp); - err_at(l, &cp, "bad \\x escape"); + let cp: pos; curpos(l, &cp); + errat(l, &cp, "bad \\x escape"); return false; }; if (!ascii.ishex(lo: u8)) { - let cp: pos; cur_pos(l, &cp); - err_at(l, &cp, "bad \\x escape"); + let cp: pos; curpos(l, &cp); + errat(l, &cp, "bad \\x escape"); return false; }; let h: i32 = ascii.digitval(hi: u8); @@ -214,13 +214,13 @@ fn escape(l: *lex, out: *i32) bool = { *out = (h << 4) | lv; return true; }; - let cp: pos; cur_pos(l, &cp); - err_at(l, &cp, "bad escape"); + let cp: pos; curpos(l, &cp); + errat(l, &cp, "bad escape"); return false; }; -// scan_decimal_run — consume a run of decimal digits and underscores. -fn scan_decimal_run(l: *lex) void = { +// scandecimalrun — consume a run of decimal digits and underscores. +fn scandecimalrun(l: *lex) void = { for (true) { let c: i32 = lpeek(l, 0u64); if (c < 0) { break; }; @@ -231,7 +231,7 @@ fn scan_decimal_run(l: *lex) void = { }; }; -fn scan_hex_run(l: *lex) void = { +fn scanhexrun(l: *lex) void = { for (true) { let c: i32 = lpeek(l, 0u64); if (c < 0) { break; }; @@ -242,7 +242,7 @@ fn scan_hex_run(l: *lex) void = { }; }; -fn scan_bin_run(l: *lex) void = { +fn scanbinrun(l: *lex) void = { for (true) { let c: i32 = lpeek(l, 0u64); if (c == 48) { lget(l); continue; }; @@ -252,7 +252,7 @@ fn scan_bin_run(l: *lex) void = { }; }; -fn scan_oct_run(l: *lex) void = { +fn scanoctrun(l: *lex) void = { for (true) { let c: i32 = lpeek(l, 0u64); if (c < 48) { break; }; @@ -263,8 +263,8 @@ fn scan_oct_run(l: *lex) void = { }; }; -// scan_exp — consume the [eE][+-]?[0-9]+ tail of a float, if present. -fn scan_exp(l: *lex) void = { +// scanexp — consume the [eE][+-]?[0-9]+ tail of a float, if present. +fn scanexp(l: *lex) void = { let e: i32 = lpeek(l, 0u64); if (e != 101) { if (e != 69) { return; }; }; // 'e' or 'E' lget(l); @@ -293,41 +293,41 @@ fn lexnum(l: *lex, start: *pos, out: *tok) void = { if (c0 == 48) { // '0' if (c1 == 120) { // 'x' - lget(l); lget(l); base = 16; scan_hex_run(l); + lget(l); lget(l); base = 16; scanhexrun(l); } else { if (c1 == 88) { // 'X' - lget(l); lget(l); base = 16; scan_hex_run(l); + lget(l); lget(l); base = 16; scanhexrun(l); } else { if (c1 == 98) { // 'b' - lget(l); lget(l); base = 2; scan_bin_run(l); + lget(l); lget(l); base = 2; scanbinrun(l); } else { if (c1 == 66) { // 'B' - lget(l); lget(l); base = 2; scan_bin_run(l); + lget(l); lget(l); base = 2; scanbinrun(l); } else { if (c1 == 111) { // 'o' - lget(l); lget(l); base = 8; scan_oct_run(l); + lget(l); lget(l); base = 8; scanoctrun(l); } else { if (c1 == 79) { // 'O' - lget(l); lget(l); base = 8; scan_oct_run(l); + lget(l); lget(l); base = 8; scanoctrun(l); } else { - scan_decimal_run(l); + scandecimalrun(l); if (lpeek(l, 0u64) == 46) { let after: i32 = lpeek(l, 1u64); if (after >= 48) { if (after <= 57) { isfloat = true; lget(l); - scan_decimal_run(l); - scan_exp(l); + scandecimalrun(l); + scanexp(l); }; }; }; };};};};};}; } else { - scan_decimal_run(l); + scandecimalrun(l); if (lpeek(l, 0u64) == 46) { let after: i32 = lpeek(l, 1u64); if (after >= 48) { if (after <= 57) { isfloat = true; lget(l); - scan_decimal_run(l); - scan_exp(l); + scandecimalrun(l); + scanexp(l); }; }; }; @@ -352,7 +352,7 @@ fn lexnum(l: *lex, start: *pos, out: *tok) void = { let ok: bool = false; out.uval = parseint(digs, dn, base, &ok); if (!ok) { - err_at(l, start, "bad integer literal"); + errat(l, start, "bad integer literal"); out.kind = TK_ERR; }; }; @@ -432,7 +432,7 @@ fn lexstr(l: *lex, start: *pos, out: *tok) void = { for (true) { let c: i32 = lpeek(l, 0u64); if (c < 0) { - err_at(l, start, "unterminated string"); + errat(l, start, "unterminated string"); out.kind = TK_ERR; out.file = start.file; out.line = start.line; @@ -477,7 +477,7 @@ fn lexstr(l: *lex, start: *pos, out: *tok) void = { fn lexrune(l: *lex, start: *pos, out: *tok) void = { let c: i32 = lpeek(l, 0u64); if (c < 0) { - err_at(l, start, "unterminated rune"); + errat(l, start, "unterminated rune"); out.kind = TK_ERR; out.file = start.file; out.line = start.line; @@ -493,7 +493,7 @@ fn lexrune(l: *lex, start: *pos, out: *tok) void = { ch = lget(l); }; if (lpeek(l, 0u64) != 39) { - err_at(l, start, "rune literal missing closing '"); + errat(l, start, "rune literal missing closing '"); out.kind = TK_ERR; out.file = start.file; out.line = start.line; @@ -509,16 +509,16 @@ fn lexrune(l: *lex, start: *pos, out: *tok) void = { out.uval = ch: u64; }; -fn emit_simple(start: *pos, k: i32, out: *tok) void = { +fn emitsimple(start: *pos, k: i32, out: *tok) void = { out.kind = k; out.file = start.file; out.line = start.line; out.col = start.col; }; -// set_pos_from — copy file/line/col from a *pos into a tok. Used by +// setposfrom — copy file/line/col from a *pos into a tok. Used by // the err-token path where we already have a pos. -fn set_pos_from(out: *tok, p: *pos) void = { +fn setposfrom(out: *tok, p: *pos) void = { out.file = p.file; out.line = p.line; out.col = p.col; @@ -541,11 +541,11 @@ export fn lexnext(l: *lex, out: *tok) void = { out.tsuffix = empty; if (!skipws(l)) { - let p: pos; cur_pos(l, &p); - emit_simple(&p, TK_EOF, out); + let p: pos; curpos(l, &p); + emitsimple(&p, TK_EOF, out); return; }; - let start: pos; cur_pos(l, &start); + let start: pos; curpos(l, &start); let c: i32 = lpeek(l, 0u64); if (c >= 0) { @@ -558,98 +558,98 @@ export fn lexnext(l: *lex, out: *tok) void = { lget(l); - if (c == 40) { emit_simple(&start, TK_LPAREN, out); return; }; - if (c == 41) { emit_simple(&start, TK_RPAREN, out); return; }; - if (c == 123) { emit_simple(&start, TK_LBRACE, out); return; }; - if (c == 125) { emit_simple(&start, TK_RBRACE, out); return; }; - if (c == 91) { emit_simple(&start, TK_LBRACK, out); return; }; - if (c == 93) { emit_simple(&start, TK_RBRACK, out); return; }; - if (c == 44) { emit_simple(&start, TK_COMMA, out); return; }; - if (c == 59) { emit_simple(&start, TK_SEMI, out); return; }; - if (c == 58) { emit_simple(&start, TK_COLON, out); return; }; - if (c == 64) { emit_simple(&start, TK_AT, out); return; }; - if (c == 63) { emit_simple(&start, TK_QUESTION, out); return; }; - if (c == 126) { emit_simple(&start, TK_TILDE, out); return; }; + if (c == 40) { emitsimple(&start, TK_LPAREN, out); return; }; + if (c == 41) { emitsimple(&start, TK_RPAREN, out); return; }; + if (c == 123) { emitsimple(&start, TK_LBRACE, out); return; }; + if (c == 125) { emitsimple(&start, TK_RBRACE, out); return; }; + if (c == 91) { emitsimple(&start, TK_LBRACK, out); return; }; + if (c == 93) { emitsimple(&start, TK_RBRACK, out); return; }; + if (c == 44) { emitsimple(&start, TK_COMMA, out); return; }; + if (c == 59) { emitsimple(&start, TK_SEMI, out); return; }; + if (c == 58) { emitsimple(&start, TK_COLON, out); return; }; + if (c == 64) { emitsimple(&start, TK_AT, out); return; }; + if (c == 63) { emitsimple(&start, TK_QUESTION, out); return; }; + if (c == 126) { emitsimple(&start, TK_TILDE, out); return; }; if (c == 46) { // '.' if (lpeek(l, 0u64) == 46) { if (lpeek(l, 1u64) == 46) { lget(l); lget(l); - emit_simple(&start, TK_ELLIPSIS, out); return; + emitsimple(&start, TK_ELLIPSIS, out); return; }; lget(l); - emit_simple(&start, TK_DOTDOT, out); return; + emitsimple(&start, TK_DOTDOT, out); return; }; - emit_simple(&start, TK_DOT, out); return; + emitsimple(&start, TK_DOT, out); return; }; if (c == 43) { - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_PLUSEQ, out); return; }; - emit_simple(&start, TK_PLUS, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_PLUSEQ, out); return; }; + emitsimple(&start, TK_PLUS, out); return; }; if (c == 45) { - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_MINUSEQ, out); return; }; - if (lpeek(l, 0u64) == 62) { lget(l); emit_simple(&start, TK_ARROW, out); return; }; - emit_simple(&start, TK_MINUS, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_MINUSEQ, out); return; }; + if (lpeek(l, 0u64) == 62) { lget(l); emitsimple(&start, TK_ARROW, out); return; }; + emitsimple(&start, TK_MINUS, out); return; }; if (c == 42) { - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_STAREQ, out); return; }; - emit_simple(&start, TK_STAR, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_STAREQ, out); return; }; + emitsimple(&start, TK_STAR, out); return; }; if (c == 47) { - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_SLASHEQ, out); return; }; - emit_simple(&start, TK_SLASH, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_SLASHEQ, out); return; }; + emitsimple(&start, TK_SLASH, out); return; }; if (c == 37) { - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_PERCENTEQ, out); return; }; - emit_simple(&start, TK_PERCENT, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_PERCENTEQ, out); return; }; + emitsimple(&start, TK_PERCENT, out); return; }; if (c == 38) { - if (lpeek(l, 0u64) == 38) { lget(l); emit_simple(&start, TK_AND, out); return; }; - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_AMPEQ, out); return; }; - emit_simple(&start, TK_AMP, out); return; + if (lpeek(l, 0u64) == 38) { lget(l); emitsimple(&start, TK_AND, out); return; }; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_AMPEQ, out); return; }; + emitsimple(&start, TK_AMP, out); return; }; if (c == 124) { - if (lpeek(l, 0u64) == 124) { lget(l); emit_simple(&start, TK_OR, out); return; }; - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_PIPEEQ, out); return; }; - emit_simple(&start, TK_PIPE, out); return; + if (lpeek(l, 0u64) == 124) { lget(l); emitsimple(&start, TK_OR, out); return; }; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_PIPEEQ, out); return; }; + emitsimple(&start, TK_PIPE, out); return; }; if (c == 94) { - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_CARETEQ, out); return; }; - emit_simple(&start, TK_CARET, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_CARETEQ, out); return; }; + emitsimple(&start, TK_CARET, out); return; }; if (c == 61) { - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_EQ, out); return; }; - if (lpeek(l, 0u64) == 62) { lget(l); emit_simple(&start, TK_FATARROW, out); return; }; - emit_simple(&start, TK_ASSIGN, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_EQ, out); return; }; + if (lpeek(l, 0u64) == 62) { lget(l); emitsimple(&start, TK_FATARROW, out); return; }; + emitsimple(&start, TK_ASSIGN, out); return; }; if (c == 33) { - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_NEQ, out); return; }; - emit_simple(&start, TK_NOT, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_NEQ, out); return; }; + emitsimple(&start, TK_NOT, out); return; }; if (c == 60) { if (lpeek(l, 0u64) == 60) { lget(l); - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_LSHIFTEQ, out); return; }; - emit_simple(&start, TK_LSHIFT, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_LSHIFTEQ, out); return; }; + emitsimple(&start, TK_LSHIFT, out); return; }; - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_LE, out); return; }; - if (lpeek(l, 0u64) == 45) { lget(l); emit_simple(&start, TK_LARROW, out); return; }; - emit_simple(&start, TK_LT, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_LE, out); return; }; + if (lpeek(l, 0u64) == 45) { lget(l); emitsimple(&start, TK_LARROW, out); return; }; + emitsimple(&start, TK_LT, out); return; }; if (c == 62) { if (lpeek(l, 0u64) == 62) { lget(l); - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_RSHIFTEQ, out); return; }; - emit_simple(&start, TK_RSHIFT, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_RSHIFTEQ, out); return; }; + emitsimple(&start, TK_RSHIFT, out); return; }; - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_GE, out); return; }; - emit_simple(&start, TK_GT, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_GE, out); return; }; + emitsimple(&start, TK_GT, out); return; }; - err_at(l, &start, "unexpected character"); + errat(l, &start, "unexpected character"); out.kind = TK_ERR; - set_pos_from(out, &start); + setposfrom(out, &start); let one: [1]u8; one[0] = c: u8; out.text = astrndup(l.a, one.ptr, 1u64); diff --git a/selfhost/cmd/wcc/parse.ww b/selfhost/cmd/wcc/parse.ww index 85acd39b..4bb42a0e 100644 --- a/selfhost/cmd/wcc/parse.ww +++ b/selfhost/cmd/wcc/parse.ww @@ -56,12 +56,12 @@ export fn parserinit(p: *parser, a: *arena, l: *lex) void = { fn advance(p: *parser) void = { refill(p); }; -fn accept_tok(p: *parser, k: i32) bool = { +fn accepttok(p: *parser, k: i32) bool = { if (p.cur_kind == k) { advance(p); return true; }; return false; }; -fn err_msg(p: *parser, msg: str) void = { +fn errmsg(p: *parser, msg: str) void = { let pre: str = "parse: "; os.write(2, pre.ptr, pre.len: u64); os.write(2, msg.ptr, msg.len: u64); @@ -69,9 +69,9 @@ fn err_msg(p: *parser, msg: str) void = { p.errs += 1; }; -fn expect_tok(p: *parser, k: i32, what: str) bool = { +fn expecttok(p: *parser, k: i32, what: str) bool = { if (p.cur_kind == k) { advance(p); return true; }; - err_msg(p, what); + errmsg(p, what); return false; }; @@ -79,7 +79,7 @@ fn expect_tok(p: *parser, k: i32, what: str) bool = { // Returns the empty str on error (and advances to make progress). fn expectident(p: *parser, into: *str) bool = { if (p.cur_kind != TK_IDENT) { - err_msg(p, "expected identifier"); + errmsg(p, "expected identifier"); advance(p); return false; }; @@ -116,14 +116,14 @@ fn parsetype(p: *parser) *node = { }; let n: *node = newnode(p.a, N_TARRAY, pf, pl, pc); n.rhs = parseexpr(p); - expect_tok(p, TK_RBRACK, "expected ']' in array type"); + expecttok(p, TK_RBRACK, "expected ']' in array type"); n.lhs = parsetype(p); return n; }; if (p.cur_kind == TK_STRUCT) { advance(p); - expect_tok(p, TK_LBRACE, "expected '{' after struct"); + expecttok(p, TK_LBRACE, "expected '{' after struct"); let n: *node = newnode(p.a, N_TSTRUCT, pf, pl, pc); let fhead: *node = nil; let ftail: *node = nil; @@ -136,13 +136,13 @@ fn parsetype(p: *parser) *node = { let fid: str; expectident(p, &fid); f.str = fid; - expect_tok(p, TK_COLON, "expected ':' in field"); + expecttok(p, TK_COLON, "expected ':' in field"); f.lhs = parsetype(p); if (fhead == nil) { fhead = f; ftail = f; } else { ftail.next = f; ftail = f; }; - if (!accept_tok(p, TK_COMMA)) { break; }; + if (!accepttok(p, TK_COMMA)) { break; }; }; - expect_tok(p, TK_RBRACE, "expected '}' after struct fields"); + expecttok(p, TK_RBRACE, "expected '}' after struct fields"); n.list = fhead; return n; }; @@ -160,7 +160,7 @@ fn parsetype(p: *parser) *node = { // (T) or (T, T, ...) or (T | T | ...) advance(p); let first: *node = parsetype(p); - if (accept_tok(p, TK_PIPE)) { + if (accepttok(p, TK_PIPE)) { let n: *node = newnode(p.a, N_TTAGGED, pf, pl, pc); let head: *node = first; let tail: *node = first; @@ -168,14 +168,14 @@ fn parsetype(p: *parser) *node = { let e: *node = parsetype(p); tail.next = e; tail = e; - if (!accept_tok(p, TK_PIPE)) { break; }; + if (!accepttok(p, TK_PIPE)) { break; }; }; - expect_tok(p, TK_RPAREN, "expected ')' in tagged-union type"); + expecttok(p, TK_RPAREN, "expected ')' in tagged-union type"); n.list = head; return n; }; - if (!accept_tok(p, TK_COMMA)) { - expect_tok(p, TK_RPAREN, "expected ')' after parenthesised type"); + if (!accepttok(p, TK_COMMA)) { + expecttok(p, TK_RPAREN, "expected ')' after parenthesised type"); return first; }; let n: *node = newnode(p.a, N_TTUPLE, pf, pl, pc); @@ -185,28 +185,28 @@ fn parsetype(p: *parser) *node = { let e: *node = parsetype(p); tail.next = e; tail = e; - if (!accept_tok(p, TK_COMMA)) { break; }; + if (!accepttok(p, TK_COMMA)) { break; }; if (p.cur_kind == TK_RPAREN) { break; }; }; - expect_tok(p, TK_RPAREN, "expected ')' in tuple type"); + expecttok(p, TK_RPAREN, "expected ')' in tuple type"); n.list = head; return n; }; if (p.cur_kind == TK_FN) { advance(p); - expect_tok(p, TK_LPAREN, "expected '(' after fn in type"); + expecttok(p, TK_LPAREN, "expected '(' after fn in type"); let n: *node = newnode(p.a, N_TFN, pf, pl, pc); // Anonymous-or-named params: parseparams handles named only; // for fn-type expressions the C parser allows IDENT-less // (anonymous) params. Stub: only named params for now. n.list = parseparams(p); - expect_tok(p, TK_RPAREN, "expected ')' after fn type params"); + expecttok(p, TK_RPAREN, "expected ')' after fn type params"); n.lhs = parsetype(p); return n; }; - err_msg(p, "expected type"); + errmsg(p, "expected type"); advance(p); return newnode(p.a, N_TNAME, pf, pl, pc); }; @@ -298,7 +298,7 @@ fn parseprimary(p: *parser) *node = { advance(p); let e: *node = parseexpr(p); // Tuple literal: (a, b, ...) - if (accept_tok(p, TK_COMMA)) { + if (accepttok(p, TK_COMMA)) { let t: *node = newnode(p.a, N_TUPLE, pf, pl, pc); t.list = e; let tail: *node = e; @@ -307,12 +307,12 @@ fn parseprimary(p: *parser) *node = { let en: *node = parseexpr(p); tail.next = en; tail = en; - if (!accept_tok(p, TK_COMMA)) { break; }; + if (!accepttok(p, TK_COMMA)) { break; }; }; - expect_tok(p, TK_RPAREN, "expected ')' in tuple"); + expecttok(p, TK_RPAREN, "expected ')' in tuple"); return t; }; - expect_tok(p, TK_RPAREN, "expected ')'"); + expecttok(p, TK_RPAREN, "expected ')'"); return e; }; if (p.cur_kind == TK_IDENT) { @@ -338,16 +338,16 @@ fn parseprimary(p: *parser) *node = { let fpc: i32 = p.cur_col; let id: str; expectident(p, &id); - expect_tok(p, TK_ASSIGN, "expected '=' in struct lit field"); + expecttok(p, TK_ASSIGN, "expected '=' in struct lit field"); let v: *node = parseexpr(p); let f: *node = newnode(p.a, N_FIELD, fpf, fpl, fpc); f.str = id; f.lhs = v; if (head == nil) { head = f; tail = f; } else { tail.next = f; tail = f; }; - if (!accept_tok(p, TK_COMMA)) { break; }; + if (!accepttok(p, TK_COMMA)) { break; }; }; - expect_tok(p, TK_RBRACE, "expected '}' after struct literal"); + expecttok(p, TK_RBRACE, "expected '}' after struct literal"); s.list = head; return s; }; @@ -356,11 +356,11 @@ fn parseprimary(p: *parser) *node = { if (p.cur_kind == TK_MATCH) { // match (e) { case let v: T => stmt; case T => stmt; case => stmt; }; advance(p); - expect_tok(p, TK_LPAREN, "expected '(' after match"); + expecttok(p, TK_LPAREN, "expected '(' after match"); let m: *node = newnode(p.a, N_MATCH, pf, pl, pc); m.lhs = parseexpr(p); - expect_tok(p, TK_RPAREN, "expected ')' after match scrutinee"); - expect_tok(p, TK_LBRACE, "expected '{' to open match body"); + expecttok(p, TK_RPAREN, "expected ')' after match scrutinee"); + expecttok(p, TK_LBRACE, "expected '{' to open match body"); let head: *node = nil; let tail: *node = nil; for (p.cur_kind == TK_CASE) { @@ -374,21 +374,21 @@ fn parseprimary(p: *parser) *node = { let id: str; expectident(p, &id); mc.str = id; - expect_tok(p, TK_COLON, "expected ':' after match binding"); + expecttok(p, TK_COLON, "expected ':' after match binding"); mc.lhs = parsetype(p); } else { if (p.cur_kind != TK_FATARROW) { mc.lhs = parsetype(p); };}; - expect_tok(p, TK_FATARROW, "expected '=>' in match arm"); + expecttok(p, TK_FATARROW, "expected '=>' in match arm"); mc.body = parsestmt(p); if (head == nil) { head = mc; tail = mc; } else { tail.next = mc; tail = mc; }; }; - expect_tok(p, TK_RBRACE, "expected '}' after match body"); + expecttok(p, TK_RBRACE, "expected '}' after match body"); m.list = head; return m; }; - err_msg(p, "expected expression"); + errmsg(p, "expected expression"); advance(p); return newnode(p.a, N_NONE, pf, pl, pc); }; @@ -402,7 +402,7 @@ fn parsearglist(p: *parser, close_kind: i32, head_out: **node) void = { let e: *node = parseexpr(p); if (head == nil) { head = e; tail = e; } else { tail.next = e; tail = e; }; - if (!accept_tok(p, TK_COMMA)) { break; }; + if (!accepttok(p, TK_COMMA)) { break; }; if (p.cur_kind == close_kind) { break; }; }; *head_out = head; @@ -421,7 +421,7 @@ fn parsepostfix(p: *parser, lhs: *node) *node = { let arghead: *node = nil; parsearglist(p, TK_RPAREN, &arghead); n.list = arghead; - expect_tok(p, TK_RPAREN, "expected ')' after args"); + expecttok(p, TK_RPAREN, "expected ')' after args"); cur = n; continue; }; @@ -435,7 +435,7 @@ fn parsepostfix(p: *parser, lhs: *node) *node = { if (p.cur_kind != TK_RBRACK) { n.cond = parseexpr(p); }; - expect_tok(p, TK_RBRACK, "expected ']' in slice"); + expecttok(p, TK_RBRACK, "expected ']' in slice"); cur = n; continue; }; @@ -453,14 +453,14 @@ fn parsepostfix(p: *parser, lhs: *node) *node = { if (p.cur_kind != TK_RBRACK) { n.cond = parseexpr(p); }; - expect_tok(p, TK_RBRACK, "expected ']' in slice"); + expecttok(p, TK_RBRACK, "expected ']' in slice"); cur = n; continue; }; let n: *node = newnode(p.a, N_INDEX, pf, pl, pc); n.lhs = cur; n.rhs = e; - expect_tok(p, TK_RBRACK, "expected ']' after index"); + expecttok(p, TK_RBRACK, "expected ']' after index"); cur = n; continue; }; @@ -581,7 +581,7 @@ fn parseexpr(p: *parser) *node = { // (single-cond C-style), expr-stmt, defer, break, continue. Switch // and match arms are not yet wired; tuple-let / multi-let neither. -fn parselet_local(p: *parser) *node = { +fn parseletlocal(p: *parser) *node = { let pf: str = p.cur_file; let pl: i32 = p.cur_line; let pc: i32 = p.cur_col; @@ -590,13 +590,13 @@ fn parselet_local(p: *parser) *node = { let id: str; expectident(p, &id); n.str = id; - if (accept_tok(p, TK_COLON)) { + if (accepttok(p, TK_COLON)) { n.lhs = parsetype(p); }; - if (accept_tok(p, TK_ASSIGN)) { + if (accepttok(p, TK_ASSIGN)) { n.rhs = parseexpr(p); }; - expect_tok(p, TK_SEMI, "expected ';' after let"); + expecttok(p, TK_SEMI, "expected ';' after let"); return n; }; @@ -604,7 +604,7 @@ fn parseblock(p: *parser) *node = { let pf: str = p.cur_file; let pl: i32 = p.cur_line; let pc: i32 = p.cur_col; - expect_tok(p, TK_LBRACE, "expected '{' to open block"); + expecttok(p, TK_LBRACE, "expected '{' to open block"); let blk: *node = newnode(p.a, N_BLOCK, pf, pl, pc); let head: *node = nil; let tail: *node = nil; @@ -616,7 +616,7 @@ fn parseblock(p: *parser) *node = { else { tail.next = s; tail = s; }; }; }; - expect_tok(p, TK_RBRACE, "expected '}' to close block"); + expecttok(p, TK_RBRACE, "expected '}' to close block"); blk.list = head; return blk; }; @@ -626,12 +626,12 @@ fn parseif(p: *parser) *node = { let pl: i32 = p.cur_line; let pc: i32 = p.cur_col; advance(p); // past `if` - expect_tok(p, TK_LPAREN, "expected '(' after if"); + expecttok(p, TK_LPAREN, "expected '(' after if"); let n: *node = newnode(p.a, N_IF, pf, pl, pc); n.cond = parseexpr(p); - expect_tok(p, TK_RPAREN, "expected ')' after if condition"); + expecttok(p, TK_RPAREN, "expected ')' after if condition"); n.body = parseblock(p); - if (accept_tok(p, TK_ELSE)) { + if (accepttok(p, TK_ELSE)) { if (p.cur_kind == TK_IF) { n.els = parseif(p); } else { @@ -646,7 +646,7 @@ fn parsefor(p: *parser) *node = { let pl: i32 = p.cur_line; let pc: i32 = p.cur_col; advance(p); // past `for` - expect_tok(p, TK_LPAREN, "expected '(' after for"); + expecttok(p, TK_LPAREN, "expected '(' after for"); let n: *node = newnode(p.a, N_FOR, pf, pl, pc); // Three forms (matching C parser): // for (cond) — only cond @@ -657,14 +657,14 @@ fn parsefor(p: *parser) *node = { // ';' it was cond. If we see two ';' total after init, post is // next. Simpler: peek for `let` to decide init form. if (p.cur_kind == TK_LET) { - n.lhs = parselet_local(p); // init (consumes its own ';') + n.lhs = parseletlocal(p); // init (consumes its own ';') n.cond = parseexpr(p); - expect_tok(p, TK_SEMI, "expected ';' after for cond"); + expecttok(p, TK_SEMI, "expected ';' after for cond"); n.rhs = parseexpr(p); } else { // Parse one expr. If next is ';', it's a 3-clause without init. let first: *node = parseexpr(p); - if (accept_tok(p, TK_SEMI)) { + if (accepttok(p, TK_SEMI)) { // cond ; post n.cond = first; n.rhs = parseexpr(p); @@ -673,7 +673,7 @@ fn parsefor(p: *parser) *node = { n.cond = first; }; }; - expect_tok(p, TK_RPAREN, "expected ')' after for"); + expecttok(p, TK_RPAREN, "expected ')' after for"); n.body = parseblock(p); return n; }; @@ -689,18 +689,18 @@ fn parsestmt(p: *parser) *node = { if (p.cur_kind == TK_LBRACE) { let b: *node = parseblock(p); - expect_tok(p, TK_SEMI, "expected ';' after block"); + expecttok(p, TK_SEMI, "expected ';' after block"); return b; }; - if (p.cur_kind == TK_LET) { return parselet_local(p); }; + if (p.cur_kind == TK_LET) { return parseletlocal(p); }; if (p.cur_kind == TK_IF) { let n: *node = parseif(p); - expect_tok(p, TK_SEMI, "expected ';' after if"); + expecttok(p, TK_SEMI, "expected ';' after if"); return n; }; if (p.cur_kind == TK_FOR) { let n: *node = parsefor(p); - expect_tok(p, TK_SEMI, "expected ';' after for"); + expecttok(p, TK_SEMI, "expected ';' after for"); return n; }; if (p.cur_kind == TK_RETURN) { @@ -714,7 +714,7 @@ fn parsestmt(p: *parser) *node = { let t: *node = newnode(p.a, N_TUPLE, pf, pl, pc); t.list = first; let tail: *node = first; - for (accept_tok(p, TK_COMMA)) { + for (accepttok(p, TK_COMMA)) { let e: *node = parseexpr(p); tail.next = e; tail = e; @@ -724,24 +724,24 @@ fn parsestmt(p: *parser) *node = { n.lhs = first; }; }; - expect_tok(p, TK_SEMI, "expected ';' after return"); + expecttok(p, TK_SEMI, "expected ';' after return"); return n; }; if (p.cur_kind == TK_DEFER) { advance(p); let n: *node = newnode(p.a, N_DEFER, pf, pl, pc); n.lhs = parseexpr(p); - expect_tok(p, TK_SEMI, "expected ';' after defer"); + expecttok(p, TK_SEMI, "expected ';' after defer"); return n; }; if (p.cur_kind == TK_BREAK) { advance(p); - expect_tok(p, TK_SEMI, "expected ';' after break"); + expecttok(p, TK_SEMI, "expected ';' after break"); return newnode(p.a, N_BREAK, pf, pl, pc); }; if (p.cur_kind == TK_CONTINUE) { advance(p); - expect_tok(p, TK_SEMI, "expected ';' after continue"); + expecttok(p, TK_SEMI, "expected ';' after continue"); return newnode(p.a, N_CONTINUE, pf, pl, pc); }; // expression statement, or tuple-destructure multi-assign: @@ -761,15 +761,15 @@ fn parsestmt(p: *parser) *node = { tail.next = lv; tail = lv; }; - expect_tok(p, TK_ASSIGN, "expected '=' after multi-assign lvalues"); + expecttok(p, TK_ASSIGN, "expected '=' after multi-assign lvalues"); m.rhs = parseexpr(p); m.list = head; - expect_tok(p, TK_SEMI, "expected ';' after multi-assign"); + expecttok(p, TK_SEMI, "expected ';' after multi-assign"); return m; }; let n: *node = newnode(p.a, N_EXPRSTMT, pf, pl, pc); n.lhs = e; - expect_tok(p, TK_SEMI, "expected ';' after expression statement"); + expecttok(p, TK_SEMI, "expected ';' after expression statement"); return n; }; @@ -784,7 +784,7 @@ fn parseuse(p: *parser) *node = { let id: str; expectident(p, &id); n.str = id; - expect_tok(p, TK_SEMI, "expected ';' after use"); + expecttok(p, TK_SEMI, "expected ';' after use"); return n; }; @@ -797,11 +797,11 @@ fn parsedef(p: *parser, exported: i32) *node = { let id: str; expectident(p, &id); n.str = id; - expect_tok(p, TK_COLON, "expected ':' in def"); + expecttok(p, TK_COLON, "expected ':' in def"); n.lhs = parsetype(p); - expect_tok(p, TK_ASSIGN, "expected '=' in def"); + expecttok(p, TK_ASSIGN, "expected '=' in def"); n.rhs = parseexpr(p); - expect_tok(p, TK_SEMI, "expected ';' after def"); + expecttok(p, TK_SEMI, "expected ';' after def"); n.exported = exported; return n; }; @@ -815,13 +815,13 @@ fn parselet(p: *parser, exported: i32) *node = { let id: str; expectident(p, &id); n.str = id; - if (accept_tok(p, TK_COLON)) { + if (accepttok(p, TK_COLON)) { n.lhs = parsetype(p); }; - if (accept_tok(p, TK_ASSIGN)) { + if (accepttok(p, TK_ASSIGN)) { n.rhs = parseexpr(p); }; - expect_tok(p, TK_SEMI, "expected ';' after let"); + expecttok(p, TK_SEMI, "expected ';' after let"); n.exported = exported; return n; }; @@ -838,11 +838,11 @@ fn parseattrs(p: *parser) *node = { let id: str; expectident(p, &id); a.str = id; - expect_tok(p, TK_LPAREN, "expected '(' after attribute name"); + expecttok(p, TK_LPAREN, "expected '(' after attribute name"); let arghead: *node = nil; parsearglist(p, TK_RPAREN, &arghead); a.list = arghead; - expect_tok(p, TK_RPAREN, "expected ')' after attribute args"); + expecttok(p, TK_RPAREN, "expected ')' after attribute args"); if (head == nil) { head = a; tail = a; } else { tail.next = a; tail = a; }; }; @@ -863,11 +863,11 @@ fn parseparams(p: *parser) *node = { let id: str; expectident(p, &id); n.str = id; - expect_tok(p, TK_COLON, "expected ':' in parameter"); + expecttok(p, TK_COLON, "expected ':' in parameter"); n.lhs = parsetype(p); if (head == nil) { head = n; tail = n; } else { tail.next = n; tail = n; }; - if (!accept_tok(p, TK_COMMA)) { break; }; + if (!accepttok(p, TK_COMMA)) { break; }; if (p.cur_kind == TK_RPAREN) { break; }; }; return head; @@ -882,20 +882,20 @@ fn parsefn(p: *parser, exported: i32, attrs: *node) *node = { let id: str; expectident(p, &id); n.str = id; - expect_tok(p, TK_LPAREN, "expected '(' after fn name"); + expecttok(p, TK_LPAREN, "expected '(' after fn name"); n.list = parseparams(p); - expect_tok(p, TK_RPAREN, "expected ')' after params"); + expecttok(p, TK_RPAREN, "expected ')' after params"); if (p.cur_kind != TK_ASSIGN) { if (p.cur_kind != TK_SEMI) { n.lhs = parsetype(p); }; }; - if (accept_tok(p, TK_ASSIGN)) { + if (accepttok(p, TK_ASSIGN)) { n.body = parseblock(p); - expect_tok(p, TK_SEMI, "expected ';' after fn body"); + expecttok(p, TK_SEMI, "expected ';' after fn body"); } else { // Body-less fn: FFI declaration (`fn name(args) ret;`). - expect_tok(p, TK_SEMI, "expected ';' after fn header"); + expecttok(p, TK_SEMI, "expected ';' after fn header"); }; n.exported = exported; n.attr = attrs; @@ -911,9 +911,9 @@ fn parsetypedecl(p: *parser, exported: i32) *node = { let id: str; expectident(p, &id); n.str = id; - expect_tok(p, TK_ASSIGN, "expected '=' in type decl"); + expecttok(p, TK_ASSIGN, "expected '=' in type decl"); n.lhs = parsetype(p); - expect_tok(p, TK_SEMI, "expected ';' after type decl"); + expecttok(p, TK_SEMI, "expected ';' after type decl"); n.exported = exported; return n; }; diff --git a/selfhost/cmd/wcc/sym.ww b/selfhost/cmd/wcc/sym.ww index eac953e1..8f87e5d5 100644 --- a/selfhost/cmd/wcc/sym.ww +++ b/selfhost/cmd/wcc/sym.ww @@ -73,7 +73,7 @@ export fn streq(a: str, b: str) bool = { return true; }; -export fn scope_lookup_local(s: *scope, name: str) *sym = { +export fn scopelookuplocal(s: *scope, name: str) *sym = { if (s == nil) { return nil; }; let h: u64 = hashstr(name); let bi: i32 = (h % (s.nbuckets: u64)): i32; @@ -86,17 +86,17 @@ export fn scope_lookup_local(s: *scope, name: str) *sym = { return nil; }; -export fn scope_lookup(s: *scope, name: str) *sym = { +export fn scopelookup(s: *scope, name: str) *sym = { for (s != nil) { - let r: *sym = scope_lookup_local(s, name); + let r: *sym = scopelookuplocal(s, name); if (r != nil) { return r; }; s = s.parent; }; return nil; }; -export fn scope_define(s: *scope, name: str, k: i32, t: *tinfo, decl: *node) *sym = { - if (scope_lookup_local(s, name) != nil) { return nil; }; +export fn scopedefine(s: *scope, name: str, k: i32, t: *tinfo, decl: *node) *sym = { + if (scopelookuplocal(s, name) != nil) { return nil; }; let sy: *sym = amalloc(s.a, 80u64): *sym; sy.name = name; sy.skind = k; diff --git a/selfhost/cmd/wcc/tok.ww b/selfhost/cmd/wcc/tok.ww index be280b98..3b38391b 100644 --- a/selfhost/cmd/wcc/tok.ww +++ b/selfhost/cmd/wcc/tok.ww @@ -134,7 +134,7 @@ type tok = struct { // ---- keyword lookup --------------------------------------------------- -fn streq_n(a: *u8, b: str, n: i32) bool = { +fn streqn(a: *u8, b: str, n: i32) bool = { if (b.len != n) { return false; }; let i: i32 = 0; for (i < n) { @@ -148,30 +148,30 @@ fn streq_n(a: *u8, b: str, n: i32) bool = { // or TK_NONE if it's an ordinary identifier. Linear search over a // small alphabetised list, matching cmd/wcc/tok.c. export fn kwlookup(p: *u8, n: i32) i32 = { - if (streq_n(p, "as", n)) { return TK_AS; }; - if (streq_n(p, "break", n)) { return TK_BREAK; }; - if (streq_n(p, "case", n)) { return TK_CASE; }; - if (streq_n(p, "chan", n)) { return TK_CHAN; }; - if (streq_n(p, "continue", n)) { return TK_CONTINUE; }; - if (streq_n(p, "def", n)) { return TK_DEF; }; - if (streq_n(p, "defer", n)) { return TK_DEFER; }; - if (streq_n(p, "else", n)) { return TK_ELSE; }; - if (streq_n(p, "export", n)) { return TK_EXPORT; }; - if (streq_n(p, "false", n)) { return TK_FALSE; }; - if (streq_n(p, "fn", n)) { return TK_FN; }; - if (streq_n(p, "for", n)) { return TK_FOR; }; - if (streq_n(p, "if", n)) { return TK_IF; }; - if (streq_n(p, "let", n)) { return TK_LET; }; - if (streq_n(p, "match", n)) { return TK_MATCH; }; - if (streq_n(p, "nil", n)) { return TK_NIL; }; - if (streq_n(p, "proc", n)) { return TK_PROC; }; - if (streq_n(p, "return", n)) { return TK_RETURN; }; - if (streq_n(p, "static", n)) { return TK_STATIC; }; - if (streq_n(p, "struct", n)) { return TK_STRUCT; }; - if (streq_n(p, "switch", n)) { return TK_SWITCH; }; - if (streq_n(p, "true", n)) { return TK_TRUE; }; - if (streq_n(p, "type", n)) { return TK_TYPE; }; - if (streq_n(p, "use", n)) { return TK_USE; }; + if (streqn(p, "as", n)) { return TK_AS; }; + if (streqn(p, "break", n)) { return TK_BREAK; }; + if (streqn(p, "case", n)) { return TK_CASE; }; + if (streqn(p, "chan", n)) { return TK_CHAN; }; + if (streqn(p, "continue", n)) { return TK_CONTINUE; }; + if (streqn(p, "def", n)) { return TK_DEF; }; + if (streqn(p, "defer", n)) { return TK_DEFER; }; + if (streqn(p, "else", n)) { return TK_ELSE; }; + if (streqn(p, "export", n)) { return TK_EXPORT; }; + if (streqn(p, "false", n)) { return TK_FALSE; }; + if (streqn(p, "fn", n)) { return TK_FN; }; + if (streqn(p, "for", n)) { return TK_FOR; }; + if (streqn(p, "if", n)) { return TK_IF; }; + if (streqn(p, "let", n)) { return TK_LET; }; + if (streqn(p, "match", n)) { return TK_MATCH; }; + if (streqn(p, "nil", n)) { return TK_NIL; }; + if (streqn(p, "proc", n)) { return TK_PROC; }; + if (streqn(p, "return", n)) { return TK_RETURN; }; + if (streqn(p, "static", n)) { return TK_STATIC; }; + if (streqn(p, "struct", n)) { return TK_STRUCT; }; + if (streqn(p, "switch", n)) { return TK_SWITCH; }; + if (streqn(p, "true", n)) { return TK_TRUE; }; + if (streqn(p, "type", n)) { return TK_TYPE; }; + if (streqn(p, "use", n)) { return TK_USE; }; return TK_NONE; }; @@ -278,13 +278,13 @@ export fn tokname(k: i32) str = { // fputq mirrors cmd/wcc/tok.c:fputq — quote the string with C-style // escapes for \, ", \n, \t, \r and \xNN for other non-printables. -fn fputc_byte(fd: i32, b: u8) void = { +fn fputcbyte(fd: i32, b: u8) void = { let buf: [1]u8; buf[0] = b; os.write(fd, buf.ptr, 1u64); }; -fn fputs_str(fd: i32, s: str) void = { +fn fputsstr(fd: i32, s: str) void = { os.write(fd, s.ptr, s.len: u64); }; @@ -303,24 +303,24 @@ fn fputhex2(fd: i32, b: u8) void = { }; fn fputq(fd: i32, p: *u8, n: i32) void = { - fputc_byte(fd, 34u8); // '"' + fputcbyte(fd, 34u8); // '"' let i: i32 = 0; for (i < n) { let c: u8 = p[i]; if (c == 92u8) { // '\\' - fputs_str(fd, "\\\\"); + fputsstr(fd, "\\\\"); } else { if (c == 34u8) { // '"' - fputs_str(fd, "\\\""); + fputsstr(fd, "\\\""); } else { if (c == 10u8) { // '\n' - fputs_str(fd, "\\n"); + fputsstr(fd, "\\n"); } else { if (c == 9u8) { // '\t' - fputs_str(fd, "\\t"); + fputsstr(fd, "\\t"); } else { if (c == 13u8) { // '\r' - fputs_str(fd, "\\r"); + fputsstr(fd, "\\r"); } else { if (c < 32u8) { fputhex2(fd, c); @@ -328,7 +328,7 @@ fn fputq(fd: i32, p: *u8, n: i32) void = { if (c == 127u8) { fputhex2(fd, c); } else { - fputc_byte(fd, c); + fputcbyte(fd, c); }; }; }; @@ -338,7 +338,7 @@ fn fputq(fd: i32, p: *u8, n: i32) void = { }; i += 1; }; - fputc_byte(fd, 34u8); + fputcbyte(fd, 34u8); }; // tokprint — write one token line to fd. Format must match @@ -354,35 +354,35 @@ export fn tokprint(fd: i32, t: *tok) void = { let tfile: str = t.file; let ttext: str = t.text; if (tfile.len > 0) { - fputs_str(fd, tfile); + fputsstr(fd, tfile); } else { - fputs_str(fd, ""); + fputsstr(fd, ""); }; - fputc_byte(fd, 58u8); // ':' + fputcbyte(fd, 58u8); // ':' let buf: [32]u8; let n: i32 = strconv.i64toa(buf[0:32], t.line: i64); os.write(fd, buf.ptr, n: u64); - fputc_byte(fd, 58u8); + fputcbyte(fd, 58u8); n = strconv.i64toa(buf[0:32], t.col: i64); os.write(fd, buf.ptr, n: u64); - fputc_byte(fd, 32u8); // ' ' - fputs_str(fd, tokname(t.kind)); + fputcbyte(fd, 32u8); // ' ' + fputsstr(fd, tokname(t.kind)); if (t.kind == TK_IDENT) { - fputc_byte(fd, 32u8); + fputcbyte(fd, 32u8); fputq(fd, ttext.ptr, ttext.len); } else { if (t.kind == TK_STR) { - fputc_byte(fd, 32u8); + fputcbyte(fd, 32u8); fputq(fd, ttext.ptr, ttext.len); } else { if (t.kind == TK_ERR) { - fputc_byte(fd, 32u8); + fputcbyte(fd, 32u8); fputq(fd, ttext.ptr, ttext.len); } else { if (t.kind == TK_INT) { - fputc_byte(fd, 32u8); + fputcbyte(fd, 32u8); n = strconv.u64toa(buf[0:32], t.uval); os.write(fd, buf.ptr, n: u64); } else { if (t.kind == TK_RUNE) { - fputc_byte(fd, 32u8); + fputcbyte(fd, 32u8); n = strconv.u64toa(buf[0:32], t.uval); os.write(fd, buf.ptr, n: u64); };};};};}; @@ -390,5 +390,5 @@ export fn tokprint(fd: i32, t: *tok) void = { // won't byte-match across implementations. Diff fixtures must // be float-free until we implement a stable float formatter. - fputc_byte(fd, 10u8); // '\n' + fputcbyte(fd, 10u8); // '\n' }; diff --git a/selfhost/cmd/wcc/typ.ww b/selfhost/cmd/wcc/typ.ww index d7f83442..9edbeb0d 100644 --- a/selfhost/cmd/wcc/typ.ww +++ b/selfhost/cmd/wcc/typ.ww @@ -153,7 +153,7 @@ export fn typesinit(c: *tctx, a: *arena) void = { c.ty_untyped_nil = prim(a, TY_UNTYPED_NIL, "untyped_nil", 0u64, 1u64); }; -export fn type_ptr(a: *arena, sub: *tinfo) *tinfo = { +export fn typeptr(a: *arena, sub: *tinfo) *tinfo = { let t: *tinfo = newtype(a, TY_PTR); t.sub = sub; t.size = 8u64; @@ -161,7 +161,7 @@ export fn type_ptr(a: *arena, sub: *tinfo) *tinfo = { return t; }; -export fn type_slice(a: *arena, sub: *tinfo) *tinfo = { +export fn typeslice(a: *arena, sub: *tinfo) *tinfo = { let t: *tinfo = newtype(a, TY_SLICE); t.sub = sub; t.size = 24u64; @@ -169,7 +169,7 @@ export fn type_slice(a: *arena, sub: *tinfo) *tinfo = { return t; }; -export fn type_array(a: *arena, sub: *tinfo, n: u64) *tinfo = { +export fn typearray(a: *arena, sub: *tinfo, n: u64) *tinfo = { let t: *tinfo = newtype(a, TY_ARRAY); t.sub = sub; t.alen = n; @@ -182,7 +182,7 @@ export fn type_array(a: *arena, sub: *tinfo, n: u64) *tinfo = { return t; }; -export fn type_chan(a: *arena, sub: *tinfo) *tinfo = { +export fn typechan(a: *arena, sub: *tinfo) *tinfo = { let t: *tinfo = newtype(a, TY_CHAN); t.sub = sub; t.size = 8u64; @@ -190,7 +190,7 @@ export fn type_chan(a: *arena, sub: *tinfo) *tinfo = { return t; }; -export fn type_named(a: *arena, name: str, under: *tinfo) *tinfo = { +export fn typenamed(a: *arena, name: str, under: *tinfo) *tinfo = { let t: *tinfo = newtype(a, TY_NAMED); t.name = name; t.under = under; @@ -203,7 +203,7 @@ export fn type_named(a: *arena, name: str, under: *tinfo) *tinfo = { // ---- predicates ------------------------------------------------------- -export fn type_isint(t: *tinfo) bool = { +export fn typeisint(t: *tinfo) bool = { if (t == nil) { return false; }; let k: i32 = t.kind; if (k == TY_I8) { return true; }; @@ -220,26 +220,26 @@ export fn type_isint(t: *tinfo) bool = { if (k == TY_RUNE){ return true; }; if (k == TY_UNTYPED_INT) { return true; }; if (k == TY_UNTYPED_RUNE) { return true; }; - if (k == TY_NAMED) { return type_isint(t.under); }; + if (k == TY_NAMED) { return typeisint(t.under); }; return false; }; -export fn type_isfloat(t: *tinfo) bool = { +export fn typeisfloat(t: *tinfo) bool = { if (t == nil) { return false; }; let k: i32 = t.kind; if (k == TY_F32) { return true; }; if (k == TY_F64) { return true; }; if (k == TY_UNTYPED_FLOAT) { return true; }; - if (k == TY_NAMED) { return type_isfloat(t.under); }; + if (k == TY_NAMED) { return typeisfloat(t.under); }; return false; }; -export fn type_isnum(t: *tinfo) bool = { - if (type_isint(t)) { return true; }; - return type_isfloat(t); +export fn typeisnum(t: *tinfo) bool = { + if (typeisint(t)) { return true; }; + return typeisfloat(t); }; -export fn type_isunsigned(t: *tinfo) bool = { +export fn typeisunsigned(t: *tinfo) bool = { if (t == nil) { return false; }; let k: i32 = t.kind; if (k == TY_U8) { return true; }; @@ -248,11 +248,11 @@ export fn type_isunsigned(t: *tinfo) bool = { if (k == TY_U64) { return true; }; if (k == TY_UINT){ return true; }; if (k == TY_UINTPTR) { return true; }; - if (k == TY_NAMED) { return type_isunsigned(t.under); }; + if (k == TY_NAMED) { return typeisunsigned(t.under); }; return false; }; -export fn type_isuntyped(t: *tinfo) bool = { +export fn typeisuntyped(t: *tinfo) bool = { if (t == nil) { return false; }; let k: i32 = t.kind; if (k == TY_UNTYPED_INT) { return true; }; @@ -264,29 +264,29 @@ export fn type_isuntyped(t: *tinfo) bool = { return false; }; -// type_eq — structural equality. Named types compare nominally. -export fn type_eq(a: *tinfo, b: *tinfo) bool = { +// typeeq — structural equality. Named types compare nominally. +export fn typeeq(a: *tinfo, b: *tinfo) bool = { if (a == b) { return true; }; if (a == nil) { return false; }; if (b == nil) { return false; }; if (a.kind != b.kind) { return false; }; let k: i32 = a.kind; - if (k == TY_PTR) { return type_eq(a.sub, b.sub); }; - if (k == TY_SLICE) { return type_eq(a.sub, b.sub); }; - if (k == TY_CHAN) { return type_eq(a.sub, b.sub); }; + if (k == TY_PTR) { return typeeq(a.sub, b.sub); }; + if (k == TY_SLICE) { return typeeq(a.sub, b.sub); }; + if (k == TY_CHAN) { return typeeq(a.sub, b.sub); }; if (k == TY_ARRAY) { if (a.alen != b.alen) { return false; }; - return type_eq(a.sub, b.sub); + return typeeq(a.sub, b.sub); }; if (k == TY_FN) { if (a.variadic != b.variadic) { return false; }; - if (!type_eq(a.ret, b.ret)) { return false; }; + if (!typeeq(a.ret, b.ret)) { return false; }; let pa: *tparam = a.params; let pb: *tparam = b.params; for (true) { if (pa == nil) { if (pb == nil) { return true; }; return false; }; if (pb == nil) { return false; }; - if (!type_eq(pa.type_, pb.type_)) { return false; }; + if (!typeeq(pa.type_, pb.type_)) { return false; }; pa = pa.tnext; pb = pb.tnext; }; @@ -306,7 +306,7 @@ export fn type_eq(a: *tinfo, b: *tinfo) bool = { if (na[i] != nb[i]) { return false; }; i += 1; }; - if (!type_eq(fa.type_, fb.type_)) { return false; }; + if (!typeeq(fa.type_, fb.type_)) { return false; }; fa = fa.tnext; fb = fb.tnext; }; @@ -319,7 +319,7 @@ export fn type_eq(a: *tinfo, b: *tinfo) bool = { for (true) { if (pa == nil) { if (pb == nil) { return true; }; return false; }; if (pb == nil) { return false; }; - if (!type_eq(pa.type_, pb.type_)) { return false; }; + if (!typeeq(pa.type_, pb.type_)) { return false; }; pa = pa.tnext; pb = pb.tnext; }; diff --git a/selfhost/cmd/wwdump/main.combined.ww b/selfhost/cmd/wwdump/main.combined.ww index 4397bf37..5c613a16 100644 --- a/selfhost/cmd/wwdump/main.combined.ww +++ b/selfhost/cmd/wwdump/main.combined.ww @@ -570,7 +570,7 @@ type tok = struct { // ---- keyword lookup --------------------------------------------------- -fn streq_n(a: *u8, b: str, n: i32) bool = { +fn streqn(a: *u8, b: str, n: i32) bool = { if (b.len != n) { return false; }; let i: i32 = 0; for (i < n) { @@ -584,30 +584,30 @@ fn streq_n(a: *u8, b: str, n: i32) bool = { // or TK_NONE if it's an ordinary identifier. Linear search over a // small alphabetised list, matching cmd/wcc/tok.c. export fn kwlookup(p: *u8, n: i32) i32 = { - if (streq_n(p, "as", n)) { return TK_AS; }; - if (streq_n(p, "break", n)) { return TK_BREAK; }; - if (streq_n(p, "case", n)) { return TK_CASE; }; - if (streq_n(p, "chan", n)) { return TK_CHAN; }; - if (streq_n(p, "continue", n)) { return TK_CONTINUE; }; - if (streq_n(p, "def", n)) { return TK_DEF; }; - if (streq_n(p, "defer", n)) { return TK_DEFER; }; - if (streq_n(p, "else", n)) { return TK_ELSE; }; - if (streq_n(p, "export", n)) { return TK_EXPORT; }; - if (streq_n(p, "false", n)) { return TK_FALSE; }; - if (streq_n(p, "fn", n)) { return TK_FN; }; - if (streq_n(p, "for", n)) { return TK_FOR; }; - if (streq_n(p, "if", n)) { return TK_IF; }; - if (streq_n(p, "let", n)) { return TK_LET; }; - if (streq_n(p, "match", n)) { return TK_MATCH; }; - if (streq_n(p, "nil", n)) { return TK_NIL; }; - if (streq_n(p, "proc", n)) { return TK_PROC; }; - if (streq_n(p, "return", n)) { return TK_RETURN; }; - if (streq_n(p, "static", n)) { return TK_STATIC; }; - if (streq_n(p, "struct", n)) { return TK_STRUCT; }; - if (streq_n(p, "switch", n)) { return TK_SWITCH; }; - if (streq_n(p, "true", n)) { return TK_TRUE; }; - if (streq_n(p, "type", n)) { return TK_TYPE; }; - if (streq_n(p, "use", n)) { return TK_USE; }; + if (streqn(p, "as", n)) { return TK_AS; }; + if (streqn(p, "break", n)) { return TK_BREAK; }; + if (streqn(p, "case", n)) { return TK_CASE; }; + if (streqn(p, "chan", n)) { return TK_CHAN; }; + if (streqn(p, "continue", n)) { return TK_CONTINUE; }; + if (streqn(p, "def", n)) { return TK_DEF; }; + if (streqn(p, "defer", n)) { return TK_DEFER; }; + if (streqn(p, "else", n)) { return TK_ELSE; }; + if (streqn(p, "export", n)) { return TK_EXPORT; }; + if (streqn(p, "false", n)) { return TK_FALSE; }; + if (streqn(p, "fn", n)) { return TK_FN; }; + if (streqn(p, "for", n)) { return TK_FOR; }; + if (streqn(p, "if", n)) { return TK_IF; }; + if (streqn(p, "let", n)) { return TK_LET; }; + if (streqn(p, "match", n)) { return TK_MATCH; }; + if (streqn(p, "nil", n)) { return TK_NIL; }; + if (streqn(p, "proc", n)) { return TK_PROC; }; + if (streqn(p, "return", n)) { return TK_RETURN; }; + if (streqn(p, "static", n)) { return TK_STATIC; }; + if (streqn(p, "struct", n)) { return TK_STRUCT; }; + if (streqn(p, "switch", n)) { return TK_SWITCH; }; + if (streqn(p, "true", n)) { return TK_TRUE; }; + if (streqn(p, "type", n)) { return TK_TYPE; }; + if (streqn(p, "use", n)) { return TK_USE; }; return TK_NONE; }; @@ -714,13 +714,13 @@ export fn tokname(k: i32) str = { // fputq mirrors cmd/wcc/tok.c:fputq — quote the string with C-style // escapes for \, ", \n, \t, \r and \xNN for other non-printables. -fn fputc_byte(fd: i32, b: u8) void = { +fn fputcbyte(fd: i32, b: u8) void = { let buf: [1]u8; buf[0] = b; os.write(fd, buf.ptr, 1u64); }; -fn fputs_str(fd: i32, s: str) void = { +fn fputsstr(fd: i32, s: str) void = { os.write(fd, s.ptr, s.len: u64); }; @@ -739,24 +739,24 @@ fn fputhex2(fd: i32, b: u8) void = { }; fn fputq(fd: i32, p: *u8, n: i32) void = { - fputc_byte(fd, 34u8); // '"' + fputcbyte(fd, 34u8); // '"' let i: i32 = 0; for (i < n) { let c: u8 = p[i]; if (c == 92u8) { // '\\' - fputs_str(fd, "\\\\"); + fputsstr(fd, "\\\\"); } else { if (c == 34u8) { // '"' - fputs_str(fd, "\\\""); + fputsstr(fd, "\\\""); } else { if (c == 10u8) { // '\n' - fputs_str(fd, "\\n"); + fputsstr(fd, "\\n"); } else { if (c == 9u8) { // '\t' - fputs_str(fd, "\\t"); + fputsstr(fd, "\\t"); } else { if (c == 13u8) { // '\r' - fputs_str(fd, "\\r"); + fputsstr(fd, "\\r"); } else { if (c < 32u8) { fputhex2(fd, c); @@ -764,7 +764,7 @@ fn fputq(fd: i32, p: *u8, n: i32) void = { if (c == 127u8) { fputhex2(fd, c); } else { - fputc_byte(fd, c); + fputcbyte(fd, c); }; }; }; @@ -774,7 +774,7 @@ fn fputq(fd: i32, p: *u8, n: i32) void = { }; i += 1; }; - fputc_byte(fd, 34u8); + fputcbyte(fd, 34u8); }; // tokprint — write one token line to fd. Format must match @@ -790,35 +790,35 @@ export fn tokprint(fd: i32, t: *tok) void = { let tfile: str = t.file; let ttext: str = t.text; if (tfile.len > 0) { - fputs_str(fd, tfile); + fputsstr(fd, tfile); } else { - fputs_str(fd, ""); + fputsstr(fd, ""); }; - fputc_byte(fd, 58u8); // ':' + fputcbyte(fd, 58u8); // ':' let buf: [32]u8; let n: i32 = strconv.i64toa(buf[0:32], t.line: i64); os.write(fd, buf.ptr, n: u64); - fputc_byte(fd, 58u8); + fputcbyte(fd, 58u8); n = strconv.i64toa(buf[0:32], t.col: i64); os.write(fd, buf.ptr, n: u64); - fputc_byte(fd, 32u8); // ' ' - fputs_str(fd, tokname(t.kind)); + fputcbyte(fd, 32u8); // ' ' + fputsstr(fd, tokname(t.kind)); if (t.kind == TK_IDENT) { - fputc_byte(fd, 32u8); + fputcbyte(fd, 32u8); fputq(fd, ttext.ptr, ttext.len); } else { if (t.kind == TK_STR) { - fputc_byte(fd, 32u8); + fputcbyte(fd, 32u8); fputq(fd, ttext.ptr, ttext.len); } else { if (t.kind == TK_ERR) { - fputc_byte(fd, 32u8); + fputcbyte(fd, 32u8); fputq(fd, ttext.ptr, ttext.len); } else { if (t.kind == TK_INT) { - fputc_byte(fd, 32u8); + fputcbyte(fd, 32u8); n = strconv.u64toa(buf[0:32], t.uval); os.write(fd, buf.ptr, n: u64); } else { if (t.kind == TK_RUNE) { - fputc_byte(fd, 32u8); + fputcbyte(fd, 32u8); n = strconv.u64toa(buf[0:32], t.uval); os.write(fd, buf.ptr, n: u64); };};};};}; @@ -826,7 +826,7 @@ export fn tokprint(fd: i32, t: *tok) void = { // won't byte-match across implementations. Diff fixtures must // be float-free until we implement a stable float formatter. - fputc_byte(fd, 10u8); // '\n' + fputcbyte(fd, 10u8); // '\n' }; // ascii — byte-class predicates and case folding for the ASCII range. @@ -988,14 +988,14 @@ fn lget(l: *lex) i32 = { return c; }; -fn cur_pos(l: *lex, out: *pos) void = { +fn curpos(l: *lex, out: *pos) void = { out.file = l.file; out.line = l.line; out.col = l.col; }; // putuint — write `v` (signed, but always non-negative here) to fd 2 -// in decimal. Standalone so err_at doesn't drag in fmt and create a +// in decimal. Standalone so errat doesn't drag in fmt and create a // dependency cycle with strconv. fn putuint(fd: i32, v: i32) void = { let tmp: [16]u8; @@ -1013,7 +1013,7 @@ fn putuint(fd: i32, v: i32) void = { os.write(fd, buf.ptr, m: u64); }; -fn err_at(l: *lex, p: *pos, msg: str) void = { +fn errat(l: *lex, p: *pos, msg: str) void = { let pf: str = p.file; os.write(2, pf.ptr, pf.len: u64); os.write(2, ":".ptr, 1u64); @@ -1052,8 +1052,8 @@ fn skipws(l: *lex) bool = { let x: i32 = lget(l); if (x < 0) { let cp: pos; - cur_pos(l, &cp); - err_at(l, &cp, "unterminated /* comment"); + curpos(l, &cp); + errat(l, &cp, "unterminated /* comment"); return false; }; if (prev == 42) { @@ -1124,13 +1124,13 @@ fn escape(l: *lex, out: *i32) bool = { if (hi < 0) { return false; }; if (lo < 0) { return false; }; if (!ascii.ishex(hi: u8)) { - let cp: pos; cur_pos(l, &cp); - err_at(l, &cp, "bad \\x escape"); + let cp: pos; curpos(l, &cp); + errat(l, &cp, "bad \\x escape"); return false; }; if (!ascii.ishex(lo: u8)) { - let cp: pos; cur_pos(l, &cp); - err_at(l, &cp, "bad \\x escape"); + let cp: pos; curpos(l, &cp); + errat(l, &cp, "bad \\x escape"); return false; }; let h: i32 = ascii.digitval(hi: u8); @@ -1138,13 +1138,13 @@ fn escape(l: *lex, out: *i32) bool = { *out = (h << 4) | lv; return true; }; - let cp: pos; cur_pos(l, &cp); - err_at(l, &cp, "bad escape"); + let cp: pos; curpos(l, &cp); + errat(l, &cp, "bad escape"); return false; }; -// scan_decimal_run — consume a run of decimal digits and underscores. -fn scan_decimal_run(l: *lex) void = { +// scandecimalrun — consume a run of decimal digits and underscores. +fn scandecimalrun(l: *lex) void = { for (true) { let c: i32 = lpeek(l, 0u64); if (c < 0) { break; }; @@ -1155,7 +1155,7 @@ fn scan_decimal_run(l: *lex) void = { }; }; -fn scan_hex_run(l: *lex) void = { +fn scanhexrun(l: *lex) void = { for (true) { let c: i32 = lpeek(l, 0u64); if (c < 0) { break; }; @@ -1166,7 +1166,7 @@ fn scan_hex_run(l: *lex) void = { }; }; -fn scan_bin_run(l: *lex) void = { +fn scanbinrun(l: *lex) void = { for (true) { let c: i32 = lpeek(l, 0u64); if (c == 48) { lget(l); continue; }; @@ -1176,7 +1176,7 @@ fn scan_bin_run(l: *lex) void = { }; }; -fn scan_oct_run(l: *lex) void = { +fn scanoctrun(l: *lex) void = { for (true) { let c: i32 = lpeek(l, 0u64); if (c < 48) { break; }; @@ -1187,8 +1187,8 @@ fn scan_oct_run(l: *lex) void = { }; }; -// scan_exp — consume the [eE][+-]?[0-9]+ tail of a float, if present. -fn scan_exp(l: *lex) void = { +// scanexp — consume the [eE][+-]?[0-9]+ tail of a float, if present. +fn scanexp(l: *lex) void = { let e: i32 = lpeek(l, 0u64); if (e != 101) { if (e != 69) { return; }; }; // 'e' or 'E' lget(l); @@ -1217,41 +1217,41 @@ fn lexnum(l: *lex, start: *pos, out: *tok) void = { if (c0 == 48) { // '0' if (c1 == 120) { // 'x' - lget(l); lget(l); base = 16; scan_hex_run(l); + lget(l); lget(l); base = 16; scanhexrun(l); } else { if (c1 == 88) { // 'X' - lget(l); lget(l); base = 16; scan_hex_run(l); + lget(l); lget(l); base = 16; scanhexrun(l); } else { if (c1 == 98) { // 'b' - lget(l); lget(l); base = 2; scan_bin_run(l); + lget(l); lget(l); base = 2; scanbinrun(l); } else { if (c1 == 66) { // 'B' - lget(l); lget(l); base = 2; scan_bin_run(l); + lget(l); lget(l); base = 2; scanbinrun(l); } else { if (c1 == 111) { // 'o' - lget(l); lget(l); base = 8; scan_oct_run(l); + lget(l); lget(l); base = 8; scanoctrun(l); } else { if (c1 == 79) { // 'O' - lget(l); lget(l); base = 8; scan_oct_run(l); + lget(l); lget(l); base = 8; scanoctrun(l); } else { - scan_decimal_run(l); + scandecimalrun(l); if (lpeek(l, 0u64) == 46) { let after: i32 = lpeek(l, 1u64); if (after >= 48) { if (after <= 57) { isfloat = true; lget(l); - scan_decimal_run(l); - scan_exp(l); + scandecimalrun(l); + scanexp(l); }; }; }; };};};};};}; } else { - scan_decimal_run(l); + scandecimalrun(l); if (lpeek(l, 0u64) == 46) { let after: i32 = lpeek(l, 1u64); if (after >= 48) { if (after <= 57) { isfloat = true; lget(l); - scan_decimal_run(l); - scan_exp(l); + scandecimalrun(l); + scanexp(l); }; }; }; @@ -1276,7 +1276,7 @@ fn lexnum(l: *lex, start: *pos, out: *tok) void = { let ok: bool = false; out.uval = parseint(digs, dn, base, &ok); if (!ok) { - err_at(l, start, "bad integer literal"); + errat(l, start, "bad integer literal"); out.kind = TK_ERR; }; }; @@ -1356,7 +1356,7 @@ fn lexstr(l: *lex, start: *pos, out: *tok) void = { for (true) { let c: i32 = lpeek(l, 0u64); if (c < 0) { - err_at(l, start, "unterminated string"); + errat(l, start, "unterminated string"); out.kind = TK_ERR; out.file = start.file; out.line = start.line; @@ -1401,7 +1401,7 @@ fn lexstr(l: *lex, start: *pos, out: *tok) void = { fn lexrune(l: *lex, start: *pos, out: *tok) void = { let c: i32 = lpeek(l, 0u64); if (c < 0) { - err_at(l, start, "unterminated rune"); + errat(l, start, "unterminated rune"); out.kind = TK_ERR; out.file = start.file; out.line = start.line; @@ -1417,7 +1417,7 @@ fn lexrune(l: *lex, start: *pos, out: *tok) void = { ch = lget(l); }; if (lpeek(l, 0u64) != 39) { - err_at(l, start, "rune literal missing closing '"); + errat(l, start, "rune literal missing closing '"); out.kind = TK_ERR; out.file = start.file; out.line = start.line; @@ -1433,16 +1433,16 @@ fn lexrune(l: *lex, start: *pos, out: *tok) void = { out.uval = ch: u64; }; -fn emit_simple(start: *pos, k: i32, out: *tok) void = { +fn emitsimple(start: *pos, k: i32, out: *tok) void = { out.kind = k; out.file = start.file; out.line = start.line; out.col = start.col; }; -// set_pos_from — copy file/line/col from a *pos into a tok. Used by +// setposfrom — copy file/line/col from a *pos into a tok. Used by // the err-token path where we already have a pos. -fn set_pos_from(out: *tok, p: *pos) void = { +fn setposfrom(out: *tok, p: *pos) void = { out.file = p.file; out.line = p.line; out.col = p.col; @@ -1465,11 +1465,11 @@ export fn lexnext(l: *lex, out: *tok) void = { out.tsuffix = empty; if (!skipws(l)) { - let p: pos; cur_pos(l, &p); - emit_simple(&p, TK_EOF, out); + let p: pos; curpos(l, &p); + emitsimple(&p, TK_EOF, out); return; }; - let start: pos; cur_pos(l, &start); + let start: pos; curpos(l, &start); let c: i32 = lpeek(l, 0u64); if (c >= 0) { @@ -1482,98 +1482,98 @@ export fn lexnext(l: *lex, out: *tok) void = { lget(l); - if (c == 40) { emit_simple(&start, TK_LPAREN, out); return; }; - if (c == 41) { emit_simple(&start, TK_RPAREN, out); return; }; - if (c == 123) { emit_simple(&start, TK_LBRACE, out); return; }; - if (c == 125) { emit_simple(&start, TK_RBRACE, out); return; }; - if (c == 91) { emit_simple(&start, TK_LBRACK, out); return; }; - if (c == 93) { emit_simple(&start, TK_RBRACK, out); return; }; - if (c == 44) { emit_simple(&start, TK_COMMA, out); return; }; - if (c == 59) { emit_simple(&start, TK_SEMI, out); return; }; - if (c == 58) { emit_simple(&start, TK_COLON, out); return; }; - if (c == 64) { emit_simple(&start, TK_AT, out); return; }; - if (c == 63) { emit_simple(&start, TK_QUESTION, out); return; }; - if (c == 126) { emit_simple(&start, TK_TILDE, out); return; }; + if (c == 40) { emitsimple(&start, TK_LPAREN, out); return; }; + if (c == 41) { emitsimple(&start, TK_RPAREN, out); return; }; + if (c == 123) { emitsimple(&start, TK_LBRACE, out); return; }; + if (c == 125) { emitsimple(&start, TK_RBRACE, out); return; }; + if (c == 91) { emitsimple(&start, TK_LBRACK, out); return; }; + if (c == 93) { emitsimple(&start, TK_RBRACK, out); return; }; + if (c == 44) { emitsimple(&start, TK_COMMA, out); return; }; + if (c == 59) { emitsimple(&start, TK_SEMI, out); return; }; + if (c == 58) { emitsimple(&start, TK_COLON, out); return; }; + if (c == 64) { emitsimple(&start, TK_AT, out); return; }; + if (c == 63) { emitsimple(&start, TK_QUESTION, out); return; }; + if (c == 126) { emitsimple(&start, TK_TILDE, out); return; }; if (c == 46) { // '.' if (lpeek(l, 0u64) == 46) { if (lpeek(l, 1u64) == 46) { lget(l); lget(l); - emit_simple(&start, TK_ELLIPSIS, out); return; + emitsimple(&start, TK_ELLIPSIS, out); return; }; lget(l); - emit_simple(&start, TK_DOTDOT, out); return; + emitsimple(&start, TK_DOTDOT, out); return; }; - emit_simple(&start, TK_DOT, out); return; + emitsimple(&start, TK_DOT, out); return; }; if (c == 43) { - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_PLUSEQ, out); return; }; - emit_simple(&start, TK_PLUS, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_PLUSEQ, out); return; }; + emitsimple(&start, TK_PLUS, out); return; }; if (c == 45) { - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_MINUSEQ, out); return; }; - if (lpeek(l, 0u64) == 62) { lget(l); emit_simple(&start, TK_ARROW, out); return; }; - emit_simple(&start, TK_MINUS, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_MINUSEQ, out); return; }; + if (lpeek(l, 0u64) == 62) { lget(l); emitsimple(&start, TK_ARROW, out); return; }; + emitsimple(&start, TK_MINUS, out); return; }; if (c == 42) { - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_STAREQ, out); return; }; - emit_simple(&start, TK_STAR, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_STAREQ, out); return; }; + emitsimple(&start, TK_STAR, out); return; }; if (c == 47) { - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_SLASHEQ, out); return; }; - emit_simple(&start, TK_SLASH, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_SLASHEQ, out); return; }; + emitsimple(&start, TK_SLASH, out); return; }; if (c == 37) { - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_PERCENTEQ, out); return; }; - emit_simple(&start, TK_PERCENT, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_PERCENTEQ, out); return; }; + emitsimple(&start, TK_PERCENT, out); return; }; if (c == 38) { - if (lpeek(l, 0u64) == 38) { lget(l); emit_simple(&start, TK_AND, out); return; }; - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_AMPEQ, out); return; }; - emit_simple(&start, TK_AMP, out); return; + if (lpeek(l, 0u64) == 38) { lget(l); emitsimple(&start, TK_AND, out); return; }; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_AMPEQ, out); return; }; + emitsimple(&start, TK_AMP, out); return; }; if (c == 124) { - if (lpeek(l, 0u64) == 124) { lget(l); emit_simple(&start, TK_OR, out); return; }; - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_PIPEEQ, out); return; }; - emit_simple(&start, TK_PIPE, out); return; + if (lpeek(l, 0u64) == 124) { lget(l); emitsimple(&start, TK_OR, out); return; }; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_PIPEEQ, out); return; }; + emitsimple(&start, TK_PIPE, out); return; }; if (c == 94) { - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_CARETEQ, out); return; }; - emit_simple(&start, TK_CARET, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_CARETEQ, out); return; }; + emitsimple(&start, TK_CARET, out); return; }; if (c == 61) { - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_EQ, out); return; }; - if (lpeek(l, 0u64) == 62) { lget(l); emit_simple(&start, TK_FATARROW, out); return; }; - emit_simple(&start, TK_ASSIGN, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_EQ, out); return; }; + if (lpeek(l, 0u64) == 62) { lget(l); emitsimple(&start, TK_FATARROW, out); return; }; + emitsimple(&start, TK_ASSIGN, out); return; }; if (c == 33) { - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_NEQ, out); return; }; - emit_simple(&start, TK_NOT, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_NEQ, out); return; }; + emitsimple(&start, TK_NOT, out); return; }; if (c == 60) { if (lpeek(l, 0u64) == 60) { lget(l); - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_LSHIFTEQ, out); return; }; - emit_simple(&start, TK_LSHIFT, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_LSHIFTEQ, out); return; }; + emitsimple(&start, TK_LSHIFT, out); return; }; - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_LE, out); return; }; - if (lpeek(l, 0u64) == 45) { lget(l); emit_simple(&start, TK_LARROW, out); return; }; - emit_simple(&start, TK_LT, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_LE, out); return; }; + if (lpeek(l, 0u64) == 45) { lget(l); emitsimple(&start, TK_LARROW, out); return; }; + emitsimple(&start, TK_LT, out); return; }; if (c == 62) { if (lpeek(l, 0u64) == 62) { lget(l); - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_RSHIFTEQ, out); return; }; - emit_simple(&start, TK_RSHIFT, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_RSHIFTEQ, out); return; }; + emitsimple(&start, TK_RSHIFT, out); return; }; - if (lpeek(l, 0u64) == 61) { lget(l); emit_simple(&start, TK_GE, out); return; }; - emit_simple(&start, TK_GT, out); return; + if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, TK_GE, out); return; }; + emitsimple(&start, TK_GT, out); return; }; - err_at(l, &start, "unexpected character"); + errat(l, &start, "unexpected character"); out.kind = TK_ERR; - set_pos_from(out, &start); + setposfrom(out, &start); let one: [1]u8; one[0] = c: u8; out.text = astrndup(l.a, one.ptr, 1u64); @@ -1973,12 +1973,12 @@ export fn parserinit(p: *parser, a: *arena, l: *lex) void = { fn advance(p: *parser) void = { refill(p); }; -fn accept_tok(p: *parser, k: i32) bool = { +fn accepttok(p: *parser, k: i32) bool = { if (p.cur_kind == k) { advance(p); return true; }; return false; }; -fn err_msg(p: *parser, msg: str) void = { +fn errmsg(p: *parser, msg: str) void = { let pre: str = "parse: "; os.write(2, pre.ptr, pre.len: u64); os.write(2, msg.ptr, msg.len: u64); @@ -1986,9 +1986,9 @@ fn err_msg(p: *parser, msg: str) void = { p.errs += 1; }; -fn expect_tok(p: *parser, k: i32, what: str) bool = { +fn expecttok(p: *parser, k: i32, what: str) bool = { if (p.cur_kind == k) { advance(p); return true; }; - err_msg(p, what); + errmsg(p, what); return false; }; @@ -1996,7 +1996,7 @@ fn expect_tok(p: *parser, k: i32, what: str) bool = { // Returns the empty str on error (and advances to make progress). fn expectident(p: *parser, into: *str) bool = { if (p.cur_kind != TK_IDENT) { - err_msg(p, "expected identifier"); + errmsg(p, "expected identifier"); advance(p); return false; }; @@ -2033,14 +2033,14 @@ fn parsetype(p: *parser) *node = { }; let n: *node = newnode(p.a, N_TARRAY, pf, pl, pc); n.rhs = parseexpr(p); - expect_tok(p, TK_RBRACK, "expected ']' in array type"); + expecttok(p, TK_RBRACK, "expected ']' in array type"); n.lhs = parsetype(p); return n; }; if (p.cur_kind == TK_STRUCT) { advance(p); - expect_tok(p, TK_LBRACE, "expected '{' after struct"); + expecttok(p, TK_LBRACE, "expected '{' after struct"); let n: *node = newnode(p.a, N_TSTRUCT, pf, pl, pc); let fhead: *node = nil; let ftail: *node = nil; @@ -2053,13 +2053,13 @@ fn parsetype(p: *parser) *node = { let fid: str; expectident(p, &fid); f.str = fid; - expect_tok(p, TK_COLON, "expected ':' in field"); + expecttok(p, TK_COLON, "expected ':' in field"); f.lhs = parsetype(p); if (fhead == nil) { fhead = f; ftail = f; } else { ftail.next = f; ftail = f; }; - if (!accept_tok(p, TK_COMMA)) { break; }; + if (!accepttok(p, TK_COMMA)) { break; }; }; - expect_tok(p, TK_RBRACE, "expected '}' after struct fields"); + expecttok(p, TK_RBRACE, "expected '}' after struct fields"); n.list = fhead; return n; }; @@ -2077,7 +2077,7 @@ fn parsetype(p: *parser) *node = { // (T) or (T, T, ...) or (T | T | ...) advance(p); let first: *node = parsetype(p); - if (accept_tok(p, TK_PIPE)) { + if (accepttok(p, TK_PIPE)) { let n: *node = newnode(p.a, N_TTAGGED, pf, pl, pc); let head: *node = first; let tail: *node = first; @@ -2085,14 +2085,14 @@ fn parsetype(p: *parser) *node = { let e: *node = parsetype(p); tail.next = e; tail = e; - if (!accept_tok(p, TK_PIPE)) { break; }; + if (!accepttok(p, TK_PIPE)) { break; }; }; - expect_tok(p, TK_RPAREN, "expected ')' in tagged-union type"); + expecttok(p, TK_RPAREN, "expected ')' in tagged-union type"); n.list = head; return n; }; - if (!accept_tok(p, TK_COMMA)) { - expect_tok(p, TK_RPAREN, "expected ')' after parenthesised type"); + if (!accepttok(p, TK_COMMA)) { + expecttok(p, TK_RPAREN, "expected ')' after parenthesised type"); return first; }; let n: *node = newnode(p.a, N_TTUPLE, pf, pl, pc); @@ -2102,28 +2102,28 @@ fn parsetype(p: *parser) *node = { let e: *node = parsetype(p); tail.next = e; tail = e; - if (!accept_tok(p, TK_COMMA)) { break; }; + if (!accepttok(p, TK_COMMA)) { break; }; if (p.cur_kind == TK_RPAREN) { break; }; }; - expect_tok(p, TK_RPAREN, "expected ')' in tuple type"); + expecttok(p, TK_RPAREN, "expected ')' in tuple type"); n.list = head; return n; }; if (p.cur_kind == TK_FN) { advance(p); - expect_tok(p, TK_LPAREN, "expected '(' after fn in type"); + expecttok(p, TK_LPAREN, "expected '(' after fn in type"); let n: *node = newnode(p.a, N_TFN, pf, pl, pc); // Anonymous-or-named params: parseparams handles named only; // for fn-type expressions the C parser allows IDENT-less // (anonymous) params. Stub: only named params for now. n.list = parseparams(p); - expect_tok(p, TK_RPAREN, "expected ')' after fn type params"); + expecttok(p, TK_RPAREN, "expected ')' after fn type params"); n.lhs = parsetype(p); return n; }; - err_msg(p, "expected type"); + errmsg(p, "expected type"); advance(p); return newnode(p.a, N_TNAME, pf, pl, pc); }; @@ -2215,7 +2215,7 @@ fn parseprimary(p: *parser) *node = { advance(p); let e: *node = parseexpr(p); // Tuple literal: (a, b, ...) - if (accept_tok(p, TK_COMMA)) { + if (accepttok(p, TK_COMMA)) { let t: *node = newnode(p.a, N_TUPLE, pf, pl, pc); t.list = e; let tail: *node = e; @@ -2224,12 +2224,12 @@ fn parseprimary(p: *parser) *node = { let en: *node = parseexpr(p); tail.next = en; tail = en; - if (!accept_tok(p, TK_COMMA)) { break; }; + if (!accepttok(p, TK_COMMA)) { break; }; }; - expect_tok(p, TK_RPAREN, "expected ')' in tuple"); + expecttok(p, TK_RPAREN, "expected ')' in tuple"); return t; }; - expect_tok(p, TK_RPAREN, "expected ')'"); + expecttok(p, TK_RPAREN, "expected ')'"); return e; }; if (p.cur_kind == TK_IDENT) { @@ -2255,16 +2255,16 @@ fn parseprimary(p: *parser) *node = { let fpc: i32 = p.cur_col; let id: str; expectident(p, &id); - expect_tok(p, TK_ASSIGN, "expected '=' in struct lit field"); + expecttok(p, TK_ASSIGN, "expected '=' in struct lit field"); let v: *node = parseexpr(p); let f: *node = newnode(p.a, N_FIELD, fpf, fpl, fpc); f.str = id; f.lhs = v; if (head == nil) { head = f; tail = f; } else { tail.next = f; tail = f; }; - if (!accept_tok(p, TK_COMMA)) { break; }; + if (!accepttok(p, TK_COMMA)) { break; }; }; - expect_tok(p, TK_RBRACE, "expected '}' after struct literal"); + expecttok(p, TK_RBRACE, "expected '}' after struct literal"); s.list = head; return s; }; @@ -2273,11 +2273,11 @@ fn parseprimary(p: *parser) *node = { if (p.cur_kind == TK_MATCH) { // match (e) { case let v: T => stmt; case T => stmt; case => stmt; }; advance(p); - expect_tok(p, TK_LPAREN, "expected '(' after match"); + expecttok(p, TK_LPAREN, "expected '(' after match"); let m: *node = newnode(p.a, N_MATCH, pf, pl, pc); m.lhs = parseexpr(p); - expect_tok(p, TK_RPAREN, "expected ')' after match scrutinee"); - expect_tok(p, TK_LBRACE, "expected '{' to open match body"); + expecttok(p, TK_RPAREN, "expected ')' after match scrutinee"); + expecttok(p, TK_LBRACE, "expected '{' to open match body"); let head: *node = nil; let tail: *node = nil; for (p.cur_kind == TK_CASE) { @@ -2291,21 +2291,21 @@ fn parseprimary(p: *parser) *node = { let id: str; expectident(p, &id); mc.str = id; - expect_tok(p, TK_COLON, "expected ':' after match binding"); + expecttok(p, TK_COLON, "expected ':' after match binding"); mc.lhs = parsetype(p); } else { if (p.cur_kind != TK_FATARROW) { mc.lhs = parsetype(p); };}; - expect_tok(p, TK_FATARROW, "expected '=>' in match arm"); + expecttok(p, TK_FATARROW, "expected '=>' in match arm"); mc.body = parsestmt(p); if (head == nil) { head = mc; tail = mc; } else { tail.next = mc; tail = mc; }; }; - expect_tok(p, TK_RBRACE, "expected '}' after match body"); + expecttok(p, TK_RBRACE, "expected '}' after match body"); m.list = head; return m; }; - err_msg(p, "expected expression"); + errmsg(p, "expected expression"); advance(p); return newnode(p.a, N_NONE, pf, pl, pc); }; @@ -2319,7 +2319,7 @@ fn parsearglist(p: *parser, close_kind: i32, head_out: **node) void = { let e: *node = parseexpr(p); if (head == nil) { head = e; tail = e; } else { tail.next = e; tail = e; }; - if (!accept_tok(p, TK_COMMA)) { break; }; + if (!accepttok(p, TK_COMMA)) { break; }; if (p.cur_kind == close_kind) { break; }; }; *head_out = head; @@ -2338,7 +2338,7 @@ fn parsepostfix(p: *parser, lhs: *node) *node = { let arghead: *node = nil; parsearglist(p, TK_RPAREN, &arghead); n.list = arghead; - expect_tok(p, TK_RPAREN, "expected ')' after args"); + expecttok(p, TK_RPAREN, "expected ')' after args"); cur = n; continue; }; @@ -2352,7 +2352,7 @@ fn parsepostfix(p: *parser, lhs: *node) *node = { if (p.cur_kind != TK_RBRACK) { n.cond = parseexpr(p); }; - expect_tok(p, TK_RBRACK, "expected ']' in slice"); + expecttok(p, TK_RBRACK, "expected ']' in slice"); cur = n; continue; }; @@ -2370,14 +2370,14 @@ fn parsepostfix(p: *parser, lhs: *node) *node = { if (p.cur_kind != TK_RBRACK) { n.cond = parseexpr(p); }; - expect_tok(p, TK_RBRACK, "expected ']' in slice"); + expecttok(p, TK_RBRACK, "expected ']' in slice"); cur = n; continue; }; let n: *node = newnode(p.a, N_INDEX, pf, pl, pc); n.lhs = cur; n.rhs = e; - expect_tok(p, TK_RBRACK, "expected ']' after index"); + expecttok(p, TK_RBRACK, "expected ']' after index"); cur = n; continue; }; @@ -2498,7 +2498,7 @@ fn parseexpr(p: *parser) *node = { // (single-cond C-style), expr-stmt, defer, break, continue. Switch // and match arms are not yet wired; tuple-let / multi-let neither. -fn parselet_local(p: *parser) *node = { +fn parseletlocal(p: *parser) *node = { let pf: str = p.cur_file; let pl: i32 = p.cur_line; let pc: i32 = p.cur_col; @@ -2507,13 +2507,13 @@ fn parselet_local(p: *parser) *node = { let id: str; expectident(p, &id); n.str = id; - if (accept_tok(p, TK_COLON)) { + if (accepttok(p, TK_COLON)) { n.lhs = parsetype(p); }; - if (accept_tok(p, TK_ASSIGN)) { + if (accepttok(p, TK_ASSIGN)) { n.rhs = parseexpr(p); }; - expect_tok(p, TK_SEMI, "expected ';' after let"); + expecttok(p, TK_SEMI, "expected ';' after let"); return n; }; @@ -2521,7 +2521,7 @@ fn parseblock(p: *parser) *node = { let pf: str = p.cur_file; let pl: i32 = p.cur_line; let pc: i32 = p.cur_col; - expect_tok(p, TK_LBRACE, "expected '{' to open block"); + expecttok(p, TK_LBRACE, "expected '{' to open block"); let blk: *node = newnode(p.a, N_BLOCK, pf, pl, pc); let head: *node = nil; let tail: *node = nil; @@ -2533,7 +2533,7 @@ fn parseblock(p: *parser) *node = { else { tail.next = s; tail = s; }; }; }; - expect_tok(p, TK_RBRACE, "expected '}' to close block"); + expecttok(p, TK_RBRACE, "expected '}' to close block"); blk.list = head; return blk; }; @@ -2543,12 +2543,12 @@ fn parseif(p: *parser) *node = { let pl: i32 = p.cur_line; let pc: i32 = p.cur_col; advance(p); // past `if` - expect_tok(p, TK_LPAREN, "expected '(' after if"); + expecttok(p, TK_LPAREN, "expected '(' after if"); let n: *node = newnode(p.a, N_IF, pf, pl, pc); n.cond = parseexpr(p); - expect_tok(p, TK_RPAREN, "expected ')' after if condition"); + expecttok(p, TK_RPAREN, "expected ')' after if condition"); n.body = parseblock(p); - if (accept_tok(p, TK_ELSE)) { + if (accepttok(p, TK_ELSE)) { if (p.cur_kind == TK_IF) { n.els = parseif(p); } else { @@ -2563,7 +2563,7 @@ fn parsefor(p: *parser) *node = { let pl: i32 = p.cur_line; let pc: i32 = p.cur_col; advance(p); // past `for` - expect_tok(p, TK_LPAREN, "expected '(' after for"); + expecttok(p, TK_LPAREN, "expected '(' after for"); let n: *node = newnode(p.a, N_FOR, pf, pl, pc); // Three forms (matching C parser): // for (cond) — only cond @@ -2574,14 +2574,14 @@ fn parsefor(p: *parser) *node = { // ';' it was cond. If we see two ';' total after init, post is // next. Simpler: peek for `let` to decide init form. if (p.cur_kind == TK_LET) { - n.lhs = parselet_local(p); // init (consumes its own ';') + n.lhs = parseletlocal(p); // init (consumes its own ';') n.cond = parseexpr(p); - expect_tok(p, TK_SEMI, "expected ';' after for cond"); + expecttok(p, TK_SEMI, "expected ';' after for cond"); n.rhs = parseexpr(p); } else { // Parse one expr. If next is ';', it's a 3-clause without init. let first: *node = parseexpr(p); - if (accept_tok(p, TK_SEMI)) { + if (accepttok(p, TK_SEMI)) { // cond ; post n.cond = first; n.rhs = parseexpr(p); @@ -2590,7 +2590,7 @@ fn parsefor(p: *parser) *node = { n.cond = first; }; }; - expect_tok(p, TK_RPAREN, "expected ')' after for"); + expecttok(p, TK_RPAREN, "expected ')' after for"); n.body = parseblock(p); return n; }; @@ -2606,18 +2606,18 @@ fn parsestmt(p: *parser) *node = { if (p.cur_kind == TK_LBRACE) { let b: *node = parseblock(p); - expect_tok(p, TK_SEMI, "expected ';' after block"); + expecttok(p, TK_SEMI, "expected ';' after block"); return b; }; - if (p.cur_kind == TK_LET) { return parselet_local(p); }; + if (p.cur_kind == TK_LET) { return parseletlocal(p); }; if (p.cur_kind == TK_IF) { let n: *node = parseif(p); - expect_tok(p, TK_SEMI, "expected ';' after if"); + expecttok(p, TK_SEMI, "expected ';' after if"); return n; }; if (p.cur_kind == TK_FOR) { let n: *node = parsefor(p); - expect_tok(p, TK_SEMI, "expected ';' after for"); + expecttok(p, TK_SEMI, "expected ';' after for"); return n; }; if (p.cur_kind == TK_RETURN) { @@ -2631,7 +2631,7 @@ fn parsestmt(p: *parser) *node = { let t: *node = newnode(p.a, N_TUPLE, pf, pl, pc); t.list = first; let tail: *node = first; - for (accept_tok(p, TK_COMMA)) { + for (accepttok(p, TK_COMMA)) { let e: *node = parseexpr(p); tail.next = e; tail = e; @@ -2641,24 +2641,24 @@ fn parsestmt(p: *parser) *node = { n.lhs = first; }; }; - expect_tok(p, TK_SEMI, "expected ';' after return"); + expecttok(p, TK_SEMI, "expected ';' after return"); return n; }; if (p.cur_kind == TK_DEFER) { advance(p); let n: *node = newnode(p.a, N_DEFER, pf, pl, pc); n.lhs = parseexpr(p); - expect_tok(p, TK_SEMI, "expected ';' after defer"); + expecttok(p, TK_SEMI, "expected ';' after defer"); return n; }; if (p.cur_kind == TK_BREAK) { advance(p); - expect_tok(p, TK_SEMI, "expected ';' after break"); + expecttok(p, TK_SEMI, "expected ';' after break"); return newnode(p.a, N_BREAK, pf, pl, pc); }; if (p.cur_kind == TK_CONTINUE) { advance(p); - expect_tok(p, TK_SEMI, "expected ';' after continue"); + expecttok(p, TK_SEMI, "expected ';' after continue"); return newnode(p.a, N_CONTINUE, pf, pl, pc); }; // expression statement, or tuple-destructure multi-assign: @@ -2678,15 +2678,15 @@ fn parsestmt(p: *parser) *node = { tail.next = lv; tail = lv; }; - expect_tok(p, TK_ASSIGN, "expected '=' after multi-assign lvalues"); + expecttok(p, TK_ASSIGN, "expected '=' after multi-assign lvalues"); m.rhs = parseexpr(p); m.list = head; - expect_tok(p, TK_SEMI, "expected ';' after multi-assign"); + expecttok(p, TK_SEMI, "expected ';' after multi-assign"); return m; }; let n: *node = newnode(p.a, N_EXPRSTMT, pf, pl, pc); n.lhs = e; - expect_tok(p, TK_SEMI, "expected ';' after expression statement"); + expecttok(p, TK_SEMI, "expected ';' after expression statement"); return n; }; @@ -2701,7 +2701,7 @@ fn parseuse(p: *parser) *node = { let id: str; expectident(p, &id); n.str = id; - expect_tok(p, TK_SEMI, "expected ';' after use"); + expecttok(p, TK_SEMI, "expected ';' after use"); return n; }; @@ -2714,11 +2714,11 @@ fn parsedef(p: *parser, exported: i32) *node = { let id: str; expectident(p, &id); n.str = id; - expect_tok(p, TK_COLON, "expected ':' in def"); + expecttok(p, TK_COLON, "expected ':' in def"); n.lhs = parsetype(p); - expect_tok(p, TK_ASSIGN, "expected '=' in def"); + expecttok(p, TK_ASSIGN, "expected '=' in def"); n.rhs = parseexpr(p); - expect_tok(p, TK_SEMI, "expected ';' after def"); + expecttok(p, TK_SEMI, "expected ';' after def"); n.exported = exported; return n; }; @@ -2732,13 +2732,13 @@ fn parselet(p: *parser, exported: i32) *node = { let id: str; expectident(p, &id); n.str = id; - if (accept_tok(p, TK_COLON)) { + if (accepttok(p, TK_COLON)) { n.lhs = parsetype(p); }; - if (accept_tok(p, TK_ASSIGN)) { + if (accepttok(p, TK_ASSIGN)) { n.rhs = parseexpr(p); }; - expect_tok(p, TK_SEMI, "expected ';' after let"); + expecttok(p, TK_SEMI, "expected ';' after let"); n.exported = exported; return n; }; @@ -2755,11 +2755,11 @@ fn parseattrs(p: *parser) *node = { let id: str; expectident(p, &id); a.str = id; - expect_tok(p, TK_LPAREN, "expected '(' after attribute name"); + expecttok(p, TK_LPAREN, "expected '(' after attribute name"); let arghead: *node = nil; parsearglist(p, TK_RPAREN, &arghead); a.list = arghead; - expect_tok(p, TK_RPAREN, "expected ')' after attribute args"); + expecttok(p, TK_RPAREN, "expected ')' after attribute args"); if (head == nil) { head = a; tail = a; } else { tail.next = a; tail = a; }; }; @@ -2780,11 +2780,11 @@ fn parseparams(p: *parser) *node = { let id: str; expectident(p, &id); n.str = id; - expect_tok(p, TK_COLON, "expected ':' in parameter"); + expecttok(p, TK_COLON, "expected ':' in parameter"); n.lhs = parsetype(p); if (head == nil) { head = n; tail = n; } else { tail.next = n; tail = n; }; - if (!accept_tok(p, TK_COMMA)) { break; }; + if (!accepttok(p, TK_COMMA)) { break; }; if (p.cur_kind == TK_RPAREN) { break; }; }; return head; @@ -2799,20 +2799,20 @@ fn parsefn(p: *parser, exported: i32, attrs: *node) *node = { let id: str; expectident(p, &id); n.str = id; - expect_tok(p, TK_LPAREN, "expected '(' after fn name"); + expecttok(p, TK_LPAREN, "expected '(' after fn name"); n.list = parseparams(p); - expect_tok(p, TK_RPAREN, "expected ')' after params"); + expecttok(p, TK_RPAREN, "expected ')' after params"); if (p.cur_kind != TK_ASSIGN) { if (p.cur_kind != TK_SEMI) { n.lhs = parsetype(p); }; }; - if (accept_tok(p, TK_ASSIGN)) { + if (accepttok(p, TK_ASSIGN)) { n.body = parseblock(p); - expect_tok(p, TK_SEMI, "expected ';' after fn body"); + expecttok(p, TK_SEMI, "expected ';' after fn body"); } else { // Body-less fn: FFI declaration (`fn name(args) ret;`). - expect_tok(p, TK_SEMI, "expected ';' after fn header"); + expecttok(p, TK_SEMI, "expected ';' after fn header"); }; n.exported = exported; n.attr = attrs; @@ -2828,9 +2828,9 @@ fn parsetypedecl(p: *parser, exported: i32) *node = { let id: str; expectident(p, &id); n.str = id; - expect_tok(p, TK_ASSIGN, "expected '=' in type decl"); + expecttok(p, TK_ASSIGN, "expected '=' in type decl"); n.lhs = parsetype(p); - expect_tok(p, TK_SEMI, "expected ';' after type decl"); + expecttok(p, TK_SEMI, "expected ';' after type decl"); n.exported = exported; return n; }; @@ -3053,7 +3053,7 @@ export fn typesinit(c: *tctx, a: *arena) void = { c.ty_untyped_nil = prim(a, TY_UNTYPED_NIL, "untyped_nil", 0u64, 1u64); }; -export fn type_ptr(a: *arena, sub: *tinfo) *tinfo = { +export fn typeptr(a: *arena, sub: *tinfo) *tinfo = { let t: *tinfo = newtype(a, TY_PTR); t.sub = sub; t.size = 8u64; @@ -3061,7 +3061,7 @@ export fn type_ptr(a: *arena, sub: *tinfo) *tinfo = { return t; }; -export fn type_slice(a: *arena, sub: *tinfo) *tinfo = { +export fn typeslice(a: *arena, sub: *tinfo) *tinfo = { let t: *tinfo = newtype(a, TY_SLICE); t.sub = sub; t.size = 24u64; @@ -3069,7 +3069,7 @@ export fn type_slice(a: *arena, sub: *tinfo) *tinfo = { return t; }; -export fn type_array(a: *arena, sub: *tinfo, n: u64) *tinfo = { +export fn typearray(a: *arena, sub: *tinfo, n: u64) *tinfo = { let t: *tinfo = newtype(a, TY_ARRAY); t.sub = sub; t.alen = n; @@ -3082,7 +3082,7 @@ export fn type_array(a: *arena, sub: *tinfo, n: u64) *tinfo = { return t; }; -export fn type_chan(a: *arena, sub: *tinfo) *tinfo = { +export fn typechan(a: *arena, sub: *tinfo) *tinfo = { let t: *tinfo = newtype(a, TY_CHAN); t.sub = sub; t.size = 8u64; @@ -3090,7 +3090,7 @@ export fn type_chan(a: *arena, sub: *tinfo) *tinfo = { return t; }; -export fn type_named(a: *arena, name: str, under: *tinfo) *tinfo = { +export fn typenamed(a: *arena, name: str, under: *tinfo) *tinfo = { let t: *tinfo = newtype(a, TY_NAMED); t.name = name; t.under = under; @@ -3103,7 +3103,7 @@ export fn type_named(a: *arena, name: str, under: *tinfo) *tinfo = { // ---- predicates ------------------------------------------------------- -export fn type_isint(t: *tinfo) bool = { +export fn typeisint(t: *tinfo) bool = { if (t == nil) { return false; }; let k: i32 = t.kind; if (k == TY_I8) { return true; }; @@ -3120,26 +3120,26 @@ export fn type_isint(t: *tinfo) bool = { if (k == TY_RUNE){ return true; }; if (k == TY_UNTYPED_INT) { return true; }; if (k == TY_UNTYPED_RUNE) { return true; }; - if (k == TY_NAMED) { return type_isint(t.under); }; + if (k == TY_NAMED) { return typeisint(t.under); }; return false; }; -export fn type_isfloat(t: *tinfo) bool = { +export fn typeisfloat(t: *tinfo) bool = { if (t == nil) { return false; }; let k: i32 = t.kind; if (k == TY_F32) { return true; }; if (k == TY_F64) { return true; }; if (k == TY_UNTYPED_FLOAT) { return true; }; - if (k == TY_NAMED) { return type_isfloat(t.under); }; + if (k == TY_NAMED) { return typeisfloat(t.under); }; return false; }; -export fn type_isnum(t: *tinfo) bool = { - if (type_isint(t)) { return true; }; - return type_isfloat(t); +export fn typeisnum(t: *tinfo) bool = { + if (typeisint(t)) { return true; }; + return typeisfloat(t); }; -export fn type_isunsigned(t: *tinfo) bool = { +export fn typeisunsigned(t: *tinfo) bool = { if (t == nil) { return false; }; let k: i32 = t.kind; if (k == TY_U8) { return true; }; @@ -3148,11 +3148,11 @@ export fn type_isunsigned(t: *tinfo) bool = { if (k == TY_U64) { return true; }; if (k == TY_UINT){ return true; }; if (k == TY_UINTPTR) { return true; }; - if (k == TY_NAMED) { return type_isunsigned(t.under); }; + if (k == TY_NAMED) { return typeisunsigned(t.under); }; return false; }; -export fn type_isuntyped(t: *tinfo) bool = { +export fn typeisuntyped(t: *tinfo) bool = { if (t == nil) { return false; }; let k: i32 = t.kind; if (k == TY_UNTYPED_INT) { return true; }; @@ -3164,29 +3164,29 @@ export fn type_isuntyped(t: *tinfo) bool = { return false; }; -// type_eq — structural equality. Named types compare nominally. -export fn type_eq(a: *tinfo, b: *tinfo) bool = { +// typeeq — structural equality. Named types compare nominally. +export fn typeeq(a: *tinfo, b: *tinfo) bool = { if (a == b) { return true; }; if (a == nil) { return false; }; if (b == nil) { return false; }; if (a.kind != b.kind) { return false; }; let k: i32 = a.kind; - if (k == TY_PTR) { return type_eq(a.sub, b.sub); }; - if (k == TY_SLICE) { return type_eq(a.sub, b.sub); }; - if (k == TY_CHAN) { return type_eq(a.sub, b.sub); }; + if (k == TY_PTR) { return typeeq(a.sub, b.sub); }; + if (k == TY_SLICE) { return typeeq(a.sub, b.sub); }; + if (k == TY_CHAN) { return typeeq(a.sub, b.sub); }; if (k == TY_ARRAY) { if (a.alen != b.alen) { return false; }; - return type_eq(a.sub, b.sub); + return typeeq(a.sub, b.sub); }; if (k == TY_FN) { if (a.variadic != b.variadic) { return false; }; - if (!type_eq(a.ret, b.ret)) { return false; }; + if (!typeeq(a.ret, b.ret)) { return false; }; let pa: *tparam = a.params; let pb: *tparam = b.params; for (true) { if (pa == nil) { if (pb == nil) { return true; }; return false; }; if (pb == nil) { return false; }; - if (!type_eq(pa.type_, pb.type_)) { return false; }; + if (!typeeq(pa.type_, pb.type_)) { return false; }; pa = pa.tnext; pb = pb.tnext; }; @@ -3206,7 +3206,7 @@ export fn type_eq(a: *tinfo, b: *tinfo) bool = { if (na[i] != nb[i]) { return false; }; i += 1; }; - if (!type_eq(fa.type_, fb.type_)) { return false; }; + if (!typeeq(fa.type_, fb.type_)) { return false; }; fa = fa.tnext; fb = fb.tnext; }; @@ -3219,7 +3219,7 @@ export fn type_eq(a: *tinfo, b: *tinfo) bool = { for (true) { if (pa == nil) { if (pb == nil) { return true; }; return false; }; if (pb == nil) { return false; }; - if (!type_eq(pa.type_, pb.type_)) { return false; }; + if (!typeeq(pa.type_, pb.type_)) { return false; }; pa = pa.tnext; pb = pb.tnext; }; @@ -3303,7 +3303,7 @@ export fn streq(a: str, b: str) bool = { return true; }; -export fn scope_lookup_local(s: *scope, name: str) *sym = { +export fn scopelookuplocal(s: *scope, name: str) *sym = { if (s == nil) { return nil; }; let h: u64 = hashstr(name); let bi: i32 = (h % (s.nbuckets: u64)): i32; @@ -3316,17 +3316,17 @@ export fn scope_lookup_local(s: *scope, name: str) *sym = { return nil; }; -export fn scope_lookup(s: *scope, name: str) *sym = { +export fn scopelookup(s: *scope, name: str) *sym = { for (s != nil) { - let r: *sym = scope_lookup_local(s, name); + let r: *sym = scopelookuplocal(s, name); if (r != nil) { return r; }; s = s.parent; }; return nil; }; -export fn scope_define(s: *scope, name: str, k: i32, t: *tinfo, decl: *node) *sym = { - if (scope_lookup_local(s, name) != nil) { return nil; }; +export fn scopedefine(s: *scope, name: str, k: i32, t: *tinfo, decl: *node) *sym = { + if (scopelookuplocal(s, name) != nil) { return nil; }; let sy: *sym = amalloc(s.a, 80u64): *sym; sy.name = name; sy.skind = k; @@ -3376,56 +3376,56 @@ type checker = struct { verbose: i32, // when non-zero, log each unresolved name }; -// seed_primitives — install the built-in type names so `i32`, `str`, +// seedprimitives — install the built-in type names so `i32`, `str`, // etc. can be looked up like ordinary symbols. -fn seed_primitives(c: *checker) void = { - scope_define(c.top, "void", SK_TYPE, c.tc.ty_void, nil); - scope_define(c.top, "bool", SK_TYPE, c.tc.ty_bool, nil); - scope_define(c.top, "rune", SK_TYPE, c.tc.ty_rune, nil); - scope_define(c.top, "i8", SK_TYPE, c.tc.ty_i8, nil); - scope_define(c.top, "i16", SK_TYPE, c.tc.ty_i16, nil); - scope_define(c.top, "i32", SK_TYPE, c.tc.ty_i32, nil); - scope_define(c.top, "i64", SK_TYPE, c.tc.ty_i64, nil); - scope_define(c.top, "u8", SK_TYPE, c.tc.ty_u8, nil); - scope_define(c.top, "u16", SK_TYPE, c.tc.ty_u16, nil); - scope_define(c.top, "u32", SK_TYPE, c.tc.ty_u32, nil); - scope_define(c.top, "u64", SK_TYPE, c.tc.ty_u64, nil); - scope_define(c.top, "int", SK_TYPE, c.tc.ty_int, nil); - scope_define(c.top, "uint", SK_TYPE, c.tc.ty_uint, nil); - scope_define(c.top, "uintptr", SK_TYPE, c.tc.ty_uintptr, nil); - scope_define(c.top, "f32", SK_TYPE, c.tc.ty_f32, nil); - scope_define(c.top, "f64", SK_TYPE, c.tc.ty_f64, nil); - scope_define(c.top, "str", SK_TYPE, c.tc.ty_str, nil); +fn seedprimitives(c: *checker) void = { + scopedefine(c.top, "void", SK_TYPE, c.tc.ty_void, nil); + scopedefine(c.top, "bool", SK_TYPE, c.tc.ty_bool, nil); + scopedefine(c.top, "rune", SK_TYPE, c.tc.ty_rune, nil); + scopedefine(c.top, "i8", SK_TYPE, c.tc.ty_i8, nil); + scopedefine(c.top, "i16", SK_TYPE, c.tc.ty_i16, nil); + scopedefine(c.top, "i32", SK_TYPE, c.tc.ty_i32, nil); + scopedefine(c.top, "i64", SK_TYPE, c.tc.ty_i64, nil); + scopedefine(c.top, "u8", SK_TYPE, c.tc.ty_u8, nil); + scopedefine(c.top, "u16", SK_TYPE, c.tc.ty_u16, nil); + scopedefine(c.top, "u32", SK_TYPE, c.tc.ty_u32, nil); + scopedefine(c.top, "u64", SK_TYPE, c.tc.ty_u64, nil); + scopedefine(c.top, "int", SK_TYPE, c.tc.ty_int, nil); + scopedefine(c.top, "uint", SK_TYPE, c.tc.ty_uint, nil); + scopedefine(c.top, "uintptr", SK_TYPE, c.tc.ty_uintptr, nil); + scopedefine(c.top, "f32", SK_TYPE, c.tc.ty_f32, nil); + scopedefine(c.top, "f64", SK_TYPE, c.tc.ty_f64, nil); + scopedefine(c.top, "str", SK_TYPE, c.tc.ty_str, nil); // `nil`, `true`, `false` are keywords — handled at the lex/parser // level, no symbol needed. - // `len`, `alloc`, `free` are pseudo-builtins; scope_define them so + // `len`, `alloc`, `free` are pseudo-builtins; scopedefine them so // their use sites resolve. The actual semantics live in cgen. - scope_define(c.top, "len", SK_FN, nil, nil); - scope_define(c.top, "alloc", SK_FN, nil, nil); - scope_define(c.top, "free", SK_FN, nil, nil); + scopedefine(c.top, "len", SK_FN, nil, nil); + scopedefine(c.top, "alloc", SK_FN, nil, nil); + scopedefine(c.top, "free", SK_FN, nil, nil); }; -// install_decl — install the top-level decl's name into the top scope. +// installdecl — install the top-level decl's name into the top scope. // We don't compute its type yet (that's the resolve pass) — just bind // the name so forward references resolve. -fn install_decl(c: *checker, d: *node) void = { +fn installdecl(c: *checker, d: *node) void = { if (d == nil) { return; }; let k: i32 = d.kind; let nm: str = d.str; - if (k == N_USE) { scope_define(c.top, nm, SK_USE, nil, d); return; }; - if (k == N_DEF) { scope_define(c.top, nm, SK_DEF, nil, d); return; }; - if (k == N_TYPEDECL) { scope_define(c.top, nm, SK_TYPE, nil, d); return; }; - if (k == N_FNDECL) { scope_define(c.top, nm, SK_FN, nil, d); return; }; - if (k == N_LET) { scope_define(c.top, nm, SK_VAR, nil, d); return; }; + if (k == N_USE) { scopedefine(c.top, nm, SK_USE, nil, d); return; }; + if (k == N_DEF) { scopedefine(c.top, nm, SK_DEF, nil, d); return; }; + if (k == N_TYPEDECL) { scopedefine(c.top, nm, SK_TYPE, nil, d); return; }; + if (k == N_FNDECL) { scopedefine(c.top, nm, SK_FN, nil, d); return; }; + if (k == N_LET) { scopedefine(c.top, nm, SK_VAR, nil, d); return; }; }; -// resolve_walk — recursive AST walk that, for every N_IDENT and +// resolvewalk — recursive AST walk that, for every N_IDENT and // N_TNAME seen, looks up the name and bumps the resolved/unresolved // counters. Local lets are installed in the current scope as soon as // their init/type expressions have been walked (forward use of a let // before its declaration would resolve to nothing — same semantics as // the C checker's collect-then-resolve flow within a function). -fn resolve_walk(c: *checker, n: *node) void = { +fn resolvewalk(c: *checker, n: *node) void = { if (n == nil) { return; }; let k: i32 = n.kind; @@ -3435,7 +3435,7 @@ fn resolve_walk(c: *checker, n: *node) void = { if (k == N_IDENT) { let nm: str = n.str; if (nm.len > 0) { - let s: *sym = scope_lookup(c.cur, nm); + let s: *sym = scopelookup(c.cur, nm); if (s == nil) { c.nunresolved += 1; if (c.verbose != 0) { @@ -3450,7 +3450,7 @@ fn resolve_walk(c: *checker, n: *node) void = { if (k == N_TNAME) { let nm: str = n.str; if (nm.len > 0) { - let s: *sym = scope_lookup(c.cur, nm); + let s: *sym = scopelookup(c.cur, nm); if (s == nil) { c.nunresolved += 1; if (c.verbose != 0) { @@ -3465,89 +3465,89 @@ fn resolve_walk(c: *checker, n: *node) void = { // `match (e) { case let v: T => stmt; ... }` — the binding `v` // is declared by the case arm and visible inside its body. if (k == N_MCASE) { - if (n.lhs != nil) { resolve_walk(c, n.lhs); }; + if (n.lhs != nil) { resolvewalk(c, n.lhs); }; let nm: str = n.str; if (nm.len > 0) { - scope_define(c.cur, nm, SK_VAR, nil, n); + scopedefine(c.cur, nm, SK_VAR, nil, n); }; - if (n.body != nil) { resolve_walk(c, n.body); }; + if (n.body != nil) { resolvewalk(c, n.body); }; return; }; if (k == N_DOT) { // Walk only the base; the .field name is a member, not a // free identifier. - if (n.lhs != nil) { resolve_walk(c, n.lhs); }; + if (n.lhs != nil) { resolvewalk(c, n.lhs); }; return; }; if (k == N_FIELD) { - if (n.lhs != nil) { resolve_walk(c, n.lhs); }; + if (n.lhs != nil) { resolvewalk(c, n.lhs); }; return; }; if (k == N_TFIELD) { - if (n.lhs != nil) { resolve_walk(c, n.lhs); }; + if (n.lhs != nil) { resolvewalk(c, n.lhs); }; return; }; // Walk children (mirroring ast.ww's printer descent order). - if (n.attr != nil) { resolve_walk(c, n.attr); }; - if (n.lhs != nil) { resolve_walk(c, n.lhs); }; - if (n.rhs != nil) { resolve_walk(c, n.rhs); }; - if (n.cond != nil) { resolve_walk(c, n.cond); }; - if (n.body != nil) { resolve_walk(c, n.body); }; - if (n.els != nil) { resolve_walk(c, n.els); }; + if (n.attr != nil) { resolvewalk(c, n.attr); }; + if (n.lhs != nil) { resolvewalk(c, n.lhs); }; + if (n.rhs != nil) { resolvewalk(c, n.rhs); }; + if (n.cond != nil) { resolvewalk(c, n.cond); }; + if (n.body != nil) { resolvewalk(c, n.body); }; + if (n.els != nil) { resolvewalk(c, n.els); }; if (n.list != nil) { let m: *node = n.list; for (m != nil) { - resolve_walk(c, m); + resolvewalk(c, m); m = m.next; }; }; // After walking children: a local `let X: T = init;` registers // `X` so subsequent statements can resolve it. Top-level lets - // are installed in install_decl, so this duplicate install at - // the file scope just no-ops (scope_define returns nil on dup). + // are installed in installdecl, so this duplicate install at + // the file scope just no-ops (scopedefine returns nil on dup). if (k == N_LET) { let nm: str = n.str; if (nm.len > 0) { - scope_define(c.cur, nm, SK_VAR, nil, n); + scopedefine(c.cur, nm, SK_VAR, nil, n); }; }; }; // install_param — when entering a fn body, define its params in a // fresh local scope. -fn install_params(c: *checker, params: *node) void = { +fn installparams(c: *checker, params: *node) void = { let p: *node = params; for (p != nil) { if (p.kind == N_PARAM) { let nm: str = p.str; if (nm.len > 0) { - scope_define(c.cur, nm, SK_PARAM, nil, p); + scopedefine(c.cur, nm, SK_PARAM, nil, p); }; }; p = p.next; }; }; -// resolve_fnbody — open a child scope for the fn, install its params, +// resolvefnbody — open a child scope for the fn, install its params, // then walk the body. Local lets installed by walk_stmt (a future // extension); for the current pass we just resolve-walk without // per-statement scopes. -fn resolve_fnbody(c: *checker, fnnode: *node) void = { +fn resolvefnbody(c: *checker, fnnode: *node) void = { let outer: *scope = c.cur; c.cur = newscope(c.a, c.cur); - install_params(c, fnnode.list); + installparams(c, fnnode.list); if (fnnode.body != nil) { - resolve_walk(c, fnnode.body); + resolvewalk(c, fnnode.body); }; c.cur = outer; }; -export fn check_init(c: *checker, a: *arena, tc: *tctx) void = { +export fn checkinit(c: *checker, a: *arena, tc: *tctx) void = { c.a = a; c.tc = tc; c.top = newscope(a, nil); @@ -3556,17 +3556,17 @@ export fn check_init(c: *checker, a: *arena, tc: *tctx) void = { c.nunresolved = 0; c.errs = 0; c.verbose = 0; - seed_primitives(c); + seedprimitives(c); }; -export fn check_file(c: *checker, file: *node) void = { +export fn checkfile(c: *checker, file: *node) void = { if (file == nil) { return; }; if (file.kind != N_FILE) { return; }; // Pass 1: install all top-level names. let d: *node = file.list; for (d != nil) { - install_decl(c, d); + installdecl(c, d); d = d.next; }; @@ -3575,16 +3575,16 @@ export fn check_file(c: *checker, file: *node) void = { for (d != nil) { let k: i32 = d.kind; if (k == N_FNDECL) { - if (d.lhs != nil) { resolve_walk(c, d.lhs); }; // return type - resolve_fnbody(c, d); + if (d.lhs != nil) { resolvewalk(c, d.lhs); }; // return type + resolvefnbody(c, d); } else { if (k == N_DEF) { - if (d.lhs != nil) { resolve_walk(c, d.lhs); }; - if (d.rhs != nil) { resolve_walk(c, d.rhs); }; + if (d.lhs != nil) { resolvewalk(c, d.lhs); }; + if (d.rhs != nil) { resolvewalk(c, d.rhs); }; } else { if (k == N_TYPEDECL) { - if (d.lhs != nil) { resolve_walk(c, d.lhs); }; + if (d.lhs != nil) { resolvewalk(c, d.lhs); }; } else { if (k == N_LET) { - if (d.lhs != nil) { resolve_walk(c, d.lhs); }; - if (d.rhs != nil) { resolve_walk(c, d.rhs); }; + if (d.lhs != nil) { resolvewalk(c, d.lhs); }; + if (d.rhs != nil) { resolvewalk(c, d.rhs); }; };};};}; d = d.next; }; @@ -3625,17 +3625,17 @@ use strconv; // ---- typedef alias registry ----------------------------------------- // // `type error = str;` makes `error` a struct-shape alias. We track -// alias→target so is_str_type / is_slice_type / struct_lookup can +// alias→target so isstrtype / isslicetype / structlookup can // resolve through the chain. Only direct N_TNAME aliases are mapped; -// `type p = struct {...}` is handled by collect_structs. +// `type p = struct {...}` is handled by collectstructs. -type alias_ent = struct { +type aliasent = struct { aname: str, target: *node, // the rhs type expr - aanext: *alias_ent, + aanext: *aliasent, }; -fn collect_aliases(c: *cgen, file: *node) void = { +fn collectaliases(c: *cgen, file: *node) void = { c.aliases = nil; let d: *node = file.list; for (d != nil) { @@ -3643,7 +3643,7 @@ fn collect_aliases(c: *cgen, file: *node) void = { let body: *node = d.lhs; if (body != nil) { if (body.kind != N_TSTRUCT) { - let a: *alias_ent = amalloc(c.a, 32u64): *alias_ent; + let a: *aliasent = amalloc(c.a, 32u64): *aliasent; a.aname = d.str; a.target = body; a.aanext = c.aliases; @@ -3655,8 +3655,8 @@ fn collect_aliases(c: *cgen, file: *node) void = { }; }; -fn alias_lookup(c: *cgen, name: str) *node = { - let a: *alias_ent = c.aliases; +fn aliaslookup(c: *cgen, name: str) *node = { + let a: *aliasent = c.aliases; for (a != nil) { let an: str = a.aname; if (streq(an, name)) { return a.target; }; @@ -3665,16 +3665,16 @@ fn alias_lookup(c: *cgen, name: str) *node = { return nil; }; -// resolve_type — follow typedef alias chains to a "canonical" type +// resolvetype — follow typedef alias chains to a "canonical" type // expr (str/slice/array/struct/...). Stops on cycles via depth limit. -fn resolve_type(c: *cgen, t: *node) *node = { +fn resolvetype(c: *cgen, t: *node) *node = { let cur: *node = t; let depth: i32 = 0; for (depth < 16) { if (cur == nil) { return nil; }; if (cur.kind != N_TNAME) { return cur; }; let nm: str = cur.str; - let next: *node = alias_lookup(c, nm); + let next: *node = aliaslookup(c, nm); if (next == nil) { return cur; }; cur = next; depth += 1; @@ -3685,23 +3685,23 @@ fn resolve_type(c: *cgen, t: *node) *node = { // ---- struct registry ------------------------------------------------ // // Per-file map from struct name → list of fields with computed offsets -// and sizes. Built when cg_file walks N_TYPEDECL with N_TSTRUCT lhs. +// and sizes. Built when cgfile walks N_TYPEDECL with N_TSTRUCT lhs. // N_DOT and N_ASSIGN consult this to resolve `s.field` for struct or // *struct bases. -type field_info = struct { +type fieldinfo = struct { fname: str, foff: i32, fsz: i32, tnode: *node, // the field type expr, for nested struct lookups - finext: *field_info, + finext: *fieldinfo, }; -type struct_info = struct { +type structinfo = struct { sname: str, - fields: *field_info, + fields: *fieldinfo, tot_size: i32, - sinext: *struct_info, + sinext: *structinfo, }; // ---- locals / frame -------------------------------------------------- @@ -3740,10 +3740,10 @@ type cgen = struct { strlit_seq: i32, strlits: *strlit, ffis: *ffi, - defs: *def_ent, + defs: *defent, fnrets: *fnret, - aliases: *alias_ent, - structs: *struct_info, + aliases: *aliasent, + structs: *structinfo, fn_name: str, fn_ret: *node, // declared return type of current fn (or nil) loop_top: i32, @@ -3751,26 +3751,26 @@ type cgen = struct { loop_cont_buf: *str, // stack of cont labels for continue }; -fn cgen_init(c: *cgen, a: *arena) void = { +fn cgeninit(c: *cgen, a: *arena) void = { c.a = a; c.locals = nil; c.frame = 0; c.last_was_return = 0; c.labelseq = 0; // Note: strlit_seq, strlits, ffis are *not* reset here; they - // persist across cgfn calls within one file. cg_file resets them + // persist across cgfn calls within one file. cgfile resets them // at the start of each compilation unit. c.loop_top = 0; c.loop_end_buf = amalloc(a, (LOOP_MAX: u64) * 16u64): *str; c.loop_cont_buf = amalloc(a, (LOOP_MAX: u64) * 16u64): *str; }; -// local_alloc — append a slot for `name` without dedup. Used for +// localalloc — append a slot for `name` without dedup. Used for // match-arm bindings, which C cgen allocates via cgexpr's by-value // `locals` list — so two separate matches each get fresh slots even -// when their bind names collide. scan_locals follows the same rule +// when their bind names collide. scanlocals follows the same rule // for N_MCASE. -fn local_alloc(c: *cgen, name: str, sz: i32, tnode: *node) i32 = { +fn localalloc(c: *cgen, name: str, sz: i32, tnode: *node) i32 = { let asz: i32 = sz; if (asz < 8) { asz = 8; }; if ((asz & 7) != 0) { asz = (asz + 7) & ~7; }; @@ -3785,13 +3785,13 @@ fn local_alloc(c: *cgen, name: str, sz: i32, tnode: *node) i32 = { return off; }; -fn local_add(c: *cgen, name: str, sz: i32, tnode: *node) i32 = { +fn localadd(c: *cgen, name: str, sz: i32, tnode: *node) i32 = { // Name-based slot reuse for N_LETs and params: if `name` is // already declared in this function, return its existing // offset. Mirrors C cgen (cmd/w6c/cgen.c:localoff). Two // disjoint scopes that declare the same name share one slot — // so `escape` in wwdump (three `let cp: pos;` across separate - // branches) reserves one slot, not three. scan_locals does + // branches) reserves one slot, not three. scanlocals does // the matching dedup at prologue time so the SUBQ stays in // sync. // @@ -3810,16 +3810,16 @@ fn local_add(c: *cgen, name: str, sz: i32, tnode: *node) i32 = { }; cur = cur.lnext; }; - return local_alloc(c, name, sz, tnode); + return localalloc(c, name, sz, tnode); }; -// scan_seen_mark — called by scan_locals on every let / match-bind +// scanseenmark — called by scanlocals on every let / match-bind // site. Returns true if `name` is already tracked in c.locals (so // the slot will be shared at emission time — no new frame bump). // Otherwise appends a name-only stub and returns false. Stubs are // thrown away when cgfn resets c.locals before emission. -fn scan_seen_mark(c: *cgen, name: str) bool = { - if (local_find_node(c, name) != nil) { return true; }; +fn scanseenmark(c: *cgen, name: str) bool = { + if (localfindnode(c, name) != nil) { return true; }; let l: *local = amalloc(c.a, 48u64): *local; l.name = name; l.off = 0; @@ -3829,7 +3829,7 @@ fn scan_seen_mark(c: *cgen, name: str) bool = { return false; }; -fn local_find_node(c: *cgen, name: str) *local = { +fn localfindnode(c: *cgen, name: str) *local = { let l: *local = c.locals; for (l != nil) { let ln: str = l.name; @@ -3839,7 +3839,7 @@ fn local_find_node(c: *cgen, name: str) *local = { return nil; }; -fn local_find(c: *cgen, name: str) i32 = { +fn localfind(c: *cgen, name: str) i32 = { let l: *local = c.locals; for (l != nil) { let ln: str = l.name; @@ -3859,34 +3859,34 @@ fn local_find(c: *cgen, name: str) i32 = { // ---- emit helpers --------------------------------------------------- -fn emit_line(s: str) void = { os.write(1, s.ptr, s.len: u64); }; +fn emitline(s: str) void = { os.write(1, s.ptr, s.len: u64); }; -fn emit_int(v: i64) void = { +fn emitint(v: i64) void = { let buf: [32]u8; let n: i32 = strconv.i64toa(buf[0:32], v); os.write(1, buf.ptr, n: u64); }; -fn emit_uint(v: u64) void = { +fn emituint(v: u64) void = { let buf: [32]u8; let n: i32 = strconv.u64toa(buf[0:32], v); os.write(1, buf.ptr, n: u64); }; -// emit_disp_reg — print "disp(reg)" or "(reg)" when disp == 0, the +// emitdispreg — print "disp(reg)" or "(reg)" when disp == 0, the // way Plan 9 6c/6a do. -fn emit_disp_reg(off: i64, reg: str) void = { - if (off != 0i64) { emit_int(off); }; - emit_line("("); - emit_line(reg); - emit_line(")"); +fn emitdispreg(off: i64, reg: str) void = { + if (off != 0i64) { emitint(off); }; + emitline("("); + emitline(reg); + emitline(")"); }; -// emit_off — print an integer offset, suppressing it entirely when 0. -// Use before any emit_line("(BP)...") or emit_line("(SB)...") sequence. +// emitoff — print an integer offset, suppressing it entirely when 0. +// Use before any emitline("(BP)...") or emitline("(SB)...") sequence. // Plan 9 cc convention: "(BP)" not "0(BP)". -fn emit_off(v: i64) void = { - if (v != 0i64) { emit_int(v); }; +fn emitoff(v: i64) void = { + if (v != 0i64) { emitint(v); }; }; // mklabel — fresh label "__". Returns an @@ -3923,18 +3923,18 @@ fn mklabel(c: *cgen, base: str) str = { return r; }; -fn emit_label(s: str) void = { +fn emitlabel(s: str) void = { os.write(1, s.ptr, s.len: u64); - emit_line(":\n"); + emitline(":\n"); }; // ---- string interning ------------------------------------------------ // // streq is provided by sym.ww and reused here. -// intern_strlit — return a stable label for `bytes`. Dedups by content +// internstrlit — return a stable label for `bytes`. Dedups by content // so identical literals share storage. -fn intern_strlit(c: *cgen, bytes: str) str = { +fn internstrlit(c: *cgen, bytes: str) str = { let s: *strlit = c.strlits; for (s != nil) { let bs: str = s.bytes; @@ -3964,9 +3964,9 @@ fn intern_strlit(c: *cgen, bytes: str) str = { return lab; }; -// emit_def_constants — DATA directive per top-level int-literal `def`. +// emitdefconstants — DATA directive per top-level int-literal `def`. // 8 bytes little-endian to match what the C cgen emits. -fn emit_def_constants(c: *cgen, file: *node) void = { +fn emitdefconstants(c: *cgen, file: *node) void = { let d: *node = file.list; for (d != nil) { if (d.kind == N_DEF) { @@ -3981,10 +3981,10 @@ fn emit_def_constants(c: *cgen, file: *node) void = { if (r.kind == N_NIL) { v = 0u64; ok = true; }; }; if (ok) { - emit_line("DATA "); + emitline("DATA "); let nm: str = d.str; os.write(1, nm.ptr, nm.len: u64); - emit_line("(SB),\""); + emitline("(SB),\""); let i: i32 = 0; let n: u64 = v; for (i < 8) { @@ -3992,11 +3992,11 @@ fn emit_def_constants(c: *cgen, file: *node) void = { n = n >> 8u64; // C emit_defs only special-cases " and \; // every other non-printable goes as \xHH. - if (b == 34u8) { emit_line("\\\""); } - else { if (b == 92u8) { emit_line("\\\\"); } + if (b == 34u8) { emitline("\\\""); } + else { if (b == 92u8) { emitline("\\\\"); } else { if (b < 32u8) { - emit_line("\\x"); + emitline("\\x"); let hi: u8 = b >> 4u8; let lo: u8 = b & 15u8; let bb: [2]u8; @@ -4007,7 +4007,7 @@ fn emit_def_constants(c: *cgen, file: *node) void = { os.write(1, bb.ptr, 2u64); } else { if (b >= 127u8) { - emit_line("\\x"); + emitline("\\x"); let hi: u8 = b >> 4u8; let lo: u8 = b & 15u8; let bb: [2]u8; @@ -4025,34 +4025,34 @@ fn emit_def_constants(c: *cgen, file: *node) void = { };}; i += 1; }; - emit_line("\"\n"); + emitline("\"\n"); }; }; d = d.next; }; }; -// emit_data_section — DATA directives for every interned strlit. +// emitdatasection — DATA directives for every interned strlit. // Trailing NUL appended so .ptr can be used as a C string by syscalls. -fn emit_data_section(c: *cgen) void = { +fn emitdatasection(c: *cgen) void = { let s: *strlit = c.strlits; for (s != nil) { - emit_line("DATA "); + emitline("DATA "); let lab: str = s.label; os.write(1, lab.ptr, lab.len: u64); - emit_line("(SB),\""); + emitline("(SB),\""); let bs: str = s.bytes; let i: i32 = 0; for (i < bs.len) { let b: u8 = bs[i]; - if (b == 34u8) { emit_line("\\\""); } // " - else { if (b == 92u8) { emit_line("\\\\"); } // \ - else { if (b == 10u8) { emit_line("\\n"); } - else { if (b == 9u8) { emit_line("\\t"); } - else { if (b == 13u8) { emit_line("\\r"); } + if (b == 34u8) { emitline("\\\""); } // " + else { if (b == 92u8) { emitline("\\\\"); } // \ + else { if (b == 10u8) { emitline("\\n"); } + else { if (b == 9u8) { emitline("\\t"); } + else { if (b == 13u8) { emitline("\\r"); } else { if (b < 32u8) { - emit_line("\\x"); + emitline("\\x"); let hi: u8 = b >> 4u8; let lo: u8 = b & 15u8; let bb: [2]u8; @@ -4063,7 +4063,7 @@ fn emit_data_section(c: *cgen) void = { os.write(1, bb.ptr, 2u64); } else { if (b >= 127u8) { - emit_line("\\x"); + emitline("\\x"); let hi: u8 = b >> 4u8; let lo: u8 = b & 15u8; let bb: [2]u8; @@ -4081,7 +4081,7 @@ fn emit_data_section(c: *cgen) void = { };};};};}; i += 1; }; - emit_line("\\x00\"\n"); + emitline("\\x00\"\n"); s = s.slnext; }; }; @@ -4098,7 +4098,7 @@ type fnret = struct { frnext: *fnret, }; -fn collect_fnrets(c: *cgen, file: *node) void = { +fn collectfnrets(c: *cgen, file: *node) void = { c.fnrets = nil; let d: *node = file.list; for (d != nil) { @@ -4113,7 +4113,7 @@ fn collect_fnrets(c: *cgen, file: *node) void = { }; }; -fn fnret_lookup(c: *cgen, name: str) *node = { +fn fnretlookup(c: *cgen, name: str) *node = { let f: *fnret = c.fnrets; for (f != nil) { let fn_: str = f.fname; @@ -4129,17 +4129,17 @@ fn fnret_lookup(c: *cgen, name: str) *node = { // ident reference loads it via `MOVQ NAME(SB), AX`. We collect them at // file load and consult on N_IDENT lookup. -type def_ent = struct { +type defent = struct { dname: str, - dnext: *def_ent, + dnext: *defent, }; -fn collect_defs(c: *cgen, file: *node) void = { +fn collectdefs(c: *cgen, file: *node) void = { c.defs = nil; let d: *node = file.list; for (d != nil) { if (d.kind == N_DEF) { - let e: *def_ent = amalloc(c.a, 32u64): *def_ent; + let e: *defent = amalloc(c.a, 32u64): *defent; e.dname = d.str; e.dnext = c.defs; c.defs = e; @@ -4148,8 +4148,8 @@ fn collect_defs(c: *cgen, file: *node) void = { }; }; -fn def_lookup(c: *cgen, name: str) bool = { - let e: *def_ent = c.defs; +fn deflookup(c: *cgen, name: str) bool = { + let e: *defent = c.defs; for (e != nil) { let dn: str = e.dname; if (streq(dn, name)) { return true; }; @@ -4160,7 +4160,7 @@ fn def_lookup(c: *cgen, name: str) bool = { // ---- FFI map --------------------------------------------------------- -fn ffi_collect(c: *cgen, file: *node) void = { +fn fficollect(c: *cgen, file: *node) void = { c.ffis = nil; if (file == nil) { return; }; let d: *node = file.list; @@ -4171,12 +4171,12 @@ fn ffi_collect(c: *cgen, file: *node) void = { if (a.kind == N_ATTR) { let aname: str = a.str; if (streq(aname, "symbol")) { - let sym_node: *node = a.list; - if (sym_node != nil) { - if (sym_node.kind == N_STRLIT) { + let symnode: *node = a.list; + if (symnode != nil) { + if (symnode.kind == N_STRLIT) { let f: *ffi = amalloc(c.a, 48u64): *ffi; f.ident = d.str; - f.symbol = sym_node.str; + f.symbol = symnode.str; f.fnext = c.ffis; c.ffis = f; }; @@ -4190,7 +4190,7 @@ fn ffi_collect(c: *cgen, file: *node) void = { }; }; -fn ffi_resolve(c: *cgen, ident: str) str = { +fn ffiresolve(c: *cgen, ident: str) str = { let f: *ffi = c.ffis; for (f != nil) { let id: str = f.ident; @@ -4202,7 +4202,7 @@ fn ffi_resolve(c: *cgen, ident: str) str = { // ---- ABI argreg helpers --------------------------------------------- -fn argreg_name(i: i32) str = { +fn argregname(i: i32) str = { if (i == 0) { return "DI"; }; if (i == 1) { return "SI"; }; if (i == 2) { return "DX"; }; @@ -4214,14 +4214,14 @@ fn argreg_name(i: i32) str = { // ---- expression cgen ------------------------------------------------- -// push_args_rev — recursively walks the arg list, evaluates rightmost +// pushargsrev — recursively walks the arg list, evaluates rightmost // first, and pushes. str args take two slots (ptr in AX, len in BX); // the order on the stack so a left-to-right pop into argregs lands // (ptr, len) correctly is: PUSHQ BX (top), PUSHQ AX (above) — the // pop sequence then yields AX, then BX. -fn push_args_rev(c: *cgen, arg: *node) i32 = { +fn pushargsrev(c: *cgen, arg: *node) i32 = { if (arg == nil) { return 0; }; - let rest: i32 = push_args_rev(c, arg.next); + let rest: i32 = pushargsrev(c, arg.next); // N_SLICE expression as arg: `buf[lo:hi]` builds a slice header // on the stack matching C cgen's sequence — push base, push hi, // compute lo, pop into BX/CX, derive len/ptr, push (cap, len, ptr). @@ -4229,77 +4229,77 @@ fn push_args_rev(c: *cgen, arg: *node) i32 = { let base: *node = arg.lhs; let lo: *node = arg.rhs; let hi: *node = arg.cond; - let base_local: *local = nil; + let baselocal: *local = nil; if (base != nil) { if (base.kind == N_IDENT) { let bn: str = base.str; - base_local = local_find_node(c, bn); + baselocal = localfindnode(c, bn); }; }; // base address → push - if (base_local != nil) { - let tn: *node = base_local.tnode; + if (baselocal != nil) { + let tn: *node = baselocal.tnode; if (tn != nil) { if (tn.kind == N_TARRAY) { - emit_line("\tLEAQ\t"); - emit_off(base_local.off: i64); - emit_line("(BP), AX\n"); + emitline("\tLEAQ\t"); + emitoff(baselocal.off: i64); + emitline("(BP), AX\n"); } else { - emit_line("\tMOVQ\t"); - emit_off(base_local.off: i64); - emit_line("(BP), AX\n"); + emitline("\tMOVQ\t"); + emitoff(baselocal.off: i64); + emitline("(BP), AX\n"); }; } else { - emit_line("\tMOVQ\t"); - emit_off(base_local.off: i64); - emit_line("(BP), AX\n"); + emitline("\tMOVQ\t"); + emitoff(baselocal.off: i64); + emitline("(BP), AX\n"); }; } else { cgexpr(c, base); }; - emit_line("\tPUSHQ\tAX\n"); + emitline("\tPUSHQ\tAX\n"); // hi (default base length) → push if (hi != nil) { cgexpr(c, hi); - } else { if (base_local != nil) { - let tn: *node = base_local.tnode; + } else { if (baselocal != nil) { + let tn: *node = baselocal.tnode; if (tn != nil) { if (tn.kind == N_TARRAY) { - let len_n: *node = tn.rhs; - if (len_n != nil) { - if (len_n.kind == N_INTLIT) { - emit_line("\tMOVQ\t$"); - emit_uint(len_n.uval); - emit_line(", AX\n"); + let lenn: *node = tn.rhs; + if (lenn != nil) { + if (lenn.kind == N_INTLIT) { + emitline("\tMOVQ\t$"); + emituint(lenn.uval); + emitline(", AX\n"); }; }; } else { if (tn.kind == N_TSLICE) { - emit_line("\tMOVQ\t"); - emit_off((base_local.off + 8): i64); - emit_line("(BP), AX\n"); + emitline("\tMOVQ\t"); + emitoff((baselocal.off + 8): i64); + emitline("(BP), AX\n"); } else { if (tn.kind == N_TNAME) { if (streq(tn.str, "str")) { - emit_line("\tMOVQ\t"); - emit_off((base_local.off + 8): i64); - emit_line("(BP), AX\n"); + emitline("\tMOVQ\t"); + emitoff((baselocal.off + 8): i64); + emitline("(BP), AX\n"); }; };};}; }; } else { - emit_line("\tMOVQ\t$0, AX\n"); + emitline("\tMOVQ\t$0, AX\n"); };}; - emit_line("\tPUSHQ\tAX\n"); + emitline("\tPUSHQ\tAX\n"); // lo (default 0) → AX if (lo != nil) { cgexpr(c, lo); } - else { emit_line("\tMOVQ\t$0, AX\n"); }; - emit_line("\tPOPQ\tBX\n"); // hi - emit_line("\tPOPQ\tCX\n"); // base - emit_line("\tMOVQ\tBX, DX\n"); // DX = hi - emit_line("\tSUBQ\tAX, DX\n"); // DX = hi - lo = len - emit_line("\tADDQ\tAX, CX\n"); // CX = base + lo = ptr - emit_line("\tPUSHQ\tDX\n"); // cap - emit_line("\tPUSHQ\tDX\n"); // len - emit_line("\tPUSHQ\tCX\n"); // ptr (top) + else { emitline("\tMOVQ\t$0, AX\n"); }; + emitline("\tPOPQ\tBX\n"); // hi + emitline("\tPOPQ\tCX\n"); // base + emitline("\tMOVQ\tBX, DX\n"); // DX = hi + emitline("\tSUBQ\tAX, DX\n"); // DX = hi - lo = len + emitline("\tADDQ\tAX, CX\n"); // CX = base + lo = ptr + emitline("\tPUSHQ\tDX\n"); // cap + emitline("\tPUSHQ\tDX\n"); // len + emitline("\tPUSHQ\tCX\n"); // ptr (top) return rest + 3; }; // Slice/tagged ident args: emit per-register MOVQ+PUSHQ pairs in @@ -4307,65 +4307,65 @@ fn push_args_rev(c: *cgen, arg: *node) i32 = { // into argregs lands the canonical (ptr/tag, len/v0, cap/v1). if (arg.kind == N_IDENT) { let nm: str = arg.str; - let lc: *local = local_find_node(c, nm); + let lc: *local = localfindnode(c, nm); if (lc != nil) { let off: i32 = lc.off; - if (is_slice_type(c, lc.tnode) || is_tagged_type(lc.tnode)) { - emit_line("\tMOVQ\t"); - emit_off((off + 16): i64); - emit_line("(BP), AX\n"); - emit_line("\tPUSHQ\tAX\n"); - emit_line("\tMOVQ\t"); - emit_off((off + 8): i64); - emit_line("(BP), AX\n"); - emit_line("\tPUSHQ\tAX\n"); - emit_line("\tMOVQ\t"); - emit_off(off: i64); - emit_line("(BP), AX\n"); - emit_line("\tPUSHQ\tAX\n"); + if (isslicetype(c, lc.tnode) || istaggedtype(lc.tnode)) { + emitline("\tMOVQ\t"); + emitoff((off + 16): i64); + emitline("(BP), AX\n"); + emitline("\tPUSHQ\tAX\n"); + emitline("\tMOVQ\t"); + emitoff((off + 8): i64); + emitline("(BP), AX\n"); + emitline("\tPUSHQ\tAX\n"); + emitline("\tMOVQ\t"); + emitoff(off: i64); + emitline("(BP), AX\n"); + emitline("\tPUSHQ\tAX\n"); return rest + 3; }; }; }; cgexpr(c, arg); - if (node_isslice(c, arg)) { - emit_line("\tPUSHQ\tCX\n"); - emit_line("\tPUSHQ\tBX\n"); - emit_line("\tPUSHQ\tAX\n"); + if (nodeisslice(c, arg)) { + emitline("\tPUSHQ\tCX\n"); + emitline("\tPUSHQ\tBX\n"); + emitline("\tPUSHQ\tAX\n"); return rest + 3; }; - if (node_isstr(c, arg)) { - emit_line("\tPUSHQ\tBX\n"); - emit_line("\tPUSHQ\tAX\n"); + if (nodeisstr(c, arg)) { + emitline("\tPUSHQ\tBX\n"); + emitline("\tPUSHQ\tAX\n"); return rest + 2; }; - emit_line("\tPUSHQ\tAX\n"); + emitline("\tPUSHQ\tAX\n"); return rest + 1; }; -fn node_isslice(c: *cgen, n: *node) bool = { +fn nodeisslice(c: *cgen, n: *node) bool = { if (n == nil) { return false; }; let k: i32 = n.kind; if (k == N_IDENT) { let nm: str = n.str; - let lc: *local = local_find_node(c, nm); - if (lc != nil) { return is_slice_type(c, lc.tnode); }; + let lc: *local = localfindnode(c, nm); + if (lc != nil) { return isslicetype(c, lc.tnode); }; return false; }; if (k == N_SLICE) { return true; }; return false; }; -// node_isstr — best-effort surface check: does this expression +// nodeisstr — best-effort surface check: does this expression // evaluate to a str value? Used to drive the call-arg push convention // (str args take two slots: ptr + len). -fn node_isstr(c: *cgen, n: *node) bool = { +fn nodeisstr(c: *cgen, n: *node) bool = { if (n == nil) { return false; }; let k: i32 = n.kind; if (k == N_STRLIT) { return true; }; if (k == N_IDENT) { let nm: str = n.str; - let lc: *local = local_find_node(c, nm); + let lc: *local = localfindnode(c, nm); if (lc != nil) { let tn: *node = lc.tnode; if (tn != nil) { @@ -4382,8 +4382,8 @@ fn node_isstr(c: *cgen, n: *node) bool = { if (callee != nil) { if (callee.kind == N_IDENT) { let cnm: str = callee.str; - let rt: *node = fnret_lookup(c, cnm); - return is_str_type(c, rt); + let rt: *node = fnretlookup(c, cnm); + return isstrtype(c, rt); }; }; return false; @@ -4399,7 +4399,7 @@ fn node_isstr(c: *cgen, n: *node) bool = { let sname: str; sname.ptr = nil; sname.len = 0; if (base.kind == N_IDENT) { - let lc: *local = local_find_node(c, base.str); + let lc: *local = localfindnode(c, base.str); if (lc != nil) { let tn: *node = lc.tnode; let lkind: i32 = -1; @@ -4413,23 +4413,23 @@ fn node_isstr(c: *cgen, n: *node) bool = { }; }; }; - // Chained dot (`p.foo.bar`): use dot_inner_struct_ptr + // Chained dot (`p.foo.bar`): use dotinnerstructptr // to resolve the inner chain to the *struct it lands // on, then look up `fld` in that struct. if (base.kind == N_DOT) { - let inner_t: *node = dot_inner_struct_ptr(c, base); - if (inner_t != nil) { - if (inner_t.kind == N_TNAME) { sname = inner_t.str; }; + let innert: *node = dotinnerstructptr(c, base); + if (innert != nil) { + if (innert.kind == N_TNAME) { sname = innert.str; }; }; }; if (sname.len > 0) { - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fld)) { - return is_str_type(c, fi.tnode); + return isstrtype(c, fi.tnode); }; fi = fi.finext; }; @@ -4439,13 +4439,13 @@ fn node_isstr(c: *cgen, n: *node) bool = { return false; }; if (k == N_CAST) { - return is_str_type(c, n.rhs); + return isstrtype(c, n.rhs); }; return false; }; -// type_name_isunsigned — true for u8/u16/u32/u64/uint/uintptr. -fn type_name_isunsigned(nm: str) bool = { +// typenameisunsigned — true for u8/u16/u32/u64/uint/uintptr. +fn typenameisunsigned(nm: str) bool = { if (streq(nm, "u8")) { return true; }; if (streq(nm, "u16")) { return true; }; if (streq(nm, "u32")) { return true; }; @@ -4455,21 +4455,21 @@ fn type_name_isunsigned(nm: str) bool = { return false; }; -// type_node_isunsigned — recurse through TNAME / TPTR / TSLICE etc. -fn type_node_isunsigned(t: *node) bool = { +// typenodeisunsigned — recurse through TNAME / TPTR / TSLICE etc. +fn typenodeisunsigned(t: *node) bool = { if (t == nil) { return false; }; - if (t.kind == N_TNAME) { return type_name_isunsigned(t.str); }; + if (t.kind == N_TNAME) { return typenameisunsigned(t.str); }; return false; }; -// type_is_8byte_primitive — does this type take exactly one 8-byte +// typeis8byteprimitive — does this type take exactly one 8-byte // slot (pointer / fn-ptr / 64-bit int / chan / scalar primitive // padded up to 8) rather than a wider aggregate? Used by N_LET // zero-init to mirror C cgen's "only zero if sz == 8 at the type // level" rule. Strings (16), slices (24), tagged unions (>=16), // tuples (16), structs (varies), arrays — all fall through to // false here even when their *slot* rounds up to 8. -fn type_is_8byte_primitive(c: *cgen, t: *node) bool = { +fn typeis8byteprimitive(c: *cgen, t: *node) bool = { if (t == nil) { return false; }; let k: i32 = t.kind; if (k == N_TPTR) { return true; }; @@ -4483,17 +4483,17 @@ fn type_is_8byte_primitive(c: *cgen, t: *node) bool = { let nm: str = t.str; if (streq(nm, "str")) { return false; }; // Struct alias: not a primitive even if the slot is 8B. - if (struct_lookup(c, nm) != nil) { return false; }; + if (structlookup(c, nm) != nil) { return false; }; // Primitive (i8/u8/.../i64/u64/bool/rune/f32/f64/int/...). // All of these get slot-padded to 8 and zero-init in C. - if (prim_size(nm) > 0) { return true; }; + if (primsize(nm) > 0) { return true; }; return false; }; return false; }; -// type_name_issigned — true for i8/i16/i32/i64/int/rune. -fn type_name_issigned(nm: str) bool = { +// typenameissigned — true for i8/i16/i32/i64/int/rune. +fn typenameissigned(nm: str) bool = { if (streq(nm, "i8")) { return true; }; if (streq(nm, "i16")) { return true; }; if (streq(nm, "i32")) { return true; }; @@ -4503,11 +4503,11 @@ fn type_name_issigned(nm: str) bool = { return false; }; -// field_load_op — pick the load instruction for a non-str struct +// fieldloadop — pick the load instruction for a non-str struct // field by its declared size + signedness. Mirrors the C cgen op // dispatch (MOVZBQ for u8/bool/i8, MOVSXD for i32, MOVL for u32, MOVQ // for 8-byte). f might be nil for fields outside our struct registry. -fn field_load_op(f: *field_info) str = { +fn fieldloadop(f: *fieldinfo) str = { if (f == nil) { return "MOVQ"; }; let sz: i32 = f.fsz; if (sz == 1) { return "MOVZBQ"; }; @@ -4515,7 +4515,7 @@ fn field_load_op(f: *field_info) str = { let t: *node = f.tnode; if (t != nil) { if (t.kind == N_TNAME) { - if (type_name_issigned(t.str)) { return "MOVSXD"; }; + if (typenameissigned(t.str)) { return "MOVSXD"; }; }; }; return "MOVL"; @@ -4523,9 +4523,9 @@ fn field_load_op(f: *field_info) str = { return "MOVQ"; }; -// field_store_op — pick the store instruction for a non-str struct +// fieldstoreop — pick the store instruction for a non-str struct // field by its declared size. MOVB for 1, MOVL for 4, MOVQ for 8. -fn field_store_op(f: *field_info) str = { +fn fieldstoreop(f: *fieldinfo) str = { if (f == nil) { return "MOVQ"; }; let sz: i32 = f.fsz; if (sz == 1) { return "MOVB"; }; @@ -4533,11 +4533,11 @@ fn field_store_op(f: *field_info) str = { return "MOVQ"; }; -// index_base_esz — element size for `arr[i]` where the base is a +// indexbaseesz — element size for `arr[i]` where the base is a // chained-dot pseudo-field `s.ptr` (s being str/*str/slice/*slice). // For str the element is one byte; for `[]T` / `*[]T` we drill into // the slice element type. -fn index_base_esz(c: *cgen, base: *node) i32 = { +fn indexbaseesz(c: *cgen, base: *node) i32 = { if (base == nil) { return 8; }; if (base.kind != N_DOT) { return 8; }; let fld: str = base.str; @@ -4545,20 +4545,20 @@ fn index_base_esz(c: *cgen, base: *node) i32 = { if (inner == nil) { return 8; }; if (inner.kind != N_IDENT) { return 8; }; let nm: str = inner.str; - let lc: *local = local_find_node(c, nm); + let lc: *local = localfindnode(c, nm); if (lc == nil) { return 8; }; let tn: *node = lc.tnode; if (tn == nil) { return 8; }; // `.ptr` pseudo-field on str/slice → element of the str/slice. if (streq(fld, "ptr")) { - let inner_t: *node = tn; - if (tn.kind == N_TPTR) { inner_t = tn.lhs; }; - if (inner_t == nil) { return 8; }; - if (inner_t.kind == N_TNAME) { - if (streq(inner_t.str, "str")) { return 1; }; + let innert: *node = tn; + if (tn.kind == N_TPTR) { innert = tn.lhs; }; + if (innert == nil) { return 8; }; + if (innert.kind == N_TNAME) { + if (streq(innert.str, "str")) { return 1; }; }; - if (inner_t.kind == N_TSLICE) { return elem_size_of(inner_t); }; + if (innert.kind == N_TSLICE) { return elemsizeof(innert); }; return 8; }; @@ -4574,9 +4574,9 @@ fn index_base_esz(c: *cgen, base: *node) i32 = { }; }; if (sname.len == 0) { return 8; }; - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si == nil) { return 8; }; - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fld)) { @@ -4587,13 +4587,13 @@ fn index_base_esz(c: *cgen, base: *node) i32 = { if (elem != nil) { if (elem.kind == N_TNAME) { if (streq(elem.str, "str")) { return 16; }; - let ps: i32 = prim_size(elem.str); + let ps: i32 = primsize(elem.str); if (ps > 0) { return ps; }; }; }; return 8; }; - if (ft.kind == N_TSLICE) { return elem_size_of(ft); }; + if (ft.kind == N_TSLICE) { return elemsizeof(ft); }; // str-typed field: indexing yields one byte // (`n.s[i]` where .s is str — matches C cgen's // MOVZBQ for byte indexing). @@ -4607,7 +4607,7 @@ fn index_base_esz(c: *cgen, base: *node) i32 = { return 8; }; -// dot_inner_struct_ptr — for an N_DOT whose lhs is a chain of dots +// dotinnerstructptr — for an N_DOT whose lhs is a chain of dots // or an N_IDENT, walk the chain and return the N_TNAME tnode of the // struct that the chain dereferences to (i.e., for `r.sym` where // .sym is *lsym, return N_TNAME("lsym")). Returns nil if the chain @@ -4615,7 +4615,7 @@ fn index_base_esz(c: *cgen, base: *node) i32 = { // // Used by the chained-DOT cgen path so `r.sym.val` knows the outer // is a field of `lsym`. -fn dot_inner_struct_ptr(c: *cgen, n: *node) *node = { +fn dotinnerstructptr(c: *cgen, n: *node) *node = { if (n == nil) { return nil; }; if (n.kind != N_DOT) { return nil; }; let base: *node = n.lhs; @@ -4623,25 +4623,25 @@ fn dot_inner_struct_ptr(c: *cgen, n: *node) *node = { if (base == nil) { return nil; }; // Resolve base's struct tnode. - let base_t: *node = nil; + let baset: *node = nil; if (base.kind == N_IDENT) { - let lc: *local = local_find_node(c, base.str); + let lc: *local = localfindnode(c, base.str); if (lc == nil) { return nil; }; let tn: *node = lc.tnode; if (tn == nil) { return nil; }; // base could be either struct-by-value (N_TNAME) or *struct (N_TPTR). - if (tn.kind == N_TNAME) { base_t = tn; }; - if (tn.kind == N_TPTR) { base_t = tn.lhs; }; + if (tn.kind == N_TNAME) { baset = tn; }; + if (tn.kind == N_TPTR) { baset = tn.lhs; }; } else { if (base.kind == N_DOT) { - base_t = dot_inner_struct_ptr(c, base); + baset = dotinnerstructptr(c, base); };}; - if (base_t == nil) { return nil; }; - if (base_t.kind != N_TNAME) { return nil; }; + if (baset == nil) { return nil; }; + if (baset.kind != N_TNAME) { return nil; }; // Look up the struct, find the field, return the field's *struct. - let si: *struct_info = struct_lookup(c, base_t.str); + let si: *structinfo = structlookup(c, baset.str); if (si == nil) { return nil; }; - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { if (streq(fi.fname, fld)) { let ft: *node = fi.tnode; @@ -4657,10 +4657,10 @@ fn dot_inner_struct_ptr(c: *cgen, n: *node) *node = { return nil; }; -// elem_size_of — given the type node of an indexable (`*T`, `[]T`, +// elemsizeof — given the type node of an indexable (`*T`, `[]T`, // `[N]T`, `str`), return the byte size of one element (1 for u8/i8/ // bool/str-byte, 8 otherwise — same shape as C cgen's esz fallback). -fn elem_size_of(t: *node) i32 = { +fn elemsizeof(t: *node) i32 = { if (t == nil) { return 1; }; let k: i32 = t.kind; let elem: *node = nil; @@ -4671,22 +4671,22 @@ fn elem_size_of(t: *node) i32 = { let nm: str = t.str; if (streq(nm, "str")) { return 1; }; // Indexing a primitive name (rare): element size = the prim. - let ps: i32 = prim_size(nm); + let ps: i32 = primsize(nm); if (ps > 0) { return ps; }; return 1; }; if (elem == nil) { return 1; }; if (elem.kind == N_TNAME) { let nm: str = elem.str; - // str element is 16B (ptr+len). prim_size returns 0 for it. + // str element is 16B (ptr+len). primsize returns 0 for it. if (streq(nm, "str")) { return 16; }; - let ps: i32 = prim_size(nm); + let ps: i32 = primsize(nm); if (ps > 0) { return ps; }; }; return 8; }; -// node_isunsigned — best-effort cgen-time inference from the AST. We +// nodeisunsigned — best-effort cgen-time inference from the AST. We // don't have a typed AST yet, so we walk surface nodes: // N_INTLIT — never marked unsigned (no tsuffix plumbing yet) // N_IDENT — look up the local's declared type @@ -4696,13 +4696,13 @@ fn elem_size_of(t: *node) i32 = { // // Conservative: if we can't tell, return false (signed). The cost of // being wrong here is byte-different asm vs C, not bad runtime. -fn node_isunsigned(c: *cgen, n: *node) bool = { +fn nodeisunsigned(c: *cgen, n: *node) bool = { if (n == nil) { return false; }; let k: i32 = n.kind; if (k == N_IDENT) { let nm: str = n.str; - let lc: *local = local_find_node(c, nm); - if (lc != nil) { return type_node_isunsigned(lc.tnode); }; + let lc: *local = localfindnode(c, nm); + if (lc != nil) { return typenodeisunsigned(lc.tnode); }; return false; }; if (k == N_DOT) { @@ -4711,7 +4711,7 @@ fn node_isunsigned(c: *cgen, n: *node) bool = { if (base != nil) { if (base.kind == N_IDENT) { let bn: str = base.str; - let lc: *local = local_find_node(c, bn); + let lc: *local = localfindnode(c, bn); if (lc != nil) { let tn: *node = lc.tnode; let lkind: i32 = -1; @@ -4726,13 +4726,13 @@ fn node_isunsigned(c: *cgen, n: *node) bool = { }; if (lkind == N_TNAME) { sname = tn.str; }; if (sname.len > 0) { - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fld)) { - return type_node_isunsigned(fi.tnode); + return typenodeisunsigned(fi.tnode); }; fi = fi.finext; }; @@ -4743,12 +4743,12 @@ fn node_isunsigned(c: *cgen, n: *node) bool = { }; return false; }; - if (k == N_CAST) { return type_node_isunsigned(n.rhs); }; + if (k == N_CAST) { return typenodeisunsigned(n.rhs); }; if (k == N_BIN) { - if (node_isunsigned(c, n.lhs)) { return true; }; - return node_isunsigned(c, n.rhs); + if (nodeisunsigned(c, n.lhs)) { return true; }; + return nodeisunsigned(c, n.rhs); }; - if (k == N_UN) { return node_isunsigned(c, n.lhs); }; + if (k == N_UN) { return nodeisunsigned(c, n.lhs); }; // N_INDEX: `p[i]` is unsigned iff p's element type is unsigned. // Walks the base local's declared type and pulls the element // out — *u8 → u8, [N]u32 → u32, []u64 → u64. Without this the @@ -4758,7 +4758,7 @@ fn node_isunsigned(c: *cgen, n: *node) bool = { let base: *node = n.lhs; if (base != nil) { if (base.kind == N_IDENT) { - let lc: *local = local_find_node(c, base.str); + let lc: *local = localfindnode(c, base.str); if (lc != nil) { let tn: *node = lc.tnode; if (tn != nil) { @@ -4767,7 +4767,7 @@ fn node_isunsigned(c: *cgen, n: *node) bool = { if (tn.kind == N_TARRAY) { elem = tn.lhs; }; if (tn.kind == N_TSLICE) { elem = tn.lhs; }; if (elem != nil) { - return type_node_isunsigned(elem); + return typenodeisunsigned(elem); }; }; }; @@ -4787,86 +4787,86 @@ fn cgexpr(c: *cgen, n: *node) void = { // `$%lld` so 64-bit constants with bit 63 set show up as // negative — e.g. FNV-1a's offset basis prints as // $-3750763034362895579, not $14695981039346656037. - emit_line("\tMOVQ\t$"); - emit_int(n.uval: i64); - emit_line(", AX\n"); + emitline("\tMOVQ\t$"); + emitint(n.uval: i64); + emitline(", AX\n"); return; }; if (k == N_RUNELIT) { - emit_line("\tMOVQ\t$"); - emit_int(n.uval: i64); - emit_line(", AX\n"); + emitline("\tMOVQ\t$"); + emitint(n.uval: i64); + emitline(", AX\n"); return; }; if (k == N_STRLIT) { // Result is the (ptr, len) pair: ptr in AX, len in BX. Call // sites that expect a str arg pick these up directly. let nstr: str = n.str; - let lab: str = intern_strlit(c, nstr); - emit_line("\tLEAQ\t"); + let lab: str = internstrlit(c, nstr); + emitline("\tLEAQ\t"); os.write(1, lab.ptr, lab.len: u64); - emit_line("(SB), AX\n"); - emit_line("\tMOVQ\t$"); - emit_int(nstr.len: i64); - emit_line(", BX\n"); + emitline("(SB), AX\n"); + emitline("\tMOVQ\t$"); + emitint(nstr.len: i64); + emitline(", BX\n"); return; }; if (k == N_TRUE) { - emit_line("\tMOVQ\t$1, AX\n"); + emitline("\tMOVQ\t$1, AX\n"); return; }; if (k == N_FALSE) { - emit_line("\tMOVQ\t$0, AX\n"); + emitline("\tMOVQ\t$0, AX\n"); return; }; if (k == N_NIL) { - emit_line("\tMOVQ\t$0, AX\n"); + emitline("\tMOVQ\t$0, AX\n"); return; }; if (k == N_IDENT) { let nm: str = n.str; - let lc: *local = local_find_node(c, nm); + let lc: *local = localfindnode(c, nm); if (lc != nil) { let off: i32 = lc.off; - emit_line("\tMOVQ\t"); - emit_off(off: i64); - emit_line("(BP), AX\n"); + emitline("\tMOVQ\t"); + emitoff(off: i64); + emitline("(BP), AX\n"); // str local: also load the len half into BX. - if (is_str_type(c, lc.tnode)) { - emit_line("\tMOVQ\t"); - emit_off((off + 8): i64); - emit_line("(BP), BX\n"); + if (isstrtype(c, lc.tnode)) { + emitline("\tMOVQ\t"); + emitoff((off + 8): i64); + emitline("(BP), BX\n"); }; // slice local: load (ptr, len, cap) into (AX, BX, CX). - if (is_slice_type(c, lc.tnode)) { - emit_line("\tMOVQ\t"); - emit_off((off + 8): i64); - emit_line("(BP), BX\n"); - emit_line("\tMOVQ\t"); - emit_off((off + 16): i64); - emit_line("(BP), CX\n"); + if (isslicetype(c, lc.tnode)) { + emitline("\tMOVQ\t"); + emitoff((off + 8): i64); + emitline("(BP), BX\n"); + emitline("\tMOVQ\t"); + emitoff((off + 16): i64); + emitline("(BP), CX\n"); }; return; }; // Top-level `def` constant — load from its DATA symbol. - if (def_lookup(c, nm)) { - emit_line("\tMOVQ\t"); + if (deflookup(c, nm)) { + emitline("\tMOVQ\t"); os.write(1, nm.ptr, nm.len: u64); - emit_line("(SB), AX\n"); + emitline("(SB), AX\n"); return; }; // Fn-name used as a value (e.g. `let f = some_fn;` or // `... = some_fn;`). LEAQ the symbol address into AX — - // resolved through ffi_resolve so a body-less FFI binding + // resolved through ffiresolve so a body-less FFI binding // emits the C symbol it was declared with via @symbol(), // not the ww-side ident. - let rt: *node = fnret_lookup(c, nm); + let rt: *node = fnretlookup(c, nm); if (rt != nil) { - let resolved: str = ffi_resolve(c, nm); - emit_line("\tLEAQ\t"); + let resolved: str = ffiresolve(c, nm); + emitline("\tLEAQ\t"); os.write(1, resolved.ptr, resolved.len: u64); - emit_line("(SB), AX\n"); + emitline("(SB), AX\n"); return; }; return; @@ -4879,61 +4879,61 @@ fn cgexpr(c: *cgen, n: *node) void = { let base: *node = n.lhs; let idx: *node = n.rhs; let esz: i32 = 8; - let base_local: *local = nil; + let baselocal: *local = nil; if (base != nil) { if (base.kind == N_IDENT) { let bn: str = base.str; - base_local = local_find_node(c, bn); - if (base_local != nil) { esz = elem_size_of(base_local.tnode); }; + baselocal = localfindnode(c, bn); + if (baselocal != nil) { esz = elemsizeof(baselocal.tnode); }; } else { if (base.kind == N_DOT) { - esz = index_base_esz(c, base); + esz = indexbaseesz(c, base); };}; }; cgexpr(c, idx); if (esz > 1) { - emit_line("\tMOVQ\t$"); - emit_int(esz: i64); - emit_line(", CX\n"); - emit_line("\tIMULQ\tCX, AX\n"); + emitline("\tMOVQ\t$"); + emitint(esz: i64); + emitline(", CX\n"); + emitline("\tIMULQ\tCX, AX\n"); }; - if (base_local != nil) { - let tn: *node = base_local.tnode; - let is_array: bool = false; - if (tn != nil) { if (tn.kind == N_TARRAY) { is_array = true; }; }; - if (is_array) { - emit_line("\tLEAQ\t"); - emit_off(base_local.off: i64); - emit_line("(BP), BX\n"); + if (baselocal != nil) { + let tn: *node = baselocal.tnode; + let isarray: bool = false; + if (tn != nil) { if (tn.kind == N_TARRAY) { isarray = true; }; }; + if (isarray) { + emitline("\tLEAQ\t"); + emitoff(baselocal.off: i64); + emitline("(BP), BX\n"); } else { - emit_line("\tMOVQ\t"); - emit_off(base_local.off: i64); - emit_line("(BP), BX\n"); + emitline("\tMOVQ\t"); + emitoff(baselocal.off: i64); + emitline("(BP), BX\n"); }; - emit_line("\tADDQ\tAX, BX\n"); + emitline("\tADDQ\tAX, BX\n"); // str element (16B): load (ptr, len) into (AX, BX) so // the value flows through the str-rhs convention. if (esz == 16) { - emit_line("\tMOVQ\t8(BX), CX\n"); - emit_line("\tMOVQ\t(BX), AX\n"); - emit_line("\tMOVQ\tCX, BX\n"); + emitline("\tMOVQ\t8(BX), CX\n"); + emitline("\tMOVQ\t(BX), AX\n"); + emitline("\tMOVQ\tCX, BX\n"); return; }; - if (esz == 1) { emit_line("\tMOVZBQ\t(BX), AX\n"); } - else { emit_line("\tMOVQ\t(BX), AX\n"); }; + if (esz == 1) { emitline("\tMOVZBQ\t(BX), AX\n"); } + else { emitline("\tMOVQ\t(BX), AX\n"); }; return; }; // Generic fallback when base isn't a plain ident. - emit_line("\tPUSHQ\tAX\n"); + emitline("\tPUSHQ\tAX\n"); cgexpr(c, base); - emit_line("\tPOPQ\tBX\n"); - emit_line("\tADDQ\tBX, AX\n"); + emitline("\tPOPQ\tBX\n"); + emitline("\tADDQ\tBX, AX\n"); if (esz == 16) { - emit_line("\tMOVQ\t8(AX), BX\n"); - emit_line("\tMOVQ\t(AX), AX\n"); + emitline("\tMOVQ\t8(AX), BX\n"); + emitline("\tMOVQ\t(AX), AX\n"); return; }; - if (esz == 1) { emit_line("\tMOVZBQ\t(AX), AX\n"); } - else { emit_line("\tMOVQ\t(AX), AX\n"); }; + if (esz == 1) { emitline("\tMOVZBQ\t(AX), AX\n"); } + else { emitline("\tMOVQ\t(AX), AX\n"); }; return; }; @@ -4945,14 +4945,14 @@ fn cgexpr(c: *cgen, n: *node) void = { // (`case let v: T =>`) get a fresh local slot loaded from // slot+8 (and slot+16 for str-typed payload). let scrut: *node = n.lhs; - let scrut_off: i32 = 0; - let scrut_t: *node = nil; + let scrutoff: i32 = 0; + let scrutt: *node = nil; if (scrut != nil) { if (scrut.kind == N_IDENT) { - let lc: *local = local_find_node(c, scrut.str); + let lc: *local = localfindnode(c, scrut.str); if (lc != nil) { - scrut_off = lc.off; - scrut_t = resolve_type(c, lc.tnode); + scrutoff = lc.off; + scrutt = resolvetype(c, lc.tnode); }; }; }; @@ -4965,17 +4965,17 @@ fn cgexpr(c: *cgen, n: *node) void = { // (no pattern) skips the tag check. if (pat != nil) { let want: i32 = 0; - if (scrut_t != nil) { - if (scrut_t.kind == N_TTAGGED) { - let pat_name: str; - pat_name.ptr = nil; pat_name.len = 0; - if (pat.kind == N_TNAME) { pat_name = pat.str; }; - let v: *node = scrut_t.list; + if (scrutt != nil) { + if (scrutt.kind == N_TTAGGED) { + let patname: str; + patname.ptr = nil; patname.len = 0; + if (pat.kind == N_TNAME) { patname = pat.str; }; + let v: *node = scrutt.list; let idx: i32 = 0; let found: bool = false; for (v != nil) { if (v.kind == N_TNAME) { - if (streq(v.str, pat_name)) { + if (streq(v.str, patname)) { want = idx; found = true; v = nil; @@ -4989,52 +4989,52 @@ fn cgexpr(c: *cgen, n: *node) void = { if (!found) { want = 0; }; }; }; - emit_line("\tMOVQ\t"); - emit_off(scrut_off: i64); - emit_line("(BP), AX\n"); - emit_line("\tCMPQ\t$"); - emit_int(want: i64); - emit_line(", AX\n"); - emit_line("\tJNE\t"); - emit_line(nxt); - emit_line("\n"); + emitline("\tMOVQ\t"); + emitoff(scrutoff: i64); + emitline("(BP), AX\n"); + emitline("\tCMPQ\t$"); + emitint(want: i64); + emitline(", AX\n"); + emitline("\tJNE\t"); + emitline(nxt); + emitline("\n"); }; // Bind `let v: T` from the slot, if requested. let bn: str = cs.str; if (bn.len > 0) { if (pat != nil) { let bsz: i32 = 8; - if (is_str_type(c, pat)) { bsz = 16; }; - // local_alloc (not local_add): match-arm + if (isstrtype(c, pat)) { bsz = 16; }; + // localalloc (not localadd): match-arm // binds don't dedup with same-named binds // in *other* matches, since C's cgexpr // allocates a fresh slot per match expr. - let voff: i32 = local_alloc(c, bn, bsz, pat); - emit_line("\tMOVQ\t"); - emit_off((scrut_off + 8): i64); - emit_line("(BP), AX\n"); - emit_line("\tMOVQ\tAX, "); - emit_off(voff: i64); - emit_line("(BP)\n"); + let voff: i32 = localalloc(c, bn, bsz, pat); + emitline("\tMOVQ\t"); + emitoff((scrutoff + 8): i64); + emitline("(BP), AX\n"); + emitline("\tMOVQ\tAX, "); + emitoff(voff: i64); + emitline("(BP)\n"); if (bsz == 16) { - emit_line("\tMOVQ\t"); - emit_off((scrut_off + 16): i64); - emit_line("(BP), AX\n"); - emit_line("\tMOVQ\tAX, "); - emit_off((voff + 8): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\t"); + emitoff((scrutoff + 16): i64); + emitline("(BP), AX\n"); + emitline("\tMOVQ\tAX, "); + emitoff((voff + 8): i64); + emitline("(BP)\n"); }; }; }; // Body. Match arms are statements; we cgstmt them. if (cs.body != nil) { cgstmt(c, cs.body); }; - emit_line("\tJMP\t"); - emit_line(endl); - emit_line("\n"); - emit_label(nxt); + emitline("\tJMP\t"); + emitline(endl); + emitline("\n"); + emitlabel(nxt); cs = cs.next; }; - emit_label(endl); + emitlabel(endl); return; }; @@ -5054,7 +5054,7 @@ fn cgexpr(c: *cgen, n: *node) void = { if (lhs != nil) { if (lhs.kind == N_IDENT) { let nm: str = lhs.str; - let lc: *local = local_find_node(c, nm); + let lc: *local = localfindnode(c, nm); if (lc != nil) { let tn: *node = lc.tnode; let lkind: i32 = -1; @@ -5070,33 +5070,33 @@ fn cgexpr(c: *cgen, n: *node) void = { }; }; if (sname.len > 0) { - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fld)) { // str field via *struct: load len into a // scratch first (so loading ptr into AX // last leaves (AX=ptr, BX=len)). - emit_line("\tMOVQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), BX\n"); - if (is_str_type(c, fi.tnode)) { - emit_line("\tMOVQ\t"); - emit_disp_reg((fi.foff + 8): i64, "BX"); - emit_line(", CX\n"); - emit_line("\tMOVQ\t"); - emit_disp_reg(fi.foff: i64, "BX"); - emit_line(", AX\n"); - emit_line("\tMOVQ\tCX, BX\n"); + emitline("\tMOVQ\t"); + emitoff(lc.off: i64); + emitline("(BP), BX\n"); + if (isstrtype(c, fi.tnode)) { + emitline("\tMOVQ\t"); + emitdispreg((fi.foff + 8): i64, "BX"); + emitline(", CX\n"); + emitline("\tMOVQ\t"); + emitdispreg(fi.foff: i64, "BX"); + emitline(", AX\n"); + emitline("\tMOVQ\tCX, BX\n"); } else { - let op: str = field_load_op(fi); - emit_line("\t"); - emit_line(op); - emit_line("\t"); - emit_disp_reg(fi.foff: i64, "BX"); - emit_line(", AX\n"); + let op: str = fieldloadop(fi); + emitline("\t"); + emitline(op); + emitline("\t"); + emitdispreg(fi.foff: i64, "BX"); + emitline(", AX\n"); }; return; }; @@ -5108,28 +5108,28 @@ fn cgexpr(c: *cgen, n: *node) void = { // Direct struct local: field load at off+foff. if (lkind == N_TNAME) { let sname: str = tn.str; - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fld)) { // str field: load both halves so chained // `.ptr` / `.len` see (AX=ptr, BX=len). - if (is_str_type(c, fi.tnode)) { - emit_line("\tMOVQ\t"); - emit_off((lc.off + fi.foff): i64); - emit_line("(BP), AX\n"); - emit_line("\tMOVQ\t"); - emit_off((lc.off + fi.foff + 8): i64); - emit_line("(BP), BX\n"); + if (isstrtype(c, fi.tnode)) { + emitline("\tMOVQ\t"); + emitoff((lc.off + fi.foff): i64); + emitline("(BP), AX\n"); + emitline("\tMOVQ\t"); + emitoff((lc.off + fi.foff + 8): i64); + emitline("(BP), BX\n"); } else { - let op: str = field_load_op(fi); - emit_line("\t"); - emit_line(op); - emit_line("\t"); - emit_off((lc.off + fi.foff): i64); - emit_line("(BP), AX\n"); + let op: str = fieldloadop(fi); + emitline("\t"); + emitline(op); + emitline("\t"); + emitoff((lc.off + fi.foff): i64); + emitline("(BP), AX\n"); }; return; }; @@ -5142,20 +5142,20 @@ fn cgexpr(c: *cgen, n: *node) void = { // count (immediate). if (lkind == N_TARRAY) { if (streq(fld, "ptr")) { - emit_line("\tLEAQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), AX\n"); + emitline("\tLEAQ\t"); + emitoff(lc.off: i64); + emitline("(BP), AX\n"); return; }; if (streq(fld, "len")) { - let len_n: *node = tn.rhs; + let lenn: *node = tn.rhs; let alen: i64 = 0i64; - if (len_n != nil) { - if (len_n.kind == N_INTLIT) { alen = len_n.uval: i64; }; + if (lenn != nil) { + if (lenn.kind == N_INTLIT) { alen = lenn.uval: i64; }; }; - emit_line("\tMOVQ\t$"); - emit_int(alen); - emit_line(", AX\n"); + emitline("\tMOVQ\t$"); + emitint(alen); + emitline(", AX\n"); return; }; }; @@ -5171,26 +5171,26 @@ fn cgexpr(c: *cgen, n: *node) void = { // pointed-to header. C cgen does the same. if (lkind == N_TPTR) { let inner: *node = tn.lhs; - let inner_kind: i32 = -1; - if (inner != nil) { inner_kind = inner.kind; }; - let inner_str: bool = false; - if (inner_kind == N_TNAME) { - if (streq(inner.str, "str")) { inner_str = true; }; + let innerkind: i32 = -1; + if (inner != nil) { innerkind = inner.kind; }; + let innerstr: bool = false; + if (innerkind == N_TNAME) { + if (streq(inner.str, "str")) { innerstr = true; }; }; - if (inner_kind == N_TSLICE) { inner_str = true; }; - if (inner_str) { - emit_line("\tMOVQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), BX\n"); - emit_line("\tMOVQ\t"); - emit_disp_reg(delta: i64, "BX"); - emit_line(", AX\n"); + if (innerkind == N_TSLICE) { innerstr = true; }; + if (innerstr) { + emitline("\tMOVQ\t"); + emitoff(lc.off: i64); + emitline("(BP), BX\n"); + emitline("\tMOVQ\t"); + emitdispreg(delta: i64, "BX"); + emitline(", AX\n"); return; }; }; - emit_line("\tMOVQ\t"); - emit_off((lc.off + delta): i64); - emit_line("(BP), AX\n"); + emitline("\tMOVQ\t"); + emitoff((lc.off + delta): i64); + emitline("(BP), AX\n"); return; }; }; @@ -5202,9 +5202,9 @@ fn cgexpr(c: *cgen, n: *node) void = { // the C cgen takes when bt is NULL/ty_err. if (lhs != nil) { if (lhs.kind == N_IDENT) { - emit_line("\tMOVQ\t"); - emit_line(fld); - emit_line("(SB), AX\n"); + emitline("\tMOVQ\t"); + emitline(fld); + emitline("(SB), AX\n"); return; }; }; @@ -5216,7 +5216,7 @@ fn cgexpr(c: *cgen, n: *node) void = { if (streq(fld, "ptr")) { cgexpr(c, lhs); return; }; if (streq(fld, "len")) { cgexpr(c, lhs); - emit_line("\tMOVQ\tBX, AX\n"); + emitline("\tMOVQ\tBX, AX\n"); return; }; // Chained struct-field-via-ptr-via-ptr access: @@ -5229,31 +5229,31 @@ fn cgexpr(c: *cgen, n: *node) void = { // the field. (Showed up porting w6l/pass.ww.) if (lhs != nil) { if (lhs.kind == N_DOT) { - let inner_t: *node = dot_inner_struct_ptr(c, lhs); - if (inner_t != nil) { - let sname: str = inner_t.str; - let si: *struct_info = struct_lookup(c, sname); + let innert: *node = dotinnerstructptr(c, lhs); + if (innert != nil) { + let sname: str = innert.str; + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { if (streq(fi.fname, fld)) { cgexpr(c, lhs); // AX = ptr to inner struct - let lop: str = field_load_op(fi); + let lop: str = fieldloadop(fi); // str field: load both halves. - if (is_str_type(c, fi.tnode)) { - emit_line("\tMOVQ\t"); - emit_disp_reg((fi.foff + 8): i64, "AX"); - emit_line(", BX\n"); - emit_line("\tMOVQ\t"); - emit_disp_reg(fi.foff: i64, "AX"); - emit_line(", AX\n"); + if (isstrtype(c, fi.tnode)) { + emitline("\tMOVQ\t"); + emitdispreg((fi.foff + 8): i64, "AX"); + emitline(", BX\n"); + emitline("\tMOVQ\t"); + emitdispreg(fi.foff: i64, "AX"); + emitline(", AX\n"); return; }; - emit_line("\t"); - emit_line(lop); - emit_line("\t"); - emit_disp_reg(fi.foff: i64, "AX"); - emit_line(", AX\n"); + emitline("\t"); + emitline(lop); + emitline("\t"); + emitdispreg(fi.foff: i64, "AX"); + emitline(", AX\n"); return; }; fi = fi.finext; @@ -5271,19 +5271,19 @@ fn cgexpr(c: *cgen, n: *node) void = { // address / deref. The wasted load before AMP keeps our asm // byte-identical to the C version. cgexpr(c, n.lhs); - if (n.op == TK_MINUS) { emit_line("\tNEGQ\tAX\n"); return; }; - if (n.op == TK_TILDE) { emit_line("\tNOTQ\tAX\n"); return; }; - if (n.op == TK_STAR) { emit_line("\tMOVQ\t(AX), AX\n"); return; }; + if (n.op == TK_MINUS) { emitline("\tNEGQ\tAX\n"); return; }; + if (n.op == TK_TILDE) { emitline("\tNOTQ\tAX\n"); return; }; + if (n.op == TK_STAR) { emitline("\tMOVQ\t(AX), AX\n"); return; }; if (n.op == TK_AMP) { let opnd: *node = n.lhs; if (opnd != nil) { if (opnd.kind == N_IDENT) { let nm: str = opnd.str; - let off: i32 = local_find(c, nm); + let off: i32 = localfind(c, nm); if (off != 0) { - emit_line("\tLEAQ\t"); - emit_off(off: i64); - emit_line("(BP), AX\n"); + emitline("\tLEAQ\t"); + emitoff(off: i64); + emitline("(BP), AX\n"); return; }; }; @@ -5293,95 +5293,95 @@ fn cgexpr(c: *cgen, n: *node) void = { if (n.op == TK_NOT) { let t: str = mklabel(c, "tt"); let e: str = mklabel(c, "te"); - emit_line("\tCMPQ\t$0, AX\n"); - emit_line("\tJE\t"); emit_line(t); emit_line("\n"); - emit_line("\tMOVQ\t$0, AX\n"); - emit_line("\tJMP\t"); emit_line(e); emit_line("\n"); - emit_label(t); - emit_line("\tMOVQ\t$1, AX\n"); - emit_label(e); + emitline("\tCMPQ\t$0, AX\n"); + emitline("\tJE\t"); emitline(t); emitline("\n"); + emitline("\tMOVQ\t$0, AX\n"); + emitline("\tJMP\t"); emitline(e); emitline("\n"); + emitlabel(t); + emitline("\tMOVQ\t$1, AX\n"); + emitlabel(e); return; }; return; }; if (k == N_BIN) { - let unsignd: bool = node_isunsigned(c, n.lhs); - if (!unsignd) { unsignd = node_isunsigned(c, n.rhs); }; + let unsignd: bool = nodeisunsigned(c, n.lhs); + if (!unsignd) { unsignd = nodeisunsigned(c, n.rhs); }; cgexpr(c, n.rhs); - emit_line("\tPUSHQ\tAX\n"); + emitline("\tPUSHQ\tAX\n"); cgexpr(c, n.lhs); - emit_line("\tPOPQ\tBX\n"); - if (n.op == TK_PLUS) { emit_line("\tADDQ\tBX, AX\n"); return; }; - if (n.op == TK_MINUS) { emit_line("\tSUBQ\tBX, AX\n"); return; }; - if (n.op == TK_STAR) { emit_line("\tIMULQ\tBX, AX\n"); return; }; + emitline("\tPOPQ\tBX\n"); + if (n.op == TK_PLUS) { emitline("\tADDQ\tBX, AX\n"); return; }; + if (n.op == TK_MINUS) { emitline("\tSUBQ\tBX, AX\n"); return; }; + if (n.op == TK_STAR) { emitline("\tIMULQ\tBX, AX\n"); return; }; if (n.op == TK_SLASH) { - emit_line("\tMOVQ\t$0, DX\n"); - if (unsignd) { emit_line("\tDIVQ\tBX\n"); } - else { emit_line("\tIDIVQ\tBX\n"); }; + emitline("\tMOVQ\t$0, DX\n"); + if (unsignd) { emitline("\tDIVQ\tBX\n"); } + else { emitline("\tIDIVQ\tBX\n"); }; return; }; if (n.op == TK_PERCENT) { - emit_line("\tMOVQ\t$0, DX\n"); - if (unsignd) { emit_line("\tDIVQ\tBX\n"); } - else { emit_line("\tIDIVQ\tBX\n"); }; - emit_line("\tMOVQ\tDX, AX\n"); + emitline("\tMOVQ\t$0, DX\n"); + if (unsignd) { emitline("\tDIVQ\tBX\n"); } + else { emitline("\tIDIVQ\tBX\n"); }; + emitline("\tMOVQ\tDX, AX\n"); return; }; - if (n.op == TK_AMP) { emit_line("\tANDQ\tBX, AX\n"); return; }; - if (n.op == TK_PIPE) { emit_line("\tORQ\tBX, AX\n"); return; }; - if (n.op == TK_CARET) { emit_line("\tXORQ\tBX, AX\n"); return; }; + if (n.op == TK_AMP) { emitline("\tANDQ\tBX, AX\n"); return; }; + if (n.op == TK_PIPE) { emitline("\tORQ\tBX, AX\n"); return; }; + if (n.op == TK_CARET) { emitline("\tXORQ\tBX, AX\n"); return; }; if (n.op == TK_LSHIFT) { - emit_line("\tMOVQ\tBX, CX\n"); - emit_line("\tSHLQ\tCX, AX\n"); + emitline("\tMOVQ\tBX, CX\n"); + emitline("\tSHLQ\tCX, AX\n"); return; }; if (n.op == TK_RSHIFT) { - emit_line("\tMOVQ\tBX, CX\n"); - emit_line("\tSHRQ\tCX, AX\n"); + emitline("\tMOVQ\tBX, CX\n"); + emitline("\tSHRQ\tCX, AX\n"); return; }; - if (n.op == TK_AND) { emit_line("\tANDQ\tBX, AX\n"); return; }; - if (n.op == TK_OR) { emit_line("\tORQ\tBX, AX\n"); return; }; + if (n.op == TK_AND) { emitline("\tANDQ\tBX, AX\n"); return; }; + if (n.op == TK_OR) { emitline("\tORQ\tBX, AX\n"); return; }; // Comparison: emit CMPQ, jump on signed/unsigned variant, // materialise 0/1 in AX. Same shape as the C cgen. - let is_cmp: bool = false; + let iscmp: bool = false; let jcc: str = ""; - if (n.op == TK_EQ) { is_cmp = true; jcc = "JE"; }; - if (n.op == TK_NEQ) { is_cmp = true; jcc = "JNE"; }; - if (n.op == TK_LT) { is_cmp = true; if (unsignd) { jcc = "JB"; } else { jcc = "JL"; }; }; - if (n.op == TK_LE) { is_cmp = true; if (unsignd) { jcc = "JBE"; } else { jcc = "JLE"; }; }; - if (n.op == TK_GT) { is_cmp = true; if (unsignd) { jcc = "JA"; } else { jcc = "JG"; }; }; - if (n.op == TK_GE) { is_cmp = true; if (unsignd) { jcc = "JAE"; } else { jcc = "JGE"; }; }; - if (is_cmp) { + if (n.op == TK_EQ) { iscmp = true; jcc = "JE"; }; + if (n.op == TK_NEQ) { iscmp = true; jcc = "JNE"; }; + if (n.op == TK_LT) { iscmp = true; if (unsignd) { jcc = "JB"; } else { jcc = "JL"; }; }; + if (n.op == TK_LE) { iscmp = true; if (unsignd) { jcc = "JBE"; } else { jcc = "JLE"; }; }; + if (n.op == TK_GT) { iscmp = true; if (unsignd) { jcc = "JA"; } else { jcc = "JG"; }; }; + if (n.op == TK_GE) { iscmp = true; if (unsignd) { jcc = "JAE"; } else { jcc = "JGE"; }; }; + if (iscmp) { let t: str = mklabel(c, "ct"); let e: str = mklabel(c, "ce"); - emit_line("\tCMPQ\tBX, AX\n"); - emit_line("\t"); emit_line(jcc); emit_line("\t"); emit_line(t); emit_line("\n"); - emit_line("\tMOVQ\t$0, AX\n"); - emit_line("\tJMP\t"); emit_line(e); emit_line("\n"); - emit_label(t); - emit_line("\tMOVQ\t$1, AX\n"); - emit_label(e); + emitline("\tCMPQ\tBX, AX\n"); + emitline("\t"); emitline(jcc); emitline("\t"); emitline(t); emitline("\n"); + emitline("\tMOVQ\t$0, AX\n"); + emitline("\tJMP\t"); emitline(e); emitline("\n"); + emitlabel(t); + emitline("\tMOVQ\t$1, AX\n"); + emitlabel(e); return; }; return; }; if (k == N_CALL) { - let nargs: i32 = push_args_rev(c, n.list); + let nargs: i32 = pushargsrev(c, n.list); let i: i32 = 0; for (i < nargs) { - emit_line("\tPOPQ\t"); - emit_line(argreg_name(i)); - emit_line("\n"); + emitline("\tPOPQ\t"); + emitline(argregname(i)); + emitline("\n"); i += 1; }; let callee: *node = n.lhs; - let callee_name: str; - callee_name.ptr = nil; callee_name.len = 0; + let calleename: str; + calleename.ptr = nil; calleename.len = 0; // Detect fn-pointer field call: `w.emit(args)` where `w` is // a struct local and `emit` is an N_TFN field. Load the // field value into AX and CALL through it. Also detect a @@ -5389,12 +5389,12 @@ fn cgexpr(c: *cgen, n: *node) void = { // pointer — mirror C cgen's localfind dispatch (commit // 635818e). Without this the call emits `CALL fp(SB)` and // the linker rightly fails. - let is_fnptr_call: bool = false; + let isfnptrcall: bool = false; if (callee != nil) { if (callee.kind == N_IDENT) { let cn: str = callee.str; - if (local_find_node(c, cn) != nil) { - is_fnptr_call = true; + if (localfindnode(c, cn) != nil) { + isfnptrcall = true; }; }; if (callee.kind == N_DOT) { @@ -5403,7 +5403,7 @@ fn cgexpr(c: *cgen, n: *node) void = { if (base != nil) { if (base.kind == N_IDENT) { let bn: str = base.str; - let lc: *local = local_find_node(c, bn); + let lc: *local = localfindnode(c, bn); if (lc != nil) { let tn: *node = lc.tnode; if (tn != nil) { @@ -5418,16 +5418,16 @@ fn cgexpr(c: *cgen, n: *node) void = { }; }; if (sname.len > 0) { - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fld)) { let ft: *node = fi.tnode; if (ft != nil) { if (ft.kind == N_TFN) { - is_fnptr_call = true; + isfnptrcall = true; }; }; fi = nil; @@ -5443,34 +5443,34 @@ fn cgexpr(c: *cgen, n: *node) void = { }; }; }; - if (is_fnptr_call) { + if (isfnptrcall) { // Load fn-ptr field value into AX; CALL AX. We emit the // load AFTER the args have been popped (so AX/BX/etc // don't get clobbered by the field load before the pops). // `popped args` left DI/SI/etc set; AX is free. cgexpr(c, callee); - emit_line("\tCALL\tAX\n"); + emitline("\tCALL\tAX\n"); } else { - emit_line("\tCALL\t"); + emitline("\tCALL\t"); if (callee != nil) { if (callee.kind == N_IDENT) { - callee_name = callee.str; - let resolved: str = ffi_resolve(c, callee_name); + calleename = callee.str; + let resolved: str = ffiresolve(c, calleename); os.write(1, resolved.ptr, resolved.len: u64); } else { if (callee.kind == N_DOT) { - callee_name = callee.str; - let resolved: str = ffi_resolve(c, callee_name); + calleename = callee.str; + let resolved: str = ffiresolve(c, calleename); os.write(1, resolved.ptr, resolved.len: u64); };}; }; - emit_line("(SB)\n"); + emitline("(SB)\n"); }; // SysV returns 16-byte aggregates in (AX, DX). Our str // convention is (AX, BX), so shuffle for str-returning calls. - if (callee_name.len > 0) { - let rt: *node = fnret_lookup(c, callee_name); - if (is_str_type(c, rt)) { - emit_line("\tMOVQ\tDX, BX\n"); + if (calleename.len > 0) { + let rt: *node = fnretlookup(c, calleename); + if (isstrtype(c, rt)) { + emitline("\tMOVQ\tDX, BX\n"); }; }; return; @@ -5488,11 +5488,11 @@ fn cgexpr(c: *cgen, n: *node) void = { if (lhs.op == TK_STAR) { if (n.op == TK_ASSIGN) { let inner: *node = lhs.lhs; - let elem_str: bool = false; - let store_op: str = "MOVQ"; + let elemstr: bool = false; + let storeop: str = "MOVQ"; if (inner != nil) { if (inner.kind == N_IDENT) { - let lc: *local = local_find_node(c, inner.str); + let lc: *local = localfindnode(c, inner.str); if (lc != nil) { let tn: *node = lc.tnode; if (tn != nil) { @@ -5500,11 +5500,11 @@ fn cgexpr(c: *cgen, n: *node) void = { let pe: *node = tn.lhs; if (pe != nil) { if (pe.kind == N_TNAME) { - if (streq(pe.str, "str")) { elem_str = true; } + if (streq(pe.str, "str")) { elemstr = true; } else { - let ps: i32 = prim_size(pe.str); - if (ps == 1) { store_op = "MOVB"; } - else { if (ps == 4) { store_op = "MOVL"; }; }; + let ps: i32 = primsize(pe.str); + if (ps == 1) { storeop = "MOVB"; } + else { if (ps == 4) { storeop = "MOVL"; }; }; }; }; }; @@ -5520,21 +5520,21 @@ fn cgexpr(c: *cgen, n: *node) void = { // str, so the pop sequence is POP CX // (len) → POP AX (ptr) → MOVQ AX, // (BX) → MOVQ CX, 8(BX). - emit_line("\tPUSHQ\tAX\n"); - if (elem_str) { emit_line("\tPUSHQ\tBX\n"); }; + emitline("\tPUSHQ\tAX\n"); + if (elemstr) { emitline("\tPUSHQ\tBX\n"); }; cgexpr(c, inner); - emit_line("\tMOVQ\tAX, BX\n"); - if (elem_str) { - emit_line("\tPOPQ\tCX\n"); - emit_line("\tPOPQ\tAX\n"); - emit_line("\tMOVQ\tAX, (BX)\n"); - emit_line("\tMOVQ\tCX, 8(BX)\n"); + emitline("\tMOVQ\tAX, BX\n"); + if (elemstr) { + emitline("\tPOPQ\tCX\n"); + emitline("\tPOPQ\tAX\n"); + emitline("\tMOVQ\tAX, (BX)\n"); + emitline("\tMOVQ\tCX, 8(BX)\n"); return; }; - emit_line("\tPOPQ\tAX\n"); - emit_line("\t"); - emit_line(store_op); - emit_line("\tAX, (BX)\n"); + emitline("\tPOPQ\tAX\n"); + emitline("\t"); + emitline(storeop); + emitline("\tAX, (BX)\n"); return; }; }; @@ -5548,57 +5548,57 @@ fn cgexpr(c: *cgen, n: *node) void = { let base: *node = lhs.lhs; let idx: *node = lhs.rhs; let esz: i32 = 8; - let base_local: *local = nil; + let baselocal: *local = nil; if (base != nil) { if (base.kind == N_IDENT) { let bn: str = base.str; - base_local = local_find_node(c, bn); - if (base_local != nil) { - esz = elem_size_of(base_local.tnode); + baselocal = localfindnode(c, bn); + if (baselocal != nil) { + esz = elemsizeof(baselocal.tnode); }; } else { if (base.kind == N_DOT) { - esz = index_base_esz(c, base); + esz = indexbaseesz(c, base); };}; }; cgexpr(c, n.rhs); // value → AX - if (esz == 16) { emit_line("\tPUSHQ\tBX\n"); }; - emit_line("\tPUSHQ\tAX\n"); + if (esz == 16) { emitline("\tPUSHQ\tBX\n"); }; + emitline("\tPUSHQ\tAX\n"); cgexpr(c, idx); // idx → AX if (esz > 1) { - emit_line("\tMOVQ\t$"); - emit_int(esz: i64); - emit_line(", CX\n"); - emit_line("\tIMULQ\tCX, AX\n"); + emitline("\tMOVQ\t$"); + emitint(esz: i64); + emitline(", CX\n"); + emitline("\tIMULQ\tCX, AX\n"); }; - emit_line("\tPUSHQ\tAX\n"); // scaled idx - if (base_local != nil) { - let tn: *node = base_local.tnode; - let is_array: bool = false; - if (tn != nil) { if (tn.kind == N_TARRAY) { is_array = true; }; }; - if (is_array) { - emit_line("\tLEAQ\t"); - emit_off(base_local.off: i64); - emit_line("(BP), BX\n"); + emitline("\tPUSHQ\tAX\n"); // scaled idx + if (baselocal != nil) { + let tn: *node = baselocal.tnode; + let isarray: bool = false; + if (tn != nil) { if (tn.kind == N_TARRAY) { isarray = true; }; }; + if (isarray) { + emitline("\tLEAQ\t"); + emitoff(baselocal.off: i64); + emitline("(BP), BX\n"); } else { - emit_line("\tMOVQ\t"); - emit_off(base_local.off: i64); - emit_line("(BP), BX\n"); + emitline("\tMOVQ\t"); + emitoff(baselocal.off: i64); + emitline("(BP), BX\n"); }; } else { cgexpr(c, base); - emit_line("\tMOVQ\tAX, BX\n"); + emitline("\tMOVQ\tAX, BX\n"); }; - emit_line("\tPOPQ\tAX\n"); // scaled idx - emit_line("\tADDQ\tAX, BX\n"); - emit_line("\tPOPQ\tAX\n"); // value + emitline("\tPOPQ\tAX\n"); // scaled idx + emitline("\tADDQ\tAX, BX\n"); + emitline("\tPOPQ\tAX\n"); // value if (esz == 16) { - emit_line("\tMOVQ\tAX, (BX)\n"); - emit_line("\tPOPQ\tCX\n"); - emit_line("\tMOVQ\tCX, 8(BX)\n"); + emitline("\tMOVQ\tAX, (BX)\n"); + emitline("\tPOPQ\tCX\n"); + emitline("\tMOVQ\tCX, 8(BX)\n"); return; }; - if (esz == 1) { emit_line("\tMOVB\tAX, (BX)\n"); } - else { emit_line("\tMOVQ\tAX, (BX)\n"); }; + if (esz == 1) { emitline("\tMOVB\tAX, (BX)\n"); } + else { emitline("\tMOVQ\tAX, (BX)\n"); }; return; }; }; @@ -5613,7 +5613,7 @@ fn cgexpr(c: *cgen, n: *node) void = { if (base != nil) { if (base.kind == N_IDENT) { let bn: str = base.str; - let lc: *local = local_find_node(c, bn); + let lc: *local = localfindnode(c, bn); if (lc != nil) { let tn: *node = lc.tnode; let lkind: i32 = -1; @@ -5627,35 +5627,35 @@ fn cgexpr(c: *cgen, n: *node) void = { if (inner.kind == N_TNAME) { sname = inner.str; }; }; if (sname.len > 0) { - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fld)) { if (n.op != TK_ASSIGN) { // compound: load current value - emit_line("\tMOVQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), BX\n"); - let lop: str = field_load_op(fi); - emit_line("\t"); - emit_line(lop); - emit_line("\t"); - emit_disp_reg(fi.foff: i64, "BX"); - emit_line(", BX\n"); - emit_line("\tPUSHQ\tBX\n"); + emitline("\tMOVQ\t"); + emitoff(lc.off: i64); + emitline("(BP), BX\n"); + let lop: str = fieldloadop(fi); + emitline("\t"); + emitline(lop); + emitline("\t"); + emitdispreg(fi.foff: i64, "BX"); + emitline(", BX\n"); + emitline("\tPUSHQ\tBX\n"); }; cgexpr(c, n.rhs); if (n.op != TK_ASSIGN) { - emit_line("\tPOPQ\tBX\n"); + emitline("\tPOPQ\tBX\n"); // PLUSEQ is commutative; MINUSEQ // needs lhs - rhs (BX is old lhs, // AX is rhs). - if (n.op == TK_PLUSEQ) { emit_line("\tADDQ\tBX, AX\n"); }; + if (n.op == TK_PLUSEQ) { emitline("\tADDQ\tBX, AX\n"); }; if (n.op == TK_MINUSEQ) { - emit_line("\tSUBQ\tAX, BX\n"); - emit_line("\tMOVQ\tBX, AX\n"); + emitline("\tSUBQ\tAX, BX\n"); + emitline("\tMOVQ\tBX, AX\n"); }; }; // str field via *struct: rhs left @@ -5663,28 +5663,28 @@ fn cgexpr(c: *cgen, n: *node) void = { // address scratch so we don't clobber // the len half before storing it. if (n.op == TK_ASSIGN) { - if (is_str_type(c, fi.tnode)) { - emit_line("\tMOVQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), CX\n"); - emit_line("\tMOVQ\tAX, "); - emit_disp_reg(fi.foff: i64, "CX"); - emit_line("\n"); - emit_line("\tMOVQ\tBX, "); - emit_disp_reg((fi.foff + 8): i64, "CX"); - emit_line("\n"); + if (isstrtype(c, fi.tnode)) { + emitline("\tMOVQ\t"); + emitoff(lc.off: i64); + emitline("(BP), CX\n"); + emitline("\tMOVQ\tAX, "); + emitdispreg(fi.foff: i64, "CX"); + emitline("\n"); + emitline("\tMOVQ\tBX, "); + emitdispreg((fi.foff + 8): i64, "CX"); + emitline("\n"); return; }; }; - emit_line("\tMOVQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), BX\n"); - let sop: str = field_store_op(fi); - emit_line("\t"); - emit_line(sop); - emit_line("\tAX, "); - emit_disp_reg(fi.foff: i64, "BX"); - emit_line("\n"); + emitline("\tMOVQ\t"); + emitoff(lc.off: i64); + emitline("(BP), BX\n"); + let sop: str = fieldstoreop(fi); + emitline("\t"); + emitline(sop); + emitline("\tAX, "); + emitdispreg(fi.foff: i64, "BX"); + emitline("\n"); return; }; fi = fi.finext; @@ -5695,19 +5695,19 @@ fn cgexpr(c: *cgen, n: *node) void = { // Direct struct local: store at off+foff. if (lkind == N_TNAME) { let sname: str = tn.str; - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let fi: *field_info = si.fields; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fld)) { cgexpr(c, n.rhs); - let sop: str = field_store_op(fi); - emit_line("\t"); - emit_line(sop); - emit_line("\tAX, "); - emit_off((lc.off + fi.foff): i64); - emit_line("(BP)\n"); + let sop: str = fieldstoreop(fi); + emitline("\t"); + emitline(sop); + emitline("\tAX, "); + emitoff((lc.off + fi.foff): i64); + emitline("(BP)\n"); return; }; fi = fi.finext; @@ -5722,55 +5722,55 @@ fn cgexpr(c: *cgen, n: *node) void = { if (delta >= 0) { if (lkind == N_TPTR) { let inner: *node = tn.lhs; - let inner_kind: i32 = -1; - if (inner != nil) { inner_kind = inner.kind; }; - let inner_str: bool = false; - if (inner_kind == N_TNAME) { - if (streq(inner.str, "str")) { inner_str = true; }; + let innerkind: i32 = -1; + if (inner != nil) { innerkind = inner.kind; }; + let innerstr: bool = false; + if (innerkind == N_TNAME) { + if (streq(inner.str, "str")) { innerstr = true; }; }; - if (inner_kind == N_TSLICE) { inner_str = true; }; - if (inner_str) { + if (innerkind == N_TSLICE) { innerstr = true; }; + if (innerstr) { if (n.op != TK_ASSIGN) { // Compound on `(*str|*slice).field`: load // current → push → eval rhs → combine → store. - emit_line("\tMOVQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), BX\n"); - emit_line("\tMOVQ\t"); - emit_disp_reg(delta: i64, "BX"); - emit_line(", BX\n"); - emit_line("\tPUSHQ\tBX\n"); + emitline("\tMOVQ\t"); + emitoff(lc.off: i64); + emitline("(BP), BX\n"); + emitline("\tMOVQ\t"); + emitdispreg(delta: i64, "BX"); + emitline(", BX\n"); + emitline("\tPUSHQ\tBX\n"); cgexpr(c, n.rhs); - emit_line("\tPOPQ\tBX\n"); + emitline("\tPOPQ\tBX\n"); // PLUSEQ is commutative; MINUSEQ // needs lhs - rhs. - if (n.op == TK_PLUSEQ) { emit_line("\tADDQ\tBX, AX\n"); }; + if (n.op == TK_PLUSEQ) { emitline("\tADDQ\tBX, AX\n"); }; if (n.op == TK_MINUSEQ) { - emit_line("\tSUBQ\tAX, BX\n"); - emit_line("\tMOVQ\tBX, AX\n"); + emitline("\tSUBQ\tAX, BX\n"); + emitline("\tMOVQ\tBX, AX\n"); }; - emit_line("\tMOVQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), BX\n"); - emit_line("\tMOVQ\tAX, "); - emit_disp_reg(delta: i64, "BX"); - emit_line("\n"); + emitline("\tMOVQ\t"); + emitoff(lc.off: i64); + emitline("(BP), BX\n"); + emitline("\tMOVQ\tAX, "); + emitdispreg(delta: i64, "BX"); + emitline("\n"); return; }; cgexpr(c, n.rhs); - emit_line("\tMOVQ\t"); - emit_off(lc.off: i64); - emit_line("(BP), BX\n"); - emit_line("\tMOVQ\tAX, "); - emit_disp_reg(delta: i64, "BX"); - emit_line("\n"); + emitline("\tMOVQ\t"); + emitoff(lc.off: i64); + emitline("(BP), BX\n"); + emitline("\tMOVQ\tAX, "); + emitdispreg(delta: i64, "BX"); + emitline("\n"); return; }; }; cgexpr(c, n.rhs); - emit_line("\tMOVQ\tAX, "); - emit_off((lc.off + delta): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tAX, "); + emitoff((lc.off + delta): i64); + emitline("(BP)\n"); return; }; }; @@ -5784,56 +5784,56 @@ fn cgexpr(c: *cgen, n: *node) void = { if (lhs != nil) { if (lhs.kind == N_IDENT) { let nm: str = lhs.str; - let off: i32 = local_find(c, nm); + let off: i32 = localfind(c, nm); if (off == 0) { return; }; // Detect str-typed local — assignment must store both // halves (AX=ptr at +0, BX=len at +8). - let lc_str: bool = false; - let lcn: *local = local_find_node(c, nm); - if (lcn != nil) { lc_str = is_str_type(c, lcn.tnode); }; + let lcstr: bool = false; + let lcn: *local = localfindnode(c, nm); + if (lcn != nil) { lcstr = isstrtype(c, lcn.tnode); }; cgexpr(c, n.rhs); if (n.op == TK_ASSIGN) { - emit_line("\tMOVQ\tAX, "); - emit_off(off: i64); - emit_line("(BP)\n"); - if (lc_str) { - emit_line("\tMOVQ\tBX, "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tAX, "); + emitoff(off: i64); + emitline("(BP)\n"); + if (lcstr) { + emitline("\tMOVQ\tBX, "); + emitoff((off + 8): i64); + emitline("(BP)\n"); }; return; }; if (n.op == TK_PLUSEQ) { - emit_line("\tADDQ\tAX, "); - emit_off(off: i64); - emit_line("(BP)\n"); + emitline("\tADDQ\tAX, "); + emitoff(off: i64); + emitline("(BP)\n"); return; }; if (n.op == TK_MINUSEQ) { - emit_line("\tSUBQ\tAX, "); - emit_off(off: i64); - emit_line("(BP)\n"); + emitline("\tSUBQ\tAX, "); + emitoff(off: i64); + emitline("(BP)\n"); return; }; // Generic compound: load → combine in BX → store. - emit_line("\tMOVQ\t"); - emit_off(off: i64); - emit_line("(BP), BX\n"); - if (n.op == TK_STAREQ) { emit_line("\tIMULQ\tAX, BX\n"); }; - if (n.op == TK_AMPEQ) { emit_line("\tANDQ\tAX, BX\n"); }; - if (n.op == TK_PIPEEQ) { emit_line("\tORQ\tAX, BX\n"); }; - if (n.op == TK_CARETEQ) { emit_line("\tXORQ\tAX, BX\n"); }; + emitline("\tMOVQ\t"); + emitoff(off: i64); + emitline("(BP), BX\n"); + if (n.op == TK_STAREQ) { emitline("\tIMULQ\tAX, BX\n"); }; + if (n.op == TK_AMPEQ) { emitline("\tANDQ\tAX, BX\n"); }; + if (n.op == TK_PIPEEQ) { emitline("\tORQ\tAX, BX\n"); }; + if (n.op == TK_CARETEQ) { emitline("\tXORQ\tAX, BX\n"); }; if (n.op == TK_LSHIFTEQ) { - emit_line("\tMOVQ\tAX, CX\n"); - emit_line("\tSHLQ\tCX, BX\n"); + emitline("\tMOVQ\tAX, CX\n"); + emitline("\tSHLQ\tCX, BX\n"); }; if (n.op == TK_RSHIFTEQ) { - emit_line("\tMOVQ\tAX, CX\n"); - emit_line("\tSHRQ\tCX, BX\n"); + emitline("\tMOVQ\tAX, CX\n"); + emitline("\tSHRQ\tCX, BX\n"); }; - emit_line("\tMOVQ\tBX, "); - emit_off(off: i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tBX, "); + emitoff(off: i64); + emitline("(BP)\n"); return; }; }; @@ -5843,8 +5843,8 @@ fn cgexpr(c: *cgen, n: *node) void = { // ---- type-driven slot sizing ---------------------------------------- -fn struct_lookup(c: *cgen, name: str) *struct_info = { - let s: *struct_info = c.structs; +fn structlookup(c: *cgen, name: str) *structinfo = { + let s: *structinfo = c.structs; for (s != nil) { let sn: str = s.sname; if (streq(sn, name)) { return s; }; @@ -5853,9 +5853,9 @@ fn struct_lookup(c: *cgen, name: str) *struct_info = { return nil; }; -// prim_size — size in bytes of a primitive type name (or 0 if not +// primsize — size in bytes of a primitive type name (or 0 if not // recognised as a primitive — the caller falls back to other paths). -fn prim_size(name: str) i32 = { +fn primsize(name: str) i32 = { if (streq(name, "u8")) { return 1; }; if (streq(name, "i8")) { return 1; }; if (streq(name, "bool")) { return 1; }; @@ -5875,7 +5875,7 @@ fn prim_size(name: str) i32 = { return 0; }; -fn slot_size(c: *cgen, typ_n: *node) i32 = { +fn slotsize(c: *cgen, typ_n: *node) i32 = { if (typ_n == nil) { return 8; }; let k: i32 = typ_n.kind; if (k == N_TPTR) { return 8; }; @@ -5887,29 +5887,29 @@ fn slot_size(c: *cgen, typ_n: *node) i32 = { if (k == N_TNAME) { let nm: str = typ_n.str; if (streq(nm, "str")) { return 16; }; - let ps: i32 = prim_size(nm); + let ps: i32 = primsize(nm); if (ps > 0) { // Pad to 8 for stack slots — matches C cgen which spills // every primitive into an 8-byte slot. return 8; }; // Named struct lookup. - let si: *struct_info = struct_lookup(c, nm); + let si: *structinfo = structlookup(c, nm); if (si != nil) { return si.tot_size; }; return 8; }; if (k == N_TARRAY) { - let len_n: *node = typ_n.rhs; - let elem_n: *node = typ_n.lhs; + let lenn: *node = typ_n.rhs; + let elemn: *node = typ_n.lhs; let elen: i64 = 1i64; - if (len_n != nil) { - if (len_n.kind == N_INTLIT) { elen = len_n.uval: i64; }; + if (lenn != nil) { + if (lenn.kind == N_INTLIT) { elen = lenn.uval: i64; }; }; let esz: i32 = 8; - if (elem_n != nil) { - if (elem_n.kind == N_TNAME) { - let en: str = elem_n.str; - let ps: i32 = prim_size(en); + if (elemn != nil) { + if (elemn.kind == N_TNAME) { + let en: str = elemn.str; + let ps: i32 = primsize(en); if (ps > 0) { esz = ps; }; }; }; @@ -5921,7 +5921,7 @@ fn slot_size(c: *cgen, typ_n: *node) i32 = { let total: i32 = 0; for (f != nil) { if (f.kind == N_TFIELD) { - total += slot_size(c, f.lhs); + total += slotsize(c, f.lhs); }; f = f.next; }; @@ -5930,50 +5930,50 @@ fn slot_size(c: *cgen, typ_n: *node) i32 = { return 8; }; -// register_struct — compute field offsets + total size for a struct +// registerstruct — compute field offsets + total size for a struct // type-decl, store in c.structs. Field type sizes use the same -// slot_size logic (with primitives kept at their natural width — we +// slotsize logic (with primitives kept at their natural width — we // only round to 8 for stack slots, not struct interiors). -fn field_size(c: *cgen, tnode: *node) i32 = { +fn fieldsize(c: *cgen, tnode: *node) i32 = { if (tnode == nil) { return 8; }; let k: i32 = tnode.kind; if (k == N_TNAME) { let nm: str = tnode.str; if (streq(nm, "str")) { return 16; }; - let ps: i32 = prim_size(nm); + let ps: i32 = primsize(nm); if (ps > 0) { return ps; }; - let si: *struct_info = struct_lookup(c, nm); + let si: *structinfo = structlookup(c, nm); if (si != nil) { return si.tot_size; }; return 8; }; if (k == N_TPTR) { return 8; }; if (k == N_TSLICE) { return 24; }; if (k == N_TARRAY) { - // Same shape as slot_size's TARRAY branch. - let len_n: *node = tnode.rhs; - let elem_n: *node = tnode.lhs; + // Same shape as slotsize's TARRAY branch. + let lenn: *node = tnode.rhs; + let elemn: *node = tnode.lhs; let elen: i64 = 1i64; - if (len_n != nil) { - if (len_n.kind == N_INTLIT) { elen = len_n.uval: i64; }; + if (lenn != nil) { + if (lenn.kind == N_INTLIT) { elen = lenn.uval: i64; }; }; - let esz: i32 = field_size(c, elem_n); + let esz: i32 = fieldsize(c, elemn); return (esz: i64 * elen): i32; }; return 8; }; -fn register_struct(c: *cgen, name: str, tstruct: *node) void = { - let si: *struct_info = amalloc(c.a, 64u64): *struct_info; +fn registerstruct(c: *cgen, name: str, tstruct: *node) void = { + let si: *structinfo = amalloc(c.a, 64u64): *structinfo; si.sname = name; si.fields = nil; si.tot_size = 0; - let head: *field_info = nil; - let tail: *field_info = nil; + let head: *fieldinfo = nil; + let tail: *fieldinfo = nil; let off: i32 = 0; let f: *node = tstruct.list; for (f != nil) { if (f.kind == N_TFIELD) { - let sz: i32 = field_size(c, f.lhs); + let sz: i32 = fieldsize(c, f.lhs); // Align to 8 for any field >= 4 bytes (matches our other // cgen choices). i8/u8/bool may sit on odd byte offsets; // the C cgen does similar best-effort packing. @@ -5984,7 +5984,7 @@ fn register_struct(c: *cgen, name: str, tstruct: *node) void = { if ((off & (aln - 1)) != 0) { off = (off + aln - 1) & ~(aln - 1); }; - let fi: *field_info = amalloc(c.a, 48u64): *field_info; + let fi: *fieldinfo = amalloc(c.a, 48u64): *fieldinfo; fi.fname = f.str; fi.foff = off; fi.fsz = sz; @@ -6003,7 +6003,7 @@ fn register_struct(c: *cgen, name: str, tstruct: *node) void = { c.structs = si; }; -fn collect_structs(c: *cgen, file: *node) void = { +fn collectstructs(c: *cgen, file: *node) void = { c.structs = nil; if (file == nil) { return; }; let d: *node = file.list; @@ -6012,7 +6012,7 @@ fn collect_structs(c: *cgen, file: *node) void = { let body: *node = d.lhs; if (body != nil) { if (body.kind == N_TSTRUCT) { - register_struct(c, d.str, body); + registerstruct(c, d.str, body); }; }; }; @@ -6023,21 +6023,21 @@ fn collect_structs(c: *cgen, file: *node) void = { // ---- frame pre-scan -------------------------------------------------- // // Recursively walks the body to count every local `let`. Each gets a -// slot sized by slot_size(typ); 8-byte default. Match-bindings + for- +// slot sized by slotsize(typ); 8-byte default. Match-bindings + for- // init lets count too. Params are added by the cgfn driver. -fn scan_locals(c: *cgen, n: *node) i32 = { +fn scanlocals(c: *cgen, n: *node) i32 = { if (n == nil) { return 0; }; let total: i32 = 0; if (n.kind == N_LET) { - // Match local_add's rounding: < 8 bumps to 8, then 8-align. - // scan_locals must agree with local_add or the prologue + // 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 // caller's stack — corrupting whatever's at -frameSize..-1 // of the caller. Same-name re-declarations share the first - // slot (see scan_seen_mark / local_add). - if (!scan_seen_mark(c, n.str)) { - let sz: i32 = slot_size(c, n.lhs); + // slot (see scanseenmark / localadd). + if (!scanseenmark(c, n.str)) { + let sz: i32 = slotsize(c, n.lhs); if (sz < 8) { sz = 8; }; if ((sz & 7) != 0) { sz = (sz + 7) & ~7; }; total += sz; @@ -6048,26 +6048,26 @@ fn scan_locals(c: *cgen, n: *node) i32 = { // handles a match as an expression with a by-value locals copy, // 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 local_add then bumps it to. + // shrink the frame below what localadd then bumps it to. if (n.kind == N_MCASE) { let bn: str = n.str; if (bn.len > 0) { let pat: *node = n.lhs; if (pat != nil) { - if (is_str_type(c, pat)) { total += 16; } + if (isstrtype(c, pat)) { total += 16; } else { total += 8; }; }; }; }; - if (n.lhs != nil) { total += scan_locals(c, n.lhs); }; - if (n.rhs != nil) { total += scan_locals(c, n.rhs); }; - if (n.cond != nil) { total += scan_locals(c, n.cond); }; - if (n.body != nil) { total += scan_locals(c, n.body); }; - if (n.els != nil) { total += scan_locals(c, n.els); }; + if (n.lhs != nil) { total += scanlocals(c, n.lhs); }; + if (n.rhs != nil) { total += scanlocals(c, n.rhs); }; + if (n.cond != nil) { total += scanlocals(c, n.cond); }; + if (n.body != nil) { total += scanlocals(c, n.body); }; + if (n.els != nil) { total += scanlocals(c, n.els); }; if (n.list != nil) { let m: *node = n.list; for (m != nil) { - total += scan_locals(c, m); + total += scanlocals(c, m); m = m.next; }; }; @@ -6101,16 +6101,16 @@ fn cgstmt(c: *cgen, n: *node) void = { let v2: *node = v.next; if (v2 != nil) { cgexpr(c, v2); - emit_line("\tPUSHQ\tAX\n"); + emitline("\tPUSHQ\tAX\n"); cgexpr(c, v); - emit_line("\tPOPQ\tDX\n"); + emitline("\tPOPQ\tDX\n"); } else { cgexpr(c, v); }; }; - emit_line("\tMOVQ\tBP, SP\n"); - emit_line("\tPOPQ\tBP\n"); - emit_line("\tRET\n"); + emitline("\tMOVQ\tBP, SP\n"); + emitline("\tPOPQ\tBP\n"); + emitline("\tRET\n"); c.last_was_return = 1; return; }; @@ -6118,22 +6118,22 @@ fn cgstmt(c: *cgen, n: *node) void = { // For str variant, cgexpr leaves (AX=ptr, BX=len), so we // shuffle DX←AX (ptr) and CX←BX (len), then load tag. // For other variants, cgexpr leaves AX, shuffle DX←AX. - if (is_tagged_type(c.fn_ret)) { + if (istaggedtype(c.fn_ret)) { cgexpr(c, rhs); - let idx: i32 = tagged_variant_index(c, c.fn_ret, rhs); - if (node_isstr(c, rhs)) { - emit_line("\tMOVQ\tBX, CX\n"); - emit_line("\tMOVQ\tAX, DX\n"); + let idx: i32 = taggedvariantindex(c, c.fn_ret, rhs); + if (nodeisstr(c, rhs)) { + emitline("\tMOVQ\tBX, CX\n"); + emitline("\tMOVQ\tAX, DX\n"); } else { - emit_line("\tMOVQ\tAX, DX\n"); + emitline("\tMOVQ\tAX, DX\n"); }; - emit_line("\tMOVQ\t$"); + emitline("\tMOVQ\t$"); if (idx < 0) { idx = 0; }; - emit_int(idx: i64); - emit_line(", AX\n"); - emit_line("\tMOVQ\tBP, SP\n"); - emit_line("\tPOPQ\tBP\n"); - emit_line("\tRET\n"); + emitint(idx: i64); + emitline(", AX\n"); + emitline("\tMOVQ\tBP, SP\n"); + emitline("\tPOPQ\tBP\n"); + emitline("\tRET\n"); c.last_was_return = 1; return; }; @@ -6142,16 +6142,16 @@ fn cgstmt(c: *cgen, n: *node) void = { // Bare `return;` in a void fn — zero AX so the caller // sees a deterministic value (matches C cgen, which // always falls through to `cgexpr_int(c, 0)`). - emit_line("\tMOVQ\t$0, AX\n"); + emitline("\tMOVQ\t$0, AX\n"); }; // SysV: 16-byte aggregates (str, 2-tuple) return in (AX, DX). // cgexpr leaves str in (AX, BX); shuffle BX→DX. - if (is_str_type(c, c.fn_ret)) { - emit_line("\tMOVQ\tBX, DX\n"); + if (isstrtype(c, c.fn_ret)) { + emitline("\tMOVQ\tBX, DX\n"); }; - emit_line("\tMOVQ\tBP, SP\n"); - emit_line("\tPOPQ\tBP\n"); - emit_line("\tRET\n"); + emitline("\tMOVQ\tBP, SP\n"); + emitline("\tPOPQ\tBP\n"); + emitline("\tRET\n"); c.last_was_return = 1; return; }; @@ -6164,8 +6164,8 @@ fn cgstmt(c: *cgen, n: *node) void = { if (k == N_LET) { let nm: str = n.str; - let sz: i32 = slot_size(c, n.lhs); - let off: i32 = local_add(c, nm, sz, n.lhs); + let sz: i32 = slotsize(c, n.lhs); + let off: i32 = localadd(c, nm, sz, n.lhs); if (n.rhs != nil) { let rhs: *node = n.rhs; // Tagged-union init: `let r: (T | E) = expr;`. @@ -6174,54 +6174,54 @@ fn cgstmt(c: *cgen, n: *node) void = { // just spill all three. // - Otherwise rhs is a bare variant value: pack tag + // value(s). - if (is_tagged_type(n.lhs)) { - let rhs_returns_tagged: bool = false; + if (istaggedtype(n.lhs)) { + let rhsreturnstagged: bool = false; if (rhs.kind == N_CALL) { let callee: *node = rhs.lhs; if (callee != nil) { - let callee_name: str; - callee_name.ptr = nil; callee_name.len = 0; - if (callee.kind == N_IDENT) { callee_name = callee.str; }; - if (callee.kind == N_DOT) { callee_name = callee.str; }; - if (callee_name.len > 0) { - let rt: *node = fnret_lookup(c, callee_name); - if (is_tagged_type(rt)) { rhs_returns_tagged = true; }; + 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 (calleename.len > 0) { + let rt: *node = fnretlookup(c, calleename); + if (istaggedtype(rt)) { rhsreturnstagged = true; }; }; }; }; cgexpr(c, rhs); - if (rhs_returns_tagged) { - emit_line("\tMOVQ\tAX, "); - emit_off(off: i64); - emit_line("(BP)\n"); - emit_line("\tMOVQ\tDX, "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); - emit_line("\tMOVQ\tCX, "); - emit_off((off + 16): i64); - emit_line("(BP)\n"); + if (rhsreturnstagged) { + emitline("\tMOVQ\tAX, "); + emitoff(off: i64); + emitline("(BP)\n"); + emitline("\tMOVQ\tDX, "); + emitoff((off + 8): i64); + emitline("(BP)\n"); + emitline("\tMOVQ\tCX, "); + emitoff((off + 16): i64); + emitline("(BP)\n"); c.last_was_return = 0; return; }; - let tag_idx: i32 = tagged_variant_index(c, n.lhs, rhs); - if (tag_idx < 0) { tag_idx = 0; }; - if (node_isstr(c, rhs)) { - emit_line("\tMOVQ\tAX, "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); - emit_line("\tMOVQ\tBX, "); - emit_off((off + 16): i64); - emit_line("(BP)\n"); + let tagidx: i32 = taggedvariantindex(c, n.lhs, rhs); + if (tagidx < 0) { tagidx = 0; }; + if (nodeisstr(c, rhs)) { + emitline("\tMOVQ\tAX, "); + emitoff((off + 8): i64); + emitline("(BP)\n"); + emitline("\tMOVQ\tBX, "); + emitoff((off + 16): i64); + emitline("(BP)\n"); } else { - emit_line("\tMOVQ\tAX, "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tAX, "); + emitoff((off + 8): i64); + emitline("(BP)\n"); }; - emit_line("\tMOVQ\t$"); - emit_int(tag_idx: i64); - emit_line(", "); - emit_off(off: i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\t$"); + emitint(tagidx: i64); + emitline(", "); + emitoff(off: i64); + emitline("(BP)\n"); c.last_was_return = 0; return; }; @@ -6237,53 +6237,53 @@ fn cgstmt(c: *cgen, n: *node) void = { if (trefn.kind == N_IDENT) { sname = trefn.str; } else { if (trefn.kind == N_TNAME) { sname = trefn.str; }; }; }; - let si: *struct_info = struct_lookup(c, sname); + let si: *structinfo = structlookup(c, sname); if (si != nil) { - let field_node: *node = rhs.list; - for (field_node != nil) { - if (field_node.kind == N_FIELD) { - let fname: str = field_node.str; - let fi: *field_info = si.fields; + let fieldnode: *node = rhs.list; + for (fieldnode != nil) { + if (fieldnode.kind == N_FIELD) { + let fname: str = fieldnode.str; + let fi: *fieldinfo = si.fields; for (fi != nil) { let fn_: str = fi.fname; if (streq(fn_, fname)) { - cgexpr(c, field_node.lhs); - let sop: str = field_store_op(fi); - emit_line("\t"); - emit_line(sop); - emit_line("\tAX, "); - emit_off((off + fi.foff): i64); - emit_line("(BP)\n"); + cgexpr(c, fieldnode.lhs); + let sop: str = fieldstoreop(fi); + emitline("\t"); + emitline(sop); + emitline("\tAX, "); + emitoff((off + fi.foff): i64); + emitline("(BP)\n"); fi = nil; } else { fi = fi.finext; }; }; }; - field_node = field_node.next; + fieldnode = fieldnode.next; }; c.last_was_return = 0; return; }; }; cgexpr(c, rhs); - emit_line("\tMOVQ\tAX, "); - emit_off(off: i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tAX, "); + emitoff(off: i64); + emitline("(BP)\n"); // str init: cgexpr also leaves len in BX; store both. if (sz == 16) { - emit_line("\tMOVQ\tBX, "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tBX, "); + emitoff((off + 8): i64); + emitline("(BP)\n"); }; // slice init: ptr/len/cap in AX/BX/CX. if (sz == 24) { - emit_line("\tMOVQ\tBX, "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); - emit_line("\tMOVQ\tCX, "); - emit_off((off + 16): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tBX, "); + emitoff((off + 8): i64); + emitline("(BP)\n"); + emitline("\tMOVQ\tCX, "); + emitoff((off + 16): i64); + emitline("(BP)\n"); }; } else { // Bare `let x: T;` with no initializer. C cgen @@ -6291,13 +6291,13 @@ fn cgstmt(c: *cgen, n: *node) void = { // the underlying type's natural size is 8 — pointers, // i64/u64, function pointers, ints. Structs/arrays/ // slices/strings/tagged/tuples are left for per-field - // writes. ww's slot_size pads struct slots up to 8, + // writes. ww's slotsize pads struct slots up to 8, // so we can't just check sz == 8: walk the type AST // directly to make the same call. - if (type_is_8byte_primitive(c, n.lhs)) { - emit_line("\tMOVQ\t$0, "); - emit_off(off: i64); - emit_line("(BP)\n"); + if (typeis8byteprimitive(c, n.lhs)) { + emitline("\tMOVQ\t$0, "); + emitoff(off: i64); + emitline("(BP)\n"); }; }; c.last_was_return = 0; @@ -6308,18 +6308,18 @@ fn cgstmt(c: *cgen, n: *node) void = { let els: str = mklabel(c, "else"); let endl: str = mklabel(c, "end"); cgexpr(c, n.cond); - emit_line("\tCMPQ\t$0, AX\n"); - emit_line("\tJE\t"); - if (n.els != nil) { emit_line(els); } - else { emit_line(endl); }; - emit_line("\n"); + emitline("\tCMPQ\t$0, AX\n"); + emitline("\tJE\t"); + if (n.els != nil) { emitline(els); } + else { emitline(endl); }; + emitline("\n"); if (n.body != nil) { cgstmt(c, n.body); }; if (n.els != nil) { - emit_line("\tJMP\t"); emit_line(endl); emit_line("\n"); - emit_label(els); + emitline("\tJMP\t"); emitline(endl); emitline("\n"); + emitlabel(els); cgstmt(c, n.els); }; - emit_label(endl); + emitlabel(endl); c.last_was_return = 0; return; }; @@ -6333,11 +6333,11 @@ fn cgstmt(c: *cgen, n: *node) void = { if (n.lhs != nil) { cgstmt(c, n.lhs); }; - emit_label(topl); + emitlabel(topl); if (n.cond != nil) { cgexpr(c, n.cond); - emit_line("\tCMPQ\t$0, AX\n"); - emit_line("\tJE\t"); emit_line(endl); emit_line("\n"); + emitline("\tCMPQ\t$0, AX\n"); + emitline("\tJE\t"); emitline(endl); emitline("\n"); }; c.loop_end_buf[c.loop_top] = endl; @@ -6349,8 +6349,8 @@ fn cgstmt(c: *cgen, n: *node) void = { c.loop_top -= 1; if (n.rhs != nil) { cgexpr(c, n.rhs); }; - emit_line("\tJMP\t"); emit_line(topl); emit_line("\n"); - emit_label(endl); + emitline("\tJMP\t"); emitline(topl); emitline("\n"); + emitlabel(endl); c.last_was_return = 0; return; }; @@ -6362,28 +6362,28 @@ fn cgstmt(c: *cgen, n: *node) void = { // as C — no fixture uses >2 today). if (k == N_MASSIGN) { if (n.rhs != nil) { cgexpr(c, n.rhs); }; - emit_line("\tPUSHQ\tDX\n"); + emitline("\tPUSHQ\tDX\n"); let l0: *node = n.list; let l1: *node = nil; if (l0 != nil) { l1 = l0.next; }; if (l0 != nil) { if (l0.kind == N_IDENT) { - let off: i32 = local_find(c, l0.str); + let off: i32 = localfind(c, l0.str); if (off != 0) { - emit_line("\tMOVQ\tAX, "); - emit_off(off: i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tAX, "); + emitoff(off: i64); + emitline("(BP)\n"); }; }; }; - emit_line("\tPOPQ\tDX\n"); + emitline("\tPOPQ\tDX\n"); if (l1 != nil) { if (l1.kind == N_IDENT) { - let off: i32 = local_find(c, l1.str); + let off: i32 = localfind(c, l1.str); if (off != 0) { - emit_line("\tMOVQ\tDX, "); - emit_off(off: i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\tDX, "); + emitoff(off: i64); + emitline("(BP)\n"); }; }; }; @@ -6394,7 +6394,7 @@ fn cgstmt(c: *cgen, n: *node) void = { if (k == N_BREAK) { if (c.loop_top > 0) { let lbl: str = c.loop_end_buf[c.loop_top - 1]; - emit_line("\tJMP\t"); emit_line(lbl); emit_line("\n"); + emitline("\tJMP\t"); emitline(lbl); emitline("\n"); }; c.last_was_return = 0; return; @@ -6402,7 +6402,7 @@ fn cgstmt(c: *cgen, n: *node) void = { if (k == N_CONTINUE) { if (c.loop_top > 0) { let lbl: str = c.loop_cont_buf[c.loop_top - 1]; - emit_line("\tJMP\t"); emit_line(lbl); emit_line("\n"); + emitline("\tJMP\t"); emitline(lbl); emitline("\n"); }; c.last_was_return = 0; return; @@ -6413,10 +6413,10 @@ fn cgstmt(c: *cgen, n: *node) void = { // ---- function-level cgen --------------------------------------------- -// is_str_type — true when the type expr resolves (through any +// isstrtype — true when the type expr resolves (through any // `type X = str;` aliases) to `str`. Takes *cgen so it can walk the // alias chain registered at file load. -fn is_str_type_raw(t: *node) bool = { +fn isstrtyperaw(t: *node) bool = { if (t == nil) { return false; }; if (t.kind == N_TNAME) { let nm: str = t.str; @@ -6425,36 +6425,36 @@ fn is_str_type_raw(t: *node) bool = { return false; }; -fn is_str_type(c: *cgen, t: *node) bool = { - if (is_str_type_raw(t)) { return true; }; +fn isstrtype(c: *cgen, t: *node) bool = { + if (isstrtyperaw(t)) { return true; }; if (c == nil) { return false; }; - let r: *node = resolve_type(c, t); - return is_str_type_raw(r); + let r: *node = resolvetype(c, t); + return isstrtyperaw(r); }; -fn is_slice_type_raw(t: *node) bool = { +fn isslicetyperaw(t: *node) bool = { if (t == nil) { return false; }; if (t.kind == N_TSLICE) { return true; }; return false; }; -fn is_slice_type(c: *cgen, t: *node) bool = { - if (is_slice_type_raw(t)) { return true; }; +fn isslicetype(c: *cgen, t: *node) bool = { + if (isslicetyperaw(t)) { return true; }; if (c == nil) { return false; }; - let r: *node = resolve_type(c, t); - return is_slice_type_raw(r); + let r: *node = resolvetype(c, t); + return isslicetyperaw(r); }; -fn is_tagged_type(t: *node) bool = { +fn istaggedtype(t: *node) bool = { if (t == nil) { return false; }; if (t.kind == N_TTAGGED) { return true; }; return false; }; -// rhs_target_name — for a returned value, what's its declared (or +// rhstargetname — for a returned value, what's its declared (or // surface-inferred) type name? `expr: T` casts dictate T directly; // bare strlit/intlit fall back to a primitive name. -fn rhs_target_name(c: *cgen, rhs: *node) str = { +fn rhstargetname(c: *cgen, rhs: *node) str = { let nm: str; nm.ptr = nil; nm.len = 0; if (rhs == nil) { return nm; }; @@ -6467,7 +6467,7 @@ fn rhs_target_name(c: *cgen, rhs: *node) str = { }; if (rhs.kind == N_STRLIT) { return "str"; }; if (rhs.kind == N_IDENT) { - let lc: *local = local_find_node(c, rhs.str); + let lc: *local = localfindnode(c, rhs.str); if (lc != nil) { let tn: *node = lc.tnode; if (tn != nil) { @@ -6478,113 +6478,113 @@ fn rhs_target_name(c: *cgen, rhs: *node) str = { return nm; }; -// tagged_variant_index — given the tagged-union type expr and the +// taggedvariantindex — given the tagged-union type expr and the // returned value's surface type, find the matching variant's 0-based // index. Compare by exact type name first; if no match, fall back to // "any str-shape variant matches an str-typed value". -fn tagged_variant_index(c: *cgen, tagged: *node, rhs: *node) i32 = { +fn taggedvariantindex(c: *cgen, tagged: *node, rhs: *node) i32 = { if (tagged == nil) { return -1; }; if (rhs == nil) { return -1; }; - let want_name: str = rhs_target_name(c, rhs); - if (want_name.len > 0) { + let wantname: str = rhstargetname(c, rhs); + if (wantname.len > 0) { let v: *node = tagged.list; let idx: i32 = 0; for (v != nil) { if (v.kind == N_TNAME) { - if (streq(v.str, want_name)) { return idx; }; + if (streq(v.str, wantname)) { return idx; }; }; v = v.next; idx += 1; }; }; // Fallback: by str-shape (resolves aliases). - let want_str: bool = node_isstr(c, rhs); + let wantstr: bool = nodeisstr(c, rhs); let v: *node = tagged.list; let idx: i32 = 0; for (v != nil) { - let v_is_str: bool = false; + let visstr: bool = false; if (v.kind == N_TNAME) { - if (is_str_type(c, v)) { v_is_str = true; }; + if (isstrtype(c, v)) { visstr = true; }; }; - if (v_is_str == want_str) { return idx; }; + if (visstr == wantstr) { return idx; }; v = v.next; idx += 1; }; return -1; }; -fn cgfn_params(c: *cgen, params: *node) void = { +fn cgfnparams(c: *cgen, params: *node) void = { let p: *node = params; let idx: i32 = 0; for (p != nil) { if (p.kind == N_PARAM) { let nm: str = p.str; - if (is_tagged_type(p.lhs)) { + if (istaggedtype(p.lhs)) { // tagged-union param: passed in 3 regs (tag, v0, v1), // 24-byte slot. - let off: i32 = local_add(c, nm, 24, p.lhs); - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off(off: i64); - emit_line("(BP)\n"); + let off: i32 = localadd(c, nm, 24, p.lhs); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff(off: i64); + emitline("(BP)\n"); idx += 1; - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff((off + 8): i64); + emitline("(BP)\n"); idx += 1; - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off((off + 16): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff((off + 16): i64); + emitline("(BP)\n"); idx += 1; - } else { if (is_slice_type(c, p.lhs)) { + } else { if (isslicetype(c, p.lhs)) { // slice param: 3 regs (ptr, len, cap), 24-byte slot. - let off: i32 = local_add(c, nm, 24, p.lhs); - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off(off: i64); - emit_line("(BP)\n"); + let off: i32 = localadd(c, nm, 24, p.lhs); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff(off: i64); + emitline("(BP)\n"); idx += 1; - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff((off + 8): i64); + emitline("(BP)\n"); idx += 1; - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off((off + 16): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff((off + 16): i64); + emitline("(BP)\n"); idx += 1; - } else { if (is_str_type(c, p.lhs)) { + } else { if (isstrtype(c, p.lhs)) { // str param: passed in two regs (ptr, len). // Slot is 16 bytes; ptr at off+0, len at off+8. - let off: i32 = local_add(c, nm, 16, p.lhs); - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off(off: i64); - emit_line("(BP)\n"); + let off: i32 = localadd(c, nm, 16, p.lhs); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff(off: i64); + emitline("(BP)\n"); idx += 1; - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off((off + 8): i64); - emit_line("(BP)\n"); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff((off + 8): i64); + emitline("(BP)\n"); idx += 1; } else { - let off: i32 = local_add(c, nm, 8, p.lhs); - emit_line("\tMOVQ\t"); - emit_line(argreg_name(idx)); - emit_line(", "); - emit_off(off: i64); - emit_line("(BP)\n"); + let off: i32 = localadd(c, nm, 8, p.lhs); + emitline("\tMOVQ\t"); + emitline(argregname(idx)); + emitline(", "); + emitoff(off: i64); + emitline("(BP)\n"); idx += 1; };};}; }; @@ -6593,48 +6593,48 @@ fn cgfn_params(c: *cgen, params: *node) void = { }; fn cgfn(c: *cgen, fn_: *node) void = { - cgen_init(c, c.a); + cgeninit(c, c.a); c.fn_name = fn_.str; c.fn_ret = fn_.lhs; - emit_line("TEXT "); + emitline("TEXT "); let nm: str = fn_.str; os.write(1, nm.ptr, nm.len: u64); - emit_line(",$"); + emitline(",$"); // Pre-scan total frame: 24 bytes per slice param, 16 per str - // param, 8 per other param, plus per-let from scan_locals. - // Seed c.locals with param-name stubs so scan_locals dedups a + // param, 8 per other param, plus per-let from scanlocals. + // Seed c.locals with param-name stubs so scanlocals dedups a // re-declared `let ` in the body against the param's // slot (matches C cgen). Stubs get cleared before emission. - let scan_p: *node = fn_.list; + let scanp: *node = fn_.list; let frame: i32 = 0; - for (scan_p != nil) { - if (scan_p.kind == N_PARAM) { - if (is_tagged_type(scan_p.lhs)) { frame += 24; } - else { if (is_slice_type(c, scan_p.lhs)) { frame += 24; } - else { if (is_str_type(c, scan_p.lhs)) { frame += 16; } + for (scanp != nil) { + if (scanp.kind == N_PARAM) { + if (istaggedtype(scanp.lhs)) { frame += 24; } + else { if (isslicetype(c, scanp.lhs)) { frame += 24; } + else { if (isstrtype(c, scanp.lhs)) { frame += 16; } else { frame += 8; }; }; }; - scan_seen_mark(c, scan_p.str); + scanseenmark(c, scanp.str); }; - scan_p = scan_p.next; + scanp = scanp.next; }; - if (fn_.body != nil) { frame += scan_locals(c, fn_.body); }; + if (fn_.body != nil) { frame += scanlocals(c, fn_.body); }; // Drop the stubs so emission rebuilds c.locals with real offsets. c.locals = nil; if ((frame & 15) != 0) { frame = (frame + 15) & ~15; }; - emit_int(frame: i64); - emit_line("\n"); + emitint(frame: i64); + emitline("\n"); - emit_line("\tPUSHQ\tBP\n"); - emit_line("\tMOVQ\tSP, BP\n"); - emit_line("\tSUBQ\t$"); - emit_int(frame: i64); - emit_line(", SP\n"); + emitline("\tPUSHQ\tBP\n"); + emitline("\tMOVQ\tSP, BP\n"); + emitline("\tSUBQ\t$"); + emitint(frame: i64); + emitline(", SP\n"); - cgfn_params(c, fn_.list); + cgfnparams(c, fn_.list); c.last_was_return = 0; if (fn_.body != nil) { cgstmt(c, fn_.body); }; @@ -6642,24 +6642,24 @@ fn cgfn(c: *cgen, fn_: *node) void = { // Zero AX before the fall-through return — matches C cgen, // which always emits this so void-returning fns don't leak // a stale callee value to their caller. - emit_line("\tMOVQ\t$0, AX\n"); - emit_line("\tMOVQ\tBP, SP\n"); - emit_line("\tPOPQ\tBP\n"); - emit_line("\tRET\n"); + emitline("\tMOVQ\t$0, AX\n"); + emitline("\tMOVQ\tBP, SP\n"); + emitline("\tPOPQ\tBP\n"); + emitline("\tRET\n"); }; }; // ---- file-level entry ------------------------------------------------ -export fn cg_file(c: *cgen, file: *node) void = { +export fn cgfile(c: *cgen, file: *node) void = { if (file == nil) { return; }; c.strlits = nil; c.strlit_seq = 0; - collect_aliases(c, file); - collect_structs(c, file); - collect_defs(c, file); - collect_fnrets(c, file); - ffi_collect(c, file); + collectaliases(c, file); + collectstructs(c, file); + collectdefs(c, file); + collectfnrets(c, file); + fficollect(c, file); let d: *node = file.list; for (d != nil) { if (d.kind == N_FNDECL) { @@ -6669,8 +6669,8 @@ export fn cg_file(c: *cgen, file: *node) void = { }; d = d.next; }; - emit_data_section(c); - emit_def_constants(c, file); + emitdatasection(c); + emitdefconstants(c, file); }; // selfhost/cmd/wwdump/main.ww — ww-side port of cmd/wwdump/main.c. @@ -6800,10 +6800,10 @@ export fn main(argc: i32, argv: **u8) i32 = { let tc: tctx; typesinit(&tc, a); let ck: checker; - check_init(&ck, a, &tc); + checkinit(&ck, a, &tc); // Quiet by default; flip to 1 when debugging missing names. ck.verbose = 0; - check_file(&ck, f); + checkfile(&ck, f); // (close out the if-else chain — we'll close all braces below) // ": / resolved" os.write(1, argstr(path).ptr, argstrlen(path): u64); @@ -6822,8 +6822,8 @@ export fn main(argc: i32, argv: **u8) i32 = { parserinit(&ps, a, &l); let f: *node = parsefile(&ps); let cg: cgen; - cgen_init(&cg, a); - cg_file(&cg, f); + cgeninit(&cg, a); + cgfile(&cg, f); };};};}; if (l.errs > 0) { return 1; }; diff --git a/selfhost/cmd/wwdump/main.ww b/selfhost/cmd/wwdump/main.ww index 5aaa7c22..ad43edd2 100644 --- a/selfhost/cmd/wwdump/main.ww +++ b/selfhost/cmd/wwdump/main.ww @@ -125,10 +125,10 @@ export fn main(argc: i32, argv: **u8) i32 = { let tc: tctx; typesinit(&tc, a); let ck: checker; - check_init(&ck, a, &tc); + checkinit(&ck, a, &tc); // Quiet by default; flip to 1 when debugging missing names. ck.verbose = 0; - check_file(&ck, f); + checkfile(&ck, f); // (close out the if-else chain — we'll close all braces below) // ": / resolved" os.write(1, argstr(path).ptr, argstrlen(path): u64); @@ -147,8 +147,8 @@ export fn main(argc: i32, argv: **u8) i32 = { parserinit(&ps, a, &l); let f: *node = parsefile(&ps); let cg: cgen; - cgen_init(&cg, a); - cg_file(&cg, f); + cgeninit(&cg, a); + cgfile(&cg, f); };};};}; if (l.errs > 0) { return 1; }; diff --git a/selfhost/test/sym_link.ww b/selfhost/test/sym_link.ww index 1e18a8c7..ff48d9e2 100644 --- a/selfhost/test/sym_link.ww +++ b/selfhost/test/sym_link.ww @@ -16,28 +16,28 @@ export fn main() i32 = { if (s == nil) { return 2; }; let n1: str = "foo"; - let r1: *sym = scope_define(s, n1, SK_VAR, nil, nil); + let r1: *sym = scopedefine(s, n1, SK_VAR, nil, nil); if (r1 == nil) { return 3; }; let n2: str = "bar"; - let r2: *sym = scope_define(s, n2, SK_TYPE, nil, nil); + let r2: *sym = scopedefine(s, n2, SK_TYPE, nil, nil); if (r2 == nil) { return 4; }; // Duplicate define in same scope must fail. - let r3: *sym = scope_define(s, n1, SK_VAR, nil, nil); + let r3: *sym = scopedefine(s, n1, SK_VAR, nil, nil); if (r3 != nil) { return 5; }; - let l1: *sym = scope_lookup(s, n1); + let l1: *sym = scopelookup(s, n1); if (l1 == nil) { return 6; }; if (l1.skind != SK_VAR) { return 7; }; - let l2: *sym = scope_lookup(s, n2); + let l2: *sym = scopelookup(s, n2); if (l2 == nil) { return 8; }; if (l2.skind != SK_TYPE) { return 9; }; // Not-found lookup returns nil. let n3: str = "baz"; - let l3: *sym = scope_lookup(s, n3); + let l3: *sym = scopelookup(s, n3); if (l3 != nil) { return 10; }; freearena(a);