2#ifndef REDUCT_FUNCTION_H
3#define REDUCT_FUNCTION_H 1
42typedef struct reduct_const_slot
57#define REDUCT_CONST_SLOT_ITEM(_item) ((reduct_const_slot_t){.type = REDUCT_CONST_SLOT_ITEM, .item = (_item)})
64#define REDUCT_CONST_SLOT_CAPTURE(_capture) \
65 ((reduct_const_slot_t){.type = REDUCT_CONST_SLOT_CAPTURE, .capture = (_capture)})
77typedef struct reduct_function
#define REDUCT_ASSERT(_cond)
#define REDUCT_CONST_SLOT_CAPTURE(_capture)
Create a constant slot containing a variable name to be captured.
reduct_uint16_t reduct_const_t
Constant index type.
REDUCT_API reduct_function_t * reduct_function_new(struct reduct *reduct)
Create a new function.
static void reduct_function_emit(struct reduct *reduct, reduct_function_t *func, reduct_inst_t inst, reduct_uint32_t position)
Emit an instruction to the function.
REDUCT_API void reduct_function_grow(struct reduct *reduct, reduct_function_t *func)
Grow the instruction buffer.
#define REDUCT_CONST_SLOT_ITEM(_item)
Create a constant slot containing an item.
REDUCT_API void reduct_function_init(reduct_function_t *func)
Initialize a function structure.
REDUCT_API reduct_const_t reduct_function_lookup_constant(struct reduct *reduct, reduct_function_t *func, reduct_const_slot_t *slot)
Get the index of a constant in a function's constant template, adding it if it doesn't exist.
REDUCT_API void reduct_function_deinit(reduct_function_t *func)
Deinitialize a function structure.
reduct_const_slot_type_t
Constant slot type.
@ REDUCT_CONST_SLOT_NONE
No constant slot.
reduct_uint32_t reduct_inst_t
Instruction type.
Bytecode instruction format.
reduct_const_slot_type_t type
The type of the constant slot.
struct reduct_item * item
The item contained in the constant slot.
struct reduct_atom * capture
The name of the variable to be captured.
Compiled function structure.
reduct_inst_t * insts
An array of instructions.
reduct_const_slot_t * constants
The array of constant slots forming the constant template.
reduct_uint16_t constantCapacity
Capacity of the constant array.
reduct_uint32_t instCapacity
Capacity of the instruction array.
reduct_uint32_t instCount
Number of instructions.
reduct_uint32_t * positions
An array of source positions parallel to the instructions.
reduct_uint16_t registerCount
The number of registers the function uses.
reduct_uint16_t constantCount
Number of constants.
reduct_uint8_t arity
The number of arguments the function expects.