@@ -47,9 +47,9 @@ import qualified Data.Map as M
4747--
4848-- * Type check, and elaborate values to include type annotations and type class dictionaries.
4949--
50−-- * Regroup values to take into account new value dependencies introduced by elaboration
50+-- * Regroup values to take into account new value dependencies introduced by elaboration.
5151--
52−-- * Eliminate dead code
52+-- * Eliminate dead code.
5353--
5454-- * Generate Javascript, and perform optimization passes.
5555--
@@ -63,17 +63,16 @@ compile opts ms = do
6363 modify (\s -> s { checkCurrentModule = Just (ModuleName moduleName) })
6464 Module moduleName <$> typeCheckAll mainModuleIdent (ModuleName moduleName) decls
6565 regrouped <- createBindingGroupsModule . collapseBindingGroupsModule $ elaborated
66− let entryPoint = optionsEntryPoint opts <|> if (optionsRunMain opts) then Just "Main" else Nothing
67− let elim = maybe regrouped (\ep -> eliminateDeadCode env ep regrouped) entryPoint
66+ let entryPoints = optionsModules opts
67+ let elim = if null entryPoints then regrouped else eliminateDeadCode env entryPoints regrouped
6868 let js = mapMaybe (flip (moduleToJs opts) env) elim
6969 let exts = intercalate "\n" . map (flip moduleToPs env) $ elim
70− js' <- case () of
71− _ | optionsRunMain opts -> do
72− when ((mainModuleIdent, Ident "main") `M.notMember` (names env)) $
73− Left $ mainModuleName ++ ".main is undefined"
74− return $ js ++ [JSApp (JSAccessor "main" (JSAccessor mainModuleName (JSVar "_ps"))) []]
75− | otherwise -> return js
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"))) []]
75+ _ -> return js
7676 return (prettyPrintJS [(wrapExportsContainer opts js')], exts, env)
7777 where
78− mainModuleName = fromMaybe "Main" (optionsEntryPoint opts)
79− mainModuleIdent = ModuleName (ProperName mainModuleName)
78+ mainModuleIdent = ModuleName . ProperName <$> (optionsMain opts)