Reduct  v4.0.5-1-g4851deb
A functional and immutable language.
Loading...
Searching...
No Matches
Reduct function

Detailed Description

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.

Data Structures

struct  reduct_const_slot_t
 Constant slot. More...
 
struct  reduct_function_t
 Compiled function structure. More...
 

Enumerations

enum  reduct_const_slot_type_t { REDUCT_CONST_SLOT_TYPE_NONE , REDUCT_CONST_SLOT_TYPE_STATIC , REDUCT_CONST_SLOT_TYPE_CAPTURE }
 Constant slot type. More...
 
enum  reduct_function_flags_t { REDUCT_FUNCTION_FLAG_NONE = 0 , REDUCT_FUNCTION_FLAG_VARIADIC = 1 << 0 , REDUCT_FUNCTION_FLAG_OPTIMIZED = 1 << 1 }
 Function flags. More...
 

Functions

REDUCT_API void reduct_function_init (reduct_function_t *func)
 Initialize a function structure.
 
REDUCT_API reduct_function_treduct_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.
 

Enumeration Type Documentation

◆ 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.

Function Documentation

◆ reduct_function_init()

REDUCT_API void reduct_function_init ( reduct_function_t func)

Initialize a function structure.

Parameters
funcThe function to initialize.

◆ reduct_function_new()

REDUCT_API reduct_function_t * reduct_function_new ( struct reduct *  reduct)

Create a new function.

Parameters
reductPointer to the Reduct structure.
Returns
A pointer to the newly allocated function.

◆ reduct_function_grow()

REDUCT_API void reduct_function_grow ( struct reduct *  reduct,
reduct_function_t func 
)

Grow the instruction buffer.

Parameters
reductPointer to the Reduct structure.
funcThe function to grow.
Here is the caller graph for this function:

◆ reduct_function_emit()

static void reduct_function_emit ( struct reduct *  reduct,
reduct_function_t func,
reduct_inst_t  inst,
uint32_t  position 
)
inlinestatic

Emit an instruction to the function.

Parameters
reductPointer to the Reduct structure.
funcThe function to emit to.
instThe instruction to emit.
positionThe position in the source code.

Definition at line 112 of file function.h.

Here is the call graph for this function:

◆ reduct_function_add_constant()

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.

Will return the index of an existing identical constant if found.

Parameters
reductPointer to the Reduct structure.
funcThe function.
handleThe value to add.
Returns
The index in the constant pool.

◆ reduct_function_add_capture()

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.

Parameters
reductPointer to the Reduct structure.
funcThe function.
Returns
The index in the constant pool.

◆ reduct_function_retain()

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.

Parameters
reductPointer to the Reduct structure.
functionPointer to the function.

◆ reduct_function_release()

REDUCT_API void reduct_function_release ( struct reduct *  reduct,
reduct_function_t function 
)

Release a function, potentially allowing the garbage collector to collect it.

Parameters
reductPointer to the Reduct structure.
functionPointer to the function.