wcc: tagged-union foundations (never, void, flatten, exhaust)
- `never` bottom type: TY_NEVER, assignable to anything; size 0.
- Type-set normalization for N_TTAGGED in resolve_type:
- flatten nested anonymous (A|B)|C → (A|B|C); named aliases stay
nominal (not flattened through)
- dedup duplicates (NAMED pointer-id; others structural)
- drop `never` variants
- collapse single-element set: (T|never) → T, (T|T) → T
- Match exhaustiveness: error when a variant is unhandled and no
default arm covers it. Multi-pattern `case T1 | T2 =>` counts
each alt.
- (T | void) optionals: bare `return;` from a tagged-union-returning
fn emits the void variant's tag (payload undefined; void size 0).
selfhost mirrored: TY_NEVER constant + tynever in tctx + seedprim
entry; voidvariantindex helper; cgreturn bare-return handling.
This commit is contained in:
@@ -42,12 +42,13 @@ def TY_NAMED: i32 = 24;
|
||||
def TY_TUPLE: i32 = 25;
|
||||
def TY_TAGGED: i32 = 26;
|
||||
def TY_ERR: i32 = 27;
|
||||
def TY_UNTYPED_INT: i32 = 28;
|
||||
def TY_UNTYPED_FLOAT: i32 = 29;
|
||||
def TY_UNTYPED_STR: i32 = 30;
|
||||
def TY_UNTYPED_RUNE: i32 = 31;
|
||||
def TY_UNTYPED_BOOL: i32 = 32;
|
||||
def TY_UNTYPED_NIL: i32 = 33;
|
||||
def TY_NEVER: i32 = 28;
|
||||
def TY_UNTYPED_INT: i32 = 29;
|
||||
def TY_UNTYPED_FLOAT: i32 = 30;
|
||||
def TY_UNTYPED_STR: i32 = 31;
|
||||
def TY_UNTYPED_RUNE: i32 = 32;
|
||||
def TY_UNTYPED_BOOL: i32 = 33;
|
||||
def TY_UNTYPED_NIL: i32 = 34;
|
||||
|
||||
// ---- tinfo / tfield / tparam -----------------------------------------
|
||||
|
||||
@@ -100,6 +101,7 @@ type tctx = struct {
|
||||
tyf64: *tinfo,
|
||||
tystr: *tinfo,
|
||||
tyerr: *tinfo,
|
||||
tynever: *tinfo,
|
||||
tyuntypedint: *tinfo,
|
||||
tyuntypedfloat: *tinfo,
|
||||
tyuntypedstr: *tinfo,
|
||||
@@ -144,6 +146,7 @@ export fn typesinit(c: *tctx, a: *arena) void = {
|
||||
c.tyf64 = prim(a, TY_F64, "f64", 8u64, 8u64);
|
||||
c.tystr = prim(a, TY_STR, "str", 16u64, 8u64);
|
||||
c.tyerr = prim(a, TY_ERR, "<err>", 0u64, 1u64);
|
||||
c.tynever = prim(a, TY_NEVER, "never", 0u64, 1u64);
|
||||
|
||||
c.tyuntypedint = prim(a, TY_UNTYPED_INT, "untyped_int", 0u64, 1u64);
|
||||
c.tyuntypedfloat = prim(a, TY_UNTYPED_FLOAT, "untyped_float", 0u64, 1u64);
|
||||
|
||||
Reference in New Issue
Block a user