forked from urbit/vere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimprison.h
170 lines (141 loc) · 4.85 KB
/
imprison.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/// @file
#ifndef U3_IMPRISON_H
#define U3_IMPRISON_H
#include "allocate.h"
#include "c3.h"
#include "gmp.h"
#include "types.h"
/** Structures.
**/
/* u3i_slab: atom builder.
*/
typedef struct _u3i_slab {
struct { // internals
u3a_atom* _vat_u; // heap atom (nullable)
c3_w _sat_w; // static storage
} _; //
union { //
c3_y* buf_y; // bytes
c3_w* buf_w; // words
}; //
c3_w len_w; // word length
} u3i_slab;
/* staged atom-building api
*/
/* u3i_slab_init(): configure bloq-length slab, zero-initialize.
*/
void
u3i_slab_init(u3i_slab* sab_u, c3_g met_g, c3_d len_d);
/* u3i_slab_bare(): configure bloq-length slab, uninitialized.
*/
void
u3i_slab_bare(u3i_slab* sab_u, c3_g met_g, c3_d len_d);
/* u3i_slab_from(): configure bloq-length slab, initialize with [a].
*/
void
u3i_slab_from(u3i_slab* sab_u, u3_atom a, c3_g met_g, c3_d len_d);
/* u3i_slab_grow(): resize slab, zero-initializing new space.
*/
void
u3i_slab_grow(u3i_slab* sab_u, c3_g met_g, c3_d len_d);
/* u3i_slab_free(): dispose memory backing slab.
*/
void
u3i_slab_free(u3i_slab* sab_u);
/* u3i_slab_mint(): produce atom from slab, trimming.
*/
u3_atom
u3i_slab_mint(u3i_slab* sab_u);
/* u3i_slab_moot(): produce atom from slab, no trimming.
*/
u3_atom
u3i_slab_moot(u3i_slab* sab_u);
/* u3i_slab_mint_bytes(): produce atom from byte-slab, trimming.
** XX assumes little-endian, implement swap to support big-endian
*/
# define u3i_slab_mint_bytes u3i_slab_mint
/* u3i_slab_moot_bytes(): produce atom from byte-slab, no trimming.
** XX assumes little-endian, implement swap to support big-endian
*/
# define u3i_slab_moot_bytes u3i_slab_moot
/* General constructors.
*/
/* u3i_word(): construct u3_atom from c3_w.
*/
u3_atom
u3i_word(c3_w dat_w);
/* u3i_chub(): construct u3_atom from c3_d.
*/
u3_atom
u3i_chub(c3_d dat_d);
/* u3i_bytes(): Copy [a] bytes from [b] to an LSB first atom.
*/
u3_atom
u3i_bytes(c3_w a_w,
const c3_y* b_y);
/* u3i_words(): Copy [a] words from [b] into an atom.
*/
u3_atom
u3i_words(c3_w a_w,
const c3_w* b_w);
/* u3i_chubs(): Copy [a] chubs from [b] into an atom.
*/
u3_atom
u3i_chubs(c3_w a_w,
const c3_d* b_d);
/* u3i_mp(): Copy the GMP integer [a] into an atom, and clear it.
*/
u3_atom
u3i_mp(mpz_t a_mp);
/* u3i_vint(): increment [a].
*/
u3_atom
u3i_vint(u3_noun a);
/* u3i_cell(): Produce the cell `[a b]`.
*/
u3_noun
u3i_cell(u3_noun a, u3_noun b);
# define u3nc(a, b) u3i_cell(a, b)
/* u3i_defcons(): allocate cell for deferred construction.
** NB: [hed] and [tel] pointers MUST be filled.
*/
u3_cell
u3i_defcons(u3_noun** hed, u3_noun** tel);
/* u3i_trel(): Produce the triple `[a b c]`.
*/
u3_noun
u3i_trel(u3_noun a, u3_noun b, u3_noun c);
# define u3nt(a, b, c) u3i_trel(a, b, c)
/* u3i_qual(): Produce the cell `[a b c d]`.
*/
u3_noun
u3i_qual(u3_noun a, u3_noun b, u3_noun c, u3_noun d);
# define u3nq(a, b, c, d) u3i_qual(a, b, c, d)
/* u3i_string(): Produce an LSB-first atom from the C string [a].
*/
u3_atom
u3i_string(const c3_c* a_c);
/* u3i_tape(): from a C string, to a list of bytes.
*/
u3_noun
u3i_tape(const c3_c* txt_c);
/* u3i_list(): list from `u3_none`-terminated varargs.
*/
u3_noun
u3i_list(u3_weak som, ...);
# define u3nl u3i_list
/* u3i_edit():
**
** Mutate `big` at axis `axe` with new value `som`
** `axe` is RETAINED.
*/
u3_noun
u3i_edit(u3_noun big, u3_noun axe, u3_noun som);
/* u3i_molt():
**
** Mutate `som` with a 0-terminated list of axis, noun pairs.
** Axes must be cats (31 bit).
*/
u3_noun
u3i_molt(u3_noun som, ...);
#endif /* ifndef U3_IMPRISON_H */