yeptris 0.6.7.2-aarch64-linux → 0.6.7.4-aarch64-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/lib/yeptris.rb +1 -1
  3. data/vendor/libyeptris/CMakeLists.txt +254 -0
  4. data/vendor/libyeptris/cmake/yeptris-config.cmake.in +5 -0
  5. data/vendor/libyeptris/cmake/yeptris.pc.in +11 -0
  6. data/vendor/libyeptris/src/CMakeLists.txt +167 -0
  7. data/vendor/libyeptris/src/include/yeptris/api.h +32 -0
  8. data/vendor/libyeptris/src/include/yeptris/cbor.h +101 -0
  9. data/vendor/libyeptris/src/include/yeptris/dom.h +181 -0
  10. data/vendor/libyeptris/src/include/yeptris/emit.h +81 -0
  11. data/vendor/libyeptris/src/include/yeptris/error.h +41 -0
  12. data/vendor/libyeptris/src/include/yeptris/events.h +157 -0
  13. data/vendor/libyeptris/src/include/yeptris/json.h +45 -0
  14. data/vendor/libyeptris/src/include/yeptris/json.hpp +258 -0
  15. data/vendor/libyeptris/src/include/yeptris/jsonc_compat.h +115 -0
  16. data/vendor/libyeptris/src/include/yeptris/marshal.h +52 -0
  17. data/vendor/libyeptris/src/include/yeptris/parse.h +48 -0
  18. data/vendor/libyeptris/src/include/yeptris/plan.h +100 -0
  19. data/vendor/libyeptris/src/include/yeptris/resolve.h +71 -0
  20. data/vendor/libyeptris/src/include/yeptris/schema.h +119 -0
  21. data/vendor/libyeptris/src/include/yeptris/tape.h +99 -0
  22. data/vendor/libyeptris/src/include/yeptris/types.h +38 -0
  23. data/vendor/libyeptris/src/include/yeptris/values.h +102 -0
  24. data/vendor/libyeptris/src/include/yeptris/version.h.in +29 -0
  25. data/vendor/libyeptris/src/include/yeptris/visit.h +77 -0
  26. data/vendor/libyeptris/src/include/yeptris/yajl_compat.h +135 -0
  27. data/vendor/libyeptris/src/include/yeptris.h +23 -0
  28. data/vendor/libyeptris/src/yeptris/build.c +371 -0
  29. data/vendor/libyeptris/src/yeptris/cbor/cbor.h +25 -0
  30. data/vendor/libyeptris/src/yeptris/cbor/decode.c +846 -0
  31. data/vendor/libyeptris/src/yeptris/cbor/encode.c +821 -0
  32. data/vendor/libyeptris/src/yeptris/common/chartype.c +41 -0
  33. data/vendor/libyeptris/src/yeptris/common/chartype.h +77 -0
  34. data/vendor/libyeptris/src/yeptris/common/cpu.c +81 -0
  35. data/vendor/libyeptris/src/yeptris/common/cpu.h +40 -0
  36. data/vendor/libyeptris/src/yeptris/common/error.c +65 -0
  37. data/vendor/libyeptris/src/yeptris/common/error.h +79 -0
  38. data/vendor/libyeptris/src/yeptris/common/mutex.h +45 -0
  39. data/vendor/libyeptris/src/yeptris/common/nametab.c +275 -0
  40. data/vendor/libyeptris/src/yeptris/common/nametab.h +68 -0
  41. data/vendor/libyeptris/src/yeptris/common/port.h +74 -0
  42. data/vendor/libyeptris/src/yeptris/common/simd_text.c +46 -0
  43. data/vendor/libyeptris/src/yeptris/common/simd_text.h +295 -0
  44. data/vendor/libyeptris/src/yeptris/common/simd_text_avx2.c +534 -0
  45. data/vendor/libyeptris/src/yeptris/common/simd_text_neon.c +662 -0
  46. data/vendor/libyeptris/src/yeptris/common/simd_text_scalar.c +298 -0
  47. data/vendor/libyeptris/src/yeptris/common/string_view.c +34 -0
  48. data/vendor/libyeptris/src/yeptris/common/string_view.h +93 -0
  49. data/vendor/libyeptris/src/yeptris/doc.h +37 -0
  50. data/vendor/libyeptris/src/yeptris/dom/dom.c +973 -0
  51. data/vendor/libyeptris/src/yeptris/dom/dom.h +290 -0
  52. data/vendor/libyeptris/src/yeptris/dom/hpool.c +107 -0
  53. data/vendor/libyeptris/src/yeptris/dom/mapindex.c +166 -0
  54. data/vendor/libyeptris/src/yeptris/dom/mapindex.h +61 -0
  55. data/vendor/libyeptris/src/yeptris/dom/mutate.c +429 -0
  56. data/vendor/libyeptris/src/yeptris/emit/emit.c +349 -0
  57. data/vendor/libyeptris/src/yeptris/emit/float/api.h +38 -0
  58. data/vendor/libyeptris/src/yeptris/emit/float/dragon.c +405 -0
  59. data/vendor/libyeptris/src/yeptris/emit/float/floatint.h +196 -0
  60. data/vendor/libyeptris/src/yeptris/emit/float/print.c +396 -0
  61. data/vendor/libyeptris/src/yeptris/emit/style.c +81 -0
  62. data/vendor/libyeptris/src/yeptris/emit/style.h +24 -0
  63. data/vendor/libyeptris/src/yeptris/emit/writer.c +746 -0
  64. data/vendor/libyeptris/src/yeptris/emit/writer.h +61 -0
  65. data/vendor/libyeptris/src/yeptris/encoding/bom.c +31 -0
  66. data/vendor/libyeptris/src/yeptris/encoding/encoding.h +63 -0
  67. data/vendor/libyeptris/src/yeptris/encoding/transcode.c +148 -0
  68. data/vendor/libyeptris/src/yeptris/encoding/utf8_validate.c +178 -0
  69. data/vendor/libyeptris/src/yeptris/events/capture.c +150 -0
  70. data/vendor/libyeptris/src/yeptris/events/capture.h +39 -0
  71. data/vendor/libyeptris/src/yeptris/events/iterparse.c +208 -0
  72. data/vendor/libyeptris/src/yeptris/events/pull.c +97 -0
  73. data/vendor/libyeptris/src/yeptris/events/push.c +104 -0
  74. data/vendor/libyeptris/src/yeptris/events/recorder.c +107 -0
  75. data/vendor/libyeptris/src/yeptris/events/values.c +527 -0
  76. data/vendor/libyeptris/src/yeptris/events/values_priv.h +51 -0
  77. data/vendor/libyeptris/src/yeptris/events/yaml_compat.c +86 -0
  78. data/vendor/libyeptris/src/yeptris/events/yaml_compat.h +90 -0
  79. data/vendor/libyeptris/src/yeptris/jsonapi/jsonc_compat.c +687 -0
  80. data/vendor/libyeptris/src/yeptris/jsonapi/yajl_compat.c +728 -0
  81. data/vendor/libyeptris/src/yeptris/marshal.c +744 -0
  82. data/vendor/libyeptris/src/yeptris/memory/allocator.c +20 -0
  83. data/vendor/libyeptris/src/yeptris/memory/allocator.h +43 -0
  84. data/vendor/libyeptris/src/yeptris/memory/arena.c +134 -0
  85. data/vendor/libyeptris/src/yeptris/memory/arena.h +52 -0
  86. data/vendor/libyeptris/src/yeptris/memory/pool.c +115 -0
  87. data/vendor/libyeptris/src/yeptris/memory/pool.h +36 -0
  88. data/vendor/libyeptris/src/yeptris/parse/engine.c +3689 -0
  89. data/vendor/libyeptris/src/yeptris/parse/engine.h +65 -0
  90. data/vendor/libyeptris/src/yeptris/parse/events.h +124 -0
  91. data/vendor/libyeptris/src/yeptris/parse/numbers.c +349 -0
  92. data/vendor/libyeptris/src/yeptris/parse/numbers.h +33 -0
  93. data/vendor/libyeptris/src/yeptris/parse/scalars.c +416 -0
  94. data/vendor/libyeptris/src/yeptris/parse/scalars.h +75 -0
  95. data/vendor/libyeptris/src/yeptris/parse.c +650 -0
  96. data/vendor/libyeptris/src/yeptris/plan.c +817 -0
  97. data/vendor/libyeptris/src/yeptris/resolve/compat11.c +334 -0
  98. data/vendor/libyeptris/src/yeptris/resolve/core12.c +143 -0
  99. data/vendor/libyeptris/src/yeptris/resolve/resolver.h +56 -0
  100. data/vendor/libyeptris/src/yeptris/resolve/tags.c +58 -0
  101. data/vendor/libyeptris/src/yeptris/scan/json.c +792 -0
  102. data/vendor/libyeptris/src/yeptris/scan/json.h +109 -0
  103. data/vendor/libyeptris/src/yeptris/scan/scan.c +463 -0
  104. data/vendor/libyeptris/src/yeptris/scan/scan.h +150 -0
  105. data/vendor/libyeptris/src/yeptris/schema.c +238 -0
  106. data/vendor/libyeptris/src/yeptris/tape.c +1292 -0
  107. data/vendor/libyeptris/src/yeptris/version.c +7 -0
  108. data/vendor/libyeptris/src/yeptris/visit/dom_visit.c +115 -0
  109. data/vendor/libyeptris/src/yeptris/visit/json_visit.c +293 -0
  110. data/vendor/libyeptris/src/yeptris/visit/yaml_visit.c +127 -0
  111. metadata +111 -4
