fix upcalls with strings

This commit is contained in:
Kristin Rutenkolk 2024-06-26 13:22:47 +02:00
parent 4a7659cf2a
commit 85d52f64b7
2 changed files with 7 additions and 2 deletions

View file

@ -1,6 +1,6 @@
{:paths ["src/clj" "target/classes" "resources"] {:paths ["src/clj" "target/classes" "resources"]
:deps {org.clojure/clojure {:mvn/version "1.11.1"} :deps {org.clojure/clojure {:mvn/version "1.11.1"}
insn/insn {:mvn/version "0.2.1"}} insn/insn {:mvn/version "0.5.4"}}
:deps/prep-lib {:alias :build :deps/prep-lib {:alias :build
:fn build/compile-java :fn build/compile-java

View file

@ -135,6 +135,7 @@
method handle without reflection, unboxing primitives when needed." method handle without reflection, unboxing primitives when needed."
[args ret] [args ret]
{:flags #{:public :final} {:flags #{:public :final}
:version 8
:super clojure.lang.AFunction :super clojure.lang.AFunction
:fields [{:name "downcall_handle" :fields [{:name "downcall_handle"
:type MethodHandle :type MethodHandle
@ -466,6 +467,7 @@
boxes any primitives passed to it and calls a closed over [[IFn]]." boxes any primitives passed to it and calls a closed over [[IFn]]."
[arg-types ret-type] [arg-types ret-type]
{:flags #{:public :final} {:flags #{:public :final}
:version 8
:fields [{:name "upcall_ifn" :fields [{:name "upcall_ifn"
:type IFn :type IFn
:flags #{:final}}] :flags #{:final}}]
@ -497,6 +499,10 @@
inc))) inc)))
acc)) acc))
[:invokeinterface IFn "invoke" (repeat (inc (count arg-types)) Object)] [:invokeinterface IFn "invoke" (repeat (inc (count arg-types)) Object)]
(if (identical? ::mem/pointer (mem/primitive-type ret-type))
[[:checkcast Long]
[:invokevirtual Long "longValue" [:long]]
[:invokestatic MemorySegment "ofAddress" [:long MemorySegment] true]])
(to-prim-asm ret-type) (to-prim-asm ret-type)
[(return-for-type ret-type :areturn)]]}]}) [(return-for-type ret-type :areturn)]]}]})
@ -538,7 +544,6 @@
(defmethod mem/serialize* ::fn (defmethod mem/serialize* ::fn
[f [_fn arg-types ret-type & {:keys [raw-fn?]}] arena] [f [_fn arg-types ret-type & {:keys [raw-fn?]}] arena]
(println "Attempting to serialize function of type" (str ret-type "(*)(" (clojure.string/join "," arg-types) ")"))
(.upcallStub (.upcallStub
(Linker/nativeLinker) (Linker/nativeLinker)
^MethodHandle (cond-> f ^MethodHandle (cond-> f