-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Haskell functionality for quickly assembling simple compilers. -- -- Haskell monad and combinators for quickly assembling simple -- compilation algorithms. @package compilation @version 0.0.0.2 -- | Compilation Monad and combinators for quickly assembling simple -- compilers. -- --
--   Control/Compilation.hs
--   
-- -- A generic compilation monad for quickly assembling simple compilers. module Control.Compilation -- | Data types, class declarations, and class memberships. type FreshIndex = Integer type Indentation = String type ModuleName = String type NestingDepth = Integer data State a State :: FreshIndex -> Indentation -> (Maybe ModuleName) -> NestingDepth -> a -> State a class StateExtension a initial :: StateExtension a => a type Compile a b = Compilation a b data Compilation a b Compilation :: (State a -> (State a, b)) -> Compilation a b Error :: String -> Compilation a b -- | Generic combinators and functions. extract :: StateExtension a => Compilation a b -> a extractFromState :: StateExtension a => a -> Compilation a b -> a nothing :: Compilation a () get :: StateExtension a => Compilation a a set :: StateExtension a => a -> Compilation a () error :: String -> Compilation a () instance StateExtension () instance StateExtension a => Monad (Compilation a) -- | Compilation Monad and combinators for quickly assembling simple -- compilers. -- --
--   Control/Compilation/Fresh.hs
--   
-- -- State extension class and combinators for implementations of a state -- that support generation of fresh (i.e., unique) values (integers and -- strings). module Control.Compilation.Fresh -- | State extension class definition, including combinators and convenient -- synonyms. class StateExtension a => Fresh a where freshInteger = do { s <- get; i <- return $ project s; set $ inject (i + 1) s; return $ i } freshString = do { i <- freshInteger; return $ show i } freshStringWithPrefix prefix = do { s <- freshString; return $ prefix ++ s } freshWithPrefix = freshStringWithPrefix fresh = freshString fresh_ = freshStringWithPrefix freshes i = do { ns <- mapM (\ _ -> fresh) [0 .. i - 1]; return $ [show n | n <- ns] } freshes_ prefix i = do { ns <- mapM (\ _ -> fresh) [0 .. i - 1]; return $ [prefix ++ show n | n <- ns] } project :: Fresh a => a -> Integer inject :: Fresh a => Integer -> a -> a freshInteger :: Fresh a => Compilation a Integer freshString :: Fresh a => Compilation a String freshStringWithPrefix :: Fresh a => String -> Compilation a String freshWithPrefix :: Fresh a => String -> Compilation a String fresh :: Fresh a => Compilation a String fresh_ :: Fresh a => String -> Compilation a String freshes :: Fresh a => Integer -> Compilation a [String] freshes_ :: Fresh a => String -> Integer -> Compilation a [String] -- | Compilation Monad and combinators for quickly assembling simple -- compilers. -- --
--   Control/Compilation/Module.hs
--   
-- -- State extension class and combinators for implementations of a state -- that support module name specification. module Control.Compilation.Module -- | State extension class definition, including combinators. class StateExtension a => Module a where setModule m = do { s <- get; set $ inject m s } getModule = do { s <- get; return $ project s } project :: Module a => a -> String inject :: Module a => String -> a -> a setModule :: Module a => String -> Compilation a () getModule :: Module a => Compilation a String -- | Compilation Monad and combinators for quickly assembling simple -- compilers. -- --
--   Control/Compilation/Environment.hs
--   
-- -- State extension class and combinators for implementations of a state -- that support an environment (i.e., lookup table or dictionary) data -- structure or structures. module Control.Compilation.Environment -- | Type synonyms. type Env a = [(String, a)] -- | State extension class definition. class StateExtension a => Environment a b where addEnv v x = do { s :: a <- get; env :: Env b <- return $ project s; set $ inject ((v, x) : env) s } popEnv = do { s :: a <- get; env :: Env b <- return $ project s; set $ inject (tail env) s } dropEnv n = do { s :: a <- get; env :: Env b <- return $ project s; set $ inject (drop n env) s } lookupEnv v = do { s :: a <- get; env :: Env b <- return $ project s; return $ lookup v env } setEnv env = do { s :: a <- get; set $ inject env s } getEnv = do { s :: a <- get; env :: Env b <- return $ project s; return $ env } project :: Environment a b => a -> Env b inject :: Environment a b => Env b -> a -> a addEnv :: Environment a b => String -> b -> Compilation a () popEnv :: Environment a b => Compilation a () dropEnv :: Environment a b => Int -> Compilation a () lookupEnv :: Environment a b => String -> Compilation a (Maybe b) setEnv :: Environment a b => Env b -> Compilation a () getEnv :: Environment a b => Compilation a (Env b) -- | Compilation Monad and combinators for quickly assembling simple -- compilers. -- --
--   Control/Compilation/String.hs
--   
-- -- A generic compilation monad and combinators for quickly assembling -- simple compilers that emit an ASCII string representation of the -- target language (well-suited for direct syntax translators). module Control.Compilation.String -- | Combinators and functions for compiling directly into a raw ASCII -- string. indent :: Compilation String () unindent :: Compilation String () space :: Compilation String () spaces :: Int -> Compilation String () newline :: Compilation String () newlines :: Int -> Compilation String () string :: String -> Compilation String () raw :: String -> Compilation String () -- | Compilation Monad and combinators for quickly assembling simple -- compilers. -- --
--   Control/Compilation/Sequence.hs
--   
-- -- A generic compilation monad for quickly assembling simple compilers -- for target languages that are primarily sequences of instructions -- (possibly with nesting, e.g., loop constructs or procedures). module Control.Compilation.Sequence -- | State extension class definition, and combinators for compiling into a -- sequence (possibly with nested blocks) of instructions. class StateExtension a => Sequence a b where nest xs = do { s :: a <- get; xss :: [[b]] <- return $ project s; set $ inject (xs : xss) s } unnest = do { s :: a <- get; xs :: [[b]] <- return $ project s; set $ inject (tail $ xs) s; return $ head $ project s } depth = do { s <- get; xss :: [[b]] <- return $ project s; return $ toInteger $ length xss } project :: Sequence a b => a -> [[b]] inject :: Sequence a b => [[b]] -> a -> a nest :: Sequence a b => [b] -> Compilation a () unnest :: Sequence a b => Compilation a [b] depth :: Sequence a b => Compilation a Integer -- | Compilation Monad and combinators for quickly assembling simple -- compilers. -- --
--   Control/Compilation/Tree.hs
--   
-- -- A generic compilation monad for quickly assembling simple compilers -- for target languages that are primarily expression trees. module Control.Compilation.Tree