diff --git a/common/Pass.hs b/common/Pass.hs index e54445a..204f3f6 100644 --- a/common/Pass.hs +++ b/common/Pass.hs @@ -20,6 +20,7 @@ with this program. If not, see . module Pass where import Control.Monad.Error +import Control.Monad.Reader import Control.Monad.State import Data.Generics import Data.List @@ -34,13 +35,24 @@ import TreeUtils -- | The monad in which AST-mangling passes operate. type PassM = ErrorT ErrorReport (StateT CompState IO) +type PassMR = ErrorT ErrorReport (ReaderT CompState IO) instance Die PassM where dieReport = throwError +instance Die PassMR where + dieReport = throwError + -- | The type of an AST-mangling pass. type Pass = A.AST -> PassM A.AST +runPassR :: PassMR a -> PassM a +runPassR p = do st <- get + r <- liftIO $ runReaderT (runErrorT p) st + case r of + Left err -> throwError err + Right result -> return result + -- | Compose a list of passes into a single pass. runPasses :: [(String, Pass)] -> Pass runPasses [] ast = return ast