@@ -0,0 +1,290 @@
1
+ /* dom.h — minimal event-built DOM (TODO.impl/11 v1).
2
+ *
3
+ * Nodes are dense records in a pool; children are sibling-linked
4
+ * (first_child/last_child/next_sibling) — safe when parent and child
5
+ * collections interleave. Anchors bind to node ids. The builder is a
6
+ * sink over the engine (MECE: the DOM never parses). v1 deviation from
7
+ * the board (recorded there): one dom.c with a kind enum — per-kind
8
+ * vtables land with mutation + emitter integration, where polymorphic
9
+ * behavior actually appears.
10
+ *
11
+ * Lifetime: borrowed event values (from the caller's input) stay views
12
+ * into that input; engine-pool values (folded/escaped) are copied into
13
+ * the DOM's pool. The input buffer must outlive the document.
14
+ */
15
+ #ifndef YEP_DOM_H
16
+ #define YEP_DOM_H
17
+
18
+ #include <stdint.h>
19
+
20
+ #include <yeptris/api.h> /* YEPTRIS_CT_ASSERT (the layout gates) */
21
+
22
+ #include "../common/simd_text.h"
23
+
24
+ #include "common/nametab.h"
25
+ #include "dom/mapindex.h"
26
+ #include "memory/allocator.h"
27
+ #include "memory/pool.h"
28
+ #include "parse/events.h"
29
+
30
+ #ifdef __cplusplus
31
+ extern "C" {
32
+ #endif
33
+
34
+ typedef enum {
35
+ YEP_DOM_SCALAR = 0,
36
+ YEP_DOM_SEQUENCE,
37
+ YEP_DOM_MAPPING,
38
+ YEP_DOM_ALIAS,
39
+ } yep_dom_kind;
40
+
41
+ #define YEP_DOM_MAX_DEPTH 1000
42
+
43
+ /* Compact node strings: (region-tagged offset, length) instead of
44
+ * pointers — the node drops to <= 64 B (TODO.impl/11's gate). Two
45
+ * regions: the borrowed parse input (offset from its base) and the
46
+ * DOM's own contiguous string arena (offset from its start; the
47
+ * arena grows by realloc, which MOVES bytes but never invalidates
48
+ * OFFSETS — the leptris arena discipline). Absence = len 0. */
49
+ #define YEP_SV_INPUT 0x80000000u /* region bit: 1 = arena, 0 = input */
50
+ #define YEP_SV_OFF 0x7FFFFFFFu /* 31-bit offsets (2 GiB ceiling) */
51
+
52
+ typedef struct yep_sview {
53
+ uint32_t off; /* YEP_SV_INPUT | byte offset into the region */
54
+ uint32_t len;
55
+ } yep_sview;
56
+
57
+ /* Compact header (TODO.restructure/64-2a): kind/style/flow/implicit
58
+ * pack into one bitfield byte. The mutation-only attached/depth
59
+ * fields left the record — they live in the DOM's lazily-built side
60
+ * tables (parse pays nothing; dom.c owns them). */
61
+ typedef struct yep_dnode {
62
+ uint8_t kind : 2; /* yep_dom_kind (0-3) */
63
+ uint8_t style : 3; /* yep_scalar_style (0-5) */
64
+ uint8_t flow : 1; /* collection opened in flow style */
65
+ uint8_t implicit : 1; /* scalar written without quotes/tag */
66
+ uint8_t tag_id; /* resolved tag (resolve/resolver.h) */
67
+ uint32_t first_child; /* child link (mappings: key,value,key,value…) */
68
+ uint32_t last_child;
69
+ uint32_t next_sibling;
70
+ uint32_t count; /* children (mappings: 2 × pairs) */
71
+ uint32_t target; /* alias: target node id */
72
+ yep_sview value; /* scalar content / alias name */
73
+ yep_sview tag;
74
+ yep_sview anchor;
75
+ } yep_dnode; /* 48 B: line/col never left the event stream (64-2c) —
76
+ the pull/push/recorder APIs remain the source */
77
+
78
+ /* 11's node-size gate, tightened by 64-2c: <= 48 B. */
79
+ YEPTRIS_CT_ASSERT(sizeof(yep_dnode) <= 48);
80
+
81
+ typedef struct yep_dom {
82
+ const yep_allocator* sys;
83
+ /* Memory guard (the bounded-parse law): when input_len > 0 (set by
84
+ * the parse seams), every growth path is capped by the input size —
85
+ * a parse over N bytes allocates O(N), so a grammar/loop bug fails
86
+ * YEP_ERR_MEMORY instead of ballooning. The mutation API (no input)
87
+ * leaves it 0 and is uncapped. */
88
+ size_t input_len;
89
+ /* mutation side tables (64-2a): attached bitmap + depths, grown
90
+ * lazily on first mutation — parse-built docs never pay */
91
+ uint8_t* mut_att;
92
+ uint16_t* mut_depth;
93
+ uint32_t mut_tbl_cap;
94
+ /* the strict-JSON route's fused walk (TODO.restructure/81): when
95
+ * set, dom_on_flow_build's walker enforces RFC 8259 keys — the
96
+ * engine's flow path leaves it 0 (the lenient YAML flow class) */
97
+ int flow_strict;
98
+ /* fused-flow staging (TODO.restructure/53): scratch nodes live at
99
+ * [stage_base, ncount) until commit; rollback restores the counts */
100
+ int flow_staged;
101
+ uint32_t flow_stage_base, flow_stage_str;
102
+ uint32_t flow_stage_root, flow_stage_anchor;
103
+ const struct yep_resolver* resolver; /* implicit typing for direct
104
+ builders (NULL = core12); parse_impl sets it beside the engine's
105
+ so the two paths resolve identically (the typing SSOT) */
106
+ yep_pool* pool; /* node/docs arrays (strings live in str) */
107
+ /* string arena: contiguous, realloc-grown; node strings are
108
+ * OFFSETS into it, so growth never dangles (dom_str_put) */
109
+ char* str;
110
+ uint32_t str_len, str_cap;
111
+ const char* input_base; /* borrowed parse input (offset base) */
112
+ /* handle arena: thread-safe (atomic bump) — query APIs allocate
113
+ * YeptrisNode wrappers here, so read-only document sharing across
114
+ * threads is safe; parse-path pools stay single-threaded */
115
+ struct yep_hpool* handles;
116
+ yep_dnode* nodes;
117
+ uint32_t ncount, ncap;
118
+ uint32_t* docs; /* document root node ids */
119
+ uint32_t dcount, dcap;
120
+ /* anchor ordinal -> binding node id, indexed directly (the engine
121
+ * stamps 1-based ordinals into the events; no name hashing here) */
122
+ uint32_t* anchor_nodes;
123
+ uint32_t anchor_nodes_cap; /* slots allocated */
124
+ uint32_t anchor_max; /* highest ordinal seen (clear prefix) */
125
+ struct yep_midx_state midx; /* lazy per-map lookup index (mapindex.c) */
126
+ /* builder state */
127
+ uint32_t stack[YEP_DOM_MAX_DEPTH];
128
+ int depth;
129
+ int doc_open;
130
+ int map_pending_key[YEP_DOM_MAX_DEPTH]; /* per-frame: key seen, value next */
131
+ uint32_t pending_key_id[YEP_DOM_MAX_DEPTH];
132
+ uint32_t pending_key;
133
+ } yep_dom;
134
+
135
+ /* Decodes to the pointer view callers use (defined after yep_dom).
136
+ * Absent views (len 0) decode to a valid base pointer with length
137
+ * 0 — callers test len. */
138
+ static inline yep_view yep_dom_view(const yep_dom* d, yep_sview sv) {
139
+ yep_view v = {NULL, 0};
140
+ if (sv.len == 0) {
141
+ return v; /* NULL+0 would be UB on a regionless document */
142
+ }
143
+ v.len = sv.len;
144
+ v.p = (sv.off & YEP_SV_INPUT ? d->str : d->input_base) + (sv.off & YEP_SV_OFF);
145
+ return v;
146
+ }
147
+
148
+ /* Input-region encoding; arena copies go through dom_str_put. */
149
+ static inline yep_sview yep_sv_input(const yep_dom* d, yep_view v) {
150
+ yep_sview sv = {(uint32_t)((const char*)v.p - d->input_base), v.len};
151
+ return sv;
152
+ }
153
+
154
+ yep_dom* yep_dom_create(const yep_allocator* sys);
155
+
156
+ /* Pre-sizes the node array and string arena from content-derived
157
+ * hints (TODO.impl/06: one SIMD count pass -> reserves -> at most
158
+ * logarithmic growth remains instead of doubling from empty).
159
+ * Hints are advisory: overshoot wastes memory, undershoot falls
160
+ * back to normal growth. 0 hint skips that reserve. */
161
+ void yep_dom_reserve(yep_dom* d, uint32_t node_hint, uint32_t str_hint);
162
+
163
+ /* One-shot sizing from the input (count passes + reserve above) —
164
+ * the single home of the heuristic; parse_impl and the memory bench
165
+ * both call it so the measure and the product can't drift. */
166
+ void yep_dom_prepare(yep_dom* d, const yep_text_stats* st);
167
+
168
+ /* Length-heuristic pre-sizing (TODO.restructure/66): real corpora
169
+ * run ~0.2-0.35 nodes/byte (the legal worst, deep bracket chains,
170
+ * reaches ~1/byte and regrows once). No input pre-pass needed. */
171
+ void yep_dom_prepare_len(yep_dom* d, size_t len);
172
+
173
+ /* builder helpers shared with mutate.c (dom-internal) */
174
+ int dom_grow_nodes(yep_dom* d, uint32_t need);
175
+ int dom_grow_docs(yep_dom* d, uint32_t need);
176
+ uint32_t dom_new_node(yep_dom* d, const yep_event* ev, uint8_t kind);
177
+ /* Node-init law shared by the event sink, the mutation builder and the
178
+ * direct builders (no yep_event plumbing): creates and initializes a
179
+ * node; UINT32_MAX = OOM. */
180
+ uint32_t dom_open_node(yep_dom* d, uint8_t kind, const yep_view* tag, const yep_view* anchor,
181
+ int anchor_borrowed, uint8_t style, uint8_t implicit, uint8_t flow);
182
+ void dom_link(yep_dom* d, uint32_t parent, uint32_t child);
183
+
184
+ /* Places a built node: at depth 0 it becomes a document root, inside a
185
+ * sequence it links as a child, inside a map the pairing law applies
186
+ * (first placement = key, second = value). Shared by the event sink,
187
+ * the direct builders, and the CBOR decoder. 0 ok, -1 OOM. */
188
+ int dom_place(yep_dom* d, uint32_t id);
189
+
190
+ /* Mutation-only facts (64-2a): the attached flag and node depth read
191
+ * through lazily-grown side tables; parse-built nodes are unattached
192
+ * with depth 0 until a mutation touches them. */
193
+ int dom_mut_att(const yep_dom* d, uint32_t id);
194
+ void dom_mut_set_att(yep_dom* d, uint32_t id, int v);
195
+ uint16_t dom_mut_depth(const yep_dom* d, uint32_t id);
196
+ void dom_mut_set_depth(yep_dom* d, uint32_t id, uint16_t depth);
197
+
198
+ /* thread-safe handle arena (see hpool.c) */
199
+ struct yep_hpool* yep_hpool_create(const yep_allocator* sys);
200
+ void yep_hpool_destroy(struct yep_hpool* p);
201
+ void* yep_hpool_alloc(struct yep_hpool* p, size_t size, size_t align);
202
+
203
+ /* mutate.c — the from-scratch builder (TODO.impl/11 phase 3).
204
+ *
205
+ * Values passed at runtime have no input buffer to borrow from, so
206
+ * they are copied into the DOM pool. Plain scalars are typed by the
207
+ * core12 resolver (the typing SSOT — mutation never invents types);
208
+ * quoted/block styles are strings. Synthesized documents resolve with
209
+ * the default schema; a compat-mode constructor arrives with 15.
210
+ *
211
+ * Returns: node ids (UINT32_MAX = OOM); statuses 0 ok, -1 invalid
212
+ * argument / OOM, -2 duplicate key (add), -3 would exceed
213
+ * YEP_DOM_MAX_DEPTH, -4 node already attached (would alias a parent).
214
+ */
215
+ uint32_t yep_mut_scalar(yep_dom* d, const char* value, size_t len, uint8_t style);
216
+ uint32_t yep_mut_seq(yep_dom* d, uint8_t flow);
217
+ uint32_t yep_mut_map(yep_dom* d, uint8_t flow);
218
+ int yep_mut_seq_add(yep_dom* d, uint32_t seq, uint32_t child);
219
+ int yep_mut_map_add(yep_dom* d, uint32_t map, const char* key, size_t klen, uint32_t value);
220
+ /* Replace-in-place (json-c semantics: position kept); 1 = replaced. */
221
+ int yep_mut_map_set(yep_dom* d, uint32_t map, const char* key, size_t klen, uint32_t value);
222
+ int yep_mut_seq_del(yep_dom* d, uint32_t seq, uint32_t index);
223
+
224
+ /* Node props on synthesized trees (15's YAMLTree): values are copied
225
+ * into the arena. set_alias_target links an alias node at the target
226
+ * (the emitter resolves and re-emits the name). */
227
+ int yep_mut_set_anchor(yep_dom* d, uint32_t node, const char* name, size_t len);
228
+ int yep_mut_set_tag(yep_dom* d, uint32_t node, const char* tag, size_t len);
229
+ uint32_t yep_mut_new_alias(yep_dom* d, uint32_t target, const char* name, size_t len);
230
+ /* Replace the entry at index (json-c array_put_idx): unlinks the old
231
+ * subtree and splices the new node in at the SAME position. */
232
+ int yep_mut_seq_set(yep_dom* d, uint32_t seq, uint32_t index, uint32_t value);
233
+ int yep_mut_map_del(yep_dom* d, uint32_t map, const char* key, size_t klen);
234
+
235
+ /* Appends a pre-built (key,value) pair (the generator path: keys are
236
+ * constructed nodes, not caller strings). Duplicate keys are
237
+ * REJECTED like map_add. */
238
+ int yep_mut_map_add_node(yep_dom* d, uint32_t map, uint32_t key, uint32_t value);
239
+ int yep_mut_map_append(yep_dom* d, uint32_t map, uint32_t key, uint32_t value);
240
+ int yep_mut_add_root(yep_dom* d, uint32_t node);
241
+ void yep_mut_set_depths(yep_dom* d, uint32_t id, uint16_t depth);
242
+
243
+ /* The sink's flow fast path (TODO.restructure/50): builds the
244
+ * strictly-validated span [open, close] directly through the DOM's own
245
+ * placement/link/anchor laws — node-for-node identical to the event
246
+ * path (the flow-direct-diff ctest pins it). 1 = built, <0 = abort. */
247
+ int dom_on_flow_build(void* ctx, const char* p, size_t open, size_t len, uint32_t line,
248
+ size_t line_start, yep_view anchor, yep_view tag, uint32_t anchor_id,
249
+ int max_depth, size_t* close);
250
+ int dom_on_flow_commit(void* ctx);
251
+ void dom_on_flow_rollback(void* ctx);
252
+ struct yep_block_value;
253
+
254
+ /* The direct scalar sink path (TODO.restructure/79). */
255
+ int dom_on_scalar(void* ctx, const yep_view* value, const yep_view* tag, const yep_view* anchor,
256
+ uint32_t anchor_id, uint8_t tag_id, uint8_t style, uint8_t implicit, uint8_t flow,
257
+ int borrowed);
258
+
259
+ int dom_on_block_pair(void* ctx, const yep_view* key, const struct yep_block_value* v,
260
+ uint32_t line, uint16_t key_col, uint16_t val_col);
261
+ int dom_on_block_open(void* ctx, const yep_view* key, uint32_t line, uint16_t key_col);
262
+ int dom_on_block_item(void* ctx, const yep_block_value* v);
263
+
264
+ /* Direct DOM construction from a strict-validated JSON buffer
265
+ * (TODO.impl/27): no engine, no event pipeline. The caller validated
266
+ * with yep_json_document; 0 on success, -1 OOM, -2 grammar surprise
267
+ * (defensive). */
268
+ int yep_dom_build_json(yep_dom* d, const char* buf, size_t len);
269
+
270
+ /* Appends len bytes to the string arena; returns the ARENA-offset
271
+ * encoding (input_base-relative encodings use yep_sv_input). */
272
+ yep_sview yep_dom_str_put(yep_dom* d, const char* p, uint32_t len);
273
+
274
+ /* Reserve/commit for in-place decoding (the JSON builder's escape
275
+ * path): tail ensures capacity and returns the write position at
276
+ * str_len; commit advances by the written length and returns the
277
+ * arena-encoded view. */
278
+ char* yep_dom_str_tail(yep_dom* d, uint32_t cap);
279
+ yep_sview yep_dom_str_commit(yep_dom* d, uint32_t written);
280
+ void yep_dom_destroy(yep_dom* d);
281
+ int yep_dom_on_event(void* ctx, const yep_event* ev);
282
+
283
+ /* Node id accessor for the public API layer. */
284
+ const yep_dnode* yep_dom_node(const yep_dom* d, uint32_t id);
285
+
286
+ #ifdef __cplusplus
287
+ }
288
+ #endif
289
+
290
+ #endif /* YEP_DOM_H */
@@ -0,0 +1,107 @@
1
+ /* hpool.c — the thread-safe handle arena (TODO.impl/19).
2
+ *
3
+ * Query APIs allocate one YeptrisNode wrapper per call with document
4
+ * lifetime; read-only document sharing across threads makes those
5
+ * allocations concurrent. A mutex-guarded bump arena (uncontended lock
6
+ * per small allocation; blocks freed at document destruction) keeps
7
+ * the parse-path pools entirely lock-free.
8
+ */
9
+
10
+ #include <stdint.h>
11
+ #include <stdlib.h>
12
+
13
+ #include "dom/dom.h"
14
+ #include "memory/allocator.h"
15
+
16
+ #include "common/mutex.h"
17
+
18
+ #define HPOOL_BLOCK (16u * 1024u)
19
+
20
+ typedef struct hblock {
21
+ struct hblock* next;
22
+ size_t size;
23
+ size_t used;
24
+ } hblock;
25
+
26
+ struct yep_hpool {
27
+ const yep_allocator* sys;
28
+ hblock* head;
29
+ yep_mutex_raw mu;
30
+ };
31
+
32
+ static hblock* hb_new(const yep_allocator* sys, size_t payload) {
33
+ hblock* b = yep_alloc(sys, sizeof(hblock) + payload);
34
+ if (b == NULL) {
35
+ return NULL;
36
+ }
37
+ b->next = NULL;
38
+ b->size = payload;
39
+ b->used = 0;
40
+ return b;
41
+ }
42
+
43
+ struct yep_hpool* yep_hpool_create(const yep_allocator* sys) {
44
+ if (sys == NULL) {
45
+ return NULL;
46
+ }
47
+ struct yep_hpool* p = yep_alloc(sys, sizeof(*p));
48
+ if (p == NULL) {
49
+ return NULL;
50
+ }
51
+ p->sys = sys;
52
+ p->head = NULL;
53
+ if (yep_mutex_init(&p->mu) != 0) {
54
+ yep_free(sys, p);
55
+ return NULL;
56
+ }
57
+ p->head = hb_new(sys, HPOOL_BLOCK);
58
+ if (p->head == NULL) {
59
+ yep_mutex_destroy(&p->mu);
60
+ yep_free(sys, p);
61
+ return NULL;
62
+ }
63
+ return p;
64
+ }
65
+
66
+ void yep_hpool_destroy(struct yep_hpool* p) {
67
+ if (p == NULL) {
68
+ return;
69
+ }
70
+ yep_mutex_destroy(&p->mu);
71
+ hblock* b = p->head;
72
+ while (b != NULL) {
73
+ hblock* next = b->next;
74
+ yep_free(p->sys, b);
75
+ b = next;
76
+ }
77
+ yep_free(p->sys, p);
78
+ }
79
+
80
+ void* yep_hpool_alloc(struct yep_hpool* p, size_t size, size_t align) {
81
+ if (p == NULL || size == 0 || align == 0 || (align & (align - 1)) != 0) {
82
+ return NULL;
83
+ }
84
+ yep_mutex_lock(&p->mu);
85
+ hblock* b = p->head;
86
+ uintptr_t base = (uintptr_t)b + sizeof(hblock);
87
+ uintptr_t start = (base + b->used + align - 1) & ~(uintptr_t)(align - 1);
88
+ if (start + size > base + b->size) {
89
+ size_t payload = HPOOL_BLOCK;
90
+ if (payload < size + align + sizeof(hblock)) {
91
+ payload = size + align + sizeof(hblock);
92
+ }
93
+ hblock* nb = hb_new(p->sys, payload);
94
+ if (nb == NULL) {
95
+ yep_mutex_unlock(&p->mu);
96
+ return NULL;
97
+ }
98
+ nb->next = b;
99
+ p->head = nb;
100
+ base = (uintptr_t)nb + sizeof(hblock);
101
+ start = (base + align - 1) & ~(uintptr_t)(align - 1);
102
+ b = nb;
103
+ }
104
+ b->used = start + size - base;
105
+ yep_mutex_unlock(&p->mu);
106
+ return (void*)start;
107
+ }
@@ -0,0 +1,166 @@
1
+ /* mapindex.c — lazy per-mapping key index (TODO.impl/11). */
2
+
3
+ #include "dom/mapindex.h"
4
+
5
+ #include <stdlib.h>
6
+ #include <string.h>
7
+
8
+ #include "dom/dom.h"
9
+
10
+ typedef struct yep_midx_slot {
11
+ uint32_t hash; /* yep_view_hash of the key view */
12
+ uint32_t key_child; /* key node id; UINT32_MAX = empty */
13
+ } yep_midx_slot;
14
+
15
+ typedef struct yep_midx_tab {
16
+ uint32_t cap; /* slot count, power of two */
17
+ yep_midx_slot slots[];
18
+ } yep_midx_tab;
19
+
20
+ /* Table capacity: power of two, >= 2x pairs (load factor <= 50%). */
21
+ static uint32_t tab_cap_for(uint32_t pairs) {
22
+ uint32_t cap = 8;
23
+ while (cap < pairs * 2) {
24
+ cap *= 2;
25
+ }
26
+ return cap;
27
+ }
28
+
29
+ static yep_midx_tab* tab_build(const struct yep_dom* d, uint32_t map) {
30
+ const yep_dnode* m = yep_dom_node(d, map);
31
+ if (m == NULL || m->kind != YEP_DOM_MAPPING) {
32
+ return NULL;
33
+ }
34
+ uint32_t pairs = m->count / 2;
35
+ uint32_t cap = tab_cap_for(pairs);
36
+ yep_midx_tab* t = yep_alloc(d->sys, sizeof(*t) + cap * sizeof(*t->slots));
37
+ if (t == NULL) {
38
+ return NULL;
39
+ }
40
+ t->cap = cap;
41
+ for (uint32_t i = 0; i < cap; i++) {
42
+ t->slots[i].key_child = UINT32_MAX;
43
+ }
44
+ uint32_t mask = cap - 1;
45
+ uint32_t id = m->first_child;
46
+ int want_key = 1;
47
+ while (id != UINT32_MAX) {
48
+ const yep_dnode* cur = yep_dom_node(d, id);
49
+ if (cur == NULL) {
50
+ break;
51
+ }
52
+ if (want_key && cur->kind == YEP_DOM_SCALAR) {
53
+ /* |1: the empty marker is key_child, not hash — this
54
+ * just avoids the all-zero-hash clustering of 1-char keys */
55
+ uint32_t h = yep_view_hash(yep_dom_view(d, cur->value)) | 1u;
56
+ uint32_t i = h & mask;
57
+ while (t->slots[i].key_child != UINT32_MAX) {
58
+ i = (i + 1) & mask; /* first key wins: occupied slots keep their entry */
59
+ }
60
+ t->slots[i].hash = h;
61
+ t->slots[i].key_child = id;
62
+ }
63
+ want_key = !want_key;
64
+ id = cur->next_sibling;
65
+ }
66
+ return t;
67
+ }
68
+
69
+ static int tabs_grow(struct yep_dom* d, uint32_t need) {
70
+ struct yep_midx_state* x = &d->midx;
71
+ if (need <= x->tabs_cap) {
72
+ return 0;
73
+ }
74
+ uint32_t cap = x->tabs_cap ? x->tabs_cap : 64;
75
+ while (cap < need) {
76
+ cap *= 2;
77
+ }
78
+ yep_midx_tab** grown = yep_alloc(d->sys, cap * sizeof(*grown));
79
+ if (grown == NULL) {
80
+ return -1;
81
+ }
82
+ if (x->tabs_cap > 0) {
83
+ memcpy(grown, x->tabs, x->tabs_cap * sizeof(*grown));
84
+ memset(grown + x->tabs_cap, 0, (cap - x->tabs_cap) * sizeof(*grown));
85
+ yep_free(d->sys, x->tabs);
86
+ } else {
87
+ memset(grown, 0, cap * sizeof(*grown));
88
+ }
89
+ x->tabs = grown;
90
+ x->tabs_cap = cap;
91
+ return 0;
92
+ }
93
+
94
+ uint32_t yep_midx_lookup(struct yep_dom* d, uint32_t map, yep_view key) {
95
+ if (d == NULL || map >= d->ncount) {
96
+ return UINT32_MAX;
97
+ }
98
+ struct yep_midx_state* x = &d->midx;
99
+ if (x->mu_ready == 0) {
100
+ return UINT32_MAX; /* document without a live index (paranoia) */
101
+ }
102
+ yep_mutex_lock(&x->mu);
103
+ if (tabs_grow(d, d->ncount) != 0) {
104
+ yep_mutex_unlock(&x->mu);
105
+ return UINT32_MAX;
106
+ }
107
+ if (x->tabs[map] == NULL) {
108
+ x->tabs[map] = tab_build(d, map);
109
+ if (x->tabs[map] == NULL) {
110
+ yep_mutex_unlock(&x->mu);
111
+ return UINT32_MAX;
112
+ }
113
+ }
114
+ yep_midx_tab* t = x->tabs[map];
115
+ uint32_t mask = t->cap - 1;
116
+ uint32_t h = yep_view_hash(key) | 1u;
117
+ uint32_t i = h & mask;
118
+ uint32_t found = UINT32_MAX;
119
+ for (;;) {
120
+ uint32_t child = t->slots[i].key_child;
121
+ if (child == UINT32_MAX) {
122
+ break; /* empty slot: absent */
123
+ }
124
+ if (t->slots[i].hash == h) {
125
+ const yep_dnode* kn = yep_dom_node(d, child);
126
+ if (kn != NULL && yep_view_eq(yep_dom_view(d, kn->value), key)) {
127
+ found = child;
128
+ break;
129
+ }
130
+ }
131
+ i = (i + 1) & mask;
132
+ }
133
+ yep_mutex_unlock(&x->mu);
134
+ return found;
135
+ }
136
+
137
+ void yep_midx_invalidate(struct yep_dom* d, uint32_t map) {
138
+ if (d == NULL || !d->midx.mu_ready || d->midx.tabs == NULL || map >= d->midx.tabs_cap) {
139
+ return;
140
+ }
141
+ yep_mutex_lock(&d->midx.mu);
142
+ yep_midx_tab* t = d->midx.tabs[map];
143
+ if (t != NULL) {
144
+ d->midx.tabs[map] = NULL;
145
+ yep_free(d->sys, t);
146
+ }
147
+ yep_mutex_unlock(&d->midx.mu);
148
+ }
149
+
150
+ void yep_midx_destroy(struct yep_dom* d) {
151
+ if (d == NULL) {
152
+ return;
153
+ }
154
+ if (d->midx.tabs != NULL) {
155
+ for (uint32_t i = 0; i < d->midx.tabs_cap; i++) {
156
+ yep_free(d->sys, d->midx.tabs[i]);
157
+ }
158
+ yep_free(d->sys, d->midx.tabs);
159
+ d->midx.tabs = NULL;
160
+ d->midx.tabs_cap = 0;
161
+ }
162
+ if (d->midx.mu_ready) {
163
+ yep_mutex_destroy(&d->midx.mu);
164
+ d->midx.mu_ready = 0;
165
+ }
166
+ }
@@ -0,0 +1,61 @@
1
+ /* mapindex.h — lazy per-mapping key index (TODO.impl/11).
2
+ *
3
+ * O(1) map lookup over the sibling-linked pair list: on a mapping's
4
+ * first lookup an open-addressing table (view hash -> key child id)
5
+ * is built from its pairs; probes compare the full view bytes on
6
+ * hash matches. First key wins on duplicates (the linear scan's
7
+ * contract). Only SCALAR keys are indexed — collection keys never
8
+ * match a string lookup, exactly like the scan.
9
+ *
10
+ * Tables and the per-node slot array live on the system allocator
11
+ * (NOT the DOM pool): mutation invalidates a table by freeing it,
12
+ * and pool memory cannot be individually released. Everything is
13
+ * freed at document destruction.
14
+ *
15
+ * Threads: table builds and mutations serialize on the document's
16
+ * index mutex; built tables are immutable, so concurrent probes are
17
+ * safe — the read-only sharing contract holds.
18
+ */
19
+ #ifndef YEP_MAPINDEX_H
20
+ #define YEP_MAPINDEX_H
21
+
22
+ #include <stdint.h>
23
+
24
+ #include "common/mutex.h"
25
+
26
+ #include "common/nametab.h"
27
+ #include "memory/allocator.h"
28
+
29
+ #ifdef __cplusplus
30
+ extern "C" {
31
+ #endif
32
+
33
+ /* Per-mapping table: hash -> key node id (opaque here; mapindex.c). */
34
+ typedef struct yep_midx_tab yep_midx_tab;
35
+
36
+ struct yep_midx_state {
37
+ yep_midx_tab** tabs; /* per node id: table or NULL (lazy) */
38
+ uint32_t tabs_cap; /* slots allocated (grown with the node set) */
39
+ yep_mutex_raw mu;
40
+ int mu_ready;
41
+ };
42
+
43
+ /* The key node id for `key` in `map`, or UINT32_MAX when absent.
44
+ * Builds the mapping's table on first use. UINT32_MAX also on
45
+ * allocation failure (the caller falls back to a linear scan if it
46
+ * needs to distinguish — callers treat both as "not found"). */
47
+ struct yep_dom;
48
+ uint32_t yep_midx_lookup(struct yep_dom* d, uint32_t map, yep_view key);
49
+
50
+ /* Drops `map`'s table (mutation changed the pairs). Cheap no-op when
51
+ * no table was built. */
52
+ void yep_midx_invalidate(struct yep_dom* d, uint32_t map);
53
+
54
+ /* Frees every table and the slot array (document destruction). */
55
+ void yep_midx_destroy(struct yep_dom* d);
56
+
57
+ #ifdef __cplusplus
58
+ }
59
+ #endif
60
+
61
+ #endif /* YEP_MAPINDEX_H */