~jojo/Carth

ref: 749208029494a7c48ce04444a513424f4b998416 Carth/std/mem.carth -rw-r--r-- 383 bytes
74920802JoJo update TODO 6 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))