{-# 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
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Addr -> Addr -> Bool
$c/= :: Addr -> Addr -> Bool
== :: Addr -> Addr -> Bool
$c== :: Addr -> Addr -> Bool
Eq,Eq 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
min :: Addr -> Addr -> Addr
$cmin :: Addr -> Addr -> Addr
max :: Addr -> Addr -> Addr
$cmax :: Addr -> Addr -> Addr
>= :: Addr -> Addr -> Bool
$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
compare :: Addr -> Addr -> Ordering
$ccompare :: Addr -> Addr -> Ordering
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 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)) = 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)) = 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 = forall a. Ptr a -> CountOf Word8 -> Ptr a
ptrPlusSz Ptr a
ptr 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