Add support for union types
This commit is contained in:
parent
382f342aa5
commit
87f48ec681
1 changed files with 22 additions and 1 deletions
|
|
@ -440,7 +440,7 @@
|
||||||
deserialize-from)
|
deserialize-from)
|
||||||
obj type)))
|
obj type)))
|
||||||
|
|
||||||
;; C String type
|
;;; C String type
|
||||||
|
|
||||||
(defmethod primitive-type ::c-string
|
(defmethod primitive-type ::c-string
|
||||||
[_type]
|
[_type]
|
||||||
|
|
@ -468,6 +468,27 @@
|
||||||
(rec (slice segment size))))))]
|
(rec (slice segment size))))))]
|
||||||
(rec segment))))
|
(rec segment))))
|
||||||
|
|
||||||
|
;;; Union types
|
||||||
|
|
||||||
|
(defmethod c-layout ::union
|
||||||
|
[[_union _dispatch types & {:as _opts} :as _type]]
|
||||||
|
(let [items (map c-layout types)]
|
||||||
|
(MemoryLayout/unionLayout
|
||||||
|
(into-array MemoryLayout items))))
|
||||||
|
|
||||||
|
(defmethod serialize-into ::union
|
||||||
|
[obj [_union dispatch _types & {:keys [extract]}] segment scope]
|
||||||
|
(let [type (dispatch obj)]
|
||||||
|
(serialize-into
|
||||||
|
(if extract
|
||||||
|
(extract type obj)
|
||||||
|
obj)
|
||||||
|
type
|
||||||
|
segment
|
||||||
|
scope)))
|
||||||
|
|
||||||
|
;;; FFI Code loading and function access
|
||||||
|
|
||||||
(defn load-system-library
|
(defn load-system-library
|
||||||
"Loads the library named `libname` from the system's load path."
|
"Loads the library named `libname` from the system's load path."
|
||||||
[libname]
|
[libname]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue