Ensure that the downcalls in the inline expansion are evaluated correctly
This commit is contained in:
parent
39d0cd854f
commit
a620752f2c
1 changed files with 94 additions and 92 deletions
|
|
@ -252,13 +252,15 @@
|
|||
[downcall arg-types ret-type]
|
||||
(let [const-ret? (s/valid? ::mem/type ret-type)
|
||||
primitive-ret? (mem/primitive? ret-type)
|
||||
scope (gensym "scope")]
|
||||
(if-not (seqable? arg-types)
|
||||
scope (gensym "scope")
|
||||
downcall-sym (gensym "downcall")]
|
||||
`(let [~downcall-sym ~downcall]
|
||||
~(if-not (seqable? arg-types)
|
||||
(let [args (gensym "args")
|
||||
ret (gensym "ret")
|
||||
serialized-args `(map (fn [arg# type#] (mem/serialize arg# type# ~scope)) ~args ~arg-types)
|
||||
prim-call `(apply ~downcall ~serialized-args)
|
||||
non-prim-call `(apply ~downcall (mem/scope-allocator ~scope) ~serialized-args)]
|
||||
prim-call `(apply ~downcall-sym ~serialized-args)
|
||||
non-prim-call `(apply ~downcall-sym (mem/scope-allocator ~scope) ~serialized-args)]
|
||||
(cond
|
||||
(and const-ret?
|
||||
primitive-ret?)
|
||||
|
|
@ -281,11 +283,11 @@
|
|||
(if (mem/primitive-type ~ret)
|
||||
(fn ~'native-fn
|
||||
[~'& ~args]
|
||||
(with-open [~scope mem/stack-scope]
|
||||
(with-open [~scope (mem/stack-scope)]
|
||||
(mem/deserialize* ~prim-call ~ret)))
|
||||
(fn ~'native-fn
|
||||
[~'& ~args]
|
||||
(with-open [~scope mem/stack-scope]
|
||||
(with-open [~scope (mem/stack-scope)]
|
||||
(mem/deserialize-from ~non-prim-call ~ret)))))))
|
||||
(let [arg-syms (repeatedly (count arg-types) #(gensym "arg"))
|
||||
ret (gensym "ret")
|
||||
|
|
@ -314,16 +316,16 @@
|
|||
(cond
|
||||
(and none-to-serialize?
|
||||
primitive-ret?)
|
||||
downcall
|
||||
downcall-sym
|
||||
|
||||
primitive-ret?
|
||||
(-> (cons downcall arg-syms)
|
||||
(-> (cons downcall-sym arg-syms)
|
||||
wrap-serialize
|
||||
native-fn)
|
||||
|
||||
:else
|
||||
`(let [~ret ~ret-type]
|
||||
~(let [call (cons downcall arg-syms)
|
||||
~(let [call (cons downcall-sym arg-syms)
|
||||
prim-call `(mem/deserialize* ~call ~ret)
|
||||
non-prim-call `(mem/deserialize-from ~(list* (first call)
|
||||
`(mem/scope-allocator ~scope)
|
||||
|
|
@ -350,7 +352,7 @@
|
|||
:else
|
||||
`(if (mem/primitive-type ~ret)
|
||||
~(native-fn (wrap-serialize prim-call))
|
||||
~(native-fn (wrap-serialize non-prim-call)))))))))))
|
||||
~(native-fn (wrap-serialize non-prim-call))))))))))))
|
||||
|
||||
(defn make-serde-wrapper
|
||||
"Constructs a wrapper function for the `downcall` which serializes the arguments
|
||||
|
|
|
|||
Loading…
Reference in a new issue