Ensure there's no double-evaluation of the return types
This commit is contained in:
parent
6f28994526
commit
b1133811a0
1 changed files with 45 additions and 40 deletions
|
|
@ -255,6 +255,7 @@
|
||||||
scope (gensym "scope")]
|
scope (gensym "scope")]
|
||||||
(if-not (seqable? arg-types)
|
(if-not (seqable? arg-types)
|
||||||
(let [args (gensym "args")
|
(let [args (gensym "args")
|
||||||
|
ret (gensym "ret")
|
||||||
serialized-args `(map (fn [arg# type#] (mem/serialize arg# type# ~scope)) ~args ~arg-types)
|
serialized-args `(map (fn [arg# type#] (mem/serialize arg# type# ~scope)) ~args ~arg-types)
|
||||||
prim-call `(apply ~downcall ~serialized-args)
|
prim-call `(apply ~downcall ~serialized-args)
|
||||||
non-prim-call `(apply ~downcall (mem/scope-allocator ~scope) ~serialized-args)]
|
non-prim-call `(apply ~downcall (mem/scope-allocator ~scope) ~serialized-args)]
|
||||||
|
|
@ -267,24 +268,27 @@
|
||||||
~prim-call))
|
~prim-call))
|
||||||
|
|
||||||
const-ret?
|
const-ret?
|
||||||
`(fn ~'native-fn
|
`(let [~ret ~ret-type]
|
||||||
[~'& ~args]
|
(fn ~'native-fn
|
||||||
(with-open [~scope (mem/stack-scopee)]
|
[~'& ~args]
|
||||||
~(if (mem/primitive-type ret-type)
|
(with-open [~scope (mem/stack-scopee)]
|
||||||
`(mem/deserialize* ~prim-call ~ret-type)
|
~(if (mem/primitive-type ret-type)
|
||||||
`(mem/deserialize-from ~non-prim-call ~ret-type))))
|
`(mem/deserialize* ~prim-call ~ret)
|
||||||
|
`(mem/deserialize-from ~non-prim-call ~ret)))))
|
||||||
|
|
||||||
:else
|
:else
|
||||||
`(if (mem/primitive-type ~ret-type)
|
`(let [~ret ~ret-type]
|
||||||
(fn ~'native-fn
|
(if (mem/primitive-type ~ret)
|
||||||
[~'& ~args]
|
(fn ~'native-fn
|
||||||
(with-open [~scope mem/stack-scope]
|
[~'& ~args]
|
||||||
(mem/deserialize* ~prim-call ~ret-type)))
|
(with-open [~scope mem/stack-scope]
|
||||||
(fn ~'native-fn
|
(mem/deserialize* ~prim-call ~ret)))
|
||||||
[~'& ~args]
|
(fn ~'native-fn
|
||||||
(with-open [~scope mem/stack-scope]
|
[~'& ~args]
|
||||||
(mem/deserialize-from ~non-prim-call ~ret-type))))))
|
(with-open [~scope mem/stack-scope]
|
||||||
|
(mem/deserialize-from ~non-prim-call ~ret)))))))
|
||||||
(let [arg-syms (repeatedly (count arg-types) #(gensym "arg"))
|
(let [arg-syms (repeatedly (count arg-types) #(gensym "arg"))
|
||||||
|
ret (gensym "ret")
|
||||||
serialize-args (map (fn [sym type]
|
serialize-args (map (fn [sym type]
|
||||||
(if (s/valid? ::mem/type type)
|
(if (s/valid? ::mem/type type)
|
||||||
(if-not (mem/primitive? type)
|
(if-not (mem/primitive? type)
|
||||||
|
|
@ -318,34 +322,35 @@
|
||||||
native-fn)
|
native-fn)
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(let [call (cons downcall arg-syms)
|
`(let [~ret ~ret-type]
|
||||||
prim-call `(mem/deserialize* ~call ~ret-type)
|
~(let [call (cons downcall arg-syms)
|
||||||
non-prim-call `(mem/deserialize-from ~(list* (first call)
|
prim-call `(mem/deserialize* ~call ~ret)
|
||||||
`(mem/scope-allocator ~scope)
|
non-prim-call `(mem/deserialize-from ~(list* (first call)
|
||||||
(rest call))
|
`(mem/scope-allocator ~scope)
|
||||||
~ret-type)]
|
(rest call))
|
||||||
(cond
|
~ret)]
|
||||||
(and none-to-serialize?
|
(cond
|
||||||
const-ret?)
|
(and none-to-serialize?
|
||||||
(native-fn (if (mem/primitive-type ret-type)
|
const-ret?)
|
||||||
prim-call
|
(native-fn (if (mem/primitive-type ret-type)
|
||||||
non-prim-call))
|
prim-call
|
||||||
|
non-prim-call))
|
||||||
|
|
||||||
none-to-serialize?
|
none-to-serialize?
|
||||||
`(if (mem/primitive-type ~ret-type)
|
(if (mem/primitive-type ~ret)
|
||||||
~(native-fn prim-call)
|
~(native-fn prim-call)
|
||||||
~(native-fn non-prim-call))
|
~(native-fn non-prim-call))
|
||||||
|
|
||||||
const-ret?
|
const-ret?
|
||||||
(native-fn (wrap-serialize
|
(native-fn (wrap-serialize
|
||||||
(if (mem/primitive-type ret-type)
|
(if (mem/primitive-type ret-type)
|
||||||
prim-call
|
prim-call
|
||||||
non-prim-call)))
|
non-prim-call)))
|
||||||
|
|
||||||
:else
|
:else
|
||||||
`(if (mem/primitive-type ~ret-type)
|
`(if (mem/primitive-type ~ret)
|
||||||
~(native-fn (wrap-serialize prim-call))
|
~(native-fn (wrap-serialize prim-call))
|
||||||
~(native-fn (wrap-serialize non-prim-call))))))))))
|
~(native-fn (wrap-serialize non-prim-call)))))))))))
|
||||||
|
|
||||||
(defn make-serde-wrapper
|
(defn make-serde-wrapper
|
||||||
"Constructs a wrapper function for the `downcall` which serializes the arguments
|
"Constructs a wrapper function for the `downcall` which serializes the arguments
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue