git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix #1246
commit3ff09c119804500164618a1a1b353d97844782d8 authorPhil Freeman <paf31@cantab.net> dateMon 10 Aug 2015, 21:17 (11 years ago) parentf0ed783
5 files changed+16−17
psc/Main.hs+1−1 psci/Types.hs+2−2 src/Language/PureScript/Make.hs+5−6 src/Language/PureScript/Parser/JS.hs+3−3 tests/Main.hs+5−5
psc/Main.hs+1−1
@@ -84,7 +84,7 @@ readInput InputOptions{..} = forM ioInputFiles $ \inFile -> (Right inFile, ) <$>
8484parseInputs :: (Functor m, Applicative m, MonadError P.MultipleErrors m, MonadWriter P.MultipleErrors m)
8585 => [(Either P.RebuildPolicy FilePath, String)]
8686 -> [(FilePath, P.ForeignJS)]
87− -> m ([(Either P.RebuildPolicy FilePath, P.Module)], M.Map P.ModuleName (FilePath, P.ForeignJS))
87+ -> m ([(Either P.RebuildPolicy FilePath, P.Module)], M.Map P.ModuleName FilePath)
8888parseInputs modules foreigns =
8989 (,) <$> P.parseModulesFromFiles (either (const "") id) modules
9090 <*> P.parseForeignModulesFromFiles foreigns
psci/Types.hs+2−2
@@ -35,7 +35,7 @@ data PSCiState = PSCiState
3535 { psciImportedFilenames :: [FilePath]
3636 , psciImportedModules :: [ImportedModule]
3737 , psciLoadedModules :: [(Either P.RebuildPolicy FilePath, P.Module)]
38− , psciForeignFiles :: M.Map P.ModuleName (FilePath, P.ForeignJS)
38+ , psciForeignFiles :: M.Map P.ModuleName FilePath
3939 , psciLetBindings :: [P.Declaration]
4040 , psciNodeFlags :: [String]
4141 }
@@ -91,7 +91,7 @@ updateLets ds st = st { psciLetBindings = psciLetBindings st ++ ds }
9191-- |
9292-- Updates the state to have more let bindings.
9393--
94−updateForeignFiles :: M.Map P.ModuleName (FilePath, P.ForeignJS) -> PSCiState -> PSCiState
94+updateForeignFiles :: M.Map P.ModuleName FilePath -> PSCiState -> PSCiState
9595updateForeignFiles fs st = st { psciForeignFiles = psciForeignFiles st `M.union` fs }
9696
9797-- |
src/Language/PureScript/Make.hs+5−6
@@ -59,7 +59,6 @@ import System.Directory
5959import System.FilePath ((</>), takeDirectory)
6060import System.IO.Error (tryIOError)
6161
62−
6362import Language.PureScript.AST
6463import Language.PureScript.CodeGen.Externs (moduleToPs)
6564import Language.PureScript.Environment
@@ -245,8 +244,8 @@ traverseEither f (Right y) = Right <$> f y
245244-- A set of make actions that read and write modules from the given directory.
246245--
247246buildMakeActions :: FilePath -- ^ the output directory
248− -> M.Map ModuleName (Either RebuildPolicy String) -- ^ a map between module names and paths to the file containing the PureScript module
249− -> M.Map ModuleName (FilePath, ForeignJS) -- ^ a map between module name and the file containing the foreign javascript for the module
247+ -> M.Map ModuleName (Either RebuildPolicy FilePath) -- ^ a map between module names and paths to the file containing the PureScript module
248+ -> M.Map ModuleName FilePath -- ^ a map between module name and the file containing the foreign javascript for the module
250249 -> Bool -- ^ Generate a prefix comment?
251250 -> MakeActions Make
252251buildMakeActions outputDir filePathMap foreigns usePrefix =
@@ -257,7 +256,7 @@ buildMakeActions outputDir filePathMap foreigns usePrefix =
257256 getInputTimestamp mn = do
258257 let path = fromMaybe (error "Module has no filename in 'make'") $ M.lookup mn filePathMap
259258 e1 <- traverseEither getTimestamp path
260− fPath <- maybe (return Nothing) (getTimestamp . fst) $ M.lookup mn foreigns
259+ fPath <- maybe (return Nothing) getTimestamp $ M.lookup mn foreigns
261260 return $ fmap (max fPath) e1
262261
263262 getOutputTimestamp :: ModuleName -> Make (Maybe UTCTime)
@@ -276,7 +275,7 @@ buildMakeActions outputDir filePathMap foreigns usePrefix =
276275 codegen m _ exts = do
277276 let mn = CF.moduleName m
278277 foreignInclude <- case mn `M.lookup` foreigns of
279− Just (path, _)
278+ Just path
280279 | not $ requiresForeign m -> do
281280 tell $ errorMessage $ UnnecessaryFFIModule mn path
282281 return Nothing
@@ -292,7 +291,7 @@ buildMakeActions outputDir filePathMap foreigns usePrefix =
292291 js = unlines $ map ("// " ++) prefix ++ [pjs]
293292 lift $ do
294293 writeTextFile jsFile js
295− maybe (return ()) (writeTextFile foreignFile . snd) $ mn `M.lookup` foreigns
294+ for_ (mn `M.lookup` foreigns) (readTextFile >=> writeTextFile foreignFile)
296295 writeTextFile externsFile exts
297296
298297 requiresForeign :: CF.Module a -> Bool
src/Language/PureScript/Parser/JS.hs+3−3
@@ -37,17 +37,17 @@ type ForeignJS = String
3737
3838parseForeignModulesFromFiles :: (Functor m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
3939 => [(FilePath, ForeignJS)]
40− -> m (M.Map ModuleName (FilePath, ForeignJS))
40+ -> m (M.Map ModuleName FilePath)
4141parseForeignModulesFromFiles files = do
4242 foreigns <- parU files $ \(path, file) ->
4343 case findModuleName (lines file) of
44− Just name -> return (name, (path, file))
44+ Just name -> return (name, path)
4545 Nothing -> throwError (errorMessage $ ErrorParsingFFIModule path)
4646 let grouped = groupBy ((==) `on` fst) $ sortBy (compare `on` fst) foreigns
4747 forM_ grouped $ \grp ->
4848 when (length grp > 1) $ do
4949 let mn = fst (head grp)
50− paths = map (fst . snd) grp
50+ paths = map snd grp
5151 tell $ errorMessage $ MultipleFFIModules mn paths
5252 return $ M.fromList foreigns
5353
tests/Main.hs+5−5
@@ -69,7 +69,7 @@ import Text.Parsec (ParseError)
6969modulesDir :: FilePath
7070modulesDir = ".test_modules" </> "node_modules"
7171
72−makeActions :: M.Map P.ModuleName (FilePath, P.ForeignJS) -> P.MakeActions P.Make
72+makeActions :: M.Map P.ModuleName FilePath -> P.MakeActions P.Make
7373makeActions foreigns = (P.buildMakeActions modulesDir (error "makeActions: input file map was read.") foreigns False)
7474 { P.getInputTimestamp = getInputTimestamp
7575 , P.getOutputTimestamp = getOutputTimestamp
@@ -98,14 +98,14 @@ type TestM = WriterT [(FilePath, String)] IO
9898runTest :: P.Make a -> IO (Either P.MultipleErrors a)
9999runTest = fmap (fmap fst) . P.runMake P.defaultOptions
100100
101−compile :: [FilePath] -> M.Map P.ModuleName (FilePath, P.ForeignJS) -> IO (Either P.MultipleErrors P.Environment)
101+compile :: [FilePath] -> M.Map P.ModuleName FilePath -> IO (Either P.MultipleErrors P.Environment)
102102compile inputFiles foreigns = runTest $ do
103103 fs <- liftIO $ readInput inputFiles
104104 ms <- P.parseModulesFromFiles id fs
105105 P.make (makeActions foreigns) (map snd ms)
106106
107107assert :: [FilePath] ->
108− M.Map P.ModuleName (FilePath, P.ForeignJS) ->
108+ M.Map P.ModuleName FilePath ->
109109 (Either P.MultipleErrors P.Environment -> IO (Maybe String)) ->
110110 TestM ()
111111assert inputFiles foreigns f = do
@@ -115,7 +115,7 @@ assert inputFiles foreigns f = do
115115 Just err -> tell [(last inputFiles, err)]
116116 Nothing -> return ()
117117
118−assertCompiles :: [FilePath] -> M.Map P.ModuleName (FilePath, P.ForeignJS) -> TestM ()
118+assertCompiles :: [FilePath] -> M.Map P.ModuleName FilePath -> TestM ()
119119assertCompiles inputFiles foreigns = do
120120 liftIO . putStrLn $ "Assert " ++ last inputFiles ++ " compiles successfully"
121121 assert inputFiles foreigns $ \e ->
@@ -131,7 +131,7 @@ assertCompiles inputFiles foreigns = do
131131 Just (ExitFailure _, _, err) -> return $ Just err
132132 Nothing -> return $ Just "Couldn't find node.js executable"
133133
134−assertDoesNotCompile :: [FilePath] -> M.Map P.ModuleName (FilePath, P.ForeignJS) -> TestM ()
134+assertDoesNotCompile :: [FilePath] -> M.Map P.ModuleName FilePath -> TestM ()
135135assertDoesNotCompile inputFiles foreigns = do
136136 let testFile = last inputFiles
137137 liftIO . putStrLn $ "Assert " ++ testFile ++ " does not compile"