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

45 lines
1.5 KiB
Plaintext

;;;; A program that stops, for driving the break loop from an editor.
;;;;
;;;; It errors on its first frame, with nothing having handled the condition,
;;;; so [flan dev] meets a program that is already stopped — which is the state
;;;; an editor has to cope with, and the one that is hardest to arrange on
;;;; purpose later. Two restarts are on offer and they return different values,
;;;; so the transcript says which one was chosen.
;;;;
;;;; After resuming it keeps polling, because the claim worth testing is that
;;;; everything else still works on either side of a break.
(import agent "vendor:agent")
(defstruct Missing [id i32])
(defn fetch [n i32] i32
(restart-case
(do (error (Missing {.id n})) 0)
(use-placeholder [] -1)
(retry [] 7)))
(defonce ticks i64)
(defn step [] i64
(set ticks (+ ticks 1))
ticks)
;;; A division under a restart-case, called from the editor rather than from
;;; main. It is here for the *other* condition the runtime builds by hand:
;;; ArithError's three fields are a C struct in flan_rt.c and a defstruct in
;;; the prelude, and the break loop's render now reads them field by field,
;;; padding and all. A layout that drifted would show the op in `lhs'.
;;; The operands are parameters so nothing constant-folds the division away.
(defn divide [a i64 b i64] i64
(restart-case
(/ a b)
(use-zero [] 0)))
(defn main [] i32
(agent/start "/tmp/flan-dev-break-fallback.sock")
(print (fetch 1)) (println "")
(dotimes [i 4000]
(agent/wait 5)
(set ticks (step)))
0)