hoppy-generator-0.6.0: C++ FFI generator - Code generator

Safe HaskellNone
LanguageHaskell2010

Foreign.Hoppy.Generator.Spec.Function

Contents

Description

Interface for defining bindings to C++ functions.

Synopsis

Data type

data Function Source #

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 # 
Instance details

Defined in Foreign.Hoppy.Generator.Spec.Function

Show Function Source # 
Instance details

Defined in Foreign.Hoppy.Generator.Spec.Function

HasAddendum Function Source # 
Instance details

Defined in Foreign.Hoppy.Generator.Spec.Function

HandlesExceptions Function Source # 
Instance details

Defined in Foreign.Hoppy.Generator.Spec.Function

Exportable Function Source # 
Instance details

Defined in Foreign.Hoppy.Generator.Spec.Function

HasExtNames Function Source # 
Instance details

Defined in Foreign.Hoppy.Generator.Spec.Function

HasReqs Function Source # 
Instance details

Defined in Foreign.Hoppy.Generator.Spec.Function

fnT :: [Type] -> Type -> Type Source #

A function taking parameters and returning a value (or voidT). Function pointers must wrap a fnT in a ptrT.

See also fnT' which accepts parameter information.

fnT' :: [Parameter] -> Type -> Type Source #

A version of fnT that accepts additional information about parameters.

Construction

makeFn Source #

Arguments

:: (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

fnExtName :: Function -> ExtName Source #

The function's external name.

fnCName :: Function -> FnName Identifier Source #

The identifier used to call the function.

fnPurity :: Function -> Purity Source #

Whether the function is pure.

fnParams :: Function -> [Parameter] Source #

The function's parameters.

fnReturn :: Function -> Type Source #

The function's return type.

fnReqs :: Function -> Reqs Source #

Requirements for bindings to access this function.

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.

Constructors

ToCpp

Haskell code is calling out to C++.

FromCpp

C++ is invoking a callback.

C++ generator

data CppCallType Source #

The name of a function to call.

Constructors

CallOp Operator

A call to the given operator, for example x++, x * y, a[i].

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 #

Generates code to marshal a value between a C++ type and the intermediate type to be used over the FFI. If dir is ToCpp, then we are a C++ function reading an argument from foreign code. If dir is FromCpp, then we are invoking a foreign callback.

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

sayCppExportFn Source #

Arguments

:: 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 getEffectiveExceptionHandlers to combine the function's handlers with those from the module and interface; this function does that already.

-> 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

sayHsExportFn Source #

Arguments

:: 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.

sayHsArgProcessing Source #

Arguments

:: 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.