git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add --run-main option
commit72f98f12dabafd271a62893907a37523e07568cb authorPhil Freeman <paf31@cantab.net> dateSat 11 Jan 2014, 13:22 (13 years ago) parentb2763ce
5 files changed+29−7
libraries/jquery/tests/jquery.purs+2−2 libraries/prelude/tests/Eff.purs+10 src/Language/PureScript.hs+10−3 src/Language/PureScript/Options.hs+2−1 src/Main.hs+5−1
libraries/jquery/tests/jquery.purs+2−2
@@ -1,9 +1,9 @@
1−module Tests where
1+module Main where
22
33import Eff
44import JQuery
55
6−test = eff do
6+main = eff do
77 b <- body
88 div <- create "<div>"
99 { color: "red" } `css` div
libraries/prelude/tests/Eff.purs+10
@@ -29,3 +29,13 @@ test4 = eff do
2929test5 = eff do
3030 trace "Hello World!"
3131 test5
32+
33+test6 s = eff do
34+ trace s
35+ test6 (s ++ " test")
36+
37+module Main where
38+
39+import Tests
40+
41+main = test6 ""
src/Language/PureScript.hs+10−3
@@ -27,12 +27,19 @@ import Language.PureScript.Sugar as P
2727import Language.PureScript.Options as P
2828
2929import Data.List (intercalate)
30−import Control.Monad (forM_)
30+import Control.Monad (when, forM_)
31+import qualified Data.Map as M
3132
3233compile :: Options -> [Module] -> Either String (String, String, Environment)
3334compile opts ms = do
3435 desugared <- desugar ms
3536 (_, env) <- runCheck $ forM_ desugared $ \(Module moduleName decls) -> typeCheckAll (ModuleName moduleName) decls
36− let js = prettyPrintJS . concatMap (flip (moduleToJs opts) env) $ desugared
37+ let js = concatMap (flip (moduleToJs opts) env) $ desugared
3738 let exts = intercalate "\n" . map (flip moduleToPs env) $ desugared
38− return (js, exts, env)
39+ js' <- case () of
40+ _ | optionsRunMain opts -> do
41+ when ((ModuleName (ProperName "Main"), Ident "main") `M.notMember` (names env)) $
42+ Left "Main.main is undefined"
43+ return $ js ++ [JSApp (JSAccessor "main" (JSVar (Ident "Main"))) []]
44+ | otherwise -> return js
45+ return (prettyPrintJS js', exts, env)
src/Language/PureScript/Options.hs+2−1
@@ -18,7 +18,8 @@ data Options = Options
1818 { optionsTco :: Bool
1919 , optionsPerformRuntimeTypeChecks :: Bool
2020 , optionsMagicDo :: Bool
21+ , optionsRunMain :: Bool
2122 } deriving Show
2223
2324defaultOptions :: Options
24−defaultOptions = Options False False False
25+defaultOptions = Options False False False False
src/Main.hs+5−1
@@ -86,8 +86,12 @@ magicDo :: Term Bool
8686magicDo = value $ flag $ (optInfo [ "magic-do" ])
8787 { optDoc = "Overload the do keyword to generate efficient code specifically for the Eff monad." }
8888
89+runMain :: Term Bool
90+runMain = value $ flag $ (optInfo [ "run-main" ])
91+ { optDoc = "Generate code to run the main method in the Main module." }
92+
8993options :: Term P.Options
90−options = P.Options <$> tco <*> performRuntimeTypeChecks <*> magicDo
94+options = P.Options <$> tco <*> performRuntimeTypeChecks <*> magicDo <*> runMain
9195
9296stdInOrInputFiles :: FilePath -> Term (Maybe [FilePath])
9397stdInOrInputFiles prelude = combine <$> useStdIn <*> (not <$> noPrelude) <*> inputFiles