summaryrefslogtreecommitdiff
path: root/src/LambdaCube/Compiler.hs
diff options
context:
space:
mode:
authorCsaba Hruska <csaba.hruska@gmail.com>2016-02-22 13:11:31 +0100
committerCsaba Hruska <csaba.hruska@gmail.com>2016-02-22 14:15:45 +0100
commit23107ec58f3831512da0f46d5dc3457de2d5de66 (patch)
tree3da220376acbe18181260e93a721fe6906096ff7 /src/LambdaCube/Compiler.hs
parent6aaa725942bcb325f377d3cf22a4483f35cb8e5a (diff)
fix: preCompile
Diffstat (limited to 'src/LambdaCube/Compiler.hs')
-rw-r--r--src/LambdaCube/Compiler.hs23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/LambdaCube/Compiler.hs b/src/LambdaCube/Compiler.hs
index 91c65666..fbd2203e 100644
--- a/src/LambdaCube/Compiler.hs
+++ b/src/LambdaCube/Compiler.hs
@@ -119,17 +119,16 @@ moduleNameToFileName n = hn n ++ ".lc"
119type ModuleFetcher m = Maybe FilePath -> Either FilePath MName -> m (FilePath, MName, m SourceCode) 119type ModuleFetcher m = Maybe FilePath -> Either FilePath MName -> m (FilePath, MName, m SourceCode)
120 120
121ioFetch :: MonadIO m => [FilePath] -> ModuleFetcher (MMT m x) 121ioFetch :: MonadIO m => [FilePath] -> ModuleFetcher (MMT m x)
122ioFetch paths imp n = do 122ioFetch paths' imp n = do
123 preludePath <- (</> "lc") <$> liftIO getDataDir 123 preludePath <- (</> "lc") <$> liftIO getDataDir
124 find $ nubBy ((==) `on` fst) $ map (first normalise . lcModuleFile) $ paths ++ [preludePath] 124 let paths = paths' ++ [preludePath]
125 where 125 find ((x, mn): xs) = liftIO (readFile' x) >>= maybe (find xs) (\src -> return (x, mn, liftIO src))
126 find ((x, mn): xs) = liftIO (readFile' x) >>= maybe (find xs) (\src -> return (x, mn, liftIO src)) 126 find [] = throwError $ show $ "can't find " <+> either (("lc file" <+>) . text) (("module" <+>) . text) n
127 find [] = throwError $ show $ "can't find " <+> either (("lc file" <+>) . text) (("module" <+>) . text) n 127 <+> "in path" <+> hsep (map text paths)
128 <+> "in path" <+> hsep (map text paths) 128 lcModuleFile path = case n of
129 129 Left n -> (path </> n, fileNameToModuleName n)
130 lcModuleFile path = case n of 130 Right n -> (path </> moduleNameToFileName n, n)
131 Left n -> (path </> n, fileNameToModuleName n) 131 find $ nubBy ((==) `on` fst) $ map (first normalise . lcModuleFile) paths
132 Right n -> (path </> moduleNameToFileName n, n)
133 132
134-------------------------------------------------------------------------------- 133--------------------------------------------------------------------------------
135 134
@@ -246,7 +245,7 @@ preCompile paths paths' backend mod = do
246 first (compilePipeline backend) <$> parseAndToCoreMain "Main" 245 first (compilePipeline backend) <$> parseAndToCoreMain "Main"
247 where 246 where
248 fetch imp = \case 247 fetch imp = \case
249 Right "Prelude" -> return ("./Prelude.lc", "Prelude", undefined) 248 Left "Prelude" -> return ("./Prelude.lc", "Prelude", undefined)
250 Right "Main" -> return ("./Main.lc", "Main", return src) 249 Left "Main" -> return ("./Main.lc", "Main", return src)
251 n -> ioFetch paths' imp n 250 n -> ioFetch paths' imp n
252 251