1-----------------------------------------------------------------------------
3-- Module : Language.PureScript
4-- Copyright : (c) Phil Freeman 2013
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
12-- The main compiler module
14-----------------------------------------------------------------------------
16module Language.PureScript (module P, compile) where
18import Language.PureScript.Values as P
19import Language.PureScript.Types as P
20import Language.PureScript.Kinds as P
21import Language.PureScript.Declarations as P
22import Language.PureScript.Names as P
23import Language.PureScript.Parser as P
24import Language.PureScript.CodeGen as P
25import Language.PureScript.CodeGen.Common as P
26import Language.PureScript.TypeChecker as P
27import Language.PureScript.Pretty as P
28import Language.PureScript.Sugar as P
29import Language.PureScript.Options as P
30import Language.PureScript.ModuleDependencies as P
31import Language.PureScript.DeadCodeElimination as P
33import Data.List (intercalate)
34import Data.Maybe (mapMaybe, fromMaybe)
35import Control.Monad (when, forM)
36import Control.Monad.State.Lazy
37import Control.Applicative ((<$>), (<|>))
38import qualified Data.Map as M
41-- Compile a collection of modules
43-- The compilation pipeline proceeds as follows:
45-- * Sort the modules based on module dependencies, checking for cyclic dependencies.
47-- * Perform a set of desugaring passes.
49-- * Type check, and elaborate values to include type annotations and type class dictionaries.
51-- * Regroup values to take into account new value dependencies introduced by elaboration.
53-- * Eliminate dead code.
55-- * Generate Javascript, and perform optimization passes.
57-- * Pretty-print the generated Javascript
59compile :: Options -> [Module] -> Either String (String, String, Environment)
61 sorted <- sortModules ms
62 desugared <- desugar sorted
63 (elaborated, env) <- runCheck $ forM desugared $ \(Module moduleName decls) -> do
64 modify (\s -> s { checkCurrentModule = Just moduleName })
65 Module moduleName <$> typeCheckAll mainModuleIdent moduleName decls
66 regrouped <- createBindingGroupsModule . collapseBindingGroupsModule $ elaborated
67 let entryPoints = moduleNameFromString `map` optionsModules opts
68 let elim = if null entryPoints then regrouped else eliminateDeadCode env entryPoints regrouped
69 let js = mapMaybe (flip (moduleToJs opts) env) elim
70 let exts = intercalate "\n" . map (flip moduleToPs env) $ elim
71 js' <- case mainModuleIdent of
73 when ((mmi, Ident "main") `M.notMember` (names env)) $
74 Left $ (show mmi) ++ ".main is undefined"
75 return $ js ++ [JSApp (JSAccessor "main" (JSAccessor (moduleNameToJs mmi) (JSVar "_ps"))) []]
77 return (prettyPrintJS [(wrapExportsContainer opts js')], exts, env)
79 mainModuleIdent = moduleNameFromString <$> optionsMain opts
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list