infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
Type System

Structures and functions for describing C data types. More...

Collaboration diagram for Type System:

Files

file  types.c
 Implements the public API for creating and managing type descriptions.
 

Classes

struct  infix_type_t
 The central structure for describing any data type in the FFI system. More...
 
struct  infix_struct_member_t
 Describes a single member of an aggregate type (struct or union). More...
 
struct  infix_function_argument_t
 Describes a single argument to a function, pairing an optional name with its type. More...
 

Typedefs

typedef struct infix_type_t infix_type
 The central structure for describing any data type in the FFI system.
 
typedef struct infix_struct_member_t infix_struct_member
 Describes a single member of an aggregate type (struct or union).
 
typedef struct infix_function_argument_t infix_function_argument
 Describes a single argument of a function type, including its optional name.
 
typedef struct infix_forward_t infix_forward_t
 An opaque handle to a JIT-compiled forward-call trampoline.
 
typedef struct infix_reverse_t infix_reverse_t
 An opaque handle to the context of a reverse-call trampoline (callback).
 
typedef infix_reverse_t infix_context_t
 A clear alias for infix_reverse_t, intended for use in callback handler signatures.
 
typedef struct infix_arena_t infix_arena_t
 An opaque handle to a memory arena for fast, temporary allocations.
 
typedef struct infix_library_t infix_library_t
 An opaque handle to a shared library.
 
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 supported by the FFI system. 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 specific primitive C types supported by the FFI system. More...
 
enum  infix_aggregate_category_t { INFIX_AGGREGATE_STRUCT , INFIX_AGGREGATE_UNION }
 Distinguishes between struct and union for named references. More...
 

Functions

c23_nodiscard infix_typeinfix_type_create_primitive (infix_primitive_type_id)
 Creates an infix_type descriptor for a primitive C type.
 
c23_nodiscard infix_typeinfix_type_create_pointer (void)
 Creates an infix_type descriptor for a generic void* pointer.
 
c23_nodiscard infix_status infix_type_create_pointer_to (infix_arena_t *, infix_type **, infix_type *)
 Creates an infix_type for a pointer to a specific type from an arena.
 
c23_nodiscard infix_typeinfix_type_create_void (void)
 Creates an infix_type 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 infix_type for a struct from an arena.
 
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 infix_type for a packed struct from an arena.
 
c23_nodiscard infix_status infix_type_create_union (infix_arena_t *, infix_type **, infix_struct_member *, size_t)
 Creates a new infix_type for a union from an arena.
 
c23_nodiscard infix_status infix_type_create_array (infix_arena_t *, infix_type **, infix_type *, size_t)
 Creates a new infix_type for a fixed-size array from an arena.
 
c23_nodiscard infix_status infix_type_create_enum (infix_arena_t *, infix_type **, infix_type *)
 Creates a new infix_type for an enum from an arena.
 
c23_nodiscard infix_status infix_type_create_named_reference (infix_arena_t *, infix_type **, const char *, infix_aggregate_category_t)
 Creates a new infix_type for a named reference from an arena.
 
c23_nodiscard infix_status infix_type_create_complex (infix_arena_t *, infix_type **, infix_type *)
 Creates a new infix_type for a _Complex number from an arena.
 
c23_nodiscard infix_status infix_type_create_vector (infix_arena_t *, infix_type **, infix_type *, size_t)
 Creates a new infix_type for a SIMD vector from an arena.
 
infix_struct_member infix_type_create_member (const char *, infix_type *, size_t)
 A factory function to create an infix_struct_member.
 

Detailed Description

Structures and functions for describing C data types.

Typedef Documentation

◆ infix_arena_t

typedef struct infix_arena_t infix_arena_t

An opaque handle to a memory arena for fast, temporary allocations.

◆ infix_context_t

A clear alias for infix_reverse_t, intended for use in callback handler signatures.

◆ infix_forward_t

An opaque handle to a JIT-compiled forward-call trampoline.

