-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Write Haskell source files including C code inline. No FFI required. -- @package inline-c @version 0.5.2.1 -- | A parser for C99 declarations. Currently, the parser has the following -- limitations: -- -- -- -- The parser is incremental and generic (see CParser). -- Pretty and Arbitrary instances are provided for all the -- data types. -- -- The entry point if you want to parse C declarations is -- parameter_declaration. module Language.C.Types.Parse -- | All the parsing is done using the type classes provided by the -- parsers package. You can use the parsing routines with any of -- the parsers that implement the classes, such as parsec or -- trifecta. -- -- The MonadReader with IsTypeName is required for parsing -- C, see http://en.wikipedia.org/wiki/The_lexer_hack. type CParser m = (Monad m, Functor m, Applicative m, MonadPlus m, Parsing m, CharParsing m, TokenParsing m, LookAheadParsing m, MonadReader IsTypeName m) -- | Function used to determine whether an Id is a type name. type IsTypeName = Identifier -> Bool -- | Runs a CParser using parsec. runCParser :: Stream s Identity Char => IsTypeName -> String -> s -> (ReaderT IsTypeName (Parsec s ()) a) -> Either ParseError a -- | Useful for quick testing. Uses "quickCParser" as source name, -- and throws an error if parsing fails. quickCParser :: IsTypeName -> String -> (ReaderT IsTypeName (Parsec String ()) a) -> a -- | Like quickCParser, but uses const False -- as IsTypeName. quickCParser_ :: String -> (ReaderT IsTypeName (Parsec String ()) a) -> a newtype Identifier Identifier :: String -> Identifier unIdentifier :: Identifier -> String identifier :: CParser m => m Identifier -- | This parser parses an Id and nothing else -- it does not -- consume trailing spaces and the like. identifier_no_lex :: CParser m => m Identifier data DeclarationSpecifier StorageClassSpecifier :: StorageClassSpecifier -> DeclarationSpecifier TypeSpecifier :: TypeSpecifier -> DeclarationSpecifier TypeQualifier :: TypeQualifier -> DeclarationSpecifier FunctionSpecifier :: FunctionSpecifier -> DeclarationSpecifier declaration_specifiers :: CParser m => m [DeclarationSpecifier] data StorageClassSpecifier TYPEDEF :: StorageClassSpecifier EXTERN :: StorageClassSpecifier STATIC :: StorageClassSpecifier AUTO :: StorageClassSpecifier REGISTER :: StorageClassSpecifier storage_class_specifier :: CParser m => m StorageClassSpecifier data TypeSpecifier VOID :: TypeSpecifier CHAR :: TypeSpecifier SHORT :: TypeSpecifier INT :: TypeSpecifier LONG :: TypeSpecifier FLOAT :: TypeSpecifier DOUBLE :: TypeSpecifier SIGNED :: TypeSpecifier UNSIGNED :: TypeSpecifier Struct :: Identifier -> TypeSpecifier Enum :: Identifier -> TypeSpecifier TypeName :: Identifier -> TypeSpecifier type_specifier :: CParser m => m TypeSpecifier data TypeQualifier CONST :: TypeQualifier RESTRICT :: TypeQualifier VOLATILE :: TypeQualifier type_qualifier :: CParser m => m TypeQualifier data FunctionSpecifier INLINE :: FunctionSpecifier function_specifier :: CParser m => m FunctionSpecifier data Declarator Declarator :: [Pointer] -> DirectDeclarator -> Declarator declaratorPointers :: Declarator -> [Pointer] declaratorDirect :: Declarator -> DirectDeclarator declarator :: CParser m => m Declarator data DirectDeclarator DeclaratorRoot :: Identifier -> DirectDeclarator ArrayOrProto :: DirectDeclarator -> ArrayOrProto -> DirectDeclarator DeclaratorParens :: Declarator -> DirectDeclarator direct_declarator :: CParser m => m DirectDeclarator data ArrayOrProto Array :: ArrayType -> ArrayOrProto Proto :: [ParameterDeclaration] -> ArrayOrProto array_or_proto :: CParser m => m ArrayOrProto data ArrayType VariablySized :: ArrayType Unsized :: ArrayType SizedByInteger :: Integer -> ArrayType SizedByIdentifier :: Identifier -> ArrayType array_type :: CParser m => m ArrayType data Pointer Pointer :: [TypeQualifier] -> Pointer pointer :: CParser m => m Pointer data ParameterDeclaration ParameterDeclaration :: [DeclarationSpecifier] -> Either Declarator AbstractDeclarator -> ParameterDeclaration parameterDeclarationSpecifiers :: ParameterDeclaration -> [DeclarationSpecifier] parameterDeclarationDeclarator :: ParameterDeclaration -> Either Declarator AbstractDeclarator parameter_declaration :: CParser m => m ParameterDeclaration parameter_list :: CParser m => m [ParameterDeclaration] data AbstractDeclarator AbstractDeclarator :: [Pointer] -> Maybe DirectAbstractDeclarator -> AbstractDeclarator abstractDeclaratorPointers :: AbstractDeclarator -> [Pointer] abstractDeclaratorDirect :: AbstractDeclarator -> Maybe DirectAbstractDeclarator abstract_declarator :: CParser m => m AbstractDeclarator data DirectAbstractDeclarator ArrayOrProtoHere :: ArrayOrProto -> DirectAbstractDeclarator ArrayOrProtoThere :: DirectAbstractDeclarator -> ArrayOrProto -> DirectAbstractDeclarator AbstractDeclaratorParens :: AbstractDeclarator -> DirectAbstractDeclarator direct_abstract_declarator :: CParser m => m DirectAbstractDeclarator -- | Type used to generate an Arbitrary ParameterDeclaration -- with arbitrary allowed type names. data ParameterDeclarationWithTypeNames ParameterDeclarationWithTypeNames :: Set Identifier -> ParameterDeclaration -> ParameterDeclarationWithTypeNames pdwtnTypeNames :: ParameterDeclarationWithTypeNames -> Set Identifier pdwtnParameterDeclaration :: ParameterDeclarationWithTypeNames -> ParameterDeclaration instance Typeable Identifier instance Typeable StorageClassSpecifier instance Typeable TypeSpecifier instance Typeable TypeQualifier instance Typeable FunctionSpecifier instance Typeable DeclarationSpecifier instance Typeable ArrayType instance Typeable Pointer instance Typeable DirectAbstractDeclarator instance Typeable AbstractDeclarator instance Typeable ArrayOrProto instance Typeable ParameterDeclaration instance Typeable Declarator instance Typeable DirectDeclarator instance Typeable OneOfSized instance Typeable ParameterDeclarationWithTypeNames instance Eq Identifier instance Ord Identifier instance Show Identifier instance Eq StorageClassSpecifier instance Show StorageClassSpecifier instance Eq TypeSpecifier instance Show TypeSpecifier instance Eq TypeQualifier instance Show TypeQualifier instance Eq FunctionSpecifier instance Show FunctionSpecifier instance Eq DeclarationSpecifier instance Show DeclarationSpecifier instance Eq ArrayType instance Show ArrayType instance Eq Pointer instance Show Pointer instance Eq DirectAbstractDeclarator instance Show DirectAbstractDeclarator instance Eq AbstractDeclarator instance Show AbstractDeclarator instance Eq ArrayOrProto instance Show ArrayOrProto instance Eq ParameterDeclaration instance Show ParameterDeclaration instance Eq Declarator instance Show Declarator instance Eq DirectDeclarator instance Show DirectDeclarator instance Eq a => Eq (OneOfSized a) instance Show a => Show (OneOfSized a) instance Eq ParameterDeclarationWithTypeNames instance Show ParameterDeclarationWithTypeNames instance Arbitrary Pointer instance Arbitrary FunctionSpecifier instance Arbitrary TypeQualifier instance Arbitrary StorageClassSpecifier instance Arbitrary ParameterDeclarationWithTypeNames instance Pretty DirectAbstractDeclarator instance Pretty AbstractDeclarator instance Pretty ParameterDeclaration instance Pretty ArrayType instance Pretty ArrayOrProto instance Pretty DirectDeclarator instance Pretty Pointer instance Pretty Declarator instance Pretty FunctionSpecifier instance Pretty TypeQualifier instance Pretty TypeSpecifier instance Pretty StorageClassSpecifier instance Pretty DeclarationSpecifier instance Pretty Identifier instance IsString Identifier -- | Views of C datatypes. While Language.C.Types.Parse defines -- datatypes for representing the concrete syntax tree of C types, this -- module provides friendlier views of C types, by turning them into a -- data type matching more closely how we read and think about types, -- both in Haskell and in C. To appreciate the difference, look at the -- difference between ParameterDeclaration and -- ParameterDeclaration. -- -- As a bonus, routines are provided for describing types in natural -- language (English) -- see describeParameterDeclaration and -- describeType. module Language.C.Types newtype Identifier Identifier :: String -> Identifier unIdentifier :: Identifier -> String data StorageClassSpecifier TYPEDEF :: StorageClassSpecifier EXTERN :: StorageClassSpecifier STATIC :: StorageClassSpecifier AUTO :: StorageClassSpecifier REGISTER :: StorageClassSpecifier data TypeQualifier CONST :: TypeQualifier RESTRICT :: TypeQualifier VOLATILE :: TypeQualifier data FunctionSpecifier INLINE :: FunctionSpecifier data ArrayType VariablySized :: ArrayType Unsized :: ArrayType SizedByInteger :: Integer -> ArrayType SizedByIdentifier :: Identifier -> ArrayType data Specifiers Specifiers :: [StorageClassSpecifier] -> [TypeQualifier] -> [FunctionSpecifier] -> Specifiers storageClassSpecifiers :: Specifiers -> [StorageClassSpecifier] typeQualifiers :: Specifiers -> [TypeQualifier] functionSpecifiers :: Specifiers -> [FunctionSpecifier] data Type TypeSpecifier :: Specifiers -> TypeSpecifier -> Type Ptr :: [TypeQualifier] -> Type -> Type Array :: ArrayType -> Type -> Type Proto :: Type -> [ParameterDeclaration] -> Type data TypeSpecifier Void :: TypeSpecifier Char :: (Maybe Sign) -> TypeSpecifier Short :: Sign -> TypeSpecifier Int :: Sign -> TypeSpecifier Long :: Sign -> TypeSpecifier LLong :: Sign -> TypeSpecifier Float :: TypeSpecifier Double :: TypeSpecifier LDouble :: TypeSpecifier TypeName :: Identifier -> TypeSpecifier Struct :: Identifier -> TypeSpecifier Enum :: Identifier -> TypeSpecifier data Sign Signed :: Sign Unsigned :: Sign data ParameterDeclaration ParameterDeclaration :: Maybe Identifier -> Type -> ParameterDeclaration parameterDeclarationId :: ParameterDeclaration -> Maybe Identifier parameterDeclarationType :: ParameterDeclaration -> Type -- | Function used to determine whether an Id is a type name. type IsTypeName = Identifier -> Bool -- | All the parsing is done using the type classes provided by the -- parsers package. You can use the parsing routines with any of -- the parsers that implement the classes, such as parsec or -- trifecta. -- -- The MonadReader with IsTypeName is required for parsing -- C, see http://en.wikipedia.org/wiki/The_lexer_hack. type CParser m = (Monad m, Functor m, Applicative m, MonadPlus m, Parsing m, CharParsing m, TokenParsing m, LookAheadParsing m, MonadReader IsTypeName m) -- | Runs a CParser using parsec. runCParser :: Stream s Identity Char => IsTypeName -> String -> s -> (ReaderT IsTypeName (Parsec s ()) a) -> Either ParseError a -- | Useful for quick testing. Uses "quickCParser" as source name, -- and throws an error if parsing fails. quickCParser :: IsTypeName -> String -> (ReaderT IsTypeName (Parsec String ()) a) -> a -- | Like quickCParser, but uses const False -- as IsTypeName. quickCParser_ :: String -> (ReaderT IsTypeName (Parsec String ()) a) -> a parseParameterDeclaration :: CParser m => m ParameterDeclaration parseParameterList :: CParser m => m [ParameterDeclaration] parseIdentifier :: CParser m => m Identifier parseType :: CParser m => m Type data UntangleErr MultipleDataTypes :: [DeclarationSpecifier] -> UntangleErr NoDataTypes :: [DeclarationSpecifier] -> UntangleErr IllegalSpecifiers :: String -> [TypeSpecifier] -> UntangleErr untangleParameterDeclaration :: ParameterDeclaration -> Either UntangleErr ParameterDeclaration tangleParameterDeclaration :: ParameterDeclaration -> ParameterDeclaration describeParameterDeclaration :: ParameterDeclaration -> Doc describeType :: Type -> Doc instance Typeable Specifiers instance Typeable Sign instance Typeable TypeSpecifier instance Typeable ParameterDeclaration instance Typeable Type instance Typeable UntangleErr instance Show Specifiers instance Eq Specifiers instance Show Sign instance Eq Sign instance Ord Sign instance Show TypeSpecifier instance Eq TypeSpecifier instance Ord TypeSpecifier instance Show ParameterDeclaration instance Eq ParameterDeclaration instance Show Type instance Eq Type instance Show UntangleErr instance Eq UntangleErr instance Pretty Type instance Pretty ParameterDeclaration instance Pretty UntangleErr instance Pretty TypeSpecifier instance Monoid Specifiers -- | A Context is used to define the capabilities of the Template -- Haskell code that handles the inline C code. See the documentation of -- the data type for more details. -- -- In practice, a Context will have to be defined for each library -- that defines new C types, to allow the TemplateHaskell code to -- interpret said types correctly. module Language.C.Inline.Context -- | A mapping from TypeSpecifiers to Haskell types. Needed both to -- parse C types, and to convert them to Haskell types. type TypesTable = Map TypeSpecifier TypeQ -- | A data type to indicate whether the user requested pure or IO function -- from Haskell data Purity Pure :: Purity IO :: Purity -- | Given a Context, it uses its ctxTypesTable to convert -- arbitrary C types. convertType :: Purity -> TypesTable -> Type -> Q (Maybe Type) -- | An alias for Ptr. type CArray = Ptr isTypeName :: TypesTable -> Identifier -> Bool -- | Specifies how to parse and process an antiquotation in the C code. -- -- All antiquotations (apart from plain variable capture) have syntax -- --
--   $XXX:YYY
--   
-- -- Where XXX is the name of the antiquoter and YYY is -- something parseable by the respective aqParser. data AntiQuoter a AntiQuoter :: (forall m. CParser m => m (String, Type, a)) -> (Purity -> TypesTable -> Type -> a -> Q (Type, Exp)) -> AntiQuoter a -- | Parses the body of the antiquotation, returning a hint for the name to -- assign to the variable that will replace the anti-quotation, the type -- of said variable, and some arbitrary data which will then be fed to -- aqMarshaller. aqParser :: AntiQuoter a -> forall m. CParser m => m (String, Type, a) -- | Takes the requested purity, the current TypesTable, and the -- type and the body returned by aqParser. -- -- Returns the Haskell type for the parameter, and the Haskell expression -- that will be passed in as the parameter. -- -- If the the type returned is ty, the Exp must -- have type forall a. (ty -> IO a) -> IO a. This allows -- to do resource handling when preparing C values. -- -- Care must be taken regarding Purity. Specifically, the -- generated IO computation must be idempotent to guarantee its safety -- when used in pure code. We cannot prevent the IO computation from -- being inlined, hence potentially duplicated. If non-idempotent -- marshallers are required (e.g. if an update to some global state is -- needed), it is best to throw an error when Purity is -- Pure (for example "you cannot use context X with -- pure"), which will show up at compile time. aqMarshaller :: AntiQuoter a -> Purity -> TypesTable -> Type -> a -> Q (Type, Exp) -- | An identifier for a AntiQuoter. type AntiQuoterId = String -- | Existential wrapper around AntiQuoter. data SomeAntiQuoter SomeAntiQuoter :: (AntiQuoter a) -> SomeAntiQuoter type AntiQuoters = Map AntiQuoterId SomeAntiQuoter -- | A Context stores various information needed to produce the -- files with the C code derived from the inline C snippets. -- -- Contexts can be composed with their Monoid instance, -- where mappend is right-biased -- in mappend x y -- y will take precedence over x. data Context Context :: TypesTable -> AntiQuoters -> Maybe String -> Maybe (String -> String) -> Context -- | Needed to convert C types to Haskell types. ctxTypesTable :: Context -> TypesTable -- | Needed to parse and process antiquotations. ctxAntiQuoters :: Context -> AntiQuoters -- | Will determine the extension of the file containing the inline C -- snippets. ctxFileExtension :: Context -> Maybe String -- | This function is used to post-process the functions generated from the -- C snippets. Currently just used to specify C linkage when generating -- C++ code. ctxOutput :: Context -> Maybe (String -> String) -- | Context useful to work with vanilla C. Used by default. -- -- ctxTypesTable: converts C basic types to their counterparts in -- Foreign.C.Types. -- -- No ctxAntiQuoters. baseCtx :: Context -- | This Context includes a AntiQuoter that removes the need -- for explicitely creating FunPtrs, named "fun". -- -- For example, we can capture function f of type CInt -> -- CInt -> IO CInt in C code using $fun:(int (*f)(int, -- int)). -- -- When used in a pure embedding, the Haskell function will have -- to be pure too. Continuing the example above we'll have CInt -> -- CInt -> IO CInt. -- -- Does not include the baseCtx, since most of the time it's going -- to be included as part of larger contexts. funCtx :: Context -- | This Context includes two AntiQuoters that allow to -- easily use Haskell vectors in C. -- -- Specifically, the vec-len and vec-ptr will get the -- length and the pointer underlying mutable (IOVector) and -- immutable (Vector) storable vectors. -- -- Note that if you use vecCtx to manipulate immutable vectors you -- must make sure that the vector is not modified in the C code. -- -- To use vec-len, simply write $vec-len:x, where -- x is something of type IOVector a or -- Vector a, for some a. To use vec-ptr -- you need to specify the type of the pointer, e.g. $vec-len:(int -- *x) will work if x has type IOVector -- CInt. vecCtx :: Context -- | Type class used to implement the anti-quoters in vecCtx. class VecCtx a where type family VecCtxScalar a :: * vecCtxLength :: VecCtx a => a -> Int vecCtxUnsafeWith :: VecCtx a => a -> (Ptr (VecCtxScalar a) -> IO b) -> IO b -- | bsCtx serves exactly the same purpose as vecCtx, but -- only for ByteString. vec-ptr becomes bs-ptr, -- and vec-len becomes bs-len. You don't need to -- specify the type of the pointer in bs-ptr, it will always be -- unsigned char*. bsCtx :: Context instance Eq Purity instance Show Purity instance Storable a => VecCtx (IOVector a) instance Storable a => VecCtx (Vector a) instance Monoid Context module Language.C.Inline.Internal -- | Sets the Context for the current module. This function, if -- called, must be called before any of the other TH functions in this -- module. Fails if that's not the case. setContext :: Context -> Q () -- | Gets the current Context. Also makes sure that the current -- module is initialised. getContext :: Q Context -- | Simply appends some string to the module's C file. Use with care. emitVerbatim :: String -> DecsQ -- | Data type representing a list of C definitions with a typed and named -- entry function. -- -- We use it as a basis to inline and call C code. data Code Code :: Safety -> TypeQ -> String -> String -> Code -- | Safety of the foreign call. codeCallSafety :: Code -> Safety -- | Type of the foreign call. codeType :: Code -> TypeQ -- | Name of the function to call in the code below. codeFunName :: Code -> String -- | The C code. codeDefs :: Code -> String -- | Inlines a piece of code inline. The resulting Exp will have the -- type specified in the codeType. -- -- In practice, this function outputs the C code to the module's C file, -- and then inserts a foreign call of type codeType calling the -- provided codeFunName. -- -- Example: -- --
--   c_add :: Int -> Int -> Int
--   c_add = $(inlineCode $ Code
--     TH.Unsafe                   -- Call safety
--     [t| Int -> Int -> Int |]    -- Call type
--     "francescos_add"            -- Call name
--     -- C Code
--     "int francescos_add(int x, int y) { int z = x + y; return z; }")
--   
inlineCode :: Code -> ExpQ -- | Same as inlineCItems, but with a single expression. -- --
--   c_cos :: Double -> Double
--   c_cos = $(inlineExp
--     TH.Unsafe
--     [t| Double -> Double |]
--     (quickCParser_ "double" parseType)
--     [("x", quickCParser_ "double") parseType]
--     "cos(x)")
--   
inlineExp :: Safety -> TypeQ -> Type -> [(Identifier, Type)] -> String -> ExpQ -- | Same as inlineCode, but accepts a string containing a list of C -- statements instead instead than a full-blown Code. A function -- containing the provided statement will be automatically generated. -- --
--   c_cos :: Double -> Double
--   c_cos = $(inlineItems
--     TH.Unsafe
--     [t| Double -> Double |]
--     (quickCParser_ "double" parseType)
--     [("x", quickCParser_ "double" parseType)]
--     "return cos(x);")
--   
inlineItems :: Safety -> TypeQ -> Type -> [(Identifier, Type)] -> String -> ExpQ data SomeEq toSomeEq :: (Eq a, Typeable a) => a -> SomeEq fromSomeEq :: (Eq a, Typeable a) => SomeEq -> Maybe a data ParameterType Plain :: String -> ParameterType AntiQuote :: AntiQuoterId -> SomeEq -> ParameterType data ParseTypedC ParseTypedC :: Type -> [(Identifier, Type, ParameterType)] -> String -> ParseTypedC ptcReturnType :: ParseTypedC -> Type ptcParameters :: ParseTypedC -> [(Identifier, Type, ParameterType)] ptcBody :: ParseTypedC -> String parseTypedC :: CParser m => AntiQuoters -> m ParseTypedC runParserInQ :: String -> IsTypeName -> (forall m. CParser m => m a) -> Q a genericQuote :: Purity -> (TypeQ -> Type -> [(Identifier, Type)] -> String -> ExpQ) -> QuasiQuoter instance Show ParameterType instance Eq ParameterType instance Show SomeEq instance Eq SomeEq -- | unsafe variants of the Language.C.Inline -- quasi-quoters, to call the C code unsafely in the sense of -- https://www.haskell.org/onlinereport/haskell2010/haskellch8.html#x15-1590008.4.3. -- In GHC, unsafe foreign calls are faster than safe foreign calls, but -- the user must guarantee the control flow will never enter Haskell code -- (via a callback or otherwise) before the call is done. -- -- This module is intended to be imported qualified: -- --
--   import qualified Language.C.Inline.Unsafe as CU
--   
module Language.C.Inline.Unsafe -- | C expressions. exp :: QuasiQuoter -- | Variant of exp, for use with expressions known to have no side -- effects. -- -- BEWARE: use this function with caution, only when you know what you -- are doing. If an expression does in fact have side-effects, then -- indiscriminate use of pure may endanger referential -- transparency, and in principle even type safety. pure :: QuasiQuoter -- | C code blocks (i.e. statements). block :: QuasiQuoter -- | Enable painless embedding of C code in Haskell code. If you're -- interested in how to use the library, skip to the "Inline C" section. -- To build, read the first two sections. -- -- This module is intended to be imported qualified: -- --
--   import qualified Language.C.Inline as C
--   
module Language.C.Inline -- | A Context stores various information needed to produce the -- files with the C code derived from the inline C snippets. -- -- Contexts can be composed with their Monoid instance, -- where mappend is right-biased -- in mappend x y -- y will take precedence over x. data Context -- | Context useful to work with vanilla C. Used by default. -- -- ctxTypesTable: converts C basic types to their counterparts in -- Foreign.C.Types. -- -- No ctxAntiQuoters. baseCtx :: Context -- | This Context includes a AntiQuoter that removes the need -- for explicitely creating FunPtrs, named "fun". -- -- For example, we can capture function f of type CInt -> -- CInt -> IO CInt in C code using $fun:(int (*f)(int, -- int)). -- -- When used in a pure embedding, the Haskell function will have -- to be pure too. Continuing the example above we'll have CInt -> -- CInt -> IO CInt. -- -- Does not include the baseCtx, since most of the time it's going -- to be included as part of larger contexts. funCtx :: Context -- | This Context includes two AntiQuoters that allow to -- easily use Haskell vectors in C. -- -- Specifically, the vec-len and vec-ptr will get the -- length and the pointer underlying mutable (IOVector) and -- immutable (Vector) storable vectors. -- -- Note that if you use vecCtx to manipulate immutable vectors you -- must make sure that the vector is not modified in the C code. -- -- To use vec-len, simply write $vec-len:x, where -- x is something of type IOVector a or -- Vector a, for some a. To use vec-ptr -- you need to specify the type of the pointer, e.g. $vec-len:(int -- *x) will work if x has type IOVector -- CInt. vecCtx :: Context -- | bsCtx serves exactly the same purpose as vecCtx, but -- only for ByteString. vec-ptr becomes bs-ptr, -- and vec-len becomes bs-len. You don't need to -- specify the type of the pointer in bs-ptr, it will always be -- unsigned char*. bsCtx :: Context -- | Sets the Context for the current module. This function, if -- called, must be called before any of the other TH functions in this -- module. Fails if that's not the case. context :: Context -> DecsQ -- | C expressions. exp :: QuasiQuoter -- | Variant of exp, for use with expressions known to have no side -- effects. -- -- BEWARE: use this function with caution, only when you know what you -- are doing. If an expression does in fact have side-effects, then -- indiscriminate use of pure may endanger referential -- transparency, and in principle even type safety. pure :: QuasiQuoter -- | C code blocks (i.e. statements). block :: QuasiQuoter -- | Emits a CPP include directive for C code associated with the current -- module. To avoid having to escape quotes, the function itself adds -- them when appropriate, so that -- --
--   include "foo.h" ==> #include "foo.h"
--   
-- -- but -- --
--   include "<foo>" ==> #include <foo>
--   
include :: String -> DecsQ -- | Emits an arbitrary C string to the C code associated with the current -- module. Use with care. verbatim :: String -> DecsQ -- | Like alloca, but also peeks the contents of the Ptr and -- returns them once the provided action has finished. withPtr :: Storable a => (Ptr a -> IO b) -> IO (a, b) withPtr_ :: Storable a => (Ptr a -> IO ()) -> IO a -- | Type class with methods useful to allocate and peek multiple pointers -- at once: -- --
--   withPtrs_ :: (Storable a, Storable b) => ((Ptr a, Ptr b) -> IO ()) -> IO (a, b)
--   withPtrs_ :: (Storable a, Storable b, Storable c) => ((Ptr a, Ptr b, Ptr c) -> IO ()) -> IO (a, b, c)
--   ...
--   
class WithPtrs a where type family WithPtrsPtrs a :: * withPtrs_ f = do { (x, _) <- withPtrs f; return x } withPtrs :: WithPtrs a => (WithPtrsPtrs a -> IO b) -> IO (a, b) withPtrs_ :: WithPtrs a => (WithPtrsPtrs a -> IO ()) -> IO a -- | $(mkFunPtr [t| CDouble -> IO -- CDouble |] generates a foreign import wrapper of type -- --
--   (CDouble -> IO CDouble) -> IO (FunPtr (CDouble -> IO CDouble))
--   
-- -- And invokes it. mkFunPtr :: TypeQ -> ExpQ -- | $(mkFunPtrFromName 'foo), if foo :: -- CDouble -> IO CDouble, splices in an -- expression of type IO (FunPtr (CDouble -- -> IO CDouble)). mkFunPtrFromName :: Name -> ExpQ -- | $(peekFunPtr [t| CDouble -> IO -- CDouble |]) generates a foreign import dynamic of type -- --
--   FunPtr (CDouble -> IO CDouble) -> (CDouble -> IO CDouble)
--   
-- -- And invokes it. peekFunPtr :: TypeQ -> ExpQ instance (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f, Storable g) => WithPtrs (a, b, c, d, e, f, g) instance (Storable a, Storable b, Storable c, Storable d, Storable e, Storable f) => WithPtrs (a, b, c, d, e, f) instance (Storable a, Storable b, Storable c, Storable d, Storable e) => WithPtrs (a, b, c, d, e) instance (Storable a, Storable b, Storable c, Storable d) => WithPtrs (a, b, c, d) instance (Storable a, Storable b, Storable c) => WithPtrs (a, b, c) instance (Storable a, Storable b) => WithPtrs (a, b)