git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add --run-main option
72f98f1Phil Freeman
libraries/jquery/tests/jquery.purs+2−2
@@ -1,9 +1,9 @@
1−module Tests where
1+module Main where
2
2
3import Eff
3import Eff
4import JQuery
4import JQuery
5
5
6−test = eff do
6+main = eff do
7 b <- body
7 b <- body
8 div <- create "<div>"
8 div <- create "<div>"
9 { color: "red" } `css` div
9 { color: "red" } `css` div
libraries/prelude/tests/Eff.purs+10
@@ -29,3 +29,13 @@ test4 = eff do
29test5 = eff do
29test5 = eff do
30 trace "Hello World!"
30 trace "Hello World!"
31 test5
31 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
27import Language.PureScript.Options as P
27import Language.PureScript.Options as P
28
28
29import Data.List (intercalate)
29import Data.List (intercalate)
30−import Control.Monad (forM_)
30+import Control.Monad (when, forM_)
31+import qualified Data.Map as M
31
32
32compile :: Options -> [Module] -> Either String (String, String, Environment)
33compile :: Options -> [Module] -> Either String (String, String, Environment)
33compile opts ms = do
34compile opts ms = do
34 desugared <- desugar ms
35 desugared <- desugar ms
35 (_, env) <- runCheck $ forM_ desugared $ \(Module moduleName decls) -> typeCheckAll (ModuleName moduleName) decls
36 (_, 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
37 let exts = intercalate "\n" . map (flip moduleToPs env) $ desugared
38 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
18 { optionsTco :: Bool
18 { optionsTco :: Bool
19 , optionsPerformRuntimeTypeChecks :: Bool
19 , optionsPerformRuntimeTypeChecks :: Bool
20 , optionsMagicDo :: Bool
20 , optionsMagicDo :: Bool
21+ , optionsRunMain :: Bool
21 } deriving Show
22 } deriving Show
22
23
23defaultOptions :: Options
24defaultOptions :: 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
86magicDo = value $ flag $ (optInfo [ "magic-do" ])
86magicDo = value $ flag $ (optInfo [ "magic-do" ])
87 { optDoc = "Overload the do keyword to generate efficient code specifically for the Eff monad." }
87 { optDoc = "Overload the do keyword to generate efficient code specifically for the Eff monad." }
88
88
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+
89options :: Term P.Options
93options :: Term P.Options
90−options = P.Options <$> tco <*> performRuntimeTypeChecks <*> magicDo
94+options = P.Options <$> tco <*> performRuntimeTypeChecks <*> magicDo <*> runMain
91
95
92stdInOrInputFiles :: FilePath -> Term (Maybe [FilePath])
96stdInOrInputFiles :: FilePath -> Term (Maybe [FilePath])
93stdInOrInputFiles prelude = combine <$> useStdIn <*> (not <$> noPrelude) <*> inputFiles
97stdInOrInputFiles prelude = combine <$> useStdIn <*> (not <$> noPrelude) <*> inputFiles