ww+wcc: Hare-strict enum types — back out the int↔enum relaxation
Cascades the four enum kinds through every signature and local that
holds one of their values, then removes the type_assignable /
unify_arith relaxation that previously let bare i32 mix with the
named enum types.
Signature updates:
- kwlookup() now returns `tkind` (not i32); tokname() takes `tkind`
- accepttok / expecttok / bprec / isassignop take `tkind`
- parsearglist's closekind is `tkind`
- newtype / prim take `tykind`; scopedefine takes `skind`
- newnode / nkname take `nkind`
Struct fields:
- tok.kind is `tkind`; parser.curkind is `tkind`
- node.kind is `nkind`; node.op is `tkind`
- tinfo.kind is `tykind`; sym.skind is `skind`
Locals holding kinds across lex/parse/check/cgen are now typed with
their enum, including sentinel patterns like `let lkind: nkind =
nkind.N_NONE; if (...) lkind = tn.kind;`.
The selfhost cgen had a load-width bug exposed by this: fieldsize()
fell back to 8 bytes for any TNAME that wasn't a struct or primitive.
For a tkind-typed field that gave `MOVQ (BX), AX` instead of `MOVL`,
diverging from the C cgen on tok.kind / parser.curkind / etc. Two
fixes:
- fieldsize now consults the enum registry and returns the storage
type's size (4 for `enum i32`)
- collectenums runs before collectstructs in cgfile so the registry
is populated when registerstruct asks for field sizes
All 22 tests stay green; 990/993/995 byte-identity probes pass with
the strict typing in place.
This commit is contained in:
@@ -89,7 +89,7 @@ fn aliaslookup(c: *cgen, name: str) *node = {
|
||||
|
||||
fn enumevalmember(prev: *enummember, e: *node, out: *u64) bool = {
|
||||
if (e == nil) { return false; };
|
||||
let k: i32 = e.kind;
|
||||
let k: nkind = e.kind;
|
||||
if (k == nkind.N_INTLIT) { *out = e.uval; return true; };
|
||||
if (k == nkind.N_RUNELIT) { *out = e.uval; return true; };
|
||||
if (k == nkind.N_TRUE) { *out = 1u64; return true; };
|
||||
@@ -110,7 +110,7 @@ fn enumevalmember(prev: *enummember, e: *node, out: *u64) bool = {
|
||||
let b: u64;
|
||||
if (!enumevalmember(prev, e.lhs, &a)) { return false; };
|
||||
if (!enumevalmember(prev, e.rhs, &b)) { return false; };
|
||||
let op: i32 = e.op;
|
||||
let op: tkind = e.op;
|
||||
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; };
|
||||
@@ -132,7 +132,7 @@ fn enumevalmember(prev: *enummember, e: *node, out: *u64) bool = {
|
||||
if (k == nkind.N_UN) {
|
||||
let v: u64;
|
||||
if (!enumevalmember(prev, e.lhs, &v)) { return false; };
|
||||
let op: i32 = e.op;
|
||||
let op: tkind = e.op;
|
||||
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; };
|
||||
|
||||
Reference in New Issue
Block a user