Reduct  v4.0.5-1-g4851deb
A functional and immutable language.
Loading...
Searching...
No Matches
Handle

Detailed Description

A handle is a lightweight reference to a Reduct item, with the ability to cache a numeric value or reference an item using Tagged Pointers (NaN Boxing).

64-bit Handle Bit Layout

The top 16 bits are used as a type tag. The remaining 48 bits represent the payload (either a 48-bit pointer or a shifted IEEE 754 double).

Tag (16 bits) Payload (48 bits)
0x0000 Item Pointer (reduct_item_t*)
0x0007...FFFF Number (Shifted IEEE 754 double)
See also
Wikipedia Tagged pointer

Macros

#define REDUCT_HANDLE_OFFSET_NUMBER   0x0007000000000000ULL
 Offset used for encoding doubles.
 
#define REDUCT_HANDLE_TAG_ITEM   0x0000000000000000ULL
 Tag for item handles.
 
#define REDUCT_HANDLE_MASK_TAG   0xFFFF000000000000ULL
 Mask for handle tag bits.
 
#define REDUCT_HANDLE_MASK_VAL   0x0000FFFFFFFFFFFFULL
 Mask for handle value bits.
 
#define REDUCT_HANDLE_MASK_PTR   REDUCT_HANDLE_MASK_VAL
 Mask for item pointer bits.
 
#define REDUCT_HANDLE_NUMBER_WIDTH   64
 The bit width used for shift operations on numbers.
 
#define REDUCT_HANDLE_FROM_NUMBER(_val)
 Create a handle from a number.
 
#define REDUCT_HANDLE_FROM_ITEM(_ptr)    ((reduct_handle_t){REDUCT_HANDLE_TAG_ITEM | ((uintptr_t)(void*)(_ptr) & REDUCT_HANDLE_MASK_PTR)})
 Create a handle from an item pointer.
 
#define REDUCT_HANDLE_FROM_ATOM(_atom)   REDUCT_HANDLE_FROM_ITEM(REDUCT_CONTAINER_OF(_atom, reduct_item_t, atom))
 Create a handle from an atom pointer.
 
#define REDUCT_HANDLE_FROM_LIST(_list)   REDUCT_HANDLE_FROM_ITEM(REDUCT_CONTAINER_OF(_list, reduct_item_t, list))
 Create a handle from a list pointer.
 
#define REDUCT_HANDLE_FROM_FUNCTION(_func)   REDUCT_HANDLE_FROM_ITEM(REDUCT_CONTAINER_OF(_func, reduct_item_t, function))
 Create a handle from a function pointer.
 
#define REDUCT_HANDLE_FROM_CLOSURE(_closure)    REDUCT_HANDLE_FROM_ITEM(REDUCT_CONTAINER_OF(_closure, reduct_item_t, closure))
 Create a handle from a closure pointer.
 
#define REDUCT_HANDLE_FROM_RVSDG_NODE(_node)    REDUCT_HANDLE_FROM_ITEM(REDUCT_CONTAINER_OF(_node, reduct_item_t, rvsdgNode))
 Create a handle from an IR node pointer.
 
#define REDUCT_HANDLE_FROM_RVSDG_EDGE(_edge)    REDUCT_HANDLE_FROM_ITEM(REDUCT_CONTAINER_OF(_edge, reduct_item_t, rvsdgEdge))
 Create a handle from an IR edge pointer.
 
#define REDUCT_HANDLE_FROM_BOOL(_reduct, _cond)   ((_cond) ? REDUCT_HANDLE_TRUE() : REDUCT_HANDLE_FALSE(_reduct))
 Create a boolean handle from a C condition.
 
#define REDUCT_HANDLE_FROM_FUTURE(_future)   REDUCT_HANDLE_FROM_ITEM(REDUCT_CONTAINER_OF(_future, reduct_item_t, future))
 Create a handle from a future pointer.
 
#define REDUCT_HANDLE_IS_NUMBER(_handle)   (((_handle)._value) >= REDUCT_HANDLE_OFFSET_NUMBER)
 Check if a handle is a number.
 
#define REDUCT_HANDLE_IS_NUMBER_SHAPED(_handle)
 Check if a handle is a number or references a number shaped item.
 
#define REDUCT_HANDLE_GET_TYPE_STRING(_handle)   (reduct_handle_type_string(reduct_handle_get_type(_handle)))
 Get the string representation of the type of the item referenced by the handle.
 
#define REDUCT_HANDLE_IS_NIL(_handle)   (REDUCT_HANDLE_IS_LIST(_handle) && REDUCT_HANDLE_TO_LIST(_handle)->length == 0)
 Check if a handle is nil (an empty list).
 
#define REDUCT_HANDLE_IS_EMPTY(_handle)    (REDUCT_HANDLE_IS_NIL(_handle) || (REDUCT_HANDLE_IS_ATOM(_handle) && REDUCT_HANDLE_TO_ATOM(_handle)->length == 0))
 Check if a handle is empty (nil or empty atom).
 
#define REDUCT_HANDLE_IS_ITEM(_handle)   ((((_handle)._value) & REDUCT_HANDLE_MASK_TAG) == REDUCT_HANDLE_TAG_ITEM)
 Check if a handle is an item.
 
#define REDUCT_HANDLE_IS_ATOM(_handle)    (REDUCT_HANDLE_IS_ITEM(_handle) && REDUCT_HANDLE_TO_ITEM(_handle)->type == REDUCT_ITEM_TYPE_ATOM)
 Check if a handle is an atom.
 
#define REDUCT_HANDLE_IS_LIST(_handle)    (REDUCT_HANDLE_IS_ITEM(_handle) && REDUCT_HANDLE_TO_ITEM(_handle)->type == REDUCT_ITEM_TYPE_LIST)
 Check if a handle is a list.
 
#define REDUCT_HANDLE_IS_FUNCTION(_handle)    (REDUCT_HANDLE_IS_ITEM(_handle) && REDUCT_HANDLE_TO_ITEM(_handle)->type == REDUCT_ITEM_TYPE_FUNCTION)
 Check if a handle is a function.
 
#define REDUCT_HANDLE_IS_CLOSURE(_handle)    (REDUCT_HANDLE_IS_ITEM(_handle) && REDUCT_HANDLE_TO_ITEM(_handle)->type == REDUCT_ITEM_TYPE_CLOSURE)
 Check if a handle is a closure.
 
#define REDUCT_HANDLE_IS_RVSDG_NODE(_handle)    (REDUCT_HANDLE_IS_ITEM(_handle) && REDUCT_HANDLE_TO_ITEM(_handle)->type == REDUCT_ITEM_TYPE_RVSDG_NODE)
 Check if a handle is an IR node.
 
#define REDUCT_HANDLE_IS_RVSDG_EDGE(_handle)    (REDUCT_HANDLE_IS_ITEM(_handle) && REDUCT_HANDLE_TO_ITEM(_handle)->type == REDUCT_ITEM_TYPE_RVSDG_EDGE)
 Check if a handle is an IR edge.
 
#define REDUCT_HANDLE_IS_FUTURE(_handle)    (REDUCT_HANDLE_IS_ITEM(_handle) && REDUCT_HANDLE_TO_ITEM(_handle)->type == REDUCT_ITEM_TYPE_FUTURE)
 Check if a handle is a future.
 
