~jojo/Carth

ref: d43904b49f898feb4b2e6ebef26d62e5651047bf Carth/std/mem.carth -rw-r--r-- 298 bytes
d43904b4JoJo std: Add Mutex 1 year, 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
(define: (box x)
    (forall (a) (Fun a (Box a)))
  (store x (transmute (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))))))