Reduct  v1.0.4-3-gdaf0d70
A functional and immutable language.
Loading...
Searching...
No Matches
closure_impl.h
Go to the documentation of this file.
1#ifndef REDUCT_CLOSURE_IMPL_H
2#define REDUCT_CLOSURE_IMPL_H 1
3
4#include "closure.h"
5#include "handle.h"
6#include "item.h"
7
9{
10 REDUCT_ASSERT(closure != REDUCT_NULL);
11 if (closure->constants != closure->smallConstants)
12 {
13 REDUCT_FREE(closure->constants);
14 }
15}
16
18{
19 REDUCT_ASSERT(reduct != REDUCT_NULL);
20 REDUCT_ASSERT(function != REDUCT_NULL);
21
22 reduct_item_t* item = reduct_item_new(reduct);
24 reduct_closure_t* closure = &item->closure;
25 closure->function = function;
27 {
28 closure->constants = closure->smallConstants;
29 }
30 else
31 {
33 }
34
35 for (reduct_uint16_t i = 0; i < function->constantCount; i++)
36 {
37 if (function->constants[i].type != REDUCT_CONST_SLOT_ITEM)
38 {
39 closure->constants[i] = REDUCT_HANDLE_NONE;
40 continue;
41 }
42
43 reduct_item_t* item = function->constants[i].item;
45 {
47 }
48 else if (item->flags & REDUCT_ITEM_FLAG_FLOAT_SHAPED)
49 {
51 }
52 else
53 {
54 closure->constants[i] = REDUCT_HANDLE_FROM_ITEM(item);
55 }
56 }
57
58 return closure;
59}
60
61#endif
Closure management.
#define REDUCT_MALLOC(_size)
Definition defs.h:27
reduct_uint64_t reduct_handle_t
Handle type.
Definition defs.h:189
#define REDUCT_ASSERT(_cond)
Definition defs.h:25
#define REDUCT_FREE(_ptr)
Definition defs.h:30
#define REDUCT_API
Definition defs.h:7
uint16_t reduct_uint16_t
Definition defs.h:97
#define REDUCT_NULL
Definition defs.h:23
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_deinit(reduct_closure_t *closure)
Deinitialize a closure structure.
Definition closure_impl.h:8
#define REDUCT_CONST_SLOT_ITEM(_item)
Create a constant slot containing an item.
Definition function.h:57
#define REDUCT_HANDLE_FROM_FLOAT(_val)
Create a handle from a float.
Definition handle.h:62
#define REDUCT_HANDLE_FROM_INT(_val)
Create a handle from an integer.
Definition handle.h:54
#define REDUCT_HANDLE_FROM_ITEM(_ptr)
Create a handle from an item pointer.
Definition handle.h:76
#define REDUCT_HANDLE_NONE
Invalid handle constant.
Definition handle.h:36
#define REDUCT_ITEM_FLAG_INT_SHAPED
Item is an integer shaped atom.
Definition item.h:39
#define REDUCT_ITEM_FLAG_FLOAT_SHAPED
Item is a float shaped atom.
Definition item.h:40
REDUCT_API reduct_item_t * reduct_item_new(struct reduct *reduct)
Allocate a new Reduct item.
#define REDUCT_ITEM_TYPE_CLOSURE
A closure.
Definition item.h:30
Handle management.
Item management.
reduct_int64_t integerValue
Pre-computed integer value, item must have REDUCT_ITEM_FLAG_INT_SHAPED.
Definition atom.h:55
reduct_float_t floatValue
Pre-computed float value, item must have REDUCT_ITEM_FLAG_FLOAT_SHAPED.
Definition atom.h:56
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
reduct_handle_t smallConstants[REDUCT_CLOSURE_SMALL_MAX]
Definition closure.h:29
reduct_const_slot_type_t type
The type of the constant slot.
Definition function.h:44
struct reduct_item * item
The item contained in the constant slot.
Definition function.h:47
Compiled function structure.
Definition function.h:78
reduct_const_slot_t * constants
The array of constant slots forming the constant template.
Definition function.h:83
reduct_uint16_t constantCount
Number of constants.
Definition function.h:84
Item structure.
Definition item.h:57
reduct_closure_t closure
A closure.
Definition item.h:70
reduct_item_flags_t flags
Flags for the item.
Definition item.h:60
reduct_atom_t atom
An atom.
Definition item.h:66
reduct_item_type_t type
The type of the item.
Definition item.h:61