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 <[email protected]>
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#include "serene/rt/context.h"
21#include "serene/rt/engine.h"
23#include "serene/utils.h"
24
25typedef struct srn_string_t srn_string_t;
26
28 /// Path on disk this buffer is associated with. When not null,
29 /// srn_src_reload re-reads from here. A null value means the buffer
30 /// has no associated file, for example a fresh REPL session that has
31 /// not loaded one. A buffer can acquire a path later by being assigned
32 /// one, or lose its connection by being passed to a future detach
33 /// helper. Owned by the buffer and freed on shutdown.
34 char *path;
35
36 /// Byte storage. `bytes[0..len]` is the live content. `bytes[len..cap]`
37 /// is unused capacity. Allocated through the engine's memory manager
38 /// and freed on shutdown.
39 uint8_t *bytes;
40 size_t len;
41 size_t cap;
43
44typedef struct srn_namespace_t {
47
49
50 /// A mapping symbol names to (srn_value_t with type symbol).
51 /// Since `hmap_t` hashes out the name, it's really a mapping from unsigned
52 /// 32bit integer to symbols
55
56 /// The buffer holding the source code for this namespace. Can be a nullptr
57 /// For new and empty namespaces. DO NOT hold any reference to this buffer
58 /// since it will be purged in case of a namespace reload.
60 /// Guards every access to source buffer. Acquire before any operation.
61 /// Even read.
64
65/// Creates a new namespace in the give context. The given context will NOT
66/// be the namespace's root context
67[[gnu::nonnull(1)]]
69
70/// Load the namespace's source from the filesystem into `src_buffer`, parse
71/// it, and populate the symbol table. Not implemented, the current body
72/// returns null unconditionally, so callers cannot rely on it yet.
73[[gnu::nonnull(1)]]
uint64_t srn_object_id_t
Definition engine.h:42
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:60
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.
Definition namespaces.c:28
char * path
Path on disk this buffer is associated with.
Definition namespaces.h:34
uint8_t * bytes
Byte storage.
Definition namespaces.h:39
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