Portability | portable |
---|---|

Stability | experimental |

Maintainer | tamar@zhox.com |

Contains the list of native types and their mapping to their equivalent FFI types

- class LLD m a b c | b -> c where
- lld :: m a b -> m a c

- class FFIType phi ix where
- translate :: Defs -> Type -> Type
- translatePartial :: Defs -> Type -> Type
- isSimpleType :: Type -> Bool
- translatePrimitive :: Defs -> Type -> Type
- translateP :: Defs -> String -> String
- translatePForm :: Defs -> Type -> Type
- translate' :: Defs -> String -> String
- trim :: String -> String
- split :: Eq a => [a] -> a -> [[a]]

# Documentation

class LLD m a b c | b -> c whereSource

Typeclase to allow Left LoaD transform. It is basically to allow a transformation to take place at the last argument/return type of the function. This is because most of the functions are in IO.

class FFIType phi ix whereSource

A class that manages the conversion between the normal and type supported by ffi.
Minimal implementation requires atleast one of the pair toNative*toFFI and fromNative*fromFFI.
The implementation will almost always call fromNative and toNative because all exported functions
are in IO since they all might have side-effects. The only exception to this is for the defaults provided
in this module.

fromList :: CInt -> ix -> IO phiSource

fromNative :: ix -> IO phiSource

FFIType Bool Bool | Numeral values are all also already FFI values, If I've read the documentation correctly Due to GHC matching only the instance heads this instance can't unfortunately be used. (Booo bad GHC) instance Num a => FFIType a a where toFFI = id fromFFI = id Booleans are by default already an FFI value |

FFIType Bool Int8 | Convert booleans to Int8 to save space for use when using the ccall or stdcall conventions |

FFIType Bool Word8 | Convert booleans to Word8 to save space for use when using the ccall or stdcall conventions |

FFIType Bool CInt | Convert booleans to Cints for use when using the ccall or stdcall conventions |

FFIType Char CChar | |

FFIType Char CWchar | |

FFIType Float CFloat | Instance for unboxed integers, which are first boxed then returned instance FFIType FastInt CInt where toFFI = toFFI . iBox fromFFI = iUnbox . fromFFI Fix float instances |

FFIType Int CInt | Fix integers from the machine dependend values to fixed 32bit values |

(Num a, Integral a) => FFIType Integer a | Convertion instance for Integer types to CLLongs (long long) |

FFIType Rational CDouble | |

FFIType String CWString | I decided to use a CAString because on windows this gives me a constant 16 value |

FFIType () () | Default values needed to satisfy .NET marshaller when having unused structures. class FFIType phi ix => FFIDefaults phi ix where class Default phi where nDefault :: phi Wrapper functions for dealing with FunPtrs wrapFn :: (FFIType (IO a) ca, FFIType b (IO cb)) => (a -> IO b) -> (ca -> IO cb) wrapFn fn = fromFFI >=> fn >=> toFFI Dedicated instance for () |

FFIType CWString CWString | Another simple identity instance, I really need to get that overlapping instances looked at. |

FFIType CInt CInt | Another simple identity instance, I really need to get that overlapping instances looked at. |

FFIType CLLong CLLong | Another simple identity instance, I really need to get that overlapping instances looked at. |

FFIType CDouble CDouble | Another simple identity instance, I really need to get that overlapping instances looked at. |

FFIType CWchar CWchar | Another simple identity instance, I really need to get that overlapping instances looked at. |

FFIType FastString CWString | Convert between FastString and CWString |

Storable a => FFIType a (Ptr a) | Any class implementing Storable has implemented enough to be considered a FFIType |

Storable a => FFIType [a] (Ptr a) | Cover lists to array convertion IF the type is also an FFI type |

(Storable a, FFIType b a) => FFIType [b] (Ptr a) | Intermediate conversion instance for storing values of arrays |

FFIType (StablePtr a) (StablePtr a) | A StorablePtr instance |

FFIType (FunPtr a) (FunPtr a) | A FunPtr instance |

(Functor f, FFIType a b) => FFIType (f a) (f b) | Instance for Functor classes |

(FFIType a b, Storable b) => FFIType [a] (Ptr CInt -> IO (Ptr b)) | One way instance for returning lists as the result of a function call. We assume to have an int* as an argument and then fill that in with the length |

