|
infix
A JIT-Powered FFI Library for C
|
The core data structures and APIs for describing C types and function signatures. More...
Classes | |
| struct | infix_type_t |
| A semi-opaque structure that describes a C type. More... | |
| struct | infix_struct_member_t |
| Describes a single member of a C struct or union. More... | |
| struct | infix_function_argument_t |
| Describes a single argument to a C function. More... | |
Typedefs | |
| typedef struct infix_type_t | infix_type |
A semi-opaque object describing a C type's memory layout and calling convention. See infix_type_t for details. | |
| typedef struct infix_struct_member_t | infix_struct_member |
A semi-opaque object describing a member of a C struct or union. See infix_struct_member_t for details. | |
| typedef struct infix_function_argument_t | infix_function_argument |
A semi-opaque object describing an argument to a C function. See infix_function_argument_t for details. | |
| typedef struct infix_forward_t | infix_forward_t |
An opaque handle to a forward (C-to-native) trampoline. Created by infix_forward_create and variants. | |
| typedef struct infix_reverse_t | infix_reverse_t |
| An opaque handle to a reverse (native-to-C) trampoline, also known as a callback or closure. | |
| typedef infix_reverse_t | infix_context_t |
An alias for infix_reverse_t, used to clarify its role as a context object in closure handlers. | |
| typedef struct infix_arena_t | infix_arena_t |
| An opaque handle to an arena allocator, used for efficient grouped memory allocations. | |
| typedef struct infix_library_t | infix_library_t |
An opaque handle to a dynamically loaded shared library (.so, .dll, .dylib). | |
| typedef struct infix_registry_t | infix_registry_t |
| An opaque handle to a named type registry. | |
Enumerations | |
| enum | infix_type_category { INFIX_TYPE_PRIMITIVE , INFIX_TYPE_POINTER , INFIX_TYPE_STRUCT , INFIX_TYPE_UNION , INFIX_TYPE_ARRAY , INFIX_TYPE_REVERSE_TRAMPOLINE , INFIX_TYPE_ENUM , INFIX_TYPE_COMPLEX , INFIX_TYPE_VECTOR , INFIX_TYPE_NAMED_REFERENCE , INFIX_TYPE_VOID } |
Enumerates the fundamental categories of types that infix can represent. More... | |
| enum | infix_primitive_type_id { INFIX_PRIMITIVE_BOOL , INFIX_PRIMITIVE_UINT8 , INFIX_PRIMITIVE_SINT8 , INFIX_PRIMITIVE_UINT16 , INFIX_PRIMITIVE_SINT16 , INFIX_PRIMITIVE_UINT32 , INFIX_PRIMITIVE_SINT32 , INFIX_PRIMITIVE_UINT64 , INFIX_PRIMITIVE_SINT64 , INFIX_PRIMITIVE_UINT128 , INFIX_PRIMITIVE_SINT128 , INFIX_PRIMITIVE_FLOAT , INFIX_PRIMITIVE_DOUBLE , INFIX_PRIMITIVE_LONG_DOUBLE } |
| Enumerates the supported primitive C types. More... | |
| enum | infix_aggregate_category_t { INFIX_AGGREGATE_STRUCT , INFIX_AGGREGATE_UNION } |
| Specifies whether a named type reference refers to a struct or a union. More... | |
Functions | |
| c23_nodiscard infix_type * | infix_type_create_primitive (infix_primitive_type_id) |
| Creates a static descriptor for a primitive C type. | |
| c23_nodiscard infix_type * | infix_type_create_pointer (void) |
Creates a static descriptor for a generic pointer (void*). | |
| c23_nodiscard infix_status | infix_type_create_pointer_to (infix_arena_t *, infix_type **, infix_type *) |
| Creates a new pointer type that points to a specific type. | |
| c23_nodiscard infix_type * | infix_type_create_void (void) |
Creates a static descriptor for the void type. | |
| c23_nodiscard infix_status | infix_type_create_struct (infix_arena_t *, infix_type **, infix_struct_member *, size_t) |
| Creates a new struct type from an array of members, calculating layout automatically. | |
| c23_nodiscard infix_status | infix_type_create_packed_struct (infix_arena_t *, infix_type **, size_t, size_t, infix_struct_member *, size_t) |
| Creates a new packed struct type with a user-specified layout. | |
| c23_nodiscard infix_status | infix_type_create_union (infix_arena_t *, infix_type **, infix_struct_member *, size_t) |
| Creates a new union type from an array of members. | |
| c23_nodiscard infix_status | infix_type_create_array (infix_arena_t *, infix_type **, infix_type *, size_t) |
| Creates a new fixed-size array type. | |
| c23_nodiscard infix_status | infix_type_create_enum (infix_arena_t *, infix_type **, infix_type *) |
| Creates a new enum type with a specified underlying integer type. | |
| c23_nodiscard infix_status | infix_type_create_named_reference (infix_arena_t *, infix_type **, const char *, infix_aggregate_category_t) |
| Creates a placeholder for a named type to be resolved by a registry. | |
| c23_nodiscard infix_status | infix_type_create_complex (infix_arena_t *, infix_type **, infix_type *) |
Creates a new _Complex number type. | |
| c23_nodiscard infix_status | infix_type_create_vector (infix_arena_t *, infix_type **, infix_type *, size_t) |
| Creates a new SIMD vector type. | |
| infix_struct_member | infix_type_create_member (const char *, infix_type *, size_t) |
A factory function to create an infix_struct_member. | |
| c23_nodiscard size_t | infix_forward_get_num_fixed_args (const infix_forward_t *) |
| Gets the number of fixed (non-variadic) arguments for a forward trampoline. | |
| c23_nodiscard const infix_type * | infix_forward_get_return_type (const infix_forward_t *) |
| Gets the return type for a forward trampoline. | |
| c23_nodiscard const infix_type * | infix_forward_get_arg_type (const infix_forward_t *, size_t) |
| Gets the type of a specific argument for a forward trampoline. | |
| c23_nodiscard size_t | infix_reverse_get_num_args (const infix_reverse_t *) |
| Gets the total number of arguments for a reverse trampoline. | |
| c23_nodiscard const infix_type * | infix_reverse_get_return_type (const infix_reverse_t *) |
| Gets the return type for a reverse trampoline. | |
| c23_nodiscard size_t | infix_reverse_get_num_fixed_args (const infix_reverse_t *) |
| Gets the number of fixed (non-variadic) arguments for a reverse trampoline. | |
| c23_nodiscard const infix_type * | infix_reverse_get_arg_type (const infix_reverse_t *, size_t) |
| Gets the type of a specific argument for a reverse trampoline. | |
| c23_nodiscard const char * | infix_type_get_name (const infix_type *) |
| Gets the semantic alias of a type, if one exists. | |
| c23_nodiscard infix_type_category | infix_type_get_category (const infix_type *) |
| Gets the fundamental category of a type. | |
| c23_nodiscard size_t | infix_type_get_size (const infix_type *) |
| Gets the size of a type in bytes. | |
| c23_nodiscard size_t | infix_type_get_alignment (const infix_type *) |
| Gets the alignment requirement of a type in bytes. | |
| c23_nodiscard size_t | infix_type_get_member_count (const infix_type *) |
| Gets the number of members in a struct or union type. | |
| c23_nodiscard const infix_struct_member * | infix_type_get_member (const infix_type *, size_t) |
| Gets a specific member from a struct or union type. | |
| c23_nodiscard const char * | infix_type_get_arg_name (const infix_type *, size_t) |
| Gets the name of a specific argument from a function type. | |
| c23_nodiscard const infix_type * | infix_type_get_arg_type (const infix_type *, size_t) |
| Gets the type of a specific argument from a function type. | |
The core data structures and APIs for describing C types and function signatures.
infix uses a powerful, introspectable type system to represent C types. These structures can be created programmatically using the Manual API or parsed from human-readable signature strings.
| typedef struct infix_arena_t infix_arena_t |
An opaque handle to an arena allocator, used for efficient grouped memory allocations.
| typedef infix_reverse_t infix_context_t |
An alias for infix_reverse_t, used to clarify its role as a context object in closure handlers.
| typedef struct infix_forward_t infix_forward_t |
An opaque handle to a forward (C-to-native) trampoline. Created by infix_forward_create and variants.
| typedef struct infix_function_argument_t infix_function_argument |
A semi-opaque object describing an argument to a C function. See infix_function_argument_t for details.
| typedef struct infix_library_t infix_library_t |
An opaque handle to a dynamically loaded shared library (.so, .dll, .dylib).
| typedef struct infix_registry_t infix_registry_t |
An opaque handle to a named type registry.
| typedef struct infix_reverse_t infix_reverse_t |
An opaque handle to a reverse (native-to-C) trampoline, also known as a callback or closure.
| typedef struct infix_struct_member_t infix_struct_member |
A semi-opaque object describing a member of a C struct or union. See infix_struct_member_t for details.
| typedef struct infix_type_t infix_type |
A semi-opaque object describing a C type's memory layout and calling convention. See infix_type_t for details.
Enumerates the supported primitive C types.
| enum infix_type_category |
Enumerates the fundamental categories of types that infix can represent.
| c23_nodiscard const infix_type * infix_forward_get_arg_type | ( | const infix_forward_t * | trampoline, |
| size_t | index | ||
| ) |
Gets the type of a specific argument for a forward trampoline.
| [in] | trampoline | The trampoline handle. |
| [in] | index | The zero-based index of the argument. |
infix_type, or nullptr if the index is out of bounds.| [in] | trampoline | The trampoline handle. |
| [in] | index | The zero-based index of the argument. |
infix_type, or nullptr if the index is out of bounds or trampoline is nullptr. | c23_nodiscard size_t infix_forward_get_num_fixed_args | ( | const infix_forward_t * | trampoline | ) |
Gets the number of fixed (non-variadic) arguments for a forward trampoline.
| [in] | trampoline | The trampoline handle. |
| [in] | trampoline | The trampoline handle. |
trampoline is nullptr. | c23_nodiscard const infix_type * infix_forward_get_return_type | ( | const infix_forward_t * | trampoline | ) |
Gets the return type for a forward trampoline.
| [in] | trampoline | The trampoline handle. |
infix_type for the return value, or nullptr.| [in] | trampoline | The trampoline handle. |
infix_type for the return value, or nullptr if trampoline is nullptr. | c23_nodiscard const infix_type * infix_reverse_get_arg_type | ( | const infix_reverse_t * | trampoline, |
| size_t | index | ||
| ) |
Gets the type of a specific argument for a reverse trampoline.
| [in] | trampoline | The trampoline context handle. |
| [in] | index | The zero-based index of the argument. |
infix_type, or nullptr if the index is out of bounds.| [in] | trampoline | The trampoline context handle. |
| [in] | index | The zero-based index of the argument. |
infix_type, or nullptr if the index is out of bounds or trampoline is nullptr. | c23_nodiscard size_t infix_reverse_get_num_args | ( | const infix_reverse_t * | trampoline | ) |
Gets the total number of arguments for a reverse trampoline.
| [in] | trampoline | The trampoline context handle. |
trampoline is nullptr. | c23_nodiscard size_t infix_reverse_get_num_fixed_args | ( | const infix_reverse_t * | trampoline | ) |
Gets the number of fixed (non-variadic) arguments for a reverse trampoline.
| [in] | trampoline | The trampoline context handle. |
| [in] | trampoline | The trampoline context handle. |
trampoline is nullptr. | c23_nodiscard const infix_type * infix_reverse_get_return_type | ( | const infix_reverse_t * | trampoline | ) |
Gets the return type for a reverse trampoline.
| [in] | trampoline | The trampoline context handle. |
infix_type for the return value, or nullptr.| [in] | trampoline | The trampoline context handle. |
infix_type for the return value, or nullptr if trampoline is nullptr. | c23_nodiscard infix_status infix_type_create_array | ( | infix_arena_t * | arena, |
| infix_type ** | out_type, | ||
| infix_type * | element_type, | ||
| size_t | num_elements | ||
| ) |
Creates a new fixed-size array type.
| [in] | arena | The arena for allocation. |
| [out] | out_type | A pointer to receive the new infix_type. |
| [in] | element_type | The type of each element in the array. |
| [in] | num_elements | The number of elements. |
INFIX_SUCCESS on success. | c23_nodiscard infix_status infix_type_create_complex | ( | infix_arena_t * | arena, |
| infix_type ** | out_type, | ||
| infix_type * | base_type | ||
| ) |
Creates a new _Complex number type.
| [in] | arena | The arena for allocation. |
| [out] | out_type | A pointer to receive the new infix_type. |
| [in] | base_type | The base floating-point type (float or double). |
INFIX_SUCCESS on success. | c23_nodiscard infix_status infix_type_create_enum | ( | infix_arena_t * | arena, |
| infix_type ** | out_type, | ||
| infix_type * | underlying_type | ||
| ) |
Creates a new enum type with a specified underlying integer type.
| [in] | arena | The arena for allocation. |
| [out] | out_type | A pointer to receive the new infix_type. |
| [in] | underlying_type | The integer infix_type (e.g., from infix_type_create_primitive(INFIX_PRIMITIVE_SINT32)). |
INFIX_SUCCESS on success.| [in] | arena | The arena for allocation. |
| [out] | out_type | A pointer to receive the new infix_type. |
| [in] | underlying_type | The integer infix_type (e.g., from infix_type_create_primitive(INFIX_PRIMITIVE_SINT32)). |
INFIX_SUCCESS on success, or INFIX_ERROR_INVALID_ARGUMENT if the underlying type is not an integer. | infix_struct_member infix_type_create_member | ( | const char * | name, |
| infix_type * | type, | ||
| size_t | offset | ||
| ) |
A factory function to create an infix_struct_member.
| [in] | name | The name of the member (optional, can be nullptr). |
| [in] | type | The infix_type of the member. |
| [in] | offset | The byte offset of the member. This is ignored by infix_type_create_struct. |
infix_struct_member object.| [in] | name | The name of the member (optional, can be nullptr). |
| [in] | type | The infix_type of the member. |
| [in] | offset | The byte offset of the member from the start of its parent aggregate. |
infix_struct_member object. | c23_nodiscard infix_status infix_type_create_named_reference | ( | infix_arena_t * | arena, |
| infix_type ** | out_type, | ||
| const char * | name, | ||
| infix_aggregate_category_t | agg_cat | ||
| ) |
Creates a placeholder for a named type to be resolved by a registry.
| [in] | arena | The arena for allocation. |
| [out] | out_type | A pointer to receive the new infix_type. |
| [in] | name | The name of the type (e.g., "MyStruct"). |
| [in] | agg_cat | The expected category of the aggregate (struct or union). |
INFIX_SUCCESS on success.Creates a placeholder for a named type to be resolved by a registry.
This is a key component for defining recursive or mutually-dependent types. The created type has a size and alignment of 0/1, which are updated during the "Resolve" and "Layout" stages of the pipeline.
| [in] | arena | The arena for allocation. |
| [out] | out_type | A pointer to receive the new infix_type. |
| [in] | name | The name of the type (e.g., "MyStruct"). |
| [in] | agg_cat | The expected category of the aggregate (struct or union). |
INFIX_SUCCESS on success. | c23_nodiscard infix_status infix_type_create_packed_struct | ( | infix_arena_t * | arena, |
| infix_type ** | out_type, | ||
| size_t | total_size, | ||
| size_t | alignment, | ||
| infix_struct_member * | members, | ||
| size_t | num_members | ||
| ) |
Creates a new packed struct type with a user-specified layout.
| [in] | arena | The arena for allocation. |
| [out] | out_type | A pointer to receive the new infix_type. |
| [in] | total_size | The total size of the packed struct in bytes. |
| [in] | alignment | The alignment requirement of the struct (e.g., 1 for #pragma pack(1)). |
| [in] | members | An array of infix_struct_member with pre-calculated offsets. |
| [in] | num_members | The number of members. |
INFIX_SUCCESS on success. | c23_nodiscard infix_type * infix_type_create_pointer | ( | void | ) |
Creates a static descriptor for a generic pointer (void*).
infix_type descriptor. Does not need to be freed. | c23_nodiscard infix_status infix_type_create_pointer_to | ( | infix_arena_t * | arena, |
| infix_type ** | out_type, | ||
| infix_type * | pointee_type | ||
| ) |
Creates a new pointer type that points to a specific type.
| [in] | arena | The arena to allocate the new type object in. |
| [out] | out_type | A pointer to receive the created infix_type. |
| [in] | pointee_type | The type that the new pointer will point to. |
INFIX_SUCCESS on success.| [in] | arena | The arena to allocate the new type object in. |
| [out] | out_type | A pointer to receive the created infix_type. |
| [in] | pointee_type | The infix_type that the new pointer will point to. |
INFIX_SUCCESS on success, or an error code on allocation failure. | c23_nodiscard infix_type * infix_type_create_primitive | ( | infix_primitive_type_id | id | ) |
Creates a static descriptor for a primitive C type.
| [in] | id | The infix_primitive_type_id of the desired primitive type. |
infix_type descriptor. Does not need to be freed.| [in] | id | The infix_primitive_type_id of the desired primitive type. |
infix_type singleton descriptor. This pointer does not need to be freed. | c23_nodiscard infix_status infix_type_create_struct | ( | infix_arena_t * | arena, |
| infix_type ** | out_type, | ||
| infix_struct_member * | members, | ||
| size_t | num_members | ||
| ) |
Creates a new struct type from an array of members, calculating layout automatically.
| [in] | arena | The arena for allocation. |
| [out] | out_type | A pointer to receive the new infix_type. |
| [in] | members | An array of infix_struct_member describing the struct's layout. The offset field is ignored. |
| [in] | num_members | The number of members in the array. |
INFIX_SUCCESS on success.| [in] | arena | The arena for allocation. |
| [out] | out_type | A pointer to receive the new infix_type. |
| [in] | members | An array of infix_struct_member describing the struct's members. The offset field is ignored. |
| [in] | num_members | The number of members in the array. |
INFIX_SUCCESS on success. | c23_nodiscard infix_status infix_type_create_union | ( | infix_arena_t * | arena, |
| infix_type ** | out_type, | ||
| infix_struct_member * | members, | ||
| size_t | num_members | ||
| ) |
Creates a new union type from an array of members.
| [in] | arena | The arena for allocation. |
| [out] | out_type | A pointer to receive the new infix_type. |
| [in] | members | An array of infix_struct_member describing the union's members. |
| [in] | num_members | The number of members. |
INFIX_SUCCESS on success. | c23_nodiscard infix_status infix_type_create_vector | ( | infix_arena_t * | arena, |
| infix_type ** | out_type, | ||
| infix_type * | element_type, | ||
| size_t | num_elements | ||
| ) |
Creates a new SIMD vector type.
| [in] | arena | The arena for allocation. |
| [out] | out_type | A pointer to receive the new infix_type. |
| [in] | element_type | The primitive type of each element. |
| [in] | num_elements | The number of elements in the vector. |
INFIX_SUCCESS on success. | c23_nodiscard infix_type * infix_type_create_void | ( | void | ) |
Creates a static descriptor for the void type.
infix_type descriptor. Does not need to be freed. | c23_nodiscard size_t infix_type_get_alignment | ( | const infix_type * | type | ) |
Gets the alignment requirement of a type in bytes.
| [in] | type | The type object to inspect. |
| [in] | type | The type object to inspect. |
type is nullptr. | c23_nodiscard const char * infix_type_get_arg_name | ( | const infix_type * | func_type, |
| size_t | index | ||
| ) |
Gets the name of a specific argument from a function type.
| [in] | func_type | The function type object to inspect (INFIX_TYPE_REVERSE_TRAMPOLINE). |
| [in] | index | The zero-based index of the argument. |
nullptr if anonymous or out of bounds.| [in] | func_type | The function type object to inspect (must have category INFIX_TYPE_REVERSE_TRAMPOLINE). |
| [in] | index | The zero-based index of the argument. |
nullptr if the argument is anonymous or the index is out of bounds. | c23_nodiscard const infix_type * infix_type_get_arg_type | ( | const infix_type * | func_type, |
| size_t | index | ||
| ) |
Gets the type of a specific argument from a function type.
| [in] | func_type | The function type object to inspect. |
| [in] | index | The zero-based index of the argument. |
infix_type, or nullptr if the index is out of bounds.| [in] | func_type | The function type object to inspect. |
| [in] | index | The zero-based index of the argument. |
infix_type, or nullptr if the index is out of bounds. | c23_nodiscard infix_type_category infix_type_get_category | ( | const infix_type * | type | ) |
Gets the fundamental category of a type.
| [in] | type | The type object to inspect. |
infix_type_category enum value.| [in] | type | The type object to inspect. |
infix_type_category enum value, or -1 if type is nullptr. | c23_nodiscard const infix_struct_member * infix_type_get_member | ( | const infix_type * | type, |
| size_t | index | ||
| ) |
Gets a specific member from a struct or union type.
| [in] | type | The aggregate type object to inspect. |
| [in] | index | The zero-based index of the member. |
infix_struct_member, or nullptr if the index is out of bounds.| [in] | type | The aggregate type object to inspect. |
| [in] | index | The zero-based index of the member. |
infix_struct_member, or nullptr if the index is out of bounds or the type is invalid. | c23_nodiscard size_t infix_type_get_member_count | ( | const infix_type * | type | ) |
Gets the number of members in a struct or union type.
| [in] | type | The aggregate type object to inspect. |
| [in] | type | The aggregate type object to inspect. Must have category INFIX_TYPE_STRUCT or INFIX_TYPE_UNION. |
| c23_nodiscard const char * infix_type_get_name | ( | const infix_type * | type | ) |
Gets the semantic alias of a type, if one exists.
| [in] | type | The type object to inspect. |
nullptr if the type is anonymous. | c23_nodiscard size_t infix_type_get_size | ( | const infix_type * | type | ) |
Gets the size of a type in bytes.
| [in] | type | The type object to inspect. |
| [in] | type | The type object to inspect. |
type is nullptr.