Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
27 lines (21 sloc) 792 Bytes
;; Functions for interacting with foreign data.
(module
(extern unsafe-deref-float ((ptr float) int) -> float)
(extern unsafe-deref-int ((ptr int) int) -> int)
(extern unsafe-deref-char ((ptr char) int) -> char)
(extern unsafe-set!-float ((ptr float) int float) -> void)
(extern unsafe-set!-int ((ptr int) int int) -> void)
(extern unsafe-set!-char ((ptr char) int char) -> void)
(define (import-int-vec p n)
(let* ((v (make-vector n 0))
(vp (unsafe-vec-ptr v)))
(for (i 0 n)
(unsafe-set!-int vp i (unsafe-deref-int p i)))
v))
(define (import-float-vec p n)
(let* ((v (make-vector n 0))
(vp (unsafe-vec-ptr v)))
(for (i 0 n)
(unsafe-set!-float vp i (unsafe-deref-float p i)))
v))
)