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

@ -106,7 +106,7 @@ export property ShopTrade {
}
export function shop_trades(base_st: mut BaseState, shop_st: mut ShopState) -> Queue<ShopTrade> {
if shop_st.shop_trade_q == null { shop_st.shop_trade_q = queue_new(base_st, "shop.trades") }
export function shop_trades(shop_st: mut ShopState) -> Queue<ShopTrade> {
if shop_st.shop_trade_q == null { shop_st.shop_trade_q = queue_new("shop.trades") }
return shop_st.shop_trade_q
}

View file

@ -1,9 +1,9 @@
# system.ludic - the shop as a system: a reset and nothing saved (the week's demand follows from
# the day, and nobody is at a counter across a save)
export function shop_reset(base_st: mut BaseState, shop_st: mut ShopState) -> void {
export function shop_reset(shop_st: mut ShopState) -> void {
shop_st.shop_at = -1
shop_demand_reset(shop_st)
q_clear(base_st, shop_trades(base_st, shop_st))
q_clear(shop_trades(shop_st))
}
export function shop_system() -> System {

View file

@ -66,7 +66,7 @@ program ShopTest {
}
# the valley's own numbers: base prices and the sell classes
function fresh(base_st: mut BaseState, shop_st: mut ShopState, shop_test_st: mut ShopTestState) -> void {
function fresh(shop_st: mut ShopState, shop_test_st: mut ShopTestState) -> void {
let prices = new []int
let sell = new []float
let p = ints(3, 6, 8, 9)
@ -95,49 +95,49 @@ program ShopTest {
shop_test_st.rep = 0
shop_test_st.day = 1
shop_test_st.money = 0
shop_reset(base_st, shop_st)
shop_reset(shop_st)
}
function trades(base_st: mut BaseState, shop_st: mut ShopState) -> []ShopTrade { return q_drain(base_st, shop_trades(base_st, shop_st)) }
function trades(shop_st: mut ShopState) -> []ShopTrade { return q_drain(shop_trades(shop_st)) }
test "buying takes the price and puts one in the pack, and says so" (base_st: mut BaseState, shop_st: mut ShopState, shop_test_st: mut ShopTestState) {
fresh(base_st, shop_st, shop_test_st)
test "buying takes the price and puts one in the pack, and says so" (shop_st: mut ShopState, shop_test_st: mut ShopTestState) {
fresh(shop_st, shop_test_st)
shop_test_st.money = 100
shop_visit(shop_st, 0)
let pr = shop_price_buy(shop_st, JACKET)
expect(shop_buy(base_st, shop_st, JACKET))
expect(shop_buy(shop_st, JACKET))
expect_eq(shop_test_st.money, 100 - pr)
expect_eq(shop_test_st.pack[JACKET], 1)
expect(not shop_buy(base_st, shop_st, JACKET))
let ts = trades(base_st, shop_st)
expect(not shop_buy(shop_st, JACKET))
let ts = trades(shop_st)
expect_eq(len(ts), 1)
expect_eq(ts[0].what, SHOP_BOUGHT)
expect_eq(ts[0].vendor, 0)
expect_eq(ts[0].price, pr)
}
test "no money, nothing bought and nothing spent" (base_st: mut BaseState, shop_st: mut ShopState, shop_test_st: mut ShopTestState) {
fresh(base_st, shop_st, shop_test_st)
test "no money, nothing bought and nothing spent" (shop_st: mut ShopState, shop_test_st: mut ShopTestState) {
fresh(shop_st, shop_test_st)
shop_test_st.money = 3
expect(not shop_can_buy(shop_st, JACKET))
expect(not shop_buy(base_st, shop_st, JACKET))
expect(not shop_buy(shop_st, JACKET))
expect_eq(shop_test_st.money, 3)
expect_eq(len(trades(base_st, shop_st)), 0)
expect_eq(len(trades(shop_st)), 0)
}
test "selling pays what the counter's vendor pays, only what the pack has" (base_st: mut BaseState, shop_st: mut ShopState, shop_test_st: mut ShopTestState) {
fresh(base_st, shop_st, shop_test_st)
test "selling pays what the counter's vendor pays, only what the pack has" (shop_st: mut ShopState, shop_test_st: mut ShopTestState) {
fresh(shop_st, shop_test_st)
shop_test_st.pack[TROUT] = 3
shop_visit(shop_st, 2)
let pr = shop_price_sell(shop_st, TROUT)
expect_eq(shop_sell(base_st, shop_st, TROUT, 5), 3)
expect_eq(shop_sell(shop_st, TROUT, 5), 3)
expect_eq(shop_test_st.money, pr * 3)
expect_eq(shop_test_st.pack[TROUT], 0)
expect_eq(trades(base_st, shop_st)[0].n, 3)
expect_eq(trades(shop_st)[0].n, 3)
}
test "a vendor buys its list and what the world adds, never what it refuses" (base_st: mut BaseState, shop_st: mut ShopState, shop_test_st: mut ShopTestState) {
fresh(base_st, shop_st, shop_test_st)
test "a vendor buys its list and what the world adds, never what it refuses" (shop_st: mut ShopState, shop_test_st: mut ShopTestState) {
fresh(shop_st, shop_test_st)
expect(shop_buys(shop_st, 1, PUFFBALL))
expect(not shop_buys(shop_st, 1, TROUT))
shop_test_st.food_too = true
@ -149,11 +149,11 @@ program ShopTest {
expect_eq(len(s), 1)
expect_eq(s[0], TROUT)
shop_visit(shop_st, 1)
expect_eq(shop_sell(base_st, shop_st, BURNT, 1), 0)
expect_eq(shop_sell(shop_st, BURNT, 1), 0)
}
test "the week's demand is the shop's own dice, and turns with the week" (base_st: mut BaseState, shop_st: mut ShopState, shop_test_st: mut ShopTestState) {
fresh(base_st, shop_st, shop_test_st)
test "the week's demand is the shop's own dice, and turns with the week" (shop_st: mut ShopState, shop_test_st: mut ShopTestState) {
fresh(shop_st, shop_test_st)
let a = shop_wanted(shop_st, 0)
expect(len(a) > 0)
for k in 0 .. len(a) { expect(shop_buys(shop_st, 0, a[k])) }
@ -173,8 +173,8 @@ program ShopTest {
expect(moved)
}
test "a shop is not a fountain: nothing it stocks sells back for what it costs" (base_st: mut BaseState, shop_st: mut ShopState, shop_test_st: mut ShopTestState) {
fresh(base_st, shop_st, shop_test_st)
test "a shop is not a fountain: nothing it stocks sells back for what it costs" (shop_st: mut ShopState, shop_test_st: mut ShopTestState) {
fresh(shop_st, shop_test_st)
for v in 0 .. shop_vendors(shop_st) {
let st = shop_stock(shop_st, v)
for k in 0 .. len(st) {
@ -190,8 +190,8 @@ program ShopTest {
}
}
test "not even at a dollar: a penny item a vendor stocks fetches nothing" (base_st: mut BaseState, shop_st: mut ShopState, shop_test_st: mut ShopTestState) {
fresh(base_st, shop_st, shop_test_st)
test "not even at a dollar: a penny item a vendor stocks fetches nothing" (shop_st: mut ShopState, shop_test_st: mut ShopTestState) {
fresh(shop_st, shop_test_st)
shop_test_st.rep = 100
shop_set_want(shop_st, 2, GRUB)
expect_eq(shop_price_buy(shop_st, GRUB), 1)
@ -199,8 +199,8 @@ program ShopTest {
expect(shop_price_sell_at(shop_st, -1, GRUB) >= 1)
}
test "friction falls with standing and never inverts" (base_st: mut BaseState, shop_st: mut ShopState, shop_test_st: mut ShopTestState) {
fresh(base_st, shop_st, shop_test_st)
test "friction falls with standing and never inverts" (shop_st: mut ShopState, shop_test_st: mut ShopTestState) {
fresh(shop_st, shop_test_st)
var last_buy = 1000000
var last_sell = -1
for r in 0 .. 11 {
@ -221,8 +221,8 @@ program ShopTest {
expect(float(b0) / 60.0 <= 1.25)
}
test "raw material keeps its order, and is not an income" (base_st: mut BaseState, shop_st: mut ShopState, shop_test_st: mut ShopTestState) {
fresh(base_st, shop_st, shop_test_st)
test "raw material keeps its order, and is not an income" (shop_st: mut ShopState, shop_test_st: mut ShopTestState) {
fresh(shop_st, shop_test_st)
for r in 0 .. 11 {
shop_test_st.rep = r * 10
let w = shop_price_sell_at(shop_st, -1, WOOD)

View file

@ -26,14 +26,14 @@ export function shop_sellable(shop_st: ShopState, v: int) -> []int {
return out
}
function shop_trade_fact(base_st: mut BaseState, shop_st: mut ShopState, what: int, it: int, n: int, price: int) -> void {
function shop_trade_fact(shop_st: mut ShopState, what: int, it: int, n: int, price: int) -> void {
let t = new ShopTrade
t.what = what
t.vendor = shop_st.shop_at
t.item = it
t.n = n
t.price = price
q_push(base_st, shop_trades(base_st, shop_st), t)
q_push(shop_trades(shop_st), t)
}
export function shop_can_buy(shop_st: ShopState, it: int) -> bool {
@ -41,23 +41,23 @@ export function shop_can_buy(shop_st: ShopState, it: int) -> bool {
}
# one, paid for and in the pack; false and nothing spent when it cannot be
export function shop_buy(base_st: mut BaseState, shop_st: mut ShopState, it: int) -> bool {
export function shop_buy(shop_st: mut ShopState, it: int) -> bool {
if not shop_can_buy(shop_st, it) { return false }
let pr = shop_price_buy(shop_st, it)
if not ShopPurse.spend(pr) { return false }
ShopPack.add(it, 1)
shop_trade_fact(base_st, shop_st, SHOP_BOUGHT, it, 1, pr)
shop_trade_fact(shop_st, SHOP_BOUGHT, it, 1, pr)
return true
}
# `n` to the vendor at the counter (as many as the pack has); how many went
export function shop_sell(base_st: mut BaseState, shop_st: mut ShopState, it: int, n: int) -> int {
export function shop_sell(shop_st: mut ShopState, it: int, n: int) -> int {
if not shop_buys(shop_st, shop_st.shop_at, it) { return 0 }
let k = Math.min(n, ShopPack.count(it))
if k <= 0 { return 0 }
let pr = shop_price_sell(shop_st, it)
if not ShopPack.take(it, k) { return 0 }
ShopPurse.earn(pr * k)
shop_trade_fact(base_st, shop_st, SHOP_SOLD, it, k, pr)
shop_trade_fact(shop_st, SHOP_SOLD, it, k, pr)
return k
}