summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2018-11-25 16:43:04 -0500
committerJoe Crayne <joe@jerkface.net>2018-11-25 16:43:04 -0500
commit516e3520940959b378c71a8738456cc91878eb49 (patch)
treea781f145634b7c9814f2cd4eee359a9ce91316cb
parent213cacba7d36062b8a3bdc4b05bb3dc2eeeb4a06 (diff)
Rename stubs file to <Module>_patch.c
-rw-r--r--c2haskell.hs19
1 files changed, 11 insertions, 8 deletions
diff --git a/c2haskell.hs b/c2haskell.hs
index e55e9a9..8b1d843 100644
--- a/c2haskell.hs
+++ b/c2haskell.hs
@@ -207,21 +207,23 @@ notKnown "Int16" = False
207notKnown "Int32" = False 207notKnown "Int32" = False
208notKnown "Int64" = False 208notKnown "Int64" = False
209notKnown "Bool" = False 209notKnown "Bool" = False
210notKnown "Word" = False
210notKnown "Int" = False 211notKnown "Int" = False
211notKnown "Char" = False 212notKnown "Char" = False
212notKnown "()" = False 213notKnown "()" = False
213notKnown _ = True 214notKnown _ = True
214 215
215hsTypeSpec :: CDeclarationSpecifier t -> [Either Ident String] 216hsTypeSpec :: CDeclarationSpecifier t -> [Either Ident String]
216hsTypeSpec (CTypeSpec (CVoidType _)) = [ Right "()" ] 217hsTypeSpec (CTypeSpec (CVoidType _)) = [ Right "()" ]
218hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "size_t" _ _) _)) = [ Right "Word"]
217hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "uint8_t" _ _) _)) = [ Right "Word8"] 219hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "uint8_t" _ _) _)) = [ Right "Word8"]
218hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "uint16_t" _ _) _)) = [ Right "Word16"] 220hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "uint16_t" _ _) _)) = [ Right "Word16"]
219hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "uint32_t" _ _) _)) = [ Right "Word32"] 221hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "uint32_t" _ _) _)) = [ Right "Word32"]
220hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "uint64_t" _ _) _)) = [ Right "Word64"] 222hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "uint64_t" _ _) _)) = [ Right "Word64"]
221hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "int8_t" _ _) _)) = [ Right "Int8"] 223hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "int8_t" _ _) _)) = [ Right "Int8"]
222hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "int16_t" _ _) _)) = [ Right "Int16"] 224hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "int16_t" _ _) _)) = [ Right "Int16"]
223hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "int32_t" _ _) _)) = [ Right "Int32"] 225hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "int32_t" _ _) _)) = [ Right "Int32"]
224hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "int64_t" _ _) _)) = [ Right "Int64"] 226hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "int64_t" _ _) _)) = [ Right "Int64"]
225hsTypeSpec (CTypeSpec (CTypeDef ctyp _)) = [ Left ctyp ] 227hsTypeSpec (CTypeSpec (CTypeDef ctyp _)) = [ Left ctyp ]
226hsTypeSpec (CTypeSpec (CBoolType _)) = [ Right "Bool"] 228hsTypeSpec (CTypeSpec (CBoolType _)) = [ Right "Bool"]
227hsTypeSpec (CTypeSpec (CIntType _)) = [ Right "Int"] 229hsTypeSpec (CTypeSpec (CIntType _)) = [ Right "Int"]
@@ -253,7 +255,8 @@ hsTransField ctyps vars
253 var <- vars 255 var <- vars
254 trace ("var="++show var) $ return () 256 trace ("var="++show var) $ return ()
255 -- CDeclr (Just fident) ptrdeclr Nothing [] _ <- maybeToList var 257 -- CDeclr (Just fident) ptrdeclr Nothing [] _ <- maybeToList var
256 let CDeclr mfident ptrdeclr Nothing [] _ = var 258 let CDeclr mfident ptrdeclr Nothing [] _ = var -- TODO: Look into: Irrefutable pattern failed (ctox/toxcore/DHT.c)
259 -- let CDeclr mfident ptrdeclr _ _ _ = var
257 trace ("fident="++show mfident) $ return () 260 trace ("fident="++show mfident) $ return ()
258 trace ("ptrdeclr="++show ptrdeclr) $ return () 261 trace ("ptrdeclr="++show ptrdeclr) $ return ()
259 let btyp = HS.TyCon () typname 262 let btyp = HS.TyCon () typname
@@ -462,7 +465,7 @@ c2haskell opts cs cmodname missings incs (CTranslUnit edecls _) = do
462 (ext,_:rname) -> reverse rname 465 (ext,_:rname) -> reverse rname
463 (rname,_) -> reverse rname 466 (rname,_) -> reverse rname
464 modname = capitalize $ basename cmodname 467 modname = capitalize $ basename cmodname
465 stubsname = "MonkeyPatch/t_stubs.c" -- todo 468 stubsname = "MonkeyPatch/" ++ modname ++ "_patch.c"
466 putStrLn $ "writing " ++ fname 469 putStrLn $ "writing " ++ fname
467 withFile fname WriteMode $ \haskmod -> do 470 withFile fname WriteMode $ \haskmod -> do
468 hPutStrLn haskmod $ "module MonkeyPatch." ++ modname ++" where" 471 hPutStrLn haskmod $ "module MonkeyPatch." ++ modname ++" where"
@@ -485,12 +488,12 @@ c2haskell opts cs cmodname missings incs (CTranslUnit edecls _) = do
485 hPutStrLn haskmod $ "data " ++ t 488 hPutStrLn haskmod $ "data " ++ t
486 forM_ sigs $ \(_,(k,hs,d)) -> do 489 forM_ sigs $ \(_,(k,hs,d)) -> do
487 forM_ hs $ \hdecl -> do 490 forM_ hs $ \hdecl -> do
491 {-
488 hPutStr haskmod (commented k) 492 hPutStr haskmod (commented k)
489 hPutStr haskmod (commented $ show $ pretty d) 493 hPutStr haskmod (commented $ show $ pretty d)
490 hPutStr haskmod (commented $ show $ getReturnValue d) 494 hPutStr haskmod (commented $ show $ getReturnValue d)
491 hPutStr haskmod (commented $ show hdecl) 495 hPutStr haskmod (commented $ show hdecl)
492 -- hPutStr haskmod $ commented $ show $ length $ symbolSource si 496 -- hPutStr haskmod $ commented $ show $ length $ symbolSource si
493 {-
494 forM_ (take 1 $ symbolSource si) $ \d -> do 497 forM_ (take 1 $ symbolSource si) $ \d -> do
495 let ts = filter notKnown $ map tname $ pointers $ concatMap types $ sigf hsTransSig d 498 let ts = filter notKnown $ map tname $ pointers $ concatMap types $ sigf hsTransSig d
496 -- putStr $ commented (ppShow (fmap (const ()) d)) 499 -- putStr $ commented (ppShow (fmap (const ()) d))