wcc: Hare-style enum [storage] { ... } type

`type Foo = enum [intT] { NAME [= expr], ... };`. Storage defaults
to i32; members auto-increment from 0 (or last+1) when `= expr` is
omitted, and value expressions can reference earlier siblings —
enough surface for io::mode-style flag enums (`RDWR = READ | WRITE`).

`Foo.MEMBER` folds to an N_INTLIT in the checker, typed as the
named enum. Binops on enum values yield the same enum (type_eq on
the named pointer), so `mode.R | mode.W` is a `mode`. Enum ↔ int
is a reinterpret-only `as` cast — same register, no tag wrap — so
`mode.RDWR as i32` and `1 as mode` both work without runtime ops.

`is`/`?`/`!` are still tagged-union-only. CSP runtime (chan/proc)
is unchanged; only the type-system slot is touched here.
This commit is contained in:
2026-05-12 04:15:31 +09:00
parent 22999cd3fa
commit 34817eedcd
10 changed files with 257 additions and 1 deletions

View File

@@ -139,6 +139,7 @@ type_isint(Type *t)
case TY_UNTYPED_INT:
case TY_UNTYPED_RUNE:
return 1;
case TY_ENUM: return type_isint(t->sub);
case TY_NAMED: return type_isint(t->under);
default: return 0;
}
@@ -370,6 +371,9 @@ type_name(Arena *a, Type *t)
}
return aprintf(a, "(%s)", acc);
}
case TY_ENUM:
return aprintf(a, "enum %s",
t->sub ? type_name(a, t->sub) : "i32");
}
return "?";
}