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
31import Data.List (intercalate)
32import Control.Monad (when, forM)
33import Control.Monad.State.Lazy
34import Control.Applicative ((<$>))
35import qualified Data.Map as M
38-- Compile a collection of modules
40-- The compilation pipeline proceeds as follows:
42-- * Sort the modules based on module dependencies, checking for cyclic dependencies.
44-- * Perform a set of desugaring passes.
46-- * Type check, and elaborate values to include type annotations and type class dictionaries.
48-- * Regroup values to take into account new value dependencies introduced by elaboration
50-- * Generate Javascript, and perform optimization passes.
52-- * Pretty-print the generated Javascript
54compile :: Options -> [Module] -> Either String (String, String, Environment)
56 sorted <- sortModules ms
57 desugared <- desugar sorted
58 (elaborated, env) <- runCheck $ forM desugared $ \(Module moduleName decls) -> do
59 modify (\s -> s { checkCurrentModule = Just (ModuleName moduleName) })
60 Module moduleName <$> typeCheckAll (ModuleName moduleName) decls
61 regrouped <- createBindingGroupsModule . collapseBindingGroupsModule $ elaborated
62 let js = concatMap (flip (moduleToJs opts) env) $ regrouped
63 let exts = intercalate "\n" . map (flip moduleToPs env) $ regrouped
65 _ | optionsRunMain opts -> do
66 when ((ModuleName (ProperName "Main"), Ident "main") `M.notMember` (names env)) $
67 Left "Main.main is undefined"
68 return $ js ++ [JSApp (JSAccessor "main" (JSVar "Main")) []]
69 | otherwise -> return js
70 return (prettyPrintJS [(wrapExportsContainer js')], exts, env)
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