#define REDUCT_HANDLE_IS_LAMBDA(_handle)   (REDUCT_HANDLE_IS_FUNCTION(_handle) || REDUCT_HANDLE_IS_CLOSURE(_handle))
 Check if a handle is a lambda.
 
#define REDUCT_HANDLE_IS_NATIVE(_reduct, _handle)    (REDUCT_HANDLE_IS_ATOM(_handle) && reduct_atom_is_native(_reduct, REDUCT_HANDLE_TO_ATOM(_handle)))
 Check if a handle is a native function.
 
#define REDUCT_HANDLE_IS_INTRINSIC(_reduct, _handle)    (REDUCT_HANDLE_IS_ATOM(_handle) && reduct_atom_is_intrinsic(_reduct, REDUCT_HANDLE_TO_ATOM(_handle)))
 Check if a handle is an intrinsic function.
 
#define REDUCT_HANDLE_IS_CALLABLE(_reduct, _handle)    (REDUCT_HANDLE_IS_LAMBDA(_handle) || REDUCT_HANDLE_IS_NATIVE(_reduct, _handle))
 Check if a handle is callable.
 
#define REDUCT_HANDLE_IS_ATOM_LIKE(_handle)   (REDUCT_HANDLE_IS_NUMBER(_handle) || REDUCT_HANDLE_IS_ATOM(_handle))
 Check if a handle either is an atom, or could be represented by an atom item.
 
#define REDUCT_HANDLE_TO_NUMBER(_handle)
 Get the number value of a handle.
 
#define REDUCT_HANDLE_TO_ITEM(_handle)   ((reduct_item_t*)(void*)(((_handle)._value) & REDUCT_HANDLE_MASK_PTR))
 Get the item pointer of a handle.
 
#define REDUCT_HANDLE_TO_ATOM(_handle)   (&REDUCT_HANDLE_TO_ITEM(_handle)->atom)
 Get the atom pointer of a handle.
 
#define REDUCT_HANDLE_TO_LIST(_handle)   (&REDUCT_HANDLE_TO_ITEM(_handle)->list)
 Get the list pointer of a handle.
 
#define REDUCT_HANDLE_TO_FUNCTION(_handle)   (&REDUCT_HANDLE_TO_ITEM(_handle)->function)
 Get the function pointer of a handle.
 
#define REDUCT_HANDLE_TO_CLOSURE(_handle)   (&REDUCT_HANDLE_TO_ITEM(_handle)->closure)
 Get the closure pointer of a handle.
 
#define REDUCT_HANDLE_TO_RVSDG_NODE(_handle)   (&REDUCT_HANDLE_TO_ITEM(_handle)->rvsdgNode)
 Get the IR node pointer of a handle.
 
#define REDUCT_HANDLE_TO_RVSDG_EDGE(_handle)   (&REDUCT_HANDLE_TO_ITEM(_handle)->rvsdgEdge)
 Get the IR edge pointer of a handle.
 
#define REDUCT_HANDLE_TO_FUTURE(_handle)   (&REDUCT_HANDLE_TO_ITEM(_handle)->future)
 Get the future pointer of a handle.
 
#define REDUCT_HANDLE_TO_BOOL(_handle)   (REDUCT_HANDLE_IS_TRUTHY(_handle) ? true : false)
 Get the boolean value of a handle.
 
#define REDUCT_HANDLE_CREATE_LIST(_reduct, _length)   REDUCT_HANDLE_FROM_LIST(reduct_list_new(_reduct, _length))
 Create a list handle.
 
#define REDUCT_HANDLE_CREATE_HANDLES(_reduct, _count, _handles)    REDUCT_HANDLE_FROM_LIST(reduct_list_new_handles(_reduct, _count, _handles))
 Create a list handle from an array of handles.
 
#define REDUCT_HANDLE_CREATE_ALIST(_reduct, _count, ...)    REDUCT_HANDLE_FROM_LIST(reduct_list_new_alist(_reduct, _count, __VA_ARGS__))
 Create a list handle of pairs (key-value) from a variable number of pairs.
 
#define REDUCT_HANDLE_CREATE_ATOM(_reduct, _len)   REDUCT_HANDLE_FROM_ATOM(reduct_atom_new(_reduct, _len))
 Create an atom handle with a reserved size.
 
#define REDUCT_HANDLE_CREATE_STRING(_reduct, _str)    REDUCT_HANDLE_FROM_ATOM(reduct_atom_lookup(_reduct, _str, strlen(_str), REDUCT_ATOM_LOOKUP_QUOTED))
 Create an atom handle from a string.
 
#define REDUCT_HANDLE_CREATE_SYMBOL(_reduct, _str)    REDUCT_HANDLE_FROM_ATOM(reduct_atom_lookup(_reduct, _str, strlen(_str), REDUCT_ATOM_LOOKUP_NONE))
 Create an interned atom handle from a string.
 
#define REDUCT_HANDLE_CREATE_NUMBER(_reduct, _val)   REDUCT_HANDLE_FROM_ATOM(reduct_atom_new_number(_reduct, _val))
 Create an atom handle from a number.
 
#define REDUCT_HANDLE_CREATE_NATIVE(_reduct, _fn)   REDUCT_HANDLE_FROM_ATOM(reduct_atom_new_native(_reduct, _fn))
 Create an atom handle from a native function.
 
#define REDUCT_HANDLE_CREATE_FUTURE(_reduct, _callable, _argc, _argv)    REDUCT_HANDLE_FROM_FUTURE(reduct_future_new(_reduct, _callable, _argc, _argv))
 Create a future handle.
 
#define REDUCT_HANDLE_FOR_EACH(_handle, _list)   REDUCT_LIST_FOR_EACH(_handle, REDUCT_HANDLE_TO_LIST(_list))
 Macro for iterating over all elements in a list handle.
 
#define REDUCT_HANDLE_JOIN(_reduct, _handle)    (REDUCT_HANDLE_IS_FUTURE(_handle) ? reduct_future_join(_reduct, REDUCT_HANDLE_TO_FUTURE(_handle)) : (_handle))
 Get the value of the future referenced by the handle or the handle itself.
 
#define REDUCT_HANDLE_NIL(_reduct)   ((_reduct)->global->nil)
 Get the constant nil handle.
 
#define REDUCT_HANDLE_FALSE(_reduct)   REDUCT_HANDLE_NIL(_reduct)
 Get the constant false (nil) handle.
 
#define REDUCT_HANDLE_TRUE()   REDUCT_HANDLE_FROM_NUMBER(1.0)
 Constant true handle.
 
#define REDUCT_HANDLE_PI()   REDUCT_HANDLE_FROM_NUMBER(REDUCT_PI)
 Constant pi handle.
 
#define REDUCT_HANDLE_E()   REDUCT_HANDLE_FROM_NUMBER(REDUCT_E)
 Constant e handle.
 
#define REDUCT_HANDLE_INF()   REDUCT_HANDLE_FROM_NUMBER(REDUCT_INF)
 Constant infinity handle.
 
#define REDUCT_HANDLE_NAN()   REDUCT_HANDLE_FROM_NUMBER(REDUCT_NAN)
 Constant not a number handle.
 
#define REDUCT_HANDLE_COMPARE_FAST(_reduct, _a, _b, _op)
 Compare two handles using a given operator with a fast path for numbers.
 
#define REDUCT_HANDLE_ARITHMETIC_FAST(_reduct, _a, _b, _c, _op)
 Perform a arithmetic operation on two handles with a fast path for numbers.
 
