Add default c-layout and java-layout implementations for primitives
This commit is contained in:
parent
75951c5019
commit
3dcbe3ff2a
1 changed files with 31 additions and 35 deletions
|
|
@ -131,18 +131,6 @@
|
||||||
::float ::double
|
::float ::double
|
||||||
::pointer ::void})
|
::pointer ::void})
|
||||||
|
|
||||||
(def c-prim-layout
|
|
||||||
"Map of primitive type names to the [[CLinker]] types for a method handle."
|
|
||||||
{::byte CLinker/C_CHAR
|
|
||||||
::short CLinker/C_SHORT
|
|
||||||
::int CLinker/C_INT
|
|
||||||
::long CLinker/C_LONG
|
|
||||||
::long-long CLinker/C_LONG_LONG
|
|
||||||
::char CLinker/C_CHAR
|
|
||||||
::float CLinker/C_FLOAT
|
|
||||||
::double CLinker/C_DOUBLE
|
|
||||||
::pointer CLinker/C_POINTER})
|
|
||||||
|
|
||||||
(defn- type-dispatch
|
(defn- type-dispatch
|
||||||
"Gets a type dispatch value from a (potentially composite) type."
|
"Gets a type dispatch value from a (potentially composite) type."
|
||||||
[type]
|
[type]
|
||||||
|
|
@ -150,19 +138,6 @@
|
||||||
(qualified-keyword? type) type
|
(qualified-keyword? type) type
|
||||||
(sequential? type) (keyword (first type))))
|
(sequential? type) (keyword (first type))))
|
||||||
|
|
||||||
(defmulti c-layout
|
|
||||||
"Gets the layout object for a given `type`.
|
|
||||||
|
|
||||||
If a type is primitive it will return the appropriate primitive
|
|
||||||
layout (see [[c-prim-layout]]).
|
|
||||||
|
|
||||||
Otherwise, it should return a [[GroupLayout]] for the given type."
|
|
||||||
type-dispatch)
|
|
||||||
|
|
||||||
(defmethod c-layout :default
|
|
||||||
[type]
|
|
||||||
(c-prim-layout type))
|
|
||||||
|
|
||||||
(defmulti primitive-type
|
(defmulti primitive-type
|
||||||
"Gets the primitive type that is used to pass as an argument for the `type`.
|
"Gets the primitive type that is used to pass as an argument for the `type`.
|
||||||
|
|
||||||
|
|
@ -177,6 +152,31 @@
|
||||||
[type]
|
[type]
|
||||||
(primitive-types type))
|
(primitive-types type))
|
||||||
|
|
||||||
|
(def c-prim-layout
|
||||||
|
"Map of primitive type names to the [[CLinker]] types for a method handle."
|
||||||
|
{::byte CLinker/C_CHAR
|
||||||
|
::short CLinker/C_SHORT
|
||||||
|
::int CLinker/C_INT
|
||||||
|
::long CLinker/C_LONG
|
||||||
|
::long-long CLinker/C_LONG_LONG
|
||||||
|
::char CLinker/C_CHAR
|
||||||
|
::float CLinker/C_FLOAT
|
||||||
|
::double CLinker/C_DOUBLE
|
||||||
|
::pointer CLinker/C_POINTER})
|
||||||
|
|
||||||
|
(defmulti c-layout
|
||||||
|
"Gets the layout object for a given `type`.
|
||||||
|
|
||||||
|
If a type is primitive it will return the appropriate primitive
|
||||||
|
layout (see [[c-prim-layout]]).
|
||||||
|
|
||||||
|
Otherwise, it should return a [[GroupLayout]] for the given type."
|
||||||
|
type-dispatch)
|
||||||
|
|
||||||
|
(defmethod c-layout :default
|
||||||
|
[type]
|
||||||
|
(c-prim-layout (or (primitive-type type) type)))
|
||||||
|
|
||||||
(def java-prim-layout
|
(def java-prim-layout
|
||||||
"Map of primitive type names to the Java types for a method handle."
|
"Map of primitive type names to the Java types for a method handle."
|
||||||
{::byte Byte/TYPE
|
{::byte Byte/TYPE
|
||||||
|
|
@ -191,12 +191,16 @@
|
||||||
::void Void/TYPE})
|
::void Void/TYPE})
|
||||||
|
|
||||||
(defmulti java-layout
|
(defmulti java-layout
|
||||||
"Gets the Java class to an argument of this type for a method handle."
|
"Gets the Java class to an argument of this type for a method handle.
|
||||||
|
|
||||||
|
If a type serializes to a primitive it should return a Java primitive type.
|
||||||
|
|
||||||
|
Otherwise, it should return [[MemorySegment]]."
|
||||||
type-dispatch)
|
type-dispatch)
|
||||||
|
|
||||||
(defmethod java-layout :default
|
(defmethod java-layout :default
|
||||||
[type]
|
[type]
|
||||||
(java-prim-layout type MemorySegment))
|
(java-prim-layout (or (primitive-type type) type) MemorySegment))
|
||||||
|
|
||||||
(defn size-of
|
(defn size-of
|
||||||
"The size in bytes of the given `type`."
|
"The size in bytes of the given `type`."
|
||||||
|
|
@ -402,14 +406,6 @@
|
||||||
[_type]
|
[_type]
|
||||||
::pointer)
|
::pointer)
|
||||||
|
|
||||||
(defmethod c-layout ::c-string
|
|
||||||
[_type]
|
|
||||||
CLinker/C_POINTER)
|
|
||||||
|
|
||||||
(defmethod java-layout ::c-string
|
|
||||||
[_type]
|
|
||||||
MemoryAddress)
|
|
||||||
|
|
||||||
(defmethod serialize* ::c-string
|
(defmethod serialize* ::c-string
|
||||||
[obj _type scope]
|
[obj _type scope]
|
||||||
(address-of (CLinker/toCString (str obj) ^ResourceScope scope)))
|
(address-of (CLinker/toCString (str obj) ^ResourceScope scope)))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue