Phase 4b: enum types name magic-int value spaces
enum Name { A, B, C } declares named int constants; Enum.Variant is a
compile-time int (index by declaration order), usable in match patterns,
comparisons, setreg. New: parse_enum + dispatch, enum_ordinal resolver
(emit_core), Enum.Variant handling (emit_expr). Scoped to a naming layer over
int (no enum-typed variables), so register/save semantics are untouched.
combat.ludic battle menus dispatch on KnightAct/MageAct instead of 0..3;
chronorift golden byte-identical. Editor vocab (ludic_syntax.h, JetBrains,
TextMate, emacs) gained enum, dropped retired edge/export/pure decl keywords;
check-vocabulary + test-tools 28/0. when/if kept by choice; bitwise stays
functions. Reseeded, fixpoint holds, test.sh 14/14.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
fd0b890acc
commit
f87964c5f7
14 changed files with 3021 additions and 2672 deletions
20
LANGUAGE.md
20
LANGUAGE.md
|
|
@ -392,6 +392,26 @@ is still accepted when a state needs a specific value.) A `machine <reg>` reads
|
|||
value>)`. Both lower to plain branches (and `match` runs on the native LLVM
|
||||
backend too).
|
||||
|
||||
## Enums
|
||||
|
||||
`enum` names a set of related integer values so a magic-number space — a menu
|
||||
selection, a mode, a machine state — reads as names instead of literals:
|
||||
|
||||
```ludic
|
||||
# doc-check: skip — composite: a declaration plus its uses
|
||||
enum Action { Attack, Guard, Item, Flee } # Attack = 0, Guard = 1, …
|
||||
|
||||
match reg(R_CUR) { Action.Attack => attack() Action.Guard => guard() _ => wait() }
|
||||
if reg(R_MODE) == Mode.Battle { … }
|
||||
```
|
||||
|
||||
A variant is a **compile-time `int`** accessed as `Enum.Variant` (`Action.Guard`
|
||||
is `1`), numbered from `0` by declaration order, so it works anywhere an int does
|
||||
— `match` patterns, comparisons, `setreg`. Enums are a naming layer over `int`:
|
||||
there is no distinct enum runtime type yet, so an enum value lives in an ordinary
|
||||
`int` or register (and is saved with it). See `examples/chronorift/combat.ludic`,
|
||||
whose battle menus dispatch on `KnightAct`/`MageAct` instead of `0..3`.
|
||||
|
||||
## Expressions
|
||||
|
||||
Precedence: `or → and → compar(< <= > >= == !=) → + - → * / % → unary(- not) →
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue