flan/test/programs/fill-ptr-union.flan

19 lines
760 B
Plaintext

;;;; A pointer and an untagged union take a byte fill. The union is filled
;;;; over its whole size, so its widest member reads back every byte; the
;;;; pointer is read back through a union that overlays it with a u64, since
;;;; there is no other way to see an address as a number.
(defunion U [a u32 b [8 u8]])
(defunion W [p (Ptr i32) n u64])
(defn main [] i32
(let [u (array 1 U)]
(set u (filled 0xAB))
(println (.a (at u 0))) ; 2880154539
(println (at (.b (at u 0)) 7))) ; 171
(let [w (array 1 W)]
(set (.p (at w 0)) (dead-beef))
(println (.n (at w 0))) ; 17275436393656397278
(set (at w 0) (filled 0x01))
(println (.n (at w 0)))) ; 72340172838076673
0)