Serene Runtime 1.0.0
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 from the filesystem by looking up the file in the filesystem, load the file into the src_buffer, parse the code, and populate the symtable.
 

Function Documentation

◆ srn_namespace_load()

srn_namespace_t * srn_namespace_load ( srn_namespace_t * ns)

Load the namespace from the filesystem by looking up the file in the filesystem, load the file into the src_buffer, parse the code, and populate the symtable.

Definition at line 50 of file namespaces.c.

50 {
51 PANIC_IF_NULL(ns);
52 return nullptr;
53}
#define PANIC_IF_NULL(ptr)
Definition utils.h:64

◆ 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 27 of file namespaces.c.

27 {
28 PANIC_IF_NULL(ctx);
29 PANIC_IF_NULL(name);
30
31 // Empty string is not a valid namespace name
32 if (srn_string_is_empty(name)) {
33 return srn_errors_make_error(ctx, metadata, EMPTY_NAMESPACE_NAME, nullptr);
34 };
35
37 ns->name = srn_string_copy(ctx, name);
38
41 ns->sym_table = hmap_empty(ctx);
42 ns->src_buffer = nullptr;
43
46
47 return srn_value_make(ctx, VNamespace, metadata, (void *)ns);
48}
srn_context_t * srn_context_make(srn_engine_t *engine)
Make an empty context, by allocating a new memory block.
Definition context.c:38
#define ALLOC(ctx, T)
Definition context.h:82
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:24
@ VNamespace
Definition core.h:122
srn_object_id_t srn_allocate_object_id(srn_engine_t *engine)
Definition engine.c:137
@ EMPTY_NAMESPACE_NAME
Definition errors.h:50
hmap_t hmap_empty(srn_context_t *ctx)
Create, initialize and return a new hashmap.
Definition hashmap.c:612
bool srn_string_is_empty(const srn_string_t *s)
Definition strings.c:48
srn_string_t * srn_string_copy(srn_context_t *ctx, const srn_string_t *src)
Copy the src string to dst string.
Definition strings.c:38
srn_engine_t * engine
Long term state of the compiler.
Definition context.h:49
srn_string_t * name
Definition namespaces.h:49
srn_context_t * root_context
Definition namespaces.h:52
srn_spinlock_t src_buffer_lock
Guards every access to source buffer.
Definition namespaces.h:66
srn_namespace_src_buffer_t * src_buffer
The buffer holding the source code for this namespace.
Definition namespaces.h:63
hmap_t sym_table
A mapping symbol names to (srn_value_t with type symbol).
Definition namespaces.h:57
srn_spinlock_t sym_table_lock
Definition namespaces.h:58
srn_object_id_t id
Definition namespaces.h:50
static void srn_spinlock_init(srn_spinlock_t *lock)
Definition utils.h:281
Here is the call graph for this function:
Here is the caller graph for this function: