Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/aienux/crates/aienos-agent-state/agent_state.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / aienux / crates / aienos-agent-state / agent_state.om` 2086 lines ยท 48316 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note aienux/crates/aienos-agent-state/agent_state.om: Pure-Omega AIENOS Agent State ABI and Execution Incarnation Substrate. 3 note Converted from aienux crates/aienos-agent-state/src/ (abi.rs, id.rs, incarnation.rs, history.rs, lineage.rs, manager.rs, lib.rs). 4 note Compose with: si/directives/om2.om om/tls/sha2.om aienux/crates/aienos-agent-state/agent_state.om ... 5 6 const AS_MAX_MGRS ulong 2 7 const AS_MAX_AGENTS ulong 8 8 const AS_MAX_BRANCHES ulong 32 9 const AS_MAX_SLOTS ulong 64 10 const AS_MAX_TOKENS ulong 64 11 const AS_MAX_DEPTH ulong 16 12 const AS_MAX_EPISTEMIC ulong 8 13 const AS_MAX_TH ulong 4 14 const AS_MAX_LIN ulong 4 15 const AS_MAX_EPI ulong 4 16 17 const AS_COMPUTE_IDLE uchar 0 18 const AS_COMPUTE_PREFILLING uchar 1 19 const AS_COMPUTE_DECODING uchar 2 20 const AS_COMPUTE_SUSPENDED uchar 3 21 const AS_COMPUTE_EVICTED uchar 4 22 23 const AS_OK int 0 24 const AS_ERR_AGENT_NOT_FOUND int -1 25 const AS_ERR_BRANCH_NOT_FOUND int -2 26 const AS_ERR_PARENT_BRANCH_NOT_FOUND int -3 27 const AS_ERR_ALREADY_SUSPENDED int -4 28 const AS_ERR_NOT_SUSPENDED int -5 29 const AS_ERR_SERIALIZATION int -6 30 const AS_ERR_DESERIALIZATION int -7 31 const AS_ERR_CHECKSUM_MISMATCH int -8 32 const AS_ERR_RECONSTRUCTION_FAILED int -9 33 const AS_ERR_CAPACITY int -10 34 35 note Distinct InvalidCheckpoint reason codes matching Rust StateError::InvalidCheckpoint 36 const AS_ERR_CKPT_NO_AGENT int -20 37 const AS_ERR_CKPT_DUP_AGENT int -21 38 const AS_ERR_CKPT_ABSENT_AGENT int -22 39 const AS_ERR_CKPT_DUP_BRANCH int -23 40 const AS_ERR_CKPT_MISSING_ROOT int -24 41 const AS_ERR_CKPT_INCONSISTENT_ROOT int -25 42 const AS_ERR_CKPT_UNEXPECTED_ROOT int -26 43 const AS_ERR_CKPT_MISSING_PARENT int -27 44 const AS_ERR_CKPT_INCONSISTENT_LINEAGE int -28 45 const AS_ERR_CKPT_NONCONTIGUOUS_FORK int -29 46 47 text as_dom_agent "AIENOS_AGENT_GENESIS_v1:" 48 text as_dom_root "AIENOS_ROOT_BRANCH_v1:" 49 text as_dom_child "AIENOS_CHILD_BRANCH_v1:" 50 text as_dom_token "AIENOS_TOKEN_GENESIS_v1" 51 text as_ckpt_magic "AIENAST1" 52 text as_hex_digits "`0123456789abcdef`" 53 54 note Standalone TokenHistory pool (AS_MAX_TH = 4) 55 global as_th_cnt ulong 4 56 global as_th_rhash uchar 128 57 global as_th_tseq ulong 256 58 global as_th_tid uint 256 59 global as_th_thash uchar 8192 60 61 note Standalone Lineage pool (AS_MAX_LIN = 4) 62 global as_lin_root uchar 128 63 global as_lin_depth ulong 4 64 global as_lin_cnt ulong 4 65 global as_lin_anc uchar 2048 66 67 note Standalone EpistemicRefs pool (AS_MAX_EPI = 4) 68 global as_epi_cnt ulong 4 69 global as_epi_ids uchar 512 70 71 note AgentStateManager pool (AS_MAX_MGRS = 2, AS_MAX_BRANCHES = 32 per manager -> 64 slots) 72 global as_mgr_inc ulong 2 73 global as_mgr_next_seq uint 2 74 global as_mgr_agent_cnt ulong 2 75 global as_mgr_agents uchar 512 76 global as_mgr_branch_cnt ulong 2 77 78 global as_br_id uchar 2048 79 global as_br_has_parent uchar 64 80 global as_br_parent_id uchar 2048 81 global as_br_agent_id uchar 2048 82 global as_br_created_at ulong 64 83 global as_br_child_cnt ulong 64 84 85 global as_br_tok_cnt ulong 64 86 global as_br_rhash uchar 2048 87 global as_br_tok_seq ulong 4096 88 global as_br_tok_id uint 4096 89 global as_br_tok_hash uchar 131072 90 91 global as_br_lin_root uchar 2048 92 global as_br_lin_depth ulong 64 93 global as_br_lin_cnt ulong 64 94 global as_br_lin_anc uchar 32768 95 96 global as_br_epi_cnt ulong 64 97 global as_br_epi_ids uchar 8192 98 99 global as_br_inc_id ulong 64 100 global as_br_inc_seq uint 64 101 global as_br_inc_kv_has uchar 64 102 global as_br_inc_kv_ref ulong 64 103 global as_br_inc_acc_has uchar 64 104 global as_br_inc_acc_ref ulong 64 105 global as_br_inc_state uchar 64 106 global as_br_inc_alloc_tok ulong 64 107 108 note Staging AgentSnapshot (used by export, decode, tamper inspection, and restore validation) 109 global as_snap_inc ulong 1 110 global as_snap_agent_cnt ulong 1 111 global as_snap_agents uchar 256 112 global as_snap_branch_cnt ulong 1 113 114 global as_snap_br_id uchar 1024 115 global as_snap_br_has_parent uchar 32 116 global as_snap_br_parent_id uchar 1024 117 global as_snap_br_agent_id uchar 1024 118 global as_snap_br_created_at ulong 32 119 120 global as_snap_br_tok_cnt ulong 32 121 global as_snap_br_rhash uchar 1024 122 global as_snap_br_tok_seq ulong 2048 123 global as_snap_br_tok_id uint 2048 124 global as_snap_br_tok_hash uchar 65536 125 126 global as_snap_br_lin_root uchar 1024 127 global as_snap_br_lin_depth ulong 32 128 global as_snap_br_lin_cnt ulong 32 129 global as_snap_br_lin_anc uchar 16384 130 131 global as_snap_br_epi_cnt ulong 32 132 global as_snap_br_epi_ids uchar 4096 133 134 note Restore validation sorted order and child counters 135 global as_val_order ulong 32 136 global as_val_child_cnt ulong 32 137 138 note === Byte encoding helpers (big-endian) === 139 140 fn as_put_u32_be buf edit uchar * off ulong v uint to void 141 put buf off uchar and shr v 24 0xff 142 put buf add off 1 uchar and shr v 16 0xff 143 put buf add off 2 uchar and shr v 8 0xff 144 put buf add off 3 uchar and v 0xff 145 end 146 147 fn as_put_u64_be buf edit uchar * off ulong v ulong to void 148 for i ulong 8 149 sh = mul sub 7 i 8 150 put buf add off i uchar and shr v sh 0xff 151 end 152 end 153 154 fn as_get_u32_be buf view uchar * off ulong to uint 155 b0 = uint get buf off 156 b1 = uint get buf add off 1 157 b2 = uint get buf add off 2 158 b3 = uint get buf add off 3 159 hi = or shl b0 24 shl b1 16 160 lo = or shl b2 8 b3 161 ret or hi lo 162 end 163 164 fn as_get_u64_be buf view uchar * off ulong to ulong 165 acc = ulong 0 166 for i ulong 8 167 b = ulong get buf add off i 168 sh = mul sub 7 i 8 169 acc = or acc shl b sh 170 end 171 ret acc 172 end 173 174 note === Cryptographic ID helpers (id.rs) === 175 176 fn as_id_eq a view uchar * b view uchar * to bool 177 for i ulong 32 178 if ne get a i get b i 179 ret false 180 end 181 end 182 ret true 183 end 184 185 fn as_id_cmp a view uchar * b view uchar * to int 186 for i ulong 32 187 va = get a i 188 vb = get b i 189 if lt va vb 190 ret -1 191 end 192 if gt va vb 193 ret 1 194 end 195 end 196 ret 0 197 end 198 199 fn as_id_is_zero a view uchar * to bool 200 for i ulong 32 201 if ne get a i 0 202 ret false 203 end 204 end 205 ret true 206 end 207 208 fn as_rec16_eq a view uchar * b view uchar * to bool 209 for i ulong 16 210 if ne get a i get b i 211 ret false 212 end 213 end 214 ret true 215 end 216 217 fn as_id_to_hex id view uchar * dst edit uchar * to void 218 for i ulong 32 219 b = ulong get id i 220 hi = and shr b 4 0xf 221 lo = and b 0xf 222 put dst mul i 2 get as_hex_digits hi 223 put dst add mul i 2 1 get as_hex_digits lo 224 end 225 end 226 227 fn as_agent_id_from_seed seed view uchar * dst edit uchar * to void 228 ctx = new ulong 40 0 229 sha256_init ctx 230 sha256_update ctx as_dom_agent 231 if gt len seed 0 232 sha256_update ctx seed 233 end 234 sha256_final ctx dst 235 end 236 237 fn as_branch_id_root agent_id view uchar * dst edit uchar * to void 238 ctx = new ulong 40 0 239 sha256_init ctx 240 sha256_update ctx as_dom_root 241 sha256_update ctx part agent_id 0 32 242 sha256_final ctx dst 243 end 244 245 fn as_branch_id_derive parent view uchar * branch_index ulong dst edit uchar * to void 246 ctx = new ulong 40 0 247 ibuf = new uchar 8 0 248 as_put_u64_be ibuf 0 branch_index 249 sha256_init ctx 250 sha256_update ctx as_dom_child 251 sha256_update ctx part parent 0 32 252 sha256_update ctx ibuf 253 sha256_final ctx dst 254 end 255 256 note === TokenHistory primitives and standalone pool (history.rs) === 257 258 fn as_token_genesis_hash dst edit uchar * to void 259 dlen = sha2_digest 256 as_dom_token dst 260 if ne dlen 32 261 trap 8 262 end 263 end 264 265 fn as_token_step_hash prev_hash view uchar * seq ulong token_id uint dst edit uchar * to void 266 ctx = new ulong 40 0 267 sbuf = new uchar 8 0 268 tbuf = new uchar 4 0 269 as_put_u64_be sbuf 0 seq 270 as_put_u32_be tbuf 0 token_id 271 sha256_init ctx 272 sha256_update ctx part prev_hash 0 32 273 sha256_update ctx sbuf 274 sha256_update ctx tbuf 275 sha256_final ctx dst 276 end 277 278 fn as_th_new slot ulong to void 279 put as_th_cnt slot 0 280 gh = new uchar 32 0 281 as_token_genesis_hash gh 282 base = mul slot 32 283 for i ulong 32 284 put as_th_rhash add base i get gh i 285 end 286 end 287 288 fn as_th_count slot ulong to ulong 289 ret get as_th_cnt slot 290 end 291 292 fn as_th_is_empty slot ulong to bool 293 ret eq get as_th_cnt slot 0 294 end 295 296 fn as_th_rolling_hash slot ulong dst edit uchar * to void 297 base = mul slot 32 298 for i ulong 32 299 put dst i get as_th_rhash add base i 300 end 301 end 302 303 fn as_th_get_token slot ulong idx ulong to uint 304 base = mul slot AS_MAX_TOKENS 305 ret get as_th_tid add base idx 306 end 307 308 fn as_th_append slot ulong token_id uint to int 309 cnt = get as_th_cnt slot 310 if ge cnt AS_MAX_TOKENS 311 ret AS_ERR_CAPACITY 312 end 313 prev = new uchar 32 0 314 nh = new uchar 32 0 315 rbase = mul slot 32 316 for i ulong 32 317 put prev i get as_th_rhash add rbase i 318 end 319 as_token_step_hash prev cnt token_id nh 320 tbase = add mul slot AS_MAX_TOKENS cnt 321 put as_th_tseq tbase cnt 322 put as_th_tid tbase token_id 323 hbase = mul tbase 32 324 for i ulong 32 325 put as_th_thash add hbase i get nh i 326 put as_th_rhash add rbase i get nh i 327 end 328 put as_th_cnt slot add cnt 1 329 ret AS_OK 330 end 331 332 fn as_th_append_tokens slot ulong tokens view uint * to int 333 n = len tokens 334 cnt = get as_th_cnt slot 335 if gt add cnt n AS_MAX_TOKENS 336 ret AS_ERR_CAPACITY 337 end 338 for i ulong n bound 64 339 rc = as_th_append slot get tokens i 340 if ne rc AS_OK 341 ret rc 342 end 343 end 344 ret AS_OK 345 end 346 347 fn as_th_copy_tok dst_slot ulong src_slot ulong k ulong to void 348 dt = add mul dst_slot AS_MAX_TOKENS k 349 st = add mul src_slot AS_MAX_TOKENS k 350 put as_th_tseq dt get as_th_tseq st 351 put as_th_tid dt get as_th_tid st 352 dh = mul dt 32 353 sh = mul st 32 354 for j ulong 32 355 put as_th_thash add dh j get as_th_thash add sh j 356 end 357 end 358 359 fn as_th_fork dst_slot ulong src_slot ulong to void 360 cnt = get as_th_cnt src_slot 361 put as_th_cnt dst_slot cnt 362 drb = mul dst_slot 32 363 srb = mul src_slot 32 364 for i ulong 32 365 put as_th_rhash add drb i get as_th_rhash add srb i 366 end 367 for k ulong cnt bound 64 368 as_th_copy_tok dst_slot src_slot k 369 end 370 end 371 372 note === Standalone Lineage and EpistemicRefs pools (lineage.rs) === 373 374 fn as_lin_new_root slot ulong root_agent view uchar * to void 375 base = mul slot 32 376 for i ulong 32 377 put as_lin_root add base i get root_agent i 378 end 379 put as_lin_depth slot 0 380 put as_lin_cnt slot 0 381 end 382 383 fn as_lin_depth_of slot ulong to ulong 384 ret get as_lin_depth slot 385 end 386 387 fn as_lin_copy_anc dst_slot ulong src_slot ulong k ulong to void 388 da = add mul dst_slot mul AS_MAX_DEPTH 32 mul k 32 389 sa = add mul src_slot mul AS_MAX_DEPTH 32 mul k 32 390 for j ulong 32 391 put as_lin_anc add da j get as_lin_anc add sa j 392 end 393 end 394 395 fn as_lin_extend dst_slot ulong src_slot ulong branch_id view uchar * to int 396 cnt = get as_lin_cnt src_slot 397 if ge cnt AS_MAX_DEPTH 398 ret AS_ERR_CAPACITY 399 end 400 dr = mul dst_slot 32 401 sr = mul src_slot 32 402 for i ulong 32 403 put as_lin_root add dr i get as_lin_root add sr i 404 end 405 for k ulong cnt bound 16 406 as_lin_copy_anc dst_slot src_slot k 407 end 408 noff = add mul dst_slot mul AS_MAX_DEPTH 32 mul cnt 32 409 for j ulong 32 410 put as_lin_anc add noff j get branch_id j 411 end 412 put as_lin_cnt dst_slot add cnt 1 413 put as_lin_depth dst_slot add get as_lin_depth src_slot 1 414 ret AS_OK 415 end 416 417 fn as_lin_contains slot ulong branch_id view uchar * to bool 418 cnt = get as_lin_cnt slot 419 base = mul slot mul AS_MAX_DEPTH 32 420 for k ulong cnt bound 16 421 off = add base mul k 32 422 same = true 423 for j ulong 32 424 if ne get as_lin_anc add off j get branch_id j 425 same = false 426 end 427 end 428 if same 429 ret true 430 end 431 end 432 ret false 433 end 434 435 fn as_epi_new slot ulong to void 436 put as_epi_cnt slot 0 437 end 438 439 fn as_epi_count slot ulong to ulong 440 ret get as_epi_cnt slot 441 end 442 443 fn as_epi_is_empty slot ulong to bool 444 ret eq get as_epi_cnt slot 0 445 end 446 447 fn as_epi_contains slot ulong rec_id view uchar * to bool 448 cnt = get as_epi_cnt slot 449 base = mul slot mul AS_MAX_EPISTEMIC 16 450 for k ulong cnt bound 8 451 off = add base mul k 16 452 same = true 453 for j ulong 16 454 if ne get as_epi_ids add off j get rec_id j 455 same = false 456 end 457 end 458 if same 459 ret true 460 end 461 end 462 ret false 463 end 464 465 fn as_epi_insert slot ulong rec_id view uchar * to int 466 if as_epi_contains slot rec_id 467 ret AS_OK 468 end 469 cnt = get as_epi_cnt slot 470 if ge cnt AS_MAX_EPISTEMIC 471 ret AS_ERR_CAPACITY 472 end 473 off = add mul slot mul AS_MAX_EPISTEMIC 16 mul cnt 16 474 for j ulong 16 475 put as_epi_ids add off j get rec_id j 476 end 477 put as_epi_cnt slot add cnt 1 478 ret AS_OK 479 end 480 481 note === Manager slot helpers (incarnation.rs and manager.rs) === 482 483 fn as_br_slot mgr ulong bidx ulong to ulong 484 ret add mul mgr AS_MAX_BRANCHES bidx 485 end 486 487 fn as_br_inc_init slot ulong inc_id ulong seq uint to void 488 put as_br_inc_id slot inc_id 489 put as_br_inc_seq slot seq 490 put as_br_inc_kv_has slot 0 491 put as_br_inc_kv_ref slot 0 492 put as_br_inc_acc_has slot 0 493 put as_br_inc_acc_ref slot 0 494 put as_br_inc_state slot AS_COMPUTE_IDLE 495 put as_br_inc_alloc_tok slot 0 496 end 497 498 fn as_br_inc_evict slot ulong to void 499 put as_br_inc_kv_has slot 0 500 put as_br_inc_kv_ref slot 0 501 put as_br_inc_acc_has slot 0 502 put as_br_inc_acc_ref slot 0 503 put as_br_inc_alloc_tok slot 0 504 put as_br_inc_state slot AS_COMPUTE_EVICTED 505 end 506 507 fn as_mgr_init mgr ulong incarnation_id ulong to void 508 put as_mgr_inc mgr incarnation_id 509 put as_mgr_next_seq mgr 1 510 put as_mgr_agent_cnt mgr 0 511 put as_mgr_branch_cnt mgr 0 512 end 513 514 fn as_mgr_has_agent mgr ulong agent_id view uchar * to bool 515 cnt = get as_mgr_agent_cnt mgr 516 base = mul mgr mul AS_MAX_AGENTS 32 517 for a ulong cnt bound 8 518 off = add base mul a 32 519 same = true 520 for i ulong 32 521 if ne get as_mgr_agents add off i get agent_id i 522 same = false 523 end 524 end 525 if same 526 ret true 527 end 528 end 529 ret false 530 end 531 532 fn as_mgr_find_branch mgr ulong branch_id view uchar * to long 533 cnt = get as_mgr_branch_cnt mgr 534 for b ulong cnt bound 32 535 slot = as_br_slot mgr b 536 off = mul slot 32 537 same = true 538 for i ulong 32 539 if ne get as_br_id add off i get branch_id i 540 same = false 541 end 542 end 543 if same 544 ret long b 545 end 546 end 547 ret -1 548 end 549 550 fn as_br_init_root slot ulong agent_id view uchar * root_id view uchar * ts ulong to void 551 off = mul slot 32 552 for i ulong 32 553 put as_br_id add off i get root_id i 554 put as_br_parent_id add off i 0 555 put as_br_agent_id add off i get agent_id i 556 put as_br_lin_root add off i get agent_id i 557 end 558 put as_br_has_parent slot 0 559 put as_br_created_at slot ts 560 put as_br_child_cnt slot 0 561 put as_br_tok_cnt slot 0 562 gh = new uchar 32 0 563 as_token_genesis_hash gh 564 for i ulong 32 565 put as_br_rhash add off i get gh i 566 end 567 put as_br_lin_depth slot 0 568 put as_br_lin_cnt slot 0 569 put as_br_epi_cnt slot 0 570 end 571 572 fn as_br_copy_tok dst_slot ulong src_slot ulong k ulong to void 573 dt = add mul dst_slot AS_MAX_TOKENS k 574 st = add mul src_slot AS_MAX_TOKENS k 575 put as_br_tok_seq dt get as_br_tok_seq st 576 put as_br_tok_id dt get as_br_tok_id st 577 dh = mul dt 32 578 sh = mul st 32 579 for j ulong 32 580 put as_br_tok_hash add dh j get as_br_tok_hash add sh j 581 end 582 end 583 584 fn as_br_copy_history dst_slot ulong src_slot ulong to void 585 cnt = get as_br_tok_cnt src_slot 586 put as_br_tok_cnt dst_slot cnt 587 dr = mul dst_slot 32 588 sr = mul src_slot 32 589 for i ulong 32 590 put as_br_rhash add dr i get as_br_rhash add sr i 591 end 592 for k ulong cnt bound 64 593 as_br_copy_tok dst_slot src_slot k 594 end 595 end 596 597 fn as_br_copy_lin_anc dst_slot ulong src_slot ulong k ulong to void 598 da = add mul dst_slot mul AS_MAX_DEPTH 32 mul k 32 599 sa = add mul src_slot mul AS_MAX_DEPTH 32 mul k 32 600 for j ulong 32 601 put as_br_lin_anc add da j get as_br_lin_anc add sa j 602 end 603 end 604 605 fn as_br_copy_epi_one dst_slot ulong src_slot ulong k ulong to void 606 doff = add mul dst_slot mul AS_MAX_EPISTEMIC 16 mul k 16 607 soff = add mul src_slot mul AS_MAX_EPISTEMIC 16 mul k 16 608 for j ulong 16 609 put as_br_epi_ids add doff j get as_br_epi_ids add soff j 610 end 611 end 612 613 fn as_br_copy_epi dst_slot ulong src_slot ulong to void 614 ecnt = get as_br_epi_cnt src_slot 615 put as_br_epi_cnt dst_slot ecnt 616 for k ulong ecnt bound 8 617 as_br_copy_epi_one dst_slot src_slot k 618 end 619 end 620 621 fn as_br_copy_lin_and_epi dst_slot ulong src_slot ulong child_id view uchar * to void 622 dr = mul dst_slot 32 623 sr = mul src_slot 32 624 for i ulong 32 625 put as_br_lin_root add dr i get as_br_lin_root add sr i 626 end 627 lcnt = get as_br_lin_cnt src_slot 628 for k ulong lcnt bound 16 629 as_br_copy_lin_anc dst_slot src_slot k 630 end 631 noff = add mul dst_slot mul AS_MAX_DEPTH 32 mul lcnt 32 632 for j ulong 32 633 put as_br_lin_anc add noff j get child_id j 634 end 635 put as_br_lin_cnt dst_slot add lcnt 1 636 put as_br_lin_depth dst_slot add get as_br_lin_depth src_slot 1 637 as_br_copy_epi dst_slot src_slot 638 end 639 640 fn as_br_fork_slot dst_slot ulong src_slot ulong child_id view uchar * ts ulong to void 641 doff = mul dst_slot 32 642 soff = mul src_slot 32 643 for i ulong 32 644 put as_br_id add doff i get child_id i 645 put as_br_parent_id add doff i get as_br_id add soff i 646 put as_br_agent_id add doff i get as_br_agent_id add soff i 647 end 648 put as_br_has_parent dst_slot 1 649 put as_br_created_at dst_slot ts 650 put as_br_child_cnt dst_slot 0 651 as_br_copy_history dst_slot src_slot 652 as_br_copy_lin_and_epi dst_slot src_slot child_id 653 end 654 655 fn as_mgr_register_agent mgr ulong agent_id view uchar * ts ulong dst_branch edit uchar * to int 656 root_id = new uchar 32 0 657 as_branch_id_root agent_id root_id 658 for i ulong 32 659 put dst_branch i get root_id i 660 end 661 if as_mgr_has_agent mgr agent_id 662 found = as_mgr_find_branch mgr root_id 663 if ge found 0 664 ret AS_OK 665 end 666 else 667 acnt = get as_mgr_agent_cnt mgr 668 if ge acnt AS_MAX_AGENTS 669 ret AS_ERR_CAPACITY 670 end 671 aoff = add mul mgr mul AS_MAX_AGENTS 32 mul acnt 32 672 for i ulong 32 673 put as_mgr_agents add aoff i get agent_id i 674 end 675 put as_mgr_agent_cnt mgr add acnt 1 676 end 677 bcnt = get as_mgr_branch_cnt mgr 678 if ge bcnt AS_MAX_BRANCHES 679 ret AS_ERR_CAPACITY 680 end 681 slot = as_br_slot mgr bcnt 682 as_br_init_root slot agent_id root_id ts 683 seq = get as_mgr_next_seq mgr 684 put as_mgr_next_seq mgr add seq 1 685 as_br_inc_init slot get as_mgr_inc mgr seq 686 put as_mgr_branch_cnt mgr add bcnt 1 687 ret AS_OK 688 end 689 690 fn as_br_append_one_token slot ulong token_id uint to int 691 cnt = get as_br_tok_cnt slot 692 if ge cnt AS_MAX_TOKENS 693 ret AS_ERR_CAPACITY 694 end 695 prev = new uchar 32 0 696 nh = new uchar 32 0 697 rbase = mul slot 32 698 for i ulong 32 699 put prev i get as_br_rhash add rbase i 700 end 701 as_token_step_hash prev cnt token_id nh 702 tidx = add mul slot AS_MAX_TOKENS cnt 703 put as_br_tok_seq tidx cnt 704 put as_br_tok_id tidx token_id 705 hbase = mul tidx 32 706 for i ulong 32 707 put as_br_tok_hash add hbase i get nh i 708 put as_br_rhash add rbase i get nh i 709 end 710 put as_br_tok_cnt slot add cnt 1 711 ret AS_OK 712 end 713 714 fn as_mgr_append_tokens mgr ulong branch_id view uchar * tokens view uint * to int 715 bidx = as_mgr_find_branch mgr branch_id 716 if lt bidx 0 717 ret AS_ERR_BRANCH_NOT_FOUND 718 end 719 slot = as_br_slot mgr ulong bidx 720 n = len tokens 721 cur = get as_br_tok_cnt slot 722 if gt add cur n AS_MAX_TOKENS 723 ret AS_ERR_CAPACITY 724 end 725 for i ulong n bound 64 726 rc = as_br_append_one_token slot get tokens i 727 if ne rc AS_OK 728 ret rc 729 end 730 end 731 st = get as_br_inc_state slot 732 if ne st AS_COMPUTE_SUSPENDED 733 if ne st AS_COMPUTE_EVICTED 734 put as_br_inc_alloc_tok slot get as_br_tok_cnt slot 735 put as_br_inc_state slot AS_COMPUTE_DECODING 736 end 737 end 738 ret AS_OK 739 end 740 741 fn as_br_epi_eq_one slot ulong k ulong rec_id view uchar * to bool 742 off = add mul slot mul AS_MAX_EPISTEMIC 16 mul k 16 743 for j ulong 16 744 if ne get as_br_epi_ids add off j get rec_id j 745 ret false 746 end 747 end 748 ret true 749 end 750 751 fn as_mgr_branch_epi_contains mgr ulong bidx ulong rec_id view uchar * to bool 752 slot = as_br_slot mgr bidx 753 cnt = get as_br_epi_cnt slot 754 for k ulong cnt bound 8 755 if as_br_epi_eq_one slot k rec_id 756 ret true 757 end 758 end 759 ret false 760 end 761 762 fn as_mgr_add_epistemic_ref mgr ulong branch_id view uchar * rec_id view uchar * to int 763 bidx = as_mgr_find_branch mgr branch_id 764 if lt bidx 0 765 ret AS_ERR_BRANCH_NOT_FOUND 766 end 767 if as_mgr_branch_epi_contains mgr ulong bidx rec_id 768 ret AS_OK 769 end 770 slot = as_br_slot mgr ulong bidx 771 cnt = get as_br_epi_cnt slot 772 if ge cnt AS_MAX_EPISTEMIC 773 ret AS_ERR_CAPACITY 774 end 775 off = add mul slot mul AS_MAX_EPISTEMIC 16 mul cnt 16 776 for j ulong 16 777 put as_br_epi_ids add off j get rec_id j 778 end 779 put as_br_epi_cnt slot add cnt 1 780 ret AS_OK 781 end 782 783 fn as_mgr_fork_branch mgr ulong parent_id view uchar * dst_child edit uchar * to int 784 pidx = as_mgr_find_branch mgr parent_id 785 if lt pidx 0 786 ret AS_ERR_PARENT_BRANCH_NOT_FOUND 787 end 788 pslot = as_br_slot mgr ulong pidx 789 bcnt = get as_mgr_branch_cnt mgr 790 if ge bcnt AS_MAX_BRANCHES 791 ret AS_ERR_CAPACITY 792 end 793 if ge get as_br_lin_cnt pslot AS_MAX_DEPTH 794 ret AS_ERR_CAPACITY 795 end 796 cidx = get as_br_child_cnt pslot 797 put as_br_child_cnt pslot add cidx 1 798 cid = new uchar 32 0 799 as_branch_id_derive parent_id cidx cid 800 for i ulong 32 801 put dst_child i get cid i 802 end 803 cslot = as_br_slot mgr bcnt 804 as_br_fork_slot cslot pslot cid add 1000 cidx 805 seq = get as_mgr_next_seq mgr 806 put as_mgr_next_seq mgr add seq 1 807 as_br_inc_init cslot get as_mgr_inc mgr seq 808 put as_mgr_branch_cnt mgr add bcnt 1 809 ret AS_OK 810 end 811 812 fn as_mgr_suspend mgr ulong branch_id view uchar * to int 813 bidx = as_mgr_find_branch mgr branch_id 814 if lt bidx 0 815 ret AS_ERR_BRANCH_NOT_FOUND 816 end 817 slot = as_br_slot mgr ulong bidx 818 if eq get as_br_inc_state slot AS_COMPUTE_SUSPENDED 819 ret AS_ERR_ALREADY_SUSPENDED 820 end 821 put as_br_inc_state slot AS_COMPUTE_SUSPENDED 822 ret AS_OK 823 end 824 825 fn as_mgr_resume mgr ulong branch_id view uchar * to long 826 bidx = as_mgr_find_branch mgr branch_id 827 if lt bidx 0 828 ret long AS_ERR_BRANCH_NOT_FOUND 829 end 830 slot = as_br_slot mgr ulong bidx 831 seq = get as_mgr_next_seq mgr 832 put as_mgr_next_seq mgr add seq 1 833 put as_br_inc_seq slot seq 834 if eq get as_br_inc_state slot AS_COMPUTE_SUSPENDED 835 put as_br_inc_state slot AS_COMPUTE_IDLE 836 end 837 ret long seq 838 end 839 840 fn as_mgr_reconstruct_physical mgr ulong branch_id view uchar * to int 841 bidx = as_mgr_find_branch mgr branch_id 842 if lt bidx 0 843 ret AS_ERR_BRANCH_NOT_FOUND 844 end 845 slot = as_br_slot mgr ulong bidx 846 tlen = get as_br_tok_cnt slot 847 put as_br_inc_alloc_tok slot tlen 848 put as_br_inc_kv_has slot 1 849 put as_br_inc_kv_ref slot add 0xdead0000 tlen 850 put as_br_inc_state slot AS_COMPUTE_DECODING 851 ret AS_OK 852 end 853 854 note === Snapshot staging helpers (copy manager <-> snapshot, encode/decode/seal, validate) === 855 856 fn as_snap_clear to void 857 put as_snap_inc 0 0 858 put as_snap_agent_cnt 0 0 859 put as_snap_branch_cnt 0 0 860 end 861 862 fn as_br_to_snap_tok sb ulong slot ulong k ulong to void 863 st = add mul sb AS_MAX_TOKENS k 864 bt = add mul slot AS_MAX_TOKENS k 865 put as_snap_br_tok_seq st get as_br_tok_seq bt 866 put as_snap_br_tok_id st get as_br_tok_id bt 867 sh = mul st 32 868 bh = mul bt 32 869 for j ulong 32 870 put as_snap_br_tok_hash add sh j get as_br_tok_hash add bh j 871 end 872 end 873 874 fn as_br_to_snap_hist sb ulong slot ulong to void 875 tcnt = get as_br_tok_cnt slot 876 put as_snap_br_tok_cnt sb tcnt 877 sr = mul sb 32 878 br = mul slot 32 879 for i ulong 32 880 put as_snap_br_rhash add sr i get as_br_rhash add br i 881 end 882 for k ulong tcnt bound 64 883 as_br_to_snap_tok sb slot k 884 end 885 end 886 887 fn as_br_to_snap_lin_one sb ulong slot ulong k ulong to void 888 soff = add mul sb mul AS_MAX_DEPTH 32 mul k 32 889 boff = add mul slot mul AS_MAX_DEPTH 32 mul k 32 890 for j ulong 32 891 put as_snap_br_lin_anc add soff j get as_br_lin_anc add boff j 892 end 893 end 894 895 fn as_br_to_snap_lin sb ulong slot ulong to void 896 sr = mul sb 32 897 br = mul slot 32 898 for i ulong 32 899 put as_snap_br_lin_root add sr i get as_br_lin_root add br i 900 end 901 put as_snap_br_lin_depth sb get as_br_lin_depth slot 902 lcnt = get as_br_lin_cnt slot 903 put as_snap_br_lin_cnt sb lcnt 904 for k ulong lcnt bound 16 905 as_br_to_snap_lin_one sb slot k 906 end 907 end 908 909 fn as_br_to_snap_epi_one sb ulong slot ulong k ulong to void 910 soff = add mul sb mul AS_MAX_EPISTEMIC 16 mul k 16 911 boff = add mul slot mul AS_MAX_EPISTEMIC 16 mul k 16 912 for j ulong 16 913 put as_snap_br_epi_ids add soff j get as_br_epi_ids add boff j 914 end 915 end 916 917 fn as_br_to_snap_epi sb ulong slot ulong to void 918 ecnt = get as_br_epi_cnt slot 919 put as_snap_br_epi_cnt sb ecnt 920 for k ulong ecnt bound 8 921 as_br_to_snap_epi_one sb slot k 922 end 923 end 924 925 fn as_br_to_snap sb ulong slot ulong to void 926 so = mul sb 32 927 bo = mul slot 32 928 for i ulong 32 929 put as_snap_br_id add so i get as_br_id add bo i 930 put as_snap_br_parent_id add so i get as_br_parent_id add bo i 931 put as_snap_br_agent_id add so i get as_br_agent_id add bo i 932 end 933 put as_snap_br_has_parent sb get as_br_has_parent slot 934 put as_snap_br_created_at sb get as_br_created_at slot 935 as_br_to_snap_hist sb slot 936 as_br_to_snap_lin sb slot 937 as_br_to_snap_epi sb slot 938 end 939 940 fn as_snap_to_br_tok slot ulong sb ulong k ulong to void 941 bt = add mul slot AS_MAX_TOKENS k 942 st = add mul sb AS_MAX_TOKENS k 943 put as_br_tok_seq bt get as_snap_br_tok_seq st 944 put as_br_tok_id bt get as_snap_br_tok_id st 945 bh = mul bt 32 946 sh = mul st 32 947 for j ulong 32 948 put as_br_tok_hash add bh j get as_snap_br_tok_hash add sh j 949 end 950 end 951 952 fn as_snap_to_br_hist slot ulong sb ulong to void 953 tcnt = get as_snap_br_tok_cnt sb 954 put as_br_tok_cnt slot tcnt 955 br = mul slot 32 956 sr = mul sb 32 957 for i ulong 32 958 put as_br_rhash add br i get as_snap_br_rhash add sr i 959 end 960 for k ulong tcnt bound 64 961 as_snap_to_br_tok slot sb k 962 end 963 end 964 965 fn as_snap_to_br_lin_one slot ulong sb ulong k ulong to void 966 boff = add mul slot mul AS_MAX_DEPTH 32 mul k 32 967 soff = add mul sb mul AS_MAX_DEPTH 32 mul k 32 968 for j ulong 32 969 put as_br_lin_anc add boff j get as_snap_br_lin_anc add soff j 970 end 971 end 972 973 fn as_snap_to_br_lin slot ulong sb ulong to void 974 br = mul slot 32 975 sr = mul sb 32 976 for i ulong 32 977 put as_br_lin_root add br i get as_snap_br_lin_root add sr i 978 end 979 put as_br_lin_depth slot get as_snap_br_lin_depth sb 980 lcnt = get as_snap_br_lin_cnt sb 981 put as_br_lin_cnt slot lcnt 982 for k ulong lcnt bound 16 983 as_snap_to_br_lin_one slot sb k 984 end 985 end 986 987 fn as_snap_to_br_epi_one slot ulong sb ulong k ulong to void 988 boff = add mul slot mul AS_MAX_EPISTEMIC 16 mul k 16 989 soff = add mul sb mul AS_MAX_EPISTEMIC 16 mul k 16 990 for j ulong 16 991 put as_br_epi_ids add boff j get as_snap_br_epi_ids add soff j 992 end 993 end 994 995 fn as_snap_to_br_epi slot ulong sb ulong to void 996 ecnt = get as_snap_br_epi_cnt sb 997 put as_br_epi_cnt slot ecnt 998 for k ulong ecnt bound 8 999 as_snap_to_br_epi_one slot sb k 1000 end 1001 end 1002 1003 fn as_snap_to_br slot ulong sb ulong to void 1004 bo = mul slot 32 1005 so = mul sb 32 1006 for i ulong 32 1007 put as_br_id add bo i get as_snap_br_id add so i 1008 put as_br_parent_id add bo i get as_snap_br_parent_id add so i 1009 put as_br_agent_id add bo i get as_snap_br_agent_id add so i 1010 end 1011 put as_br_has_parent slot get as_snap_br_has_parent sb 1012 put as_br_created_at slot get as_snap_br_created_at sb 1013 as_snap_to_br_hist slot sb 1014 as_snap_to_br_lin slot sb 1015 as_snap_to_br_epi slot sb 1016 end 1017 1018 fn as_br_id_cmp_slots s1 ulong s2 ulong to int 1019 o1 = mul s1 32 1020 o2 = mul s2 32 1021 for i ulong 32 1022 a = get as_br_id add o1 i 1023 b = get as_br_id add o2 i 1024 if lt a b 1025 ret -1 1026 end 1027 if gt a b 1028 ret 1 1029 end 1030 end 1031 ret 0 1032 end 1033 1034 fn as_snap_br_id_cmp sb1 ulong sb2 ulong to int 1035 o1 = mul sb1 32 1036 o2 = mul sb2 32 1037 for i ulong 32 1038 a = get as_snap_br_id add o1 i 1039 b = get as_snap_br_id add o2 i 1040 if lt a b 1041 ret -1 1042 end 1043 if gt a b 1044 ret 1 1045 end 1046 end 1047 ret 0 1048 end 1049 1050 fn as_snap_find_branch branch_id view uchar * to long 1051 cnt = get as_snap_branch_cnt 0 1052 for sb ulong cnt bound 32 1053 off = mul sb 32 1054 same = true 1055 for i ulong 32 1056 if ne get as_snap_br_id add off i get branch_id i 1057 same = false 1058 end 1059 end 1060 if same 1061 ret long sb 1062 end 1063 end 1064 ret -1 1065 end 1066 1067 fn as_snap_copy_tok dst_b ulong src_b ulong k ulong to void 1068 dt = add mul dst_b AS_MAX_TOKENS k 1069 st = add mul src_b AS_MAX_TOKENS k 1070 put as_snap_br_tok_seq dt get as_snap_br_tok_seq st 1071 put as_snap_br_tok_id dt get as_snap_br_tok_id st 1072 dh = mul dt 32 1073 sh = mul st 32 1074 for j ulong 32 1075 put as_snap_br_tok_hash add dh j get as_snap_br_tok_hash add sh j 1076 end 1077 end 1078 1079 fn as_snap_copy_branch_hist dst_b ulong src_b ulong to void 1080 tcnt = get as_snap_br_tok_cnt src_b 1081 put as_snap_br_tok_cnt dst_b tcnt 1082 for k ulong tcnt bound 64 1083 as_snap_copy_tok dst_b src_b k 1084 end 1085 end 1086 1087 fn as_snap_copy_lin_one dst_b ulong src_b ulong k ulong to void 1088 doff = add mul dst_b mul AS_MAX_DEPTH 32 mul k 32 1089 soff = add mul src_b mul AS_MAX_DEPTH 32 mul k 32 1090 for j ulong 32 1091 put as_snap_br_lin_anc add doff j get as_snap_br_lin_anc add soff j 1092 end 1093 end 1094 1095 fn as_snap_copy_branch_lin dst_b ulong src_b ulong to void 1096 lcnt = get as_snap_br_lin_cnt src_b 1097 put as_snap_br_lin_cnt dst_b lcnt 1098 for k ulong lcnt bound 16 1099 as_snap_copy_lin_one dst_b src_b k 1100 end 1101 end 1102 1103 fn as_snap_copy_epi_one dst_b ulong src_b ulong k ulong to void 1104 doff = add mul dst_b mul AS_MAX_EPISTEMIC 16 mul k 16 1105 soff = add mul src_b mul AS_MAX_EPISTEMIC 16 mul k 16 1106 for j ulong 16 1107 put as_snap_br_epi_ids add doff j get as_snap_br_epi_ids add soff j 1108 end 1109 end 1110 1111 fn as_snap_copy_branch_epi dst_b ulong src_b ulong to void 1112 ecnt = get as_snap_br_epi_cnt src_b 1113 put as_snap_br_epi_cnt dst_b ecnt 1114 for k ulong ecnt bound 8 1115 as_snap_copy_epi_one dst_b src_b k 1116 end 1117 end 1118 1119 fn as_snap_copy_branch dst_b ulong src_b ulong to void 1120 doff = mul dst_b 32 1121 soff = mul src_b 32 1122 for i ulong 32 1123 put as_snap_br_id add doff i get as_snap_br_id add soff i 1124 put as_snap_br_parent_id add doff i get as_snap_br_parent_id add soff i 1125 put as_snap_br_agent_id add doff i get as_snap_br_agent_id add soff i 1126 put as_snap_br_rhash add doff i get as_snap_br_rhash add soff i 1127 put as_snap_br_lin_root add doff i get as_snap_br_lin_root add soff i 1128 end 1129 put as_snap_br_has_parent dst_b get as_snap_br_has_parent src_b 1130 put as_snap_br_created_at dst_b get as_snap_br_created_at src_b 1131 put as_snap_br_lin_depth dst_b get as_snap_br_lin_depth src_b 1132 as_snap_copy_branch_hist dst_b src_b 1133 as_snap_copy_branch_lin dst_b src_b 1134 as_snap_copy_branch_epi dst_b src_b 1135 end 1136 1137 fn as_snap_remove_branch sb ulong to void 1138 cnt = get as_snap_branch_cnt 0 1139 if ge sb cnt 1140 ret 1141 end 1142 last = sub cnt 1 1143 if lt sb last 1144 for idx ulong sub last sb bound 32 1145 dst_b = add sb idx 1146 as_snap_copy_branch dst_b add dst_b 1 1147 end 1148 end 1149 put as_snap_branch_cnt 0 last 1150 end 1151 1152 fn as_snap_push_new_root agent_id view uchar * ts ulong to int 1153 cnt = get as_snap_branch_cnt 0 1154 if ge cnt AS_MAX_BRANCHES 1155 ret AS_ERR_CAPACITY 1156 end 1157 rid = new uchar 32 0 1158 gh = new uchar 32 0 1159 as_branch_id_root agent_id rid 1160 as_token_genesis_hash gh 1161 off = mul cnt 32 1162 for i ulong 32 1163 put as_snap_br_id add off i get rid i 1164 put as_snap_br_parent_id add off i 0 1165 put as_snap_br_agent_id add off i get agent_id i 1166 put as_snap_br_rhash add off i get gh i 1167 put as_snap_br_lin_root add off i get agent_id i 1168 end 1169 put as_snap_br_has_parent cnt 0 1170 put as_snap_br_created_at cnt ts 1171 put as_snap_br_tok_cnt cnt 0 1172 put as_snap_br_lin_depth cnt 0 1173 put as_snap_br_lin_cnt cnt 0 1174 put as_snap_br_epi_cnt cnt 0 1175 put as_snap_branch_cnt 0 add cnt 1 1176 ret AS_OK 1177 end 1178 1179 fn as_snap_encode_br_hdr buf edit uchar * pos ulong sb ulong to long 1180 cap = len buf 1181 if gt add pos 141 cap 1182 ret long AS_ERR_SERIALIZATION 1183 end 1184 off = mul sb 32 1185 for i ulong 32 1186 put buf add pos i get as_snap_br_id add off i 1187 end 1188 pos = add pos 32 1189 put buf pos get as_snap_br_has_parent sb 1190 pos = add pos 1 1191 for i ulong 32 1192 put buf add pos i get as_snap_br_parent_id add off i 1193 end 1194 pos = add pos 32 1195 for i ulong 32 1196 put buf add pos i get as_snap_br_agent_id add off i 1197 end 1198 pos = add pos 32 1199 as_put_u64_be buf pos get as_snap_br_created_at sb 1200 pos = add pos 8 1201 as_put_u32_be buf pos uint get as_snap_br_tok_cnt sb 1202 pos = add pos 4 1203 for i ulong 32 1204 put buf add pos i get as_snap_br_rhash add off i 1205 end 1206 ret long add pos 32 1207 end 1208 1209 fn as_snap_encode_br_toks buf edit uchar * pos ulong sb ulong to long 1210 cap = len buf 1211 tcnt = get as_snap_br_tok_cnt sb 1212 if gt add pos mul tcnt 44 cap 1213 ret long AS_ERR_SERIALIZATION 1214 end 1215 tb = mul sb AS_MAX_TOKENS 1216 for k ulong tcnt bound 64 1217 as_put_u64_be buf pos get as_snap_br_tok_seq add tb k 1218 pos = add pos 8 1219 as_put_u32_be buf pos get as_snap_br_tok_id add tb k 1220 pos = add pos 4 1221 hb = mul add tb k 32 1222 for j ulong 32 1223 put buf add pos j get as_snap_br_tok_hash add hb j 1224 end 1225 pos = add pos 32 1226 end 1227 ret long pos 1228 end 1229 1230 fn as_snap_encode_one_anc buf edit uchar * pos ulong sb ulong k ulong to void 1231 aoff = add mul sb mul AS_MAX_DEPTH 32 mul k 32 1232 for j ulong 32 1233 put buf add pos j get as_snap_br_lin_anc add aoff j 1234 end 1235 end 1236 1237 fn as_snap_encode_br_lin buf edit uchar * pos ulong sb ulong to long 1238 lcnt = get as_snap_br_lin_cnt sb 1239 if gt add pos add 44 mul lcnt 32 len buf 1240 ret long AS_ERR_SERIALIZATION 1241 end 1242 off = mul sb 32 1243 for i ulong 32 1244 put buf add pos i get as_snap_br_lin_root add off i 1245 end 1246 pos = add pos 32 1247 as_put_u64_be buf pos get as_snap_br_lin_depth sb 1248 pos = add pos 8 1249 as_put_u32_be buf pos uint lcnt 1250 pos = add pos 4 1251 for k ulong lcnt bound 16 1252 as_snap_encode_one_anc buf pos sb k 1253 pos = add pos 32 1254 end 1255 ret long pos 1256 end 1257 1258 fn as_snap_encode_one_epi buf edit uchar * pos ulong sb ulong k ulong to void 1259 eoff = add mul sb mul AS_MAX_EPISTEMIC 16 mul k 16 1260 for j ulong 16 1261 put buf add pos j get as_snap_br_epi_ids add eoff j 1262 end 1263 end 1264 1265 fn as_snap_encode_br_epi buf edit uchar * pos ulong sb ulong to long 1266 ecnt = get as_snap_br_epi_cnt sb 1267 if gt add pos add 4 mul ecnt 16 len buf 1268 ret long AS_ERR_SERIALIZATION 1269 end 1270 as_put_u32_be buf pos uint ecnt 1271 pos = add pos 4 1272 for k ulong ecnt bound 8 1273 as_snap_encode_one_epi buf pos sb k 1274 pos = add pos 16 1275 end 1276 ret long pos 1277 end 1278 1279 fn as_snap_encode_br_body buf edit uchar * pos ulong sb ulong to long 1280 p1 = as_snap_encode_br_toks buf pos sb 1281 if lt p1 0 1282 ret p1 1283 end 1284 p2 = as_snap_encode_br_lin buf ulong p1 sb 1285 if lt p2 0 1286 ret p2 1287 end 1288 ret as_snap_encode_br_epi buf ulong p2 sb 1289 end 1290 1291 fn as_seal_snap_agents buf edit uchar * pos ulong to long 1292 acnt = get as_snap_agent_cnt 0 1293 if gt add pos add 4 mul acnt 32 len buf 1294 ret long AS_ERR_SERIALIZATION 1295 end 1296 as_put_u32_be buf pos uint acnt 1297 pos = add pos 4 1298 for a ulong acnt bound 8 1299 aoff = mul a 32 1300 for i ulong 32 1301 put buf add pos i get as_snap_agents add aoff i 1302 end 1303 pos = add pos 32 1304 end 1305 ret long pos 1306 end 1307 1308 fn as_seal_snapshot buf edit uchar * to long 1309 if lt len buf 60 1310 ret long AS_ERR_SERIALIZATION 1311 end 1312 for i ulong 8 1313 put buf i get as_ckpt_magic i 1314 end 1315 as_put_u64_be buf 44 get as_snap_inc 0 1316 pa = as_seal_snap_agents buf 52 1317 if lt pa 0 1318 ret pa 1319 end 1320 pos = ulong pa 1321 if gt add pos 4 len buf 1322 ret long AS_ERR_SERIALIZATION 1323 end 1324 bcnt = get as_snap_branch_cnt 0 1325 as_put_u32_be buf pos uint bcnt 1326 pos = add pos 4 1327 for sb ulong bcnt bound 32 1328 p1 = as_snap_encode_br_hdr buf pos sb 1329 if lt p1 0 1330 ret p1 1331 end 1332 p2 = as_snap_encode_br_body buf ulong p1 sb 1333 if lt p2 0 1334 ret p2 1335 end 1336 pos = ulong p2 1337 end 1338 plen = sub pos 44 1339 as_put_u32_be buf 40 uint plen 1340 dig = new uchar 32 0 1341 if ne sha2_digest 256 part buf 44 plen dig 32 1342 ret long AS_ERR_SERIALIZATION 1343 end 1344 for i ulong 32 1345 put buf add 8 i get dig i 1346 end 1347 ret long pos 1348 end 1349 1350 fn as_snap_decode_br_hdr buf view uchar * pos ulong total ulong sb ulong to long 1351 if gt add pos 141 total 1352 ret long AS_ERR_DESERIALIZATION 1353 end 1354 off = mul sb 32 1355 for i ulong 32 1356 put as_snap_br_id add off i get buf add pos i 1357 end 1358 pos = add pos 32 1359 hp = get buf pos 1360 if gt hp 1 1361 ret long AS_ERR_DESERIALIZATION 1362 end 1363 put as_snap_br_has_parent sb hp 1364 pos = add pos 1 1365 for i ulong 32 1366 put as_snap_br_parent_id add off i get buf add pos i 1367 end 1368 pos = add pos 32 1369 for i ulong 32 1370 put as_snap_br_agent_id add off i get buf add pos i 1371 end 1372 pos = add pos 32 1373 put as_snap_br_created_at sb as_get_u64_be buf pos 1374 pos = add pos 8 1375 tcnt = ulong as_get_u32_be buf pos 1376 if gt tcnt AS_MAX_TOKENS 1377 ret long AS_ERR_DESERIALIZATION 1378 end 1379 put as_snap_br_tok_cnt sb tcnt 1380 pos = add pos 4 1381 for i ulong 32 1382 put as_snap_br_rhash add off i get buf add pos i 1383 end 1384 ret long add pos 32 1385 end 1386 1387 fn as_snap_decode_br_toks buf view uchar * pos ulong total ulong sb ulong to long 1388 tcnt = get as_snap_br_tok_cnt sb 1389 if gt add pos mul tcnt 44 total 1390 ret long AS_ERR_DESERIALIZATION 1391 end 1392 tb = mul sb AS_MAX_TOKENS 1393 for k ulong tcnt bound 64 1394 put as_snap_br_tok_seq add tb k as_get_u64_be buf pos 1395 pos = add pos 8 1396 put as_snap_br_tok_id add tb k as_get_u32_be buf pos 1397 pos = add pos 4 1398 hb = mul add tb k 32 1399 for j ulong 32 1400 put as_snap_br_tok_hash add hb j get buf add pos j 1401 end 1402 pos = add pos 32 1403 end 1404 ret long pos 1405 end 1406 1407 fn as_snap_decode_one_anc buf view uchar * pos ulong sb ulong k ulong to void 1408 aoff = add mul sb mul AS_MAX_DEPTH 32 mul k 32 1409 for j ulong 32 1410 put as_snap_br_lin_anc add aoff j get buf add pos j 1411 end 1412 end 1413 1414 fn as_snap_decode_br_lin buf view uchar * pos ulong total ulong sb ulong to long 1415 if gt add pos 44 total 1416 ret long AS_ERR_DESERIALIZATION 1417 end 1418 off = mul sb 32 1419 for i ulong 32 1420 put as_snap_br_lin_root add off i get buf add pos i 1421 end 1422 pos = add pos 32 1423 put as_snap_br_lin_depth sb as_get_u64_be buf pos 1424 pos = add pos 8 1425 lcnt = ulong as_get_u32_be buf pos 1426 pos = add pos 4 1427 if gt lcnt AS_MAX_DEPTH 1428 ret long AS_ERR_DESERIALIZATION 1429 end 1430 if gt add pos mul lcnt 32 total 1431 ret long AS_ERR_DESERIALIZATION 1432 end 1433 put as_snap_br_lin_cnt sb lcnt 1434 for k ulong lcnt bound 16 1435 as_snap_decode_one_anc buf pos sb k 1436 pos = add pos 32 1437 end 1438 ret long pos 1439 end 1440 1441 fn as_snap_decode_one_epi buf view uchar * pos ulong sb ulong k ulong to void 1442 eoff = add mul sb mul AS_MAX_EPISTEMIC 16 mul k 16 1443 for j ulong 16 1444 put as_snap_br_epi_ids add eoff j get buf add pos j 1445 end 1446 end 1447 1448 fn as_snap_decode_br_epi buf view uchar * pos ulong total ulong sb ulong to long 1449 if gt add pos 4 total 1450 ret long AS_ERR_DESERIALIZATION 1451 end 1452 ecnt = ulong as_get_u32_be buf pos 1453 pos = add pos 4 1454 if gt ecnt AS_MAX_EPISTEMIC 1455 ret long AS_ERR_DESERIALIZATION 1456 end 1457 if gt add pos mul ecnt 16 total 1458 ret long AS_ERR_DESERIALIZATION 1459 end 1460 put as_snap_br_epi_cnt sb ecnt 1461 for k ulong ecnt bound 8 1462 as_snap_decode_one_epi buf pos sb k 1463 pos = add pos 16 1464 end 1465 ret long pos 1466 end 1467 1468 fn as_snap_decode_br_lin_epi buf view uchar * pos ulong total ulong sb ulong to long 1469 p1 = as_snap_decode_br_lin buf pos total sb 1470 if lt p1 0 1471 ret p1 1472 end 1473 ret as_snap_decode_br_epi buf ulong p1 total sb 1474 end 1475 1476 fn as_decode_ckpt_envelope buf view uchar * total ulong to int 1477 if lt total 44 1478 ret AS_ERR_DESERIALIZATION 1479 end 1480 if gt total len buf 1481 ret AS_ERR_DESERIALIZATION 1482 end 1483 for i ulong 8 1484 if ne get buf i get as_ckpt_magic i 1485 ret AS_ERR_DESERIALIZATION 1486 end 1487 end 1488 plen = ulong as_get_u32_be buf 40 1489 if ne add 44 plen total 1490 ret AS_ERR_DESERIALIZATION 1491 end 1492 dig = new uchar 32 0 1493 if ne sha2_digest 256 part buf 44 plen dig 32 1494 ret AS_ERR_DESERIALIZATION 1495 end 1496 for i ulong 32 1497 if ne get buf add 8 i get dig i 1498 ret AS_ERR_CHECKSUM_MISMATCH 1499 end 1500 end 1501 ret AS_OK 1502 end 1503 1504 fn as_decode_snap_agents buf view uchar * pos ulong total ulong to long 1505 if gt add pos 12 total 1506 ret long AS_ERR_DESERIALIZATION 1507 end 1508 put as_snap_inc 0 as_get_u64_be buf pos 1509 pos = add pos 8 1510 acnt = ulong as_get_u32_be buf pos 1511 pos = add pos 4 1512 if gt acnt AS_MAX_AGENTS 1513 ret long AS_ERR_DESERIALIZATION 1514 end 1515 if gt add pos add mul acnt 32 4 total 1516 ret long AS_ERR_DESERIALIZATION 1517 end 1518 put as_snap_agent_cnt 0 acnt 1519 for a ulong acnt bound 8 1520 aoff = mul a 32 1521 for i ulong 32 1522 put as_snap_agents add aoff i get buf add pos i 1523 end 1524 pos = add pos 32 1525 end 1526 ret long pos 1527 end 1528 1529 fn as_decode_checkpoint_to_snap buf view uchar * total ulong to int 1530 rc = as_decode_ckpt_envelope buf total 1531 if ne rc AS_OK 1532 ret rc 1533 end 1534 pa = as_decode_snap_agents buf 44 total 1535 if lt pa 0 1536 ret int pa 1537 end 1538 pos = ulong pa 1539 bcnt = ulong as_get_u32_be buf pos 1540 pos = add pos 4 1541 if gt bcnt AS_MAX_BRANCHES 1542 ret AS_ERR_DESERIALIZATION 1543 end 1544 put as_snap_branch_cnt 0 bcnt 1545 for sb ulong bcnt bound 32 1546 p1 = as_snap_decode_br_hdr buf pos total sb 1547 if lt p1 0 1548 ret int p1 1549 end 1550 p2 = as_snap_decode_br_toks buf ulong p1 total sb 1551 if lt p2 0 1552 ret int p2 1553 end 1554 p3 = as_snap_decode_br_lin_epi buf ulong p2 total sb 1555 if lt p3 0 1556 ret int p3 1557 end 1558 pos = ulong p3 1559 end 1560 if ne pos total 1561 ret AS_ERR_DESERIALIZATION 1562 end 1563 ret AS_OK 1564 end 1565 1566 note === Checkpoint export & validation === 1567 1568 fn as_br_matches_agent slot ulong agent_id view uchar * to bool 1569 boff = mul slot 32 1570 for i ulong 32 1571 if ne get as_br_agent_id add boff i get agent_id i 1572 ret false 1573 end 1574 end 1575 ret true 1576 end 1577 1578 fn as_sort_val_order_br mcnt ulong to void 1579 for i ulong mcnt bound 32 1580 for j ulong mcnt bound 32 1581 if lt add j 1 mcnt 1582 s1 = get as_val_order j 1583 s2 = get as_val_order add j 1 1584 if gt as_br_id_cmp_slots s1 s2 0 1585 put as_val_order j s2 1586 put as_val_order add j 1 s1 1587 end 1588 end 1589 end 1590 end 1591 end 1592 1593 fn as_mgr_export_checkpoint mgr ulong agent_id view uchar * dst_buf edit uchar * to long 1594 if not as_mgr_has_agent mgr agent_id 1595 ret long AS_ERR_AGENT_NOT_FOUND 1596 end 1597 as_snap_clear 1598 put as_snap_inc 0 get as_mgr_inc mgr 1599 put as_snap_agent_cnt 0 1 1600 for i ulong 32 1601 put as_snap_agents i get agent_id i 1602 end 1603 bcnt = get as_mgr_branch_cnt mgr 1604 mcnt = ulong 0 1605 for b ulong bcnt bound 32 1606 slot = as_br_slot mgr b 1607 if as_br_matches_agent slot agent_id 1608 put as_val_order mcnt slot 1609 mcnt = add mcnt 1 1610 end 1611 end 1612 as_sort_val_order_br mcnt 1613 put as_snap_branch_cnt 0 mcnt 1614 for k ulong mcnt bound 32 1615 as_br_to_snap k get as_val_order k 1616 end 1617 ret as_seal_snapshot dst_buf 1618 end 1619 1620 fn as_mgr_checkpoint mgr ulong agent_id view uchar * dst_hash edit uchar * to int 1621 tmp = new uchar 65536 0 1622 n = as_mgr_export_checkpoint mgr agent_id tmp 1623 if lt n 0 1624 ret int n 1625 end 1626 for i ulong 32 1627 put dst_hash i get tmp add 8 i 1628 end 1629 ret AS_OK 1630 end 1631 1632 note === Restore validation helpers (exact Rust order) === 1633 1634 fn as_snap_has_agent agent_id view uchar * limit ulong to bool 1635 for a ulong limit bound 8 1636 aoff = mul a 32 1637 same = true 1638 for i ulong 32 1639 if ne get as_snap_agents add aoff i get agent_id i 1640 same = false 1641 end 1642 end 1643 if same 1644 ret true 1645 end 1646 end 1647 ret false 1648 end 1649 1650 fn as_val_find_sorted target view uchar * bcnt ulong to long 1651 for i ulong bcnt bound 32 1652 sb = get as_val_order i 1653 off = mul sb 32 1654 same = true 1655 for j ulong 32 1656 if ne get as_snap_br_id add off j get target j 1657 same = false 1658 end 1659 end 1660 if same 1661 ret long i 1662 end 1663 end 1664 ret -1 1665 end 1666 1667 fn as_val_agents_and_branches to int 1668 acnt = get as_snap_agent_cnt 0 1669 if eq acnt 0 1670 ret AS_ERR_CKPT_NO_AGENT 1671 end 1672 aid = new uchar 32 0 1673 for a ulong acnt bound 8 1674 aoff = mul a 32 1675 for i ulong 32 1676 put aid i get as_snap_agents add aoff i 1677 end 1678 if as_snap_has_agent aid a 1679 ret AS_ERR_CKPT_DUP_AGENT 1680 end 1681 end 1682 bcnt = get as_snap_branch_cnt 0 1683 for sb ulong bcnt bound 32 1684 boff = mul sb 32 1685 for i ulong 32 1686 put aid i get as_snap_br_agent_id add boff i 1687 end 1688 if not as_snap_has_agent aid acnt 1689 ret AS_ERR_CKPT_ABSENT_AGENT 1690 end 1691 for prev ulong sb bound 32 1692 if eq as_snap_br_id_cmp prev sb 0 1693 ret AS_ERR_CKPT_DUP_BRANCH 1694 end 1695 end 1696 put as_val_order sb sb 1697 end 1698 note Sort as_val_order ascending by branch_id (matching Rust BTreeMap) 1699 for i ulong bcnt bound 32 1700 for j ulong bcnt bound 32 1701 if lt add j 1 bcnt 1702 s1 = get as_val_order j 1703 s2 = get as_val_order add j 1 1704 if gt as_snap_br_id_cmp s1 s2 0 1705 put as_val_order j s2 1706 put as_val_order add j 1 s1 1707 end 1708 end 1709 end 1710 end 1711 ret AS_OK 1712 end 1713 1714 fn as_val_one_root a ulong bcnt ulong to int 1715 aid = new uchar 32 0 1716 rid = new uchar 32 0 1717 aoff = mul a 32 1718 for i ulong 32 1719 put aid i get as_snap_agents add aoff i 1720 end 1721 as_branch_id_root aid rid 1722 rpos = as_val_find_sorted rid bcnt 1723 if lt rpos 0 1724 ret AS_ERR_CKPT_MISSING_ROOT 1725 end 1726 rsb = get as_val_order ulong rpos 1727 roff = mul rsb 32 1728 for i ulong 32 1729 if ne get as_snap_br_agent_id add roff i get aid i 1730 ret AS_ERR_CKPT_INCONSISTENT_ROOT 1731 end 1732 if ne get as_snap_br_lin_root add roff i get aid i 1733 ret AS_ERR_CKPT_INCONSISTENT_ROOT 1734 end 1735 end 1736 if ne get as_snap_br_has_parent rsb 0 1737 ret AS_ERR_CKPT_INCONSISTENT_ROOT 1738 end 1739 if ne get as_snap_br_lin_depth rsb 0 1740 ret AS_ERR_CKPT_INCONSISTENT_ROOT 1741 end 1742 if ne get as_snap_br_lin_cnt rsb 0 1743 ret AS_ERR_CKPT_INCONSISTENT_ROOT 1744 end 1745 ret AS_OK 1746 end 1747 1748 fn as_val_roots to int 1749 acnt = get as_snap_agent_cnt 0 1750 bcnt = get as_snap_branch_cnt 0 1751 for a ulong acnt bound 8 1752 rc = as_val_one_root a bcnt 1753 if ne rc AS_OK 1754 ret rc 1755 end 1756 end 1757 ret AS_OK 1758 end 1759 1760 fn as_val_child_anc_eq sb ulong psb ulong k ulong to bool 1761 boff = add mul sb mul AS_MAX_DEPTH 32 mul k 32 1762 poff = add mul psb mul AS_MAX_DEPTH 32 mul k 32 1763 for j ulong 32 1764 if ne get as_snap_br_lin_anc add boff j get as_snap_br_lin_anc add poff j 1765 ret false 1766 end 1767 end 1768 ret true 1769 end 1770 1771 fn as_val_child_lineage sb ulong psb ulong to int 1772 boff = mul sb 32 1773 poff = mul psb 32 1774 for i ulong 32 1775 if ne get as_snap_br_agent_id add boff i get as_snap_br_agent_id add poff i 1776 ret AS_ERR_CKPT_INCONSISTENT_LINEAGE 1777 end 1778 if ne get as_snap_br_lin_root add boff i get as_snap_br_lin_root add poff i 1779 ret AS_ERR_CKPT_INCONSISTENT_LINEAGE 1780 end 1781 end 1782 pdepth = get as_snap_br_lin_depth psb 1783 if eq pdepth 0xffffffffffffffff 1784 ret AS_ERR_CKPT_INCONSISTENT_LINEAGE 1785 end 1786 if ne get as_snap_br_lin_depth sb add pdepth 1 1787 ret AS_ERR_CKPT_INCONSISTENT_LINEAGE 1788 end 1789 pcnt = get as_snap_br_lin_cnt psb 1790 if ne get as_snap_br_lin_cnt sb add pcnt 1 1791 ret AS_ERR_CKPT_INCONSISTENT_LINEAGE 1792 end 1793 for k ulong pcnt bound 16 1794 if not as_val_child_anc_eq sb psb k 1795 ret AS_ERR_CKPT_INCONSISTENT_LINEAGE 1796 end 1797 end 1798 last_off = add mul sb mul AS_MAX_DEPTH 32 mul pcnt 32 1799 for j ulong 32 1800 if ne get as_snap_br_lin_anc add last_off j get as_snap_br_id add boff j 1801 ret AS_ERR_CKPT_INCONSISTENT_LINEAGE 1802 end 1803 end 1804 ret AS_OK 1805 end 1806 1807 fn as_val_one_branch i ulong bcnt ulong to int 1808 sb = get as_val_order i 1809 off = mul sb 32 1810 tmp = new uchar 32 0 1811 exp = new uchar 32 0 1812 if eq get as_snap_br_has_parent sb 0 1813 for j ulong 32 1814 put tmp j get as_snap_br_agent_id add off j 1815 end 1816 as_branch_id_root tmp exp 1817 for j ulong 32 1818 if ne get as_snap_br_id add off j get exp j 1819 ret AS_ERR_CKPT_UNEXPECTED_ROOT 1820 end 1821 end 1822 ret AS_OK 1823 end 1824 for j ulong 32 1825 put tmp j get as_snap_br_parent_id add off j 1826 end 1827 ppos = as_val_find_sorted tmp bcnt 1828 if lt ppos 0 1829 ret AS_ERR_CKPT_MISSING_PARENT 1830 end 1831 psb = get as_val_order ulong ppos 1832 rc = as_val_child_lineage sb psb 1833 if ne rc AS_OK 1834 ret rc 1835 end 1836 put as_val_child_cnt ulong ppos add get as_val_child_cnt ulong ppos 1 1837 ret AS_OK 1838 end 1839 1840 fn as_val_parents_and_lineage to int 1841 bcnt = get as_snap_branch_cnt 0 1842 for i ulong bcnt bound 32 1843 put as_val_child_cnt i 0 1844 end 1845 for i ulong bcnt bound 32 1846 rc = as_val_one_branch i bcnt 1847 if ne rc AS_OK 1848 ret rc 1849 end 1850 end 1851 ret AS_OK 1852 end 1853 1854 fn as_val_one_fork pid view uchar * cidx ulong bcnt ulong to int 1855 cid = new uchar 32 0 1856 as_branch_id_derive pid cidx cid 1857 cpos = as_val_find_sorted cid bcnt 1858 if lt cpos 0 1859 ret AS_ERR_CKPT_NONCONTIGUOUS_FORK 1860 end 1861 csb = get as_val_order ulong cpos 1862 if eq get as_snap_br_has_parent csb 0 1863 ret AS_ERR_CKPT_NONCONTIGUOUS_FORK 1864 end 1865 coff = mul csb 32 1866 for j ulong 32 1867 if ne get as_snap_br_parent_id add coff j get pid j 1868 ret AS_ERR_CKPT_NONCONTIGUOUS_FORK 1869 end 1870 end 1871 ret AS_OK 1872 end 1873 1874 fn as_val_parent_forks i ulong bcnt ulong to int 1875 ccnt = get as_val_child_cnt i 1876 if eq ccnt 0 1877 ret AS_OK 1878 end 1879 pid = new uchar 32 0 1880 psb = get as_val_order i 1881 poff = mul psb 32 1882 for j ulong 32 1883 put pid j get as_snap_br_id add poff j 1884 end 1885 for cidx ulong ccnt bound 32 1886 rc = as_val_one_fork pid cidx bcnt 1887 if ne rc AS_OK 1888 ret rc 1889 end 1890 end 1891 ret AS_OK 1892 end 1893 1894 fn as_val_contiguous_forks to int 1895 bcnt = get as_snap_branch_cnt 0 1896 for i ulong bcnt bound 32 1897 rc = as_val_parent_forks i bcnt 1898 if ne rc AS_OK 1899 ret rc 1900 end 1901 end 1902 ret AS_OK 1903 end 1904 1905 fn as_mgr_commit_snap_agents mgr ulong to void 1906 acnt = get as_snap_agent_cnt 0 1907 put as_mgr_agent_cnt mgr acnt 1908 mabase = mul mgr mul AS_MAX_AGENTS 32 1909 for a ulong acnt bound 8 1910 aoff = mul a 32 1911 doff = add mabase aoff 1912 for j ulong 32 1913 put as_mgr_agents add doff j get as_snap_agents add aoff j 1914 end 1915 end 1916 end 1917 1918 fn as_mgr_restore_from_checkpoint mgr ulong ckpt view uchar * ckpt_len ulong new_inc ulong to int 1919 rc = as_decode_checkpoint_to_snap ckpt ckpt_len 1920 if ne rc AS_OK 1921 ret rc 1922 end 1923 rc = as_val_agents_and_branches 1924 if ne rc AS_OK 1925 ret rc 1926 end 1927 rc = as_val_roots 1928 if ne rc AS_OK 1929 ret rc 1930 end 1931 rc = as_val_parents_and_lineage 1932 if ne rc AS_OK 1933 ret rc 1934 end 1935 rc = as_val_contiguous_forks 1936 if ne rc AS_OK 1937 ret rc 1938 end 1939 as_mgr_init mgr new_inc 1940 as_mgr_commit_snap_agents mgr 1941 bcnt = get as_snap_branch_cnt 0 1942 put as_mgr_branch_cnt mgr bcnt 1943 for i ulong bcnt bound 32 1944 sb = get as_val_order i 1945 slot = as_br_slot mgr i 1946 as_snap_to_br slot sb 1947 put as_br_child_cnt slot get as_val_child_cnt i 1948 seq = get as_mgr_next_seq mgr 1949 put as_mgr_next_seq mgr add seq 1 1950 as_br_inc_init slot new_inc seq 1951 as_br_inc_evict slot 1952 end 1953 ret AS_OK 1954 end 1955 1956 note === Deep equality helper comparing a branch slot with a snapshot branch === 1957 1958 fn as_br_eq_snap_tok slot ulong sb ulong k ulong to bool 1959 bt = add mul slot AS_MAX_TOKENS k 1960 st = add mul sb AS_MAX_TOKENS k 1961 if ne get as_br_tok_seq bt get as_snap_br_tok_seq st 1962 ret false 1963 end 1964 if ne get as_br_tok_id bt get as_snap_br_tok_id st 1965 ret false 1966 end 1967 bh = mul bt 32 1968 sh = mul st 32 1969 for j ulong 32 1970 if ne get as_br_tok_hash add bh j get as_snap_br_tok_hash add sh j 1971 ret false 1972 end 1973 end 1974 ret true 1975 end 1976 1977 fn as_br_eq_snap_hist slot ulong sb ulong to bool 1978 tcnt = get as_br_tok_cnt slot 1979 if ne tcnt get as_snap_br_tok_cnt sb 1980 ret false 1981 end 1982 bo = mul slot 32 1983 so = mul sb 32 1984 for i ulong 32 1985 if ne get as_br_rhash add bo i get as_snap_br_rhash add so i 1986 ret false 1987 end 1988 end 1989 for k ulong tcnt bound 64 1990 if not as_br_eq_snap_tok slot sb k 1991 ret false 1992 end 1993 end 1994 ret true 1995 end 1996 1997 fn as_br_eq_snap_lin_one slot ulong sb ulong k ulong to bool 1998 boff = add mul slot mul AS_MAX_DEPTH 32 mul k 32 1999 soff = add mul sb mul AS_MAX_DEPTH 32 mul k 32 2000 for j ulong 32 2001 if ne get as_br_lin_anc add boff j get as_snap_br_lin_anc add soff j 2002 ret false 2003 end 2004 end 2005 ret true 2006 end 2007 2008 fn as_br_eq_snap_lin slot ulong sb ulong to bool 2009 bo = mul slot 32 2010 so = mul sb 32 2011 for i ulong 32 2012 if ne get as_br_lin_root add bo i get as_snap_br_lin_root add so i 2013 ret false 2014 end 2015 end 2016 if ne get as_br_lin_depth slot get as_snap_br_lin_depth sb 2017 ret false 2018 end 2019 lcnt = get as_br_lin_cnt slot 2020 if ne lcnt get as_snap_br_lin_cnt sb 2021 ret false 2022 end 2023 for k ulong lcnt bound 16 2024 if not as_br_eq_snap_lin_one slot sb k 2025 ret false 2026 end 2027 end 2028 ret true 2029 end 2030 2031 fn as_br_eq_snap_epi_one slot ulong sb ulong k ulong to bool 2032 boff = add mul slot mul AS_MAX_EPISTEMIC 16 mul k 16 2033 soff = add mul sb mul AS_MAX_EPISTEMIC 16 mul k 16 2034 for j ulong 16 2035 if ne get as_br_epi_ids add boff j get as_snap_br_epi_ids add soff j 2036 ret false 2037 end 2038 end 2039 ret true 2040 end 2041 2042 fn as_br_eq_snap_epi slot ulong sb ulong to bool 2043 ecnt = get as_br_epi_cnt slot 2044 if ne ecnt get as_snap_br_epi_cnt sb 2045 ret false 2046 end 2047 for k ulong ecnt bound 8 2048 if not as_br_eq_snap_epi_one slot sb k 2049 ret false 2050 end 2051 end 2052 ret true 2053 end 2054 2055 fn as_br_eq_snap_lin_epi slot ulong sb ulong to bool 2056 if not as_br_eq_snap_lin slot sb 2057 ret false 2058 end 2059 ret as_br_eq_snap_epi slot sb 2060 end 2061 2062 fn as_br_eq_snap slot ulong sb ulong to bool 2063 if ne get as_br_has_parent slot get as_snap_br_has_parent sb 2064 ret false 2065 end 2066 if ne get as_br_created_at slot get as_snap_br_created_at sb 2067 ret false 2068 end 2069 bo = mul slot 32 2070 so = mul sb 32 2071 for i ulong 32 2072 if ne get as_br_id add bo i get as_snap_br_id add so i 2073 ret false 2074 end 2075 if ne get as_br_parent_id add bo i get as_snap_br_parent_id add so i 2076 ret false 2077 end 2078 if ne get as_br_agent_id add bo i get as_snap_br_agent_id add so i 2079 ret false 2080 end 2081 end 2082 if not as_br_eq_snap_hist slot sb 2083 ret false 2084 end 2085 ret as_br_eq_snap_lin_epi slot sb 2086 end