~jojo/Carth

ref: 55fb4f948f1f3797078b584dc60b4f7dd68b37ed Carth/std/mem.carth -rw-r--r-- 383 bytes
55fb4f94JoJo Check `cast` in Infer instead of Gen 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
(define: (box x)
    (forall (a) (Fun a (Box a)))
  (store x (cast-ptr (id@"GC_malloc" (sizeof a)))))

(define: cast-ptr
    (forall (a b) (Fun (Box a) (Box b)))
  transmute)

(define: (ptr/+ ptr x) (forall (a) (Fun (Box a) Nat (Box a)))
  (transmute (+ (transmute ptr) (* x (cast (sizeof a))))))

(define: (mem/unsafe-null Unit)
    (forall (a) (Fun Unit (Box a)))
  (transmute 0))