Reduct  v4.0.5-1-g4851deb
A functional and immutable language.
Loading...
Searching...
No Matches
atom.h File Reference

Atom representation and operations. More...

#include <reduct/arena.h>
#include <reduct/defs.h>
#include <reduct/native.h>
#include <reduct/schema.h>
#include <reduct/sync.h>
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
Include dependency graph for atom.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  reduct_atom_t
 Atom structure. More...
 
struct  reduct_atom_global_t
 Global atom-related environment structure. More...
 

Macros

#define REDUCT_ATOM_MAP_INITIAL   64
 The initial size of the atom map.
 
#define REDUCT_ATOM_MAP_GROWTH   2
 The growth factor of the atom map.
 
#define REDUCT_ATOM_SMALL_MAX   16
 The maximum length of a small atom.
 
#define REDUCT_ATOM_TOMBSTONE   ((reduct_atom_t*)(uintptr_t)1)
 Tombstone value for the atom map.
 
#define REDUCT_ATOM_INDEX_NONE   ((uint32_t)-1)
 The value of an unindexed atom.
 
#define REDUCT_ATOM_FLAG_NONE   0
 No flags.
 
#define REDUCT_ATOM_FLAG_NUMBER   (1 << 0)
 Atom is known to be number shaped.
 
#define REDUCT_ATOM_FLAG_INTRINSIC   (1 << 1)
 Atom is known to represent an intrinsic.
 
#define REDUCT_ATOM_FLAG_NATIVE   (1 << 2)
 Atom is known to represent a native function.
 
#define REDUCT_ATOM_FLAG_NUMBER_CHECKED   (1 << 3)
 Atom has been checked for number shaping.
 
#define REDUCT_ATOM_FLAG_NATIVE_CHECKED   (1 << 4)
 Atom has been checked for a native function.
 
#define REDUCT_ATOM_FLAG_LARGE   (1 << 5)
 Atom has an allocated buffer within a stack.
 
#define REDUCT_ATOM_FLAG_SCHEMA   (1 << 6)
 Atom is a schema field.
 
#define REDUCT_ATOM_FLAG_QUOTED   (1 << 7)
 Atom is quoted.
 
#define REDUCT_FNV_PRIME   16777619U
 FNV-1a 32-bit prime.
 
#define REDUCT_FNV_OFFSET   2166136261U
 FNV-1a 32-bit offset basis.
 

Typedefs

typedef uint8_t reduct_atom_flags_t
 

Enumerations

enum  reduct_atom_lookup_flags_t { REDUCT_ATOM_LOOKUP_NONE = 0 , REDUCT_ATOM_LOOKUP_QUOTED = 1 << 0 }
 Atom lookup flags. More...
 

Functions

REDUCT_API void reduct_atom_global_init (reduct_atom_global_t *global)
 Initialize a global atom state.
 
REDUCT_API void reduct_atom_global_deinit (reduct_atom_global_t *global)
 Deinitialize a global atom state.
 
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_treduct_atom_new (struct reduct *reduct, size_t len)
 Create an atom with a reserved size.
 
REDUCT_API reduct_atom_treduct_atom_new_string (struct reduct *reduct, const char *str)
 Create an atom from a null-terminated string.
 
REDUCT_API reduct_atom_treduct_atom_new_number (struct reduct *reduct, double value)
 Create an atom from a number value.
 
REDUCT_API reduct_atom_treduct_atom_new_native (struct reduct *reduct, reduct_native_fn native)
 Create an atom for a anonymous native function.
 
REDUCT_API bool reduct_atom_intern (struct reduct *reduct, reduct_atom_t *atom)
 Intern an existing atom into the Reduct structure.
 
REDUCT_API reduct_atom_treduct_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 reduct_atom_lookup_flags_t reduct_atom_get_lookup_flags (reduct_atom_t *atom)
 Retrieve the lookup flags required to lookup this specific atom.
 
static REDUCT_ALWAYS_INLINE reduct_atom_treduct_atom_ensure_interned (struct reduct *reduct, reduct_atom_t *atom)
 Ensure an atom is interned.
 
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.
 
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.
 
REDUCT_API void reduct_atom_release (struct reduct *reduct, reduct_atom_t *atom)
 Release an atom, potentially allowing the garbage collector to collect it.
 
static REDUCT_ALWAYS_INLINE bool reduct_atom_is_intrinsic (struct reduct *reduct, reduct_atom_t *atom)
 Check if an atom is an intrinsic.
 
static bool reduct_atom_is_native (struct reduct *reduct, reduct_atom_t *atom)
 Check if an atom is a native function.
 
static REDUCT_ALWAYS_INLINE bool reduct_atom_is_number (reduct_atom_t *atom)
 Check if an atom is number-shaped.
 
static REDUCT_ALWAYS_INLINE double reduct_atom_get_number (reduct_atom_t *atom)
 Get the number value of an atom.
 
REDUCT_API reduct_atom_treduct_atom_substr (struct reduct *reduct, reduct_atom_t *atom, size_t start, size_t len)
 Create a substring of an existing atom.
 
REDUCT_API reduct_atom_treduct_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_treduct_atom_new_copy (struct reduct *reduct, const char *data, size_t len)
 Create a new atom by copying data directly into it.
 
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 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.
 

Detailed Description

Atom representation and operations.

Definition in file atom.h.