flan/test/programs/agent-hooks.flan

28 lines
1.2 KiB
Plaintext

;;;; The Flan half of test/agent_hooks.c, which is the program's entry point:
;;;; this file has no [main]. It exists to put restart frames on the stack in
;;;; numbers no hand-written program would, and then stop.
;;;;
;;;; One restart per level of recursion, so the depth is the number of frames
;;;; a break loop is offered. Taking the restart at a level returns that
;;;; level's own number, which is how the harness sees which frame it landed
;;;; in.
(import agent "vendor:agent")
(defstruct Deep [n i32])
(defn deep [n i32] i32
(restart-case
(if (= n 0) (do (error (Deep {.n n})) 0) (deep (- n 1)))
(retry [] n)))
;;; The same, with a name two hundred bytes long, so the snapshot's name
;;; buffer fills before its entry count does.
(defn wide [n i32] i32
(restart-case
(if (= n 0) (do (error (Deep {.n n})) 0) (wide (- n 1)))
(retry-with-a-name-long-enough-that-twenty-of-them-fill-the-four-kilobytes-a-break-loop-keeps-for-the-names-of-its-restarts-and-the-twenty-first-does-not-fit-anywhere-in-the-buffer-at-all-xxx-and-so-on [] n)))
;;; A dyn keyword, so the dyn runtime is linked and the agent's [dyn] verb has
;;; something to render. agent_hooks.c's "resuming" mode reads one.
(defn dynword [] dyn :k)