feat(base): 0.R4 - a queue keeps its own count, so every package verb takes only its own state; ludic migrate state --prune

ludic.base's Queue<T> carries a QueueTag (its name and pending count): queue_new(name), q_push(q, v),
q_drain(q), q_clear(q) take no BaseState, and core_undrained(tags) names the given queues still holding
facts. A reducer on a package's state can now call that package's verbs (wallet_earn(wallet_st, n)).

ludic migrate state --prune (ludicc --migrate-prune) takes out each state parameter a function no
longer uses, nor anything it calls, and the argument that fills it - including an argument for a
parameter the callee has dropped, which is taken out before the call is checked, so a generic's T is
told by the argument that says it. A reducer keeps its state. --dry-run now counts the edits it would
make. Every package was moved with it: 608 base_st parameters and their arguments, 1889 edits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-26 04:19:56 +03:00
parent 8cf4b3fed6
commit 71735b10a2
151 changed files with 58668 additions and 54719 deletions

View file

@ -12,52 +12,64 @@ program QueueTest {
return c
}
function fifo_case(base_st: mut BaseState) -> void {
let q: Queue<int> = queue_new(base_st, "ints")
q_push(base_st, q, 3)
q_push(base_st, q, 1)
q_push(base_st, q, 2)
function fifo_case() -> void {
let q: Queue<int> = queue_new("ints")
q_push(q, 3)
q_push(q, 1)
q_push(q, 2)
expect_eq(q_len(q), 3)
let xs = q_drain(base_st, q)
let xs = q_drain(q)
expect_eq(len(xs), 3)
expect_eq(xs[0], 3)
expect_eq(xs[1], 1)
expect_eq(xs[2], 2)
expect_eq(q_len(q), 0)
expect_eq(len(q_drain(base_st, q)), 0)
expect_eq(len(q_drain(q)), 0)
}
function record_case(base_st: mut BaseState) -> void {
let q: Queue<Caught> = queue_new(base_st, "caught")
q_push(base_st, q, caught(2, 1.5))
q_push(base_st, q, caught(4, 0.25))
let cs = q_drain(base_st, q)
function record_case() -> void {
let q: Queue<Caught> = queue_new("caught")
q_push(q, caught(2, 1.5))
q_push(q, caught(4, 0.25))
let cs = q_drain(q)
expect_eq(cs[1].species, 4)
expect(cs[0].weight == 1.5)
}
function clear_case(base_st: mut BaseState) -> void {
let q: Queue<string> = queue_new(base_st, "words")
q_push(base_st, q, "a")
q_clear(base_st, q)
function clear_case() -> void {
let q: Queue<string> = queue_new("words")
q_push(q, "a")
q_clear(q)
expect_eq(q_len(q), 0)
}
function undrained_case(base_st: mut BaseState) -> void {
let a: Queue<int> = queue_new(base_st, "left_behind")
let b: Queue<int> = queue_new(base_st, "read")
q_push(base_st, a, 1)
q_push(base_st, b, 2)
q_drain(base_st, b)
let names = core_undrained(base_st)
expect_eq(len(names), 1)
expect(names[0] == "left_behind")
q_drain(base_st, a)
expect_eq(len(core_undrained(base_st)), 0)
# nothing but the queue says what T is: a drain and a clear still know it
function infer_case() -> void {
let q: Queue<Caught> = queue_new("told")
q_push(q, caught(1, 2.0))
expect_eq(q_drain(q)[0].species, 1)
q_push(q, caught(3, 1.0))
q_clear(q)
expect_eq(q_len(q), 0)
}
test "a queue drains in the order it was pushed" (base_st: mut BaseState) { fifo_case(base_st) }
test "a queue holds records" (base_st: mut BaseState) { record_case(base_st) }
test "clear drops what is waiting" (base_st: mut BaseState) { clear_case(base_st) }
test "the undrained queues are named, and a drain clears the report" (base_st: mut BaseState) { undrained_case(base_st) }
function undrained_case() -> void {
let a: Queue<int> = queue_new("left_behind")
let b: Queue<int> = queue_new("read")
q_push(a, 1)
q_push(b, 2)
q_drain(b)
let tags = [q_tag(a), q_tag(b)]
let names = core_undrained(tags)
expect_eq(len(names), 1)
expect(names[0] == "left_behind")
q_drain(a)
expect_eq(len(core_undrained(tags)), 0)
}
test "a queue drains in the order it was pushed" () { fifo_case() }
test "a queue holds records" () { record_case() }
test "clear drops what is waiting" () { clear_case() }
test "a queue's element type is told by the queue alone" () { infer_case() }
test "the undrained queues are named, and a drain clears the report" () { undrained_case() }
}

View file

@ -10,8 +10,8 @@ program RouteTest {
bind FishingWorld { is_water: fn water_everywhere_but_land }
# the route: a landed fish goes into the pack
function route_fishing_pack(base_st: mut BaseState, toy_fishing_st: ToyFishingState, toy_pack_st: mut ToyPackState, t: Tick) -> void {
let fish = q_drain(base_st, toy_fishing_st.caught)
function route_fishing_pack(toy_fishing_st: ToyFishingState, toy_pack_st: mut ToyPackState, t: Tick) -> void {
let fish = q_drain(toy_fishing_st.caught)
for i in 0 .. len(fish) { pack_add(toy_pack_st, fish[i].species, 1) }
}
@ -35,7 +35,7 @@ program RouteTest {
expect(not fishing_cast(toy_fishing_st, 500.0, 2.0))
core_tick_all(base_st, tick_new(1.0 / 60.0, 0, 0.0))
expect_eq(pack_total(toy_pack_st), 3)
expect_eq(len(core_undrained(base_st)), 0)
expect_eq(len(core_undrained([q_tag(toy_fishing_st.caught)])), 0)
}
test "the pack saves its own section and the fishing, which saves nothing, is reset" (base_st: mut BaseState, toy_fishing_st: mut ToyFishingState, toy_pack_st: ToyPackState) {

View file

@ -14,17 +14,17 @@ export function fishing_cast(toy_fishing_st: mut ToyFishingState, x: float, z: f
toy_fishing_st.casts += 1
return true
}
function fishing_reset(base_st: mut BaseState, toy_fishing_st: mut ToyFishingState) -> void {
function fishing_reset(toy_fishing_st: mut ToyFishingState) -> void {
toy_fishing_st.casts = 0
toy_fishing_st.dice = rng_new(7)
toy_fishing_st.caught = queue_new(base_st, "fishing.caught")
toy_fishing_st.caught = queue_new("fishing.caught")
}
function fishing_tick(base_st: mut BaseState, toy_fishing_st: mut ToyFishingState, t: Tick) -> void {
function fishing_tick(toy_fishing_st: mut ToyFishingState, t: Tick) -> void {
while toy_fishing_st.casts > 0 {
let c = new Caught
c.species = rng_between(toy_fishing_st.dice, 0, 2)
c.weight = 0.5 + rng_float(toy_fishing_st.dice)
q_push(base_st, toy_fishing_st.caught, c)
q_push(toy_fishing_st.caught, c)
toy_fishing_st.casts -= 1
}
}