sslang-0.1.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Common.Compiler

Description

Data types and helpers used to compose the compiler pipeline.

Synopsis

Documentation

data ErrorMsg Source #

Type for error messages.

Instances

Instances details
Eq ErrorMsg Source # 
Instance details

Defined in Common.Compiler

Show ErrorMsg Source # 
Instance details

Defined in Common.Compiler

IsString ErrorMsg Source # 
Instance details

Defined in Common.Compiler

Semigroup ErrorMsg Source # 
Instance details

Defined in Common.Compiler

Monoid ErrorMsg Source # 
Instance details

Defined in Common.Compiler

data Error Source #

Types of compiler errors that can be thrown during compilation.

Constructors

Dump String

Halt compiler to dump output (not an error)

UnexpectedError ErrorMsg

Internal error; should be unreachable

UnimplementedError ErrorMsg

"It's a research artifact"

TypeError ErrorMsg

Round peg in square hole

ScopeError ErrorMsg

Identifier is out of scope

NameError ErrorMsg

Invalid naming convention at binding

PatternError ErrorMsg

Malformed pattern

LexError ErrorMsg

Error encountered by scanner

ParseError ErrorMsg

Error encountered by parser

Instances

Instances details
Eq Error Source # 
Instance details

Defined in Common.Compiler

Methods

(==) :: Error -> Error -> Bool #

(/=) :: Error -> Error -> Bool #

Show Error Source # 
Instance details

Defined in Common.Compiler

Methods

showsPrec :: Int -> Error -> ShowS #

show :: Error -> String #

showList :: [Error] -> ShowS #

MonadError Error Pass Source # 
Instance details

Defined in Common.Compiler

Methods

throwError :: Error -> Pass a #

catchError :: Pass a -> (Error -> Pass a) -> Pass a #

MonadError Error AnomalyFn Source # 
Instance details

Defined in IR.Pattern.Anomaly

MonadError Error GenFn Source # 
Instance details

Defined in Codegen.Codegen

Methods

throwError :: Error -> GenFn a #

catchError :: GenFn a -> (Error -> GenFn a) -> GenFn a #

data Warning Source #

Types of compiler warnings that can be logged during compilation.

Constructors

TypeWarning ErrorMsg

Warning about type

NameWarning ErrorMsg

Warning related to identifier names

PatternWarning ErrorMsg

Warning related to patterns

Instances

Instances details
Eq Warning Source # 
Instance details

Defined in Common.Compiler

Methods

(==) :: Warning -> Warning -> Bool #

(/=) :: Warning -> Warning -> Bool #

Show Warning Source # 
Instance details

Defined in Common.Compiler

MonadWriter [Warning] Pass Source # 
Instance details

Defined in Common.Compiler

Methods

writer :: (a, [Warning]) -> Pass a #

tell :: [Warning] -> Pass () #

listen :: Pass a -> Pass (a, [Warning]) #

pass :: Pass (a, [Warning] -> [Warning]) -> Pass a #

MonadWriter [Warning] AnomalyFn Source # 
Instance details

Defined in IR.Pattern.Anomaly

Methods

writer :: (a, [Warning]) -> AnomalyFn a #

tell :: [Warning] -> AnomalyFn () #

listen :: AnomalyFn a -> AnomalyFn (a, [Warning]) #

pass :: AnomalyFn (a, [Warning] -> [Warning]) -> AnomalyFn a #

MonadWriter [Warning] GenFn Source # 
Instance details

Defined in Codegen.Codegen

Methods

writer :: (a, [Warning]) -> GenFn a #

tell :: [Warning] -> GenFn () #

listen :: GenFn a -> GenFn (a, [Warning]) #

pass :: GenFn (a, [Warning] -> [Warning]) -> GenFn a #

newtype Pass a Source #

The compiler pipeline monad; supports throwing errors, logging, etc.

Constructors

Pass (PassMonad a) 

Instances

Instances details
Monad Pass Source # 
Instance details

Defined in Common.Compiler

Methods

(>>=) :: Pass a -> (a -> Pass b) -> Pass b #

(>>) :: Pass a -> Pass b -> Pass b #

return :: a -> Pass a #

Functor Pass Source # 
Instance details

Defined in Common.Compiler

Methods

fmap :: (a -> b) -> Pass a -> Pass b #

(<$) :: a -> Pass b -> Pass a #

MonadFail Pass Source # 
Instance details

Defined in Common.Compiler

Methods

fail :: String -> Pass a #

Applicative Pass Source # 
Instance details

Defined in Common.Compiler

Methods

pure :: a -> Pass a #

(<*>) :: Pass (a -> b) -> Pass a -> Pass b #

liftA2 :: (a -> b -> c) -> Pass a -> Pass b -> Pass c #

(*>) :: Pass a -> Pass b -> Pass b #

(<*) :: Pass a -> Pass b -> Pass a #

MonadError Error Pass Source # 
Instance details

Defined in Common.Compiler

Methods

throwError :: Error -> Pass a #

catchError :: Pass a -> (Error -> Pass a) -> Pass a #

MonadWriter [Warning] Pass Source # 
Instance details

Defined in Common.Compiler

Methods

writer :: (a, [Warning]) -> Pass a #

tell :: [Warning] -> Pass () #

listen :: Pass a -> Pass (a, [Warning]) #

