flan/test/programs/dev-dyn-global.flan
Joseph Ferano a4c6b996ff def re-runs its initialiser, and defvar is renamed defonce
The trio the author decided on 2026-09-20 is now all built: def is CL's
defparameter — its initialiser runs on every daemon re-run, unguarded, so
an edited initialiser repaints the same storage on C-c C-c plus re-run —
defonce (Clojure's name for CL's defvar, per the author) initialises once
behind the .init~once. flag, and defconst stays the image.

One parse arm reads both forms; the difference is Ast.reinit, carried to
Tast.global's grerun. Emit.startup_plan gives a def no guard flag, and
Check.check_global lifts every def initialiser — zero and literal
included — into global/<n>, so the host's startup reaches it through the
function cell and a re-evaluated def swaps it (Session's def_inits;
Emit.redefinition declares the cell for a non-sibling target). The old
defvar spelling is refused with the rename and both compiling spellings,
and every program, test, doc and editor list is swept — except sand.flan,
the author's live WIP, whose seven defvar lines are flagged in FIX.org
and keep its three dependent tests red on this branch.
2026-09-21 07:12:04 +07:00

25 lines
1.1 KiB
Plaintext

;;;; A dyn global that outlives the run that filled it.
;;;;
;;;; The park is not a quiet state: the daemon services evaluated thunks on
;;;; the parked thread, a thunk allocates, and an allocation collects. So the
;;;; question this program is built to ask is whether the roots the emitted
;;;; main pushed for its dyn globals are still on the collector's stack after
;;;; the run that pushed them has finished — because the park cuts that stack
;;;; back, and cutting it back to empty took the globals with the frames.
;;;;
;;;; [config] is a map rather than a number on purpose: a dyn number is an
;;;; immediate word and survives an unrooted heap by not being on it, so it
;;;; would answer the same whether or not the root was there. What is stored
;;;; is a heap object, and reading it back is a read of heap memory.
;;;;
;;;; main returns immediately: the run has nothing to do but fill the global,
;;;; and everything this fixture is for happens after it.
(import agent "vendor:agent")
(defonce config dyn)
(defn main [] i32
(agent/start "/tmp/flan-dev-dyn-global-fallback.sock")
(set config {:s "kept" :n 1})
0)