From fe32dedb08b9719f32457d931a311499d089c51a Mon Sep 17 00:00:00 2001 From: Hojun-Cho Date: Tue, 2 Jun 2026 19:56:48 +0900 Subject: [PATCH] lib/ww/lex: char-literals for lexer magic decimals (Wave-1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pure byte-id-neutral substitution of ASCII magic decimals with char literals across lex.ww (131) + tok.ww (19); regen w6c + wwdump combined.ww (lex is embedded in those two only). escape() out-values for \a (7) and \b (8) are now '\a'/'\b' — both the C bootstrap lexer (cmd/wcc/lex.c:160-161) and ww's own escape() map them, so the literals are value-equivalent and stage-symmetric. Digit-value arithmetic (parseint/parsef64/hexchar: c - '0' over u8) is left decimal: a rune/i32 char literal would promote the u8 operand and is not byte-id-neutral. Multi-byte type-suffix comments (i8../f64) are kept — they label more than a single char. --- lib/ww/lex/lex.ww | 260 +++++++++++------------ lib/ww/lex/tok.ww | 38 ++-- selfhost/cmd/w6c/main.combined.ww | 298 +++++++++++++-------------- selfhost/cmd/wwdump/main.combined.ww | 298 +++++++++++++-------------- 4 files changed, 447 insertions(+), 447 deletions(-) diff --git a/lib/ww/lex/lex.ww b/lib/ww/lex/lex.ww index f1894b0f..f9564c5d 100644 --- a/lib/ww/lex/lex.ww +++ b/lib/ww/lex/lex.ww @@ -24,25 +24,25 @@ import strings; // ascii::; ascii::isalpha + the '_' check live here instead. fn isidstart(c: rune) bool = { if (ascii.isalpha(c)) { return true; }; - if (c == 95) { return true; }; // '_' + if (c == '_') { return true; }; return false; }; fn isidpart(c: rune) bool = { if (ascii.isalnum(c)) { return true; }; - if (c == 95) { return true; }; + if (c == '_') { return true; }; return false; }; // hexval — value of `c` as a hex digit (0..15) or void if not a hex // digit. Used by string-literal `\xHH` escapes. fn hexval(c: rune) (i32 | void) = { - if (ascii.isdigit(c)) { return (c - 48): i32; }; - if (c >= 65) { - if (c <= 70) { return ((c - 65) + 10): i32; }; // 'A'..'F' + if (ascii.isdigit(c)) { return (c - '0'): i32; }; + if (c >= 'A') { + if (c <= 'F') { return ((c - 'A') + 10): i32; }; }; - if (c >= 97) { - if (c <= 102) { return ((c - 97) + 10): i32; }; // 'a'..'f' + if (c >= 'a') { + if (c <= 'f') { return ((c - 'a') + 10): i32; }; }; return; }; @@ -84,7 +84,7 @@ fn lget(l: *lex) i32 = { if (l.lpos >= l.srclen) { return -1; }; let c: i32 = srcb(l, l.lpos); l.lpos += 1u64; - if (c == 10) { // '\n' + if (c == '\n') { l.line += 1; l.col = 1; } else { @@ -135,23 +135,23 @@ fn skipws(l: *lex) bool = { for (true) { let c: i32 = lpeek(l, 0u64); if (c < 0) { return false; }; - if (c == 32) { lget(l); continue; }; - if (c == 9) { lget(l); continue; }; - if (c == 13) { lget(l); continue; }; - if (c == 10) { lget(l); continue; }; - if (c == 47) { // '/' + if (c == ' ') { lget(l); continue; }; + if (c == '\t') { lget(l); continue; }; + if (c == '\r') { lget(l); continue; }; + if (c == '\n') { lget(l); continue; }; + if (c == '/') { let c2: i32 = lpeek(l, 1u64); - if (c2 == 47) { + if (c2 == '/') { lget(l); lget(l); // consume '//' for (true) { let cx: i32 = lpeek(l, 0u64); if (cx < 0) { return false; }; - if (cx == 10) { break; }; + if (cx == '\n') { break; }; lget(l); }; continue; }; - if (c2 == 42) { // '*' + if (c2 == '*') { lget(l); lget(l); let prev: i32 = -1; for (true) { @@ -162,8 +162,8 @@ fn skipws(l: *lex) bool = { errat(l, &cp, "unterminated /* comment"); return false; }; - if (prev == 42) { - if (x == 47) { break; }; + if (prev == '*') { + if (x == '/') { break; }; }; prev = x; }; @@ -182,7 +182,7 @@ fn parseint(p: *u8, n: u64, base: i32, ok: *bool) u64 = { for (i < n) { let ix: i32 = i: i32; let c: u8 = p[ix]; - if (c == 95u8) { // '_' + if (c == '_') { i += 1u64; continue; }; @@ -213,18 +213,18 @@ fn parseint(p: *u8, n: u64, base: i32, ok: *bool) u64 = { fn escape(l: *lex, out: *i32) bool = { let c: i32 = lget(l); if (c < 0) { return false; }; - if (c == 110) { *out = 10; return true; }; - if (c == 116) { *out = 9; return true; }; - if (c == 114) { *out = 13; return true; }; - if (c == 92) { *out = 92; return true; }; - if (c == 39) { *out = 39; return true; }; - if (c == 34) { *out = 34; return true; }; - if (c == 48) { *out = 0; return true; }; - if (c == 97) { *out = 7; return true; }; - if (c == 98) { *out = 8; return true; }; - if (c == 102) { *out = 12; return true; }; - if (c == 118) { *out = 11; return true; }; - if (c == 120) { + if (c == 'n') { *out = '\n'; return true; }; + if (c == 't') { *out = '\t'; return true; }; + if (c == 'r') { *out = '\r'; return true; }; + if (c == '\\') { *out = '\\'; return true; }; + if (c == '\'') { *out = '\''; return true; }; + if (c == '"') { *out = '"'; return true; }; + if (c == '0') { *out = '\0'; return true; }; + if (c == 'a') { *out = '\a'; return true; }; + if (c == 'b') { *out = '\b'; return true; }; + if (c == 'f') { *out = '\f'; return true; }; + if (c == 'v') { *out = '\v'; return true; }; + if (c == 'x') { let hi: i32 = lget(l); let lo: i32 = lget(l); if (hi < 0) { return false; }; @@ -260,7 +260,7 @@ fn scandecimalrun(l: *lex) void = { let c: i32 = lpeek(l, 0u64); if (c < 0) { break; }; if (!ascii.isdigit(c: rune)) { - if (c != 95) { break; }; + if (c != '_') { break; }; }; lget(l); }; @@ -271,7 +271,7 @@ fn scanhexrun(l: *lex) void = { let c: i32 = lpeek(l, 0u64); if (c < 0) { break; }; if (!ascii.isxdigit(c: rune)) { - if (c != 95) { break; }; + if (c != '_') { break; }; }; lget(l); }; @@ -280,9 +280,9 @@ fn scanhexrun(l: *lex) void = { fn scanbinrun(l: *lex) void = { for (true) { let c: i32 = lpeek(l, 0u64); - if (c == 48) { lget(l); continue; }; - if (c == 49) { lget(l); continue; }; - if (c == 95) { lget(l); continue; }; + if (c == '0') { lget(l); continue; }; + if (c == '1') { lget(l); continue; }; + if (c == '_') { lget(l); continue; }; break; }; }; @@ -290,9 +290,9 @@ fn scanbinrun(l: *lex) void = { fn scanoctrun(l: *lex) void = { for (true) { let c: i32 = lpeek(l, 0u64); - if (c < 48) { break; }; - if (c > 55) { - if (c != 95) { break; }; + if (c < '0') { break; }; + if (c > '7') { + if (c != '_') { break; }; }; lget(l); }; @@ -301,11 +301,11 @@ fn scanoctrun(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' + if (e != 'e') { if (e != 'E') { return; }; }; lget(l); let s: i32 = lpeek(l, 0u64); - if (s == 43) { lget(l); } - else { if (s == 45) { lget(l); }; }; + if (s == '+') { lget(l); } + else { if (s == '-') { lget(l); }; }; for (true) { let c: i32 = lpeek(l, 0u64); if (c < 0) { break; }; @@ -334,7 +334,7 @@ fn parsef64(s: *u8, n: u64) f64 = { let frac: i64 = 0i64; let fscale: i64 = 1i64; if (i < n) { - if (s[i] == 46u8) { // '.' + if (s[i] == '.') { i += 1u64; for (i < n) { let b: u8 = s[i]; @@ -350,13 +350,13 @@ fn parsef64(s: *u8, n: u64) f64 = { let expneg: bool = false; if (i < n) { let e: u8 = s[i]; - if (e == 101u8 || e == 69u8) { // 'e' / 'E' + if (e == 'e' || e == 'E') { i += 1u64; if (i < n) { - if (s[i] == 45u8) { // '-' + if (s[i] == '-') { expneg = true; i += 1u64; - } else { if (s[i] == 43u8) { // '+' + } else { if (s[i] == '+') { i += 1u64; };}; }; @@ -402,25 +402,25 @@ fn lexnum(l: *lex, start: *pos, out: *tok) void = { let c0: i32 = lpeek(l, 0u64); let c1: i32 = lpeek(l, 1u64); - if (c0 == 48) { // '0' - if (c1 == 120) { // 'x' + if (c0 == '0') { + if (c1 == 'x') { lget(l); lget(l); base = 16; scanhexrun(l); - } else { if (c1 == 88) { // 'X' + } else { if (c1 == 'X') { lget(l); lget(l); base = 16; scanhexrun(l); - } else { if (c1 == 98) { // 'b' + } else { if (c1 == 'b') { lget(l); lget(l); base = 2; scanbinrun(l); - } else { if (c1 == 66) { // 'B' + } else { if (c1 == 'B') { lget(l); lget(l); base = 2; scanbinrun(l); - } else { if (c1 == 111) { // 'o' + } else { if (c1 == 'o') { lget(l); lget(l); base = 8; scanoctrun(l); - } else { if (c1 == 79) { // 'O' + } else { if (c1 == 'O') { lget(l); lget(l); base = 8; scanoctrun(l); } else { scandecimalrun(l); - if (lpeek(l, 0u64) == 46) { + if (lpeek(l, 0u64) == '.') { let after: i32 = lpeek(l, 1u64); - if (after >= 48) { - if (after <= 57) { + if (after >= '0') { + if (after <= '9') { isfloat = true; lget(l); scandecimalrun(l); @@ -431,10 +431,10 @@ fn lexnum(l: *lex, start: *pos, out: *tok) void = { };};};};};}; } else { scandecimalrun(l); - if (lpeek(l, 0u64) == 46) { + if (lpeek(l, 0u64) == '.') { let after: i32 = lpeek(l, 1u64); - if (after >= 48) { - if (after <= 57) { + if (after >= '0') { + if (after <= '9') { isfloat = true; lget(l); scandecimalrun(l); @@ -460,7 +460,7 @@ fn lexnum(l: *lex, start: *pos, out: *tok) void = { let j: u64 = 0u64; for (i < n) { let b: u8 = l.src[begin + i]; - if (b != 95u8) { // '_' + if (b != '_') { clean[j] = b; j += 1u64; }; @@ -503,27 +503,27 @@ fn lexnum(l: *lex, start: *pos, out: *tok) void = { let p: *u8 = l.src + sb; let isok: bool = false; if (sl == 2u64) { - if (p[0] == 105u8) { - if (p[1] == 56u8) { isok = true; }; // i8 + if (p[0] == 'i') { + if (p[1] == '8') { isok = true; }; // i8 }; - if (p[0] == 117u8) { - if (p[1] == 56u8) { isok = true; }; // u8 + if (p[0] == 'u') { + if (p[1] == '8') { isok = true; }; // u8 }; }; if (sl == 3u64) { - if (p[0] == 105u8) { - if (p[1] == 49u8) { if (p[2] == 54u8) { isok = true; }; }; // i16 - if (p[1] == 51u8) { if (p[2] == 50u8) { isok = true; }; }; // i32 - if (p[1] == 54u8) { if (p[2] == 52u8) { isok = true; }; }; // i64 + if (p[0] == 'i') { + if (p[1] == '1') { if (p[2] == '6') { isok = true; }; }; // i16 + if (p[1] == '3') { if (p[2] == '2') { isok = true; }; }; // i32 + if (p[1] == '6') { if (p[2] == '4') { isok = true; }; }; // i64 }; - if (p[0] == 117u8) { - if (p[1] == 49u8) { if (p[2] == 54u8) { isok = true; }; }; - if (p[1] == 51u8) { if (p[2] == 50u8) { isok = true; }; }; - if (p[1] == 54u8) { if (p[2] == 52u8) { isok = true; }; }; + if (p[0] == 'u') { + if (p[1] == '1') { if (p[2] == '6') { isok = true; }; }; + if (p[1] == '3') { if (p[2] == '2') { isok = true; }; }; + if (p[1] == '6') { if (p[2] == '4') { isok = true; }; }; }; - if (p[0] == 102u8) { - if (p[1] == 51u8) { if (p[2] == 50u8) { isok = true; }; }; // f32 - if (p[1] == 54u8) { if (p[2] == 52u8) { isok = true; }; }; // f64 + if (p[0] == 'f') { + if (p[1] == '3') { if (p[2] == '2') { isok = true; }; }; // f32 + if (p[1] == '6') { if (p[2] == '4') { isok = true; }; }; // f64 }; }; if (isok) { @@ -553,7 +553,7 @@ fn lexident(l: *lex, start: *pos, out: *tok) void = { out.col = start.col; // Bare '_' is the discard marker. `_x`, `_1` are normal idents. if (n == 1u64) { - if (p[0] == 95u8) { + if (p[0] == '_') { out.kind = tkind.TK_UNDER; let view: str; view.ptr = p; @@ -592,9 +592,9 @@ fn lexstr(l: *lex, start: *pos, out: *tok) void = { out.text = strings.dup(view); return; }; - if (c == 34) { lget(l); break; }; + if (c == '"') { lget(l); break; }; let ch: i32 = 0; - if (c == 92) { + if (c == '\\') { lget(l); if (!escape(l, &ch)) { ch = 0; }; } else { @@ -641,13 +641,13 @@ fn lexrune(l: *lex, start: *pos, out: *tok) void = { return; }; let ch: i32 = 0; - if (c == 92) { + if (c == '\\') { lget(l); if (!escape(l, &ch)) { ch = 0; }; } else { ch = lget(l); }; - if (lpeek(l, 0u64) != 39) { + if (lpeek(l, 0u64) != '\'') { errat(l, start, "rune literal missing closing '"); out.kind = tkind.TK_ERR; out.file = start.file; @@ -711,27 +711,27 @@ export fn lexnext(l: *lex, out: *tok) void = { if (ascii.isdigit(c: rune)) { lexnum(l, &start, out); return; }; }; - if (c == 34) { lget(l); lexstr(l, &start, out); return; }; - if (c == 39) { lget(l); lexrune(l, &start, out); return; }; + if (c == '"') { lget(l); lexstr(l, &start, out); return; }; + if (c == '\'') { lget(l); lexrune(l, &start, out); return; }; lget(l); - if (c == 40) { emitsimple(&start, tkind.TK_LPAREN, out); return; }; - if (c == 41) { emitsimple(&start, tkind.TK_RPAREN, out); return; }; - if (c == 123) { emitsimple(&start, tkind.TK_LBRACE, out); return; }; - if (c == 125) { emitsimple(&start, tkind.TK_RBRACE, out); return; }; - if (c == 91) { emitsimple(&start, tkind.TK_LBRACK, out); return; }; - if (c == 93) { emitsimple(&start, tkind.TK_RBRACK, out); return; }; - if (c == 44) { emitsimple(&start, tkind.TK_COMMA, out); return; }; - if (c == 59) { emitsimple(&start, tkind.TK_SEMI, out); return; }; - if (c == 58) { emitsimple(&start, tkind.TK_COLON, out); return; }; - if (c == 64) { emitsimple(&start, tkind.TK_AT, out); return; }; - if (c == 63) { emitsimple(&start, tkind.TK_QUESTION, out); return; }; - if (c == 126) { emitsimple(&start, tkind.TK_TILDE, out); return; }; + if (c == '(') { emitsimple(&start, tkind.TK_LPAREN, out); return; }; + if (c == ')') { emitsimple(&start, tkind.TK_RPAREN, out); return; }; + if (c == '{') { emitsimple(&start, tkind.TK_LBRACE, out); return; }; + if (c == '}') { emitsimple(&start, tkind.TK_RBRACE, out); return; }; + if (c == '[') { emitsimple(&start, tkind.TK_LBRACK, out); return; }; + if (c == ']') { emitsimple(&start, tkind.TK_RBRACK, out); return; }; + if (c == ',') { emitsimple(&start, tkind.TK_COMMA, out); return; }; + if (c == ';') { emitsimple(&start, tkind.TK_SEMI, out); return; }; + if (c == ':') { emitsimple(&start, tkind.TK_COLON, out); return; }; + if (c == '@') { emitsimple(&start, tkind.TK_AT, out); return; }; + if (c == '?') { emitsimple(&start, tkind.TK_QUESTION, out); return; }; + if (c == '~') { emitsimple(&start, tkind.TK_TILDE, out); return; }; - if (c == 46) { // '.' - if (lpeek(l, 0u64) == 46) { - if (lpeek(l, 1u64) == 46) { + if (c == '.') { + if (lpeek(l, 0u64) == '.') { + if (lpeek(l, 1u64) == '.') { lget(l); lget(l); emitsimple(&start, tkind.TK_ELLIPSIS, out); return; }; @@ -741,67 +741,67 @@ export fn lexnext(l: *lex, out: *tok) void = { emitsimple(&start, tkind.TK_DOT, out); return; }; - if (c == 43) { - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_PLUSEQ, out); return; }; + if (c == '+') { + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_PLUSEQ, out); return; }; emitsimple(&start, tkind.TK_PLUS, out); return; }; - if (c == 45) { - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_MINUSEQ, out); return; }; - if (lpeek(l, 0u64) == 62) { lget(l); emitsimple(&start, tkind.TK_ARROW, out); return; }; + if (c == '-') { + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_MINUSEQ, out); return; }; + if (lpeek(l, 0u64) == '>') { lget(l); emitsimple(&start, tkind.TK_ARROW, out); return; }; emitsimple(&start, tkind.TK_MINUS, out); return; }; - if (c == 42) { - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_STAREQ, out); return; }; + if (c == '*') { + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_STAREQ, out); return; }; emitsimple(&start, tkind.TK_STAR, out); return; }; - if (c == 47) { - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_SLASHEQ, out); return; }; + if (c == '/') { + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_SLASHEQ, out); return; }; emitsimple(&start, tkind.TK_SLASH, out); return; }; - if (c == 37) { - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_PERCENTEQ, out); return; }; + if (c == '%') { + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_PERCENTEQ, out); return; }; emitsimple(&start, tkind.TK_PERCENT, out); return; }; - if (c == 38) { - if (lpeek(l, 0u64) == 38) { lget(l); emitsimple(&start, tkind.TK_AND, out); return; }; - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_AMPEQ, out); return; }; + if (c == '&') { + if (lpeek(l, 0u64) == '&') { lget(l); emitsimple(&start, tkind.TK_AND, out); return; }; + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_AMPEQ, out); return; }; emitsimple(&start, tkind.TK_AMP, out); return; }; - if (c == 124) { - if (lpeek(l, 0u64) == 124) { lget(l); emitsimple(&start, tkind.TK_OR, out); return; }; - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_PIPEEQ, out); return; }; + if (c == '|') { + if (lpeek(l, 0u64) == '|') { lget(l); emitsimple(&start, tkind.TK_OR, out); return; }; + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_PIPEEQ, out); return; }; emitsimple(&start, tkind.TK_PIPE, out); return; }; - if (c == 94) { - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_CARETEQ, out); return; }; + if (c == '^') { + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_CARETEQ, out); return; }; emitsimple(&start, tkind.TK_CARET, out); return; }; - if (c == 61) { - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_EQ, out); return; }; - if (lpeek(l, 0u64) == 62) { lget(l); emitsimple(&start, tkind.TK_FATARROW, out); return; }; + if (c == '=') { + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_EQ, out); return; }; + if (lpeek(l, 0u64) == '>') { lget(l); emitsimple(&start, tkind.TK_FATARROW, out); return; }; emitsimple(&start, tkind.TK_ASSIGN, out); return; }; - if (c == 33) { - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_NEQ, out); return; }; + if (c == '!') { + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_NEQ, out); return; }; emitsimple(&start, tkind.TK_NOT, out); return; }; - if (c == 60) { - if (lpeek(l, 0u64) == 60) { + if (c == '<') { + if (lpeek(l, 0u64) == '<') { lget(l); - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_LSHIFTEQ, out); return; }; + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_LSHIFTEQ, out); return; }; emitsimple(&start, tkind.TK_LSHIFT, out); return; }; - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_LE, out); return; }; - if (lpeek(l, 0u64) == 45) { lget(l); emitsimple(&start, tkind.TK_LARROW, out); return; }; + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_LE, out); return; }; + if (lpeek(l, 0u64) == '-') { lget(l); emitsimple(&start, tkind.TK_LARROW, out); return; }; emitsimple(&start, tkind.TK_LT, out); return; }; - if (c == 62) { - if (lpeek(l, 0u64) == 62) { + if (c == '>') { + if (lpeek(l, 0u64) == '>') { lget(l); - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_RSHIFTEQ, out); return; }; + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_RSHIFTEQ, out); return; }; emitsimple(&start, tkind.TK_RSHIFT, out); return; }; - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_GE, out); return; }; + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_GE, out); return; }; emitsimple(&start, tkind.TK_GT, out); return; }; diff --git a/lib/ww/lex/tok.ww b/lib/ww/lex/tok.ww index 6e774115..f8b40bb9 100644 --- a/lib/ww/lex/tok.ww +++ b/lib/ww/lex/tok.ww @@ -323,34 +323,34 @@ fn hexchar(n: u8) u8 = { fn fputhex2(fd: i32, b: u8) void = { let out: [4]u8; - out[0] = 92u8; // '\\' - out[1] = 120u8; // 'x' + out[0] = '\\'; + out[1] = 'x'; out[2] = hexchar(b >> 4u8); out[3] = hexchar(b & 15u8); os.write(fd, out.ptr, 4u64); }; fn fputq(fd: i32, p: *u8, n: i32) void = { - fputcbyte(fd, 34u8); // '"' + fputcbyte(fd, '"'); let i: i32 = 0; for (i < n) { let c: u8 = p[i]; - if (c == 92u8) { // '\\' + if (c == '\\') { fputsstr(fd, "\\\\"); } else { - if (c == 34u8) { // '"' + if (c == '"') { fputsstr(fd, "\\\""); } else { - if (c == 10u8) { // '\n' + if (c == '\n') { fputsstr(fd, "\\n"); } else { - if (c == 9u8) { // '\t' + if (c == '\t') { fputsstr(fd, "\\t"); } else { - if (c == 13u8) { // '\r' + if (c == '\r') { fputsstr(fd, "\\r"); } else { - if (c < 32u8) { + if (c < ' ') { fputhex2(fd, c); } else { if (c == 127u8) { @@ -366,7 +366,7 @@ fn fputq(fd: i32, p: *u8, n: i32) void = { }; i += 1; }; - fputcbyte(fd, 34u8); + fputcbyte(fd, '"'); }; // tokprint — write one token line to fd. Format must match @@ -386,30 +386,30 @@ export fn tokprint(fd: i32, t: *tok) void = { } else { fputsstr(fd, ""); }; - fputcbyte(fd, 58u8); // ':' + fputcbyte(fd, ':'); let ls: str = strconv.i64tos(t.line: i64, strconv.base.DEC); os.write(fd, ls.ptr, ls.len: u64); - fputcbyte(fd, 58u8); + fputcbyte(fd, ':'); let cs: str = strconv.i64tos(t.col: i64, strconv.base.DEC); os.write(fd, cs.ptr, cs.len: u64); - fputcbyte(fd, 32u8); // ' ' + fputcbyte(fd, ' '); fputsstr(fd, tokname(t.kind)); if (t.kind == tkind.TK_IDENT) { - fputcbyte(fd, 32u8); + fputcbyte(fd, ' '); fputq(fd, ttext.ptr, ttext.len); } else { if (t.kind == tkind.TK_STR) { - fputcbyte(fd, 32u8); + fputcbyte(fd, ' '); fputq(fd, ttext.ptr, ttext.len); } else { if (t.kind == tkind.TK_ERR) { - fputcbyte(fd, 32u8); + fputcbyte(fd, ' '); fputq(fd, ttext.ptr, ttext.len); } else { if (t.kind == tkind.TK_INT) { - fputcbyte(fd, 32u8); + fputcbyte(fd, ' '); let us: str = strconv.u64tos(t.uval, strconv.base.DEC); os.write(fd, us.ptr, us.len: u64); } else { if (t.kind == tkind.TK_RUNE) { - fputcbyte(fd, 32u8); + fputcbyte(fd, ' '); let us: str = strconv.u64tos(t.uval, strconv.base.DEC); os.write(fd, us.ptr, us.len: u64); };};};};}; @@ -417,5 +417,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. - fputcbyte(fd, 10u8); // '\n' + fputcbyte(fd, '\n'); }; diff --git a/selfhost/cmd/w6c/main.combined.ww b/selfhost/cmd/w6c/main.combined.ww index 6163794c..5d68a199 100644 --- a/selfhost/cmd/w6c/main.combined.ww +++ b/selfhost/cmd/w6c/main.combined.ww @@ -6700,34 +6700,34 @@ fn hexchar(n: u8) u8 = { fn fputhex2(fd: i32, b: u8) void = { let out: [4]u8; - out[0] = 92u8; // '\\' - out[1] = 120u8; // 'x' + out[0] = '\\'; + out[1] = 'x'; out[2] = hexchar(b >> 4u8); out[3] = hexchar(b & 15u8); os.write(fd, out.ptr, 4u64); }; fn fputq(fd: i32, p: *u8, n: i32) void = { - fputcbyte(fd, 34u8); // '"' + fputcbyte(fd, '"'); let i: i32 = 0; for (i < n) { let c: u8 = p[i]; - if (c == 92u8) { // '\\' + if (c == '\\') { fputsstr(fd, "\\\\"); } else { - if (c == 34u8) { // '"' + if (c == '"') { fputsstr(fd, "\\\""); } else { - if (c == 10u8) { // '\n' + if (c == '\n') { fputsstr(fd, "\\n"); } else { - if (c == 9u8) { // '\t' + if (c == '\t') { fputsstr(fd, "\\t"); } else { - if (c == 13u8) { // '\r' + if (c == '\r') { fputsstr(fd, "\\r"); } else { - if (c < 32u8) { + if (c < ' ') { fputhex2(fd, c); } else { if (c == 127u8) { @@ -6743,7 +6743,7 @@ fn fputq(fd: i32, p: *u8, n: i32) void = { }; i += 1; }; - fputcbyte(fd, 34u8); + fputcbyte(fd, '"'); }; // tokprint — write one token line to fd. Format must match @@ -6763,30 +6763,30 @@ export fn tokprint(fd: i32, t: *tok) void = { } else { fputsstr(fd, ""); }; - fputcbyte(fd, 58u8); // ':' + fputcbyte(fd, ':'); let ls: str = strconv.i64tos(t.line: i64, strconv.base.DEC); os.write(fd, ls.ptr, ls.len: u64); - fputcbyte(fd, 58u8); + fputcbyte(fd, ':'); let cs: str = strconv.i64tos(t.col: i64, strconv.base.DEC); os.write(fd, cs.ptr, cs.len: u64); - fputcbyte(fd, 32u8); // ' ' + fputcbyte(fd, ' '); fputsstr(fd, tokname(t.kind)); if (t.kind == tkind.TK_IDENT) { - fputcbyte(fd, 32u8); + fputcbyte(fd, ' '); fputq(fd, ttext.ptr, ttext.len); } else { if (t.kind == tkind.TK_STR) { - fputcbyte(fd, 32u8); + fputcbyte(fd, ' '); fputq(fd, ttext.ptr, ttext.len); } else { if (t.kind == tkind.TK_ERR) { - fputcbyte(fd, 32u8); + fputcbyte(fd, ' '); fputq(fd, ttext.ptr, ttext.len); } else { if (t.kind == tkind.TK_INT) { - fputcbyte(fd, 32u8); + fputcbyte(fd, ' '); let us: str = strconv.u64tos(t.uval, strconv.base.DEC); os.write(fd, us.ptr, us.len: u64); } else { if (t.kind == tkind.TK_RUNE) { - fputcbyte(fd, 32u8); + fputcbyte(fd, ' '); let us: str = strconv.u64tos(t.uval, strconv.base.DEC); os.write(fd, us.ptr, us.len: u64); };};};};}; @@ -6794,7 +6794,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. - fputcbyte(fd, 10u8); // '\n' + fputcbyte(fd, '\n'); }; // lib/ww/lex/lex.ww — port of cmd/wcc/lex.c. @@ -6823,25 +6823,25 @@ import strings; // ascii::; ascii::isalpha + the '_' check live here instead. fn isidstart(c: rune) bool = { if (ascii.isalpha(c)) { return true; }; - if (c == 95) { return true; }; // '_' + if (c == '_') { return true; }; return false; }; fn isidpart(c: rune) bool = { if (ascii.isalnum(c)) { return true; }; - if (c == 95) { return true; }; + if (c == '_') { return true; }; return false; }; // hexval — value of `c` as a hex digit (0..15) or void if not a hex // digit. Used by string-literal `\xHH` escapes. fn hexval(c: rune) (i32 | void) = { - if (ascii.isdigit(c)) { return (c - 48): i32; }; - if (c >= 65) { - if (c <= 70) { return ((c - 65) + 10): i32; }; // 'A'..'F' + if (ascii.isdigit(c)) { return (c - '0'): i32; }; + if (c >= 'A') { + if (c <= 'F') { return ((c - 'A') + 10): i32; }; }; - if (c >= 97) { - if (c <= 102) { return ((c - 97) + 10): i32; }; // 'a'..'f' + if (c >= 'a') { + if (c <= 'f') { return ((c - 'a') + 10): i32; }; }; return; }; @@ -6883,7 +6883,7 @@ fn lget(l: *lex) i32 = { if (l.lpos >= l.srclen) { return -1; }; let c: i32 = srcb(l, l.lpos); l.lpos += 1u64; - if (c == 10) { // '\n' + if (c == '\n') { l.line += 1; l.col = 1; } else { @@ -6934,23 +6934,23 @@ fn skipws(l: *lex) bool = { for (true) { let c: i32 = lpeek(l, 0u64); if (c < 0) { return false; }; - if (c == 32) { lget(l); continue; }; - if (c == 9) { lget(l); continue; }; - if (c == 13) { lget(l); continue; }; - if (c == 10) { lget(l); continue; }; - if (c == 47) { // '/' + if (c == ' ') { lget(l); continue; }; + if (c == '\t') { lget(l); continue; }; + if (c == '\r') { lget(l); continue; }; + if (c == '\n') { lget(l); continue; }; + if (c == '/') { let c2: i32 = lpeek(l, 1u64); - if (c2 == 47) { + if (c2 == '/') { lget(l); lget(l); // consume '//' for (true) { let cx: i32 = lpeek(l, 0u64); if (cx < 0) { return false; }; - if (cx == 10) { break; }; + if (cx == '\n') { break; }; lget(l); }; continue; }; - if (c2 == 42) { // '*' + if (c2 == '*') { lget(l); lget(l); let prev: i32 = -1; for (true) { @@ -6961,8 +6961,8 @@ fn skipws(l: *lex) bool = { errat(l, &cp, "unterminated /* comment"); return false; }; - if (prev == 42) { - if (x == 47) { break; }; + if (prev == '*') { + if (x == '/') { break; }; }; prev = x; }; @@ -6981,7 +6981,7 @@ fn parseint(p: *u8, n: u64, base: i32, ok: *bool) u64 = { for (i < n) { let ix: i32 = i: i32; let c: u8 = p[ix]; - if (c == 95u8) { // '_' + if (c == '_') { i += 1u64; continue; }; @@ -7012,18 +7012,18 @@ fn parseint(p: *u8, n: u64, base: i32, ok: *bool) u64 = { fn escape(l: *lex, out: *i32) bool = { let c: i32 = lget(l); if (c < 0) { return false; }; - if (c == 110) { *out = 10; return true; }; - if (c == 116) { *out = 9; return true; }; - if (c == 114) { *out = 13; return true; }; - if (c == 92) { *out = 92; return true; }; - if (c == 39) { *out = 39; return true; }; - if (c == 34) { *out = 34; return true; }; - if (c == 48) { *out = 0; return true; }; - if (c == 97) { *out = 7; return true; }; - if (c == 98) { *out = 8; return true; }; - if (c == 102) { *out = 12; return true; }; - if (c == 118) { *out = 11; return true; }; - if (c == 120) { + if (c == 'n') { *out = '\n'; return true; }; + if (c == 't') { *out = '\t'; return true; }; + if (c == 'r') { *out = '\r'; return true; }; + if (c == '\\') { *out = '\\'; return true; }; + if (c == '\'') { *out = '\''; return true; }; + if (c == '"') { *out = '"'; return true; }; + if (c == '0') { *out = '\0'; return true; }; + if (c == 'a') { *out = '\a'; return true; }; + if (c == 'b') { *out = '\b'; return true; }; + if (c == 'f') { *out = '\f'; return true; }; + if (c == 'v') { *out = '\v'; return true; }; + if (c == 'x') { let hi: i32 = lget(l); let lo: i32 = lget(l); if (hi < 0) { return false; }; @@ -7059,7 +7059,7 @@ fn scandecimalrun(l: *lex) void = { let c: i32 = lpeek(l, 0u64); if (c < 0) { break; }; if (!ascii.isdigit(c: rune)) { - if (c != 95) { break; }; + if (c != '_') { break; }; }; lget(l); }; @@ -7070,7 +7070,7 @@ fn scanhexrun(l: *lex) void = { let c: i32 = lpeek(l, 0u64); if (c < 0) { break; }; if (!ascii.isxdigit(c: rune)) { - if (c != 95) { break; }; + if (c != '_') { break; }; }; lget(l); }; @@ -7079,9 +7079,9 @@ fn scanhexrun(l: *lex) void = { fn scanbinrun(l: *lex) void = { for (true) { let c: i32 = lpeek(l, 0u64); - if (c == 48) { lget(l); continue; }; - if (c == 49) { lget(l); continue; }; - if (c == 95) { lget(l); continue; }; + if (c == '0') { lget(l); continue; }; + if (c == '1') { lget(l); continue; }; + if (c == '_') { lget(l); continue; }; break; }; }; @@ -7089,9 +7089,9 @@ fn scanbinrun(l: *lex) void = { fn scanoctrun(l: *lex) void = { for (true) { let c: i32 = lpeek(l, 0u64); - if (c < 48) { break; }; - if (c > 55) { - if (c != 95) { break; }; + if (c < '0') { break; }; + if (c > '7') { + if (c != '_') { break; }; }; lget(l); }; @@ -7100,11 +7100,11 @@ fn scanoctrun(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' + if (e != 'e') { if (e != 'E') { return; }; }; lget(l); let s: i32 = lpeek(l, 0u64); - if (s == 43) { lget(l); } - else { if (s == 45) { lget(l); }; }; + if (s == '+') { lget(l); } + else { if (s == '-') { lget(l); }; }; for (true) { let c: i32 = lpeek(l, 0u64); if (c < 0) { break; }; @@ -7133,7 +7133,7 @@ fn parsef64(s: *u8, n: u64) f64 = { let frac: i64 = 0i64; let fscale: i64 = 1i64; if (i < n) { - if (s[i] == 46u8) { // '.' + if (s[i] == '.') { i += 1u64; for (i < n) { let b: u8 = s[i]; @@ -7149,13 +7149,13 @@ fn parsef64(s: *u8, n: u64) f64 = { let expneg: bool = false; if (i < n) { let e: u8 = s[i]; - if (e == 101u8 || e == 69u8) { // 'e' / 'E' + if (e == 'e' || e == 'E') { i += 1u64; if (i < n) { - if (s[i] == 45u8) { // '-' + if (s[i] == '-') { expneg = true; i += 1u64; - } else { if (s[i] == 43u8) { // '+' + } else { if (s[i] == '+') { i += 1u64; };}; }; @@ -7201,25 +7201,25 @@ fn lexnum(l: *lex, start: *pos, out: *tok) void = { let c0: i32 = lpeek(l, 0u64); let c1: i32 = lpeek(l, 1u64); - if (c0 == 48) { // '0' - if (c1 == 120) { // 'x' + if (c0 == '0') { + if (c1 == 'x') { lget(l); lget(l); base = 16; scanhexrun(l); - } else { if (c1 == 88) { // 'X' + } else { if (c1 == 'X') { lget(l); lget(l); base = 16; scanhexrun(l); - } else { if (c1 == 98) { // 'b' + } else { if (c1 == 'b') { lget(l); lget(l); base = 2; scanbinrun(l); - } else { if (c1 == 66) { // 'B' + } else { if (c1 == 'B') { lget(l); lget(l); base = 2; scanbinrun(l); - } else { if (c1 == 111) { // 'o' + } else { if (c1 == 'o') { lget(l); lget(l); base = 8; scanoctrun(l); - } else { if (c1 == 79) { // 'O' + } else { if (c1 == 'O') { lget(l); lget(l); base = 8; scanoctrun(l); } else { scandecimalrun(l); - if (lpeek(l, 0u64) == 46) { + if (lpeek(l, 0u64) == '.') { let after: i32 = lpeek(l, 1u64); - if (after >= 48) { - if (after <= 57) { + if (after >= '0') { + if (after <= '9') { isfloat = true; lget(l); scandecimalrun(l); @@ -7230,10 +7230,10 @@ fn lexnum(l: *lex, start: *pos, out: *tok) void = { };};};};};}; } else { scandecimalrun(l); - if (lpeek(l, 0u64) == 46) { + if (lpeek(l, 0u64) == '.') { let after: i32 = lpeek(l, 1u64); - if (after >= 48) { - if (after <= 57) { + if (after >= '0') { + if (after <= '9') { isfloat = true; lget(l); scandecimalrun(l); @@ -7259,7 +7259,7 @@ fn lexnum(l: *lex, start: *pos, out: *tok) void = { let j: u64 = 0u64; for (i < n) { let b: u8 = l.src[begin + i]; - if (b != 95u8) { // '_' + if (b != '_') { clean[j] = b; j += 1u64; }; @@ -7302,27 +7302,27 @@ fn lexnum(l: *lex, start: *pos, out: *tok) void = { let p: *u8 = l.src + sb; let isok: bool = false; if (sl == 2u64) { - if (p[0] == 105u8) { - if (p[1] == 56u8) { isok = true; }; // i8 + if (p[0] == 'i') { + if (p[1] == '8') { isok = true; }; // i8 }; - if (p[0] == 117u8) { - if (p[1] == 56u8) { isok = true; }; // u8 + if (p[0] == 'u') { + if (p[1] == '8') { isok = true; }; // u8 }; }; if (sl == 3u64) { - if (p[0] == 105u8) { - if (p[1] == 49u8) { if (p[2] == 54u8) { isok = true; }; }; // i16 - if (p[1] == 51u8) { if (p[2] == 50u8) { isok = true; }; }; // i32 - if (p[1] == 54u8) { if (p[2] == 52u8) { isok = true; }; }; // i64 + if (p[0] == 'i') { + if (p[1] == '1') { if (p[2] == '6') { isok = true; }; }; // i16 + if (p[1] == '3') { if (p[2] == '2') { isok = true; }; }; // i32 + if (p[1] == '6') { if (p[2] == '4') { isok = true; }; }; // i64 }; - if (p[0] == 117u8) { - if (p[1] == 49u8) { if (p[2] == 54u8) { isok = true; }; }; - if (p[1] == 51u8) { if (p[2] == 50u8) { isok = true; }; }; - if (p[1] == 54u8) { if (p[2] == 52u8) { isok = true; }; }; + if (p[0] == 'u') { + if (p[1] == '1') { if (p[2] == '6') { isok = true; }; }; + if (p[1] == '3') { if (p[2] == '2') { isok = true; }; }; + if (p[1] == '6') { if (p[2] == '4') { isok = true; }; }; }; - if (p[0] == 102u8) { - if (p[1] == 51u8) { if (p[2] == 50u8) { isok = true; }; }; // f32 - if (p[1] == 54u8) { if (p[2] == 52u8) { isok = true; }; }; // f64 + if (p[0] == 'f') { + if (p[1] == '3') { if (p[2] == '2') { isok = true; }; }; // f32 + if (p[1] == '6') { if (p[2] == '4') { isok = true; }; }; // f64 }; }; if (isok) { @@ -7352,7 +7352,7 @@ fn lexident(l: *lex, start: *pos, out: *tok) void = { out.col = start.col; // Bare '_' is the discard marker. `_x`, `_1` are normal idents. if (n == 1u64) { - if (p[0] == 95u8) { + if (p[0] == '_') { out.kind = tkind.TK_UNDER; let view: str; view.ptr = p; @@ -7391,9 +7391,9 @@ fn lexstr(l: *lex, start: *pos, out: *tok) void = { out.text = strings.dup(view); return; }; - if (c == 34) { lget(l); break; }; + if (c == '"') { lget(l); break; }; let ch: i32 = 0; - if (c == 92) { + if (c == '\\') { lget(l); if (!escape(l, &ch)) { ch = 0; }; } else { @@ -7440,13 +7440,13 @@ fn lexrune(l: *lex, start: *pos, out: *tok) void = { return; }; let ch: i32 = 0; - if (c == 92) { + if (c == '\\') { lget(l); if (!escape(l, &ch)) { ch = 0; }; } else { ch = lget(l); }; - if (lpeek(l, 0u64) != 39) { + if (lpeek(l, 0u64) != '\'') { errat(l, start, "rune literal missing closing '"); out.kind = tkind.TK_ERR; out.file = start.file; @@ -7510,27 +7510,27 @@ export fn lexnext(l: *lex, out: *tok) void = { if (ascii.isdigit(c: rune)) { lexnum(l, &start, out); return; }; }; - if (c == 34) { lget(l); lexstr(l, &start, out); return; }; - if (c == 39) { lget(l); lexrune(l, &start, out); return; }; + if (c == '"') { lget(l); lexstr(l, &start, out); return; }; + if (c == '\'') { lget(l); lexrune(l, &start, out); return; }; lget(l); - if (c == 40) { emitsimple(&start, tkind.TK_LPAREN, out); return; }; - if (c == 41) { emitsimple(&start, tkind.TK_RPAREN, out); return; }; - if (c == 123) { emitsimple(&start, tkind.TK_LBRACE, out); return; }; - if (c == 125) { emitsimple(&start, tkind.TK_RBRACE, out); return; }; - if (c == 91) { emitsimple(&start, tkind.TK_LBRACK, out); return; }; - if (c == 93) { emitsimple(&start, tkind.TK_RBRACK, out); return; }; - if (c == 44) { emitsimple(&start, tkind.TK_COMMA, out); return; }; - if (c == 59) { emitsimple(&start, tkind.TK_SEMI, out); return; }; - if (c == 58) { emitsimple(&start, tkind.TK_COLON, out); return; }; - if (c == 64) { emitsimple(&start, tkind.TK_AT, out); return; }; - if (c == 63) { emitsimple(&start, tkind.TK_QUESTION, out); return; }; - if (c == 126) { emitsimple(&start, tkind.TK_TILDE, out); return; }; + if (c == '(') { emitsimple(&start, tkind.TK_LPAREN, out); return; }; + if (c == ')') { emitsimple(&start, tkind.TK_RPAREN, out); return; }; + if (c == '{') { emitsimple(&start, tkind.TK_LBRACE, out); return; }; + if (c == '}') { emitsimple(&start, tkind.TK_RBRACE, out); return; }; + if (c == '[') { emitsimple(&start, tkind.TK_LBRACK, out); return; }; + if (c == ']') { emitsimple(&start, tkind.TK_RBRACK, out); return; }; + if (c == ',') { emitsimple(&start, tkind.TK_COMMA, out); return; }; + if (c == ';') { emitsimple(&start, tkind.TK_SEMI, out); return; }; + if (c == ':') { emitsimple(&start, tkind.TK_COLON, out); return; }; + if (c == '@') { emitsimple(&start, tkind.TK_AT, out); return; }; + if (c == '?') { emitsimple(&start, tkind.TK_QUESTION, out); return; }; + if (c == '~') { emitsimple(&start, tkind.TK_TILDE, out); return; }; - if (c == 46) { // '.' - if (lpeek(l, 0u64) == 46) { - if (lpeek(l, 1u64) == 46) { + if (c == '.') { + if (lpeek(l, 0u64) == '.') { + if (lpeek(l, 1u64) == '.') { lget(l); lget(l); emitsimple(&start, tkind.TK_ELLIPSIS, out); return; }; @@ -7540,67 +7540,67 @@ export fn lexnext(l: *lex, out: *tok) void = { emitsimple(&start, tkind.TK_DOT, out); return; }; - if (c == 43) { - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_PLUSEQ, out); return; }; + if (c == '+') { + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_PLUSEQ, out); return; }; emitsimple(&start, tkind.TK_PLUS, out); return; }; - if (c == 45) { - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_MINUSEQ, out); return; }; - if (lpeek(l, 0u64) == 62) { lget(l); emitsimple(&start, tkind.TK_ARROW, out); return; }; + if (c == '-') { + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_MINUSEQ, out); return; }; + if (lpeek(l, 0u64) == '>') { lget(l); emitsimple(&start, tkind.TK_ARROW, out); return; }; emitsimple(&start, tkind.TK_MINUS, out); return; }; - if (c == 42) { - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_STAREQ, out); return; }; + if (c == '*') { + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_STAREQ, out); return; }; emitsimple(&start, tkind.TK_STAR, out); return; }; - if (c == 47) { - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_SLASHEQ, out); return; }; + if (c == '/') { + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_SLASHEQ, out); return; }; emitsimple(&start, tkind.TK_SLASH, out); return; }; - if (c == 37) { - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_PERCENTEQ, out); return; }; + if (c == '%') { + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_PERCENTEQ, out); return; }; emitsimple(&start, tkind.TK_PERCENT, out); return; }; - if (c == 38) { - if (lpeek(l, 0u64) == 38) { lget(l); emitsimple(&start, tkind.TK_AND, out); return; }; - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_AMPEQ, out); return; }; + if (c == '&') { + if (lpeek(l, 0u64) == '&') { lget(l); emitsimple(&start, tkind.TK_AND, out); return; }; + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_AMPEQ, out); return; }; emitsimple(&start, tkind.TK_AMP, out); return; }; - if (c == 124) { - if (lpeek(l, 0u64) == 124) { lget(l); emitsimple(&start, tkind.TK_OR, out); return; }; - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_PIPEEQ, out); return; }; + if (c == '|') { + if (lpeek(l, 0u64) == '|') { lget(l); emitsimple(&start, tkind.TK_OR, out); return; }; + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_PIPEEQ, out); return; }; emitsimple(&start, tkind.TK_PIPE, out); return; }; - if (c == 94) { - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_CARETEQ, out); return; }; + if (c == '^') { + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_CARETEQ, out); return; }; emitsimple(&start, tkind.TK_CARET, out); return; }; - if (c == 61) { - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_EQ, out); return; }; - if (lpeek(l, 0u64) == 62) { lget(l); emitsimple(&start, tkind.TK_FATARROW, out); return; }; + if (c == '=') { + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_EQ, out); return; }; + if (lpeek(l, 0u64) == '>') { lget(l); emitsimple(&start, tkind.TK_FATARROW, out); return; }; emitsimple(&start, tkind.TK_ASSIGN, out); return; }; - if (c == 33) { - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_NEQ, out); return; }; + if (c == '!') { + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_NEQ, out); return; }; emitsimple(&start, tkind.TK_NOT, out); return; }; - if (c == 60) { - if (lpeek(l, 0u64) == 60) { + if (c == '<') { + if (lpeek(l, 0u64) == '<') { lget(l); - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_LSHIFTEQ, out); return; }; + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_LSHIFTEQ, out); return; }; emitsimple(&start, tkind.TK_LSHIFT, out); return; }; - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_LE, out); return; }; - if (lpeek(l, 0u64) == 45) { lget(l); emitsimple(&start, tkind.TK_LARROW, out); return; }; + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_LE, out); return; }; + if (lpeek(l, 0u64) == '-') { lget(l); emitsimple(&start, tkind.TK_LARROW, out); return; }; emitsimple(&start, tkind.TK_LT, out); return; }; - if (c == 62) { - if (lpeek(l, 0u64) == 62) { + if (c == '>') { + if (lpeek(l, 0u64) == '>') { lget(l); - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_RSHIFTEQ, out); return; }; + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_RSHIFTEQ, out); return; }; emitsimple(&start, tkind.TK_RSHIFT, out); return; }; - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_GE, out); return; }; + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_GE, out); return; }; emitsimple(&start, tkind.TK_GT, out); return; }; diff --git a/selfhost/cmd/wwdump/main.combined.ww b/selfhost/cmd/wwdump/main.combined.ww index 6ea44d46..2836b9a0 100644 --- a/selfhost/cmd/wwdump/main.combined.ww +++ b/selfhost/cmd/wwdump/main.combined.ww @@ -6700,34 +6700,34 @@ fn hexchar(n: u8) u8 = { fn fputhex2(fd: i32, b: u8) void = { let out: [4]u8; - out[0] = 92u8; // '\\' - out[1] = 120u8; // 'x' + out[0] = '\\'; + out[1] = 'x'; out[2] = hexchar(b >> 4u8); out[3] = hexchar(b & 15u8); os.write(fd, out.ptr, 4u64); }; fn fputq(fd: i32, p: *u8, n: i32) void = { - fputcbyte(fd, 34u8); // '"' + fputcbyte(fd, '"'); let i: i32 = 0; for (i < n) { let c: u8 = p[i]; - if (c == 92u8) { // '\\' + if (c == '\\') { fputsstr(fd, "\\\\"); } else { - if (c == 34u8) { // '"' + if (c == '"') { fputsstr(fd, "\\\""); } else { - if (c == 10u8) { // '\n' + if (c == '\n') { fputsstr(fd, "\\n"); } else { - if (c == 9u8) { // '\t' + if (c == '\t') { fputsstr(fd, "\\t"); } else { - if (c == 13u8) { // '\r' + if (c == '\r') { fputsstr(fd, "\\r"); } else { - if (c < 32u8) { + if (c < ' ') { fputhex2(fd, c); } else { if (c == 127u8) { @@ -6743,7 +6743,7 @@ fn fputq(fd: i32, p: *u8, n: i32) void = { }; i += 1; }; - fputcbyte(fd, 34u8); + fputcbyte(fd, '"'); }; // tokprint — write one token line to fd. Format must match @@ -6763,30 +6763,30 @@ export fn tokprint(fd: i32, t: *tok) void = { } else { fputsstr(fd, ""); }; - fputcbyte(fd, 58u8); // ':' + fputcbyte(fd, ':'); let ls: str = strconv.i64tos(t.line: i64, strconv.base.DEC); os.write(fd, ls.ptr, ls.len: u64); - fputcbyte(fd, 58u8); + fputcbyte(fd, ':'); let cs: str = strconv.i64tos(t.col: i64, strconv.base.DEC); os.write(fd, cs.ptr, cs.len: u64); - fputcbyte(fd, 32u8); // ' ' + fputcbyte(fd, ' '); fputsstr(fd, tokname(t.kind)); if (t.kind == tkind.TK_IDENT) { - fputcbyte(fd, 32u8); + fputcbyte(fd, ' '); fputq(fd, ttext.ptr, ttext.len); } else { if (t.kind == tkind.TK_STR) { - fputcbyte(fd, 32u8); + fputcbyte(fd, ' '); fputq(fd, ttext.ptr, ttext.len); } else { if (t.kind == tkind.TK_ERR) { - fputcbyte(fd, 32u8); + fputcbyte(fd, ' '); fputq(fd, ttext.ptr, ttext.len); } else { if (t.kind == tkind.TK_INT) { - fputcbyte(fd, 32u8); + fputcbyte(fd, ' '); let us: str = strconv.u64tos(t.uval, strconv.base.DEC); os.write(fd, us.ptr, us.len: u64); } else { if (t.kind == tkind.TK_RUNE) { - fputcbyte(fd, 32u8); + fputcbyte(fd, ' '); let us: str = strconv.u64tos(t.uval, strconv.base.DEC); os.write(fd, us.ptr, us.len: u64); };};};};}; @@ -6794,7 +6794,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. - fputcbyte(fd, 10u8); // '\n' + fputcbyte(fd, '\n'); }; // lib/ww/lex/lex.ww — port of cmd/wcc/lex.c. @@ -6823,25 +6823,25 @@ import strings; // ascii::; ascii::isalpha + the '_' check live here instead. fn isidstart(c: rune) bool = { if (ascii.isalpha(c)) { return true; }; - if (c == 95) { return true; }; // '_' + if (c == '_') { return true; }; return false; }; fn isidpart(c: rune) bool = { if (ascii.isalnum(c)) { return true; }; - if (c == 95) { return true; }; + if (c == '_') { return true; }; return false; }; // hexval — value of `c` as a hex digit (0..15) or void if not a hex // digit. Used by string-literal `\xHH` escapes. fn hexval(c: rune) (i32 | void) = { - if (ascii.isdigit(c)) { return (c - 48): i32; }; - if (c >= 65) { - if (c <= 70) { return ((c - 65) + 10): i32; }; // 'A'..'F' + if (ascii.isdigit(c)) { return (c - '0'): i32; }; + if (c >= 'A') { + if (c <= 'F') { return ((c - 'A') + 10): i32; }; }; - if (c >= 97) { - if (c <= 102) { return ((c - 97) + 10): i32; }; // 'a'..'f' + if (c >= 'a') { + if (c <= 'f') { return ((c - 'a') + 10): i32; }; }; return; }; @@ -6883,7 +6883,7 @@ fn lget(l: *lex) i32 = { if (l.lpos >= l.srclen) { return -1; }; let c: i32 = srcb(l, l.lpos); l.lpos += 1u64; - if (c == 10) { // '\n' + if (c == '\n') { l.line += 1; l.col = 1; } else { @@ -6934,23 +6934,23 @@ fn skipws(l: *lex) bool = { for (true) { let c: i32 = lpeek(l, 0u64); if (c < 0) { return false; }; - if (c == 32) { lget(l); continue; }; - if (c == 9) { lget(l); continue; }; - if (c == 13) { lget(l); continue; }; - if (c == 10) { lget(l); continue; }; - if (c == 47) { // '/' + if (c == ' ') { lget(l); continue; }; + if (c == '\t') { lget(l); continue; }; + if (c == '\r') { lget(l); continue; }; + if (c == '\n') { lget(l); continue; }; + if (c == '/') { let c2: i32 = lpeek(l, 1u64); - if (c2 == 47) { + if (c2 == '/') { lget(l); lget(l); // consume '//' for (true) { let cx: i32 = lpeek(l, 0u64); if (cx < 0) { return false; }; - if (cx == 10) { break; }; + if (cx == '\n') { break; }; lget(l); }; continue; }; - if (c2 == 42) { // '*' + if (c2 == '*') { lget(l); lget(l); let prev: i32 = -1; for (true) { @@ -6961,8 +6961,8 @@ fn skipws(l: *lex) bool = { errat(l, &cp, "unterminated /* comment"); return false; }; - if (prev == 42) { - if (x == 47) { break; }; + if (prev == '*') { + if (x == '/') { break; }; }; prev = x; }; @@ -6981,7 +6981,7 @@ fn parseint(p: *u8, n: u64, base: i32, ok: *bool) u64 = { for (i < n) { let ix: i32 = i: i32; let c: u8 = p[ix]; - if (c == 95u8) { // '_' + if (c == '_') { i += 1u64; continue; }; @@ -7012,18 +7012,18 @@ fn parseint(p: *u8, n: u64, base: i32, ok: *bool) u64 = { fn escape(l: *lex, out: *i32) bool = { let c: i32 = lget(l); if (c < 0) { return false; }; - if (c == 110) { *out = 10; return true; }; - if (c == 116) { *out = 9; return true; }; - if (c == 114) { *out = 13; return true; }; - if (c == 92) { *out = 92; return true; }; - if (c == 39) { *out = 39; return true; }; - if (c == 34) { *out = 34; return true; }; - if (c == 48) { *out = 0; return true; }; - if (c == 97) { *out = 7; return true; }; - if (c == 98) { *out = 8; return true; }; - if (c == 102) { *out = 12; return true; }; - if (c == 118) { *out = 11; return true; }; - if (c == 120) { + if (c == 'n') { *out = '\n'; return true; }; + if (c == 't') { *out = '\t'; return true; }; + if (c == 'r') { *out = '\r'; return true; }; + if (c == '\\') { *out = '\\'; return true; }; + if (c == '\'') { *out = '\''; return true; }; + if (c == '"') { *out = '"'; return true; }; + if (c == '0') { *out = '\0'; return true; }; + if (c == 'a') { *out = '\a'; return true; }; + if (c == 'b') { *out = '\b'; return true; }; + if (c == 'f') { *out = '\f'; return true; }; + if (c == 'v') { *out = '\v'; return true; }; + if (c == 'x') { let hi: i32 = lget(l); let lo: i32 = lget(l); if (hi < 0) { return false; }; @@ -7059,7 +7059,7 @@ fn scandecimalrun(l: *lex) void = { let c: i32 = lpeek(l, 0u64); if (c < 0) { break; }; if (!ascii.isdigit(c: rune)) { - if (c != 95) { break; }; + if (c != '_') { break; }; }; lget(l); }; @@ -7070,7 +7070,7 @@ fn scanhexrun(l: *lex) void = { let c: i32 = lpeek(l, 0u64); if (c < 0) { break; }; if (!ascii.isxdigit(c: rune)) { - if (c != 95) { break; }; + if (c != '_') { break; }; }; lget(l); }; @@ -7079,9 +7079,9 @@ fn scanhexrun(l: *lex) void = { fn scanbinrun(l: *lex) void = { for (true) { let c: i32 = lpeek(l, 0u64); - if (c == 48) { lget(l); continue; }; - if (c == 49) { lget(l); continue; }; - if (c == 95) { lget(l); continue; }; + if (c == '0') { lget(l); continue; }; + if (c == '1') { lget(l); continue; }; + if (c == '_') { lget(l); continue; }; break; }; }; @@ -7089,9 +7089,9 @@ fn scanbinrun(l: *lex) void = { fn scanoctrun(l: *lex) void = { for (true) { let c: i32 = lpeek(l, 0u64); - if (c < 48) { break; }; - if (c > 55) { - if (c != 95) { break; }; + if (c < '0') { break; }; + if (c > '7') { + if (c != '_') { break; }; }; lget(l); }; @@ -7100,11 +7100,11 @@ fn scanoctrun(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' + if (e != 'e') { if (e != 'E') { return; }; }; lget(l); let s: i32 = lpeek(l, 0u64); - if (s == 43) { lget(l); } - else { if (s == 45) { lget(l); }; }; + if (s == '+') { lget(l); } + else { if (s == '-') { lget(l); }; }; for (true) { let c: i32 = lpeek(l, 0u64); if (c < 0) { break; }; @@ -7133,7 +7133,7 @@ fn parsef64(s: *u8, n: u64) f64 = { let frac: i64 = 0i64; let fscale: i64 = 1i64; if (i < n) { - if (s[i] == 46u8) { // '.' + if (s[i] == '.') { i += 1u64; for (i < n) { let b: u8 = s[i]; @@ -7149,13 +7149,13 @@ fn parsef64(s: *u8, n: u64) f64 = { let expneg: bool = false; if (i < n) { let e: u8 = s[i]; - if (e == 101u8 || e == 69u8) { // 'e' / 'E' + if (e == 'e' || e == 'E') { i += 1u64; if (i < n) { - if (s[i] == 45u8) { // '-' + if (s[i] == '-') { expneg = true; i += 1u64; - } else { if (s[i] == 43u8) { // '+' + } else { if (s[i] == '+') { i += 1u64; };}; }; @@ -7201,25 +7201,25 @@ fn lexnum(l: *lex, start: *pos, out: *tok) void = { let c0: i32 = lpeek(l, 0u64); let c1: i32 = lpeek(l, 1u64); - if (c0 == 48) { // '0' - if (c1 == 120) { // 'x' + if (c0 == '0') { + if (c1 == 'x') { lget(l); lget(l); base = 16; scanhexrun(l); - } else { if (c1 == 88) { // 'X' + } else { if (c1 == 'X') { lget(l); lget(l); base = 16; scanhexrun(l); - } else { if (c1 == 98) { // 'b' + } else { if (c1 == 'b') { lget(l); lget(l); base = 2; scanbinrun(l); - } else { if (c1 == 66) { // 'B' + } else { if (c1 == 'B') { lget(l); lget(l); base = 2; scanbinrun(l); - } else { if (c1 == 111) { // 'o' + } else { if (c1 == 'o') { lget(l); lget(l); base = 8; scanoctrun(l); - } else { if (c1 == 79) { // 'O' + } else { if (c1 == 'O') { lget(l); lget(l); base = 8; scanoctrun(l); } else { scandecimalrun(l); - if (lpeek(l, 0u64) == 46) { + if (lpeek(l, 0u64) == '.') { let after: i32 = lpeek(l, 1u64); - if (after >= 48) { - if (after <= 57) { + if (after >= '0') { + if (after <= '9') { isfloat = true; lget(l); scandecimalrun(l); @@ -7230,10 +7230,10 @@ fn lexnum(l: *lex, start: *pos, out: *tok) void = { };};};};};}; } else { scandecimalrun(l); - if (lpeek(l, 0u64) == 46) { + if (lpeek(l, 0u64) == '.') { let after: i32 = lpeek(l, 1u64); - if (after >= 48) { - if (after <= 57) { + if (after >= '0') { + if (after <= '9') { isfloat = true; lget(l); scandecimalrun(l); @@ -7259,7 +7259,7 @@ fn lexnum(l: *lex, start: *pos, out: *tok) void = { let j: u64 = 0u64; for (i < n) { let b: u8 = l.src[begin + i]; - if (b != 95u8) { // '_' + if (b != '_') { clean[j] = b; j += 1u64; }; @@ -7302,27 +7302,27 @@ fn lexnum(l: *lex, start: *pos, out: *tok) void = { let p: *u8 = l.src + sb; let isok: bool = false; if (sl == 2u64) { - if (p[0] == 105u8) { - if (p[1] == 56u8) { isok = true; }; // i8 + if (p[0] == 'i') { + if (p[1] == '8') { isok = true; }; // i8 }; - if (p[0] == 117u8) { - if (p[1] == 56u8) { isok = true; }; // u8 + if (p[0] == 'u') { + if (p[1] == '8') { isok = true; }; // u8 }; }; if (sl == 3u64) { - if (p[0] == 105u8) { - if (p[1] == 49u8) { if (p[2] == 54u8) { isok = true; }; }; // i16 - if (p[1] == 51u8) { if (p[2] == 50u8) { isok = true; }; }; // i32 - if (p[1] == 54u8) { if (p[2] == 52u8) { isok = true; }; }; // i64 + if (p[0] == 'i') { + if (p[1] == '1') { if (p[2] == '6') { isok = true; }; }; // i16 + if (p[1] == '3') { if (p[2] == '2') { isok = true; }; }; // i32 + if (p[1] == '6') { if (p[2] == '4') { isok = true; }; }; // i64 }; - if (p[0] == 117u8) { - if (p[1] == 49u8) { if (p[2] == 54u8) { isok = true; }; }; - if (p[1] == 51u8) { if (p[2] == 50u8) { isok = true; }; }; - if (p[1] == 54u8) { if (p[2] == 52u8) { isok = true; }; }; + if (p[0] == 'u') { + if (p[1] == '1') { if (p[2] == '6') { isok = true; }; }; + if (p[1] == '3') { if (p[2] == '2') { isok = true; }; }; + if (p[1] == '6') { if (p[2] == '4') { isok = true; }; }; }; - if (p[0] == 102u8) { - if (p[1] == 51u8) { if (p[2] == 50u8) { isok = true; }; }; // f32 - if (p[1] == 54u8) { if (p[2] == 52u8) { isok = true; }; }; // f64 + if (p[0] == 'f') { + if (p[1] == '3') { if (p[2] == '2') { isok = true; }; }; // f32 + if (p[1] == '6') { if (p[2] == '4') { isok = true; }; }; // f64 }; }; if (isok) { @@ -7352,7 +7352,7 @@ fn lexident(l: *lex, start: *pos, out: *tok) void = { out.col = start.col; // Bare '_' is the discard marker. `_x`, `_1` are normal idents. if (n == 1u64) { - if (p[0] == 95u8) { + if (p[0] == '_') { out.kind = tkind.TK_UNDER; let view: str; view.ptr = p; @@ -7391,9 +7391,9 @@ fn lexstr(l: *lex, start: *pos, out: *tok) void = { out.text = strings.dup(view); return; }; - if (c == 34) { lget(l); break; }; + if (c == '"') { lget(l); break; }; let ch: i32 = 0; - if (c == 92) { + if (c == '\\') { lget(l); if (!escape(l, &ch)) { ch = 0; }; } else { @@ -7440,13 +7440,13 @@ fn lexrune(l: *lex, start: *pos, out: *tok) void = { return; }; let ch: i32 = 0; - if (c == 92) { + if (c == '\\') { lget(l); if (!escape(l, &ch)) { ch = 0; }; } else { ch = lget(l); }; - if (lpeek(l, 0u64) != 39) { + if (lpeek(l, 0u64) != '\'') { errat(l, start, "rune literal missing closing '"); out.kind = tkind.TK_ERR; out.file = start.file; @@ -7510,27 +7510,27 @@ export fn lexnext(l: *lex, out: *tok) void = { if (ascii.isdigit(c: rune)) { lexnum(l, &start, out); return; }; }; - if (c == 34) { lget(l); lexstr(l, &start, out); return; }; - if (c == 39) { lget(l); lexrune(l, &start, out); return; }; + if (c == '"') { lget(l); lexstr(l, &start, out); return; }; + if (c == '\'') { lget(l); lexrune(l, &start, out); return; }; lget(l); - if (c == 40) { emitsimple(&start, tkind.TK_LPAREN, out); return; }; - if (c == 41) { emitsimple(&start, tkind.TK_RPAREN, out); return; }; - if (c == 123) { emitsimple(&start, tkind.TK_LBRACE, out); return; }; - if (c == 125) { emitsimple(&start, tkind.TK_RBRACE, out); return; }; - if (c == 91) { emitsimple(&start, tkind.TK_LBRACK, out); return; }; - if (c == 93) { emitsimple(&start, tkind.TK_RBRACK, out); return; }; - if (c == 44) { emitsimple(&start, tkind.TK_COMMA, out); return; }; - if (c == 59) { emitsimple(&start, tkind.TK_SEMI, out); return; }; - if (c == 58) { emitsimple(&start, tkind.TK_COLON, out); return; }; - if (c == 64) { emitsimple(&start, tkind.TK_AT, out); return; }; - if (c == 63) { emitsimple(&start, tkind.TK_QUESTION, out); return; }; - if (c == 126) { emitsimple(&start, tkind.TK_TILDE, out); return; }; + if (c == '(') { emitsimple(&start, tkind.TK_LPAREN, out); return; }; + if (c == ')') { emitsimple(&start, tkind.TK_RPAREN, out); return; }; + if (c == '{') { emitsimple(&start, tkind.TK_LBRACE, out); return; }; + if (c == '}') { emitsimple(&start, tkind.TK_RBRACE, out); return; }; + if (c == '[') { emitsimple(&start, tkind.TK_LBRACK, out); return; }; + if (c == ']') { emitsimple(&start, tkind.TK_RBRACK, out); return; }; + if (c == ',') { emitsimple(&start, tkind.TK_COMMA, out); return; }; + if (c == ';') { emitsimple(&start, tkind.TK_SEMI, out); return; }; + if (c == ':') { emitsimple(&start, tkind.TK_COLON, out); return; }; + if (c == '@') { emitsimple(&start, tkind.TK_AT, out); return; }; + if (c == '?') { emitsimple(&start, tkind.TK_QUESTION, out); return; }; + if (c == '~') { emitsimple(&start, tkind.TK_TILDE, out); return; }; - if (c == 46) { // '.' - if (lpeek(l, 0u64) == 46) { - if (lpeek(l, 1u64) == 46) { + if (c == '.') { + if (lpeek(l, 0u64) == '.') { + if (lpeek(l, 1u64) == '.') { lget(l); lget(l); emitsimple(&start, tkind.TK_ELLIPSIS, out); return; }; @@ -7540,67 +7540,67 @@ export fn lexnext(l: *lex, out: *tok) void = { emitsimple(&start, tkind.TK_DOT, out); return; }; - if (c == 43) { - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_PLUSEQ, out); return; }; + if (c == '+') { + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_PLUSEQ, out); return; }; emitsimple(&start, tkind.TK_PLUS, out); return; }; - if (c == 45) { - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_MINUSEQ, out); return; }; - if (lpeek(l, 0u64) == 62) { lget(l); emitsimple(&start, tkind.TK_ARROW, out); return; }; + if (c == '-') { + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_MINUSEQ, out); return; }; + if (lpeek(l, 0u64) == '>') { lget(l); emitsimple(&start, tkind.TK_ARROW, out); return; }; emitsimple(&start, tkind.TK_MINUS, out); return; }; - if (c == 42) { - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_STAREQ, out); return; }; + if (c == '*') { + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_STAREQ, out); return; }; emitsimple(&start, tkind.TK_STAR, out); return; }; - if (c == 47) { - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_SLASHEQ, out); return; }; + if (c == '/') { + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_SLASHEQ, out); return; }; emitsimple(&start, tkind.TK_SLASH, out); return; }; - if (c == 37) { - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_PERCENTEQ, out); return; }; + if (c == '%') { + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_PERCENTEQ, out); return; }; emitsimple(&start, tkind.TK_PERCENT, out); return; }; - if (c == 38) { - if (lpeek(l, 0u64) == 38) { lget(l); emitsimple(&start, tkind.TK_AND, out); return; }; - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_AMPEQ, out); return; }; + if (c == '&') { + if (lpeek(l, 0u64) == '&') { lget(l); emitsimple(&start, tkind.TK_AND, out); return; }; + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_AMPEQ, out); return; }; emitsimple(&start, tkind.TK_AMP, out); return; }; - if (c == 124) { - if (lpeek(l, 0u64) == 124) { lget(l); emitsimple(&start, tkind.TK_OR, out); return; }; - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_PIPEEQ, out); return; }; + if (c == '|') { + if (lpeek(l, 0u64) == '|') { lget(l); emitsimple(&start, tkind.TK_OR, out); return; }; + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_PIPEEQ, out); return; }; emitsimple(&start, tkind.TK_PIPE, out); return; }; - if (c == 94) { - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_CARETEQ, out); return; }; + if (c == '^') { + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_CARETEQ, out); return; }; emitsimple(&start, tkind.TK_CARET, out); return; }; - if (c == 61) { - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_EQ, out); return; }; - if (lpeek(l, 0u64) == 62) { lget(l); emitsimple(&start, tkind.TK_FATARROW, out); return; }; + if (c == '=') { + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_EQ, out); return; }; + if (lpeek(l, 0u64) == '>') { lget(l); emitsimple(&start, tkind.TK_FATARROW, out); return; }; emitsimple(&start, tkind.TK_ASSIGN, out); return; }; - if (c == 33) { - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_NEQ, out); return; }; + if (c == '!') { + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_NEQ, out); return; }; emitsimple(&start, tkind.TK_NOT, out); return; }; - if (c == 60) { - if (lpeek(l, 0u64) == 60) { + if (c == '<') { + if (lpeek(l, 0u64) == '<') { lget(l); - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_LSHIFTEQ, out); return; }; + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_LSHIFTEQ, out); return; }; emitsimple(&start, tkind.TK_LSHIFT, out); return; }; - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_LE, out); return; }; - if (lpeek(l, 0u64) == 45) { lget(l); emitsimple(&start, tkind.TK_LARROW, out); return; }; + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_LE, out); return; }; + if (lpeek(l, 0u64) == '-') { lget(l); emitsimple(&start, tkind.TK_LARROW, out); return; }; emitsimple(&start, tkind.TK_LT, out); return; }; - if (c == 62) { - if (lpeek(l, 0u64) == 62) { + if (c == '>') { + if (lpeek(l, 0u64) == '>') { lget(l); - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_RSHIFTEQ, out); return; }; + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_RSHIFTEQ, out); return; }; emitsimple(&start, tkind.TK_RSHIFT, out); return; }; - if (lpeek(l, 0u64) == 61) { lget(l); emitsimple(&start, tkind.TK_GE, out); return; }; + if (lpeek(l, 0u64) == '=') { lget(l); emitsimple(&start, tkind.TK_GE, out); return; }; emitsimple(&start, tkind.TK_GT, out); return; };