ww+wcc: graduate selfhost TK_* defs to tkind enum
`type tkind = enum i32 { TK_NONE = 0, TK_EOF = 1, ... TK_LAST = 86 }`
replaces the 87-line `def TK_*: i32 = N` cluster in lib/ww/lex/tok.ww.
Numeric values explicit so 990_selfhost's byte-diff against the C-side
`Tkind` enum still passes.
All ~270 reference sites in lib/ww and selfhost/cmd/{wcc,wwdump}
sed-renamed `TK_X` → `tkind.TK_X`. Struct fields (`tok.kind`,
`parser.curkind`) intentionally kept as `i32` — making them `tkind`
shifted some byte-positions in the cgen output and broke 990/993/995
byte-identity probes without an obvious win.
To make the rename non-cascading on every signature, type_assignable
and unify_arith in cmd/wcc/check+type relax to allow enum ↔ int
mixing when storage matches (a `tkind` value flows into an `i32`
slot and vice versa, no explicit cast). This deviates from Hare's
strict enum semantics; doc'd as an explicit pragmatic relaxation
for the compiler's internal enum-shaped kinds. External user code
can still get the type-safety benefit if they declare their
parameters with the enum type.
combined.ww files regenerated by ww build.
This commit is contained in:
@@ -111,31 +111,31 @@ fn enumevalmember(prev: *enummember, e: *node, out: *u64) bool = {
|
||||
if (!enumevalmember(prev, e.lhs, &a)) { return false; };
|
||||
if (!enumevalmember(prev, e.rhs, &b)) { return false; };
|
||||
let op: i32 = e.op;
|
||||
if (op == TK_PLUS) { *out = a + b; return true; };
|
||||
if (op == TK_MINUS) { *out = a - b; return true; };
|
||||
if (op == TK_STAR) { *out = a * b; return true; };
|
||||
if (op == TK_SLASH) {
|
||||
if (op == tkind.TK_PLUS) { *out = a + b; return true; };
|
||||
if (op == tkind.TK_MINUS) { *out = a - b; return true; };
|
||||
if (op == tkind.TK_STAR) { *out = a * b; return true; };
|
||||
if (op == tkind.TK_SLASH) {
|
||||
if (b == 0u64) { return false; };
|
||||
*out = a / b; return true;
|
||||
};
|
||||
if (op == TK_PERCENT) {
|
||||
if (op == tkind.TK_PERCENT) {
|
||||
if (b == 0u64) { return false; };
|
||||
*out = a % b; return true;
|
||||
};
|
||||
if (op == TK_AMP) { *out = a & b; return true; };
|
||||
if (op == TK_PIPE) { *out = a | b; return true; };
|
||||
if (op == TK_CARET) { *out = a ^ b; return true; };
|
||||
if (op == TK_LSHIFT) { *out = a << b; return true; };
|
||||
if (op == TK_RSHIFT) { *out = a >> b; return true; };
|
||||
if (op == tkind.TK_AMP) { *out = a & b; return true; };
|
||||
if (op == tkind.TK_PIPE) { *out = a | b; return true; };
|
||||
if (op == tkind.TK_CARET) { *out = a ^ b; return true; };
|
||||
if (op == tkind.TK_LSHIFT) { *out = a << b; return true; };
|
||||
if (op == tkind.TK_RSHIFT) { *out = a >> b; return true; };
|
||||
return false;
|
||||
};
|
||||
if (k == N_UN) {
|
||||
let v: u64;
|
||||
if (!enumevalmember(prev, e.lhs, &v)) { return false; };
|
||||
let op: i32 = e.op;
|
||||
if (op == TK_MINUS) { *out = (-(v: i64)): u64; return true; };
|
||||
if (op == TK_TILDE) { *out = ~v; return true; };
|
||||
if (op == TK_PLUS) { *out = v; return true; };
|
||||
if (op == tkind.TK_MINUS) { *out = (-(v: i64)): u64; return true; };
|
||||
if (op == tkind.TK_TILDE) { *out = ~v; return true; };
|
||||
if (op == tkind.TK_PLUS) { *out = v; return true; };
|
||||
return false;
|
||||
};
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user