{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE UnliftedFFITypes #-}
module Basement.Compat.Primitive
( bool#
, PinnedStatus(..), toPinnedStatus#
, compatMkWeak#
, compatIsByteArrayPinned#
, compatIsMutableByteArrayPinned#
, unsafeCoerce#
, Word(..)
) where
import qualified Prelude
import GHC.Exts
import GHC.Prim
import GHC.Word
import GHC.IO
import Basement.Compat.PrimTypes
data PinnedStatus = Pinned | Unpinned
deriving (PinnedStatus -> PinnedStatus -> Bool
(PinnedStatus -> PinnedStatus -> Bool)
-> (PinnedStatus -> PinnedStatus -> Bool) -> Eq PinnedStatus
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PinnedStatus -> PinnedStatus -> Bool
$c/= :: PinnedStatus -> PinnedStatus -> Bool
== :: PinnedStatus -> PinnedStatus -> Bool
$c== :: PinnedStatus -> PinnedStatus -> Bool
Prelude.Eq)
toPinnedStatus# :: Pinned# -> PinnedStatus
toPinnedStatus# :: Pinned# -> PinnedStatus
toPinnedStatus# Pinned#
0# = PinnedStatus
Unpinned
toPinnedStatus# Pinned#
_ = PinnedStatus
Pinned
bool# :: Int# -> Prelude.Bool
bool# :: Pinned# -> Bool
bool# Pinned#
v = Pinned# -> Bool
isTrue# Pinned#
v
{-# INLINE bool# #-}
compatMkWeak# :: o -> b -> Prelude.IO () -> State# RealWorld -> (#State# RealWorld, Weak# b #)
compatMkWeak# :: o
-> b
-> IO ()
-> State# RealWorld
-> (# State# RealWorld, Weak# b #)
compatMkWeak# o
o b
b IO ()
c State# RealWorld
s = o
-> b
-> (State# RealWorld -> (# State# RealWorld, () #))
-> State# RealWorld
-> (# State# RealWorld, Weak# b #)
forall a b c.
a
-> b
-> (State# RealWorld -> (# State# RealWorld, c #))
-> State# RealWorld
-> (# State# RealWorld, Weak# b #)
mkWeak# o
o b
b (case IO ()
c of { IO State# RealWorld -> (# State# RealWorld, () #)
f -> State# RealWorld -> (# State# RealWorld, () #)
f }) State# RealWorld
s
{-# INLINE compatMkWeak# #-}
#if __GLASGOW_HASKELL__ >= 802
compatIsByteArrayPinned# :: ByteArray# -> Pinned#
compatIsByteArrayPinned# :: ByteArray# -> Pinned#
compatIsByteArrayPinned# ByteArray#
ba = ByteArray# -> Pinned#
isByteArrayPinned# ByteArray#
ba
compatIsMutableByteArrayPinned# :: MutableByteArray# s -> Pinned#
compatIsMutableByteArrayPinned# :: MutableByteArray# s -> Pinned#
compatIsMutableByteArrayPinned# MutableByteArray# s
ba = MutableByteArray# s -> Pinned#
forall d. MutableByteArray# d -> Pinned#
isMutableByteArrayPinned# MutableByteArray# s
ba
#else
foreign import ccall unsafe "basement_is_bytearray_pinned"
compatIsByteArrayPinned# :: ByteArray# -> Pinned#
foreign import ccall unsafe "basement_is_bytearray_pinned"
compatIsMutableByteArrayPinned# :: MutableByteArray# s -> Pinned#
#endif