{-# LANGUAGE Unsafe #-}
{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples #-}
{-# OPTIONS_GHC -funbox-strict-fields #-}
{-# OPTIONS_HADDOCK hide #-}
module GHC.Internal.IOPort (
IOPort(..)
, newIOPort
, newEmptyIOPort
, readIOPort
, writeIOPort
, doubleReadException
) where
import GHC.Internal.Base
import GHC.Internal.Exception
import GHC.Internal.Text.Show
data IOPortException = IOPortException deriving Int -> IOPortException -> ShowS
[IOPortException] -> ShowS
IOPortException -> String
(Int -> IOPortException -> ShowS)
-> (IOPortException -> String)
-> ([IOPortException] -> ShowS)
-> Show IOPortException
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> IOPortException -> ShowS
showsPrec :: Int -> IOPortException -> ShowS
$cshow :: IOPortException -> String
show :: IOPortException -> String
$cshowList :: [IOPortException] -> ShowS
showList :: [IOPortException] -> ShowS
Show
instance Exception IOPortException where
displayException :: IOPortException -> String
displayException IOPortException
IOPortException = String
"IOPortException"
doubleReadException :: SomeException
doubleReadException :: SomeException
doubleReadException = IOPortException -> SomeException
forall e. Exception e => e -> SomeException
toException IOPortException
IOPortException
data IOPort a = IOPort (IOPort# RealWorld a)
instance Eq (IOPort a) where
(IOPort IOPort# RealWorld a
ioport1#) == :: IOPort a -> IOPort a -> Bool
== (IOPort IOPort# RealWorld a
ioport2#) =
Int# -> Bool
isTrue# (IOPort# RealWorld a -> IOPort# RealWorld a -> Int#
forall s a. IOPort# s a -> IOPort# s a -> Int#
sameIOPort# IOPort# RealWorld a
ioport1# IOPort# RealWorld a
ioport2#)
newEmptyIOPort :: IO (IOPort a)
newEmptyIOPort :: forall a. IO (IOPort a)
newEmptyIOPort = (State# RealWorld -> (# State# RealWorld, IOPort a #))
-> IO (IOPort a)
forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO ((State# RealWorld -> (# State# RealWorld, IOPort a #))
-> IO (IOPort a))
-> (State# RealWorld -> (# State# RealWorld, IOPort a #))
-> IO (IOPort a)
forall a b. (a -> b) -> a -> b
$ \ State# RealWorld
s# ->
case State# RealWorld -> (# State# RealWorld, IOPort# RealWorld a #)
forall d a. State# d -> (# State# d, IOPort# d a #)
newIOPort# State# RealWorld
s# of
(# State# RealWorld
s2#, IOPort# RealWorld a
svar# #) -> (# State# RealWorld
s2#, IOPort# RealWorld a -> IOPort a
forall a. IOPort# RealWorld a -> IOPort a
IOPort IOPort# RealWorld a
svar# #)
newIOPort :: a -> IO (IOPort a)
newIOPort :: forall a. a -> IO (IOPort a)
newIOPort a
value =
IO (IOPort a)
forall a. IO (IOPort a)
newEmptyIOPort IO (IOPort a) -> (IOPort a -> IO (IOPort a)) -> IO (IOPort a)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \ IOPort a
ioport ->
IOPort a -> a -> IO Bool
forall a. IOPort a -> a -> IO Bool
writeIOPort IOPort a
ioport a
value IO Bool -> IO (IOPort a) -> IO (IOPort a)
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
IOPort a -> IO (IOPort a)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return IOPort a
ioport
readIOPort :: IOPort a -> IO a
readIOPort :: forall a. IOPort a -> IO a
readIOPort (IOPort IOPort# RealWorld a
ioport#) = (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO ((State# RealWorld -> (# State# RealWorld, a #)) -> IO a)
-> (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
forall a b. (a -> b) -> a -> b
$ \ State# RealWorld
s# -> IOPort# RealWorld a
-> State# RealWorld -> (# State# RealWorld, a #)
forall d a. IOPort# d a -> State# d -> (# State# d, a #)
readIOPort# IOPort# RealWorld a
ioport# State# RealWorld
s#
writeIOPort :: IOPort a -> a -> IO Bool
writeIOPort :: forall a. IOPort a -> a -> IO Bool
writeIOPort (IOPort IOPort# RealWorld a
ioport#) a
x = (State# RealWorld -> (# State# RealWorld, Bool #)) -> IO Bool
forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO ((State# RealWorld -> (# State# RealWorld, Bool #)) -> IO Bool)
-> (State# RealWorld -> (# State# RealWorld, Bool #)) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \ State# RealWorld
s# ->
case IOPort# RealWorld a
-> a -> State# RealWorld -> (# State# RealWorld, Int# #)
forall d a. IOPort# d a -> a -> State# d -> (# State# d, Int# #)
writeIOPort# IOPort# RealWorld a
ioport# a
x State# RealWorld
s# of
(# State# RealWorld
s, Int#
0# #) -> (# State# RealWorld
s, Bool
False #)
(# State# RealWorld
s, Int#
_ #) -> (# State# RealWorld
s, Bool
True #)