@@ -24,6 +24,7 @@ import Parse.Module (getModuleName)
24import Initialize (buildFromSource, getSortedDependencies)
24import Initialize (buildFromSource, getSortedDependencies)
25import Generate.JavaScript (jsModule)
25import Generate.JavaScript (jsModule)
26import Generate.Html (createHtml, JSSource(..))
26import Generate.Html (createHtml, JSSource(..))
27+import qualified InterfaceSerialization as IS
27import Paths_Elm
28import Paths_Elm
29import SourceSyntax.PrettyPrint (pretty, variable)
30import SourceSyntax.PrettyPrint (pretty, variable)
@@ -39,9 +40,9 @@ data Flags =
39 , print_types :: Bool
40 , print_types :: Bool
40 , scripts :: [FilePath]
41 , scripts :: [FilePath]
41 , no_prelude :: Bool
42 , no_prelude :: Bool
42− , cache_dir :: FilePath
43+ , cache_dir :: FilePath
43− , build_dir :: FilePath
44+ , build_dir :: FilePath
44− , src_dir :: [FilePath]
45+ , src_dir :: [FilePath]
46 deriving (Data,Typeable,Show,Eq)
47 deriving (Data,Typeable,Show,Eq)
@@ -93,27 +94,30 @@ elmo flags filePath = cachePath flags filePath "elmo"
93elmi :: Flags -> FilePath -> FilePath
94elmi :: Flags -> FilePath -> FilePath
94elmi flags filePath = cachePath flags filePath "elmi"
95elmi flags filePath = cachePath flags filePath "elmi"
97+buildFile :: Flags -> Int -> Int -> Interfaces -> FilePath -> IO (String, ModuleInterface)
98+buildFile flags moduleNum numModules interfaces filePath = do
99+ compiled <- alreadyCompiled
101+ bytes <- IS.loadInterface (elmi flags filePath)
102+ case bytes >>= IS.interfaceDecode (elmi flags filePath) >>=
103+ IS.validVersion filePath of
97−buildFile :: Flags -> Int -> Int -> Interfaces -> FilePath -> IO (String,ModuleInterface)
105+ Left err -> do
98−buildFile flags moduleNum numModules interfaces filePath =
106+ hPutStrLn stderr err
99− do compiled <- alreadyCompiled
107+ exitFailure
103− handle <- openBinaryFile (elmi flags filePath) ReadMode
104− bits <- L.hGetContents handle
105− let info :: (String, ModuleInterface)
106− info = Binary.decode bits
107− modInterface = snd info
109+ Right (name, interface) -> do
109− when (print_types flags)
110+ when (print_types flags)
110− (printTypes interfaces
111+ (printTypes interfaces
111− (iTypes modInterface)
112+ (iTypes interface)
112− (iAliases modInterface)
113+ (iAliases interface)
113− (iImports modInterface))
114+ (iImports interface))
116+ return (name, interface)
115− L.length bits `seq` hClose handle
118 alreadyCompiled :: IO Bool
122 alreadyCompiled :: IO Bool
119 alreadyCompiled = do
123 alreadyCompiled = do
@@ -140,6 +144,7 @@ buildFile flags moduleNum numModules interfaces filePath =
141 createDirectoryIfMissing True (cache_dir flags)
145 createDirectoryIfMissing True (cache_dir flags)
142 createDirectoryIfMissing True (build_dir flags)
146 createDirectoryIfMissing True (build_dir flags)
143 metaModule <-
148 metaModule <-
144 case buildFromSource (no_prelude flags) interfaces source of
149 case buildFromSource (no_prelude flags) interfaces source of
145 Left errors -> do
150 Left errors -> do
@@ -152,6 +157,7 @@ buildFile flags moduleNum numModules interfaces filePath =
152 (types metaModule) (aliases metaModule) (imports metaModule))
157 (types metaModule) (aliases metaModule) (imports metaModule))
154 let interface = Canonical.interface name $ ModuleInterface {
159 let interface = Canonical.interface name $ ModuleInterface {
160+ iVersion = showVersion version,
155 iTypes = types metaModule,
161 iTypes = types metaModule,
156 iImports = imports metaModule,
162 iImports = imports metaModule,
157 iAdts = datatypes metaModule,
163 iAdts = datatypes metaModule,
@@ -206,12 +212,12 @@ build flags rootFile = do
207 appendToOutput :: BS.ByteString -> FilePath -> IO BS.ByteString
213 appendToOutput :: BS.ByteString -> FilePath -> IO BS.ByteString
208 appendToOutput js filePath =
214 appendToOutput js filePath =
209− do src <- BS.readFile (elmo flags filePath)
216+ src <- BS.readFile (elmo flags filePath)
210− return (BS.append src js)
217+ return (BS.append src js)
212 sources js = map Link (scripts flags) ++ [ Source js ]
219 sources js = map Link (scripts flags) ++ [ Source js ]
215buildFiles :: Flags -> Int -> Interfaces -> String -> [FilePath] -> IO (String, Interfaces)
221buildFiles :: Flags -> Int -> Interfaces -> String -> [FilePath] -> IO (String, Interfaces)
216buildFiles _ _ interfaces moduleName [] = return (moduleName, interfaces)
222buildFiles _ _ interfaces moduleName [] = return (moduleName, interfaces)
217buildFiles flags numModules interfaces _ (filePath:rest) = do
223buildFiles flags numModules interfaces _ (filePath:rest) = do