flan/test/programs/printers.flan
Joseph Ferano b9f5b5c44c A promise the compiler cannot check gets its own refusal, and a session expands its buffer's macros
Two loose ends from NEXT.md.

slice-from-ptr's run-time refusal borrowed @flan_slice_error and reported a
range and a length the caller never wrote. It has flan_slice_promise_error
now: signals BoundsError, walks the handlers, offers the break loop, falls
through to a message and a status like the two beside it. The sentence names
what was promised and what was passed, and a second line says what is not
checked. The condition fields stay (0, n, 0) — the violated condition as a
range, and not (0, n, n), which reads as in bounds.

And a session now holds the buffer's own defmacros: seeded in Session.create
from the same read that produced decls, and added by Session.eval so a
defmacro typed at the editor joins the set the way a defn does. Not a re-read
of the file, which would put unsaved-versus-saved skew inside expansion. The
commit stays below the checker. Macro.program dedupes the ambient set against
the forms being parsed, left-wins, because unqualified names can now collide.
2026-09-13 20:33:47 +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])
(defvar ticks i64)
(defvar big u64)
(defvar b Blob)
(defvar arr [4 i32])
(defvar 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)