Serene Runtime 1.0.0-dev
C runtime for the Serene programming language
Loading...
Searching...
No Matches
namespaces.h
Go to the documentation of this file.
1/* -*- C -*-
2 * Serene programming language
3 * Copyright (C) 2019-2026 Sameer Rahmani <lxsameer@lxsameer.com>
4 *
5 * This library is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library. If not, see <https://www.gnu.org/licenses/>.
17 */
18#pragma once
19
20/** @file
21A namespace is an isolation for names nad technically a compilation unit. Typically each namespace
22will resolve to a single file on the filesystem. Namespaces maintain a sym table that maps global
23names that the namespace provides to their definition.
24 */
25
26#include <stdatomic.h>
27
28#include "serene/rt/context.h"
29#include "serene/rt/engine.h"
32#include "serene/utils.h"
33
34typedef struct srn_string_t srn_string_t;
36typedef struct srn_term_t srn_term_t;
37typedef struct srn_engine_t srn_engine_t;
38
39typedef struct srn_namespace_t {
42 /// Designated buffer id of this namespace on the source manager.
44
46
47 /// A mapping symbol names to `srn_nodet_t` values.
48 /// Since `hmap_t` hashes out the name, it's really a mapping from unsigned
49 /// 32bit integer to `srn_nodet_t` values
50 _Atomic(hmap_t *) sym_table;
51 /// Only when setting the sym_table hmap it self
53
54 /// The top level node of the namespace. Each namespace should have just ONE node at the top which
55 /// is the node that describes the namespace itself (Similar to how clojure namespaces work)
58
59/**
60 * Create a new and empty namespace if it is not already created in the engine, if it exists, return
61 * the namespace. Note that in case of creation, this function will register the new namespace with
62 * the `engine`.
63 */
64[[gnu::nonnull(1, 2)]]
67
68/**
69 * Load the namespace's source from the filesystem into `src_buffer`, parse it, and populate the
70 * symbol table. Not implemented, the current body returns null unconditionally, so callers cannot
71 * rely on it yet.
72 */
73[[gnu::nonnull(1)]]
uint64_t srn_object_id_t
Definition engine.h:45
This is an implementation of Compressed Hash-Array Mapped Prefix-tree, which is a bit-partitioned,...
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 ta...
Definition namespaces.c:101
srn_namespace_t * srn_namespace_get_or_create(srn_engine_t *engine, srn_string_t *name, srn_error_t **err)
Create a new and empty namespace if it is not already created in the engine, if it exists,...
Definition namespaces.c:30
Source manager is what that read the source files and own the buffer that contains the data.
size_t srn_sm_buffer_id_t
Engine is a structure to own the long living and main pieces of the compiler.
Definition engine.h:54
A runtime error, a tag classifying the failure and a human-readable message.
Definition errors.h:173
srn_string_t * name
Definition namespaces.h:40
srn_context_t * root_context
Definition namespaces.h:45
srn_sm_buffer_id_t buffer_id
Designated buffer id of this namespace on the source manager.
Definition namespaces.h:43
srn_term_t * node
The top level node of the namespace.
Definition namespaces.h:56
srn_object_id_t id
Definition namespaces.h:41
srn_fiber_mutex_t * sym_table_lock
Only when setting the sym_table hmap it self.
Definition namespaces.h:52
_Atomic(hmap_t *) sym_table
A mapping symbol names to srn_nodet_t values.