Reduct  v4.0.5-1-g4851deb
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 5 ///< 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 reduct_handle_t* constants; ///< The array of constant slots forming the constant template.
31
32/**
33 * @brief Allocate a new closure.
34 *
35 * @param reduct Pointer to the Reduct structure.
36 * @param function The prototype function item.
37 * @return A pointer to the newly allocated closure.
38 */
40
41/**
42 * @brief Retain a closure, preventing it from being collected by the garbage collector.
43 *
44 * @param reduct Pointer to the Reduct structure.
45 * @param closure Pointer to the closure.
46 */
47REDUCT_API void reduct_closure_retain(struct reduct* reduct, reduct_closure_t* closure);
48
49/**
50 * @brief Release a closure, potentially allowing the garbage collector to collect it.
51 *
52 * @param reduct Pointer to the Reduct structure.
53 * @param closure Pointer to the closure.
54 */
55REDUCT_API void reduct_closure_release(struct reduct* reduct, reduct_closure_t* closure);
56
57/** @} */
58
59#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
reduct_handle_t * constants
The array of constant slots forming the constant template.
Definition closure.h:28
reduct_function_t * function
Pointer to the prototype function item.
Definition closure.h:27
Compiled function structure.
Definition function.h:68
Handle type.
Definition defs.h:119