25.10.2015 Views

Write You a Haskell Stephen Diehl

1kEcQTb

1kEcQTb

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

• e PHOAS, the type-erased Core is transformed into <strong>Haskell</strong> expressions by mapping lambda<br />

expressions in our language directly into <strong>Haskell</strong> lambda expressions and then evaluated using the<br />

<strong>Haskell</strong> runtime.<br />

Pass Rep <strong>Haskell</strong> Type<br />

Parsing Source Text.Text<br />

Desugaring Frontend Frontend.Expr<br />

Typechecking Core Core.Expr<br />

Evaluation PHOAS CoreEval.ExprP<br />

For our later Fun language our pipeline builds on top of the Proto<strong>Haskell</strong> but instead of going to an<br />

interpreter it will be compiled into native code through the native code generator (on top of LLVM) and<br />

compiled into a binary executable or evaluated by a just-in-time (JIT) compiler.<br />

Pass Rep <strong>Haskell</strong> Type<br />

Parsing Source Text.Text<br />

Desugaring Frontend Frontend.Expr<br />

Typechecking Core Core.Expr<br />

Transformation STG STG.Expr<br />

Transformation Imp Imp.Expr<br />

Code Generation LLVM LLVM.General.Module<br />

CompilerM<br />

e main driver of the compiler will be a ExceptT + State + IO transformer stack . All other passes and<br />

transformations in the compiler will hang off of this monad, which encapsulates the main compilation<br />

pipeline.<br />

type CompilerMonad =<br />

ExceptT Msg<br />

(StateT CompilerState IO)<br />

data CompilerState = CompilerState<br />

{ _fname :: Maybe FilePath -- ^ File path<br />

, _imports :: [FilePath] -- ^ Loaded modules<br />

, _src :: Maybe L.Text -- ^ File source<br />

, _ast :: Maybe Syn.Module -- ^ Frontend AST<br />

, _tenv :: Env.Env -- ^ Typing environment<br />

, _kenv :: Map.Map Name Kind -- ^ Kind environment<br />

, _cenv :: ClassEnv.ClassEnv -- ^ Typeclass environment<br />

, _cast :: Maybe Core.Module -- ^ Core AST<br />

107

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!