#define REDUCT_HANDLE_DIV_FAST(_reduct, _a, _b, _c)
 Perform a division operation on two handles with a fast path for numbers.
 
#define REDUCT_HANDLE_MOD_FAST(_reduct, _a, _b, _c)
 Perform a modulo operation on two handles.
 
#define REDUCT_HANDLE_BITWISE_FAST(_reduct, _a, _b, _c, _op)
 Perform a bitwise operation on two handles.
 
#define REDUCT_HANDLE_IS_TRUTHY(_handle)    (!REDUCT_HANDLE_IS_LIST(_handle) || REDUCT_HANDLE_TO_LIST(_handle)->length != 0)
 Check if a handle is truthy.
 
#define REDUCT_HANDLE_RETAIN(_reduct, _handle)
 Retain a handle, preventing its referenced item from being collected by the garbage collector.
 
#define REDUCT_HANDLE_RELEASE(_reduct, _handle)
 Release a handle, allowing its referenced item to be collected by the garbage collector.
 
#define REDUCT_HANDLE_FREE(_reduct, _handle)
 Free the item that a handle is referencing.
 

Enumerations

enum  reduct_handle_type_t {
  REDUCT_HANDLE_TYPE_NONE = 0 , REDUCT_HANDLE_TYPE_NUMBER , REDUCT_HANDLE_TYPE_ATOM , REDUCT_HANDLE_TYPE_LIST ,
  REDUCT_HANDLE_TYPE_FUNCTION , REDUCT_HANDLE_TYPE_CLOSURE , REDUCT_HANDLE_TYPE_ARENA , REDUCT_HANDLE_TYPE_RVSDG_NODE ,
  REDUCT_HANDLE_TYPE_RVSDG_EDGE , REDUCT_HANDLE_TYPE_FUTURE , REDUCT_HANDLE_TYPE_UNKNOWN
}
 High-level handle types. More...
 

Functions

REDUCT_API reduct_handle_type_t reduct_handle_get_type (reduct_handle_t handle)
 Get the high-level type of a handle.
 
REDUCT_API const char * reduct_handle_type_string (reduct_handle_type_t type)
 Get the string name of a handle type.
 
REDUCT_API void reduct_handle_ensure_item (struct reduct *reduct, reduct_handle_t *handle)
 Ensure that a handle is an item handle.
 
static REDUCT_ALWAYS_INLINE struct reduct_item * reduct_handle_as_item (struct reduct *reduct, reduct_handle_t handle)
 Ensure that a handle is an item and return the pointer.
 
static REDUCT_ALWAYS_INLINE int64_t reduct_handle_as_int (struct reduct *reduct, reduct_handle_t handle)
 Retrieve the integer representation of the handle.
 
static REDUCT_ALWAYS_INLINE double reduct_handle_as_number (struct reduct *reduct, reduct_handle_t handle)
 Retrieve the number representation of the handle.
 
static REDUCT_ALWAYS_INLINE reduct_atom_treduct_handle_as_atom (struct reduct *reduct, reduct_handle_t handle)
 Retrieve the atom pointer of the handle.
 
REDUCT_API bool reduct_handle_is_equal (struct reduct *reduct, reduct_handle_t a, reduct_handle_t b)
 Check if two items are exactly equal string-wise or structurally.
 
REDUCT_API int64_t reduct_handle_compare (struct reduct *reduct, reduct_handle_t a, reduct_handle_t b)
 Compare two items for ordering (less than, equal, or greater than).
 
REDUCT_API void reduct_handle_atom_string (struct reduct *reduct, reduct_handle_t *handle, const char **outStr, size_t *outLen)
 Get the string pointer and length from an atom handle.
 
REDUCT_API reduct_handle_t reduct_handle_nth (struct reduct *reduct, reduct_handle_t handle, size_t index)
 Get the element at the specified index from a list or atom handle.
 
REDUCT_API size_t reduct_handle_len (struct reduct *reduct, reduct_handle_t handle)
 Get the length of a handle (list elements or atom characters).
 
REDUCT_API bool reduct_handle_is_str (struct reduct *reduct, reduct_handle_t handle, const char *str)
 Check if an atom handle is equal to a string.
 

Macro Definition Documentation

◆ REDUCT_HANDLE_OFFSET_NUMBER

#define REDUCT_HANDLE_OFFSET_NUMBER   0x0007000000000000ULL

Offset used for encoding doubles.

Definition at line 56 of file handle.h.

◆ REDUCT_HANDLE_TAG_ITEM

#define REDUCT_HANDLE_TAG_ITEM   0x0000000000000000ULL

Tag for item handles.

Definition at line 58 of file handle.h.

◆ REDUCT_HANDLE_MASK_TAG

#define REDUCT_HANDLE_MASK_TAG   0xFFFF000000000000ULL

Mask for handle tag bits.

Definition at line 60 of file handle.h.

◆ REDUCT_HANDLE_MASK_VAL

#define REDUCT_HANDLE_MASK_VAL   0x0000FFFFFFFFFFFFULL

Mask for handle value bits.

Definition at line 61 of file handle.h.

◆ REDUCT_HANDLE_MASK_PTR

#define REDUCT_HANDLE_MASK_PTR   REDUCT_HANDLE_MASK_VAL

Mask for item pointer bits.

Definition at line 62 of file handle.h.

◆ REDUCT_HANDLE_NUMBER_WIDTH

#define REDUCT_HANDLE_NUMBER_WIDTH   64

The bit width used for shift operations on numbers.

Definition at line 64 of file handle.h.

◆ REDUCT_HANDLE_FROM_NUMBER

