git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add --codegen option to support separate compilation
18ae8f5Phil Freeman
psc/Main.hs+5−1
@@ -107,8 +107,12 @@ dceModules :: Term [String]
107dceModules = value $ optAll [] $ (optInfo [ "m", "module" ])
107dceModules = value $ optAll [] $ (optInfo [ "m", "module" ])
108 { optDoc = "Enables dead code elimination, all code which is not a transitive dependency of a specified module will be removed. This argument can be used multiple times." }
108 { optDoc = "Enables dead code elimination, all code which is not a transitive dependency of a specified module will be removed. This argument can be used multiple times." }
109
109
110+codeGenModules :: Term [String]
111+codeGenModules = value $ optAll [] $ (optInfo [ "codegen" ])
112+ { optDoc = "A list of modules for which Javascript and externs should be generated. This argument can be used multiple times." }
113+
110options :: Term P.Options
114options :: Term P.Options
111−options = P.Options <$> tco <*> magicDo <*> runMain <*> noOpts <*> browserNamespace <*> dceModules
115+options = P.Options <$> tco <*> magicDo <*> runMain <*> noOpts <*> browserNamespace <*> dceModules <*> codeGenModules
112
116
113stdInOrInputFiles :: FilePath -> Term (Maybe [FilePath])
117stdInOrInputFiles :: FilePath -> Term (Maybe [FilePath])
114stdInOrInputFiles prelude = combine <$> useStdIn <*> (not <$> noPrelude) <*> inputFiles
118stdInOrInputFiles prelude = combine <$> useStdIn <*> (not <$> noPrelude) <*> inputFiles
psci/Main.hs+1−1
@@ -195,7 +195,7 @@ completion = completeWord Nothing " \t\n\r" findCompletions
195-- | Compilation options.
195-- | Compilation options.
196--
196--
197options :: P.Options
197options :: P.Options
198−options = P.Options True True (Just "Main") True "PS" []
198+options = P.Options True True (Just "Main") True "PS" [] []
199
199
200-- |
200-- |
201-- Makes a volatile module to execute the current expression.
201-- Makes a volatile module to execute the current expression.
src/Language/PureScript.hs+4−2
@@ -68,8 +68,10 @@ compile opts ms = do
68 regrouped <- createBindingGroupsModule . collapseBindingGroupsModule $ elaborated
68 regrouped <- createBindingGroupsModule . collapseBindingGroupsModule $ elaborated
69 let entryPoints = moduleNameFromString `map` optionsModules opts
69 let entryPoints = moduleNameFromString `map` optionsModules opts
70 let elim = if null entryPoints then regrouped else eliminateDeadCode entryPoints regrouped
70 let elim = if null entryPoints then regrouped else eliminateDeadCode entryPoints regrouped
71+ let codeGenModules = moduleNameFromString `map` optionsCodeGenModules opts
72+ let modulesToCodeGen = if null codeGenModules then elim else filter (\(Module mn _ _) -> mn `elem` codeGenModules) elim
71− let js = mapMaybe (flip (moduleToJs opts) env) elim
73+ let js = mapMaybe (flip (moduleToJs opts) env) modulesToCodeGen
72− let exts = intercalate "\n" . map (`moduleToPs` env) $ elim
74+ let exts = intercalate "\n" . map (`moduleToPs` env) $ modulesToCodeGen
73 js' <- case mainModuleIdent of
75 js' <- case mainModuleIdent of
74 Just mmi -> do
76 Just mmi -> do
75 when ((mmi, Ident C.main) `M.notMember` names env) $
77 when ((mmi, Ident C.main) `M.notMember` names env) $
src/Language/PureScript/Options.hs+5−1
@@ -45,10 +45,14 @@ data Options = Options {
45 -- The modules to keep while enabling dead code elimination
45 -- The modules to keep while enabling dead code elimination
46 --
46 --
47 , optionsModules :: [String]
47 , optionsModules :: [String]
48+ -- |
49+ -- The modules to code gen
50+ --
51+ , optionsCodeGenModules :: [String]
48 } deriving Show
52 } deriving Show
49
53
50-- |
54-- |
51-- Default compiler options
55-- Default compiler options
52--
56--
53defaultOptions :: Options
57defaultOptions :: Options
54−defaultOptions = Options False False Nothing False "PS" []
58+defaultOptions = Options False False Nothing False "PS" [] []