Add some more helpers for the Generator monad

This commit is contained in:
Tristan Ravitch 2017-10-04 09:49:17 -07:00
parent 00f2b1d423
commit 48f556ffcb

View File

@ -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)