pass :: Pass (a, [Warning] -> [Warning]) -> Pass a #

class Monad m => MonadError e (m :: Type -> Type) | m -> e where #

The strategy of combining computations that can throw exceptions by bypassing bound functions from the point an exception is thrown to the point that it is handled.

Is parameterized over the type of error information and the monad type constructor. It is common to use Either String as the monad type constructor for an error monad in which error descriptions take the form of strings. In that case and many other common cases the resulting monad is already defined as an instance of the MonadError class. You can also define your own error type and/or use a monad type constructor other than Either String or Either IOError. In these cases you will have to explicitly define instances of the MonadError class. (If you are using the deprecated Control.Monad.Error or Control.Monad.Trans.Error, you may also have to define an Error instance.)

Methods

throwError :: e -> m a #

Is used within a monadic computation to begin exception processing.

catchError :: m a -> (e -> m a) -> m a #

A handler function to handle previous errors and return to normal execution. A common idiom is:

do { action1; action2; action3 } `catchError` handler

where the action functions can call throwError. Note that handler and the do-block must have the same return type.

Instances

Instances details
MonadError () Maybe

Since: mtl-2.2.2

Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: () -> Maybe a #

catchError :: Maybe a -> (() -> Maybe a) -> Maybe a #

MonadError IOException IO 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: IOException -> IO a #

catchError :: IO a -> (IOException -> IO a) -> IO a #

MonadError Error Pass Source # 
Instance details

Defined in Common.Compiler

Methods

throwError :: Error -> Pass a #

catchError :: Pass a -> (Error -> Pass a) -> Pass a #

MonadError Error AnomalyFn Source # 
Instance details

Defined in IR.Pattern.Anomaly

MonadError Error GenFn Source # 
Instance details

Defined in Codegen.Codegen

Methods

throwError :: Error -> GenFn a #

catchError :: GenFn a -> (Error -> GenFn a) -> GenFn a #

MonadError e m => MonadError e (MaybeT m) 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> MaybeT m a #

catchError :: MaybeT m a -> (e -> MaybeT m a) -> MaybeT m a #

MonadError e m => MonadError e (ListT m) 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> ListT m a #

catchError :: ListT m a -> (e -> ListT m a) -> ListT m a #

MonadError e (Either e) 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> Either e a #

catchError :: Either e a -> (e -> Either e a) -> Either e a #

(Monoid w, MonadError e m) => MonadError e (WriterT w m) 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> WriterT w m a #

catchError :: WriterT w m a -> (e -> WriterT w m a) -> WriterT w m a #

Monad m => MonadError e (ExceptT e m)

Since: mtl-2.2

Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> ExceptT e m a #

catchError :: ExceptT e m a -> (e -> ExceptT e m a) -> ExceptT e m a #

(Monoid w, MonadError e m) => MonadError e (WriterT w m) 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> WriterT w m a #

catchError :: WriterT w m a -> (e -> WriterT w m a) -> WriterT w m a #

MonadError e m => MonadError e (StateT s m) 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> StateT s m a #

catchError :: StateT s m a -> (e -> StateT s m a) -> StateT s m a #

MonadError e m => MonadError e (StateT s m) 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> StateT s m a #

catchError :: StateT s m a -> (e -> StateT s m a) -> StateT s m a #

MonadError e m => MonadError e (ReaderT r m) 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> ReaderT r m a #

catchError :: ReaderT r m a -> (e -> ReaderT r m a) -> ReaderT r m a #

MonadError e m => MonadError e (IdentityT m) 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> IdentityT m a #

catchError :: IdentityT m a -> (e -> IdentityT m a) -> IdentityT m a #

(Monad m, Error e) => MonadError e (ErrorT e m) 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> ErrorT e m a #

catchError :: ErrorT e m a -> (e -> ErrorT e m a) -> ErrorT e m a #

(Monoid w, MonadError e m) => MonadError e (RWST r w s m) 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> RWST r w s m a #

catchError :: RWST r w s m a -> (e -> RWST r w s m a) -> RWST r w s m a #

(Monoid w, MonadError e m) => MonadError e (RWST r w s m) 
Instance details

Defined in Control.Monad.Error.Class

Methods

throwError :: e -> RWST r w s m a #

catchError :: RWST r w s m a -> (e -> RWST r w s m a) -> RWST r w s m a #

runPass :: Pass a -> Either Error (a, [Warning]) Source #

Invoke a compiler Pass.

dump :: Pretty a => a -> Pass x Source #

Dump pretty-printable output from within a compiler pass.

unexpected :: MonadError Error m => String -> m a Source #

Report unexpected compiler error and halt pipeline.

warn :: MonadWriter [Warning] m => Warning -> m () Source #

Log a compiler warning.

todo :: MonadError Error m => String -> m a Source #

Report unexpected compiler error and halt pipeline.

passIO :: Pass a -> IO (a, [Warning]) Source #

Execute compiler pass in I/O monad, exiting upon exception.

liftEither :: MonadError e m => Either e a -> m a #

Lifts an Either e into any MonadError e.

do { val <- liftEither =<< action1; action2 }

where action1 returns an Either to represent errors.

Since: mtl-2.2.2

typeError :: MonadError Error m => String -> m a Source #

Throw a type error with some String error message.