#define REDUCT_HANDLE_FROM_NUMBER (   _val)
Value:
((reduct_handle_t){((union { \
double d; \
uint64_t u; \
}){.d = (_val)}) \
.u + \
#define REDUCT_HANDLE_OFFSET_NUMBER
Offset used for encoding doubles.
Definition handle.h:56
Handle type.
Definition defs.h:119

Create a handle from a number.

Parameters
_valThe number value.
Returns
The handle.

Definition at line 72 of file handle.h.

◆ REDUCT_HANDLE_FROM_ITEM

#define REDUCT_HANDLE_FROM_ITEM (   _ptr)     ((reduct_handle_t){REDUCT_HANDLE_TAG_ITEM | ((uintptr_t)(void*)(_ptr) & REDUCT_HANDLE_MASK_PTR)})

Create a handle from an item pointer.

Parameters
_ptrThe pointer to the reduct_item_t.
Returns
The handle.

Definition at line 86 of file handle.h.

◆ REDUCT_HANDLE_FROM_ATOM

#define REDUCT_HANDLE_FROM_ATOM (   _atom)    REDUCT_HANDLE_FROM_ITEM(REDUCT_CONTAINER_OF(_atom, reduct_item_t, atom))

Create a handle from an atom pointer.

Parameters
_atomThe pointer to the reduct_atom_t.
Returns
The handle.

Definition at line 95 of file handle.h.

◆ REDUCT_HANDLE_FROM_LIST

#define REDUCT_HANDLE_FROM_LIST (   _list)    REDUCT_HANDLE_FROM_ITEM(REDUCT_CONTAINER_OF(_list, reduct_item_t, list))

Create a handle from a list pointer.

Parameters
_listThe pointer to the reduct_list_t.
Returns
The handle.

Definition at line 103 of file handle.h.

◆ REDUCT_HANDLE_FROM_FUNCTION

#define REDUCT_HANDLE_FROM_FUNCTION (   _func)    REDUCT_HANDLE_FROM_ITEM(REDUCT_CONTAINER_OF(_func, reduct_item_t, function))

Create a handle from a function pointer.

Parameters
_funcThe pointer to the reduct_function_t.
Returns
The handle.

Definition at line 111 of file handle.h.

◆ REDUCT_HANDLE_FROM_CLOSURE

#define REDUCT_HANDLE_FROM_CLOSURE (   _closure)     REDUCT_HANDLE_FROM_ITEM(REDUCT_CONTAINER_OF(_closure, reduct_item_t, closure))

Create a handle from a closure pointer.

Parameters
_closureThe pointer to the reduct_closure_t.
Returns
The handle.

Definition at line 119 of file handle.h.

◆ REDUCT_HANDLE_FROM_RVSDG_NODE

#define REDUCT_HANDLE_FROM_RVSDG_NODE (   _node)     REDUCT_HANDLE_FROM_ITEM(REDUCT_CONTAINER_OF(_node, reduct_item_t, rvsdgNode))

Create a handle from an IR node pointer.

Parameters
_nodeThe pointer to the reduct_rvsdg_node_t.
Returns
The handle.

Definition at line 128 of file handle.h.

◆ REDUCT_HANDLE_FROM_RVSDG_EDGE

#define REDUCT_HANDLE_FROM_RVSDG_EDGE (   _edge)     REDUCT_HANDLE_FROM_ITEM(REDUCT_CONTAINER_OF(_edge, reduct_item_t, rvsdgEdge))

Create a handle from an IR edge pointer.

Parameters
_edgeThe pointer to the reduct_rvsdg_edge_t.
Returns
The handle.

Definition at line 137 of file handle.h.

◆ REDUCT_HANDLE_FROM_BOOL

#define REDUCT_HANDLE_FROM_BOOL (   _reduct,
  _cond 
)    ((_cond) ? REDUCT_HANDLE_TRUE() : REDUCT_HANDLE_FALSE(_reduct))

Create a boolean handle from a C condition.

Parameters
_reductPointer to the Reduct structure.
_condThe condition to evaluate.

Definition at line 146 of file handle.h.

◆ REDUCT_HANDLE_FROM_FUTURE

#define REDUCT_HANDLE_FROM_FUTURE (   _future)    REDUCT_HANDLE_FROM_ITEM(REDUCT_CONTAINER_OF(_future, reduct_item_t, future))

Create a handle from a future pointer.

Parameters
_futureThe pointer to the reduct_future_t.
Returns
The handle.

Definition at line 154 of file handle.h.

◆ REDUCT_HANDLE_IS_NUMBER

#define REDUCT_HANDLE_IS_NUMBER (   _handle)    (((_handle)._value) >= REDUCT_HANDLE_OFFSET_NUMBER)

Check if a handle is a number.

Parameters
_handlePointer to the handle.
Returns
Non-zero if the handle is a number, zero otherwise.

Definition at line 162 of file handle.h.

◆ REDUCT_HANDLE_IS_NUMBER_SHAPED

#define REDUCT_HANDLE_IS_NUMBER_SHAPED (   _handle)
Value:
(REDUCT_HANDLE_IS_NUMBER(_handle) || \
static REDUCT_ALWAYS_INLINE bool reduct_atom_is_number(reduct_atom_t *atom)
Check if an atom is number-shaped.
Definition atom.h:329
#define REDUCT_HANDLE_IS_NUMBER(_handle)
Check if a handle is a number.
Definition handle.h:162
#define REDUCT_HANDLE_TO_ATOM(_handle)
Get the atom pointer of a handle.
Definition handle.h:355
#define REDUCT_HANDLE_IS_ATOM(_handle)
Check if a handle is an atom.
Definition handle.h:228

Check if a handle is a number or references a number shaped item.

Parameters
_handlePointer to the handle.
Returns
Non-zero if the handle is number shaped, zero otherwise.

Definition at line 170 of file handle.h.

◆ REDUCT_HANDLE_GET_TYPE_STRING

#define REDUCT_HANDLE_GET_TYPE_STRING (   _handle)    (reduct_handle_type_string(reduct_handle_get_type(_handle)))

Get the string representation of the type of the item referenced by the handle.

Parameters
_handlePointer to the handle.
Returns
The string representation of the item type.

Definition at line 196 of file handle.h.

◆ REDUCT_HANDLE_IS_NIL

#define REDUCT_HANDLE_IS_NIL (   _handle)    (REDUCT_HANDLE_IS_LIST(_handle) && REDUCT_HANDLE_TO_LIST(_handle)->length == 0)

Check if a handle is nil (an empty list).

Parameters
_handlePointer to the handle.
Returns
Non-zero if the handle is nil, zero otherwise.

Definition at line 204 of file handle.h.

◆ REDUCT_HANDLE_IS_EMPTY

#define REDUCT_HANDLE_IS_EMPTY (   _handle)     (REDUCT_HANDLE_IS_NIL(_handle) || (REDUCT_HANDLE_IS_ATOM(_handle) && REDUCT_HANDLE_TO_ATOM(_handle)->length == 0))

Check if a handle is empty (nil or empty atom).

Parameters
_handlePointer to the handle.

Definition at line 211 of file handle.h.

◆ REDUCT_HANDLE_IS_ITEM

#define REDUCT_HANDLE_IS_ITEM (   _handle)    ((((_handle)._value) & REDUCT_HANDLE_MASK_TAG) == REDUCT_HANDLE_TAG_ITEM)

Check if a handle is an item.

Parameters
_handlePointer to the handle.
Returns
Non-zero if the handle is an item, zero otherwise.

Definition at line 220 of file handle.h.

◆ REDUCT_HANDLE_IS_ATOM

#define REDUCT_HANDLE_IS_ATOM (   _handle)     (REDUCT_HANDLE_IS_ITEM(_handle) && REDUCT_HANDLE_TO_ITEM(_handle)->type == REDUCT_ITEM_TYPE_ATOM)

Check if a handle is an atom.

Parameters
_handlePointer to the handle.
Returns
Non-zero if the handle is an atom, zero otherwise.

Definition at line 228 of file handle.h.

◆ REDUCT_HANDLE_IS_LIST

#define REDUCT_HANDLE_IS_LIST (   _handle)     (REDUCT_HANDLE_IS_ITEM(_handle) && REDUCT_HANDLE_TO_ITEM(_handle)->type == REDUCT_ITEM_TYPE_LIST)

Check if a handle is a list.

Parameters
_handlePointer to the handle.
Returns
Non-zero if the handle is a list, zero otherwise.

Definition at line 237 of file handle.h.

◆ REDUCT_HANDLE_IS_FUNCTION

#define REDUCT_HANDLE_IS_FUNCTION (   _handle)     (REDUCT_HANDLE_IS_ITEM(_handle) && REDUCT_HANDLE_TO_ITEM(_handle)->type == REDUCT_ITEM_TYPE_FUNCTION)

Check if a handle is a function.

Parameters
_handlePointer to the handle.
Returns
Non-zero if the handle is a function, zero otherwise.

Definition at line 246 of file handle.h.

◆ REDUCT_HANDLE_IS_CLOSURE

#define REDUCT_HANDLE_IS_CLOSURE (   _handle)     (REDUCT_HANDLE_IS_ITEM(_handle) && REDUCT_HANDLE_TO_ITEM(_handle)->type == REDUCT_ITEM_TYPE_CLOSURE)

Check if a handle is a closure.

Parameters
_handlePointer to the handle.
Returns
Non-zero if the handle is a closure, zero otherwise.

Definition at line 255 of file handle.h.

◆ REDUCT_HANDLE_IS_RVSDG_NODE

#define REDUCT_HANDLE_IS_RVSDG_NODE (   _handle)     (REDUCT_HANDLE_IS_ITEM(_handle) && REDUCT_HANDLE_TO_ITEM(_handle)->type == REDUCT_ITEM_TYPE_RVSDG_NODE)

Check if a handle is an IR node.

Parameters
_handlePointer to the handle.
Returns
Non-zero if the handle is an IR node, zero otherwise.

Definition at line 264 of file handle.h.

◆ REDUCT_HANDLE_IS_RVSDG_EDGE

#define REDUCT_HANDLE_IS_RVSDG_EDGE (   _handle)     (REDUCT_HANDLE_IS_ITEM(_handle) && REDUCT_HANDLE_TO_ITEM(_handle)->type == REDUCT_ITEM_TYPE_RVSDG_EDGE)

Check if a handle is an IR edge.

Parameters
_handlePointer to the handle.
Returns
Non-zero if the handle is an IR edge, zero otherwise.

Definition at line 273 of file handle.h.

◆ REDUCT_HANDLE_IS_FUTURE

#define REDUCT_HANDLE_IS_FUTURE (   _handle)     (REDUCT_HANDLE_IS_ITEM(_handle) && REDUCT_HANDLE_TO_ITEM(_handle)->type == REDUCT_ITEM_TYPE_FUTURE)

Check if a handle is a future.

Parameters
_handlePointer to the handle.

Definition at line 281 of file handle.h.

◆ REDUCT_HANDLE_IS_LAMBDA

#define REDUCT_HANDLE_IS_LAMBDA (   _handle)    (REDUCT_HANDLE_IS_FUNCTION(_handle) || REDUCT_HANDLE_IS_CLOSURE(_handle))

Check if a handle is a lambda.

Parameters
_handlePointer to the handle.
Returns
Non-zero if the handle is a lambda, zero otherwise.

Definition at line 290 of file handle.h.

◆ REDUCT_HANDLE_IS_NATIVE

#define REDUCT_HANDLE_IS_NATIVE (   _reduct,
  _handle 
)     (REDUCT_HANDLE_IS_ATOM(_handle) && reduct_atom_is_native(_reduct, REDUCT_HANDLE_TO_ATOM(_handle)))

Check if a handle is a native function.

Parameters
_handlePointer to the handle.
Returns
Non-zero if the handle is a native function, zero otherwise.

Definition at line 298 of file handle.h.

◆ REDUCT_HANDLE_IS_INTRINSIC

#define REDUCT_HANDLE_IS_INTRINSIC (   _reduct,
  _handle 
)     (REDUCT_HANDLE_IS_ATOM(_handle) && reduct_atom_is_intrinsic(_reduct, REDUCT_HANDLE_TO_ATOM(_handle)))

