@@ -22,6 +22,7 @@ import qualified Data.ByteString.Lazy as L
2222import qualified Metadata.Prelude as Prelude
2323import qualified Transform.Canonicalize as Canonical
2424import SourceSyntax.Module
25+import Parse.Module (getModuleName)
2526import Initialize (buildFromSource, getSortedDependencies)
2627import Generate.JavaScript (jsModule)
2728import Generate.Html (createHtml, JSStyle(..), JSSource(..))
@@ -96,7 +97,7 @@ elmi :: Flags -> FilePath -> FilePath
9697elmi flags filePath = cachePath flags filePath "elmi"
9798
9899
99−buildFile :: Flags -> Int -> Int -> Interfaces -> FilePath -> IO ModuleInterface
100+buildFile :: Flags -> Int -> Int -> Interfaces -> FilePath -> IO (String,ModuleInterface)
100101buildFile flags moduleNum numModules interfaces filePath =
101102 do compiled <- alreadyCompiled
102103 case compiled of
@@ -104,13 +105,11 @@ buildFile flags moduleNum numModules interfaces filePath =
104105 True -> do
105106 handle <- openBinaryFile (elmi flags filePath) ReadMode
106107 bits <- L.hGetContents handle
107− let iface = getInterface (Binary.decode bits)
108+ let info :: (String, ModuleInterface)
109+ info = Binary.decode bits
108110 L.length bits `seq` hClose handle
109− return iface
111+ return info
110112 where
111− getInterface :: (String, ModuleInterface) -> ModuleInterface
112− getInterface = snd
113−
114113 alreadyCompiled :: IO Bool
115114 alreadyCompiled = do
116115 existsi <- doesFileExist (elmi flags filePath)
@@ -124,15 +123,16 @@ buildFile flags moduleNum numModules interfaces filePath =
124123 number :: String
125124 number = "[" ++ show moduleNum ++ " of " ++ show numModules ++ "]"
126125
127− name :: String
128− name = List.intercalate "." (splitDirectories (dropExtensions filePath))
129−
130− compile :: IO ModuleInterface
126+ compile :: IO (String,ModuleInterface)
131127 compile = do
128+ source <- readFile filePath
129+ let name = case getModuleName source of
130+ Just n -> n
131+ Nothing -> "Name"
132132 putStrLn $ concat [ number, " Compiling ", name
133133 , replicate (max 1 (20 - length name)) ' '
134134 , "( " ++ filePath ++ " )" ]
135− source <- readFile filePath
135+
136136 createDirectoryIfMissing True (cache_dir flags)
137137 createDirectoryIfMissing True (build_dir flags)
138138 metaModule <-
@@ -158,7 +158,7 @@ buildFile flags moduleNum numModules interfaces filePath =
158158 L.hPut handle (Binary.encode (name,interface))
159159 hClose handle
160160 writeFile (elmo flags filePath) (jsModule metaModule)
161− return interface
161+ return (name,interface)
162162
163163printTypes metaModule = do
164164 putStrLn ""
@@ -207,7 +207,6 @@ build flags rootFile = do
207207buildFiles :: Flags -> Int -> Interfaces -> String -> [FilePath] -> IO (String, Interfaces)
208208buildFiles _ _ interfaces moduleName [] = return (moduleName, interfaces)
209209buildFiles flags numModules interfaces _ (filePath:rest) = do
210− interface <- buildFile flags (numModules - length rest) numModules interfaces filePath
211− let moduleName = List.intercalate "." . splitDirectories $ dropExtensions filePath
212− interfaces' = Map.insert moduleName interface interfaces
213− buildFiles flags numModules interfaces' moduleName rest
210+ (name,interface) <- buildFile flags (numModules - length rest) numModules interfaces filePath
211+ let interfaces' = Map.insert name interface interfaces
212+ buildFiles flags numModules interfaces' name rest