diff options
| author | hallgren <hallgren@chalmers.se> | 2013-11-20 00:45:33 +0000 |
|---|---|---|
| committer | hallgren <hallgren@chalmers.se> | 2013-11-20 00:45:33 +0000 |
| commit | 018c9838ed31571b699118ae75b1d62d5527fd77 (patch) | |
| tree | e3ff7163a838915020f2a1e355c984d22df7ad9c /src/compiler/GFC.hs | |
| parent | ddac5f9e5aa935f4c154253831a36e49a48cdc8d (diff) | |
Reduced clutter in monadic code
+ Eliminated vairous ad-hoc coersion functions between specific monads
(IO, Err, IOE, Check) in favor of more general lifting functions
(liftIO, liftErr).
+ Generalized many basic monadic operations from specific monads to
arbitrary monads in the appropriate class (MonadIO and/or ErrorMonad),
thereby completely eliminating the need for lifting functions in lots
of places.
This can be considered a small step forward towards a cleaner
compiler API and more malleable compiler code in general.
Diffstat (limited to 'src/compiler/GFC.hs')
| -rw-r--r-- | src/compiler/GFC.hs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/compiler/GFC.hs b/src/compiler/GFC.hs index f75a39ab1..dd9f1771b 100644 --- a/src/compiler/GFC.hs +++ b/src/compiler/GFC.hs @@ -55,9 +55,9 @@ compileSourceFiles opts fs = compileCFFiles :: Options -> [FilePath] -> IOE () compileCFFiles opts fs = - do s <- ioeIO $ fmap unlines $ mapM readFile fs + do s <- liftIO $ fmap unlines $ mapM readFile fs let cnc = justModuleName (last fs) - gf <- ioeErr $ getCF cnc s + gf <- getCF cnc s gr <- compileSourceGrammar opts gf if flag optStopAfterPhase opts == Compile then return () @@ -76,7 +76,7 @@ unionPGFFiles opts fs = then putStrLnE $ "Refusing to overwrite " ++ pgfFile else writePGF opts pgf writeOutputs opts pgf - where readPGFVerbose f = putPointE Normal opts ("Reading " ++ f ++ "...") $ ioeIO $ readPGF f + where readPGFVerbose f = putPointE Normal opts ("Reading " ++ f ++ "...") $ liftIO $ readPGF f writeOutputs :: Options -> PGF -> IOE () writeOutputs opts pgf = do @@ -93,7 +93,7 @@ writeByteCode opts pgf path = case flag optOutputDir opts of Nothing -> file Just dir -> dir </> file - in putPointE Normal opts ("Writing " ++ path ++ "...") $ ioeIO $ + in putPointE Normal opts ("Writing " ++ path ++ "...") $ liftIO $ bracket (openFile path WriteMode) (hClose) @@ -109,14 +109,14 @@ writeByteCode opts pgf writePGF :: Options -> PGF -> IOE () writePGF opts pgf = do let outfile = grammarName opts pgf <.> "pgf" - putPointE Normal opts ("Writing " ++ outfile ++ "...") $ ioeIO $ encodeFile outfile pgf + putPointE Normal opts ("Writing " ++ outfile ++ "...") $ liftIO $ encodeFile outfile pgf grammarName :: Options -> PGF -> String grammarName opts pgf = fromMaybe (showCId (absname pgf)) (flag optName opts) writeOutput :: Options -> FilePath-> String -> IOE () writeOutput opts file str = - putPointE Normal opts ("Writing " ++ path ++ "...") $ ioeIO $ + putPointE Normal opts ("Writing " ++ path ++ "...") $ liftIO $ writeUTF8File path str where path = maybe id (</>) (flag optOutputDir opts) file |
