Serene Runtime 1.0.0
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
27/// There's no reason behind this number, just me guessing
28
29#define MAX_NS_NAME_LEN 4096
30
32 /// Path on disk this buffer is associated with. When not null,
33 /// srn_src_reload re-reads from here. A null value means the buffer
34 /// has no associated file, for example a fresh REPL session that has
35 /// not loaded one. A buffer can acquire a path later by being assigned
36 /// one, or lose its connection by being passed to a future detach
37 /// helper. Owned by the buffer and freed on shutdown.
38 char *path;
39
40 /// Byte storage. `bytes[0..len]` is the live content. `bytes[len..cap]`
41 /// is unused capacity. Allocated through the engine's memory manager
42 /// and freed on shutdown.
43 uint8_t *bytes;
44 size_t len;
45 size_t cap;
47
48typedef struct srn_namespace_t {
51
53
54 /// A mapping symbol names to (srn_value_t with type symbol).
55 /// Since `hmap_t` hashes out the name, it's really a mapping from unsigned
56 /// 32bit integer to symbols
59
60 /// The buffer holding the source code for this namespace. Can be a nullptr
61 /// For new and empty namespaces. DO NOT hold any reference to this buffer
62 /// since it will be purged in case of a namespace reload.
64 /// Guards every access to source buffer. Acquire before any operation.
65 /// Even read.
68
69/// Creates a new namespace in the give context. The given context will NOT
70/// be the namespace's root context
71[[gnu::nonnull(1)]]
73 srn_string_t *name);
74
75/// Load the namespace from the filesystem by looking up the file
76/// in the filesystem, load the file into the src_buffer, parse
77/// the code, and populate the symtable.
78[[gnu::nonnull(1)]]
uint64_t srn_object_id_t
Definition engine.h:40
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 from the filesystem by looking up the file in the filesystem, load the file into t...
Definition namespaces.c:50
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:27
char * path
Path on disk this buffer is associated with.
Definition namespaces.h:38
uint8_t * bytes
Byte storage.
Definition namespaces.h:43
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