Reduct  v4.1.3-1-gd06c383
A functional and immutable language.
Loading...
Searching...
No Matches
core.h
Go to the documentation of this file.
1#ifndef REDUCT_CORE_H
2#define REDUCT_CORE_H 1
3
4#include <reduct/arena.h>
5#include <reduct/atom.h>
6#include <reduct/defs.h>
7#include <reduct/error.h>
8#include <reduct/eval.h>
9#include <reduct/gc.h>
10#include <reduct/item.h>
11#include <reduct/list.h>
12#include <reduct/module.h>
13#include <reduct/native.h>
14#include <reduct/schema.h>
15#include <reduct/scratch.h>
16#include <reduct/task.h>
17
18struct reduct_item;
19struct reduct_eval_frame;
20
21#include <assert.h>
22#include <stdatomic.h>
23#include <stdlib.h>
24
25/**
26 * @file core.h
27 * @brief Core definitions and structures.
28 * @defgroup core
29 *
30 * @{
31 */
32
33#define REDUCT_SCHEMA_INITIAL 4 ///< Initial size of the schema array.
34#define REDUCT_SCHEMA_GROWTH 2 ///< Growth factor of the schema array.
35
36#define REDUCT_CONSTANTS_MAX 8 ///< Maximum amount of predefined constants.
37
38#define REDUCT_SCRATCH_INITIAL 128 ///< Initial scratch buffer size.
39#define REDUCT_SCRATCH_MAX 16 ///< The maximum number of scratch buffers.
40
41/**
42 * @brief Global state structure.
43 * @struct reduct_global_t
44 */
61
62/**
63 * @brief Per-thread state structure.
64 * @struct reduct_t
65 */
77
78/**
79 * @brief Create a new Reduct environment.
80 *
81 * @return A pointer to the first per thread state structure of the new environment or `NULL`.
82 */
84
85/**
86 * @brief Free the Reduct structure.
87 *
88 * @param reduct Pointer to the Reduct structure to free.
89 */
91
92/**
93 * @brief Set the user data pointer for the Reduct structure.
94 *
95 * @param reduct Pointer to the Reduct structure.
96 * @param userdata The user data pointer.
97 */
98REDUCT_API void reduct_userdata_set(reduct_t* reduct, void* userdata);
99
100/**
101 * @brief Get the user data pointer from the Reduct structure.
102 *
103 * @param reduct Pointer to the Reduct structure.
104 * @return The user data pointer.
105 */
107
108/**
109 * @brief Set the command line arguments for the Reduct structure.
110 *
111 * Will be utilized by the `(args!)` native.
112 *
113 * @param reduct Pointer to the Reduct structure.
114 * @param argc The number of arguments.
115 * @param argv The argument strings.
116 */
117REDUCT_API void reduct_args_set(reduct_t* reduct, int argc, char** argv);
118
119/**
120 * @brief Hash a string.
121 *
122 * @param str The string to hash.
123 * @param len The length of the string.
124 * @return The hash of the string.
125 */
126static inline REDUCT_ALWAYS_INLINE uint32_t reduct_hash(const char* str, size_t len)
127{
128 uint32_t hash = REDUCT_FNV_OFFSET;
129 for (size_t i = 0; i < len; i++)
130 {
131 hash ^= (unsigned char)str[i];
132 hash *= REDUCT_FNV_PRIME;
133 }
134 return hash;
135}
136
137/** @} */
138
139#endif
Arena allocation.
Atom representation and operations.
#define REDUCT_ALWAYS_INLINE
Definition defs.h:61
#define REDUCT_API
Definition defs.h:24
Error handling and reporting.
Virtual machine evaluation.
Garbage collection.
#define REDUCT_FNV_PRIME
FNV-1a 32-bit prime.
Definition atom.h:121
#define REDUCT_FNV_OFFSET
FNV-1a 32-bit offset basis.
Definition atom.h:122
REDUCT_API void * reduct_userdata_get(reduct_t *reduct)
Get the user data pointer from the Reduct structure.
REDUCT_API void reduct_userdata_set(reduct_t *reduct, void *userdata)
Set the user data pointer for the Reduct structure.
static REDUCT_ALWAYS_INLINE uint32_t reduct_hash(const char *str, size_t len)
Hash a string.
Definition core.h:126
REDUCT_API reduct_t * reduct_new(void)
Create a new Reduct environment.
REDUCT_API void reduct_free(reduct_t *reduct)
Free the Reduct structure.
REDUCT_API void reduct_args_set(reduct_t *reduct, int argc, char **argv)
Set the command line arguments for the Reduct structure.
Item management.
List management.
Module system.
Native function and intrinsic registration.
Schema transformation.
Scratch buffer allocation.
Per-thread arena-related state structure.
Definition arena.h:60
Global atom-related environment structure.
Definition atom.h:129
Error structure.
Definition error.h:56
Per-thread eval-related state structure.
Definition eval.h:42
Global garbage collection-related state structure.
Definition gc.h:25
Global state structure.
Definition core.h:46
reduct_module_global_t struct reduct * threads
Definition core.h:51
reduct_task_global_t task
Definition core.h:59
reduct_handle_t nil
Definition core.h:49
reduct_optimize_global_t optimize
Definition core.h:58
uint64_t threadCount
Definition core.h:52
reduct_atom_global_t atom
Definition core.h:53
reduct_gc_global_t gc
Definition core.h:56
reduct_item_global_t item
Definition core.h:55
char ** argv
Definition core.h:48
reduct_native_global_t native
Definition core.h:54
reduct_schema_global_t schema
Definition core.h:57
Handle type.
Definition defs.h:121
Global item-related state structure.
Definition item.h:112
Per-thread item-related state structure.
Definition item.h:126
Global module state structure.
Definition module.h:78
Global native-related state structure.
Definition native.h:46
Global optimization-related state structure.
Definition optimize.h:50
Global schema-related state structure.
Definition schema.h:83
Per-thread scratch-related state structure.
Definition scratch.h:38
Per-thread state structure.
Definition core.h:67
reduct_global_t * global
Definition core.h:69
reduct_error_t * error
Definition core.h:70
reduct_eval_local_t eval
Definition core.h:74
reduct_arena_local_t arena
Definition core.h:71
reduct_item_local_t item
Definition core.h:72
thrd_t thrd
Definition core.h:68
reduct_scratch_local_t scratch
Definition core.h:73
void * userdata
Definition core.h:75
Global thread-related state structure.
Definition task.h:56
Task primitives.