refactor generate-struct-type to return the form via syntax quote

Co-authored-by: Joshua Suskalo <joshua@suskalo.org>
This commit is contained in:
Kristin Rutenkolk 2025-01-03 00:23:36 +01:00 committed by GitHub
parent d24ebc7810
commit a6864fdba5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2185,16 +2185,22 @@
(struct-methods [] [(s-count) (s-containsKey) (s-valAt) (s-valAt-2) (s-entryAt)]) (struct-methods [] [(s-count) (s-containsKey) (s-valAt) (s-valAt-2) (s-entryAt)])
(prefix-methods [prefix ms] (map (fn [[method-name & tail]] (cons (with-meta (symbol (str prefix method-name)) (meta method-name)) tail)) ms)) (prefix-methods [prefix ms] (map (fn [[method-name & tail]] (cons (with-meta (symbol (str prefix method-name)) (meta method-name)) tail)) ms))
(impl-methods [] (concat (prefix-methods "map_" (map-methods)) (prefix-methods "vec_" (vec-methods)) (prefix-methods "struct_" (struct-methods))))] (impl-methods [] (concat (prefix-methods "map_" (map-methods)) (prefix-methods "vec_" (vec-methods)) (prefix-methods "struct_" (struct-methods))))]
(concat `(deftype ~(symbol (name typename)) ~(vec typed-member-symbols)
[`deftype (symbol (name typename)) (vec typed-member-symbols) `coffi.mem.IStruct `coffi.mem.IStructImpl `clojure.lang.IPersistentMap `clojure.lang.MapEquivalence `java.util.Map `clojure.lang.IFn] coffi.mem.IStruct
(struct-methods) ~@(struct-methods)
(map-methods) coffi.mem.IStructImpl
(impl-methods) ~@(impl-methods)
[(s-nth-key) clojure.lang.IPersistentMap
(invoke1) clojure.lang.MapEquivalence
(invoke2) java.util.Map
(list 'asMap ['this] 'this) ~@(map-methods)
(list 'asVec ['this] (list `VecWrap. 'this))])))) clojure.lang.IFn
~(s-nth-key)
~(invoke1)
~(invoke2)
(~'asMap [~'this] ~'this)
(~'asVec [~'this] (VecWrap. ~'this)))
(defmacro defstruct (defmacro defstruct
"Defines a struct type. all members need to be supplied in pairs of `coffi-type member-name`. "Defines a struct type. all members need to be supplied in pairs of `coffi-type member-name`.