Unifex v0.3.0 Unifex.CodeGenerator.BaseType behaviour View Source

Behaviour and abstraction over type-specific code generation.

When invoking callbacks for type :type and interface Interface it searches for a module that implements given callback in the following order:

  • Unifex.CodeGenerator.BaseTypes.Type.Interface
  • Unifex.CodeGenerator.BaseTypes.Type
  • Unifex.CodeGenerator.BaseTypes.Default.Interface

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 c:generate_native_type/0 and provided name.

Generates an destrucition of variable content. Should be paired with generate_initialization/1

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 c:generate_initialization/1

Generates an initialization of variable content. Should be paired with c:generate_destruction/1

Generates a native counterpart for the type.

Link to this section Types

Specs

arg_parse_ctx_t() :: %{
  result_var: Unifex.CodeGenerator.code_t(),
  exit_label: Unifex.CodeGenerator.code_t()
}

Specs

spec_tuple_t() :: {name :: atom(), type :: t()}

Specs

t() :: atom() | {:list, atom()}

Link to this section Functions

Link to this function

generate_arg_name(type, name, code_generator)

View Source
Link to this function

generate_arg_parse(type, name, argument, postproc_fun \\ &(&1), code_generator)

View Source

Generates parsing of UNIFEX_TERM argument into the native variable

Link to this function

generate_arg_serialize(type, name, code_generator)

View Source

Specs

generate_arg_serialize(t(), name :: atom(), module()) ::
  Unifex.CodeGenerator.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.

Link to this function

generate_declaration(type, name, mode \\ :default, code_generator)

View Source

Specs

generate_declaration(t(), name :: atom(), mode :: :default | :const, module()) ::
  [Unifex.CodeGenerator.code_t()]

Generates a declaration of parameter (to be placed in function header) based on c:generate_native_type/0 and provided name.

Uses type as fallback for generate_native_type/1

Link to this function

generate_destruction(type, name, code_generator)

View Source

Specs

generate_destruction(t(), name :: atom(), module()) ::
  Unifex.CodeGenerator.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

Link to this function

generate_initialization(type, name, code_generator)

View Source

Specs

generate_initialization(t(), name :: atom(), module()) ::
  Unifex.CodeGenerator.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 function

generate_native_type(type, mode \\ :default, code_generator)

View Source

Link to this section Callbacks

Link to this callback

generate_arg_parse(argument, variable, ctx)

View Source (optional)

Specs

generate_arg_parse(argument :: String.t(), variable :: String.t(), ctx :: map()) ::
  Unifex.CodeGenerator.code_t()

Generates function call parsing UNIFEX_TERM argument into the native variable with name variable. Function should return boolean value.

Link to this callback

generate_arg_serialize(name, ctx)

View Source (optional)

Specs

generate_arg_serialize(name :: atom(), ctx :: map()) ::
  Unifex.CodeGenerator.code_t()

Provides a way to convert native variable name into UNIFEX_TERM

Link to this callback

generate_destruction(name, ctx)

View Source (optional)

Specs

generate_destruction(name :: atom(), ctx :: map()) ::
  Unifex.CodeGenerator.code_t()

Generates a destruction of variable content. Should be paired with c:generate_initialization/1

Link to this callback

generate_initialization(name, ctx)

View Source (optional)

Specs

generate_initialization(name :: atom(), ctx :: map()) ::
  Unifex.CodeGenerator.code_t()

Generates an initialization of variable content. Should be paired with c:generate_destruction/1

Link to this callback

generate_native_type(ctx)

View Source (optional)

Specs

generate_native_type(ctx :: map()) ::
  Unifex.CodeGenerator.code_t() | [Unifex.CodeGenerator.code_t()]

Generates a native counterpart for the type.