flan/test/programs/reach-walk.flan
Joseph Ferano 9a820d86cd Sweep every field label from the colon spelling to the dot
The script is in tools/ rather than thrown away, because two lanes are
writing Flan in the old spelling right now and their files need the same
pass at merge.

It works on forms, not on text: a keyword becomes a dot only where it sits
in a field-label position inside a brace, so an enum member in value
position, a map key inside an EDN string and a type-position {K V} are all
left alone. :keys keeps its colon -- it names no field.
2026-09-12 14:47:54 +07:00

54 lines
1.9 KiB
Plaintext

;;;; Three edges of Reach's walk, each the only route to one function.
;;;;
;;;; A release build is pruned: a function nothing reachable from main or from
;;;; a global initialiser calls is not emitted at all. So an edge the walk
;;;; forgets does not produce a wrong answer — it produces a program that does
;;;; not link, with a message about a symbol nobody wrote. Each of the three
;;;; functions below is called from exactly one place, and that place is an
;;;; edge no other program in the corpus exercises:
;;;;
;;;; index-of the index expression of a place, (set (at a (f)) v)
;;;; through a place under (addr ...), here a (deref ...) so that it is
;;;; the addr edge and not the index one again
;;;; placeholder a restart-case clause body, which is reached by a transfer
;;;; and never by a call the walk can see from the body
;;;;
;;;; Nothing here is about the values; the values are how the test notices that
;;;; the program was built and ran at all.
(defvar cells [4 i32])
(defvar slot i32)
(defstruct Nope [id i32])
(defn index-of [] i32 2)
(defn through [] (Ptr i32) (addr slot))
(defn placeholder [] i32 42)
;;; Signals with nothing to return, so the clause body is the only way past.
(defn missing [] i32
(error (Nope {.id 1})))
(defn pick [] i32
(restart-case (missing)
(use-placeholder [] (placeholder))))
(defn main [] i32
;; The index of a place is an expression, and it can call.
(set (at cells (index-of)) 10)
(print (at cells 2)) (println "")
;; (addr (deref p)) is p, so this is the addr edge over a place whose own
;; walk is Pderef rather than Pindex — the index case above cannot stand in
;; for it.
(let [q (addr (deref (through)))]
(set (deref q) 20))
(print slot) (println "")
;; The clause body, reached only because the handler transfers into it.
(handler-bind [(Nope [c] (invoke-restart 'use-placeholder))]
(print (pick)) (println ""))
0)