ivory- Safe embedded C programming.

Safe HaskellNone




bitOp :: forall a. IvoryExpr a => ExpOp -> a -> a -> aSource

class (Num a, IvoryExpr a) => IvoryBits a whereSource


(.&) :: a -> a -> aSource

(.|) :: a -> a -> aSource

(.^) :: a -> a -> aSource

iComplement :: a -> aSource

iShiftL :: a -> a -> aSource

iShiftR :: a -> a -> aSource

class (IvoryBits a, IvoryBits b) => BitSplit a b | a -> b whereSource

Extraction of the upper or lower half of a bit type into the next smallest bit type.


ubits :: a -> bSource

lbits :: a -> bSource

class (IvoryBits a, IvoryBits b) => BitCast a b whereSource

A narrowing cast from one bit type to another. This explicitly discards the upper bits of the input value to return a smaller type, and is only defined for unsigned integers.


bitCast :: a -> bSource

extractByte :: BitCast a Uint8 => a -> (Uint8, a)Source

Extract the least significant byte from an integer. This returns the two values (x & 0xFF, x >> 8), with the first value safely casted to an 8-bit integer.

This is convenient to use with a state monad and sets, such as:

 fst $ runState x $ do
   a <- sets extractByte
   b <- sets extractByte
   return (a, b)