| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Language.C.Inline.Context
Contents
Description
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.
- type TypesTable = Map TypeSpecifier TypeQ
- data Purity
- convertType :: Purity -> TypesTable -> Type -> Q (Maybe Type)
- type CArray = Ptr
- isTypeName :: TypesTable -> Identifier -> Bool
- data AntiQuoter a = AntiQuoter {}
- type AntiQuoterId = String
- data SomeAntiQuoter = forall a . (Eq a, Typeable a) => SomeAntiQuoter (AntiQuoter a)
- type AntiQuoters = Map AntiQuoterId SomeAntiQuoter
- data Context = Context {}
- baseCtx :: Context
- funCtx :: Context
- vecCtx :: Context
- class VecCtx a where
- type VecCtxScalar a :: *
- vecCtxLength :: a -> Int
- vecCtxUnsafeWith :: a -> (Ptr (VecCtxScalar a) -> IO b) -> IO b
- bsCtx :: Context
TypesTable
type TypesTable = Map TypeSpecifier TypeQ Source
A mapping from TypeSpecifiers to Haskell types. Needed both to
parse C types, and to convert them to Haskell types.
A data type to indicate whether the user requested pure or IO function from Haskell
convertType :: Purity -> TypesTable -> Type -> Q (Maybe Type) Source
Given a Context, it uses its ctxTypesTable to convert
arbitrary C types.
isTypeName :: TypesTable -> Identifier -> Bool Source
AntiQuoter
data AntiQuoter a Source
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.
Constructors
| AntiQuoter | |
Fields
| |
type AntiQuoterId = String Source
An identifier for a AntiQuoter.
data SomeAntiQuoter Source
Existential wrapper around AntiQuoter.
Constructors
| forall a . (Eq a, Typeable a) => SomeAntiQuoter (AntiQuoter a) |
Context
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 yy will take precedence over x.
Constructors
| Context | |
Fields
| |
Context useful to work with vanilla C. Used by default.
ctxTypesTable: converts C basic types to their counterparts in
Foreign.C.Types.
No ctxAntiQuoters.
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.
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 or IOVector a, for some Vector aa. 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
Type class used to implement the anti-quoters in vecCtx.
Associated Types
type VecCtxScalar a :: * Source
Methods
vecCtxLength :: a -> Int Source
vecCtxUnsafeWith :: a -> (Ptr (VecCtxScalar a) -> IO b) -> IO b Source