git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #281 from garyb/master
9ee7d74Phil Freeman
examples/passing/Arrays.purs+1−1
@@ -31,4 +31,4 @@ main = do
31 let y = sort x
31 let y = sort x
32 if x == [3,2,1]
32 if x == [3,2,1]
33 then Debug.Trace.trace "Done"
33 then Debug.Trace.trace "Done"
34− else Control.Monad.Error.throwError "Not done"
34+ else Control.Monad.Eff.Error.throwError "Not done"
examples/passing/BindersInFunctions.purs+1−1
@@ -9,4 +9,4 @@ main =
9 let ts = tails [[1, 2, 3], [4, 5], [6]] in
9 let ts = tails [[1, 2, 3], [4, 5], [6]] in
10 if ts == [[2, 3], [5], []]
10 if ts == [[2, 3], [5], []]
11 then Debug.Trace.trace "Done"
11 then Debug.Trace.trace "Done"
12− else Control.Monad.Error.throwError "Incorrect result from 'tails'."
12+ else Control.Monad.Eff.Error.throwError "Incorrect result from 'tails'."
examples/passing/Eff.purs+1−1
@@ -3,7 +3,7 @@ module TestEff where
3import Prelude
3import Prelude
4import Control.Monad.Eff
4import Control.Monad.Eff
5import Control.Monad.ST
5import Control.Monad.ST
6−import Control.Monad.Error
6+import Control.Monad.Eff.Error
7import Debug.Trace
7import Debug.Trace
8
8
9test1 = catchError (\s -> return 0) $ do
9test1 = catchError (\s -> return 0) $ do
examples/passing/EmptyDataDecls.purs+1−1
@@ -17,4 +17,4 @@ cons x (Array xs) = Array $ x : xs
17main = let (Array xs) = cons 1 $ cons 2 $ cons 3 nil
17main = let (Array xs) = cons 1 $ cons 2 $ cons 3 nil
18 in if xs == [1, 2, 3]
18 in if xs == [1, 2, 3]
19 then Debug.Trace.trace "Done"
19 then Debug.Trace.trace "Done"
20− else Control.Monad.Error.throwError "Failed"
20+ else Control.Monad.Eff.Error.throwError "Failed"
examples/passing/FunctionScope.purs+1−1
@@ -14,4 +14,4 @@ module Main where
14 let value = mkValue 1
14 let value = mkValue 1
15 if value == 1
15 if value == 1
16 then Debug.Trace.trace "Done"
16 then Debug.Trace.trace "Done"
17− else Control.Monad.Error.throwError "Not done"
17+ else Control.Monad.Eff.Error.throwError "Not done"
examples/passing/Functions2.purs+1−1
@@ -14,4 +14,4 @@ module Main where
14 let value = test "Done" {}
14 let value = test "Done" {}
15 if value == "Done"
15 if value == "Done"
16 then Debug.Trace.trace "Done"
16 then Debug.Trace.trace "Done"
17− else Control.Monad.Error.throwError "Not done"
17+ else Control.Monad.Eff.Error.throwError "Not done"
prelude/prelude.purs+1−1
@@ -1031,7 +1031,7 @@ module Random where
1031 \ return Math.random();\
1031 \ return Math.random();\
1032 \}" :: forall e. Eff (random :: Random | e) Number
1032 \}" :: forall e. Eff (random :: Random | e) Number
1033
1033
1034−module Control.Monad.Error where
1034+module Control.Monad.Eff.Error where
1035
1035
1036 import Control.Monad.Eff
1036 import Control.Monad.Eff
1037
1037
src/Language/PureScript/CodeGen/JS.hs+6−3
@@ -52,11 +52,14 @@ moduleToJs opts (Module name decls (Just exps)) env =
52 case jsDecls of
52 case jsDecls of
53 [] -> Nothing
53 [] -> Nothing
54 _ -> Just $ JSAssignment (JSAccessor (moduleNameToJs name) (JSVar C._ps)) $
54 _ -> Just $ JSAssignment (JSAccessor (moduleNameToJs name) (JSVar C._ps)) $
55− JSApp (JSFunction Nothing ["module"] (JSBlock $ jsDecls ++ [JSReturn $ JSVar "module"]))
55+ JSApp (JSFunction Nothing [] (JSBlock $
56− [JSBinary Or (JSAccessor (moduleNameToJs name) (JSVar C._ps)) (JSObjectLiteral [])]
56+ JSVariableIntroduction "module" (Just $ JSObjectLiteral []) :
57+ jsDecls ++
58+ jsExports ++
59+ [JSReturn $ JSVar "module"])) []
57 where
60 where
58 jsDecls = (concat $ mapMaybe (\decl -> fmap (map $ optimize opts) $ declToJs opts name decl env) decls)
61 jsDecls = (concat $ mapMaybe (\decl -> fmap (map $ optimize opts) $ declToJs opts name decl env) decls)
59− ++ concatMap exportToJs exps
62+ jsExports = concatMap exportToJs exps
60moduleToJs _ _ _ = error "Exports should have been elaborated in name desugaring"
63moduleToJs _ _ _ = error "Exports should have been elaborated in name desugaring"
61
64
62-- |
65-- |
src/Language/PureScript/Sugar/Names.hs+8−3
@@ -89,8 +89,11 @@ updateExportedModule env mn update = do
89-- |
89-- |
90-- Adds an empty module to an ExportEnvironment.
90-- Adds an empty module to an ExportEnvironment.
91--
91--
92−addEmptyModule :: ExportEnvironment -> ModuleName -> ExportEnvironment
92+addEmptyModule :: ExportEnvironment -> ModuleName -> Either String ExportEnvironment
93−addEmptyModule env name = M.insert name (Exports [] [] []) env
93+addEmptyModule env name =
94+ if name `M.member` env
95+ then throwError $ "Module '" ++ show name ++ "' has been defined more than once"
96+ else return $ M.insert name (Exports [] [] []) env
94
97
95-- |
98-- |
96-- Adds a type belonging to a module to the export environment.
99-- Adds a type belonging to a module to the export environment.
@@ -255,7 +258,9 @@ findExports = foldM addModule $ M.singleton (ModuleName [ProperName "Prim"]) pri
255
258
256 -- Add all of the exported declarations from a module to the global export environment
259 -- Add all of the exported declarations from a module to the global export environment
257 addModule :: ExportEnvironment -> Module -> Either String ExportEnvironment
260 addModule :: ExportEnvironment -> Module -> Either String ExportEnvironment
261+ addModule env m@(Module mn ds _) = do
262+ env' <- addEmptyModule env mn
258− addModule env m@(Module mn ds _) = rethrowForModule m $ foldM (addDecl mn) (addEmptyModule env mn) ds
263+ rethrowForModule m $ foldM (addDecl mn) env' ds
259
264
260 -- Add a declaration from a module to the global export environment
265 -- Add a declaration from a module to the global export environment
261 addDecl :: ModuleName -> ExportEnvironment -> Declaration -> Either String ExportEnvironment
266 addDecl :: ModuleName -> ExportEnvironment -> Declaration -> Either String ExportEnvironment