A reduct function is a sequence of instructions and an associated constant pool that can be executed by the Reduct virtual machine.
Constants Template
A function's constant pool is actually a template of constant slots. These slots can either contain ann item or a variable name that needs to be captured from the enclosing scope when a closure is created.
|
| REDUCT_API void | reduct_function_init (reduct_function_t *func) |
| | Initialize a function structure.
|
| |
| REDUCT_API reduct_function_t * | reduct_function_new (struct reduct *reduct) |
| | Create a new function.
|
| |
| REDUCT_API void | reduct_function_grow (struct reduct *reduct, reduct_function_t *func) |
| | Grow the instruction buffer.
|
| |
| static void | reduct_function_emit (struct reduct *reduct, reduct_function_t *func, reduct_inst_t inst, uint32_t position) |
| | Emit an instruction to the function.
|
| |
| REDUCT_API reduct_const_t | reduct_function_add_constant (struct reduct *reduct, reduct_function_t *func, reduct_handle_t handle) |
| | Add a static constant to the function's template, returning its index.
|
| |
| REDUCT_API reduct_const_t | reduct_function_add_capture (struct reduct *reduct, reduct_function_t *func) |
| | Add a capture placeholder slot to the function's template, returning its index.
|
| |
| REDUCT_API void | reduct_function_retain (struct reduct *reduct, reduct_function_t *function) |
| | Retain a function, preventing it from being collected by the garbage collector.
|
| |
| REDUCT_API void | reduct_function_release (struct reduct *reduct, reduct_function_t *function) |
| | Release a function, potentially allowing the garbage collector to collect it.
|
| |
◆ reduct_const_slot_type_t
Constant slot type.
| Enumerator |
|---|
| REDUCT_CONST_SLOT_TYPE_NONE | No constant slot.
|
| REDUCT_CONST_SLOT_TYPE_STATIC | A constant slot containing a static value.
|
| REDUCT_CONST_SLOT_TYPE_CAPTURE | A constant slot acting as a placeholder for a capture.
|
Definition at line 35 of file function.h.
◆ reduct_function_flags_t
Function flags.
| Enumerator |
|---|
| REDUCT_FUNCTION_FLAG_NONE | |
| REDUCT_FUNCTION_FLAG_VARIADIC | Function accepts variadic arguments.
|
| REDUCT_FUNCTION_FLAG_OPTIMIZED | Function has been optimized.
|
Definition at line 56 of file function.h.
◆ reduct_function_init()
Initialize a function structure.
- Parameters
-
| func | The function to initialize. |
◆ reduct_function_new()
Create a new function.
- Parameters
-
| reduct | Pointer to the Reduct structure. |
- Returns
- A pointer to the newly allocated function.
◆ reduct_function_grow()
Grow the instruction buffer.
- Parameters
-
| reduct | Pointer to the Reduct structure. |
| func | The function to grow. |
◆ reduct_function_emit()
Emit an instruction to the function.
- Parameters
-
| reduct | Pointer to the Reduct structure. |
| func | The function to emit to. |
| inst | The instruction to emit. |
| position | The position in the source code. |
Definition at line 112 of file function.h.
◆ reduct_function_add_constant()
Add a static constant to the function's template, returning its index.
Will return the index of an existing identical constant if found.
- Parameters
-
| reduct | Pointer to the Reduct structure. |
| func | The function. |
| handle | The value to add. |
- Returns
- The index in the constant pool.
◆ reduct_function_add_capture()
Add a capture placeholder slot to the function's template, returning its index.
- Parameters
-
| reduct | Pointer to the Reduct structure. |
| func | The function. |
- Returns
- The index in the constant pool.
◆ reduct_function_retain()
Retain a function, preventing it from being collected by the garbage collector.
- Parameters
-
| reduct | Pointer to the Reduct structure. |
| function | Pointer to the function. |
◆ reduct_function_release()
Release a function, potentially allowing the garbage collector to collect it.
- Parameters
-
| reduct | Pointer to the Reduct structure. |
| function | Pointer to the function. |