wip(0.S2): migrate - a var nothing writes becomes a let; a state is keyed by its module, directory or program, so every program's plan agrees; paths normalized; program states named SceneDemoState / scene_demo_st; the LSP reads state, mut and entry/handler parameters

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-25 15:31:34 +03:00
parent 3eda72e8c2
commit 5ffe50ed02
463 changed files with 72045 additions and 67421 deletions

View file

@ -5,22 +5,20 @@
# Running it prints: 10 20 0
program Answer {
event cancellable Ask { kind: int }
state AnswerState {
answer: int = 0
}
var answer: int = 0
@On(Ask) handler One(answer_st: mut AnswerState) { if kind != 1 { return }; answer_st.answer = 10; cancel }
@On(Ask) handler Two(answer_st: mut AnswerState) { if kind != 2 { return }; answer_st.answer = 20; cancel }
@On(Ask) handler One { if kind != 1 { return }; answer = 10; cancel }
@On(Ask) handler Two { if kind != 2 { return }; answer = 20; cancel }
function ask(answer_st: mut AnswerState, k: int) -> int {
answer_st.answer = 0
if emit Ask(kind: k) != 0 { return answer_st.answer }
function ask(k: int) -> int {
answer = 0
if emit Ask(kind: k) != 0 { return answer }
return 0
}
entry (answer_st: mut AnswerState) {
print(ask(answer_st, 1))
print(ask(answer_st, 2))
print(ask(answer_st, 3))
entry {
print(ask(1))
print(ask(2))
print(ask(3))
}
}

View file

@ -6,9 +6,7 @@
#
# Running it prints: 50 2 1 50
program LayerEvents {
state LayereventsState {
step: int = 0
}
var step: int = 0
@On(layer_Hud_show) handler Shown { print(1) } # a mod reacts when the HUD returns
@On(layer_Hud_hide) handler Hidden { print(2) } # ...and when it's hidden
@ -18,11 +16,11 @@ program LayerEvents {
handler Draw phase Update { print(50) } # only runs while Hud is enabled
}
layer Ctrl {
handler Drive(layerevents_st: mut LayereventsState) phase LateUpdate {
layerevents_st.step += 1
if layerevents_st.step == 1 { disable layer Hud } # frame 1: hide -> Hidden 2, Draw stops
if layerevents_st.step == 2 { enable layer Hud } # frame 2: show -> Shown 1, Draw resumes
if layerevents_st.step == 3 { quit() } # frame 3: after Draw ran again
handler Drive phase LateUpdate {
step += 1
if step == 1 { disable layer Hud } # frame 1: hide -> Hidden 2, Draw stops
if step == 2 { enable layer Hud } # frame 2: show -> Shown 1, Draw resumes
if step == 3 { quit() } # frame 3: after Draw ran again
}
}
}

View file

@ -3,16 +3,14 @@
# `Damage` has two @On listeners: one prints the amount, one accumulates a total.
# Emitting it twice runs both listeners each time. Prints 10 / 32 / 42.
program ModEvents {
state ModeventsState {
total: int = 0
}
var total: int = 0
event Damage { amount: int = 0 }
@On(Damage) handler Native { print(amount) } # prints each hit
@On(Damage) handler Accum(modevents_st: mut ModeventsState) { modevents_st.total += amount } # sums them
@On(Damage) handler Accum { total += amount } # sums them
entry (modevents_st: ModeventsState) {
entry {
emit Damage(amount: 10) # Native prints 10
emit Damage(amount: 32) # Native prints 32
print(modevents_st.total) # 42
print(total) # 42
}
}

View file

@ -6,18 +6,16 @@
#
# Running it prints: 16 (the cycle bottoms out at the depth cap, deterministically)
program Recurse {
state RecurseState {
n: int = 0
}
var n: int = 0
event Ping { }
event Pong { }
@On(Ping) handler A(recurse_st: mut RecurseState) { recurse_st.n += 1; emit Pong() } # each Ping deepens by one Pong
@On(Ping) handler A { n += 1; emit Pong() } # each Ping deepens by one Pong
@On(Pong) handler B { emit Ping() } # ...and each Pong by one Ping
entry (recurse_st: RecurseState) {
entry {
emit Ping()
print(recurse_st.n)
print(n)
}
}

View file

@ -6,18 +6,16 @@
program Scoped {
property Health { hp: int = 0 }
model Unit { Health }
state ScopedState {
fires: int = 0
}
var fires: int = 0
event Tick { }
@On(Tick) handler OnTick(scoped_st: mut ScopedState) { for (Health) in query [Health, {Unit}] { scoped_st.fires += 1 } }
@On(Tick) handler OnTick { for (Health) in query [Health, {Unit}] { fires += 1 } }
entry (scoped_st: ScopedState) {
entry {
spawn Unit { Health { hp: 1 } }
emit Tick() # 1 live Unit -> fires = 1
emit Tick() # fires = 2
for (Health) in query [Health, {Unit}] { despawn self() } # kill the Unit
emit Tick() # no live Units -> fires stays 2
print(scoped_st.fires) # 2
print(fires) # 2
}
}