flan/test/programs/dev-parity.flan

112 lines
3.5 KiB
Plaintext

;;;; One global of every shape the inspector walks, for comparing two
;;;; renderings of each: the break loop's [globals], which reads the stopped
;;;; program's memory through lib/inspect.ml and compiles nothing, and an
;;;; evaluated expression naming the global, which is still rendered by a
;;;; compiled thunk through lib/render.ml. They must agree byte for byte —
;;;; the editor parses both back, and a value that read one way in the break
;;;; buffer and another at C-x C-e would be two answers to one question.
(import agent "vendor:agent")
(defstruct Boom [why i32])
(defstruct Point [x f32 y f32])
(defstruct Wide [a i32 b i32 c i32 d i32 e i32 f i32 g i32 h i32 i i32 j i32])
(defstruct In4 [v i32])
(defstruct In3 [v In4])
(defstruct In2 [v In3])
(defstruct In1 [v In2])
(defstruct In0 [v In1])
(defstruct Enemy [hp i32 x i32])
(defenum Colour [red 0 green 1 blue 2])
(defdata Shape
[Empty
(Dot [x f64 y f64])
(Rect [w i32 h i32])])
(defunion W [p (Ptr i32) n u64])
(defstruct Pair [a $t b $t])
(defonce small i8)
(defonce mid u16)
(defonce large u32)
(defonce huge u64)
(defonce neg i64)
(defonce ratio f32)
(defonce far f64)
(defonce odd f64)
(defonce yes bool)
(defonce byte u8)
(defonce text string)
(defonce colour Colour)
(defonce stray Colour)
(defonce some (Option Point))
(defonce none (Option i32))
(defonce wide Wide)
(defonce deep In0)
(defonce dot Shape)
(defonce empty Shape)
(defonce row [10 i32])
(defonce words [u8])
(defonce nums [i32])
(defonce live (Ptr Enemy))
(defonce dead (Ptr Enemy))
(defonce nowhere (Ptr Enemy))
(defonce un W)
(defonce anything dyn)
(defonce pair (Pair i32))
;; The innermost frame names every global above, so the break loop's section
;; holds all of them; then it stops. It prints them, and a frame whose only
;; slots are the printer's temporaries is still attributed its globals.
(defn inner [] i64
(print small) (print mid) (print large) (print huge)
(print neg) (print ratio) (print far) (print odd) (print yes)
(print byte) (print text) (print colour) (print stray)
(print some) (print none) (print wide) (print deep)
(print dot) (print empty) (print row) (print words)
(print nums) (print live) (print dead) (print nowhere)
(print un) (print anything) (print pair)
(println "")
(error (Boom {.why 3}))
0)
(defn main [] i32
(agent/start "/tmp/flan-dev-parity-fallback.sock")
(let [v (vec-new Enemy)
w (vec-new Enemy)
bytes (vec-new u8)
ints (vec-new i32)]
(push v (Enemy {.hp 41 .x 2}))
(push w (Enemy {.hp 7 .x 9}))
(push bytes 104) (push bytes 105) (push bytes 10)
(push ints 4) (push ints -5) (push ints 6)
(set live (addr (at v 0)))
(set dead (addr (at w 0)))
(free w)
(set words (slice bytes))
(set nums (slice ints))
(set small -5)
(set mid 65535)
(set large 4000000000)
(set huge (u64 -1))
(set neg -9000000000)
(set ratio 1.25)
(set far 3.5e20)
(set odd (/ 0.0 0.0))
(set yes true)
(set byte 97)
(set text "a\"b\\c\nd\te")
(set colour :blue)
(set some (Some (Point {.x 1.5 .y -2.5})))
(set wide (Wide {.a 1 .b 2 .c 3 .d 4 .e 5 .f 6 .g 7 .h 8 .i 9 .j 10}))
(set deep (In0 {.v (In1 {.v (In2 {.v (In3 {.v (In4 {.v 5})})})})}))
(set dot (Shape.Dot {.x 0.5 .y 2}))
(set empty Shape.Empty)
(set (at row 0) 11)
(set (at row 9) 99)
(set un (W {.n 12}))
(set anything {:s "kept" :n 1})
(set pair (Pair 3 4))
(print (inner)) (println ""))
(dotimes [i 4000]
(agent/wait 5))
0)