flan/test/programs/printers.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

49 lines
1.8 KiB
Plaintext

;;;; The fixture C-x C-e is tested against: one value of every shape the
;;;; renderer knows, held in globals so an expression has something real to
;;;; read out of a running process.
;;;;
;;;; It keeps running rather than counting reloads, because a thunk only runs
;;;; when the program next reaches a frame boundary. (agent/wait 5) is both the
;;;; poll and the pacing — 5ms of nothing, which is what a frame is when there
;;;; is no frame.
(import agent "vendor:agent")
(defstruct V [x f32 y f32])
(defstruct Blob [id i32 name string pos V tags [3 i32]])
(defenum Colour [red 0 green 1 blue 2])
(defonce ticks i64)
(defonce big u64)
(defonce b Blob)
(defonce arr [4 i32])
(defonce col Colour)
;;; Read by nothing on purpose: it is here to be *evaluated*, so that C-x C-e
;;; is tested against a constant living in the program's memory and not only
;;; against arithmetic the compiler could have done itself.
(defconst step-by i64 3)
;;; Called by nothing here either, and for the same reason: it is the buffer's
;;; *own* macro, and what it is for is to be called from an expression typed at
;;; the editor. A session used to hold the prelude's macros and its imports'
;;; and not these, so (tenfold 7) was an unknown name in the very file that
;;; declares it. Nothing in this program names it, so no macro module is built
;;; for the build itself -- the first one is paid by the evaluation that calls
;;; it.
(defmacro tenfold [& args]
`(* ~(at args 0) 10))
(defn main [] i32
(agent/start "/tmp/flan-printers-fallback.sock")
(set big 0xFFFFFFFFFFFFFFFF)
(set (.id b) 7)
(set (.name b) "sandy \"quoted\"")
(set (.x (.pos b)) 1.5)
(set (at (.tags b) 1) 42)
(set (at arr 2) 9)
(set col :blue)
(dotimes [i 4000]
(agent/wait 5)
(set ticks (+ ticks 1)))
0)