◆ infix_function_argument

Describes a single argument of a function type, including its optional name.

◆ infix_library_t

An opaque handle to a shared library.

◆ infix_registry_t

An opaque handle to a named type registry.

◆ infix_reverse_t

An opaque handle to the context of a reverse-call trampoline (callback).

◆ infix_struct_member

Describes a single member of an aggregate type (struct or union).

◆ infix_type

typedef struct infix_type_t infix_type

The central structure for describing any data type in the FFI system.

Enumeration Type Documentation

◆ infix_aggregate_category_t

Distinguishes between struct and union for named references.

Enumerator
INFIX_AGGREGATE_STRUCT 
INFIX_AGGREGATE_UNION 

◆ infix_primitive_type_id

Enumerates the specific primitive C types supported by the FFI system.

See also
https://en.wikipedia.org/wiki/C_data_types
Enumerator
INFIX_PRIMITIVE_BOOL 

bool or _Bool

INFIX_PRIMITIVE_UINT8 

unsigned char, uint8_t

INFIX_PRIMITIVE_SINT8 

signed char, int8_t

INFIX_PRIMITIVE_UINT16 

unsigned short, uint16_t

INFIX_PRIMITIVE_SINT16 

signed short, int16_t

INFIX_PRIMITIVE_UINT32 

unsigned int, uint32_t

INFIX_PRIMITIVE_SINT32 

signed int, int32_t

INFIX_PRIMITIVE_UINT64 

unsigned long long, uint64_t

INFIX_PRIMITIVE_SINT64 

signed long long, int64_t

INFIX_PRIMITIVE_UINT128 

__uint128_t (GCC/Clang specific)

INFIX_PRIMITIVE_SINT128 

__int128_t (GCC/Clang specific)

INFIX_PRIMITIVE_FLOAT 

float

INFIX_PRIMITIVE_DOUBLE 

double

INFIX_PRIMITIVE_LONG_DOUBLE 

long double

◆ infix_type_category

Enumerates the fundamental categories of types supported by the FFI system.

Enumerator
INFIX_TYPE_PRIMITIVE 

A built-in type like int, float, double.

INFIX_TYPE_POINTER 

A generic void* pointer type.

INFIX_TYPE_STRUCT 

A user-defined structure (struct).

INFIX_TYPE_UNION 

A user-defined union (union).

INFIX_TYPE_ARRAY 

A fixed-size array.

INFIX_TYPE_REVERSE_TRAMPOLINE 

A callback wrapper.

INFIX_TYPE_ENUM 

A C-style enumeration, with an underlying integer type.

INFIX_TYPE_COMPLEX 

A _Complex number type.

INFIX_TYPE_VECTOR 

A SIMD vector type.

INFIX_TYPE_NAMED_REFERENCE 

A reference to a named type (e.g., struct<Node>).

INFIX_TYPE_VOID 

The void type, used for function returns with no value.

Function Documentation

◆ infix_type_create_array()

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 infix_type for a fixed-size array from an arena.

Parameters
arenaThe arena from which to allocate.
[out]out_typeOn success, this will point to the newly created infix_type.
element_typeAn infix_type describing the type of each element in the array.
num_elementsThe number of elements in the array.
Returns
INFIX_SUCCESS on success, or an error code on failure.

◆ infix_type_create_complex()

c23_nodiscard infix_status infix_type_create_complex ( infix_arena_t arena,
infix_type **  out_type,
infix_type base_type 
)

Creates a new infix_type for a _Complex number from an arena.

Parameters
arenaThe arena from which to allocate.
[out]out_typeOn success, this will point to the newly created infix_type.
base_typeThe floating-point infix_type of the real and imaginary parts.
Returns
INFIX_SUCCESS on success.

◆ infix_type_create_enum()

c23_nodiscard infix_status infix_type_create_enum ( infix_arena_t arena,
infix_type **  out_type,
infix_type underlying_type 
)

