@@ -22,6 +22,7 @@ import qualified Data.ByteString.Lazy as L
22import qualified Metadata.Prelude as Prelude
22import qualified Metadata.Prelude as Prelude
23import qualified Transform.Canonicalize as Canonical
23import qualified Transform.Canonicalize as Canonical
24import SourceSyntax.Module
24import SourceSyntax.Module
25+import Parse.Module (getModuleName)
25import Initialize (buildFromSource, getSortedDependencies)
26import Initialize (buildFromSource, getSortedDependencies)
26import Generate.JavaScript (jsModule)
27import Generate.JavaScript (jsModule)
27import Generate.Html (createHtml, JSStyle(..), JSSource(..))
28import Generate.Html (createHtml, JSStyle(..), JSSource(..))
@@ -96,7 +97,7 @@ elmi :: Flags -> FilePath -> FilePath
96elmi flags filePath = cachePath flags filePath "elmi"
97elmi flags filePath = cachePath flags filePath "elmi"
99−buildFile :: Flags -> Int -> Int -> Interfaces -> FilePath -> IO ModuleInterface
100+buildFile :: Flags -> Int -> Int -> Interfaces -> FilePath -> IO (String,ModuleInterface)
100buildFile flags moduleNum numModules interfaces filePath =
101buildFile flags moduleNum numModules interfaces filePath =
101 do compiled <- alreadyCompiled
102 do compiled <- alreadyCompiled
102 case compiled of
103 case compiled of
@@ -104,13 +105,11 @@ buildFile flags moduleNum numModules interfaces filePath =
104 True -> do
105 True -> do
105 handle <- openBinaryFile (elmi flags filePath) ReadMode
106 handle <- openBinaryFile (elmi flags filePath) ReadMode
106 bits <- L.hGetContents handle
107 bits <- L.hGetContents handle
108+ let info :: (String, ModuleInterface)
107− let iface = getInterface (Binary.decode bits)
109+ info = Binary.decode bits
108 L.length bits `seq` hClose handle
110 L.length bits `seq` hClose handle
109− return iface
111+ return info
111− getInterface :: (String, ModuleInterface) -> ModuleInterface
114 alreadyCompiled :: IO Bool
113 alreadyCompiled :: IO Bool
115 alreadyCompiled = do
114 alreadyCompiled = do
116 existsi <- doesFileExist (elmi flags filePath)
115 existsi <- doesFileExist (elmi flags filePath)
@@ -124,15 +123,16 @@ buildFile flags moduleNum numModules interfaces filePath =
124 number :: String
123 number :: String
125 number = "[" ++ show moduleNum ++ " of " ++ show numModules ++ "]"
124 number = "[" ++ show moduleNum ++ " of " ++ show numModules ++ "]"
128− name = List.intercalate "." (splitDirectories (dropExtensions filePath))
130− compile :: IO ModuleInterface
126+ compile :: IO (String,ModuleInterface)
131 compile = do
127 compile = do
128+ source <- readFile filePath
129+ let name = case getModuleName source of
132 putStrLn $ concat [ number, " Compiling ", name
132 putStrLn $ concat [ number, " Compiling ", name
133 , replicate (max 1 (20 - length name)) ' '
133 , replicate (max 1 (20 - length name)) ' '
134 , "( " ++ filePath ++ " )" ]
134 , "( " ++ filePath ++ " )" ]
135− source <- readFile filePath
135+
136 createDirectoryIfMissing True (cache_dir flags)
136 createDirectoryIfMissing True (cache_dir flags)
137 createDirectoryIfMissing True (build_dir flags)
137 createDirectoryIfMissing True (build_dir flags)
138 metaModule <-
138 metaModule <-
@@ -158,7 +158,7 @@ buildFile flags moduleNum numModules interfaces filePath =
158 L.hPut handle (Binary.encode (name,interface))
158 L.hPut handle (Binary.encode (name,interface))
159 hClose handle
159 hClose handle
160 writeFile (elmo flags filePath) (jsModule metaModule)
160 writeFile (elmo flags filePath) (jsModule metaModule)
161− return interface
161+ return (name,interface)
163printTypes metaModule = do
163printTypes metaModule = do
164 putStrLn ""
164 putStrLn ""
@@ -207,7 +207,6 @@ build flags rootFile = do
207buildFiles :: Flags -> Int -> Interfaces -> String -> [FilePath] -> IO (String, Interfaces)
207buildFiles :: Flags -> Int -> Interfaces -> String -> [FilePath] -> IO (String, Interfaces)
208buildFiles _ _ interfaces moduleName [] = return (moduleName, interfaces)
208buildFiles _ _ interfaces moduleName [] = return (moduleName, interfaces)
209buildFiles flags numModules interfaces _ (filePath:rest) = do
209buildFiles flags numModules interfaces _ (filePath:rest) = do
210− interface <- buildFile flags (numModules - length rest) numModules interfaces filePath
210+ (name,interface) <- buildFile flags (numModules - length rest) numModules interfaces filePath
211− let moduleName = List.intercalate "." . splitDirectories $ dropExtensions filePath
212− interfaces' = Map.insert moduleName interface interfaces
211+ let interfaces' = Map.insert name interface interfaces
213− buildFiles flags numModules interfaces' moduleName rest
212+ buildFiles flags numModules interfaces' name rest