shithub: MicroHs

Download patch

ref: d93dc04067fa92b9a58299a42fc73282e1836d7b
parent: ef3d5eb28f6145d1a860901c9abe3fe0f18b777f
author: Lennart Augustsson <lennart@augustsson.net>
date: Fri Sep 1 11:54:22 EDT 2023

Use correct file name.

--- a/Tools/Addcombs.hs
+++ b/Tools/Addcombs.hs
@@ -19,4 +19,4 @@
   putStrLn $ "struct { size_t b_size; size_t b_pos; uint8_t b_buffer[]; } combs = { " ++ show size ++ ", 0, {"
   mapM_ (putStrLn . showChunk) chunks
   putStrLn "}};"
-  putStrLn "BFILE *comb_internal = (BFILE*)&combs;"
\ No newline at end of file
+  putStrLn "BFILE *comb_internal = (BFILE*)&combs;"
--- a/src/MicroHs/Compile.hs
+++ b/src/MicroHs/Compile.hs
@@ -4,7 +4,7 @@
   compile,
   Flags(..), verbose, runIt, output
   ) where
-import Prelude --Xhiding (Monad(..), mapM, showString)
+import Prelude --Xhiding (Monad(..), mapM, showString, showList)
 import qualified System.IO as IO
 --Ximport Compat
 --Ximport qualified CompatIO as IO
@@ -99,7 +99,8 @@
   t1 <- liftIO getTimeMilli
   let
     fn = map (\ c -> if eqChar c '.' then '/' else c) (unIdent nm) ++ ".hs"
-  mdl@(EModule nmn _ defs) <- S.fmap (parseDie pTop fn) (liftIO (readFilePath (paths flags) fn))
+  (pathfn, file) <- liftIO (readFilePath (paths flags) fn)
+  let mdl@(EModule nmn _ defs) = parseDie pTop pathfn file
   --liftIO $ putStrLn $ showEModule mdl
   S.when (not (eqIdent nm nmn)) $
     error $ "module name does not agree with file name: " ++ showIdent nm ++ " " ++ showIdent nmn
@@ -122,15 +123,19 @@
 
 ------------------
 
-readFilePath :: [FilePath] -> FilePath -> IO String
+readFilePath :: [FilePath] -> FilePath -> IO (FilePath, String)
 readFilePath path name = IO.do
-  h <- openFilePath path name
-  IO.hGetContents h
+  mh <- openFilePath path name
+  case mh of
+    Nothing -> error $ "File not found: " ++ showString name ++ "\npath=" ++ showList showString path
+    Just (fn, h) -> IO.do
+      file <- IO.hGetContents h
+      IO.return (fn, file)
 
-openFilePath :: [FilePath] -> FilePath -> IO Handle
+openFilePath :: [FilePath] -> FilePath -> IO (Maybe (FilePath, Handle))
 openFilePath adirs fileName =
   case adirs of
-    [] -> error $ "File not found: " ++ showString fileName
+    [] -> IO.return Nothing
     dir:dirs -> IO.do
       let
         path = dir ++ "/" ++ fileName
@@ -137,4 +142,4 @@
       mh <- openFileM path IO.ReadMode
       case mh of
         Nothing -> openFilePath dirs fileName -- If opening failed, try the next directory
-        Just hdl -> IO.return hdl
+        Just hdl -> IO.return (Just (path, hdl))
--