diff --git a/compiler/Compiler.hs b/compiler/Compiler.hs index 5b37c65..25e1e4c 100644 --- a/compiler/Compiler.hs +++ b/compiler/Compiler.hs @@ -97,26 +97,22 @@ elmi flags filePath = cachePath flags filePath "elmi" buildFile :: Flags -> Int -> Int -> Interfaces -> FilePath -> IO (String, ModuleInterface) buildFile flags moduleNum numModules interfaces filePath = do compiled <- alreadyCompiled - if compiled then do + if not compiled then compile else do bytes <- IS.loadInterface (elmi flags filePath) - case bytes >>= IS.interfaceDecode (elmi flags filePath) >>= - IS.validVersion filePath of - + let binary = IS.interfaceDecode (elmi flags filePath) =<< bytes + case IS.validVersion filePath =<< binary of Left err -> do - hPutStrLn stderr err - exitFailure + hPutStrLn stderr err + exitFailure Right (name, interface) -> do - when (print_types flags) - (printTypes interfaces - (iTypes interface) - (iAliases interface) - (iImports interface)) + when (print_types flags) $ + printTypes interfaces + (iTypes interface) + (iAliases interface) + (iImports interface) - return (name, interface) - - else - compile + return (name, interface) where alreadyCompiled :: IO Bool @@ -212,9 +208,8 @@ build flags rootFile = do where appendToOutput :: BS.ByteString -> FilePath -> IO BS.ByteString appendToOutput js filePath = - do - src <- BS.readFile (elmo flags filePath) - return (BS.append src js) + do src <- BS.readFile (elmo flags filePath) + return (BS.append src js) sources js = map Link (scripts flags) ++ [ Source js ] diff --git a/compiler/InterfaceSerialization.hs b/compiler/InterfaceSerialization.hs index 47dad46..351d3ac 100644 --- a/compiler/InterfaceSerialization.hs +++ b/compiler/InterfaceSerialization.hs @@ -23,26 +23,27 @@ loadInterface filePath = do return $ Right byteString else - return $ Left $ "Unable to find file " ++ filePath ++ - " for deserialization!" + return $ Left $ "Unable to find file " ++ filePath ++ + " for deserialization!" -interfaceDecode :: Binary.Binary a => FilePath -> L.ByteString -> - Either String a +interfaceDecode :: Binary.Binary a => + FilePath -> L.ByteString -> Either String a interfaceDecode filePath bytes = do case Binary.decodeOrFail bytes of - Left (_, offset, err) -> do - Left $ "Got an error, '" ++ err ++ "' at offset " ++ - show offset ++ " of " ++ filePath ++ ".\n\n" ++ - "This error may be due to an outdated or corrupt " ++ - "artifact from a previous build. Please rebuild " ++ - filePath ++ " and try again." - Right (_, _, binaryInfo) -> Right binaryInfo + Left (_, offset, err) -> + Left $ concat [ "Got an error, '" ++ err ++ "' at offset " + , show offset ++ " of " ++ filePath ++ ".\n\n" + , "This error may be due to an outdated or corrupt " + , "artifact from a previous build. Please rebuild " + , filePath ++ " and try again." + ] + validVersion :: FilePath -> (String, ModuleInterface) -> Either String (String, ModuleInterface) validVersion filePath (name, interface) = - if (iVersion interface) == showVersion version then + if iVersion interface == showVersion version then Right (name, interface) else Left $ "Found build artifacts created by a different " ++