Unifex v0.2.2 Unifex.BaseType behaviour View Source
This module provides different generators allowing to map the types from Unifex specs into proper native types
The generators from this module are trying to delegate the calls to the callbacks in modules adequate for the type but provide fallback values (all the callbacks are optional)
Link to this section Summary
Functions
Generates parsing of UNIFEX_TERM argument
into the native variable
Provides a way to convert native variable name
into UNIFEX_TERM
Generates a declaration of parameter (to be placed in function header) based on generate_native_type/0
and
provided name
Generates an destrucition of variable content. Should be paired with generate_initialization/1
Generates Elixir post-processing of the value returned from native function
Generates an initialization of variable content. Should be paired with generate_destruction/1
Callbacks
Generates function call parsing UNIFEX_TERM argument
into the native variable with name variable
. Function should
return boolean value
Provides a way to convert native variable name
into UNIFEX_TERM
Generates a destruction of variable content. Should be paired with generate_initialization/1
Generates Elixir post-processing of the value returned from native function
Generates an initialization of variable content. Should be paired with generate_destruction/1
Generates a native counterpart for the type
Generates an expression that will return how many bytes should be allocated for this type
Link to this section Types
arg_parse_ctx_t()
View Source
arg_parse_ctx_t() :: %{
result_var: Unifex.NativeCodeGenerator.code_t(),
exit_label: Unifex.NativeCodeGenerator.code_t()
}
arg_parse_ctx_t() :: %{ result_var: Unifex.NativeCodeGenerator.code_t(), exit_label: Unifex.NativeCodeGenerator.code_t() }
spec_tuple_t() View Source
Link to this section Functions
generate_arg_name(arg) View Source
generate_arg_parse(arg, ctx)
View Source
generate_arg_parse(
{spec_tuple_t(), i :: non_neg_integer()},
ctx :: arg_parse_ctx_t()
) :: Unifex.NativeCodeGenerator.code_t()
generate_arg_parse( {spec_tuple_t(), i :: non_neg_integer()}, ctx :: arg_parse_ctx_t() ) :: Unifex.NativeCodeGenerator.code_t()
Generates parsing of UNIFEX_TERM argument
into the native variable
generate_arg_serialize(arg)
View Source
generate_arg_serialize(spec_tuple_t()) :: Unifex.NativeCodeGenerator.code_t()
generate_arg_serialize(spec_tuple_t()) :: Unifex.NativeCodeGenerator.code_t()
Provides a way to convert native variable name
into UNIFEX_TERM
Tries to get value from type-specific module, uses enif_make_#{type}
as fallback value.
generate_declaration(arg)
View Source
generate_declaration(spec_tuple_t()) :: [Unifex.NativeCodeGenerator.code_t()]
generate_declaration(spec_tuple_t()) :: [Unifex.NativeCodeGenerator.code_t()]
Generates a declaration of parameter (to be placed in function header) based on generate_native_type/0
and
provided name
.
Uses type
as fallback for c:generate_native_type/1
generate_destruction(arg)
View Source
generate_destruction(spec_tuple_t()) :: Unifex.NativeCodeGenerator.code_t()
generate_destruction(spec_tuple_t()) :: Unifex.NativeCodeGenerator.code_t()
Generates an destrucition of variable content. Should be paired with generate_initialization/1
Returns an empty string if the type does not provide destructor
generate_elixir_postprocessing(arg)
View Source
generate_elixir_postprocessing(spec_tuple_t()) :: Macro.t()
generate_elixir_postprocessing(spec_tuple_t()) :: Macro.t()
Generates Elixir post-processing of the value returned from native function.
Fallbacks to simply passing the value (as variable reference)
generate_initialization(arg)
View Source
generate_initialization(spec_tuple_t()) :: Unifex.NativeCodeGenerator.code_t()
generate_initialization(spec_tuple_t()) :: Unifex.NativeCodeGenerator.code_t()
Generates an initialization of variable content. Should be paired with generate_destruction/1
Returns an empty string if the type does not provide initialization
Link to this section Callbacks
generate_arg_parse(argument, variable)
View Source
(optional)
generate_arg_parse(argument :: String.t(), variable :: String.t()) ::
Unifex.NativeCodeGenerator.code_t()
generate_arg_parse(argument :: String.t(), variable :: String.t()) :: Unifex.NativeCodeGenerator.code_t()
Generates function call parsing UNIFEX_TERM argument
into the native variable with name variable
. Function should
return boolean value.
generate_arg_serialize(name)
View Source
(optional)
generate_arg_serialize(name :: atom()) :: Unifex.NativeCodeGenerator.code_t()
generate_arg_serialize(name :: atom()) :: Unifex.NativeCodeGenerator.code_t()
Provides a way to convert native variable name
into UNIFEX_TERM
generate_destruction(name)
View Source
(optional)
generate_destruction(name :: atom()) :: Unifex.NativeCodeGenerator.code_t()
generate_destruction(name :: atom()) :: Unifex.NativeCodeGenerator.code_t()
Generates a destruction of variable content. Should be paired with generate_initialization/1
generate_elixir_postprocessing(name) View Source (optional)
Generates Elixir post-processing of the value returned from native function.
Should return quoted code. The value can be referenced using Macro.var/2
call.
Useful when some call cannot be made from native code (e.g. call to another NIF from NIF)
generate_initialization(name)
View Source
(optional)
generate_initialization(name :: atom()) :: Unifex.NativeCodeGenerator.code_t()
generate_initialization(name :: atom()) :: Unifex.NativeCodeGenerator.code_t()
Generates an initialization of variable content. Should be paired with generate_destruction/1
generate_native_type()
View Source
(optional)
generate_native_type() :: Unifex.NativeCodeGenerator.code_t()
generate_native_type() :: Unifex.NativeCodeGenerator.code_t()
Generates a native counterpart for the type.
generate_sizeof()
View Source
(optional)
generate_sizeof() :: Unifex.NativeCodeGenerator.code_t()
generate_sizeof() :: Unifex.NativeCodeGenerator.code_t()
Generates an expression that will return how many bytes should be allocated for this type.