Merge Phase 6a: remove redundant when/enter keywords

This commit is contained in:
Orkun ÇAKILKAYA 2026-08-27 23:14:32 +03:00
commit da48dc8499
8 changed files with 3406 additions and 3462 deletions

View file

@ -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

View file

@ -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

View file

@ -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 }

View file

@ -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")

View file

@ -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" },

View file

@ -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" },

View file

@ -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[] = {