mirror of
https://github.com/GaloisInc/macaw.git
synced 2024-11-24 08:53:12 +03:00
Add some more helpers for the Generator monad
This commit is contained in:
parent
00f2b1d423
commit
48f556ffcb
@ -11,6 +11,8 @@ module Data.Macaw.PPC.Generator (
|
|||||||
PPCGenerator,
|
PPCGenerator,
|
||||||
runGenerator,
|
runGenerator,
|
||||||
execGenerator,
|
execGenerator,
|
||||||
|
evalGenerator,
|
||||||
|
genResult,
|
||||||
Expr(..),
|
Expr(..),
|
||||||
BlockSeq(..),
|
BlockSeq(..),
|
||||||
PreBlock(..),
|
PreBlock(..),
|
||||||
@ -160,6 +162,16 @@ runGenerator s0 act = ET.runExceptT (St.runStateT (runGen act) s0)
|
|||||||
execGenerator :: GenState ppc s -> PPCGenerator ppc s () -> ST s (Either GeneratorError (GenState ppc s))
|
execGenerator :: GenState ppc s -> PPCGenerator ppc s () -> ST s (Either GeneratorError (GenState ppc s))
|
||||||
execGenerator s0 act = ET.runExceptT (St.execStateT (runGen act) s0)
|
execGenerator s0 act = ET.runExceptT (St.execStateT (runGen act) s0)
|
||||||
|
|
||||||
|
evalGenerator :: GenState ppc s -> PPCGenerator ppc s a -> ST s (Either GeneratorError a)
|
||||||
|
evalGenerator s0 act = ET.runExceptT (St.evalStateT (runGen act) s0)
|
||||||
|
|
||||||
|
genResult :: PPCGenerator ppc s (GenResult ppc s)
|
||||||
|
genResult = do
|
||||||
|
s <- St.get
|
||||||
|
return GenResult { resBlockSeq = blockSeq s
|
||||||
|
, resState = Just (s ^. blockState)
|
||||||
|
}
|
||||||
|
|
||||||
addStmt :: Stmt ppc s -> PPCGenerator ppc s ()
|
addStmt :: Stmt ppc s -> PPCGenerator ppc s ()
|
||||||
addStmt stmt = (blockState . pBlockStmts) %= (Seq.|> stmt)
|
addStmt stmt = (blockState . pBlockStmts) %= (Seq.|> stmt)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user