-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A Library and Preprocessor that makes it easier to create shared libs from Haskell programs. -- -- The supplied PreProcessor can be run over any existing source and -- would generate FFI code for every function marked to be exported by -- the special notation documented inside the package. It then proceeds -- to compile this generated code into a windows DLL. -- -- The Library contains some helper code that's commonly needed to -- convert between types, and contains the code for the typeclasses the -- PreProcessor uses in the generated code to keep things clean. -- -- It will always generated the required C types for use when calling the -- dll, but it will also generate the C# unsafe code if requested. -- -- Read http:blog.zhox.com/hs2lib.pdf (not published yet) -- -- Current Restrictions: -- -- @package Hs2lib @version 0.4.8 -- | Module containing types and enums for misc instances, for commonly -- used datatypes like Maybe, Either etc module WinDll.Lib.InstancesTypes maybenothing :: Int maybejust :: Int eitherright :: Int eitherleft :: Int type MaybePtr a = Ptr (Maybe a) type EitherPtr a b = Ptr (Either a b) -- | This module contains the lookup values to do type conversions. These -- lists are the basic, build-in predefined lists. module WinDll.Lib.Native type Defs = [(String, String)] -- | List containing mapping to C/C++ Types nativeLisths2c :: [(String, String)] -- | Contains a list of mapping types. This is the first list to be -- extended by the pragmas We need to preserve the Haskell type name for -- later transformations and for FFI nativeConvList :: [(String, String)] -- | List of type conversion from C/C++ to C# types nativeC2cslist :: [(String, String)] -- | List containing mapping to C# Types nativeCslist :: Bool -> [(String, String)] -- | List containing mapping to CSizes nativeC_sizes :: [(String, Int)] -- | Types used when describing structures in WinDll module WinDll.Structs.Types type Name = String type Import = String type ExportName = String type Type = Type type TypeName = String type TypeNames = [TypeName] type NamedTypes = [(Name, Type)] type AnnNamedTypes = [AnnType] type Types = [Type] -- | Annotation on functions, This allows more complex types to be -- expressed data Ann Ann :: [Int] -> Bool -> [Int] -> [(String, String)] -> [(String, String)] -> [(String, Int)] -> (Bool -> [(String, String)]) -> Ann -- | Offsets into the type list to indicate which fields are counters for -- lists annArrayIndices :: Ann -> [Int] -- | Indicates if the field type is a List type. annArrayIsList :: Ann -> Bool -- | Indices/Offsets to indicate whether this function has any StablePtr -- values annStableIndices :: Ann -> [Int] -- | Copy of the definition list for the Haskell translation functions annWorkingSet :: Ann -> [(String, String)] -- | Copy of the definition list for the C translation functions annWorkingSetC :: Ann -> [(String, String)] -- | Copy of the definition list for the C sizes translation functions annWorkingSetCSize :: Ann -> [(String, Int)] -- | Copy of the definition list for the C# translation functions annWorkingSetCs :: Ann -> Bool -> [(String, String)] -- | Annotated type, basically a 4-tuple that holds all possible -- information on a datatype field data AnnType AnnType :: Name -> Type -> Ann -> Type -> AnnType -- | The field name, if this is a record the name will be the record name. antName :: AnnType -> Name -- | The preprocessed type of the field antType :: AnnType -> Type -- | The type annotations for the antType antAnn :: AnnType -> Ann -- | The original unpreprocessed type antOrigType :: AnnType -> Type -- | Generic empty annotation noAnn :: Ann -- | Find any Names embedded within any arbitraty structures findStrings' :: Data a => a -> [String] instance Typeable Ann instance Typeable AnnType instance Show Ann instance Eq Ann instance Data Ann instance Show AnnType instance Eq AnnType instance Data AnnType instance Show (Bool -> [(String, String)]) instance Eq (Bool -> [(String, String)]) instance Monoid Ann -- | Contains the list of native types and their mapping to their -- equivalent FFI types module WinDll.Lib.NativeMapping -- | 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 LLD m a b c | b -> c lld :: LLD m a b c => m a b -> m a c -- | A class that manages the conversion between the normal and type -- supported by ffi. Minimal implementation requires atleast one of the -- pair toNativetoFFI and fromNativefromFFI. 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. class FFIType phi ix toFFI :: FFIType phi ix => phi -> ix fromFFI :: FFIType phi ix => ix -> phi fromList :: FFIType phi ix => CInt -> ix -> IO phi fromNative :: FFIType phi ix => ix -> IO phi toNative :: FFIType phi ix => phi -> IO ix freeFFI :: FFIType phi ix => phi -> ix -> IO () -- | 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) translate :: Defs -> Type -> Type -- | 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 translatePartial :: Defs -> Type -> Type -- | Check to see if the next type is a Simple type. e.g. A TyVar or TyCon isSimpleType :: Type -> Bool -- | 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. translatePrimitive :: Defs -> Type -> Type -- | 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. translateP :: Defs -> String -> String -- | Translate Partial Form, This is basically translatePrimitive . -- translatePartial translatePForm :: Defs -> Type -> Type -- | 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. translate' :: Defs -> String -> String -- | Remove all spaces from a sentence trim :: String -> String -- | A function to split a list of elements by the given seperator split :: Eq a => [a] -> a -> [[a]] instance [incoherent] FFIType Char CWchar instance [incoherent] FFIType Rational CDouble instance [incoherent] FFIType Char CChar instance [incoherent] (Functor f, FFIType a b) => FFIType (f a) (f b) instance [incoherent] (Num a, Integral a) => FFIType Integer a instance [incoherent] Storable a => Storable [a] instance [incoherent] (FFIType a b, Storable b) => FFIType [a] (Ptr CInt -> IO (Ptr b)) instance [incoherent] Storable a => FFIType [a] (Ptr a) instance [incoherent] Storable a => FFIType a (Ptr a) instance [incoherent] FFIType Float CFloat instance [incoherent] FFIType Int CInt instance [incoherent] FFIType FastString CWString instance [incoherent] FFIType CLLong CLLong instance [incoherent] FFIType CDouble CDouble instance [incoherent] FFIType CInt CInt instance [incoherent] FFIType CWString CWString instance [incoherent] FFIType CWchar CWchar instance [incoherent] (Storable a, FFIType b a) => FFIType [b] (Ptr a) instance [incoherent] FFIType String CWString instance [incoherent] (FFIType a b, FFIType c d) => FFIType (a -> c) (b -> d) instance [incoherent] FFIType (FunPtr a) (FunPtr a) instance [incoherent] FFIType (StablePtr a) (StablePtr a) instance [incoherent] FFIType Bool Int8 instance [incoherent] FFIType Bool Word8 instance [incoherent] FFIType Bool CInt instance [incoherent] FFIType Bool Bool instance [incoherent] FFIType () () instance [incoherent] LLD (->) a b (IO b) -- | Module containing definitions for tuples, since those can't be -- automatically translated. We This file contains predefined mappings of -- tuples till 8-tuples. If you need more you need to unfortunately add -- these yourself module WinDll.Lib.Tuples data Tuple2 a b Tuple2 :: a -> b -> Tuple2 a b data Tuple3 a b c Tuple3 :: a -> b -> c -> Tuple3 a b c data Tuple4 a b c d Tuple4 :: a -> b -> c -> d -> Tuple4 a b c d data Tuple5 a b c d e Tuple5 :: a -> b -> c -> d -> e -> Tuple5 a b c d e data Tuple6 a b c d e f Tuple6 :: a -> b -> c -> d -> e -> f -> Tuple6 a b c d e f data Tuple7 a b c d e f g Tuple7 :: a -> b -> c -> d -> e -> f -> g -> Tuple7 a b c d e f g data Tuple8 a b c d e f g h Tuple8 :: a -> b -> c -> d -> e -> f -> g -> h -> Tuple8 a b c d e f g h type Tuple2Ptr a b = Ptr (Tuple2 a b) type Tuple3Ptr a b c = Ptr (Tuple3 a b c) type Tuple4Ptr a b c d = Ptr (Tuple4 a b c d) type Tuple5Ptr a b c d e = Ptr (Tuple5 a b c d e) type Tuple6Ptr a b c d e f = Ptr (Tuple6 a b c d e f) type Tuple7Ptr a b c d e f g = Ptr (Tuple7 a b c d e f g) type Tuple8Ptr a b c d e f g h = Ptr (Tuple8 a b c d e f g h) instance (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f, Storable g, Storable h) => Storable (a, b, c, d, e, f, g, h) instance (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f, Storable g) => Storable (a, b, c, d, e, f, g) instance (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f) => Storable (a, b, c, d, e, f) instance (Storable a, Storable b, Storable c, Storable d, Storable e) => Storable (a, b, c, d, e) instance (Storable a, Storable b, Storable c, Storable d) => Storable (a, b, c, d) instance (Storable a, Storable b, Storable c) => Storable (a, b, c) instance (Storable a, Storable b) => Storable (a, b) instance (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f, Storable g, Storable h) => Storable (Tuple8 a b c d e f g h) instance (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f, Storable g) => Storable (Tuple7 a b c d e f g) instance (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f) => Storable (Tuple6 a b c d e f) instance (Storable a, Storable b, Storable c, Storable d, Storable e) => Storable (Tuple5 a b c d e) instance (Storable a, Storable b, Storable c, Storable d) => Storable (Tuple4 a b c d) instance (Storable a, Storable b, Storable c) => Storable (Tuple3 a b c) instance (Storable a, Storable b) => Storable (Tuple2 a b) instance (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) instance (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) instance (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) instance (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) instance (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) instance (FFIType a b, FFIType c d, FFIType e f, Storable b, Storable d, Storable f) => FFIType (a, c, e) (Tuple3Ptr b d f) instance (FFIType a b, FFIType c d, Storable b, Storable d) => FFIType (a, c) (Tuple2Ptr b d) instance (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) instance (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) instance (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) instance (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) instance (FFIType a b, FFIType c d, FFIType e f, FFIType g h) => FFIType (a, c, e, g) (Tuple4 b d f h) instance (FFIType a b, FFIType c d, FFIType e f) => FFIType (a, c, e) (Tuple3 b d f) instance (FFIType a b, FFIType c d) => FFIType (a, c) (Tuple2 b d) instance Storable a => Functor (Tuple8 a b c d e f g) instance Storable a => Functor (Tuple7 a b c d e f) instance Storable a => Functor (Tuple6 a b c d e) instance Storable a => Functor (Tuple5 a b c d) instance Storable a => Functor (Tuple4 a b c) instance Storable a => Functor (Tuple3 a b) instance Storable a => Functor (Tuple2 a) -- | This module handles generically the convertion from and to native -- types module WinDll.Lib.Converter