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

@ -39,8 +39,8 @@ export state ClockState {
}
# the facts: each day that turned, in order; the game drains it and runs its morning
export function clock_days(base_st: mut BaseState, clock_st: mut ClockState) -> Queue<DayTurned> {
if clock_st.ck_days == null { clock_st.ck_days = queue_new(base_st, "clock.days") }
export function clock_days(clock_st: mut ClockState) -> Queue<DayTurned> {
if clock_st.ck_days == null { clock_st.ck_days = queue_new("clock.days") }
return clock_st.ck_days
}

View file

@ -1,6 +1,6 @@
# system.ludic - the clock as a system: it runs first (PH_INPUT) so every later system reads this
# frame's hour, and it saves its own section
function clock_tick(base_st: mut BaseState, clock_st: mut ClockState, t: Tick) -> void { clock_advance(base_st, clock_st, t.hours) }
function clock_tick(clock_st: mut ClockState, t: Tick) -> void { clock_advance(clock_st, t.hours) }
export function clock_save(clock_st: ClockState) -> Val {
let v = Value.object()
@ -10,11 +10,11 @@ export function clock_save(clock_st: ClockState) -> Val {
return v
}
export function clock_load(base_st: mut BaseState, clock_st: mut ClockState, v: Val, version: int) -> void {
export function clock_load(clock_st: mut ClockState, v: Val, version: int) -> void {
clock_st.ck_day = sv_int(v, "day", 1)
clock_set_hours(clock_st, sv_float(v, "hours", clock_st.ck_start_hours))
clock_st.ck_moon = sv_float(v, "moon", 0.5)
q_clear(base_st, clock_days(base_st, clock_st))
q_clear(clock_days(clock_st))
}
export function clock_system() -> System {

View file

@ -15,7 +15,7 @@ program ClockTest {
bind ClockWorld { owns_world: fn fake_owns, rest_scale: fn fake_rest, seed: fn fake_seed }
function fresh(base_st: mut BaseState, clock_st: mut ClockState, clock_test_st: mut ClockTestState) -> void {
function fresh(clock_st: mut ClockState, clock_test_st: mut ClockTestState) -> void {
clock_test_st.owns = true
clock_test_st.rest = 1.0
clock_config(clock_st, 8.0, 20.0, 6.0)
@ -24,71 +24,71 @@ program ClockTest {
let seasons = new []int
for m in 0 .. 12 { push(seasons, m / 3) }
clock_calendar(clock_st, 10, seasons)
clock_reset(base_st, clock_st)
clock_reset(clock_st)
}
function turned(base_st: mut BaseState, clock_st: mut ClockState) -> []DayTurned { return q_drain(base_st, clock_days(base_st, clock_st)) }
function waiting(base_st: mut BaseState, clock_st: mut ClockState) -> int { return q_len(clock_days(base_st, clock_st)) }
function turned(clock_st: mut ClockState) -> []DayTurned { return q_drain(clock_days(clock_st)) }
function waiting(clock_st: mut ClockState) -> int { return q_len(clock_days(clock_st)) }
function run_hours(h: float) -> void {
let s = clock_system()
s.tick(tick_new(0.016, 0, h))
}
test "a trip starts on day one at the start hour, the moon inside its range" (base_st: mut BaseState, clock_st: mut ClockState, clock_test_st: mut ClockTestState) {
fresh(base_st, clock_st, clock_test_st)
test "a trip starts on day one at the start hour, the moon inside its range" (clock_st: mut ClockState, clock_test_st: mut ClockTestState) {
fresh(clock_st, clock_test_st)
expect_eq(clock_day(clock_st), 1)
expect(clock_hours(clock_st) == 8.0)
expect(clock_moon(clock_st) >= 0.2 and clock_moon(clock_st) < 0.8)
expect(clock_hhmm(clock_st) == "08:00")
}
test "the same seed gives the same moon" (base_st: mut BaseState, clock_st: mut ClockState, clock_test_st: mut ClockTestState) {
fresh(base_st, clock_st, clock_test_st)
test "the same seed gives the same moon" (clock_st: mut ClockState, clock_test_st: mut ClockTestState) {
fresh(clock_st, clock_test_st)
let a = clock_moon(clock_st)
clock_reset(base_st, clock_st)
clock_reset(clock_st)
expect(clock_moon(clock_st) == a)
}
test "a real minute is a game hour at scale 60, and resting speeds it" (base_st: mut BaseState, clock_st: mut ClockState, clock_test_st: mut ClockTestState) {
fresh(base_st, clock_st, clock_test_st)
test "a real minute is a game hour at scale 60, and resting speeds it" (clock_st: mut ClockState, clock_test_st: mut ClockTestState) {
fresh(clock_st, clock_test_st)
expect(clock_hours_in(clock_st, 60.0) == 1.0)
clock_test_st.rest = 4.0
expect(clock_rate(clock_st) == 240.0)
}
test "past midnight the day turns, once, as a fact" (base_st: mut BaseState, clock_st: mut ClockState, clock_test_st: mut ClockTestState) {
fresh(base_st, clock_st, clock_test_st)
test "past midnight the day turns, once, as a fact" (clock_st: mut ClockState, clock_test_st: mut ClockTestState) {
fresh(clock_st, clock_test_st)
run_hours(15.0)
expect_eq(waiting(base_st, clock_st), 0)
expect_eq(waiting(clock_st), 0)
run_hours(2.5)
expect_eq(clock_day(clock_st), 2)
expect(clock_hours(clock_st) == 1.5)
let t = turned(base_st, clock_st)
let t = turned(clock_st)
expect_eq(len(t), 1)
expect_eq(t[0].day, 2)
expect_eq(t[0].how, DAY_STAYED_UP)
}
test "a machine that does not own the world does not move it" (base_st: mut BaseState, clock_st: mut ClockState, clock_test_st: mut ClockTestState) {
fresh(base_st, clock_st, clock_test_st)
test "a machine that does not own the world does not move it" (clock_st: mut ClockState, clock_test_st: mut ClockTestState) {
fresh(clock_st, clock_test_st)
clock_test_st.owns = false
run_hours(20.0)
expect(clock_hours(clock_st) == 8.0)
expect_eq(clock_day(clock_st), 1)
}
test "a night slept turns the day and moves the moon a month's share" (base_st: mut BaseState, clock_st: mut ClockState, clock_test_st: mut ClockTestState) {
fresh(base_st, clock_st, clock_test_st)
test "a night slept turns the day and moves the moon a month's share" (clock_st: mut ClockState, clock_test_st: mut ClockTestState) {
fresh(clock_st, clock_test_st)
let m0 = clock_moon(clock_st)
clock_set_hours(clock_st, 6.5)
clock_new_day(base_st, clock_st)
clock_new_day(clock_st)
expect_eq(clock_day(clock_st), 2)
expect(clock_moon(clock_st) > m0)
expect_eq(turned(base_st, clock_st)[0].how, DAY_SLEPT)
expect_eq(turned(clock_st)[0].how, DAY_SLEPT)
}
test "night is outside the day's hours, and the hour wraps" (base_st: mut BaseState, clock_st: mut ClockState, clock_test_st: mut ClockTestState) {
fresh(base_st, clock_st, clock_test_st)
test "night is outside the day's hours, and the hour wraps" (clock_st: mut ClockState, clock_test_st: mut ClockTestState) {
fresh(clock_st, clock_test_st)
clock_set_hours(clock_st, 21.0)
expect(clock_is_night(clock_st))
clock_set_hours(clock_st, 12.0)
@ -97,8 +97,8 @@ program ClockTest {
expect(clock_hours(clock_st) == 1.0)
}
test "the calendar is a function of the day" (base_st: mut BaseState, clock_st: mut ClockState, clock_test_st: mut ClockTestState) {
fresh(base_st, clock_st, clock_test_st)
test "the calendar is a function of the day" (clock_st: mut ClockState, clock_test_st: mut ClockTestState) {
fresh(clock_st, clock_test_st)
expect_eq(clock_season_of(clock_st, 1), 0)
expect_eq(clock_month_of(clock_st, 31), 3)
expect_eq(clock_season_of(clock_st, 31), 1)
@ -110,17 +110,17 @@ program ClockTest {
expect_eq(clock_season(clock_st), 0)
}
test "a save section reads back the same clock" (base_st: mut BaseState, clock_st: mut ClockState, clock_test_st: mut ClockTestState) {
fresh(base_st, clock_st, clock_test_st)
test "a save section reads back the same clock" (clock_st: mut ClockState, clock_test_st: mut ClockTestState) {
fresh(clock_st, clock_test_st)
clock_set_day(clock_st, 17)
clock_set_hours(clock_st, 13.25)
clock_set_moon(clock_st, 0.375)
let root = save_tree()
save_section(root, "clock", 1, clock_save(clock_st))
let text = save_encode(root)
clock_reset(base_st, clock_st)
clock_reset(clock_st)
let n = load_section(save_decode(text), "clock")
clock_load(base_st, clock_st, n.data, n.version)
clock_load(clock_st, n.data, n.version)
expect_eq(clock_day(clock_st), 17)
expect(clock_hours(clock_st) == 13.25)
expect(clock_moon(clock_st) == 0.375)

View file

@ -10,34 +10,34 @@ export function clock_set_hours(clock_st: mut ClockState, h: float) -> void {
clock_st.ck_hours = x
}
function ck_turn(base_st: mut BaseState, clock_st: mut ClockState, how: int) -> void {
function ck_turn(clock_st: mut ClockState, how: int) -> void {
clock_st.ck_day += 1
clock_st.ck_moon = (clock_st.ck_moon + 1.0 / clock_st.ck_moon_days) % 1.0
let d = new DayTurned
d.day = clock_st.ck_day
d.how = how
q_push(base_st, clock_days(base_st, clock_st), d)
q_push(clock_days(clock_st), d)
}
# a new day however it came (a night slept, a collapse); the caller sets the hour first
export function clock_new_day(base_st: mut BaseState, clock_st: mut ClockState) -> void { ck_turn(base_st, clock_st, DAY_SLEPT) }
export function clock_new_day(clock_st: mut ClockState) -> void { ck_turn(clock_st, DAY_SLEPT) }
# run the hours on by `gh` game hours; past midnight the day turns. Only the machine that owns
# the world moves it - another machine is told the time.
export function clock_advance(base_st: mut BaseState, clock_st: mut ClockState, gh: float) -> void {
export function clock_advance(clock_st: mut ClockState, gh: float) -> void {
if not ck_owns() { return }
clock_st.ck_hours = clock_st.ck_hours + gh
while not (clock_st.ck_hours < 24.0) {
clock_st.ck_hours = clock_st.ck_hours - 24.0
ck_turn(base_st, clock_st, DAY_STAYED_UP)
ck_turn(clock_st, DAY_STAYED_UP)
}
}
# a new trip: day one at the start hour, the moon somewhere in its month
export function clock_reset(base_st: mut BaseState, clock_st: mut ClockState) -> void {
export function clock_reset(clock_st: mut ClockState) -> void {
clock_st.ck_dice = rng_new(ClockWorld.seed())
clock_st.ck_day = 1
clock_st.ck_hours = clock_st.ck_start_hours
clock_st.ck_moon = rng_span(clock_st.ck_dice, clock_st.ck_moon_lo, clock_st.ck_moon_hi) % 1.0
q_clear(base_st, clock_days(base_st, clock_st))
q_clear(clock_days(clock_st))
}