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.TypeChecker as P
26import Language.PureScript.Pretty as P
27import Language.PureScript.Sugar as P
28import Language.PureScript.Options as P
29import Language.PureScript.ModuleDependencies as P
30import Language.PureScript.DeadCodeElimination as P
32import Data.List (intercalate)
33import Data.Maybe (mapMaybe, fromMaybe)
34import Control.Monad (when, forM)
35import Control.Monad.State.Lazy
36import Control.Applicative ((<$>), (<|>))
37import qualified Data.Map as M
40-- Compile a collection of modules
42-- The compilation pipeline proceeds as follows:
44-- * Sort the modules based on module dependencies, checking for cyclic dependencies.
46-- * Perform a set of desugaring passes.
48-- * Type check, and elaborate values to include type annotations and type class dictionaries.
50-- * Regroup values to take into account new value dependencies introduced by elaboration.
52-- * Eliminate dead code.
54-- * Generate Javascript, and perform optimization passes.
56-- * Pretty-print the generated Javascript
58compile :: Options -> [Module] -> Either String (String, String, Environment)
60 sorted <- sortModules ms
61 desugared <- desugar sorted
62 (elaborated, env) <- runCheck $ forM desugared $ \(Module moduleName decls) -> do
63 modify (\s -> s { checkCurrentModule = Just (ModuleName moduleName) })
64 Module moduleName <$> typeCheckAll mainModuleIdent (ModuleName moduleName) decls
65 regrouped <- createBindingGroupsModule . collapseBindingGroupsModule $ elaborated
66 let entryPoints = optionsModules opts
67 let elim = if null entryPoints then regrouped else eliminateDeadCode env entryPoints regrouped
68 let js = mapMaybe (flip (moduleToJs opts) env) elim
69 let exts = intercalate "\n" . map (flip moduleToPs env) $ elim
70 js' <- case optionsMain opts of
71 Just mainModuleName -> do
72 when ((ModuleName (ProperName mainModuleName), Ident "main") `M.notMember` (names env)) $
73 Left $ mainModuleName ++ ".main is undefined"
74 return $ js ++ [JSApp (JSAccessor "main" (JSAccessor mainModuleName (JSVar "_ps"))) []]
76 return (prettyPrintJS [(wrapExportsContainer opts js')], exts, env)
78 mainModuleIdent = ModuleName . ProperName <$> (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