Reduct  v4.1.3-1-gd06c383
A functional and immutable language.
Loading...
Searching...
No Matches
closure.h
Go to the documentation of this file.
1#ifndef REDUCT_CLOSURE_H
2#define REDUCT_CLOSURE_H 1
3
4struct reduct_item;
5
6#include <reduct/defs.h>
7#include <reduct/function.h>
8
9/**
10 * @file closure.h
11 * @brief Closure management.
12 * @defgroup closure Closure
13 *
14 * A closure is a function instance that has captured variables from its enclosing scope.
15 *
16 * @{
17 */
18
19#define REDUCT_CLOSURE_SMALL_MAX 4 ///< The maximum number of small constants.
20
21/**
22 * @brief Closure structure.
23 * @struct reduct_closure_t
24 */
25typedef struct reduct_closure
26{
27 reduct_function_t* function; ///< Pointer to the prototype function item.
28 size_t constantCount; ///< The number of constants in the constant pool (equal to the number of captured and static
29 ///< constants in the function).
30 reduct_handle_t* constants; ///< The array of constants forming the constant pool.
33
34/**
35 * @brief Allocate a new closure.
36 *
37 * @param reduct Pointer to the Reduct structure.
38 * @param function The prototype function item.
39 * @return A pointer to the newly allocated closure.
40 */
42
43/**
44 * @brief Retain a closure, preventing it from being collected by the garbage collector.
45 *
46 * @param reduct Pointer to the Reduct structure.
47 * @param closure Pointer to the closure, can be `NULL`.
48 */
49REDUCT_API void reduct_closure_retain(struct reduct* reduct, reduct_closure_t* closure);
50
51/**
52 * @brief Release a closure, potentially allowing the garbage collector to collect it.
53 *
54 * @param reduct Pointer to the Reduct structure.
55 * @param closure Pointer to the closure, can be `NULL`.
56 */
57REDUCT_API void reduct_closure_release(struct reduct* reduct, reduct_closure_t* closure);
58
59/** @} */
60
61#endif
#define REDUCT_API
Definition defs.h:24
Compiled function.
REDUCT_API reduct_closure_t * reduct_closure_new(struct reduct *reduct, reduct_function_t *function)
Allocate a new closure.
#define REDUCT_CLOSURE_SMALL_MAX
The maximum number of small constants.
Definition closure.h:19
REDUCT_API void reduct_closure_release(struct reduct *reduct, reduct_closure_t *closure)
Release a closure, potentially allowing the garbage collector to collect it.
REDUCT_API void reduct_closure_retain(struct reduct *reduct, reduct_closure_t *closure)
Retain a closure, preventing it from being collected by the garbage collector.
Closure structure.
Definition closure.h:26
size_t constantCount
Definition closure.h:28
reduct_handle_t * constants
The array of constants forming the constant pool.
Definition closure.h:30
reduct_function_t * function
Pointer to the prototype function item.
Definition closure.h:27
Compiled function structure.
Definition function.h:65
Handle type.
Definition defs.h:121