flan/test/programs/dyn-index-site.flan

32 lines
1.1 KiB
Plaintext

;;;; dyn-trap-site.flan's prefix, for the three container operations: at,
;;;; set-at and push. Each trap prints the file, line and column of the call
;;;; that failed, ahead of its sentence.
;;;;
;;;; The argument chooses which one fails, one per run, because each ends the
;;;; process. The line numbers are asserted by the test, so an edit above them
;;;; moves them. Modes 3 and 4 reach at and set-at through a view of a typed
;;;; Vec whose arena was released, which is a different trap on the same call.
(defn as-dyn [d dyn] dyn d)
(defonce tv (Vec i64))
(defn main [args [str]] i32
(let [which (if (> (length args) 1) (i32 (bytes->i64 (bytes-view (at args 1)))) 0)
v (vec-new dyn)
ar (arena-new 4096)]
(push v 1)
(set tv (vec-new i64 ar))
(push tv 7)
(println "before")
(cond
(= which 0) (println (at v 5))
(= which 1) (set (at v 5) 2)
(= which 2) (let [n (at v 0)] (push n 3))
:else
(let [dv (as-dyn tv)]
(free-all ar)
(if (= which 3)
(println (at dv 0))
(set (at dv 0) 8)))))
0)