Remove example macroexpansion

This commit is contained in:
Joshua Suskalo 2021-09-16 15:14:24 -05:00
parent d05b5596f8
commit e3292bdff4

View file

@ -586,63 +586,6 @@
~@(list (:doc args))
fun#))))
(comment
(let [args-types [::c-string]
ret-type ::int
downcall (downcall-handle
(find-symbol "strlen")
(method-type args-types ret-type)
(function-descriptor args-types ret-type))
invoke (insn/new-instance
{:flags #{:public :final}
:super clojure.lang.AFunction
:fields [{:name "downcall_handle"
:type MethodHandle
:flags #{:final}}]
:methods [{:name :init
:flags #{:public}
:desc [MethodHandle :void]
:emit [[:aload 0]
[:dup]
[:invokespecial :super :init [:void]]
[:aload 1]
[:putfield :this "downcall_handle" MethodHandle]
[:return]]}
{:name :invoke
:flags #{:public}
:desc [Object Object]
:emit [
;; load the handle
[:aload 0]
[:getfield :this "downcall_handle" MethodHandle]
;; load the arguments
[:aload 1]
;; invokeExact
[:invokevirtual MethodHandle "invokeExact" [MemoryAddress :int]]
;; convert to object
[:istore 2]
[:new Integer]
[:dup]
[:iload 2]
[:invokespecial Integer :init [:int :void]]
;; return
[:areturn]
]}]}
downcall)
strlen (fn [str]
(with-open [scope (stack-scope)]
(let [arg1 (serialize (nth args-types 0) str scope)]
(deserialize* (invoke arg1) ret-type))))
fun strlen]
(def
^{:arglists '([str])}
strlen
"Counts the number of bytes in a C string."
fun))
)
#_:clj-kondo/ignore
(comment
;;; Prospective syntax for ffi