module Foundation.Internal.Primitive
( bool#
, PinnedStatus, pinned, unpinned, isPinned
, compatAndI#
, compatQuotRemInt#
, compatCopyAddrToByteArray#
, compatMkWeak#
, compatGetSizeofMutableByteArray#
, compatShrinkMutableByteArray#
, compatResizeMutableByteArray#
, Word(..)
) where
import qualified Prelude
import GHC.Prim
import GHC.Word
#if __GLASGOW_HASKELL__ >= 800
import GHC.IO
#endif
data PinnedStatus = PinnedStatus Int#
isPinned :: PinnedStatus -> Prelude.Bool
isPinned (PinnedStatus 0#) = Prelude.False
isPinned _ = Prelude.True
pinned :: PinnedStatus
pinned = PinnedStatus 1#
unpinned :: PinnedStatus
unpinned = PinnedStatus 0#
#if MIN_VERSION_base(4,7,0)
bool# :: Int# -> Prelude.Bool
bool# v = tagToEnum# v
#else
bool# :: Prelude.Bool -> Prelude.Bool
bool# v = v
#endif
compatAndI# :: Int# -> Int# -> Int#
#if !MIN_VERSION_base(4,7,0)
compatAndI# a b = word2Int# (and# (int2Word# a) (int2Word# b))
#else
compatAndI# = andI#
#endif
compatQuotRemInt# :: Int# -> Int# -> (# Int#, Int# #)
#if !MIN_VERSION_base(4,6,0)
compatQuotRemInt# a b = (# quotInt# a b, remInt# a b #)
#else
compatQuotRemInt# = quotRemInt#
#endif
compatCopyAddrToByteArray# :: Addr# -> MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
#if MIN_VERSION_base(4,7,0)
compatCopyAddrToByteArray# = copyAddrToByteArray#
#else
compatCopyAddrToByteArray# addr ba ofs sz stini =
loop ofs 0# stini
where
loop o i st
| bool# (i ==# sz) = st
| Prelude.otherwise =
case readWord8OffAddr# addr i st of
(# st2, w #) -> loop (o +# 1#) (i +# 1#) (writeWord8Array# ba o w st2)
#endif
compatMkWeak# :: o -> b -> Prelude.IO () -> State# RealWorld -> (#State# RealWorld, Weak# b #)
#if __GLASGOW_HASKELL__ >= 800
compatMkWeak# o b c s = mkWeak# o b (case c of { IO f -> f }) s
#else
compatMkWeak# o b c s = mkWeak# o b c s
#endif
compatGetSizeofMutableByteArray# :: MutableByteArray# s -> State# s -> (#State# s, Int# #)
#if __GLASGOW_HASKELL__ >= 800
compatGetSizeofMutableByteArray# mba s = getSizeofMutableByteArray# mba s
#else
compatGetSizeofMutableByteArray# mba s = (# s, sizeofMutableByteArray# mba #)
#endif
compatShrinkMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, MutableByteArray# s #)
#if __GLASGOW_HASKELL__ >= 800
compatShrinkMutableByteArray# mba i s =
case shrinkMutableByteArray# mba i s of { s2 -> (# s2, mba #) }
#else
compatShrinkMutableByteArray# src i s =
case newAlignedPinnedByteArray# i 8# s of { (# s2, dst #) ->
case copyMutableByteArray# dst 0# src 0# i s2 of { s3 -> (# s3, dst #) }}
#endif
compatResizeMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, MutableByteArray# s #)
#if __GLASGOW_HASKELL__ >= 800
compatResizeMutableByteArray# mba i s = resizeMutableByteArray# mba i s
#else
compatResizeMutableByteArray# src i s =
case newAlignedPinnedByteArray# i 8# s of { (# s2, dst #) ->
case copyMutableByteArray# dst 0# src 0# nbBytes s2 of { s3 -> (# s3, dst #) }}
where
isGrow = bool# (i ># len)
nbBytes
| isGrow = len
| Prelude.otherwise = i
!len = sizeofMutableByteArray# src
#endif