(FFIType a b, FFIType c d) => FFIType (a -> c) (b -> d) | Tranform functions to and from the correct types TODO: Update this variant to use the impure variants, This will be an issue.. |

(FFIType a b, FFIType c d, Storable b, Storable d) => FFIType (a, c) (Tuple2Ptr b d) | |

(FFIType a b, FFIType c d) => FFIType (a, c) (Tuple2 b d) | |

(FFIType a b, FFIType c d, FFIType e f, Storable b, Storable d, Storable f) => FFIType (a, c, e) (Tuple3Ptr b d f) | |

(FFIType a b, FFIType c d, FFIType e f) => FFIType (a, c, e) (Tuple3 b d f) | |

(FFIType a b, FFIType c d, FFIType e f, FFIType g h, Storable b, Storable d, Storable f, Storable h) => FFIType (a, c, e, g) (Tuple4Ptr b d f h) | |

(FFIType a b, FFIType c d, FFIType e f, FFIType g h) => FFIType (a, c, e, g) (Tuple4 b d f h) | |

(FFIType a b, FFIType c d, FFIType e f, FFIType g h, FFIType i j, Storable j, Storable b, Storable d, Storable f, Storable h) => FFIType (a, c, e, g, i) (Tuple5Ptr b d f h j) | |

(FFIType a b, FFIType c d, FFIType e f, FFIType g h, FFIType i j) => FFIType (a, c, e, g, i) (Tuple5 b d f h j) | |

(FFIType a b, FFIType c d, FFIType e f, FFIType g h, FFIType i j, FFIType k l, Storable j, Storable l, Storable b, Storable d, Storable f, Storable h) => FFIType (a, c, e, g, i, k) (Tuple6Ptr b d f h j l) | |

(FFIType a b, FFIType c d, FFIType e f, FFIType g h, FFIType i j, FFIType k l) => FFIType (a, c, e, g, i, k) (Tuple6 b d f h j l) | |

(FFIType a b, FFIType c d, FFIType e f, FFIType g h, FFIType i j, FFIType k l, FFIType m n, Storable n, Storable j, Storable l, Storable b, Storable d, Storable f, Storable h) => FFIType (a, c, e, g, i, k, m) (Tuple7Ptr b d f h j l n) | |

(FFIType a b, FFIType c d, FFIType e f, FFIType g h, FFIType i j, FFIType k l, FFIType m n) => FFIType (a, c, e, g, i, k, m) (Tuple7 b d f h j l n) | |

(FFIType a b, FFIType c d, FFIType e f, FFIType g h, FFIType i j, FFIType k l, FFIType m n, FFIType o p, Storable n, Storable p, Storable j, Storable l, Storable b, Storable d, Storable f, Storable h) => FFIType (a, c, e, g, i, k, m, o) (Tuple8Ptr b d f h j l n p) | |

(FFIType a b, FFIType c d, FFIType e f, FFIType g h, FFIType i j, FFIType k l, FFIType m n, FFIType o p) => FFIType (a, c, e, g, i, k, m, o) (Tuple8 b d f h j l n p) |

translate :: Defs -> Type -> TypeSource

Tuples are not FFI compatible, As such i'll translate them to a build in tuple datatype . This function translates the embedded types of a Ty to the correct forms using the function translate' (see below)

translatePartial :: Defs -> Type -> TypeSource

Translate everything but applied types. e.g. Foo Token -> FooPtr Token And lists, since lists are implicitly an applied type: e.g [Token] -->> [] Token -->> Ptr Token

isSimpleType :: Type -> BoolSource

Check to see if the next type is a Simple type. e.g. A TyVar or TyCon

translatePrimitive :: Defs -> Type -> TypeSource

Contrary to translate translatePrimitive will only transform the defined primitive types in the convList below. This is because while a transformed signature should only be partially transformed till the first application (Since that'll be the main pointer) we should pre-transform the primitive types into their well known static forms.

translateP :: Defs -> String -> StringSource

Helper function to define translatePrimitive. It attemps to lookup the type in convList but in the case where it's not found the search query is returned.

translatePForm :: Defs -> Type -> TypeSource

Translate Partial Form, This is basically translatePrimitive . translatePartial

translate' :: Defs -> String -> StringSource

Look up the FFI type representation of the given type. Moreover when the type is not found it is assumed to be a new structure and it is assumed to be a pointer value.