Check if a handle is an intrinsic function.

Parameters
_reductPointer to the Reduct structure.
_handlePointer to the handle.
Returns
Non-zero if the handle is an intrinsic function, zero otherwise.

Definition at line 308 of file handle.h.

◆ REDUCT_HANDLE_IS_CALLABLE

#define REDUCT_HANDLE_IS_CALLABLE (   _reduct,
  _handle 
)     (REDUCT_HANDLE_IS_LAMBDA(_handle) || REDUCT_HANDLE_IS_NATIVE(_reduct, _handle))

Check if a handle is callable.

Parameters
_handlePointer to the handle.
Returns
Non-zero if the handle is callable, zero otherwise.

Definition at line 317 of file handle.h.

◆ REDUCT_HANDLE_IS_ATOM_LIKE

#define REDUCT_HANDLE_IS_ATOM_LIKE (   _handle)    (REDUCT_HANDLE_IS_NUMBER(_handle) || REDUCT_HANDLE_IS_ATOM(_handle))

Check if a handle either is an atom, or could be represented by an atom item.

Parameters
_handlePointer to the handle.
Returns
Non-zero if the handle is atom-like, zero otherwise.

Definition at line 326 of file handle.h.

◆ REDUCT_HANDLE_TO_NUMBER

#define REDUCT_HANDLE_TO_NUMBER (   _handle)
Value:
(((union { \
uint64_t u; \
double d; \
}){.u = ((_handle)._value) - REDUCT_HANDLE_OFFSET_NUMBER}) \
.d)

Get the number value of a handle.

Parameters
_handlePointer to the handle.
Returns
The number value.

Definition at line 334 of file handle.h.

◆ REDUCT_HANDLE_TO_ITEM

#define REDUCT_HANDLE_TO_ITEM (   _handle)    ((reduct_item_t*)(void*)(((_handle)._value) & REDUCT_HANDLE_MASK_PTR))

Get the item pointer of a handle.

Parameters
_handlePointer to the handle.
Returns
The item pointer.

Definition at line 347 of file handle.h.

◆ REDUCT_HANDLE_TO_ATOM

#define REDUCT_HANDLE_TO_ATOM (   _handle)    (&REDUCT_HANDLE_TO_ITEM(_handle)->atom)

Get the atom pointer of a handle.

Parameters
_handlePointer to the handle.
Returns
The atom pointer.

Definition at line 355 of file handle.h.

◆ REDUCT_HANDLE_TO_LIST

#define REDUCT_HANDLE_TO_LIST (   _handle)    (&REDUCT_HANDLE_TO_ITEM(_handle)->list)

Get the list pointer of a handle.

Parameters
_handlePointer to the handle.
Returns
The list pointer.

Definition at line 363 of file handle.h.

◆ REDUCT_HANDLE_TO_FUNCTION

#define REDUCT_HANDLE_TO_FUNCTION (   _handle)    (&REDUCT_HANDLE_TO_ITEM(_handle)->function)

Get the function pointer of a handle.

Parameters
_handlePointer to the handle.
Returns
The function pointer.

Definition at line 371 of file handle.h.

◆ REDUCT_HANDLE_TO_CLOSURE

#define REDUCT_HANDLE_TO_CLOSURE (   _handle)    (&REDUCT_HANDLE_TO_ITEM(_handle)->closure)

Get the closure pointer of a handle.

Parameters
_handlePointer to the handle.
Returns
The closure pointer.

Definition at line 379 of file handle.h.

◆ REDUCT_HANDLE_TO_RVSDG_NODE

#define REDUCT_HANDLE_TO_RVSDG_NODE (   _handle)    (&REDUCT_HANDLE_TO_ITEM(_handle)->rvsdgNode)

Get the IR node pointer of a handle.

Parameters
_handlePointer to the handle.
Returns
The IR node pointer.

Definition at line 387 of file handle.h.

◆ REDUCT_HANDLE_TO_RVSDG_EDGE

#define REDUCT_HANDLE_TO_RVSDG_EDGE (   _handle)    (&REDUCT_HANDLE_TO_ITEM(_handle)->rvsdgEdge)