Creates a new infix_type for an enum from an arena.

Parameters
arenaThe arena from which to allocate.
[out]out_typeOn success, will point to the newly created infix_type.
underlying_typeThe integer infix_type that this enum is based on.
Returns
INFIX_SUCCESS on success, or an error code on failure.

◆ infix_type_create_member()

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.

Parameters
nameThe member's name (for debugging; can be nullptr).
typeA pointer to the member's infix_type.
offsetThe byte offset of the member, obtained via the offsetof macro.
Returns
An initialized infix_struct_member.

◆ infix_type_create_named_reference()

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 new infix_type for a named reference from an arena.

Parameters
arenaThe arena from which to allocate.
[out]out_typeOn success, will point to the newly created infix_type.
nameThe name of the type being referenced.
aggregate_categoryDistinguishes between struct and union for the reference.
Returns
INFIX_SUCCESS on success, or an error code on failure.
Note
A type graph containing a named reference is "unresolved".

◆ infix_type_create_packed_struct()

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 infix_type for a packed struct from an arena.

Parameters
arenaThe arena from which to allocate.
[out]out_typeOn success, this will point to the newly created infix_type.
total_sizeThe exact size of the packed struct in bytes.
alignmentThe alignment of the packed struct in bytes (often 1).
membersAn array of infix_struct_member describing each member.
num_membersThe number of elements in the members array.
Returns
INFIX_SUCCESS on success, or an error code on failure.

◆ infix_type_create_pointer()

c23_nodiscard infix_type * infix_type_create_pointer ( void  )

Creates an infix_type descriptor for a generic void* pointer.

Returns
A pointer to the static infix_type descriptor for a pointer.
Warning
Do not free the returned pointer.

◆ infix_type_create_pointer_to()

c23_nodiscard infix_status infix_type_create_pointer_to ( infix_arena_t arena,
infix_type **  out_type,
infix_type pointee_type 
)

Creates an infix_type for a pointer to a specific type from an arena.

Parameters
arenaThe arena from which to allocate memory for the new pointer type.
[out]out_typeOn success, this will point to the newly created infix_type.
pointee_typeAn infix_type describing the type the pointer points to.
Returns
INFIX_SUCCESS on success, or an error code on failure.

◆ infix_type_create_primitive()

c23_nodiscard infix_type * infix_type_create_primitive ( infix_primitive_type_id  id)

Creates an infix_type descriptor for a primitive C type.

Parameters
idThe enumerator for the desired primitive type (e.g., INFIX_PRIMITIVE_SINT32).
Returns
A pointer to the static infix_type descriptor.
Warning
The returned pointer points to a static global and must NOT be freed.

◆ infix_type_create_struct()

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 infix_type for a struct from an arena.

Parameters
arenaThe arena from which to allocate memory for the new type.
[out]out_typeOn success, this will point to the newly created infix_type.
membersAn array of infix_struct_member describing each member.
num_membersThe number of elements in the members array.
Returns
INFIX_SUCCESS on success, or an error code on failure.

◆ infix_type_create_union()

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 infix_type for a union from an arena.

Parameters
arenaThe arena from which to allocate.
[out]out_typeOn success, this will point to the newly created infix_type.
membersAn array of infix_struct_member describing each member of the union.
num_membersThe number of elements in the members array.
Returns
INFIX_SUCCESS on success, or an error code on failure.

◆ infix_type_create_vector()

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 infix_type for a SIMD vector from an arena.

Parameters
arenaThe arena from which to allocate.
[out]out_typeOn success, this will point to the newly created infix_type.
element_typeThe primitive infix_type of the vector's elements.
num_elementsThe number of elements in the vector.
Returns
INFIX_SUCCESS on success.

◆ infix_type_create_void()

c23_nodiscard infix_type * infix_type_create_void ( void  )

Creates an infix_type descriptor for the void type.

Returns
A pointer to the static infix_type for void.
Warning
Do not free the returned pointer.