Reduct  v1.0.4-3-gdaf0d70
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...
 

Macros

#define REDUCT_CONST_SLOT_ITEM(_item)   ((reduct_const_slot_t){.type = REDUCT_CONST_SLOT_ITEM, .item = (_item)})
 Create a constant slot containing an item.
 
#define REDUCT_CONST_SLOT_CAPTURE(_capture)    ((reduct_const_slot_t){.type = REDUCT_CONST_SLOT_CAPTURE, .capture = (_capture)})
 Create a constant slot containing a variable name to be captured.
 

Typedefs

typedef reduct_uint16_t reduct_const_t
 Constant index type.
 

Enumerations

enum  reduct_const_slot_type_t { REDUCT_CONST_SLOT_NONE , REDUCT_CONST_SLOT_ITEM , REDUCT_CONST_SLOT_CAPTURE }
 Constant slot type. More...
 

Functions

REDUCT_API void reduct_function_init (reduct_function_t *func)
 Initialize a function structure.
 
REDUCT_API void reduct_function_deinit (reduct_function_t *func)
 Deinitialize 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, reduct_uint32_t position)
 Emit an instruction to the function.
 
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.
 

Macro Definition Documentation

◆ REDUCT_CONST_SLOT_ITEM

#define REDUCT_CONST_SLOT_ITEM (   _item)    ((reduct_const_slot_t){.type = REDUCT_CONST_SLOT_ITEM, .item = (_item)})

Create a constant slot containing an item.

Parameters
_itemThe item to wrap in a slot.

Definition at line 57 of file function.h.

◆ REDUCT_CONST_SLOT_CAPTURE

#define REDUCT_CONST_SLOT_CAPTURE (   _capture)     ((reduct_const_slot_t){.type = REDUCT_CONST_SLOT_CAPTURE, .capture = (_capture)})

Create a constant slot containing a variable name to be captured.

Parameters
_captureThe name of the variable to be captured.

Definition at line 64 of file function.h.

Typedef Documentation

◆ reduct_const_t

Constant index type.

Definition at line 71 of file function.h.

Enumeration Type Documentation

◆ reduct_const_slot_type_t

Constant slot type.

Enumerator
REDUCT_CONST_SLOT_NONE 

No constant slot.

REDUCT_CONST_SLOT_ITEM 

A constant slot containing an item.

REDUCT_CONST_SLOT_CAPTURE 

A constant slot containing a variable name to be captured.

Definition at line 31 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.

Definition at line 10 of file function_impl.h.

Here is the caller graph for this function:

◆ reduct_function_deinit()

REDUCT_API void reduct_function_deinit ( reduct_function_t func)

Deinitialize a function structure.

Parameters
funcThe function to deinitialize.

Definition at line 25 of file function_impl.h.

Here is the caller graph for this function:

◆ reduct_function_new()

REDUCT_API reduct_function_t * reduct_function_new ( struct reduct *  reduct)

Create a new function.

Parameters
reductThe Reduct structure.
Returns
A pointer to the newly allocated function.
Here is the caller graph for this function:

◆ reduct_function_grow()

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

Grow the instruction buffer.

Parameters
reductThe 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,
reduct_uint32_t  position 
)
inlinestatic

Emit an instruction to the function.

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

Definition at line 128 of file function.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reduct_function_lookup_constant()

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.

Parameters
reductThe Reduct structure.
funcThe function.
slotThe constant slot to add or lookup.
Returns
The index of the constant in the constant template.
Here is the caller graph for this function: