on master help sign in
Begin passing module interfaces when compiling dependencies
commitb1dd1574a8af0ccab50ef7b54f2bfd1dcee2638e authorEvan Czaplicki <info@elm-lang.org> dateSun 21 Jul 2013, 07:14 (13 years ago) parent22f7f8a
2 files changed+16−11
compiler/Compiler.hs+15−10 compiler/Initialize.hs+1−1
compiler/Compiler.hs+15−10
@@ -79,8 +79,8 @@ elmo flags filePath = file flags filePath "elmo"
7979elmi flags filePath = file flags filePath "elmi"
8080
8181
82−buildFile :: Flags -> Int -> Int -> FilePath -> IO ModuleInterface
83−buildFile flags moduleNum numModules filePath =
82+buildFile :: Flags -> Int -> Int -> (Map.Map String ModuleInterface) -> FilePath -> IO ModuleInterface
83+buildFile flags moduleNum numModules interfaces filePath =
8484 do compiled <- alreadyCompiled
8585 if compiled then decodeFile (elmi flags filePath) else compile
8686
@@ -105,7 +105,7 @@ buildFile flags moduleNum numModules filePath =
105105 source <- readFile filePath
106106 createDirectoryIfMissing True (output_directory flags)
107107 metaModule <-
108− case buildFromSource Map.empty source of
108+ case buildFromSource interfaces source of
109109 Left err -> mapM print err >> exitFailure
110110 Right modul -> return (modul :: MetadataModule () ())
111111 if print_types flags then printTypes metaModule else return ()
@@ -124,11 +124,12 @@ toSrcTypes tipes = Traverse.traverse convert tipes
124124 where
125125 convert t = fmap (Parse.readType . P.render) (Type.extraPretty t)
126126
127−printTypes metaModule =
128− forM_ (Map.toList $ types metaModule) $ \(n,t) -> do
127+printTypes metaModule = do
128+ putStrLn ""
129+ forM_ (Map.toList $ types metaModule) $ \(n,t) -> do
129130 pt <- Type.extraPretty t
130131 print $ P.text n <+> P.text ":" <+> pt
131−
132+ putStrLn ""
132133
133134getRuntime :: Flags -> IO FilePath
134135getRuntime flags =
@@ -139,7 +140,7 @@ getRuntime flags =
139140build :: Flags -> FilePath -> IO ()
140141build flags rootFile = do
141142 files <- if make flags then getSortedModuleNames rootFile else return [rootFile]
142− buildFiles flags (length files) Map.empty files
143+ interfaces <- buildFiles flags (length files) Map.empty files
143144 js <- foldM appendToOutput "" files
144145 case only_js flags of
145146 True -> do
@@ -165,10 +166,14 @@ build flags rootFile = do
165166 [ Source (if minify flags then Minified else Readable) js ]
166167
167168
168−buildFiles :: Flags -> Int -> Map.Map String ModuleInterface -> [FilePath] -> IO ()
169−buildFiles _ _ _ [] = return ()
169+buildFiles :: Flags
170+ -> Int
171+ -> Map.Map String ModuleInterface
172+ -> [FilePath]
173+ -> IO (Map.Map String ModuleInterface)
174+buildFiles _ _ interfaces [] = return interfaces
170175buildFiles flags numModules interfaces (filePath:rest) = do
171− interface <- buildFile flags (numModules - length rest) numModules filePath
176+ interface <- buildFile flags (numModules - length rest) numModules interfaces filePath
172177 let moduleName = List.intercalate "." (splitDirectories (dropExtensions filePath))
173178 interfaces' = Map.insert moduleName interface interfaces
174179 buildFiles flags numModules interfaces' rest
compiler/Initialize.hs+1−1
@@ -18,7 +18,7 @@ import qualified Type.Inference as TI
1818import qualified Type.Constrain.Declaration as TcDecl
1919
2020
21−type TypeLibrary = Map.Map String (Map.Map String Type)
21+type TypeLibrary = Map.Map String ModuleInterface
2222
2323buildFromSource ::
2424 (Data t, Data v) =>