module C2HSState (
module State,
CST, runC2HS,
SwitchBoard(..), Traces(..), setTraces, traceSet,
putTraceStr, setSwitch, getSwitch)
where
import Control.Monad (when)
import State
import Switches (SwitchBoard(..), Traces(..),
initialSwitchBoard)
type CST s a = PreCST SwitchBoard s a
runC2HS :: (String, String, String) -> CST () a -> IO a
runC2HS :: (String, String, String) -> CST () a -> IO a
runC2HS (String, String, String)
vcd = (String, String, String) -> SwitchBoard -> CST () a -> IO a
forall e a. (String, String, String) -> e -> PreCST e () a -> IO a
run (String, String, String)
vcd SwitchBoard
initialSwitchBoard
setTraces :: (Traces -> Traces) -> CST s ()
setTraces :: (Traces -> Traces) -> CST s ()
setTraces Traces -> Traces
t = (SwitchBoard -> SwitchBoard) -> CST s ()
forall e s. (e -> e) -> PreCST e s ()
updExtra (\SwitchBoard
es -> SwitchBoard
es {tracesSB :: Traces
tracesSB = Traces -> Traces
t (SwitchBoard -> Traces
tracesSB SwitchBoard
es)})
traceSet :: (Traces -> Bool) -> CST s Bool
traceSet :: (Traces -> Bool) -> CST s Bool
traceSet Traces -> Bool
t = (SwitchBoard -> Bool) -> CST s Bool
forall e a s. (e -> a) -> PreCST e s a
readExtra (Traces -> Bool
t (Traces -> Bool) -> (SwitchBoard -> Traces) -> SwitchBoard -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SwitchBoard -> Traces
tracesSB)
putTraceStr :: (Traces -> Bool) -> String -> CST s ()
putTraceStr :: (Traces -> Bool) -> String -> CST s ()
putTraceStr Traces -> Bool
t String
msg = do
Bool
set <- (Traces -> Bool) -> CST s Bool
forall s. (Traces -> Bool) -> CST s Bool
traceSet Traces -> Bool
t
Bool -> CST s () -> CST s ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
set (CST s () -> CST s ()) -> CST s () -> CST s ()
forall a b. (a -> b) -> a -> b
$
Handle -> String -> CST s ()
forall e s. Handle -> String -> PreCST e s ()
hPutStrCIO Handle
stderr String
msg
setSwitch :: (SwitchBoard -> SwitchBoard) -> CST s ()
setSwitch :: (SwitchBoard -> SwitchBoard) -> CST s ()
setSwitch = (SwitchBoard -> SwitchBoard) -> CST s ()
forall e s. (e -> e) -> PreCST e s ()
updExtra
getSwitch :: (SwitchBoard -> a) -> CST s a
getSwitch :: (SwitchBoard -> a) -> CST s a
getSwitch = (SwitchBoard -> a) -> CST s a
forall e a s. (e -> a) -> PreCST e s a
readExtra