60 hmap_t *table = atomic_load_explicit(&ns->sym_table, memory_order_acquire);
74 table = atomic_load_explicit(&ns->sym_table, memory_order_relaxed);
75 sym = hmap_lookup(table, &k, nullptr);
81 sym = srn_symbol_make(ns->root_context, metadata, ns, symbol_name);
85 hmap_t *next = ALLOC_OR_PANIC(ns->root_context, hmap_t);
86 *next = hmap_insert(table, &k, (void *)sym);
87 atomic_store_explicit(&ns->sym_table, next, memory_order_release);
110 int len = snprintf(
nullptr, 0,
"gensym_%" PRIu64,
id);
115 (void)snprintf(name,
len + 1,
"gensym_%" PRIu64,
id);
123 hmap_t *table = atomic_load_explicit(&ns->sym_table, memory_order_relaxed);
125 if (hmap_lookup(table, &k, nullptr) == nullptr) {
129 sym = srn_symbol_make(ns->root_context, metadata, ns, AS_STRING(sym_name));
131 hmap_t *next = ALLOC_OR_PANIC(ns->root_context, hmap_t);
132 *next = hmap_insert(table, &k, (void *)sym);
133 atomic_store_explicit(&ns->sym_table, next, memory_order_release);
138 if (sym !=
nullptr) {
void * srn_allocate(const srn_context_t *ctx, size_t size, size_t alignment)
Allocate size bytes aligned to alignment from the context's memory block.
srn_value_t * srn_value_make(srn_context_t *ctx, srn_value_tag_t tag, srn_metadata_t *metadata, void *payload)
Creates a new serene value.
#define AS_STRING(value_ref)
srn_object_id_t srn_allocate_object_id(srn_engine_t *engine)
Error handling for the runtime.
void * hmap_lookup(const hmap_t *hmap, const hmap_key_t *k, void *default_value)
Lookup the given k in the given hmap and return the value if it's been found.
This is an implementation of Compressed Hash-Array Mapped Prefix-tree, which is a bit-partitioned,...
#define WITH_LOCK(lock, body)
Run body with lock held.
A namespace is an isolation for names nad technically a compilation unit.
srn_value_t * srn_string_make(srn_context_t *ctx, srn_metadata_t *metadata, const char *src)
Create a string from a null terminated C string.
bool srn_string_is_empty(const srn_string_t *s)
srn_string_t * srn_string_copy(srn_context_t *ctx, const srn_string_t *src)
Allocate a copy of src through ctx and return it.
Note: For key equality we use the memcpy function.
srn_engine_t * engine
Long term state of the compiler.
srn_fiber_mutex_t * sym_table_lock
Only when setting the sym_table hmap it self.
size_t size
Size of the buffer.
uint8_t buffer[]
The buffer that holds the WTF8 sequence.
srn_value_t * srn_symbol_make(srn_context_t *ctx, srn_metadata_t *metadata, srn_namespace_t *ns, srn_string_t *name)
Create a new symbol. IT DOES NOT INTERNALIZE THE SYMBOL.
srn_value_t * srn_symbol_intern(srn_context_t *ctx, srn_metadata_t *metadata, srn_namespace_t *ns, srn_string_t *symbol_name)
srn_value_t * srn_symbol_gen(srn_context_t *ctx, srn_metadata_t *metadata, srn_namespace_t *ns, srn_string_t *optional_name)
#define PANIC_IF_NULL(ptr)
#define PANIC_IF(cond, msg)