Reduct  v1.0.4-3-gdaf0d70
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
4struct reduct_item;
5
6#include "atom.h"
7#include "error.h"
8#include "item.h"
9#include "list.h"
10
11/**
12 * @file core.h
13 * @brief Core definitions and structures.
14 * @defgroup core
15 *
16 * @{
17 */
18
19#define REDUCT_BUCKETS_MAX 128 ///< Amount of buckets used for intering atoms.
20#define REDUCT_CONSTANTS_MAX 8 ///< Maximum amount of predefined constants.
21
22#define REDUCT_GC_THRESHOLD_INITIAL 128 ///< Initial blocks allocated threshold for garbage collection.
23
24/**
25 * @brief Input flags.
26 */
27typedef enum
28{
30 REDUCT_INPUT_FLAG_OWNED = 1 ///< The input buffer is owned by the input structure and should be freed.
32
33/**
34 * @brief Input structure.
35 * @struct reduct_input_t
36 */
37typedef struct reduct_input
38{
39 struct reduct_input* prev;
40 const char* buffer;
41 const char* end;
43 char path[REDUCT_PATH_MAX];
45
46/**
47 * @brief Constant structure.
48 * @struct reduct_constant_t
49 */
50typedef struct reduct_constant
51{
52 struct reduct_atom* name;
53 struct reduct_item* item;
55
56/**
57 * @brief State structure.
58 * @struct reduct_t
59 */
83
84/**
85 * @brief Create a new Reduct structure.
86 *
87 * @param error Pointer to the error structure to be used for error reporting.
88 * @return A pointer to the newly allocated Reduct structure.
89 */
91
92/**
93 * @brief Free the Reduct structure.
94 *
95 * @param reduct Pointer to the Reduct structure to free.
96 */
97REDUCT_API void reduct_free(reduct_t* reduct);
98
99/**
100 * @brief Set the command line arguments for the Reduct structure.
101 *
102 * Will be utilized by the `(args!)` native.
103 *
104 * @param reduct Pointer to the Reduct structure.
105 * @param argc The number of arguments.
106 * @param argv The argument strings.
107 */
108REDUCT_API void reduct_args_set(reduct_t* reduct, int argc, char** argv);
109
110/**
111 * @brief Register a constant in a Reduct structure.
112 *
113 * @param reduct Pointer to the Reduct structure.
114 * @param name The name of the constant.
115 * @param item The item associated with the constant.
116 */
117REDUCT_API void reduct_constant_register(reduct_t* reduct, const char* name, struct reduct_item* item);
118
119/**
120 * @brief Create a new input structure and push it onto the input stack.
121 *
122 * @param reduct The Reduct structure.
123 * @param buffer The input buffer.
124 * @param length The length of the input buffer.
125 * @param path The path to the input file.
126 * @param flags Input flags.
127 * @return A pointer to the newly created input structure.
128 */
129REDUCT_API reduct_input_t* reduct_input_new(reduct_t* reduct, const char* buffer, reduct_size_t length,
130 const char* path, reduct_input_flags_t flags);
131
132/** @} */
133
134#endif
Atom representation and operations.
size_t reduct_size_t
Definition defs.h:100
uint32_t reduct_uint32_t
Definition defs.h:95
#define REDUCT_PATH_MAX
Maximum path length for Reduct.
Definition defs.h:173
jmp_buf reduct_jmp_buf_t
Definition defs.h:40
#define REDUCT_API
Definition defs.h:7
Error handling and reporting.
REDUCT_API void reduct_constant_register(reduct_t *reduct, const char *name, struct reduct_item *item)
Register a constant in a Reduct structure.
REDUCT_API reduct_t * reduct_new(reduct_error_t *error)
Create a new Reduct structure.
Definition core_impl.h:11
#define REDUCT_CONSTANTS_MAX
Maximum amount of predefined constants.
Definition core.h:20
reduct_input_flags_t
Input flags.
Definition core.h:28
REDUCT_API reduct_input_t * reduct_input_new(reduct_t *reduct, const char *buffer, reduct_size_t length, const char *path, reduct_input_flags_t flags)
Create a new input structure and push it onto the input stack.
Definition core_impl.h:123
#define REDUCT_BUCKETS_MAX
Amount of buckets used for intering atoms.
Definition core.h:19
REDUCT_API void reduct_free(reduct_t *reduct)
Free the Reduct structure.
Definition core_impl.h:47
REDUCT_API void reduct_args_set(reduct_t *reduct, int argc, char **argv)
Set the command line arguments for the Reduct structure.
Definition core_impl.h:95
@ REDUCT_INPUT_FLAG_NONE
Definition core.h:29
@ REDUCT_INPUT_FLAG_OWNED
The input buffer is owned by the input structure and should be freed.
Definition core.h:30
Item management.
List management.
Constant structure.
Definition core.h:51
struct reduct_atom * name
Definition core.h:52
struct reduct_item * item
Definition core.h:53
Error structure.
Definition error.h:37
Input structure.
Definition core.h:38
const char * end
Definition core.h:41
struct reduct_input * prev
Definition core.h:39
const char * buffer
Definition core.h:40
reduct_input_flags_t flags
Definition core.h:42
Item block structure.
Definition item.h:89
Item structure.
Definition item.h:57
State structure.
Definition core.h:61
reduct_item_t * trueItem
Definition core.h:70
reduct_size_t gcThreshold
Definition core.h:63
reduct_error_t * error
Definition core.h:78
reduct_item_block_t * block
Definition core.h:64
struct reduct_eval_state * evalState
Definition core.h:79
reduct_item_block_t firstBlock
Definition core.h:68
reduct_input_t * input
Definition core.h:66
reduct_input_t firstInput
Definition core.h:69
reduct_item_t * piItem
Definition core.h:73
reduct_item_t * nilItem
Definition core.h:72
struct reduct_item * freeList
Definition core.h:65
char ** argv
Definition core.h:81
reduct_jmp_buf_t jmp
Definition core.h:67
reduct_item_t * eItem
Definition core.h:74
reduct_uint32_t constantCount
Definition core.h:77
reduct_size_t blocksAllocated
Definition core.h:62
int argc
Definition core.h:80
reduct_item_t * falseItem
Definition core.h:71