From de81b0e81c75e0d66c5fb0d5c0569e98d2e9c293 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Fri, 8 Feb 2008 11:21:42 +0000 Subject: [PATCH] Added a version of PassM that only requires read access to the state (i.e. needs CSMR) called PassMR --- common/Pass.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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