
@c Extracted automatically from ../jit/jit-apply.c - DO NOT EDIT


@section Function application and closures
@cindex Function application
@cindex Closures
@cindex jit-apply.h

Sometimes all you have for a function is a pointer to it and a dynamic
description of its arguments.  Calling such a function can be extremely
difficult in standard C.  The routines in this section, particularly
@code{jit_apply}, provide a convenient interface for doing this.

At other times, you may wish to wrap up one of your own dynamic functions
in such a way that it appears to be a regular C function.  This is
performed with @code{jit_closure_create}.


@deftypefun void jit_apply (jit_type_t signature, void *@var{func}, void **@var{args}, unsigned int @var{num_fixed_args}, void *@var{return_value})
Call a function that has a particular function signature.
If the signature has more than @var{num_fixed_args} arguments,
then it is assumed to be a vararg call, with the additional
arguments passed in the vararg argument area on the stack.
The @var{signature} must specify the type of all arguments,
including those in the vararg argument area.
@end deftypefun

@deftypefun void jit_apply_raw (jit_type_t @var{signature}, void *@var{func}, void *@var{args}, void *@var{return_value})
Call a function, passing a set of raw arguments.  This can only
be used if @code{jit_raw_supported} returns non-zero for the signature.
The @var{args} value is assumed to be an array of @code{jit_nint} values
that correspond to each of the arguments.  Raw function calls
are slightly faster than their non-raw counterparts, but can
only be used in certain circumstances.
@end deftypefun

@deftypefun int jit_raw_supported (jit_type_t @var{signature})
Determine if @code{jit_apply_raw} can be used to call functions
with a particular signature.  Returns zero if not.
@end deftypefun

@deftypefun {void *} jit_closure_create (jit_context_t @var{context}, jit_type_t @var{signature}, jit_closure_func @var{func}, void *@var{user_data})
Create a closure from a function signature, a closure handling function,
and a user data value.  Returns NULL if out of memory, or if closures are
not supported.  The @var{func} argument should have the following
prototype:

@example
void func (jit_type_t signature, void *result,
void **args, void *user_data);
@end example

If the closure signature includes variable arguments, then @code{args}
will contain pointers to the fixed arguments, followed by a
@code{jit_closure_va_list_t} value for accessing the remainder of
the arguments.

The memory for the closure will be reclaimed when the @var{context}
is destroyed.
@end deftypefun

@deftypefun int jit_closures_supported (void)
Determine if this platform has support for closures.
@end deftypefun

@deftypefun jit_nint jit_closure_va_get_nint (jit_closure_va_list_t @var{va})
@deftypefunx jit_nuint jit_closure_va_get_nuint (jit_closure_va_list_t @var{va})
@deftypefunx jit_long jit_closure_va_get_long (jit_closure_va_list_t @var{va})
@deftypefunx jit_ulong jit_closure_va_get_ulong (jit_closure_va_list_t @var{va})
@deftypefunx jit_float32 jit_closure_va_get_float32 (jit_closure_va_list_t @var{va})
@deftypefunx jit_float64 jit_closure_va_get_float64 (jit_closure_va_list_t @var{va})
@deftypefunx jit_nfloat jit_closure_va_get_nfloat (jit_closure_va_list_t @var{va})
@deftypefunx {void *} jit_closure_va_get_ptr (jit_closure_va_list_t @var{va})
Get the next value of a specific type from a closure's variable arguments.
@end deftypefun

@deftypefun void jit_closure_va_get_struct (jit_closure_va_list_t @var{va}, void *@var{buf}, jit_type_t @var{type})
Get a structure or union value of a specific @var{type} from a closure's
variable arguments, and copy it into @var{buf}.
@end deftypefun

