ww: add Hare-style is/as postfix ops on tagged unions

`e is T` returns bool (variant tag == T's index); `e as T` unwraps
to T or exit(1) on mismatch. Postfix, same precedence as `:` cast.
TK_IS / N_TYPETEST / N_TYPEASSERT appended at the tail of their
enums so every prior numeric value stays unchanged — the
990_selfhost wwdump-diff stays byte-clean.

Cgen mirrors the match-case slot-based load (tag at +0, value at
+8/+16), so an N_IDENT tagged-union local works just like a
match scrutinee. Selfhost cgen inlines the slot resolution
because the wwstage cgen drops sign bits on `*i32` output
parameters in this position.

Renames `errors.is` -> `errors.equal` (the only naming collision;
the existing comment already noted it shared shape with
strings.equal/bytes.equal).
This commit is contained in:
2026-05-11 23:21:08 +09:00
parent 8899ce5621
commit dd188ca460
16 changed files with 614 additions and 15 deletions

View File

@@ -29,6 +29,7 @@ static const struct kwent kwtab[] = {
{ "fn", TK_FN },
{ "for", TK_FOR },
{ "if", TK_IF },
{ "is", TK_IS },
{ "let", TK_LET },
{ "match", TK_MATCH },
{ "nil", TK_NIL },
@@ -89,6 +90,7 @@ tokname(Tkind k)
case TK_TRUE: return "true";
case TK_FALSE: return "false";
case TK_AS: return "as";
case TK_IS: return "is";
case TK_STATIC: return "static";
case TK_MATCH: return "match";
case TK_CONST: return "const";