    {-# LANGUAGE MagicHash #-}
    module Basement.Types.Ptr
        ( Addr(..)
        , addrPlus
        , addrPlusSz
        , addrPlusCSz
        , Ptr(..)
        , ptrPlus
        , ptrPlusSz
        , ptrPlusCSz
        , castPtr
        ) where

    import           Basement.Compat.Base
    import           Basement.Compat.C.Types
    import           Basement.Types.OffsetSize
    import           GHC.Ptr
    import           GHC.Prim
    import           GHC.Types

    data Addr = Addr Addr#
        deriving (Addr -> Addr -> Bool
    (Addr -> Addr -> Bool) -> (Addr -> Addr -> Bool) -> Eq Addr
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Addr -> Addr -> Bool
    == :: Addr -> Addr -> Bool
    $c/= :: Addr -> Addr -> Bool
    /= :: Addr -> Addr -> Bool
    Eq,Eq Addr
    Eq Addr
    -> (Addr -> Addr -> Ordering)
    -> (Addr -> Addr -> Bool)
    -> (Addr -> Addr -> Bool)
    -> (Addr -> Addr -> Bool)
    -> (Addr -> Addr -> Bool)
    -> (Addr -> Addr -> Addr)
    -> (Addr -> Addr -> Addr)
    -> Ord Addr
    Addr -> Addr -> Bool
    Addr -> Addr -> Ordering
    Addr -> Addr -> Addr
    forall a.
    Eq a
    -> (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: Addr -> Addr -> Ordering
    compare :: Addr -> Addr -> Ordering
    $c< :: Addr -> Addr -> Bool
    < :: Addr -> Addr -> Bool
    $c<= :: Addr -> Addr -> Bool
    <= :: Addr -> Addr -> Bool
    $c> :: Addr -> Addr -> Bool
    > :: Addr -> Addr -> Bool
    $c>= :: Addr -> Addr -> Bool
    >= :: Addr -> Addr -> Bool
    $cmax :: Addr -> Addr -> Addr
    max :: Addr -> Addr -> Addr
    $cmin :: Addr -> Addr -> Addr
    min :: Addr -> Addr -> Addr
    Ord)

    addrPlus :: Addr -> Offset Word8 -> Addr
    addrPlus :: Addr -> Offset Word8 -> Addr
    addrPlus (Addr Addr#
    addr) (Offset (I# Int#
    i)) = Addr# -> Addr
    Addr (Addr# -> Int# -> Addr#
    plusAddr# Addr#
    addr Int#
    i)

    addrPlusSz :: Addr -> CountOf Word8 -> Addr
    addrPlusSz :: Addr -> CountOf Word8 -> Addr
    addrPlusSz (Addr Addr#
    addr) (CountOf (I# Int#
    i)) = Addr# -> Addr
    Addr (Addr# -> Int# -> Addr#
    plusAddr# Addr#
    addr Int#
    i)

    addrPlusCSz :: Addr -> CSize -> Addr
    addrPlusCSz :: Addr -> CSize -> Addr
    addrPlusCSz Addr
    addr = Addr -> CountOf Word8 -> Addr
    addrPlusSz Addr
    addr (CountOf Word8 -> Addr)
    -> (CSize -> CountOf Word8) -> CSize -> Addr
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
    Category cat =>
    cat b c -> cat a b -> cat a c
    . CSize -> CountOf Word8
    sizeOfCSize

    ptrPlus :: Ptr a -> Offset Word8 -> Ptr a
    ptrPlus :: forall a. Ptr a -> Offset Word8 -> Ptr a
    ptrPlus (Ptr Addr#
    addr) (Offset (I# Int#
    i)) = Addr# -> Ptr a
    forall a. Addr# -> Ptr a
    Ptr (Addr# -> Int# -> Addr#
    plusAddr# Addr#
    addr Int#
    i)

    ptrPlusSz :: Ptr a -> CountOf Word8 -> Ptr a
    ptrPlusSz :: forall a. Ptr a -> CountOf Word8 -> Ptr a
    ptrPlusSz (Ptr Addr#
    addr) (CountOf (I# Int#
    i)) = Addr# -> Ptr a
    forall a. Addr# -> Ptr a
    Ptr (Addr# -> Int# -> Addr#
    plusAddr# Addr#
    addr Int#
    i)

    ptrPlusCSz :: Ptr a -> CSize -> Ptr a
    ptrPlusCSz :: forall a. Ptr a -> CSize -> Ptr a
    ptrPlusCSz Ptr a
    ptr = Ptr a -> CountOf Word8 -> Ptr a
    forall a. Ptr a -> CountOf Word8 -> Ptr a
    ptrPlusSz Ptr a
    ptr (CountOf Word8 -> Ptr a)
    -> (CSize -> CountOf Word8) -> CSize -> Ptr a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
    Category cat =>
    cat b c -> cat a b -> cat a c
    . CSize -> CountOf Word8
    sizeOfCSize