Safe Haskell | None |
---|---|
Language | Haskell2010 |
This handy module extend Storable typeclasse with default instances for C-like enums/fixed arrays (FFI).
Using StorableExt
, we are now able to use deriving via clause on sum types.
data X = A | B | C deriving stock Enum deriving Storable via StorableExt X
This type will be stored as a word32 (C enum FFI).
Using the StorableFixedArray
, we are now able to encode fixed sizes in the type (in conjunction with storable-record Foreign.Storable.FixedArray).
data X = X (StorableFixedArray Word32 10)
This type will be stored as 10 contiguous word32 (C fixed array).
Synopsis
- newtype StorableExt a = StorableExt {
- unStorableExt :: a
- newtype StorableFixedArray a b = StorableFixedArray {}
- class Storable a
Documentation
newtype StorableExt a Source #
Wrapper to extend storable default instances.
StorableExt | |
|
Instances
Eq a => Eq (StorableExt a) Source # | |
Defined in Zydis.Util (==) :: StorableExt a -> StorableExt a -> Bool # (/=) :: StorableExt a -> StorableExt a -> Bool # | |
Show a => Show (StorableExt a) Source # | |
Defined in Zydis.Util showsPrec :: Int -> StorableExt a -> ShowS # show :: StorableExt a -> String # showList :: [StorableExt a] -> ShowS # | |
Enum a => Storable (StorableExt a) Source # | |
Defined in Zydis.Util sizeOf :: StorableExt a -> Int # alignment :: StorableExt a -> Int # peekElemOff :: Ptr (StorableExt a) -> Int -> IO (StorableExt a) # pokeElemOff :: Ptr (StorableExt a) -> Int -> StorableExt a -> IO () # peekByteOff :: Ptr b -> Int -> IO (StorableExt a) # pokeByteOff :: Ptr b -> Int -> StorableExt a -> IO () # peek :: Ptr (StorableExt a) -> IO (StorableExt a) # poke :: Ptr (StorableExt a) -> StorableExt a -> IO () # |
newtype StorableFixedArray a b Source #
Wrapper to extend storable default instances.
Instances
The member functions of this class facilitate writing values of primitive types to raw memory (which may have been allocated with the above mentioned routines) and reading values from blocks of raw memory. The class, furthermore, includes support for computing the storage requirements and alignment restrictions of storable types.
Memory addresses are represented as values of type
, for some
Ptr
aa
which is an instance of class Storable
. The type argument to
Ptr
helps provide some valuable type safety in FFI code (you can't
mix pointers of different types without an explicit cast), while
helping the Haskell type system figure out which marshalling method is
needed for a given pointer.
All marshalling between Haskell and a foreign language ultimately
boils down to translating Haskell data structures into the binary
representation of a corresponding data structure of the foreign
language and vice versa. To code this marshalling in Haskell, it is
necessary to manipulate primitive data types stored in unstructured
memory blocks. The class Storable
facilitates this manipulation on
all types for which it is instantiated, which are the standard basic
types of Haskell, the fixed size Int
types (Int8
, Int16
,
Int32
, Int64
), the fixed size Word
types (Word8
, Word16
,
Word32
, Word64
), StablePtr
, all types from Foreign.C.Types,
as well as Ptr
.
sizeOf, alignment, (peek | peekElemOff | peekByteOff), (poke | pokeElemOff | pokeByteOff)