diff options
author | Csaba Hruska <csaba.hruska@gmail.com> | 2016-02-04 13:15:48 +0100 |
---|---|---|
committer | Csaba Hruska <csaba.hruska@gmail.com> | 2016-02-04 13:15:48 +0100 |
commit | 80aa72b28ae90815c9e142a6fbc7fed14ed56b07 (patch) | |
tree | cb5992af5a78ba69a901c3414e33efac3bbc34d0 | |
parent | 514da00bf5e0e913acdcdf1706157d0d9c7276e8 (diff) |
always include builtins path
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | lambdacube-compiler.cabal | 2 | ||||
-rw-r--r-- | src/LambdaCube/Compiler.hs | 11 | ||||
-rw-r--r-- | tool/Compiler.hs | 12 |
4 files changed, 15 insertions, 12 deletions
@@ -51,6 +51,7 @@ done: | |||
51 | - compiler optimization: erease univ. pol. arguments of constructors | 51 | - compiler optimization: erease univ. pol. arguments of constructors |
52 | - compiler optimization: erease univ. pol. arguments of case functions | 52 | - compiler optimization: erease univ. pol. arguments of case functions |
53 | - compiler optimization: speed up 'eval' function | 53 | - compiler optimization: speed up 'eval' function |
54 | - compiler put internals and prelude automaticly to include path when using compiler as a library | ||
54 | - use less 'try' in parser | 55 | - use less 'try' in parser |
55 | - desugar node definitions | 56 | - desugar node definitions |
56 | - definitions are allowed in any order (not just bottom-up) | 57 | - definitions are allowed in any order (not just bottom-up) |
@@ -66,7 +67,6 @@ next: | |||
66 | - editor: editor socket reconnection | 67 | - editor: editor socket reconnection |
67 | - editor: highlight errors in editor | 68 | - editor: highlight errors in editor |
68 | - release 0.4 compiler on hackage | 69 | - release 0.4 compiler on hackage |
69 | - put internals and prelude automaticly to include path when using compiler as a library | ||
70 | - sync getting started description with the example source code | 70 | - sync getting started description with the example source code |
71 | - blog about release: | 71 | - blog about release: |
72 | - few sentences about the past events | 72 | - few sentences about the past events |
diff --git a/lambdacube-compiler.cabal b/lambdacube-compiler.cabal index ee3bea97..83661eba 100644 --- a/lambdacube-compiler.cabal +++ b/lambdacube-compiler.cabal | |||
@@ -37,6 +37,8 @@ source-repository head | |||
37 | location: https://github.com/lambdacube3d/lambdacube-compiler | 37 | location: https://github.com/lambdacube3d/lambdacube-compiler |
38 | 38 | ||
39 | library | 39 | library |
40 | other-modules: | ||
41 | Paths_lambdacube_compiler | ||
40 | exposed-modules: | 42 | exposed-modules: |
41 | -- Compiler | 43 | -- Compiler |
42 | LambdaCube.Compiler | 44 | LambdaCube.Compiler |
diff --git a/src/LambdaCube/Compiler.hs b/src/LambdaCube/Compiler.hs index 7237ae12..e5496062 100644 --- a/src/LambdaCube/Compiler.hs +++ b/src/LambdaCube/Compiler.hs | |||
@@ -49,6 +49,9 @@ import LambdaCube.Compiler.Pretty hiding ((</>)) | |||
49 | import LambdaCube.Compiler.Infer (Infos, listInfos, ErrorMsg(..), PolyEnv(..), Export(..), Module(..), ErrorT, throwErrorTCM, parseLC, joinPolyEnvs, filterPolyEnv, inference_, ImportItems (..), Range(..), Exp, outputType, boolType, trueExp) | 49 | import LambdaCube.Compiler.Infer (Infos, listInfos, ErrorMsg(..), PolyEnv(..), Export(..), Module(..), ErrorT, throwErrorTCM, parseLC, joinPolyEnvs, filterPolyEnv, inference_, ImportItems (..), Range(..), Exp, outputType, boolType, trueExp) |
50 | import LambdaCube.Compiler.CoreToIR | 50 | import LambdaCube.Compiler.CoreToIR |
51 | 51 | ||
52 | -- inlcude path for: Builtins, Internals and Prelude | ||
53 | import Paths_lambdacube_compiler (getDataDir) | ||
54 | |||
52 | type EName = String | 55 | type EName = String |
53 | type MName = String | 56 | type MName = String |
54 | 57 | ||
@@ -97,15 +100,16 @@ readFile' fname = do | |||
97 | if b then Just <$> readFileStrict fname else return Nothing | 100 | if b then Just <$> readFileStrict fname else return Nothing |
98 | 101 | ||
99 | ioFetch :: MonadIO m => [FilePath] -> ModuleFetcher (MMT m) | 102 | ioFetch :: MonadIO m => [FilePath] -> ModuleFetcher (MMT m) |
100 | ioFetch paths imp n = f fnames | 103 | ioFetch paths imp n = do |
101 | where | 104 | preludePath <- (</> "lc") <$> liftIO getDataDir |
105 | let | ||
102 | f [] = throwErrorTCM $ "can't find module" <+> hsep (map text fnames) | 106 | f [] = throwErrorTCM $ "can't find module" <+> hsep (map text fnames) |
103 | f (x:xs) = liftIO (readFile' x) >>= \case | 107 | f (x:xs) = liftIO (readFile' x) >>= \case |
104 | Nothing -> f xs | 108 | Nothing -> f xs |
105 | Just src -> do | 109 | Just src -> do |
106 | --liftIO $ putStrLn $ "loading " ++ x | 110 | --liftIO $ putStrLn $ "loading " ++ x |
107 | return (x, src) | 111 | return (x, src) |
108 | fnames = map normalise . concatMap lcModuleFile $ nub paths | 112 | fnames = map normalise . concatMap lcModuleFile $ nub $ preludePath : paths |
109 | lcModuleFile path = (++ ".lc") <$> g imp | 113 | lcModuleFile path = (++ ".lc") <$> g imp |
110 | where | 114 | where |
111 | g Nothing = [path </> n] | 115 | g Nothing = [path </> n] |
@@ -115,6 +119,7 @@ ioFetch paths imp n = f fnames | |||
115 | h acc [] = reverse acc | 119 | h acc [] = reverse acc |
116 | h acc ('.':cs) = reverse acc </> h [] cs | 120 | h acc ('.':cs) = reverse acc </> h [] cs |
117 | h acc (c: cs) = h (c: acc) cs | 121 | h acc (c: cs) = h (c: acc) cs |
122 | f fnames | ||
118 | 123 | ||
119 | splitMPath fn = (joinPath as, intercalate "." $ bs ++ [y]) | 124 | splitMPath fn = (joinPath as, intercalate "." $ bs ++ [y]) |
120 | where | 125 | where |
diff --git a/tool/Compiler.hs b/tool/Compiler.hs index 0723c0c8..215cf106 100644 --- a/tool/Compiler.hs +++ b/tool/Compiler.hs | |||
@@ -4,27 +4,23 @@ import Data.Aeson | |||
4 | import qualified Data.ByteString.Lazy as B | 4 | import qualified Data.ByteString.Lazy as B |
5 | import System.FilePath | 5 | import System.FilePath |
6 | 6 | ||
7 | import Paths_lambdacube_compiler (getDataDir) | ||
8 | import LambdaCube.Compiler | 7 | import LambdaCube.Compiler |
9 | 8 | ||
10 | data Config | 9 | data Config |
11 | = Config | 10 | = Config |
12 | { srcName :: String | 11 | { srcName :: String |
13 | , backend :: Backend | 12 | , backend :: Backend |
14 | , sourceDir :: FilePath | 13 | , includePaths :: [FilePath] |
15 | } | 14 | } |
16 | 15 | ||
17 | sample :: Parser Config | 16 | sample :: Parser Config |
18 | sample = Config | 17 | sample = Config |
19 | <$> argument str (metavar "SOURCE_FILE") | 18 | <$> argument str (metavar "SOURCE_FILE") |
20 | <*> flag OpenGL33 WebGL1 (long "webgl" <> help "generate WebGL 1.0 pipeline" ) | 19 | <*> flag OpenGL33 WebGL1 (long "webgl" <> help "generate WebGL 1.0 pipeline" ) |
21 | <*> pure "/lc" | 20 | <*> pure ["."] |
22 | 21 | ||
23 | main :: IO () | 22 | main :: IO () |
24 | main = do | 23 | main = compile =<< execParser opts |
25 | cabalDataDir <- getDataDir | ||
26 | cfg <- execParser opts | ||
27 | compile (cfg {sourceDir = cabalDataDir </> "lc"}) | ||
28 | where | 24 | where |
29 | opts = info (helper <*> sample) | 25 | opts = info (helper <*> sample) |
30 | ( fullDesc | 26 | ( fullDesc |
@@ -36,7 +32,7 @@ compile Config{..} = do | |||
36 | let dropExt n | takeExtension n == ".lc" = dropExtension n | 32 | let dropExt n | takeExtension n == ".lc" = dropExtension n |
37 | dropExt n = n | 33 | dropExt n = n |
38 | baseName = dropExt srcName | 34 | baseName = dropExt srcName |
39 | pplRes <- compileMain [".", sourceDir] backend baseName | 35 | pplRes <- compileMain includePaths backend baseName |
40 | case pplRes of | 36 | case pplRes of |
41 | Left err -> putStrLn err | 37 | Left err -> putStrLn err |
42 | Right ppl -> B.writeFile (baseName <> ".json") $ encode ppl | 38 | Right ppl -> B.writeFile (baseName <> ".json") $ encode ppl |