33 lines
1.5 KiB
Plaintext
33 lines
1.5 KiB
Plaintext
;;;; A frame loop that formats numbers every frame and calls (free-temp) at the
|
|
;;;; end of each. i64->bytes and f64->bytes put their text in the temp
|
|
;;;; allocator, so the loop's memory stays flat however many frames it runs,
|
|
;;;; and in a dev build the allocation registry does not fill: each frame's
|
|
;;;; blocks die at the free-temp and their addresses are handed out again.
|
|
;;;; Frame 7's text is kept past its free-temp by cloning it into the heap,
|
|
;;;; which is how text outlives its frame.
|
|
;;;;
|
|
;;;; The argument is the frame count. A negative one runs that many frames and
|
|
;;;; never calls free-temp, which is the control: memory grows and a dev
|
|
;;;; build's registry fills. The last line is whether more blocks are live
|
|
;;;; than the registry's first size, 4096 — it grows past that rather than
|
|
;;;; drop notes, so the live count is what says it filled.
|
|
(declare-c reg-live [live-only i32] i64 "flan_dev_reg_count")
|
|
|
|
(defn main [args [str]] i32
|
|
(let [arg (bytes->i64 (bytes-view (at args 1)))
|
|
n (if (< arg 0) (- 0 arg) arg)
|
|
total (i64 0)
|
|
kept (bytes-view "")]
|
|
(dotimes [i (i32 n)]
|
|
(let [s (str (i64->bytes (i64 i)))
|
|
f (f64->bytes (+ (f64 i) 0.5))]
|
|
(set total (+ total (i64 (+ (length (bytes-view s)) (length f)))))
|
|
(when (= i 7)
|
|
(set kept (clone f (heap-allocator)))))
|
|
(when (> arg 0)
|
|
(free-temp)))
|
|
(println total)
|
|
(println (str kept))
|
|
(println (if (> (reg-live 1) 4096) 1 0)))
|
|
0)
|