Phase 6a: remove the redundant when and enter keywords
Cohesion audit found two keywords that are pure duplicates:
- `when c { }` produced a byte-identical S_IF to an else-less `if c { }`
(no distinguishing flag) — so it was a second spelling of the same node.
- `enter Name` produced identical codegen to `become Name`: it set an
`ival` flag that emit_become never reads.
Both removed from the parser. `if` already parses with an optional `else`, so
nothing is lost. examples/scenes.ludic (an uncompiled design sketch) and the
LANGUAGE.md scenes section now use `become Name` for scene transitions.
Vocabulary synced (ludic_syntax.h, TextMate grammar, LudicTokens.kt);
check-vocabulary clean. Reseeded (22148 lines); C-free fixpoint holds;
goldens identical; 17/17.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
5ecd300d16
commit
920d476a15
8 changed files with 3406 additions and 3462 deletions
12
LANGUAGE.md
12
LANGUAGE.md
|
|
@ -453,8 +453,8 @@ another `.ludic` file (see `examples/lib/`).
|
|||
|
||||
## Statements
|
||||
|
||||
`let x = expr` · `x = expr` (`+= -= *= /=`) · `if/else` · `when cond { }`
|
||||
(if-without-else) · `while cond { }` · `for i in a .. b { }` (numeric range) ·
|
||||
`let x = expr` · `x = expr` (`+= -= *= /=`) · `if cond { }` / `if/else`
|
||||
(the `else` is optional) · `while cond { }` · `for i in a .. b { }` (numeric range) ·
|
||||
`for (…) in query […] { }` · `break` · `continue` · `return` · `spawn` ·
|
||||
`despawn` · `enable` / `disable` (a property `on e`, a model, or a handler) ·
|
||||
`match` · `machine`.
|
||||
|
|
@ -655,7 +655,7 @@ as near-term — are now implemented and self-hosting; their lowerings are in
|
|||
> ⚠️ **Not yet implemented in the current (self-hosted) compiler.** `scene`,
|
||||
> `layer`, and the `on enter` / `on exit` hooks are a design target: the
|
||||
> compiler has no `scene` declaration and [`examples/scenes.ludic`](examples/scenes.ludic)
|
||||
> does not compile today (`enter Name` parses only as a `become` alias). Games
|
||||
> does not compile today. Games
|
||||
> that need mutually-exclusive states use a mode register (`reg`/`setreg`) with a
|
||||
> `machine`, as `examples/chronorift` does. This section describes the intended
|
||||
> syntax for when scene support lands.
|
||||
|
|
@ -672,7 +672,7 @@ scene Title start {
|
|||
|
||||
layer Main {
|
||||
handler Choose phase Update {
|
||||
if ui_clicked(UI_NewGame) { enter Overworld }
|
||||
if ui_clicked(UI_NewGame) { become Overworld }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -694,12 +694,12 @@ scene Overworld {
|
|||
were written — so `Hud`'s `Render` paints over `World`'s.
|
||||
- `on enter` / `on exit` are lifecycle hooks, not phases. Scene setup goes in
|
||||
`on enter`; a layer handler may not use phase `Start`.
|
||||
- `enter Name` transitions: the current scene's `on exit` runs, the active scene
|
||||
- `become Name` transitions: the current scene's `on exit` runs, the active scene
|
||||
becomes `Name`, and its `on enter` runs. Inside a layer handler the compiler
|
||||
knows which scene is leaving, so a transition costs two direct calls and a
|
||||
store — there is no dispatch table.
|
||||
|
||||
`examples/scenes.ludic` is a runnable demonstration of the ordering rules.
|
||||
`examples/scenes.ludic` sketches the ordering rules (it does not compile yet).
|
||||
|
||||
## Queries in a handler signature
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ program SceneDemo {
|
|||
handler Tick phase Update {
|
||||
setreg(R_N, reg(R_N) + 1)
|
||||
print_int(100 + reg(R_N))
|
||||
if reg(R_N) >= 2 { enter Play }
|
||||
if reg(R_N) >= 2 { become Play }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -171,10 +171,6 @@ fn stmt() -> Node {
|
|||
else { pi = save } # no else: keep the separator for block()'s Rule-B check
|
||||
return n
|
||||
}
|
||||
if streq(t.text, "when") { # `when c { }` — an if with no else
|
||||
pi = pi + 1; let n = node(S_IF); n.a = expr(); n.b = block()
|
||||
return n
|
||||
}
|
||||
if streq(t.text, "while") { pi = pi + 1; let n = node(S_WHILE); n.a = expr(); n.b = block(); return n }
|
||||
if streq(t.text, "for") {
|
||||
pi = pi + 1
|
||||
|
|
@ -198,7 +194,6 @@ fn stmt() -> Node {
|
|||
eat_op("}"); return n
|
||||
}
|
||||
if streq(t.text, "become") { pi = pi + 1; let n = node(S_BECOME); n.s = eat_id(); return n }
|
||||
if streq(t.text, "enter") { pi = pi + 1; let n = node(S_BECOME); n.s = eat_id(); n.ival = 1; return n }
|
||||
if streq(t.text, "despawn") { pi = pi + 1; let n = node(S_DESPAWN); n.a = expr(); return n }
|
||||
if streq(t.text, "enable") or streq(t.text, "disable") {
|
||||
let en = 0; if streq(t.text, "enable") { en = 1 }
|
||||
|
|
|
|||
|
|
@ -48,8 +48,8 @@ object LudicVocabulary {
|
|||
"phase", "query", "reads", "writes", "on"
|
||||
)
|
||||
val STMT = setOf(
|
||||
"let", "return", "if", "else", "when", "while", "for", "in", "spawn", "despawn",
|
||||
"enable", "disable", "match", "machine", "state", "become", "enter", "where",
|
||||
"let", "return", "if", "else", "while", "for", "in", "spawn", "despawn",
|
||||
"enable", "disable", "match", "machine", "state", "become", "where",
|
||||
"and", "or", "not", "break", "continue", "new"
|
||||
)
|
||||
val PRIMITIVES = setOf("int", "fixed", "bool", "entity", "str", "ptr", "void")
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@
|
|||
},
|
||||
"keyword": {
|
||||
"patterns": [
|
||||
{ "name": "keyword.control.ludic", "match": "\\b(if|else|when|while|for|in|match|machine|become|enter|return|spawn|despawn|enable|disable|where|break|continue|new)\\b" },
|
||||
{ "name": "keyword.control.ludic", "match": "\\b(if|else|while|for|in|match|machine|become|return|spawn|despawn|enable|disable|where|break|continue|new)\\b" },
|
||||
{ "name": "keyword.operator.logical.ludic", "match": "\\b(and|or|not)\\b" },
|
||||
{ "name": "keyword.other.clause.ludic", "match": "\\b(phase|query|reads|writes|on)\\b" },
|
||||
{ "name": "keyword.other.ludic", "match": "\\b(import|extern)\\b" },
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@
|
|||
},
|
||||
"keyword": {
|
||||
"patterns": [
|
||||
{ "name": "keyword.control.ludic", "match": "\\b(if|else|when|while|for|in|match|machine|become|enter|return|spawn|despawn|enable|disable|where|break|continue|new)\\b" },
|
||||
{ "name": "keyword.control.ludic", "match": "\\b(if|else|while|for|in|match|machine|become|return|spawn|despawn|enable|disable|where|break|continue|new)\\b" },
|
||||
{ "name": "keyword.operator.logical.ludic", "match": "\\b(and|or|not)\\b" },
|
||||
{ "name": "keyword.other.clause.ludic", "match": "\\b(phase|query|reads|writes|on)\\b" },
|
||||
{ "name": "keyword.other.ludic", "match": "\\b(import|extern)\\b" },
|
||||
|
|
|
|||
|
|
@ -66,8 +66,8 @@ static const char* LUDIC_KW_RESERVED[] = {
|
|||
"scene","layer","start", 0
|
||||
};
|
||||
static const char* LUDIC_KW_STMT[] = {
|
||||
"let","return","if","else","when","while","for","in","spawn","despawn",
|
||||
"enable","disable","match","machine","state","become","enter","where",
|
||||
"let","return","if","else","while","for","in","spawn","despawn",
|
||||
"enable","disable","match","machine","state","become","where",
|
||||
"and","or","not","break","continue","new", 0
|
||||
};
|
||||
static const char* LUDIC_TYPES[] = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue