Reduct  v4.1.3-1-gd06c383
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 template is split into two contiguous regions and describe how a closures constant pool should be created.

The inital captureCount number of constant slots are for captured variables and are specified in the same order as the RVSDG lambda nodes inputs. These are not actually stored physically within the function but instead will be created as empty constants within created closures which are then filled using capture opcodes.

After the captured constants are a constantCount number of static constants which will be copied into the closure's constant pool.

Data Structures

struct  reduct_function_inst_source_t
 Source position of a parallel instruction. More...
 
struct  reduct_function_t
 Compiled function structure. More...
 

Enumerations

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 modulePos, reduct_module_id_t moduleId)
 Emit an instruction to the function.
 
REDUCT_API void reduct_function_set_capture_count (struct reduct *reduct, reduct_function_t *func, uint16_t captureCount)
 Set the number of captured variables for a 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 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_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 43 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  modulePos,
reduct_module_id_t  moduleId 
)
inlinestatic

Emit an instruction to the function.

Parameters
reductPointer to the Reduct structure.
funcThe function to emit to.
instThe instruction to emit.
modulePosThe index within the modules buffer that created the parallel instruction.
moduleIdThe ID of the module that the parallel instruction is associated with.

Definition at line 111 of file function.h.

Here is the call graph for this function:

◆ reduct_function_set_capture_count()

REDUCT_API void reduct_function_set_capture_count ( struct reduct *  reduct,
reduct_function_t func,
uint16_t  captureCount 
)

Set the number of captured variables for a function.

Parameters
reductPointer to the Reduct structure.
funcThe function to modify.
captureCountThe new number of captured variables.

◆ 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_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, can be NULL.

◆ 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, can be NULL.