Serene Runtime 1.0.0-dev
C runtime for the Serene programming language
Loading...
Searching...
No Matches
namespaces.c File Reference
Include dependency graph for namespaces.c:

Go to the source code of this file.

Functions

srn_value_tsrn_namespace_make (srn_context_t *ctx, srn_metadata_t *metadata, srn_string_t *name)
 Creates a new namespace in the give context.
srn_namespace_tsrn_namespace_load (srn_namespace_t *ns)
 Load the namespace's source from the filesystem into src_buffer, parse it, and populate the symbol table.

Function Documentation

◆ srn_namespace_load()

srn_namespace_t * srn_namespace_load ( srn_namespace_t * ns)

Load the namespace's source from the filesystem into src_buffer, parse it, and populate the symbol table.

Not implemented, the current body returns null unconditionally, so callers cannot rely on it yet.

Definition at line 60 of file namespaces.c.

60 {
61 PANIC_IF_NULL(ns);
62 return nullptr;
63}
#define PANIC_IF_NULL(ptr)
Definition utils.h:66

◆ srn_namespace_make()

srn_value_t * srn_namespace_make ( srn_context_t * ctx,
srn_metadata_t * metadata,
srn_string_t * name )

Creates a new namespace in the give context.

The given context will NOT be the namespace's root context

Definition at line 28 of file namespaces.c.

28 {
29 PANIC_IF_NULL(ctx);
30 PANIC_IF_NULL(name);
31
32 // Empty string is not a valid namespace name
33 if (srn_string_is_empty(name)) {
34 return srn_errors_make_error(ctx, metadata, EMPTY_NAMESPACE_NAME, nullptr);
35 };
36
38 return srn_errors_make_error(
39 ctx, metadata, STRING_LENGTH_LIMIT_EXCEEDED, "Namespace name exceeds the length limit"
40 );
41 }
42
44 ns->name = srn_string_copy(ctx, name);
45
48 // The symbol table outlives the creating context, so it is pinned to the
49 // namespace's own root context; the table's keys and trie nodes land in
50 // that chain rather than in the creating caller's block.
52 ns->src_buffer = nullptr;
53
56
57 return srn_value_make(ctx, VNamespace, metadata, (void *)ns);
58}
srn_context_t * srn_context_make(srn_engine_t *engine)
Make an empty context, by allocating a new memory block.
Definition context.c:39
#define ALLOC(ctx, T)
Definition context.h:84
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.
Definition core.c:36
@ VNamespace
Definition core.h:122
srn_object_id_t srn_allocate_object_id(srn_engine_t *engine)
Definition engine.c:172
@ EMPTY_NAMESPACE_NAME
Definition errors.h:81
@ STRING_LENGTH_LIMIT_EXCEEDED
Definition errors.h:83
hmap_t hmap_empty(const srn_context_t *ctx)
Create, initialize and return a new hashmap pinned to ctx.
Definition hashmap.c:655
size_t srn_string_length(const srn_string_t *s)
Definition strings.c:34
bool srn_string_is_empty(const srn_string_t *s)
Definition strings.c:49
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.
Definition strings.c:39
srn_limits_config_t limits
srn_engine_t * engine
Long term state of the compiler.
Definition context.h:49
srn_configuration_t config
The runtime's tunable knobs, the single source for every configurable value (see configuration....
Definition engine.h:62
size_t ns_name_max_len
Longest namespace name accepted, in bytes.
srn_string_t * name
Definition namespaces.h:45
srn_context_t * root_context
Definition namespaces.h:48
srn_spinlock_t src_buffer_lock
Guards every access to source buffer.
Definition namespaces.h:62
srn_namespace_src_buffer_t * src_buffer
The buffer holding the source code for this namespace.
Definition namespaces.h:59
hmap_t sym_table
A mapping symbol names to (srn_value_t with type symbol).
Definition namespaces.h:53
srn_spinlock_t sym_table_lock
Definition namespaces.h:54
srn_object_id_t id
Definition namespaces.h:46
static void srn_spinlock_init(srn_spinlock_t *lock)
Definition utils.h:280
Here is the call graph for this function:
Here is the caller graph for this function: