mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
21 lines
777 B
Plaintext
21 lines
777 B
Plaintext
(load-and-use Test)
|
|
|
|
(deftemplate runner (Fn [(Ptr ()) (Ptr ())] a)
|
|
"$a $NAME(void* fn, void* args)"
|
|
"$a $NAME(void* fnptr, void* args) {
|
|
return (($a(*)(void*))fnptr)(args);
|
|
}")
|
|
|
|
(deftest test
|
|
(assert-equal test
|
|
(let [x 42 fnfn (fn [] @&x)]
|
|
(runner (Function.unsafe-ptr &fnfn) (Function.unsafe-env-ptr &fnfn)))
|
|
42
|
|
"Function.unsafe-ptr & Function.unsafe-env-ptr works as expected")
|
|
|
|
(assert-equal test
|
|
(let [x 42 fnfn (fn [y] (Int.copy y))]
|
|
(runner (Function.unsafe-ptr &fnfn) (Unsafe.coerce &x)))
|
|
42
|
|
"Function.unsafe-ptr & Unsafe.coerce works as expected"))
|