Get the IR edge pointer of a handle.

Parameters
_handlePointer to the handle.
Returns
The IR edge pointer.

Definition at line 395 of file handle.h.

◆ REDUCT_HANDLE_TO_FUTURE

#define REDUCT_HANDLE_TO_FUTURE (   _handle)    (&REDUCT_HANDLE_TO_ITEM(_handle)->future)

Get the future pointer of a handle.

Parameters
_handlePointer to the handle.

Definition at line 402 of file handle.h.

◆ REDUCT_HANDLE_TO_BOOL

#define REDUCT_HANDLE_TO_BOOL (   _handle)    (REDUCT_HANDLE_IS_TRUTHY(_handle) ? true : false)

Get the boolean value of a handle.

Parameters
_handlePointer to the handle.
Returns
The boolean value.

Definition at line 410 of file handle.h.

◆ REDUCT_HANDLE_CREATE_LIST

#define REDUCT_HANDLE_CREATE_LIST (   _reduct,
  _length 
)    REDUCT_HANDLE_FROM_LIST(reduct_list_new(_reduct, _length))

Create a list handle.

Parameters
_reductPointer to the Reduct structure.
_lengthThe length of the list.

Definition at line 418 of file handle.h.

◆ REDUCT_HANDLE_CREATE_HANDLES

#define REDUCT_HANDLE_CREATE_HANDLES (   _reduct,
  _count,
  _handles 
)     REDUCT_HANDLE_FROM_LIST(reduct_list_new_handles(_reduct, _count, _handles))

Create a list handle from an array of handles.

Parameters
_reductPointer to the Reduct structure.
_countThe number of handles.
_handlesThe array of handles.

Definition at line 427 of file handle.h.

◆ REDUCT_HANDLE_CREATE_ALIST

#define REDUCT_HANDLE_CREATE_ALIST (   _reduct,
  _count,
  ... 
)     REDUCT_HANDLE_FROM_LIST(reduct_list_new_alist(_reduct, _count, __VA_ARGS__))

Create a list handle of pairs (key-value) from a variable number of pairs.

Parameters
_reductPointer to the Reduct structure.
_countThe number of pairs.
...Each pair should be provided as a (const char*, reduct_handle_t).

Definition at line 437 of file handle.h.

◆ REDUCT_HANDLE_CREATE_ATOM

#define REDUCT_HANDLE_CREATE_ATOM (   _reduct,
  _len 
)    REDUCT_HANDLE_FROM_ATOM(reduct_atom_new(_reduct, _len))

Create an atom handle with a reserved size.

Parameters
_reductPointer to the Reduct structure.
_lenThe length of the buffer.

Definition at line 446 of file handle.h.

◆ REDUCT_HANDLE_CREATE_STRING

#define REDUCT_HANDLE_CREATE_STRING (   _reduct,
  _str 
)     REDUCT_HANDLE_FROM_ATOM(reduct_atom_lookup(_reduct, _str, strlen(_str), REDUCT_ATOM_LOOKUP_QUOTED))

Create an atom handle from a string.

Parameters
_reductPointer to the Reduct structure.
_strThe null-terminated string.

Definition at line 454 of file handle.h.

◆ REDUCT_HANDLE_CREATE_SYMBOL

#define REDUCT_HANDLE_CREATE_SYMBOL (   _reduct,
  _str 
)     REDUCT_HANDLE_FROM_ATOM(reduct_atom_lookup(_reduct, _str, strlen(_str), REDUCT_ATOM_LOOKUP_NONE))

Create an interned atom handle from a string.

Parameters
_reductPointer to the Reduct structure.
_strThe null-terminated string.

Definition at line 463 of file handle.h.

◆ REDUCT_HANDLE_CREATE_NUMBER

#define REDUCT_HANDLE_CREATE_NUMBER (   _reduct,
  _val 
)    REDUCT_HANDLE_FROM_ATOM(reduct_atom_new_number(_reduct, _val))

Create an atom handle from a number.

Parameters
_reductPointer to the Reduct structure.
_valThe number value.

Definition at line 472 of file handle.h.

◆ REDUCT_HANDLE_CREATE_NATIVE

#define REDUCT_HANDLE_CREATE_NATIVE (   _reduct,
  _fn 
)    REDUCT_HANDLE_FROM_ATOM(reduct_atom_new_native(_reduct, _fn))

Create an atom handle from a native function.

Parameters
_reductPointer to the Reduct structure.
_fnThe native function pointer.

Definition at line 480 of file handle.h.

◆ REDUCT_HANDLE_CREATE_FUTURE

#define REDUCT_HANDLE_CREATE_FUTURE (   _reduct,
  _callable,
  _argc,
  _argv 
)     REDUCT_HANDLE_FROM_FUTURE(reduct_future_new(_reduct, _callable, _argc, _argv))

Create a future handle.

Parameters
_reductPointer to the Reduct structure.
_callableThe callable handle.
_argcThe number of arguments.
_argvPointer to the arguments array.

Definition at line 490 of file handle.h.

◆ REDUCT_HANDLE_FOR_EACH

#define REDUCT_HANDLE_FOR_EACH (   _handle,
  _list 
)    REDUCT_LIST_FOR_EACH(_handle, REDUCT_HANDLE_TO_LIST(_list))

Macro for iterating over all elements in a list handle.

Parameters
_handleThe reduct_handle_t variable to store each element.
_listPointer to the list handle.

Definition at line 499 of file handle.h.

◆ REDUCT_HANDLE_JOIN

#define REDUCT_HANDLE_JOIN (   _reduct,
  _handle 
)     (REDUCT_HANDLE_IS_FUTURE(_handle) ? reduct_future_join(_reduct, REDUCT_HANDLE_TO_FUTURE(_handle)) : (_handle))

Get the value of the future referenced by the handle or the handle itself.

Parameters
_reductPointer to the Reduct structure.
_handleThe handle.
Returns
The result of the future if the handle is a future, otherwise the handle itself.

Definition at line 508 of file handle.h.

◆ REDUCT_HANDLE_NIL

#define REDUCT_HANDLE_NIL (   _reduct)    ((_reduct)->global->nil)

Get the constant nil handle.

Parameters
_reductPointer to the Reduct structure.

Definition at line 516 of file handle.h.

◆ REDUCT_HANDLE_FALSE

#define REDUCT_HANDLE_FALSE (   _reduct)    REDUCT_HANDLE_NIL(_reduct)

Get the constant false (nil) handle.

Parameters
_reductPointer to the Reduct structure.

Definition at line 522 of file handle.h.

◆ REDUCT_HANDLE_TRUE

#define REDUCT_HANDLE_TRUE ( )    REDUCT_HANDLE_FROM_NUMBER(1.0)

Constant true handle.

Definition at line 524 of file handle.h.

◆ REDUCT_HANDLE_PI

#define REDUCT_HANDLE_PI ( )    REDUCT_HANDLE_FROM_NUMBER(REDUCT_PI)

Constant pi handle.

Definition at line 526 of file handle.h.

◆ REDUCT_HANDLE_E

#define REDUCT_HANDLE_E ( )    REDUCT_HANDLE_FROM_NUMBER(REDUCT_E)

Constant e handle.

Definition at line 528 of file handle.h.

◆ REDUCT_HANDLE_INF

#define REDUCT_HANDLE_INF ( )    REDUCT_HANDLE_FROM_NUMBER(REDUCT_INF)

