Reduct  v1.0.4-3-gdaf0d70
A functional and immutable language.
Loading...
Searching...
No Matches
eval.h
Go to the documentation of this file.
1#ifndef REDUCT_EVAL_H
2#define REDUCT_EVAL_H 1
3
4struct reduct_closure;
5
6/**
7 * @file eval.h
8 * @brief Virtual machine evaluation.
9 * @defgroup eval Evaluation
10 *
11 * @{
12 */
13
14#include "core.h"
15#include "function.h"
16#include "handle.h"
17
18#define REDUCT_EVAL_REGS_INITIAL 64 ///< The initial amount of registers.
19#define REDUCT_EVAL_REGS_GROWTH_FACTOR 2 ///< The growth factor of the registers array.
20
21#define REDUCT_EVAL_FRAMES_INITIAL 32 ///< The initial size of the frames array.
22#define REDUCT_EVAL_FRAMES_GROWTH_FACTOR 2 ///< The growth factor of the frames array.
23
24/**
25 * @brief Evaluation frame structure.
26 * @struct reduct_eval_frame_t
27 */
28typedef struct reduct_eval_frame
29{
30 struct reduct_closure* closure; ///< The closure being evaluated.
31 reduct_inst_t* ip; ///< The current instruction pointer.
32 reduct_uint32_t base; ///< The base register, where the functions registers start.
33 reduct_uint32_t prevRegCount; ///< The previous register count to restore upon return.
35
36/**
37 * @brief Evaluation state structure.
38 * @struct reduct_eval_state_t
39 */
49
50/**
51 * @brief Deinitialize an evaluation state structure.
52 *
53 * @param state The evaluation state to deinitialize.
54 */
56
57/**
58 * @brief Evaluates a compiled Reduct function.
59 *
60 * @param reduct The Reduct instance.
61 * @param function The function to evaluate.
62 * @return The result of the evaluation as a Reduct handle.
63 */
65
66/**
67 * @brief Parses, compiles and evaluates a file.
68 *
69 * @param reduct The Reduct instance.
70 * @param path The path to the file.
71 * @return The result of the evaluation.
72 */
73REDUCT_API reduct_handle_t reduct_eval_file(reduct_t* reduct, const char* path);
74
75/**
76 * @brief Parses, compiles and evaluates a string.
77 *
78 * @param reduct The Reduct instance.
79 * @param str The string to evaluate.
80 * @param len The length of the string.
81 * @return The result of the evaluation.
82 */
84
85/**
86 * @brief Calls a Reduct callable (closure or native) with arguments.
87 *
88 * @param reduct The Reduct instance.
89 * @param callable The callable item handle.
90 * @param argc The number of arguments.
91 * @param argv Pointer to the arguments array.
92 * @return The result of the call.
93 */
95 reduct_handle_t* argv);
96
97/** @} */
98
99#endif
Core definitions and structures.
size_t reduct_size_t
Definition defs.h:100
reduct_uint64_t reduct_handle_t
Handle type.
Definition defs.h:189
uint32_t reduct_uint32_t
Definition defs.h:95
#define REDUCT_API
Definition defs.h:7
Compiled function.
REDUCT_API reduct_handle_t reduct_eval_string(reduct_t *reduct, const char *str, reduct_size_t len)
Parses, compiles and evaluates a string.
Definition eval_impl.h:528
REDUCT_API void reduct_eval_state_deinit(reduct_eval_state_t *state)
Deinitialize an evaluation state structure.
Definition eval_impl.h:36
REDUCT_API reduct_handle_t reduct_eval_file(reduct_t *reduct, const char *path)
Parses, compiles and evaluates a file.
Definition eval_impl.h:518
REDUCT_API reduct_handle_t reduct_eval_call(reduct_t *reduct, reduct_handle_t callable, reduct_size_t argc, reduct_handle_t *argv)
Calls a Reduct callable (closure or native) with arguments.
Definition eval_impl.h:538
REDUCT_API reduct_handle_t reduct_eval(reduct_t *reduct, reduct_function_t *function)
Evaluates a compiled Reduct function.
reduct_uint32_t reduct_inst_t
Instruction type.
Definition inst.h:97
Handle management.
Evaluation frame structure.
Definition eval.h:29
struct reduct_closure * closure
The closure being evaluated.
Definition eval.h:30
reduct_inst_t * ip
The current instruction pointer.
Definition eval.h:31
reduct_uint32_t prevRegCount
The previous register count to restore upon return.
Definition eval.h:33
reduct_uint32_t base
The base register, where the functions registers start.
Definition eval.h:32
Evaluation state structure.
Definition eval.h:41
reduct_uint32_t regCount
Definition eval.h:46
reduct_handle_t * regs
Definition eval.h:45
reduct_uint32_t frameCapacity
Definition eval.h:44
reduct_eval_frame_t * frames
Definition eval.h:42
reduct_uint32_t frameCount
Definition eval.h:43
reduct_uint32_t regCapacity
Definition eval.h:47
Compiled function structure.
Definition function.h:78
State structure.
Definition core.h:61