55#define REDUCT_ATOM_MAP_INITIAL 64
56#define REDUCT_ATOM_MAP_GROWTH 2
57#define REDUCT_ATOM_SMALL_MAX 16
59#define REDUCT_ATOM_TOMBSTONE ((reduct_atom_t*)(uintptr_t)1)
61#define REDUCT_ATOM_INDEX_NONE ((uint32_t)-1)
73#define REDUCT_ATOM_FLAG_NONE 0
74#define REDUCT_ATOM_FLAG_NUMBER (1 << 0)
75#define REDUCT_ATOM_FLAG_INTRINSIC (1 << 1)
76#define REDUCT_ATOM_FLAG_NATIVE (1 << 2)
77#define REDUCT_ATOM_FLAG_NUMBER_CHECKED (1 << 3)
78#define REDUCT_ATOM_FLAG_NATIVE_CHECKED (1 << 4)
79#define REDUCT_ATOM_FLAG_LARGE (1 << 5)
80#define REDUCT_ATOM_FLAG_SCHEMA (1 << 6)
81#define REDUCT_ATOM_FLAG_QUOTED (1 << 7)
87typedef struct reduct_atom
121#define REDUCT_FNV_PRIME 16777619U
122#define REDUCT_FNV_OFFSET 2166136261U
389 memcpy(atom->
string, data, len);
#define REDUCT_LIKELY(_x)
#define REDUCT_UNLIKELY(_x)
#define REDUCT_ALWAYS_INLINE
reduct_handle_t(* reduct_native_fn)(struct reduct *reduct, size_t argc, reduct_handle_t *argv)
Native function pointer type.
struct reduct_rvsdg_origin *(* reduct_native_intrinsic_fn)(struct reduct_builder *builder, struct reduct_list *expr)
Intrinsic handler function type.
static bool reduct_atom_is_native(struct reduct *reduct, reduct_atom_t *atom)
Check if an atom is a native function.
#define REDUCT_ATOM_FLAG_NATIVE
Atom is known to represent a native function.
REDUCT_API reduct_atom_lookup_flags_t reduct_atom_get_lookup_flags(reduct_atom_t *atom)
Retrieve the lookup flags required to lookup this specific atom.
REDUCT_API int64_t reduct_atom_as_int(struct reduct *reduct, reduct_atom_t *atom)
Retrieve an integer value from an atom, regardless of if it is quoted or not.
REDUCT_API reduct_atom_t * reduct_atom_superstr(struct reduct *reduct, reduct_atom_t *atom, size_t len)
Create a superstring of an existing atom.
static REDUCT_ALWAYS_INLINE reduct_atom_t * reduct_atom_ensure_interned(struct reduct *reduct, reduct_atom_t *atom)
Ensure an atom is interned.
static REDUCT_ALWAYS_INLINE double reduct_atom_get_number(reduct_atom_t *atom)
Get the number value of an atom.
REDUCT_API void reduct_atom_global_init(reduct_atom_global_t *global)
Initialize a global atom state.
reduct_atom_lookup_flags_t
Atom lookup flags.
REDUCT_API void reduct_atom_release(struct reduct *reduct, reduct_atom_t *atom)
Release an atom, potentially allowing the garbage collector to collect it.
REDUCT_API bool reduct_atom_intern(struct reduct *reduct, reduct_atom_t *atom)
Intern an existing atom into the Reduct structure.
#define REDUCT_ATOM_FLAG_NATIVE_CHECKED
Atom has been checked for a native function.
REDUCT_API reduct_atom_t * reduct_atom_new_number(struct reduct *reduct, double value)
Create an atom from a number value.
static REDUCT_ALWAYS_INLINE bool reduct_atom_is_number(reduct_atom_t *atom)
Check if an atom is number-shaped.
REDUCT_API void reduct_atom_retain(struct reduct *reduct, reduct_atom_t *atom)
Retain an atom, preventing it from being collected by the garbage collector.
#define REDUCT_ATOM_INDEX_NONE
The value of an unindexed atom.
REDUCT_API void reduct_atom_global_deinit(reduct_atom_global_t *global)
Deinitialize a global atom state.
static REDUCT_ALWAYS_INLINE bool reduct_atom_is_intrinsic(struct reduct *reduct, reduct_atom_t *atom)
Check if an atom is an intrinsic.
#define REDUCT_ATOM_SMALL_MAX
The maximum length of a small atom.
REDUCT_API reduct_atom_t * reduct_atom_new_string(struct reduct *reduct, const char *str)
Create an atom from a null-terminated string.
#define REDUCT_ATOM_FLAG_NUMBER_CHECKED
Atom has been checked for number shaping.
REDUCT_API reduct_atom_t * reduct_atom_new(struct reduct *reduct, size_t len)
Create an atom with a reserved size.
REDUCT_API bool reduct_atom_is_equal(reduct_atom_t *atom, const char *str, size_t len)
Check if an atom is equal to a string.
REDUCT_API reduct_atom_t * reduct_atom_substr(struct reduct *reduct, reduct_atom_t *atom, size_t start, size_t len)
Create a substring of an existing atom.
uint8_t reduct_atom_flags_t
REDUCT_API reduct_atom_t * reduct_atom_lookup(struct reduct *reduct, const char *str, size_t len, reduct_atom_lookup_flags_t flags)
Lookup an interned atom in the Reduct structure.
REDUCT_API void reduct_atom_check_number(reduct_atom_t *atom)
Cache if an atom is a number.
REDUCT_API void reduct_atom_check_native(struct reduct *reduct, reduct_atom_t *atom)
Cache if an atom is a native function.
#define REDUCT_ATOM_FLAG_NUMBER
Atom is known to be number shaped.
static REDUCT_ALWAYS_INLINE reduct_atom_t * reduct_atom_new_copy(struct reduct *reduct, const char *data, size_t len)
Create a new atom by copying data directly into it.
REDUCT_API reduct_atom_t * reduct_atom_new_native(struct reduct *reduct, reduct_native_fn native)
Create an atom for a anonymous native function.
REDUCT_API double reduct_atom_as_number(struct reduct *reduct, reduct_atom_t *atom)
Retrieve a number value from an atom, regardless of if it is quoted or not.
#define REDUCT_ATOM_FLAG_INTRINSIC
Atom is known to represent an intrinsic.
@ REDUCT_ATOM_LOOKUP_NONE
No flags.
@ REDUCT_ATOM_LOOKUP_QUOTED
Atom should be explicitly quoted.
uint32_t reduct_schema_index_t
Schema index type.
Native function and intrinsic registration.
Global atom-related environment structure.
struct reduct_atom ** map
reduct_native_fn native
Cached native function, atom must have REDUCT_ATOM_FLAG_NATIVE.
uint32_t length
The length of the string (must be first, check the reduct_item_t structure).
double numberValue
Pre-computed number value, atom must have REDUCT_ATOM_FLAG_NUMBER.
reduct_native_intrinsic_fn intrinsic
Cached intrinsic function, atom must have REDUCT_ATOM_FLAG_NATIVE.
uint32_t hash
The hash of the string.
reduct_schema_index_t * schema
char * string
Pointer to the data.
reduct_arena_t * arena
The arena that this atoms string was allocated from, atom must have REDUCT_ATOM_FLAG_LARGE.
uint32_t index
The index within the atom map.
reduct_atom_flags_t flags
Atom flags.
Read-Write Mutex structure.
Syncronization primitives.