Constant infinity handle.

Definition at line 530 of file handle.h.

◆ REDUCT_HANDLE_NAN

#define REDUCT_HANDLE_NAN ( )    REDUCT_HANDLE_FROM_NUMBER(REDUCT_NAN)

Constant not a number handle.

Definition at line 532 of file handle.h.

◆ REDUCT_HANDLE_COMPARE_FAST

#define REDUCT_HANDLE_COMPARE_FAST (   _reduct,
  _a,
  _b,
  _op 
)
Value:
: (reduct_handle_compare(_reduct, (_a), (_b)) _op 0))
#define REDUCT_LIKELY(_x)
Definition defs.h:58
#define REDUCT_HANDLE_TO_NUMBER(_handle)
Get the number value of a handle.
Definition handle.h:334
REDUCT_API int64_t reduct_handle_compare(struct reduct *reduct, reduct_handle_t a, reduct_handle_t b)
Compare two items for ordering (less than, equal, or greater than).

Compare two handles using a given operator with a fast path for numbers.

Parameters
_reductPointer to the Reduct structure.
_aThe first handle.
_bThe second handle.
_opThe comparison operator (e.g., <, >, <=, >=, etc.).
Returns
The result of the comparison.

Definition at line 543 of file handle.h.

◆ REDUCT_HANDLE_ARITHMETIC_FAST

#define REDUCT_HANDLE_ARITHMETIC_FAST (   _reduct,
  _a,
  _b,
  _c,
  _op 
)
Value:
do \
{ \
reduct_handle_t _bVal = (_b); \
reduct_handle_t _cVal = (_c); \
double _bv, _cv; \
{ \
_bv = REDUCT_HANDLE_TO_NUMBER(_bVal); \
_cv = REDUCT_HANDLE_TO_NUMBER(_cVal); \
} \
else \
{ \
_bv = reduct_handle_as_number(_reduct, _bVal); \
_cv = reduct_handle_as_number(_reduct, _cVal); \
} \
*(_a) = REDUCT_HANDLE_FROM_NUMBER(_bv _op _cv); \
} while (0)
#define REDUCT_HANDLE_FROM_NUMBER(_val)
Create a handle from a number.
Definition handle.h:72
static REDUCT_ALWAYS_INLINE double reduct_handle_as_number(struct reduct *reduct, reduct_handle_t handle)
Retrieve the number representation of the handle.
Definition handle.h:785

Perform a arithmetic operation on two handles with a fast path for numbers.

Parameters
_reductPointer to the Reduct structure.
_aThe target handle.
_bThe first handle.
_cThe second handle.
_opThe arithmetic operator, (e.g., +, -, *, etc.)

Definition at line 557 of file handle.h.

◆ REDUCT_HANDLE_DIV_FAST

#define REDUCT_HANDLE_DIV_FAST (   _reduct,
  _a,
  _b,
  _c 
)
Value:
do \
{ \
reduct_handle_t _bVal = (_b); \
reduct_handle_t _cVal = (_c); \
double _bv, _cv; \
{ \
_bv = REDUCT_HANDLE_TO_NUMBER(_bVal); \
_cv = REDUCT_HANDLE_TO_NUMBER(_cVal); \
} \
else \
{ \
_bv = reduct_handle_as_number(_reduct, _bVal); \
_cv = reduct_handle_as_number(_reduct, _cVal); \
} \
if (REDUCT_UNLIKELY(_cv == 0.0)) \
{ \
REDUCT_ERROR_THROW(_reduct, "division by zero"); \
} \
*(_a) = REDUCT_HANDLE_FROM_NUMBER(_bv / _cv); \
} while (0)
#define REDUCT_UNLIKELY(_x)
Definition defs.h:59

Perform a division operation on two handles with a fast path for numbers.

Parameters
_reductPointer to the Reduct structure.
_aThe target handle.
_bThe first handle.
_cThe second handle.

Definition at line 584 of file handle.h.

◆ REDUCT_HANDLE_MOD_FAST

#define REDUCT_HANDLE_MOD_FAST (   _reduct,
  _a,
  _b,
  _c 
)
Value:
do \
{ \
reduct_handle_t _bVal = (_b); \
reduct_handle_t _cVal = (_c); \
double _bv, _cv; \
{ \
_bv = REDUCT_HANDLE_TO_NUMBER(_bVal); \
_cv = REDUCT_HANDLE_TO_NUMBER(_cVal); \
} \
else \
{ \
_bv = reduct_handle_as_number(_reduct, _bVal); \
_cv = reduct_handle_as_number(_reduct, _cVal); \
} \
if (REDUCT_UNLIKELY(_cv == 0.0)) \
{ \
REDUCT_ERROR_THROW(_reduct, "division by zero"); \
} \
*(_a) = REDUCT_HANDLE_FROM_NUMBER(fmod(_bv, _cv)); \
} while (0)

Perform a modulo operation on two handles.

Parameters
_reductPointer to the Reduct structure.
_aThe target handle.
_bThe first handle.
_cThe second handle.

Definition at line 615 of file handle.h.

◆ REDUCT_HANDLE_BITWISE_FAST

#define REDUCT_HANDLE_BITWISE_FAST (   _reduct,
  _a,
  _b,
  _c,
  _op 
)
Value:
do \
{ \
reduct_handle_t _bVal = (_b); \
reduct_handle_t _cVal = (_c); \
double _bv, _cv; \
{ \
_bv = REDUCT_HANDLE_TO_NUMBER(_bVal); \
_cv = REDUCT_HANDLE_TO_NUMBER(_cVal); \
} \
else \
{ \
_bv = reduct_handle_as_number(_reduct, _bVal); \
_cv = reduct_handle_as_number(_reduct, _cVal); \
} \
*(_a) = REDUCT_HANDLE_FROM_NUMBER((double)((int64_t)_bv _op(int64_t) _cv)); \
} while (0)

Perform a bitwise operation on two handles.

Parameters
_reductPointer to the Reduct structure.
_aThe target handle.
_bThe first handle.
_cThe second handle
_opThe bitwise operator, (e.g., &, |, ^, etc.)

Definition at line 647 of file handle.h.

◆ REDUCT_HANDLE_IS_TRUTHY

#define REDUCT_HANDLE_IS_TRUTHY (   _handle)     (!REDUCT_HANDLE_IS_LIST(_handle) || REDUCT_HANDLE_TO_LIST(_handle)->length != 0)

Check if a handle is truthy.

Parameters
_handlePointer to the handle.
Returns
true if the handle is truthy, false otherwise.

Definition at line 672 of file handle.h.

◆ REDUCT_HANDLE_RETAIN

#define REDUCT_HANDLE_RETAIN (   _reduct,
  _handle 
)
Value:
do \
{ \
reduct_handle_t _h = (_handle); \
{ \
reduct_item_retain(REDUCT_HANDLE_TO_ITEM(_h)); \
} \
} while (0)
#define REDUCT_HANDLE_IS_ITEM(_handle)
Check if a handle is an item.
Definition handle.h:220
#define REDUCT_HANDLE_TO_ITEM(_handle)
Get the item pointer of a handle.
Definition handle.h:347

Retain a handle, preventing its referenced item from being collected by the garbage collector.

Parameters
_reductPointer to the Reduct structure.
_handlePointer to the handle.

Definition at line 681 of file handle.h.

