Safe Haskell | None |
---|
- bitdata :: QuasiQuoter
- data Bits n
- type Bit = Bits 1
- data BitArray n a
- type family BitRep n :: *
- repToBits :: forall n. (SingI n, IvoryRep (BitRep n)) => BitRep n -> Bits n
- bitsToRep :: Bits n -> BitRep n
- zeroBits :: IvoryRep (BitRep n) => Bits n
- bitLength :: forall a n. SingI n => BitArray n a -> Int
- bitIx :: forall a n. (BitData a, SingI n, SingI (BitSize a), SingI (ArraySize n a)) => Int -> BitDataField (BitArray n a) a
- class (SingI (BitSize (BitType a)), IvoryRep (BitDataRep a), BitType a ~ Bits (BitSize (BitType a))) => BitData a where
- data BitDataField a b
- type BitDataRep a = BitRep (BitSize (BitType a))
- toRep :: BitData a => a -> BitDataRep a
- fromRep :: BitData a => BitDataRep a -> a
- setBitDataBit :: BitData a => BitDataField a Bit -> a -> a
- clearBitDataBit :: BitData a => BitDataField a Bit -> a -> a
- getBitDataField :: (BitData a, BitData b, BitCast (BitDataRep a) (BitDataRep b)) => BitDataField a b -> a -> b
- setBitDataField :: (BitData a, BitData b, SafeCast (BitDataRep b) (BitDataRep a)) => BitDataField a b -> a -> b -> a
- (#!) :: forall a n. (BitData a, SingI n, SingI (BitSize a), SingI (ArraySize n a), BitCast (BitRep (ArraySize n a)) (BitDataRep a), IvoryRep (BitRep (ArraySize n a))) => BitArray n a -> Int -> a
- (#.) :: (BitData a, BitData b, BitCast (BitDataRep a) (BitDataRep b)) => a -> BitDataField a b -> b
- (#>) :: BitDataField a b -> BitDataField b c -> BitDataField a c
- data BitDataM d a
- runBits :: BitData d => BitDataRep d -> BitDataM d a -> (a, BitDataRep d)
- withBits :: BitData d => BitDataRep d -> BitDataM d () -> BitDataRep d
- withBitsRef :: BitData d => Ref s1 (Stored (BitDataRep d)) -> BitDataM d a -> Ivory eff a
- clear :: BitData d => BitDataM d ()
- setBit :: BitData d => BitDataField d Bit -> BitDataM d ()
- clearBit :: BitData d => BitDataField d Bit -> BitDataM d ()
- setField :: (BitData d, BitData b, SafeCast (BitDataRep b) (BitDataRep d)) => BitDataField d b -> b -> BitDataM d ()
- bitToBool :: Bit -> IBool
- boolToBit :: IBool -> Bit
quasiquoter
Quasiquoter for defining Ivory bit value and bit data types.
Only the declaration and expression forms are implemented.
bit types
A wrapper for an Ivory type that can hold an n bit unsigned integer.
type family BitRep n :: *Source
Type function: BitRep (n :: Nat) returns an Ivory type given a bit size as a type-level natural. Instances of this type family for bits [1..64] are generated using Template Haskell.
repToBits :: forall n. (SingI n, IvoryRep (BitRep n)) => BitRep n -> Bits nSource
Convert an Ivory value to a bit value. If the input value contains out of range bits, they will be ignored.
bitLength :: forall a n. SingI n => BitArray n a -> IntSource
Return the number of elements in a BitArray.
bitIx :: forall a n. (BitData a, SingI n, SingI (BitSize a), SingI (ArraySize n a)) => Int -> BitDataField (BitArray n a) aSource
Return a BitDataField that accesses the nth element of a BitArray. This can be composed with other field accessors using .
bit data
class (SingI (BitSize (BitType a)), IvoryRep (BitDataRep a), BitType a ~ Bits (BitSize (BitType a))) => BitData a whereSource
Class of bit data types defined by the bitdata quasiquoter.
toBits :: a -> BitType aSource
Convert a bit data type to its raw bit value. This is always well defined and should be exported.
fromBits :: BitType a -> aSource
Convert a raw bit value to a bit data type. All values may not be well defined with respect to the original set of bit data constructors. For now, we allow these junk values to be created, but that may change in the future (perhaps by implementing a checked, Ivory run-time conversion).
data BitDataField a b Source
Description of a bit field defined by the bitdata quasiquoter. Each field defined in the record syntax will generate a top-level definition of BitDataField.
This constructor must remain unexported so that only fields checked by the quasiquoter are created.
Show (BitDataField a b) |
type BitDataRep a = BitRep (BitSize (BitType a))Source
The Ivory type that stores the actual value for a bit data type.
This is a shorthand to simplify the constraints on functions that take arguments of the BitData class.
bit data conversions
toRep :: BitData a => a -> BitDataRep aSource
Convert a bit data value to its Ivory representation.
fromRep :: BitData a => BitDataRep a -> aSource
Convert a raw Ivory type to a bit data type. If the input value is too large, the out of range upper bits will be masked off.
bit data field operations
setBitDataBit :: BitData a => BitDataField a Bit -> a -> aSource
Set a single-bit field in a bit data value.
clearBitDataBit :: BitData a => BitDataField a Bit -> a -> aSource
Clear a single-bit field in a bit data value.
getBitDataField :: (BitData a, BitData b, BitCast (BitDataRep a) (BitDataRep b)) => BitDataField a b -> a -> bSource
Extract a field from a bit data definition. Returns the value as the type defined on the right hand side of the field definition in the bitdata quasiquoter.
setBitDataField :: (BitData a, BitData b, SafeCast (BitDataRep b) (BitDataRep a)) => BitDataField a b -> a -> b -> aSource
Set a field from a bit data definition.
bit data operators
(#!) :: forall a n. (BitData a, SingI n, SingI (BitSize a), SingI (ArraySize n a), BitCast (BitRep (ArraySize n a)) (BitDataRep a), IvoryRep (BitRep (ArraySize n a))) => BitArray n a -> Int -> aSource
(#.) :: (BitData a, BitData b, BitCast (BitDataRep a) (BitDataRep b)) => a -> BitDataField a b -> bSource
Infix operator to read a bit data field. (like Data.Lens.^.)
(#>) :: BitDataField a b -> BitDataField b c -> BitDataField a cSource
Bit data field composition. (like Control.Category.>>>)
bit actions
runBits :: BitData d => BitDataRep d -> BitDataM d a -> (a, BitDataRep d)Source
Execute a bitdata action given an initial value, returning the new bitdata value and the result of the action.
withBits :: BitData d => BitDataRep d -> BitDataM d () -> BitDataRep dSource
Execute a bitdata action given an initial value, returning the new bitdata value.
withBitsRef :: BitData d => Ref s1 (Stored (BitDataRep d)) -> BitDataM d a -> Ivory eff aSource
Execute a bit data action given a reference to a value, writing the resulting value back to the reference upon completion and returning the result of the action.
setBit :: BitData d => BitDataField d Bit -> BitDataM d ()Source
Set a single bit field in the current bit data value.
setField :: (BitData d, BitData b, SafeCast (BitDataRep b) (BitDataRep d)) => BitDataField d b -> b -> BitDataM d ()Source
Set a field to a value.