shithub: MicroHs

Download patch

ref: acc1d2e3712981ac47b26a6403ac874d4e163aea
parent: 1e2d0c28f0d071c623c6d1e7436f506c4459a24f
author: Lennart Augustsson <lennart@augustsson.net>
date: Sun Sep 29 08:11:28 EDT 2024

Fix some bugs.

--- a/TODO
+++ b/TODO
@@ -47,3 +47,4 @@
 * export list in -boot doesn't work
 * Cannot derive Show for 'newtype Alt f a = Alt (f a)'
 * Fundep bug mtl:Control/Monad/RWS/Class.hs
+* Cannot parse (== -1)
--- a/lib/Foreign/C/String.hs
+++ b/lib/Foreign/C/String.hs
@@ -1,8 +1,9 @@
 module Foreign.C.String(
-  CChar, CString, CStringLen,
+  CString, CStringLen,
   newCAString, newCAStringLen,
   peekCAString, peekCAStringLen,
   withCAString,
+  peekCString,
   ) where
 import Prelude()              -- do not import Prelude
 import Primitives
@@ -31,3 +32,8 @@
 
 peekCAStringLen :: CStringLen -> IO String
 peekCAStringLen (p, i) = primPeekCAStringLen p i
+
+-- Not quite right
+peekCString :: CString -> IO String
+peekCString = primPeekCAString
+
--- a/lib/System/IO/Error.hs
+++ b/lib/System/IO/Error.hs
@@ -1,8 +1,9 @@
 module System.IO.Error (
-    IOException,
+    IOException(..),
 
     -- * I\/O errors
     IOError,
+    IOErrorType(..),
 
     userError,
 
--- a/src/MicroHs/FFI.hs
+++ b/src/MicroHs/FFI.hs
@@ -10,7 +10,9 @@
 
 makeFFI :: Flags -> [LDef] -> String
 makeFFI _ ds =
-  let ffiImports = [ (parseImpEnt i f, t) | (i, Lit (LForImp f (CType t))) <- ds ]
+  let ffiImports = [ (parseImpEnt i f, t) | (i, d) <- ds, Lit (LForImp f (CType t)) <- [get d] ]
+                 where get (App _ a) = a   -- if there is no IO type, we have (App primPerform (LForImp ...))
+                       get a = a
       wrappers = [ t | (ImpWrapper, t) <- ffiImports]
       dynamics = [ t | (ImpDynamic, t) <- ffiImports]
       imps     = uniqName $ filter ((`notElem` runtimeFFI) . impName) ffiImports
@@ -31,6 +33,7 @@
 uniqName = map head . groupBy ((==) `on` impName) . sortBy (compare `on` impName)
 
 data ImpEnt = ImpStatic Ident (Maybe String) Imp String | ImpDynamic | ImpWrapper
+--  deriving (Show)
 
 impName :: (ImpEnt, EType) -> String
 impName (ImpStatic i _ Value _, _) = unIdent' i
@@ -38,6 +41,7 @@
 impName _ = undefined
 
 data Imp = Ptr | Value | Func
+--  deriving (Show)
 
 -- "[static] [name.h] [&] [name]"
 -- "dynamic"