◆ REDUCT_HANDLE_RELEASE

#define REDUCT_HANDLE_RELEASE (   _reduct,
  _handle 
)
Value:
do \
{ \
reduct_handle_t _h = (_handle); \
{ \
reduct_item_release(REDUCT_HANDLE_TO_ITEM(_h)); \
} \
} while (0)

Release a handle, allowing its referenced item to be collected by the garbage collector.

Parameters
_reductPointer to the Reduct structure.
_handleThe handle.

Definition at line 697 of file handle.h.

◆ REDUCT_HANDLE_FREE

#define REDUCT_HANDLE_FREE (   _reduct,
  _handle 
)
Value:
do \
{ \
reduct_handle_t _h = (_handle); \
{ \
reduct_item_free((_reduct), REDUCT_HANDLE_TO_ITEM(_h)); \
} \
} while (0)

Free the item that a handle is referencing.

Intended to be used by the GC or when it is known that a handle has no more users and its item was allocated by the current thread.

Parameters
_reductPointer to the Reduct structure.
_handleThe handle to the item.

Definition at line 716 of file handle.h.

Enumeration Type Documentation

◆ reduct_handle_type_t

High-level handle types.

Enumerator
REDUCT_HANDLE_TYPE_NONE 

Invalid type.

REDUCT_HANDLE_TYPE_NUMBER 

Handle is a number or references a number shaped atom.

REDUCT_HANDLE_TYPE_ATOM 

Handle is a reference to an atom.

REDUCT_HANDLE_TYPE_LIST 

Handle is a reference to a list.

REDUCT_HANDLE_TYPE_FUNCTION 

Handle is a reference to a function.

REDUCT_HANDLE_TYPE_CLOSURE 

Handle is a reference to a closure.

REDUCT_HANDLE_TYPE_ARENA 

Handle is a reference to an arena.

REDUCT_HANDLE_TYPE_RVSDG_NODE 

Handle is a reference to an IR node.

REDUCT_HANDLE_TYPE_RVSDG_EDGE 

Handle is a reference to an IR edge.

REDUCT_HANDLE_TYPE_FUTURE 

Handle is a reference to a future.

REDUCT_HANDLE_TYPE_UNKNOWN 

Handle is corrupt or otherwise invalid.

Definition at line 41 of file handle.h.

Function Documentation

◆ reduct_handle_get_type()

REDUCT_API reduct_handle_type_t reduct_handle_get_type ( reduct_handle_t  handle)

Get the high-level type of a handle.

Parameters
handlePointer to the handle.
Returns
The type of the handle.

◆ reduct_handle_type_string()

REDUCT_API const char * reduct_handle_type_string ( reduct_handle_type_t  type)

Get the string name of a handle type.

Parameters
typeThe handle type.
Returns
A constant string representing the type.

◆ reduct_handle_ensure_item()

REDUCT_API void reduct_handle_ensure_item ( struct reduct *  reduct,
reduct_handle_t handle 
)

Ensure that a handle is an item handle.

If the handle is a number, it will be upgraded to an item handle by looking up a corresponding atom.

Parameters
reductPointer to the Reduct structure.
handleThe handle to ensure.
Here is the caller graph for this function:

◆ reduct_handle_as_item()

static REDUCT_ALWAYS_INLINE struct reduct_item * reduct_handle_as_item ( struct reduct *  reduct,
reduct_handle_t  handle 
)
inlinestatic

Ensure that a handle is an item and return the pointer.

Parameters
reductPointer to the Reduct structure.
handleThe handle.
Returns
The item pointer.

Definition at line 743 of file handle.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reduct_handle_as_int()

static REDUCT_ALWAYS_INLINE int64_t reduct_handle_as_int ( struct reduct *  reduct,
reduct_handle_t  handle 
)
inlinestatic

Retrieve the integer representation of the handle.

Will cast number values to integers or retrieve number values stored within an atom referenced by the handle if the handle is itself not a number.

Parameters
reductPointer to the Reduct structure.
handleThe handle.
Returns
The integer value.

Definition at line 763 of file handle.h.

Here is the call graph for this function:

◆ reduct_handle_as_number()

static REDUCT_ALWAYS_INLINE double reduct_handle_as_number ( struct reduct *  reduct,
reduct_handle_t  handle 
)
inlinestatic

Retrieve the number representation of the handle.

Will retrieve number values stored within an atom referenced by the handle if the handle is itself not a number.

Parameters
reductPointer to the Reduct structure.
handleThe handle.
Returns
The number value.

Definition at line 785 of file handle.h.

Here is the call graph for this function:

◆ reduct_handle_as_atom()

static REDUCT_ALWAYS_INLINE reduct_atom_t * reduct_handle_as_atom ( struct reduct *  reduct,
reduct_handle_t  handle 
)
inlinestatic

Retrieve the atom pointer of the handle.

Will upgrade the handle to an item handle if it is a number.

Parameters
reductPointer to the Reduct structure.
handleThe handle.
Returns
The atom pointer.

Definition at line 806 of file handle.h.

Here is the call graph for this function:

◆ reduct_handle_is_equal()

REDUCT_API bool reduct_handle_is_equal ( struct reduct *  reduct,
reduct_handle_t  a,
reduct_handle_t  b 
)

Check if two items are exactly equal string-wise or structurally.

Parameters
reductPointer to the Reduct structure.
aThe first handle, will be upgraded.
bThe second handle, will be upgraded.
Returns
true if the items are strictly equal, false otherwise.

◆ reduct_handle_compare()

REDUCT_API int64_t reduct_handle_compare ( struct reduct *  reduct,
reduct_handle_t  a,
reduct_handle_t  b 
)

Compare two items for ordering (less than, equal, or greater than).

Useful for sorting or range checks.

Parameters
reductPointer to the Reduct structure.
aThe first handle.
bThe second handle.
Returns
A negative value if a < b, zero if a == b, and a positive value if a > b.

◆ reduct_handle_atom_string()

REDUCT_API void reduct_handle_atom_string ( struct reduct *  reduct,
reduct_handle_t handle,
const char **  outStr,
size_t *  outLen 
)

Get the string pointer and length from an atom handle.

Parameters
reductPointer to the Reduct structure.
handleThe handle to the atom.
outStrPointer to store the string pointer, not NULL terminated.
outLenPointer to store the string length.

◆ reduct_handle_nth()

REDUCT_API reduct_handle_t reduct_handle_nth ( struct reduct *  reduct,
reduct_handle_t  handle,
size_t  index 
)

Get the element at the specified index from a list or atom handle.

For lists, returns the nth element. For atoms, returns the nth character as a string handle.

Parameters
reductPointer to the Reduct structure.
handleThe handle.
indexThe index.
Returns
The element handle.

◆ reduct_handle_len()

REDUCT_API size_t reduct_handle_len ( struct reduct *  reduct,
reduct_handle_t  handle 
)

Get the length of a handle (list elements or atom characters).

Parameters
reductPointer to the Reduct structure.
handleThe handle.
Returns
The length.

◆ reduct_handle_is_str()

REDUCT_API bool reduct_handle_is_str ( struct reduct *  reduct,
reduct_handle_t  handle,
const char *  str 
)

Check if an atom handle is equal to a string.

Parameters
reductPointer to the Reduct structure.
handleThe atom handle.
strThe string to compare.
Returns
true if the atom is equal to the string, false otherwise.