Safe Haskell | None |
---|---|
Language | Haskell2010 |
Interface for defining bindings to C++ functions.
Synopsis
- data Function
- fnT :: [Type] -> Type -> Type
- fnT' :: [Parameter] -> Type -> Type
- makeFn :: (IsFnName Identifier name, IsParameter p) => name -> Maybe ExtName -> Purity -> [p] -> Type -> Function
- fnExtName :: Function -> ExtName
- fnCName :: Function -> FnName Identifier
- fnPurity :: Function -> Purity
- fnParams :: Function -> [Parameter]
- fnReturn :: Function -> Type
- fnReqs :: Function -> Reqs
- fnAddendum :: Function -> Addendum
- fnExceptionHandlers :: Function -> ExceptionHandlers
- data CallDirection
- data CppCallType
- sayCppArgRead :: CallDirection -> (Int, Type, Maybe Type) -> Generator ()
- sayCppArgNames :: Int -> Generator ()
- sayCppExportFn :: ExtName -> CppCallType -> Maybe Type -> [Parameter] -> Type -> ExceptionHandlers -> Bool -> Generator ()
- sayHsExportFn :: SayExportMode -> ExtName -> ExtName -> Purity -> [Parameter] -> Type -> ExceptionHandlers -> Generator ()
- sayHsArgProcessing :: CallDirection -> Type -> String -> String -> Generator ()
- sayHsCallAndProcessReturn :: CallDirection -> Type -> [String] -> Generator ()
Data type
A C++ function declaration.
Use this data type's HasReqs
instance to make the function accessible. You
do not need to add requirements for parameter or return types.
Instances
Eq Function Source # | |
Show Function Source # | |
HasAddendum Function Source # | |
Defined in Foreign.Hoppy.Generator.Spec.Function | |
HandlesExceptions Function Source # | |
Exportable Function Source # | |
Defined in Foreign.Hoppy.Generator.Spec.Function toExport :: Function -> Export Source # castExport :: (Typeable Function, Exportable b, Typeable b) => Function -> Maybe b Source # sayExportCpp :: SayExportMode -> Function -> Generator () Source # sayExportHaskell :: SayExportMode -> Function -> Generator () Source # | |
HasExtNames Function Source # | |
Defined in Foreign.Hoppy.Generator.Spec.Function getPrimaryExtName :: Function -> ExtName Source # getNestedExtNames :: Function -> [ExtName] Source # | |
HasReqs Function Source # | |
fnT' :: [Parameter] -> Type -> Type Source #
A version of fnT
that accepts additional information about parameters.
Construction
:: (IsFnName Identifier name, IsParameter p) | |
=> name | |
-> Maybe ExtName | An optional external name; will be automatically derived from the identifier if absent. |
-> Purity | |
-> [p] | Parameter types. |
-> Type | Return type. |
-> Function |
Creates a binding for a C++ function.
Properties
fnAddendum :: Function -> Addendum Source #
The function's addendum.
fnExceptionHandlers :: Function -> ExceptionHandlers Source #
Exceptions that the function might throw.
Code generators
data CallDirection Source #
The direction between languages in which a value is being passed.
Instances
Show CallDirection Source # | |
Defined in Foreign.Hoppy.Generator.Spec.Function showsPrec :: Int -> CallDirection -> ShowS # show :: CallDirection -> String # showList :: [CallDirection] -> ShowS # |
C++ generator
data CppCallType Source #
The name of a function to call.
CallOp Operator | A call to the given operator, for example |
CallFn (Generator ()) | A call to the function whose name is emitted by the given action. |
VarRead (Generator ()) | Not a function call, but a read from a variable whose name is emitted by the given action. |
VarWrite (Generator ()) | Not a function call, but a write to a variable whose name is emitted by the given action. |
sayCppArgRead :: CallDirection -> (Int, Type, Maybe Type) -> Generator () Source #
sayCppArgNames :: Int -> Generator () Source #
Prints a comma-separated list of the argument names used for C++ gateway functions. The number specifies how many names to print.
Internal
C++ generator
:: ExtName | The external name of the function. |
-> CppCallType | The C++ name at which the function can be invoked. |
-> Maybe Type | If present, then we are wrapping a method within some class, and the type is that of the class. |
-> [Parameter] | Info about the function's parameters. |
-> Type | The function's return type. |
-> ExceptionHandlers | Exception handlers configured on the function itself. No need to call
|
-> Bool | Whether to generate the function definition. If false, only the declaration is generated (no function body). |
-> Generator () |
Generates a C++ wrapper function for calling a C++ function (or method, or reading from or writing to a variable). The generated function handles C++-side marshalling of values and propagating exceptions as requested.
See also sayHsExportFn
.
Haskell generator
:: SayExportMode | The phase of code generation. |
-> ExtName | The external name for the entity we're generating. For class entities, this will include the class's external name as a prefix. |
-> ExtName | An alternate external name to use to generate Haskell function names. For non-class entities, this can be just the regular external name. For class entities, in order to strip off the class name that was added so that the entity's external name is unique, this can just be the name of the function, variable, etc. |
-> Purity | Whether or not the function is pure (free of side effects). |
-> [Parameter] | Parameter info. |
-> Type | The return type. |
-> ExceptionHandlers | Any exception handlers to apply to the binding, in addition to what its module and interface provide. |
-> Generator () |
Generates a Haskell wrapper function for calling a C++ function (or method,
or reading from or writing to a variable, as with sayCppExportFn
). The
generated function handles Haskell-side marshalling of values and propagating
exceptions as requested.
:: CallDirection | The direction of the FFI call. |
-> Type | The type of the value to be marshalled. |
-> String | The name of the binding holding the input value. |
-> String | The name of the binding to create for the output value. |
-> Generator () |
Generates Haskell code to perform marshalling of a function's argument in a specified direction.
This function either generates a line or lines such that subsequent lines can refer to the output binding. The final line is either terminated with
... $ \value ->
or
let ... in
so that precedence is not an issue.
sayHsCallAndProcessReturn :: CallDirection -> Type -> [String] -> Generator () Source #
Note that the CallDirection
is the direction of the call, not the
direction of the return. ToCpp
means we're returning to the foreign
language, FromCpp
means we're returning from it.