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.Applicative ((<$>))
34import qualified Data.Map as M
37-- Compile a collection of modules
39-- The compilation pipeline proceeds as follows:
41-- * Sort the modules based on module dependencies, checking for cyclic dependencies.
43-- * Perform a set of desugaring passes.
45-- * Type check, and elaborate values to include type annotations and type class dictionaries.
47-- * Regroup values to take into account new value dependencies introduced by elaboration
49-- * Generate Javascript, and perform optimization passes.
51-- * Pretty-print the generated Javascript
53compile :: Options -> [Module] -> Either String (String, String, Environment)
55 sorted <- sortModules ms
56 desugared <- desugar sorted
57 (elaborated, env) <- runCheck $ forM desugared $ \(Module moduleName decls) -> Module moduleName <$> typeCheckAll (ModuleName moduleName) decls
58 regrouped <- createBindingGroupsModule . collapseBindingGroupsModule $ elaborated
59 let js = concatMap (flip (moduleToJs opts) env) $ regrouped
60 let exts = intercalate "\n" . map (flip moduleToPs env) $ regrouped
62 _ | optionsRunMain opts -> do
63 when ((ModuleName (ProperName "Main"), Ident "main") `M.notMember` (names env)) $
64 Left "Main.main is undefined"
65 return $ js ++ [JSApp (JSAccessor "main" (JSVar (Ident "Main"))) []]
66 | otherwise -> return js
67 return (prettyPrintJS 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