|
Reduct
v4.0.5-1-g4851deb
A functional and immutable language.
|
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).
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) |
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_t * | reduct_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. | |
| #define REDUCT_HANDLE_OFFSET_NUMBER 0x0007000000000000ULL |
| #define REDUCT_HANDLE_TAG_ITEM 0x0000000000000000ULL |
| #define REDUCT_HANDLE_MASK_TAG 0xFFFF000000000000ULL |
| #define REDUCT_HANDLE_MASK_VAL 0x0000FFFFFFFFFFFFULL |
| #define REDUCT_HANDLE_MASK_PTR REDUCT_HANDLE_MASK_VAL |
| #define REDUCT_HANDLE_NUMBER_WIDTH 64 |
| #define REDUCT_HANDLE_FROM_NUMBER | ( | _val | ) |
Create a handle from a number.
| _val | The number value. |
| #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.
| _ptr | The pointer to the reduct_item_t. |
| #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.
| _atom | The pointer to the reduct_atom_t. |
| #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.
| _list | The pointer to the reduct_list_t. |
| #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.
| _func | The pointer to the reduct_function_t. |
| #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.
| _closure | The pointer to the reduct_closure_t. |
| #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.
| _node | The pointer to the reduct_rvsdg_node_t. |
| #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.
| _edge | The pointer to the reduct_rvsdg_edge_t. |
| #define REDUCT_HANDLE_FROM_BOOL | ( | _reduct, | |
| _cond | |||
| ) | ((_cond) ? REDUCT_HANDLE_TRUE() : REDUCT_HANDLE_FALSE(_reduct)) |
| #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.
| _future | The pointer to the reduct_future_t. |
| #define REDUCT_HANDLE_IS_NUMBER | ( | _handle | ) | (((_handle)._value) >= REDUCT_HANDLE_OFFSET_NUMBER) |
| #define REDUCT_HANDLE_IS_NUMBER_SHAPED | ( | _handle | ) |
Check if a handle is a number or references a number shaped item.
| _handle | Pointer to the handle. |
| #define REDUCT_HANDLE_GET_TYPE_STRING | ( | _handle | ) | (reduct_handle_type_string(reduct_handle_get_type(_handle))) |
| #define REDUCT_HANDLE_IS_NIL | ( | _handle | ) | (REDUCT_HANDLE_IS_LIST(_handle) && REDUCT_HANDLE_TO_LIST(_handle)->length == 0) |
| #define REDUCT_HANDLE_IS_EMPTY | ( | _handle | ) | (REDUCT_HANDLE_IS_NIL(_handle) || (REDUCT_HANDLE_IS_ATOM(_handle) && REDUCT_HANDLE_TO_ATOM(_handle)->length == 0)) |
| #define REDUCT_HANDLE_IS_ITEM | ( | _handle | ) | ((((_handle)._value) & REDUCT_HANDLE_MASK_TAG) == REDUCT_HANDLE_TAG_ITEM) |
| #define REDUCT_HANDLE_IS_ATOM | ( | _handle | ) | (REDUCT_HANDLE_IS_ITEM(_handle) && REDUCT_HANDLE_TO_ITEM(_handle)->type == REDUCT_ITEM_TYPE_ATOM) |
| #define REDUCT_HANDLE_IS_LIST | ( | _handle | ) | (REDUCT_HANDLE_IS_ITEM(_handle) && REDUCT_HANDLE_TO_ITEM(_handle)->type == REDUCT_ITEM_TYPE_LIST) |
| #define REDUCT_HANDLE_IS_FUNCTION | ( | _handle | ) | (REDUCT_HANDLE_IS_ITEM(_handle) && REDUCT_HANDLE_TO_ITEM(_handle)->type == REDUCT_ITEM_TYPE_FUNCTION) |
| #define REDUCT_HANDLE_IS_CLOSURE | ( | _handle | ) | (REDUCT_HANDLE_IS_ITEM(_handle) && REDUCT_HANDLE_TO_ITEM(_handle)->type == REDUCT_ITEM_TYPE_CLOSURE) |
| #define REDUCT_HANDLE_IS_RVSDG_NODE | ( | _handle | ) | (REDUCT_HANDLE_IS_ITEM(_handle) && REDUCT_HANDLE_TO_ITEM(_handle)->type == REDUCT_ITEM_TYPE_RVSDG_NODE) |
| #define REDUCT_HANDLE_IS_RVSDG_EDGE | ( | _handle | ) | (REDUCT_HANDLE_IS_ITEM(_handle) && REDUCT_HANDLE_TO_ITEM(_handle)->type == REDUCT_ITEM_TYPE_RVSDG_EDGE) |
| #define REDUCT_HANDLE_IS_FUTURE | ( | _handle | ) | (REDUCT_HANDLE_IS_ITEM(_handle) && REDUCT_HANDLE_TO_ITEM(_handle)->type == REDUCT_ITEM_TYPE_FUTURE) |
| #define REDUCT_HANDLE_IS_LAMBDA | ( | _handle | ) | (REDUCT_HANDLE_IS_FUNCTION(_handle) || REDUCT_HANDLE_IS_CLOSURE(_handle)) |
| #define REDUCT_HANDLE_IS_NATIVE | ( | _reduct, | |
| _handle | |||
| ) | (REDUCT_HANDLE_IS_ATOM(_handle) && reduct_atom_is_native(_reduct, REDUCT_HANDLE_TO_ATOM(_handle))) |
| #define REDUCT_HANDLE_IS_INTRINSIC | ( | _reduct, | |
| _handle | |||
| ) | (REDUCT_HANDLE_IS_ATOM(_handle) && reduct_atom_is_intrinsic(_reduct, REDUCT_HANDLE_TO_ATOM(_handle))) |
| #define REDUCT_HANDLE_IS_CALLABLE | ( | _reduct, | |
| _handle | |||
| ) | (REDUCT_HANDLE_IS_LAMBDA(_handle) || REDUCT_HANDLE_IS_NATIVE(_reduct, _handle)) |
| #define REDUCT_HANDLE_IS_ATOM_LIKE | ( | _handle | ) | (REDUCT_HANDLE_IS_NUMBER(_handle) || REDUCT_HANDLE_IS_ATOM(_handle)) |
| #define REDUCT_HANDLE_TO_NUMBER | ( | _handle | ) |
Get the number value of a handle.
| _handle | Pointer to the handle. |
| #define REDUCT_HANDLE_TO_ITEM | ( | _handle | ) | ((reduct_item_t*)(void*)(((_handle)._value) & REDUCT_HANDLE_MASK_PTR)) |
| #define REDUCT_HANDLE_TO_ATOM | ( | _handle | ) | (&REDUCT_HANDLE_TO_ITEM(_handle)->atom) |
| #define REDUCT_HANDLE_TO_LIST | ( | _handle | ) | (&REDUCT_HANDLE_TO_ITEM(_handle)->list) |
| #define REDUCT_HANDLE_TO_FUNCTION | ( | _handle | ) | (&REDUCT_HANDLE_TO_ITEM(_handle)->function) |
| #define REDUCT_HANDLE_TO_CLOSURE | ( | _handle | ) | (&REDUCT_HANDLE_TO_ITEM(_handle)->closure) |
| #define REDUCT_HANDLE_TO_RVSDG_NODE | ( | _handle | ) | (&REDUCT_HANDLE_TO_ITEM(_handle)->rvsdgNode) |
| #define REDUCT_HANDLE_TO_RVSDG_EDGE | ( | _handle | ) | (&REDUCT_HANDLE_TO_ITEM(_handle)->rvsdgEdge) |
| #define REDUCT_HANDLE_TO_FUTURE | ( | _handle | ) | (&REDUCT_HANDLE_TO_ITEM(_handle)->future) |
| #define REDUCT_HANDLE_TO_BOOL | ( | _handle | ) | (REDUCT_HANDLE_IS_TRUTHY(_handle) ? true : false) |
| #define REDUCT_HANDLE_CREATE_LIST | ( | _reduct, | |
| _length | |||
| ) | REDUCT_HANDLE_FROM_LIST(reduct_list_new(_reduct, _length)) |
| #define REDUCT_HANDLE_CREATE_HANDLES | ( | _reduct, | |
| _count, | |||
| _handles | |||
| ) | REDUCT_HANDLE_FROM_LIST(reduct_list_new_handles(_reduct, _count, _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.
| _reduct | Pointer to the Reduct structure. |
| _count | The number of pairs. |
| ... | Each pair should be provided as a (const char*, reduct_handle_t). |
| #define REDUCT_HANDLE_CREATE_ATOM | ( | _reduct, | |
| _len | |||
| ) | REDUCT_HANDLE_FROM_ATOM(reduct_atom_new(_reduct, _len)) |
| #define REDUCT_HANDLE_CREATE_STRING | ( | _reduct, | |
| _str | |||
| ) | REDUCT_HANDLE_FROM_ATOM(reduct_atom_lookup(_reduct, _str, strlen(_str), REDUCT_ATOM_LOOKUP_QUOTED)) |
| #define REDUCT_HANDLE_CREATE_SYMBOL | ( | _reduct, | |
| _str | |||
| ) | REDUCT_HANDLE_FROM_ATOM(reduct_atom_lookup(_reduct, _str, strlen(_str), REDUCT_ATOM_LOOKUP_NONE)) |
| #define REDUCT_HANDLE_CREATE_NUMBER | ( | _reduct, | |
| _val | |||
| ) | REDUCT_HANDLE_FROM_ATOM(reduct_atom_new_number(_reduct, _val)) |
| #define REDUCT_HANDLE_CREATE_NATIVE | ( | _reduct, | |
| _fn | |||
| ) | REDUCT_HANDLE_FROM_ATOM(reduct_atom_new_native(_reduct, _fn)) |
| #define REDUCT_HANDLE_CREATE_FUTURE | ( | _reduct, | |
| _callable, | |||
| _argc, | |||
| _argv | |||
| ) | REDUCT_HANDLE_FROM_FUTURE(reduct_future_new(_reduct, _callable, _argc, _argv)) |
| #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.
| _handle | The reduct_handle_t variable to store each element. |
| _list | Pointer to the list handle. |
| #define REDUCT_HANDLE_JOIN | ( | _reduct, | |
| _handle | |||
| ) | (REDUCT_HANDLE_IS_FUTURE(_handle) ? reduct_future_join(_reduct, REDUCT_HANDLE_TO_FUTURE(_handle)) : (_handle)) |
| #define REDUCT_HANDLE_NIL | ( | _reduct | ) | ((_reduct)->global->nil) |
| #define REDUCT_HANDLE_FALSE | ( | _reduct | ) | REDUCT_HANDLE_NIL(_reduct) |
| #define REDUCT_HANDLE_TRUE | ( | ) | REDUCT_HANDLE_FROM_NUMBER(1.0) |
| #define REDUCT_HANDLE_PI | ( | ) | REDUCT_HANDLE_FROM_NUMBER(REDUCT_PI) |
| #define REDUCT_HANDLE_E | ( | ) | REDUCT_HANDLE_FROM_NUMBER(REDUCT_E) |
| #define REDUCT_HANDLE_INF | ( | ) | REDUCT_HANDLE_FROM_NUMBER(REDUCT_INF) |
| #define REDUCT_HANDLE_NAN | ( | ) | REDUCT_HANDLE_FROM_NUMBER(REDUCT_NAN) |
| #define REDUCT_HANDLE_COMPARE_FAST | ( | _reduct, | |
| _a, | |||
| _b, | |||
| _op | |||
| ) |
Compare two handles using a given operator with a fast path for numbers.
| _reduct | Pointer to the Reduct structure. |
| _a | The first handle. |
| _b | The second handle. |
| _op | The comparison operator (e.g., <, >, <=, >=, etc.). |
| #define REDUCT_HANDLE_ARITHMETIC_FAST | ( | _reduct, | |
| _a, | |||
| _b, | |||
| _c, | |||
| _op | |||
| ) |
Perform a arithmetic operation on two handles with a fast path for numbers.
| _reduct | Pointer to the Reduct structure. |
| _a | The target handle. |
| _b | The first handle. |
| _c | The second handle. |
| _op | The arithmetic operator, (e.g., +, -, *, etc.) |
| #define REDUCT_HANDLE_DIV_FAST | ( | _reduct, | |
| _a, | |||
| _b, | |||
| _c | |||
| ) |
Perform a division operation on two handles with a fast path for numbers.
| _reduct | Pointer to the Reduct structure. |
| _a | The target handle. |
| _b | The first handle. |
| _c | The second handle. |
| #define REDUCT_HANDLE_MOD_FAST | ( | _reduct, | |
| _a, | |||
| _b, | |||
| _c | |||
| ) |
Perform a modulo operation on two handles.
| _reduct | Pointer to the Reduct structure. |
| _a | The target handle. |
| _b | The first handle. |
| _c | The second handle. |
| #define REDUCT_HANDLE_BITWISE_FAST | ( | _reduct, | |
| _a, | |||
| _b, | |||
| _c, | |||
| _op | |||
| ) |
Perform a bitwise operation on two handles.
| _reduct | Pointer to the Reduct structure. |
| _a | The target handle. |
| _b | The first handle. |
| _c | The second handle |
| _op | The bitwise operator, (e.g., &, |, ^, etc.) |
| #define REDUCT_HANDLE_IS_TRUTHY | ( | _handle | ) | (!REDUCT_HANDLE_IS_LIST(_handle) || REDUCT_HANDLE_TO_LIST(_handle)->length != 0) |
| #define REDUCT_HANDLE_RETAIN | ( | _reduct, | |
| _handle | |||
| ) |
Retain a handle, preventing its referenced item from being collected by the garbage collector.
| _reduct | Pointer to the Reduct structure. |
| _handle | Pointer to the handle. |
| #define REDUCT_HANDLE_RELEASE | ( | _reduct, | |
| _handle | |||
| ) |
Release a handle, allowing its referenced item to be collected by the garbage collector.
| _reduct | Pointer to the Reduct structure. |
| _handle | The handle. |
| #define REDUCT_HANDLE_FREE | ( | _reduct, | |
| _handle | |||
| ) |
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.
| _reduct | Pointer to the Reduct structure. |
| _handle | The handle to the item. |
| enum reduct_handle_type_t |
High-level handle types.
| REDUCT_API reduct_handle_type_t reduct_handle_get_type | ( | reduct_handle_t | handle | ) |
Get the high-level type of a handle.
| handle | Pointer to the handle. |
| REDUCT_API const char * reduct_handle_type_string | ( | reduct_handle_type_t | type | ) |
Get the string name of a handle type.
| type | The handle type. |
| 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.
| reduct | Pointer to the Reduct structure. |
| handle | The handle to ensure. |
|
inlinestatic |
|
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.
| reduct | Pointer to the Reduct structure. |
| handle | The handle. |
Definition at line 763 of file handle.h.
|
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.
| reduct | Pointer to the Reduct structure. |
| handle | The handle. |
Definition at line 785 of file handle.h.
|
inlinestatic |
| 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 | Pointer to the Reduct structure. |
| a | The first handle, will be upgraded. |
| b | The second handle, will be upgraded. |
true if the items are strictly equal, false otherwise. | 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.
| reduct | Pointer to the Reduct structure. |
| a | The first handle. |
| b | The second handle. |
| 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 | Pointer to the Reduct structure. |
| handle | The handle to the atom. |
| outStr | Pointer to store the string pointer, not NULL terminated. |
| outLen | Pointer to store the string length. |
| 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.
| reduct | Pointer to the Reduct structure. |
| handle | The handle. |
| index | The index. |
| 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 | Pointer to the Reduct structure. |
| handle | The handle. |
| 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.
| reduct | Pointer to the Reduct structure. |
| handle | The atom handle. |
| str | The string to compare. |
true if the atom is equal to the string, false otherwise.