fficxx-runtime 0.1 → 0.2
raw patch · 2 files changed
+77/−2 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ FFICXX.Runtime.Cast: class FunPtrWrappable a where type family FunPtrHsType a :: * type family FunPtrType a :: * data family FunPtrWrapped a :: *
+ FFICXX.Runtime.Cast: class IsCType a
+ FFICXX.Runtime.Cast: class IsRawType a
+ FFICXX.Runtime.Cast: fptrWrap :: FunPtrWrappable a => FunPtrWrapped a -> IO (FunPtr (FunPtrType a))
+ FFICXX.Runtime.Cast: instance Castable (Ptr CChar) (Ptr CChar)
+ FFICXX.Runtime.Cast: instance Castable (Ptr CDouble) (Ptr CDouble)
+ FFICXX.Runtime.Cast: instance Castable (Ptr CInt) (Ptr CInt)
+ FFICXX.Runtime.Cast: instance Castable (Ptr CLong) (Ptr CLong)
+ FFICXX.Runtime.Cast: instance Castable (Ptr CString) (Ptr CString)
+ FFICXX.Runtime.Cast: instance Castable (Ptr CUInt) (Ptr CUInt)
+ FFICXX.Runtime.Cast: instance Castable (Ptr CULong) (Ptr CULong)
+ FFICXX.Runtime.Cast: instance Castable CDouble CDouble
+ FFICXX.Runtime.Cast: instance Castable CInt CInt
+ FFICXX.Runtime.Cast: instance Castable CLong CLong
+ FFICXX.Runtime.Cast: instance Castable CUInt CUInt
+ FFICXX.Runtime.Cast: instance Castable CULong CULong
+ FFICXX.Runtime.Cast: instance Castable Word8 CChar
+ FFICXX.Runtime.Cast: instance IsCType CChar
+ FFICXX.Runtime.Cast: instance IsCType CInt
+ FFICXX.Runtime.Cast: instance IsCType CLong
+ FFICXX.Runtime.Cast: instance IsCType CString
+ FFICXX.Runtime.Cast: instance IsCType CUInt
+ FFICXX.Runtime.Cast: instance IsCType CULong
+ FFICXX.Runtime.Cast: wrap :: FunPtrWrappable a => FunPtrHsType a -> FunPtrWrapped a
Files
- fficxx-runtime.cabal +1/−1
- lib/FFICXX/Runtime/Cast.hs +76/−1
fficxx-runtime.cabal view
@@ -1,5 +1,5 @@ Name: fficxx-runtime-Version: 0.1+Version: 0.2 Synopsis: Runtime for fficxx-generated library Description: Runtime for fficxx-generated library License: BSD3
lib/FFICXX/Runtime/Cast.hs view
@@ -3,6 +3,7 @@ EmptyDataDecls, ExistentialQuantification, ScopedTypeVariables, GADTs #-} + ----------------------------------------------------------------------------- -- | -- Module : FFICXX.Runtime.Cast@@ -25,6 +26,8 @@ import System.IO.Unsafe +class IsRawType a + class Castable a b where cast :: a -> b uncast :: b -> a @@ -34,6 +37,14 @@ get_fptr :: a -> ForeignPtr (Raw a) cast_fptr_to_obj :: ForeignPtr (Raw a) -> a ++class FunPtrWrappable a where+ type FunPtrHsType a :: *+ type FunPtrType a :: *+ data FunPtrWrapped a :: * + fptrWrap :: FunPtrWrapped a -> IO (FunPtr (FunPtrType a)) + wrap :: FunPtrHsType a -> FunPtrWrapped a + class Existable a where data Exist a :: * @@ -43,11 +54,18 @@ data GADTType a :: * -> * data EGADTType a :: * +class IsCType a where +instance IsCType CChar+instance IsCType CInt+instance IsCType CUInt +instance IsCType CString +instance IsCType CULong +instance IsCType CLong +-- cause incoherent instances but cannot avoid it now {---- eliminate this for the time being to have a solution with Repl instance Castable a a where cast = id uncast = id@@ -57,6 +75,58 @@ cast = id uncast = id ++instance Castable CDouble CDouble where+ cast = id+ uncast = id++++instance Castable CUInt CUInt where+ cast = id + uncast = id ++instance Castable CInt CInt where + cast = id + uncast = id ++instance Castable CLong CLong where+ cast = id+ uncast = id++instance Castable CULong CULong where + cast = id + uncast = id +++instance Castable (Ptr CInt) (Ptr CInt) where + cast = id + uncast = id ++instance Castable (Ptr CChar) (Ptr CChar) where + cast = id + uncast = id ++instance Castable (Ptr CUInt) (Ptr CUInt) where + cast = id + uncast = id ++instance Castable (Ptr CULong) (Ptr CULong) where + cast = id + uncast = id ++instance Castable (Ptr CLong) (Ptr CLong) where + cast = id + uncast = id ++instance Castable (Ptr CDouble) (Ptr CDouble) where + cast = id + uncast = id ++instance Castable (Ptr CString) (Ptr CString) where + cast = id + uncast = id + instance Castable Int CInt where cast = fromIntegral uncast = fromIntegral@@ -64,6 +134,10 @@ instance Castable Word CUInt where cast = fromIntegral uncast = fromIntegral++instance Castable Word8 CChar where+ cast = fromIntegral + uncast = fromIntegral instance Castable Double CDouble where cast = realToFrac@@ -84,6 +158,7 @@ instance Castable [String] (Ptr CString) where cast xs = unsafePerformIO (mapM newCString xs >>= newArray) uncast _c_xs = undefined+ instance (Castable a a', Castable b b') => Castable (a->b) (a'->b') where cast f = cast . f . uncast