traits + Sized(): default methods and the sized marker

- `trait` keyword: like `interface`, but tagged `__trait`; its methods
  carry default bodies.  A class that `implements` a trait has those
  bodies mixed in (a class's own method wins), then is checked
  structurally -- so the mix-in runs BEFORE `__implements_check`.
- runtime `__trait_mixin(cls, trait)`: copies a trait's default methods
  into the class (skipping `__*` meta keys and existing members).
- `Sized` -- the marker object for "layout known at compile time"; every
  concrete value satisfies it, so `x is Sized` / `implements(x, Sized)`
  hold and signatures can name it (`buf : Sized()`).
- tests/traits.cat + suite: default method, override, `is`, and Sized.
  Suite 144 -> 151.
This commit is contained in:
Minus committed 2026-11-18 17:18:58 +00:00
1 parent 95f3823acf
commit 70728093ef
6 files changed
+133 -9

No files matched your search

+1
View File
@@ -31,6 +31,7 @@ enum CAT_LEXER_Kind {
CAT_LEXER_TOK_EXTENDS, CAT_LEXER_TOK_INTERFACE, CAT_LEXER_TOK_IMPLEMENTS,
CAT_LEXER_TOK_IS,
CAT_LEXER_TOK_COMPTIME,
CAT_LEXER_TOK_TRAIT,
/* symbols */
CAT_LEXER_TOK_PLUS, CAT_LEXER_TOK_MINUS, CAT_LEXER_TOK_STAR,
CAT_LEXER_TOK_SLASH, CAT_LEXER_TOK_PERCENT, CAT_LEXER_TOK_CARET,