|
Reduct
v1.0.4-3-gdaf0d70
A functional and immutable language.
|
Handle management. More...
Go to the source code of this file.
Data Structures | |
| struct | reduct_promotion_t |
| Promotion result for numeric operations. More... | |
Macros | |
| #define | REDUCT_HANDLE_NONE 0x0000000000000000ULL |
| Invalid handle constant. | |
| #define | REDUCT_HANDLE_OFFSET_FLOAT 0x0007000000000000ULL |
| Offset used for encoding doubles. | |
| #define | REDUCT_HANDLE_TAG_INT 0x0006000000000000ULL |
| Tag for integer handles. | |
| #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_MASK_FLAGS 0x00000000000000FFULL |
| Mask for flags (not stored in handle anymore). | |
| #define | REDUCT_HANDLE_FROM_INT(_val) (REDUCT_HANDLE_TAG_INT | ((reduct_handle_t)(_val) & REDUCT_HANDLE_MASK_VAL)) |
| Create a handle from an integer. | |
| #define | REDUCT_HANDLE_FROM_FLOAT(_val) |
| Create a handle from a float. | |
| #define | REDUCT_HANDLE_FROM_ITEM(_ptr) (REDUCT_HANDLE_TAG_ITEM | ((reduct_handle_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_IS_INT(_handle) (((*(_handle)) & REDUCT_HANDLE_MASK_TAG) == REDUCT_HANDLE_TAG_INT) |
| Check if a handle is an integer. | |
| #define | REDUCT_HANDLE_IS_FLOAT(_handle) ((*(_handle)) >= REDUCT_HANDLE_OFFSET_FLOAT) |
| Check if a handle is a float. | |
| #define | REDUCT_HANDLE_IS_INT_SHAPED(_handle) |
| Check if a handle is an integer of references a integer shaped item. | |
| #define | REDUCT_HANDLE_IS_FLOAT_SHAPED(_handle) |
| Check if a handle is a float or references a float shaped item. | |
| #define | REDUCT_HANDLE_GET_TYPE(_handle) (REDUCT_HANDLE_IS_ITEM(_handle) ? REDUCT_HANDLE_TO_ITEM(_handle)->type : REDUCT_ITEM_TYPE_ATOM) |
Get the type of the item referenced by the handle, or REDUCT_ITEM_TYPE_ATOM if not an item. | |
| #define | REDUCT_HANDLE_IS_NUMBER_SHAPED(_handle) (REDUCT_HANDLE_IS_INT_SHAPED(_handle) || REDUCT_HANDLE_IS_FLOAT_SHAPED(_handle)) |
| Check if a handle is a number or references a number shaped item. | |
| #define | REDUCT_HANDLE_IS_ITEM(_handle) (((*(_handle)) & REDUCT_HANDLE_MASK_TAG) == REDUCT_HANDLE_TAG_ITEM) |
| Check if a handle is an item. | |
| #define | REDUCT_HANDLE_IS_ATOM(_handle) (REDUCT_HANDLE_GET_TYPE(_handle) == REDUCT_ITEM_TYPE_ATOM) |
| Check if a handle is an atom. | |
| #define | REDUCT_HANDLE_IS_LIST(_handle) (REDUCT_HANDLE_GET_TYPE(_handle) == REDUCT_ITEM_TYPE_LIST) |
| Check if a handle is a list. | |
| #define | REDUCT_HANDLE_IS_FUNCTION(_handle) (REDUCT_HANDLE_GET_TYPE(_handle) == REDUCT_ITEM_TYPE_FUNCTION) |
| Check if a handle is a function. | |
| #define | REDUCT_HANDLE_IS_CLOSURE(_handle) (REDUCT_HANDLE_GET_TYPE(_handle) == REDUCT_ITEM_TYPE_CLOSURE) |
| Check if a handle is a closure. | |
| #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(_handle) (REDUCT_HANDLE_IS_ITEM(_handle) && (REDUCT_HANDLE_GET_FLAGS(_handle) & REDUCT_ITEM_FLAG_NATIVE)) |
| Check if a handle is a native function. | |
| #define | REDUCT_HANDLE_IS_CALLABLE(_handle) (REDUCT_HANDLE_IS_LAMBDA(_handle) || REDUCT_HANDLE_IS_NATIVE(_handle)) |
| Check if a handle is callable. | |
| #define | REDUCT_HANDLE_TO_INT(_handle) (((reduct_int64_t)((*(_handle)) << 16)) >> 16) |
| Get the integer value of a handle. | |
| #define | REDUCT_HANDLE_TO_FLOAT(_handle) |
| Get the float value of a handle. | |
| #define | REDUCT_HANDLE_TO_ITEM(_handle) ((reduct_item_t*)(void*)((*(_handle)) & REDUCT_HANDLE_MASK_PTR)) |
| Get the item pointer of a handle. | |
| #define | REDUCT_HANDLE_GET_FLAGS(_handle) (REDUCT_HANDLE_IS_ITEM(_handle) ? REDUCT_HANDLE_TO_ITEM(_handle)->flags : 0) |
| Get flags from an item handle. | |
| #define | REDUCT_HANDLE_FALSE() REDUCT_HANDLE_FROM_INT(0) |
| Constant false handle. | |
| #define | REDUCT_HANDLE_TRUE() REDUCT_HANDLE_FROM_INT(1) |
| Constant true handle. | |
| #define | REDUCT_HANDLE_FROM_BOOL(_cond) ((_cond) ? REDUCT_HANDLE_TRUE() : REDUCT_HANDLE_FALSE()) |
| Create a boolean handle from a C condition. | |
| #define | REDUCT_HANDLE_COMPARE_FAST(_reduct, _a, _b, _op) |
| Compare two handles using a given operator with a fast path for integers and floats. | |
| #define | REDUCT_HANDLE_ARITHMETIC_FAST(_reduct, _a, _b, _c, _op) |
| Perform a arithmetic operation on two handles with a fast path for integers and floats. | |
| #define | REDUCT_HANDLE_IS_TRUTHY(_handle) |
| Check if a handle is truthy. | |
Enumerations | |
| enum | reduct_promotion_type_t { REDUCT_PROMOTION_TYPE_NONE = 0 , REDUCT_PROMOTION_TYPE_INT = 1 , REDUCT_PROMOTION_TYPE_FLOAT = 2 } |
| Promotion types for numeric operations. More... | |
Functions | |
| REDUCT_API void | reduct_handle_ensure_item (struct reduct *reduct, reduct_handle_t *handle) |
| Ensure that a handle is an item handle. | |
| REDUCT_API struct reduct_item * | reduct_handle_item (struct reduct *reduct, reduct_handle_t *handle) |
| Ensure that a handle is an item and return the pointer. | |
| REDUCT_API void | reduct_handle_promote (struct reduct *reduct, reduct_handle_t *a, reduct_handle_t *b, reduct_promotion_t *out) |
| Promote two handles to a common numeric type. | |
| REDUCT_API reduct_bool_t | 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 reduct_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 reduct_handle_t | reduct_handle_nil (struct reduct *reduct) |
| Get the constant nil handle. | |
| REDUCT_API reduct_handle_t | reduct_handle_pi (struct reduct *reduct) |
| Get the constant PI handle. | |
| REDUCT_API reduct_handle_t | reduct_handle_e (struct reduct *reduct) |
| Get the constant E handle. | |
| REDUCT_API void | reduct_handle_get_string_params (struct reduct *reduct, reduct_handle_t *handle, char **outStr, reduct_size_t *outLen) |
| Get the string pointer and length from an atom handle. | |
Handle management.
Definition in file handle.h.