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

@ -21,51 +21,49 @@ program CraftingTest {
def CraftRecipes chair { out: TORCH, ins: [WOOD], ns: [3], station: BENCH }
def CraftRecipes secret { out: TORCH, ins: [WOOD], ns: [1], learned: false }
state CraftingtestState {
pack: []int = null
bench_near: bool = true
pot_takes: bool = true
pot_got: int = -1
}
var pack: []int = null
var bench_near: bool = true
var pot_takes: bool = true
var pot_got: int = -1
function count(craftingtest_st: CraftingtestState, it: int) -> int { return craftingtest_st.pack[it] }
function take(craftingtest_st: mut CraftingtestState, it: int, n: int) -> bool {
if craftingtest_st.pack[it] < n { return false }
craftingtest_st.pack[it] = craftingtest_st.pack[it] - n
function count(it: int) -> int { return pack[it] }
function take(it: int, n: int) -> bool {
if pack[it] < n { return false }
pack[it] = pack[it] - n
return true
}
function add(craftingtest_st: mut CraftingtestState, it: int, n: int) -> int {
craftingtest_st.pack[it] = craftingtest_st.pack[it] + n
function add(it: int, n: int) -> int {
pack[it] = pack[it] + n
return n
}
function room(craftingtest_st: CraftingtestState, it: int) -> int {
if it == TORCH { return 3 - craftingtest_st.pack[it] }
function room(it: int) -> int {
if it == TORCH { return 3 - pack[it] }
return 99
}
function leaves(it: int) -> int {
if it == WATER { return BOTTLE }
return -1
}
function ready(craftingtest_st: CraftingtestState, st: int) -> bool {
if st == BENCH { return craftingtest_st.bench_near }
function ready(st: int) -> bool {
if st == BENCH { return bench_near }
return true
}
function start(craftingtest_st: mut CraftingtestState, st: int, recipe: int) -> bool {
if not craftingtest_st.pot_takes { return false }
craftingtest_st.pot_got = recipe
function start(st: int, recipe: int) -> bool {
if not pot_takes { return false }
pot_got = recipe
return true
}
bind CraftPack { count: fn count, take: fn take, add: fn add, room: fn room, leaves: fn leaves }
bind CraftStations { ready: fn ready, start: fn start }
function fresh(base_st: mut BaseState, crafting_st: mut CraftingState, craftingtest_st: mut CraftingtestState) -> void {
craftingtest_st.pack = new []int
for i in 0 .. 8 { push(craftingtest_st.pack, 0) }
craft_reset(base_st, crafting_st)
function fresh() -> void {
pack = new []int
for i in 0 .. 8 { push(pack, 0) }
craft_reset()
}
function facts(base_st: mut BaseState, crafting_st: mut CraftingState) -> []Crafted { return q_drain(base_st, craft_facts(base_st, crafting_st)) }
function facts() -> []Crafted { return q_drain(craft_facts()) }
test "the registry is the game's, in the order written" {
expect_eq(CRAFT_COUNT, 5)
@ -76,105 +74,105 @@ program CraftingTest {
expect_eq(craft_find(99), -1)
}
test "made at once from the makings, and said" (base_st: mut BaseState, crafting_st: mut CraftingState, craftingtest_st: mut CraftingtestState) {
fresh(base_st, crafting_st, craftingtest_st)
test "made at once from the makings, and said" {
fresh()
expect(not craft_can(CRAFT_TORCH))
craftingtest_st.pack[WOOD] = 2
craftingtest_st.pack[CLOTH] = 1
expect(craft_make(base_st, crafting_st, CRAFT_TORCH))
expect_eq(craftingtest_st.pack[WOOD], 1)
expect_eq(craftingtest_st.pack[CLOTH], 0)
expect_eq(craftingtest_st.pack[TORCH], 1)
let fs = facts(base_st, crafting_st)
pack[WOOD] = 2
pack[CLOTH] = 1
expect(craft_make(CRAFT_TORCH))
expect_eq(pack[WOOD], 1)
expect_eq(pack[CLOTH], 0)
expect_eq(pack[TORCH], 1)
let fs = facts()
expect_eq(len(fs), 1)
expect_eq(fs[0].item, TORCH)
expect(not fs[0].queued)
}
test "nothing is taken when it cannot be made" (base_st: mut BaseState, crafting_st: mut CraftingState, craftingtest_st: mut CraftingtestState) {
fresh(base_st, crafting_st, craftingtest_st)
craftingtest_st.pack[WOOD] = 1
expect(not craft_make(base_st, crafting_st, CRAFT_TORCH))
expect_eq(craftingtest_st.pack[WOOD], 1)
expect_eq(len(facts(base_st, crafting_st)), 0)
test "nothing is taken when it cannot be made" {
fresh()
pack[WOOD] = 1
expect(not craft_make(CRAFT_TORCH))
expect_eq(pack[WOOD], 1)
expect_eq(len(facts()), 0)
}
test "the station decides, and so does the room for what it makes" (base_st: mut BaseState, crafting_st: mut CraftingState, craftingtest_st: mut CraftingtestState) {
fresh(base_st, crafting_st, craftingtest_st)
craftingtest_st.pack[WOOD] = 9
craftingtest_st.bench_near = false
test "the station decides, and so does the room for what it makes" {
fresh()
pack[WOOD] = 9
bench_near = false
expect(craft_has(CRAFT_CHAIR))
expect(not craft_can(CRAFT_CHAIR))
craftingtest_st.bench_near = true
bench_near = true
expect(craft_can(CRAFT_CHAIR))
craftingtest_st.pack[TORCH] = 3
pack[TORCH] = 3
expect(not craft_can(CRAFT_CHAIR))
}
test "an unlearned recipe is never made" (base_st: mut BaseState, crafting_st: mut CraftingState, craftingtest_st: mut CraftingtestState) {
fresh(base_st, crafting_st, craftingtest_st)
craftingtest_st.pack[WOOD] = 5
test "an unlearned recipe is never made" {
fresh()
pack[WOOD] = 5
expect(not craft_can(CRAFT_SECRET))
}
test "a timed recipe goes into its station, and water leaves its bottle" (base_st: mut BaseState, crafting_st: mut CraftingState, craftingtest_st: mut CraftingtestState) {
fresh(base_st, crafting_st, craftingtest_st)
craftingtest_st.pack[HERB] = 2
craftingtest_st.pack[WATER] = 1
expect(craft_make(base_st, crafting_st, CRAFT_TEA))
expect_eq(craftingtest_st.pot_got, CRAFT_TEA)
expect_eq(craftingtest_st.pack[TEA], 0)
expect_eq(craftingtest_st.pack[WATER], 0)
expect_eq(craftingtest_st.pack[BOTTLE], 1)
let fs = facts(base_st, crafting_st)
test "a timed recipe goes into its station, and water leaves its bottle" {
fresh()
pack[HERB] = 2
pack[WATER] = 1
expect(craft_make(CRAFT_TEA))
expect_eq(pot_got, CRAFT_TEA)
expect_eq(pack[TEA], 0)
expect_eq(pack[WATER], 0)
expect_eq(pack[BOTTLE], 1)
let fs = facts()
expect(fs[0].queued)
expect_eq(fs[0].station, POT)
}
test "a station that says no gives everything back" (base_st: mut BaseState, crafting_st: mut CraftingState, craftingtest_st: mut CraftingtestState) {
fresh(base_st, crafting_st, craftingtest_st)
craftingtest_st.pot_takes = false
craftingtest_st.pack[HERB] = 2
craftingtest_st.pack[WATER] = 1
expect(not craft_make(base_st, crafting_st, CRAFT_TEA))
expect_eq(craftingtest_st.pack[HERB], 2)
expect_eq(craftingtest_st.pack[WATER], 1)
expect_eq(craftingtest_st.pack[BOTTLE], 0)
expect_eq(len(facts(base_st, crafting_st)), 0)
test "a station that says no gives everything back" {
fresh()
pot_takes = false
pack[HERB] = 2
pack[WATER] = 1
expect(not craft_make(CRAFT_TEA))
expect_eq(pack[HERB], 2)
expect_eq(pack[WATER], 1)
expect_eq(pack[BOTTLE], 0)
expect_eq(len(facts()), 0)
}
test "a hold makes it after its seconds, and not before" (base_st: mut BaseState, crafting_st: mut CraftingState, craftingtest_st: mut CraftingtestState) {
fresh(base_st, crafting_st, craftingtest_st)
craftingtest_st.pack[HERB] = 4
test "a hold makes it after its seconds, and not before" {
fresh()
pack[HERB] = 4
expect(craft_holds(CRAFT_ROPE))
expect(not craft_holds(CRAFT_TORCH))
expect(craft_hold_start(crafting_st, CRAFT_ROPE))
expect(not craft_hold_run(base_st, crafting_st, 1.0))
expect(craft_hold_frac(crafting_st, CRAFT_ROPE) == 0.5)
expect(not craft_hold_run(base_st, crafting_st, 0.9))
expect(craft_hold_run(base_st, crafting_st, 0.2))
expect_eq(craftingtest_st.pack[ROPE], 2)
expect_eq(craft_holding(crafting_st), -1)
expect(craft_hold_start(CRAFT_ROPE))
expect(not craft_hold_run(1.0))
expect(craft_hold_frac(CRAFT_ROPE) == 0.5)
expect(not craft_hold_run(0.9))
expect(craft_hold_run(0.2))
expect_eq(pack[ROPE], 2)
expect_eq(craft_holding(), -1)
}
test "letting go wastes nothing, and losing the makings stops the hold" (base_st: mut BaseState, crafting_st: mut CraftingState, craftingtest_st: mut CraftingtestState) {
fresh(base_st, crafting_st, craftingtest_st)
craftingtest_st.pack[HERB] = 4
craft_hold_start(crafting_st, CRAFT_ROPE)
craft_hold_run(base_st, crafting_st, 1.5)
craft_hold_stop(crafting_st)
expect_eq(craftingtest_st.pack[HERB], 4)
craft_hold_start(crafting_st, CRAFT_ROPE)
craftingtest_st.pack[HERB] = 3
expect(not craft_hold_run(base_st, crafting_st, 5.0))
expect_eq(craft_holding(crafting_st), -1)
expect_eq(craftingtest_st.pack[ROPE], 0)
test "letting go wastes nothing, and losing the makings stops the hold" {
fresh()
pack[HERB] = 4
craft_hold_start(CRAFT_ROPE)
craft_hold_run(1.5)
craft_hold_stop()
expect_eq(pack[HERB], 4)
craft_hold_start(CRAFT_ROPE)
pack[HERB] = 3
expect(not craft_hold_run(5.0))
expect_eq(craft_holding(), -1)
expect_eq(pack[ROPE], 0)
}
test "a click recipe cannot be held" (base_st: mut BaseState, crafting_st: mut CraftingState, craftingtest_st: mut CraftingtestState) {
fresh(base_st, crafting_st, craftingtest_st)
craftingtest_st.pack[WOOD] = 1
craftingtest_st.pack[CLOTH] = 1
expect(not craft_hold_start(crafting_st, CRAFT_TORCH))
test "a click recipe cannot be held" {
fresh()
pack[WOOD] = 1
pack[CLOTH] = 1
expect(not craft_hold_start(CRAFT_TORCH))
}
}