1#ifndef REDUCT_SCRATCH_H
2#define REDUCT_SCRATCH_H 1
20#define REDUCT_SCRATCH_INITIAL 128
21#define REDUCT_SCRATCH_MAX 16
27typedef struct reduct_scratch
37typedef struct reduct_scratch_state
65#define REDUCT_SCRATCH_GET(_reduct, _name, _type, _length) \
66 _type* _name = NULL; \
69 size_t _needed = (_length) * sizeof(_type); \
70 if ((_reduct)->scratch.size >= REDUCT_SCRATCH_MAX) \
72 REDUCT_ERROR_INTERNAL(_reduct, "scratch buffer overflow"); \
74 reduct_scratch_t* _s = &(_reduct)->scratch.buffers[(_reduct)->scratch.size++]; \
75 _s->buffer = malloc(_needed); \
76 if (_s->buffer == NULL) \
78 REDUCT_ERROR_INTERNAL(_reduct, "out of memory"); \
80 _s->length = _needed; \
81 _name = (_type*)_s->buffer; \
92#define REDUCT_SCRATCH_GROW(_reduct, _name, _type, _length) \
95 size_t _needed = (_length) * sizeof(_type); \
96 reduct_scratch_t* _s = &(_reduct)->scratch.buffers[(_reduct)->scratch.size - 1]; \
97 _s->buffer = realloc(_s->buffer, _needed); \
98 if (_s->buffer == NULL) \
100 REDUCT_ERROR_INTERNAL(_reduct, "out of memory"); \
102 _s->length = _needed; \
103 _name = (_type*)_s->buffer; \
112#define REDUCT_SCRATCH_PUT(_reduct, _name) \
115 assert((_reduct)->scratch.size > 0); \
116 reduct_scratch_t* _s = &(_reduct)->scratch.buffers[--(_reduct)->scratch.size]; \
Atom representation and operations.
Error handling and reporting.
REDUCT_API void reduct_scratch_local_init(reduct_scratch_local_t *local)
Initialize a local scratch state.
REDUCT_API void reduct_scratch_local_deinit(reduct_scratch_local_t *local)
Deinitialize a local scratch state.
#define REDUCT_SCRATCH_MAX
The maximum number of scratch buffers.
Native function and intrinsic registration.
Per-thread scratch-related state structure.
Scratch buffer structure.