refactor generate-struct-type to return the form via syntax quote
Co-authored-by: Joshua Suskalo <joshua@suskalo.org>
This commit is contained in:
parent
d24ebc7810
commit
a6864fdba5
1 changed files with 16 additions and 10 deletions
|
|
@ -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`.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue