flan/test/programs/debug.flan

31 lines
1.2 KiB
Plaintext

;;;; The program the source-level debugging case runs under lldb.
;;;;
;;;; Every field holds a distinct known value of a distinct shape, so a DWARF
;;;; member offset that is wrong prints something obviously wrong rather than
;;;; something plausible — which is the failure mode this whole case exists
;;;; for. debug-permuted.flan is the same program with the fields declared in
;;;; a different order and every value unchanged: the two must print the same
;;;; field/value pairs from different offsets.
;;;;
;;;; alive at 0 (a byte), 7 of padding, heat at 8, id at 16, 4 of padding,
;;;; name at 24 — the slice is the member that moves if the alignment rule is
;;;; wrong, because it is the only one whose own alignment exceeds its first
;;;; member's size.
(defstruct Cell [alive bool heat f64 id i32 name str])
(defn tick [c (Ptr Cell) n i32] i32
(let [bump (+ n 1)]
(set (.heat c) (+ (.heat c) 1.5))
(set (.id c) bump)
bump))
(defn main [] i32
(let [c (Cell {.alive true .heat 3.25 .id 7 .name "grain"})]
(let [r (tick (addr c) 41)]
(print r) (println "")
(print (.heat c)) (println "")
(print (.id c)) (println "")
(print (.name c)) (println "")
0)))