yeptris 0.6.19.1-arm-linux-eabihf → 0.6.20.2-arm-linux-eabihf

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.
@@ -0,0 +1,640 @@
1
+ /* ytape.c — the packed YAML record tape (#378, TODO.max-perf/12).
2
+ *
3
+ * Recorder: a yep_sink over the SEVEN committed-op callbacks plus the
4
+ * general event path. The engine stays in its fused arms (no event
5
+ * construction on classified shapes — the event-recorder prototype's
6
+ * measured floor); the recorder's writes are 8-byte words instead of
7
+ * the eager builders' 48-byte node inits, arena copies, resolver calls
8
+ * and placement.
9
+ *
10
+ * Replay: decodes words into the SAME builder functions
11
+ * (dom_on_block_pair/open/item, dom_on_scalar, dom_on_flow_build,
12
+ * yep_dom_on_event), so typing, anchoring and placement semantics are
13
+ * the eager path's by construction. The differential gate
14
+ * (test/unit/test_ytape.cpp) pins tree identity across the corpora.
15
+ */
16
+
17
+ #include <string.h>
18
+
19
+ #include "dom/dom.h"
20
+ #include "memory/allocator.h"
21
+ #include "scan/json.h"
22
+ #include "scan/scan.h"
23
+ #include "ytape.h"
24
+
25
+ /* ---- word packing ---- */
26
+
27
+ #define YTP_KIND_OF(w) ((uint8_t)((w) >> 56))
28
+
29
+ static int yt_put(yep_ytape* t, uint64_t w);
30
+
31
+ static uint64_t yt_span_in(uint32_t off, uint32_t len, uint8_t kind) {
32
+ return ((uint64_t)kind << 56) | ((uint64_t)(len & 0xFFFFFFu) << 32) | (uint64_t)off;
33
+ }
34
+
35
+ static uint64_t yt_props(uint8_t kind, uint32_t anchor_id, uint32_t flags) {
36
+ return ((uint64_t)kind << 56) | ((uint64_t)(anchor_id & 0xFFFFFFu) << 32) |
37
+ (uint64_t)(flags & 0xFFFFFFFFu);
38
+ }
39
+
40
+ /* ---- the recorder ---- */
41
+
42
+ int ytap_init(yep_ytape* t, const char* input, size_t len, int max_depth) {
43
+ memset(t, 0, sizeof(*t));
44
+ t->input = input;
45
+ t->input_len = len;
46
+ t->max_depth = max_depth;
47
+ size_t cap = len / 2 + 64;
48
+ if (cap > 0xFFFFFFFFu) {
49
+ cap = 0xFFFFFFFFu;
50
+ }
51
+ t->w = (uint64_t*)yep_alloc(yep_system_allocator(), cap * sizeof(uint64_t));
52
+ if (t->w == NULL) {
53
+ return -1;
54
+ }
55
+ t->cap = (uint32_t)cap;
56
+ return 0;
57
+ }
58
+
59
+ void ytap_free(yep_ytape* t) {
60
+ if (t->w != NULL) {
61
+ yep_free(yep_system_allocator(), t->w);
62
+ t->w = NULL;
63
+ }
64
+ }
65
+
66
+ /* Growth bounded by the input (the bounded-parse law): a 4N-word
67
+ * ceiling, never a runaway realloc chain. The allocator has no
68
+ * realloc — one copy per growth, at most a few per document. */
69
+ static int yt_put(yep_ytape* t, uint64_t w) {
70
+ if (t->count >= t->cap) {
71
+ if (t->oom) {
72
+ return -1;
73
+ }
74
+ size_t ncap = (size_t)t->cap * 2;
75
+ size_t ceiling = t->input_len * 4 + 256;
76
+ if (ncap > ceiling) {
77
+ ncap = ceiling;
78
+ }
79
+ if (ncap <= (size_t)t->cap) {
80
+ t->oom = 1;
81
+ return -1;
82
+ }
83
+ uint64_t* nw = (uint64_t*)yep_alloc(yep_system_allocator(), ncap * sizeof(uint64_t));
84
+ if (nw == NULL) {
85
+ t->oom = 1;
86
+ return -1;
87
+ }
88
+ memcpy(nw, t->w, (size_t)t->count * sizeof(uint64_t));
89
+ yep_free(yep_system_allocator(), t->w);
90
+ t->w = nw;
91
+ t->cap = (uint32_t)ncap;
92
+ }
93
+ t->w[t->count++] = w;
94
+ return 0;
95
+ }
96
+
97
+ /* The pool-form span: two words, 32-bit length, raw pointer (stable:
98
+ * pool blocks never move until the document frees them). */
99
+ static int yt_span_pool(yep_ytape* t, const void* p, size_t len) {
100
+ if (yt_put(t, ((uint64_t)YTP_SPAN_POOL << 56) | (uint64_t)(uint32_t)len) != 0) {
101
+ return -1;
102
+ }
103
+ return yt_put(t, (uint64_t)(uintptr_t)p);
104
+ }
105
+
106
+ /* One span word when the view is input-relative and fits 24 bits; the
107
+ * generic pair otherwise. */
108
+ static int yt_span(yep_ytape* t, const yep_view* v) {
109
+ if (v->p >= t->input && v->p <= t->input + t->input_len && v->len < 0x1000000u) {
110
+ return yt_put(t, yt_span_in((uint32_t)(v->p - t->input), (uint32_t)v->len, YTP_SPAN_IN));
111
+ }
112
+ return yt_span_pool(t, v->p, v->len);
113
+ }
114
+
115
+ /* Span-mode bits shared by the props words: 0 absent, 1 input, 2 pool
116
+ * (mode is re-derived by pointer range — the recorder never trusts
117
+ * borrowedness for tag/anchor views). */
118
+ #define YTM_ABSENT 0
119
+ #define YTM_IN 1
120
+ #define YTM_POOL 2
121
+
122
+ static int yt_mode(const yep_ytape* t, const yep_view* v) {
123
+ if (v->p == NULL || v->len == 0) {
124
+ return YTM_ABSENT;
125
+ }
126
+ if (v->p >= t->input && v->p <= t->input + t->input_len) {
127
+ return YTM_IN;
128
+ }
129
+ return YTM_POOL;
130
+ }
131
+
132
+ static int yt_span_by_mode(yep_ytape* t, const yep_view* v) {
133
+ if (v->p == NULL || v->len == 0) {
134
+ return 0;
135
+ }
136
+ return yt_span(t, v);
137
+ }
138
+
139
+ /* The general event path. STREAM/DOCUMENT frames compact to one word
140
+ * (the DOM reads nothing else off them); SEQ/MAP/SCALAR/ALIAS pack
141
+ * props + value + optional tag/anchor spans. */
142
+ static int yt_on_event(void* ctx, const yep_event* ev) {
143
+ yep_ytape* t = (yep_ytape*)ctx;
144
+ switch (ev->type) {
145
+ case YEP_EV_STREAM_START:
146
+ case YEP_EV_STREAM_END:
147
+ case YEP_EV_DOCUMENT_START:
148
+ case YEP_EV_DOCUMENT_END:
149
+ if (ev->type == YEP_EV_DOCUMENT_START) {
150
+ t->docs++;
151
+ }
152
+ return yt_put(t, ((uint64_t)YTP_EV_COMPACT << 56) | (uint64_t)ev->type);
153
+ case YEP_EV_SEQ_START:
154
+ case YEP_EV_MAP_START:
155
+ if (t->depth >= YEP_DOM_MAX_DEPTH) {
156
+ return -1; /* the DOM answers -1 here; the engine's error
157
+ * path stays identical */
158
+ }
159
+ t->depth++;
160
+ break;
161
+ case YEP_EV_SEQ_END:
162
+ case YEP_EV_MAP_END:
163
+ t->depth--;
164
+ break;
165
+ default:
166
+ break;
167
+ }
168
+ uint32_t anchor_hi = 0;
169
+ uint32_t aid = ev->anchor_id;
170
+ if (aid > 0xFFFFFFu) {
171
+ anchor_hi = 1;
172
+ aid = 0xFFFFFFu;
173
+ }
174
+ uint32_t tag_mode = (uint32_t)yt_mode(t, &ev->tag);
175
+ uint32_t anchor_mode = (uint32_t)yt_mode(t, &ev->anchor);
176
+ uint32_t flags = (uint32_t)ev->type | ((uint32_t)ev->style << 4) |
177
+ ((uint32_t)ev->implicit << 7) | ((uint32_t)ev->flow << 8) |
178
+ ((uint32_t)ev->multiline << 9) | ((uint32_t)(ev->borrowed != 0) << 10) |
179
+ (tag_mode << 11) | (anchor_mode << 13) | (anchor_hi << 15) |
180
+ ((uint32_t)ev->tag_id << 16);
181
+ if (yt_put(t, yt_props(YTP_EVENT, aid, flags)) != 0) {
182
+ return -1;
183
+ }
184
+ if (yt_span(t, &ev->value) != 0) {
185
+ return -1;
186
+ }
187
+ if (tag_mode != YTM_ABSENT && yt_span_by_mode(t, &ev->tag) != 0) {
188
+ return -1;
189
+ }
190
+ if (anchor_mode != YTM_ABSENT && yt_span_by_mode(t, &ev->anchor) != 0) {
191
+ return -1;
192
+ }
193
+ if (anchor_hi && yt_put(t, (uint64_t)ev->anchor_id) != 0) {
194
+ return -1;
195
+ }
196
+ return 0;
197
+ }
198
+
199
+ static int yt_on_scalar(void* ctx, const yep_view* value, const yep_view* tag,
200
+ const yep_view* anchor, uint32_t anchor_id, uint8_t tag_id, uint8_t style,
201
+ uint8_t implicit, uint8_t flow, int borrowed) {
202
+ yep_ytape* t = (yep_ytape*)ctx;
203
+ uint32_t anchor_hi = 0;
204
+ uint32_t aid = anchor_id;
205
+ if (aid > 0xFFFFFFu) {
206
+ anchor_hi = 1;
207
+ aid = 0xFFFFFFu;
208
+ }
209
+ uint32_t tag_mode = (uint32_t)yt_mode(t, tag);
210
+ uint32_t anchor_mode = (uint32_t)yt_mode(t, anchor);
211
+ uint32_t flags = (uint32_t)tag_id | ((uint32_t)style << 8) | ((uint32_t)implicit << 11) |
212
+ ((uint32_t)flow << 12) | ((uint32_t)(borrowed != 0) << 13) | (tag_mode << 14) |
213
+ (anchor_mode << 16) | (anchor_hi << 18);
214
+ if (yt_put(t, yt_props(YTP_SCALAR, aid, flags)) != 0) {
215
+ return -1;
216
+ }
217
+ if (yt_span(t, value) != 0) {
218
+ return -1;
219
+ }
220
+ if (tag_mode != YTM_ABSENT && yt_span_by_mode(t, tag) != 0) {
221
+ return -1;
222
+ }
223
+ if (anchor_mode != YTM_ABSENT && yt_span_by_mode(t, anchor) != 0) {
224
+ return -1;
225
+ }
226
+ if (anchor_hi && yt_put(t, (uint64_t)anchor_id) != 0) {
227
+ return -1;
228
+ }
229
+ return 0;
230
+ }
231
+
232
+ static int yt_on_block_pair(void* ctx, const yep_view* key, const yep_block_value* v, uint32_t line,
233
+ uint16_t key_col, uint16_t val_col) {
234
+ (void)line;
235
+ (void)key_col;
236
+ (void)val_col; /* yep_dnode carries no positions (64-2c) */
237
+ yep_ytape* t = (yep_ytape*)ctx;
238
+ uint32_t anchor_hi = 0;
239
+ uint32_t aid = v->anchor_id;
240
+ if (aid > 0xFFFFFFu) {
241
+ anchor_hi = 1;
242
+ aid = 0xFFFFFFu;
243
+ }
244
+ uint32_t flags = ((uint32_t)v->cls & 7u) | ((uint32_t)(v->borrowed != 0) << 3) |
245
+ ((uint32_t)yt_mode(t, &v->anchor) << 4) | (anchor_hi << 6);
246
+ if (yt_put(t, yt_props(YTP_PAIR, aid, flags)) != 0) {
247
+ return -1;
248
+ }
249
+ if (yt_span(t, key) != 0) {
250
+ return -1;
251
+ }
252
+ /* ALIAS names record as spans either way (the eager builder
253
+ * stamps borrowed=1 for them); plain values borrow by the flag. */
254
+ if (v->borrowed || v->cls == YEP_LVAL_ALIAS) {
255
+ if (yt_span(t, &v->value) != 0) {
256
+ return -1;
257
+ }
258
+ } else if (yt_span_pool(t, v->value.p, v->value.len) != 0) {
259
+ return -1;
260
+ }
261
+ if (((flags >> 4) & 3u) != YTM_ABSENT && yt_span_by_mode(t, &v->anchor) != 0) {
262
+ return -1;
263
+ }
264
+ if (anchor_hi && yt_put(t, (uint64_t)v->anchor_id) != 0) {
265
+ return -1;
266
+ }
267
+ return 1; /* handled: the engine skips the two events */
268
+ }
269
+
270
+ static int yt_on_block_open(void* ctx, const yep_view* key, uint32_t line, uint16_t key_col) {
271
+ (void)line;
272
+ (void)key_col;
273
+ yep_ytape* t = (yep_ytape*)ctx;
274
+ if (t->depth >= YEP_DOM_MAX_DEPTH) {
275
+ return 0; /* the engine's event path owns the depth error */
276
+ }
277
+ if (key->len < 0x1000000u && key->p >= t->input && key->p <= t->input + t->input_len) {
278
+ if (yt_put(t, yt_span_in((uint32_t)(key->p - t->input), (uint32_t)key->len, YTP_OPEN)) !=
279
+ 0) {
280
+ return -1;
281
+ }
282
+ } else {
283
+ /* a pool or oversized block key: the scalar form's open-key
284
+ * bit carries it (defensive — the engine classifies keys from
285
+ * the line; replay routes back to on_block_open) */
286
+ if (yt_put(t, yt_props(YTP_SCALAR, 0, 1u << 21)) != 0) {
287
+ return -1;
288
+ }
289
+ if (yt_span(t, key) != 0) {
290
+ return -1;
291
+ }
292
+ }
293
+ t->depth++;
294
+ return 1;
295
+ }
296
+
297
+ static int yt_on_block_item(void* ctx, const yep_block_value* v) {
298
+ yep_ytape* t = (yep_ytape*)ctx;
299
+ if (v->borrowed && v->value.len < 0x1000000u && v->value.p >= t->input &&
300
+ v->value.p <= t->input + t->input_len) {
301
+ if (yt_put(t, yt_span_in((uint32_t)(v->value.p - t->input), (uint32_t)v->value.len,
302
+ YTP_ITEM)) != 0) {
303
+ return -1;
304
+ }
305
+ return 1;
306
+ }
307
+ /* pool content or oversized: the scalar form with the item bit */
308
+ if (yt_put(t, yt_props(YTP_SCALAR, 0, 1u << 20)) != 0) {
309
+ return -1;
310
+ }
311
+ if (yt_span_pool(t, v->value.p, v->value.len) != 0) {
312
+ return -1;
313
+ }
314
+ return 1;
315
+ }
316
+
317
+ static int yt_on_flow_build(void* ctx, const char* p, size_t open, size_t len, uint32_t line,
318
+ size_t line_start, yep_view anchor, yep_view tag, uint32_t anchor_id,
319
+ int max_depth, size_t* close) {
320
+ (void)line;
321
+ (void)line_start; /* the flow builder reads neither */
322
+ yep_ytape* t = (yep_ytape*)ctx;
323
+ if (t->depth >= YEP_DOM_MAX_DEPTH) {
324
+ return 0; /* the event path owns the error shape */
325
+ }
326
+ /* classification = the DOM's own walk with the builds stripped:
327
+ * the same reject/long-key verdicts, then ONE record for the
328
+ * whole staged span (replay runs the full build through
329
+ * dom_on_flow_build). */
330
+ yep_json_walk w;
331
+ yep_json_tok tok;
332
+ yep_json_walk_init(&w, p, len, open, max_depth);
333
+ w.strict = t->flow_strict;
334
+ for (;;) {
335
+ yep_jw_status st = yep_json_walk_next(&w, &tok);
336
+ if (st == YEP_JW_REJECT) {
337
+ return 0; /* not JSON-class: the general kernel */
338
+ }
339
+ if (st == YEP_JW_DONE) {
340
+ break;
341
+ }
342
+ }
343
+ if (w.long_key) {
344
+ return 2; /* pass 2 owns the simple-key error, as the DOM's */
345
+ }
346
+ t->flow_mark = t->count;
347
+ uint32_t anchor_hi = 0;
348
+ uint32_t aid = anchor_id;
349
+ if (aid > 0xFFFFFFu) {
350
+ anchor_hi = 1;
351
+ aid = 0xFFFFFFu;
352
+ }
353
+ uint32_t tag_mode = (uint32_t)yt_mode(t, &tag);
354
+ uint32_t anchor_mode = (uint32_t)yt_mode(t, &anchor);
355
+ uint32_t flags = tag_mode | (anchor_mode << 2) | (anchor_hi << 4);
356
+ if (yt_put(t, yt_props(YTP_FLOW, aid, flags)) != 0) {
357
+ return -1;
358
+ }
359
+ if (yt_put(t, (uint64_t)open | ((uint64_t)len << 32)) != 0) {
360
+ return -1;
361
+ }
362
+ if (tag_mode != YTM_ABSENT && yt_span_by_mode(t, &tag) != 0) {
363
+ return -1;
364
+ }
365
+ if (anchor_mode != YTM_ABSENT && yt_span_by_mode(t, &anchor) != 0) {
366
+ return -1;
367
+ }
368
+ if (anchor_hi && yt_put(t, (uint64_t)anchor_id) != 0) {
369
+ return -1;
370
+ }
371
+ *close = w.close;
372
+ return 1;
373
+ }
374
+
375
+ static int yt_on_flow_commit(void* ctx) {
376
+ (void)ctx; /* the records are already written */
377
+ return 1;
378
+ }
379
+
380
+ static void yt_on_flow_rollback(void* ctx) {
381
+ yep_ytape* t = (yep_ytape*)ctx;
382
+ t->count = t->flow_mark; /* the DOM's stage reset, in words */
383
+ }
384
+
385
+ void ytap_sink(yep_ytape* t, yep_sink* sink) {
386
+ memset(sink, 0, sizeof(*sink));
387
+ sink->on_event = yt_on_event;
388
+ sink->ctx = t;
389
+ sink->on_flow_build = yt_on_flow_build;
390
+ sink->on_flow_commit = yt_on_flow_commit;
391
+ sink->on_flow_rollback = yt_on_flow_rollback;
392
+ sink->on_block_pair = yt_on_block_pair;
393
+ sink->on_scalar = yt_on_scalar;
394
+ sink->on_block_open = yt_on_block_open;
395
+ sink->on_block_item = yt_on_block_item;
396
+ }
397
+
398
+ /* ---- replay ---- */
399
+
400
+ static int yt_read_span(const yep_ytape* t, const uint64_t* w, uint32_t* i, uint32_t count,
401
+ yep_view* v) {
402
+ if (*i >= count) {
403
+ return -1;
404
+ }
405
+ uint64_t word = w[(*i)++];
406
+ uint8_t k = YTP_KIND_OF(word);
407
+ if (k == YTP_SPAN_IN) {
408
+ v->p = t->input + (uint32_t)word;
409
+ v->len = (uint32_t)(word >> 32) & 0xFFFFFFu;
410
+ return 0;
411
+ }
412
+ if (k == YTP_SPAN_POOL) {
413
+ if (*i >= count) {
414
+ return -1;
415
+ }
416
+ v->p = (const char*)(uintptr_t)w[(*i)++];
417
+ v->len = (uint32_t)word;
418
+ return 0;
419
+ }
420
+ return -1; /* a props word in a span slot: corruption */
421
+ }
422
+
423
+ int dom_from_ytape(yep_dom* d, const yep_ytape* t) {
424
+ if (d == NULL || t == NULL || t->w == NULL) {
425
+ return -1;
426
+ }
427
+ d->input_base = t->input;
428
+ d->input_len = t->input_len;
429
+ yep_dom_prepare_len(d, t->input_len);
430
+ const uint64_t* w = t->w;
431
+ uint32_t count = t->count;
432
+ uint32_t i = 0;
433
+ while (i < count) {
434
+ uint8_t kind = YTP_KIND_OF(w[i]);
435
+ switch (kind) {
436
+ case YTP_EV_COMPACT: {
437
+ yep_event ev;
438
+ memset(&ev, 0, sizeof(ev));
439
+ ev.type = (yep_event_type)(uint8_t)w[i];
440
+ i++;
441
+ if (yep_dom_on_event(d, &ev) != 0) {
442
+ return -1;
443
+ }
444
+ break;
445
+ }
446
+ case YTP_EVENT: {
447
+ uint32_t flags = (uint32_t)(w[i] & 0xFFFFFFFFu);
448
+ uint32_t aid = (uint32_t)(w[i] >> 32) & 0xFFFFFFu;
449
+ i++;
450
+ yep_event ev;
451
+ memset(&ev, 0, sizeof(ev));
452
+ ev.type = (yep_event_type)(flags & 0xFu);
453
+ ev.style = (uint8_t)((flags >> 4) & 7u);
454
+ ev.implicit = (uint8_t)((flags >> 7) & 1u);
455
+ ev.flow = (uint8_t)((flags >> 8) & 1u);
456
+ ev.multiline = (uint8_t)((flags >> 9) & 1u);
457
+ ev.borrowed = (int)((flags >> 10) & 1u);
458
+ uint32_t tag_mode = (flags >> 11) & 3u;
459
+ uint32_t anchor_mode = (flags >> 13) & 3u;
460
+ uint32_t anchor_hi = (flags >> 15) & 1u;
461
+ ev.tag_id = (uint8_t)((flags >> 16) & 0xFFu);
462
+ if (yt_read_span(t, w, &i, count, &ev.value) != 0) {
463
+ return -1;
464
+ }
465
+ if (tag_mode != YTM_ABSENT) {
466
+ if (yt_read_span(t, w, &i, count, &ev.tag) != 0) {
467
+ return -1;
468
+ }
469
+ }
470
+ if (anchor_mode != YTM_ABSENT) {
471
+ if (yt_read_span(t, w, &i, count, &ev.anchor) != 0) {
472
+ return -1;
473
+ }
474
+ }
475
+ if (anchor_hi) {
476
+ if (i >= count) {
477
+ return -1;
478
+ }
479
+ aid = (uint32_t)w[i++];
480
+ }
481
+ ev.anchor_id = aid;
482
+ if (yep_dom_on_event(d, &ev) != 0) {
483
+ return -1;
484
+ }
485
+ break;
486
+ }
487
+ case YTP_SCALAR: {
488
+ uint32_t flags = (uint32_t)(w[i] & 0xFFFFFFFFu);
489
+ uint32_t aid = (uint32_t)(w[i] >> 32) & 0xFFFFFFu;
490
+ i++;
491
+ int is_item = (int)((flags >> 20) & 1u);
492
+ int is_open_key = (int)((flags >> 21) & 1u);
493
+ if (is_item || is_open_key) {
494
+ yep_view v;
495
+ if (yt_read_span(t, w, &i, count, &v) != 0) {
496
+ return -1;
497
+ }
498
+ yep_block_value bv;
499
+ memset(&bv, 0, sizeof(bv));
500
+ bv.cls = YEP_LVAL_PLAIN;
501
+ bv.borrowed = (v.p >= t->input && v.p <= t->input + t->input_len) ? 1 : 0;
502
+ bv.value = v;
503
+ int rc = is_item ? dom_on_block_item(d, &bv) : dom_on_block_open(d, &v, 0, 0);
504
+ if (rc < 0) {
505
+ return -1;
506
+ }
507
+ break;
508
+ }
509
+ uint8_t tag_id = (uint8_t)(flags & 0xFFu);
510
+ uint8_t style = (uint8_t)((flags >> 8) & 7u);
511
+ uint8_t implicit = (uint8_t)((flags >> 11) & 1u);
512
+ uint8_t flow = (uint8_t)((flags >> 12) & 1u);
513
+ int borrowed = (int)((flags >> 13) & 1u);
514
+ uint32_t tag_mode = (flags >> 14) & 3u;
515
+ uint32_t anchor_mode = (flags >> 16) & 3u;
516
+ uint32_t anchor_hi = (flags >> 18) & 1u;
517
+ yep_view value, tag = {0}, anchor = {0};
518
+ if (yt_read_span(t, w, &i, count, &value) != 0) {
519
+ return -1;
520
+ }
521
+ if (tag_mode != YTM_ABSENT && yt_read_span(t, w, &i, count, &tag) != 0) {
522
+ return -1;
523
+ }
524
+ if (anchor_mode != YTM_ABSENT && yt_read_span(t, w, &i, count, &anchor) != 0) {
525
+ return -1;
526
+ }
527
+ if (anchor_hi) {
528
+ if (i >= count) {
529
+ return -1;
530
+ }
531
+ aid = (uint32_t)w[i++];
532
+ }
533
+ if (dom_on_scalar(d, &value, tag_mode ? &tag : NULL, anchor_mode ? &anchor : NULL, aid,
534
+ tag_id, style, implicit, flow, borrowed) < 0) {
535
+ return -1;
536
+ }
537
+ break;
538
+ }
539
+ case YTP_ITEM: {
540
+ yep_view v;
541
+ v.p = t->input + (uint32_t)w[i];
542
+ v.len = (uint32_t)(w[i] >> 32) & 0xFFFFFFu;
543
+ i++;
544
+ yep_block_value bv;
545
+ memset(&bv, 0, sizeof(bv));
546
+ bv.cls = YEP_LVAL_PLAIN;
547
+ bv.borrowed = 1;
548
+ bv.value = v;
549
+ if (dom_on_block_item(d, &bv) < 0) {
550
+ return -1;
551
+ }
552
+ break;
553
+ }
554
+ case YTP_PAIR: {
555
+ uint32_t flags = (uint32_t)(w[i] & 0xFFFFFFFFu);
556
+ uint32_t aid = (uint32_t)(w[i] >> 32) & 0xFFFFFFu;
557
+ i++;
558
+ yep_block_value bv;
559
+ memset(&bv, 0, sizeof(bv));
560
+ bv.cls = (uint8_t)(flags & 7u);
561
+ bv.borrowed = (int)((flags >> 3) & 1u);
562
+ uint32_t anchor_mode = (flags >> 4) & 3u;
563
+ uint32_t anchor_hi = (flags >> 6) & 1u;
564
+ yep_view key;
565
+ if (yt_read_span(t, w, &i, count, &key) != 0) {
566
+ return -1;
567
+ }
568
+ if (yt_read_span(t, w, &i, count, &bv.value) != 0) {
569
+ return -1;
570
+ }
571
+ if (bv.cls == YEP_LVAL_ALIAS) {
572
+ bv.borrowed = 1; /* the eager builder stamps alias names */
573
+ }
574
+ if (anchor_mode != YTM_ABSENT && yt_read_span(t, w, &i, count, &bv.anchor) != 0) {
575
+ return -1;
576
+ }
577
+ if (anchor_hi) {
578
+ if (i >= count) {
579
+ return -1;
580
+ }
581
+ aid = (uint32_t)w[i++];
582
+ }
583
+ bv.anchor_id = aid;
584
+ if (dom_on_block_pair(d, &key, &bv, 0, 0, 0) < 0) {
585
+ return -1;
586
+ }
587
+ break;
588
+ }
589
+ case YTP_OPEN: {
590
+ yep_view key;
591
+ key.p = t->input + (uint32_t)w[i];
592
+ key.len = (uint32_t)(w[i] >> 32) & 0xFFFFFFu;
593
+ i++;
594
+ if (dom_on_block_open(d, &key, 0, 0) < 0) {
595
+ return -1;
596
+ }
597
+ break;
598
+ }
599
+ case YTP_FLOW: {
600
+ uint32_t flags = (uint32_t)(w[i] & 0xFFFFFFFFu);
601
+ uint32_t aid = (uint32_t)(w[i] >> 32) & 0xFFFFFFu;
602
+ i++;
603
+ uint32_t tag_mode = flags & 3u;
604
+ uint32_t anchor_mode = (flags >> 2) & 3u;
605
+ uint32_t anchor_hi = (flags >> 4) & 1u;
606
+ if (i >= count) {
607
+ return -1;
608
+ }
609
+ size_t open = (size_t)(uint32_t)w[i];
610
+ size_t len = (size_t)(uint32_t)(w[i] >> 32);
611
+ i++;
612
+ yep_view tag = {0}, anchor = {0};
613
+ if (tag_mode != YTM_ABSENT && yt_read_span(t, w, &i, count, &tag) != 0) {
614
+ return -1;
615
+ }
616
+ if (anchor_mode != YTM_ABSENT && yt_read_span(t, w, &i, count, &anchor) != 0) {
617
+ return -1;
618
+ }
619
+ if (anchor_hi) {
620
+ if (i >= count) {
621
+ return -1;
622
+ }
623
+ aid = (uint32_t)w[i++];
624
+ }
625
+ size_t close = 0;
626
+ if (dom_on_flow_build(d, t->input, open, len, 0, 0, anchor, tag, aid, t->max_depth,
627
+ &close) != 1) {
628
+ return -1;
629
+ }
630
+ if (dom_on_flow_commit(d) < 0) {
631
+ return -1;
632
+ }
633
+ break;
634
+ }
635
+ default:
636
+ return -1; /* a span word where an op belongs: corruption */
637
+ }
638
+ }
639
+ return 0;
640
+ }