The evaluator is a register-based virtual machine executing the bytecode produced by the emitter.
- Warning
- Calls are zero-copy such that the callee's frame is placed directly over the caller's argument registers, so arguments become the callee's starting registers, and tail calls reuse the current frame.
-
Registers and frames are held in arrays that are realloc'd as frames are pushed and popped. Any pointer into them, most notably the argv pointer passed to native functions, is only valid for the duration of the call that produced it. Native functions that call back into Reduct must copy the handles they need out of argv before doing so.
|
| REDUCT_API void | reduct_eval_local_init (reduct_eval_local_t *local) |
| | Initialize a local eval state.
|
| |
| REDUCT_API void | reduct_eval_local_deinit (reduct_eval_local_t *local) |
| | Deinitialize a local eval state.
|
| |
| REDUCT_API reduct_handle_t | reduct_eval (struct reduct *reduct, reduct_handle_t handle) |
| | Evaluates a handle.
|
| |
| REDUCT_API reduct_handle_t | reduct_eval_file (struct reduct *reduct, const char *path, reduct_optimize_flags_t optimize) |
| | Parses, builds, optimizes, emits and evaluates a file.
|
| |
| REDUCT_API reduct_handle_t | reduct_eval_string (struct reduct *reduct, const char *str, size_t len, reduct_optimize_flags_t optimize) |
| | Parses, builds, optimizes, emits and evaluates a string.
|
| |
| REDUCT_API reduct_handle_t | reduct_eval_call (struct reduct *reduct, reduct_handle_t callable, size_t argc, reduct_handle_t *argv) |
| | Calls a Reduct callable (closure or native) with arguments.
|
| |
| REDUCT_API reduct_handle_t | reduct_eval_call_v (struct reduct *reduct, reduct_handle_t callable, size_t argc,...) |
| | Calls a Reduct callable (closure or native) with variadic arguments.
|
| |
◆ REDUCT_EVAL_REGS_INITIAL
| #define REDUCT_EVAL_REGS_INITIAL 64 |
The initial amount of registers.
Definition at line 27 of file eval.h.
◆ REDUCT_EVAL_REGS_GROWTH_FACTOR
| #define REDUCT_EVAL_REGS_GROWTH_FACTOR 2 |
The growth factor of the registers array.
Definition at line 28 of file eval.h.
◆ REDUCT_EVAL_FRAMES_INITIAL
| #define REDUCT_EVAL_FRAMES_INITIAL 32 |
The initial size of the frames array.
Definition at line 30 of file eval.h.
◆ REDUCT_EVAL_FRAMES_GROWTH_FACTOR
| #define REDUCT_EVAL_FRAMES_GROWTH_FACTOR 2 |
The growth factor of the frames array.
Definition at line 31 of file eval.h.
◆ reduct_eval_local_init()
Initialize a local eval state.
- Parameters
-
| local | Pointer to the local eval state to initialize. |
◆ reduct_eval_local_deinit()
Deinitialize a local eval state.
- Parameters
-
| local | Pointer to the local eval state to deinitialize. |
◆ reduct_eval()
Evaluates a handle.
If the handle is a compiled function then it will be interpreted, otherwise, it will first be compiled into a function.
- Warning
- May be called re-entrantly, including from within a native function. Doing so may grow the register and frame arrays, invalidating any pointers previously obtained into them.
- Parameters
-
| reduct | The Reduct instance. |
| handle | The handle to evaluate. |
- Returns
- The result of the evaluation as a Reduct handle.
◆ reduct_eval_file()
Parses, builds, optimizes, emits and evaluates a file.
- Warning
- May be called re-entrantly, including from within a native function. Doing so may grow the register and frame arrays, invalidating any pointers previously obtained into them.
- Parameters
-
| reduct | The Reduct instance. |
| path | The path to the file. |
| flags | Optimization flags to control which optimizations are applied. |
- Returns
- The result of the evaluation.
◆ reduct_eval_string()
Parses, builds, optimizes, emits and evaluates a string.
- Warning
- May be called re-entrantly, including from within a native function. Doing so may grow the register and frame arrays, invalidating any pointers previously obtained into them.
- Parameters
-
| reduct | The Reduct instance. |
| str | The string to evaluate. |
| len | The length of the string. |
| flags | Optimization flags to control which optimizations are applied. |
- Returns
- The result of the evaluation.
◆ reduct_eval_call()
Calls a Reduct callable (closure or native) with arguments.
- Warning
- May be called re-entrantly, including from within a native function. Doing so may grow the register and frame arrays, invalidating any pointers previously obtained into them.
- Parameters
-
| reduct | The Reduct instance. |
| callable | The callable item handle. |
| argc | The number of arguments. |
| argv | Pointer to the arguments array. |
- Returns
- The result of the call.
◆ reduct_eval_call_v()
Calls a Reduct callable (closure or native) with variadic arguments.
- Warning
- May be called re-entrantly, including from within a native function. Doing so may grow the register and frame arrays, invalidating any pointers previously obtained into them.
- Parameters
-
| reduct | The Reduct instance. |
| callable | The callable item handle. |
| argc | The number of arguments. |
| ... | The arguments (as reduct_handle_t). |
- Returns
- The result of the call.