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
omega-mv / tools / r16_loop_inventory.om
| 1 | om2 |
| 2 | note SPDX-License-Identifier: Apache-2.0 |
| 3 | note Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 4 | note |
| 5 | note r16_loop_inventory.om -- R16-G2 code-search gate in pure seeded OM-2. |
| 6 | note Replaces tools/r16_loop_inventory.c with byte-for-byte CLI/JSON/stderr parity. |
| 7 | |
| 8 | const NREPO ulong 5 |
| 9 | const NCLASS ulong 8 |
| 10 | const MAX_SITES ulong 16384 |
| 11 | const MAX_ROWS ulong 8192 |
| 12 | |
| 13 | note ---- static texts ---- |
| 14 | text t_git "/usr/bin/git" |
| 15 | text t_dashC "-C" |
| 16 | text t_revparse "rev-parse" |
| 17 | text t_HEAD "HEAD" |
| 18 | text t_lsfiles "ls-files" |
| 19 | text t_dashz "-z" |
| 20 | text t_dashdash "--" |
| 21 | text t_glob_c "*.c" |
| 22 | text t_glob_h "*.h" |
| 23 | text t_glob_rs "*.rs" |
| 24 | text t_devnull "/dev/null" |
| 25 | |
| 26 | text t_r0 "omega" |
| 27 | text t_r1 "aien-sovereign-core" |
| 28 | text t_r2 "aegis-runtime" |
| 29 | text t_r3 "aienos" |
| 30 | text t_r4 "physics" |
| 31 | |
| 32 | text t_e0 "R16_REPO_OMEGA" |
| 33 | text t_e1 "R16_REPO_SOVEREIGN_CORE" |
| 34 | text t_e2 "R16_REPO_AEGIS_RUNTIME" |
| 35 | text t_e3 "R16_REPO_AIENOS" |
| 36 | text t_e4 "R16_REPO_PHYSICS" |
| 37 | text t_env_map "R16_MAP" |
| 38 | text t_env_home "HOME" |
| 39 | |
| 40 | text t_defmap "spec/r16-orchestrator-retirement-map.md" |
| 41 | text t_dot "." |
| 42 | text t_dash "-" |
| 43 | text t_qmark "?" |
| 44 | text t_eq "=" |
| 45 | text t_slash "/" |
| 46 | text t_ws_survey "/workspace/r16-survey/" |
| 47 | text t_rs ".rs" |
| 48 | |
| 49 | text t_ex0 "vendor/" |
| 50 | text t_ex1 "third_party/" |
| 51 | text t_ex2 "tests/r16_inventory/" |
| 52 | |
| 53 | text t_fl_pat "--patterns" |
| 54 | text t_fl_skel "--skeleton" |
| 55 | text t_fl_map "--map" |
| 56 | text t_fl_json "--json" |
| 57 | |
| 58 | text t_usage "usage: r16_loop_inventory [--map FILE] [--json FILE] [--skeleton] [--patterns]\nenv: R16_MAP R16_REPO_OMEGA R16_REPO_SOVEREIGN_CORE R16_REPO_AEGIS_RUNTIME\n R16_REPO_AIENOS R16_REPO_PHYSICS\n" |
| 59 | |
| 60 | text t_die_pfx "r16_loop_inventory: " |
| 61 | text t_die_gitls "git ls-files failed in " |
| 62 | text t_die_map "cannot open map " |
| 63 | text t_die_write "cannot write " |
| 64 | text t_die_pipe "pipe failed" |
| 65 | text t_die_fork "fork failed" |
| 66 | text t_die_read "cannot read " |
| 67 | text t_die_oom "out of memory" |
| 68 | |
| 69 | text t_bw_sleep "sleep" |
| 70 | text t_bw_usleep "usleep" |
| 71 | text t_bw_nanosleep "nanosleep" |
| 72 | text t_bw_msleep "msleep" |
| 73 | text t_bw_poll "poll" |
| 74 | text t_bw_recv "recv" |
| 75 | text t_bw_heartbeat "heartbeat" |
| 76 | text t_bw_tick "tick" |
| 77 | text t_bw_dispatch "dispatch" |
| 78 | text t_bw_schedule "schedule" |
| 79 | text t_bw_scheduler "scheduler" |
| 80 | text t_bw_sched "sched" |
| 81 | text t_bw_orchestrate "orchestrate" |
| 82 | text t_bw_orchestrator "orchestrator" |
| 83 | text t_bw_orchestration "orchestration" |
| 84 | text t_bw_turn "turn" |
| 85 | text t_bw_turns "turns" |
| 86 | text t_bw_pulse "pulse" |
| 87 | text t_bw_yield "yield" |
| 88 | text t_bw_epoll "epoll" |
| 89 | text t_bw_wait "wait" |
| 90 | text t_bw_step "step" |
| 91 | text t_bw_steps "steps" |
| 92 | |
| 93 | text t_nm0 "rununtilcomplete" |
| 94 | text t_nm1 "maxsteps" |
| 95 | text t_nm2 "maxturns" |
| 96 | text t_ns0 "run_until_complete" |
| 97 | text t_ns1 "max_steps" |
| 98 | text t_ns2 "max_turns" |
| 99 | text t_named_pfx "named:" |
| 100 | |
| 101 | text t_kw_while "while" |
| 102 | text t_kw_for "for" |
| 103 | text t_kw_loop "loop" |
| 104 | text t_kw_do "do" |
| 105 | text t_cond_1 "1" |
| 106 | text t_cond_true "true" |
| 107 | text t_cond_not0 "!0" |
| 108 | text t_cond_semi ";;" |
| 109 | text t_unb ":unbounded" |
| 110 | text t_unb_plus ":unbounded+" |
| 111 | text t_body_col ":body:" |
| 112 | text t_climode "cli-mode" |
| 113 | text t_argvb "argv[" |
| 114 | text t_cli_dem "\"--demonstrate-" |
| 115 | text t_cli_ref "\"--reference-" |
| 116 | text t_cli_run "\"--run-" |
| 117 | |
| 118 | text t_m_shas "<!-- r16-inventory:shas -->" |
| 119 | text t_m_rows "<!-- r16-inventory:rows -->" |
| 120 | text t_m_end "<!-- /r16-inventory" |
| 121 | text t_m_sep "---|" |
| 122 | text t_m_hdr1 "| id |" |
| 123 | text t_m_hdr2 "| repo | sha" |
| 124 | text t_manual "manual" |
| 125 | text t_legacy_oracle "legacy_oracle" |
| 126 | text t_reference "reference" |
| 127 | |
| 128 | text t_id0 "cas" |
| 129 | text t_id1 "seqlock" |
| 130 | text t_id2 "probe" |
| 131 | text t_id3 "parse" |
| 132 | text t_id4 "walk" |
| 133 | text t_id5 "read" |
| 134 | text t_id6 "arithmetic" |
| 135 | text t_id7 "sift" |
| 136 | text t_id8 "sample" |
| 137 | text t_id9 "merge" |
| 138 | text t_id10 "retry" |
| 139 | text t_id11 "format" |
| 140 | text t_id12 "bpe" |
| 141 | text t_id13 "utf8" |
| 142 | text t_id14 "token" |
| 143 | text t_id15 "decode" |
| 144 | text t_id16 "scan" |
| 145 | |
| 146 | text t_pat_text "R16 loop inventory patterns (tools/r16_loop_inventory.c)\nfiles: git ls-files '*.c' '*.h' '*.rs' (tracked only); excluded path prefixes: vendor/ third_party/ tests/r16_inventory/ (vendor/ and third_party/ also at any depth)\ncomments and string/char literal contents blanked before matching\nloop heads: C while( for( do{ ; Rust while, for..in, loop{ ; C do-while tails not double-counted\nunbounded: while(1) while(true) while(!0) for(;;) Rust loop{} Rust while true\nbody words (identifier words, split at _ digits and case): sleep usleep nanosleep msleep poll recv heartbeat tick dispatch schedule scheduler orchestrate orchestrator turn turns pulse yield epoll\nflagged loop = unbounded OR a body word in condition or body\nnamed terms (any code line; case/underscore-insensitive; run_until_complete anywhere in an identifier, max_steps and max_turns only as the whole identifier; hit counts use substring): run_until_complete max_steps max_turns\ncli-mode (C): a code line testing argv[ against a \"--demonstrate-...\", \"--reference-...\" or \"--run-...\" literal\nmanual rows (line cell starts with \"manual\"): evidence line must still exist in the file\n (symbol not verified); same class rules apply\njoin key: repo + path + enclosing symbol + whitespace-collapsed source line\nclass-A reachability (omega only, naming proxy; G3 checks the link map): path or symbol must contain legacy_oracle or reference\nclass N (not a central loop): data/control-flow idiom; reason must name allowed idiom; body must not contain wait words\n" |
| 147 | |
| 148 | text t_skel_hdr "| id | repo | path | line | symbol | old role | new role | class | authoritative | reason | evidence |\n|---|---|---|---|---|---|---|---|---|---|---|\n" |
| 149 | text t_new "NEW" |
| 150 | text t_pipe_sp " | " |
| 151 | text t_sp_pipe "| " |
| 152 | text t_pipe_nl " |\n" |
| 153 | text t_bt1 "`" |
| 154 | text t_bt2_l "`` " |
| 155 | text t_bt2_r " ``" |
| 156 | text t_esc_pipe "\\|" |
| 157 | |
| 158 | text t_json_p1 "{\n \"schema\": \"AIEN_R16_LOOP_INVENTORY_V1\",\n \"map\": " |
| 159 | text t_json_p2 ",\n \"repos\": [\n" |
| 160 | text t_json_r1 " {\"name\": \"" |
| 161 | text t_json_r2 "\", \"path\": " |
| 162 | text t_json_r3 ", \"head\": " |
| 163 | text t_json_r4 ", \"map_sha\": " |
| 164 | text t_json_r5 ", \"status\": \"" |
| 165 | text t_json_r6 "\", \"sites_by_class\": {" |
| 166 | text t_json_r7 "}, \"term_hits\": {" |
| 167 | text t_json_s0 " ],\n \"sites\": [\n" |
| 168 | text t_json_s1 " {\"repo\": \"" |
| 169 | text t_json_s2 "\", \"path\": " |
| 170 | text t_json_s3 ", \"lines\": \"" |
| 171 | text t_json_s4 "\", \"symbol\": " |
| 172 | text t_json_s5 ", \"trigger\": " |
| 173 | text t_json_s6 ", \"row\": " |
| 174 | text t_json_s7 ", \"class\": " |
| 175 | text t_json_s8 ", \"authoritative\": " |
| 176 | text t_json_s9 ", \"evidence\": " |
| 177 | text t_json_f1 " ],\n \"manual_rows\": " |
| 178 | text t_json_f2 ",\n \"sites_total\": " |
| 179 | text t_json_f3 ",\n \"unclassified\": " |
| 180 | text t_json_f4 ",\n \"question_rows\": " |
| 181 | text t_json_f5 ",\n \"bad_class\": " |
| 182 | text t_json_f6 ",\n \"a_reachable\": " |
| 183 | text t_json_f7 ",\n \"stale_rows\": " |
| 184 | text t_json_f8 ",\n \"map_errors\": " |
| 185 | text t_json_f9 ",\n \"skipped_repos\": " |
| 186 | text t_json_f10 ",\n \"class_n_sites\": " |
| 187 | text t_json_f11 ",\n \"result\": \"" |
| 188 | text t_json_f12 "\"\n}\n" |
| 189 | |
| 190 | text t_SKIPPED "SKIPPED" |
| 191 | text t_SCANNED "SCANNED" |
| 192 | text t_PASS "PASS" |
| 193 | text t_FAIL "FAIL" |
| 194 | text t_hex "0123456789abcdef" |
| 195 | text t_cls_chars "ABCDEFN?" |
| 196 | text t_empty "" |
| 197 | |
| 198 | text t_e_scanned "SCANNED " |
| 199 | text t_e_head " HEAD " |
| 200 | text t_e_skipped "SKIPPED " |
| 201 | text t_e_nogit ": no git work tree at " |
| 202 | text t_e_set " (set " |
| 203 | text t_e_notpass "). Skipping is NOT a pass.\n" |
| 204 | text t_e_warn "WARN " |
| 205 | text t_e_warn2 ": scanned HEAD " |
| 206 | text t_e_warn3 " differs from map SHA " |
| 207 | text t_e_maperr "MAP-ERROR line " |
| 208 | text t_e_maperr2 ": row has " |
| 209 | text t_e_maperr3 " cells, need 11\n" |
| 210 | text t_e_mapunk ": unknown repo '" |
| 211 | text t_e_mapdup "MAP-ERROR duplicate rows " |
| 212 | text t_e_and " and " |
| 213 | text t_e_uncls "UNCLASSIFIED " |
| 214 | text t_e_quest "QUESTION " |
| 215 | text t_e_badcls "BAD-CLASS " |
| 216 | text t_e_nnoid "N-NO-IDIOM " |
| 217 | text t_e_nnoid2 ": reason lacks required idiom word\n" |
| 218 | text t_e_nnoid_m " (manual): reason lacks required idiom word\n" |
| 219 | text t_e_nwait "N-WAIT-WORD " |
| 220 | text t_e_nwait2 "] contains wait word in body\n" |
| 221 | text t_e_areach "A-REACHABLE " |
| 222 | text t_e_areach2 "] class A still under a production name\n" |
| 223 | text t_e_areach_m "] (manual) class A still under a production name\n" |
| 224 | text t_e_retgone "RETIRED-GONE " |
| 225 | text t_e_retgone2 " (class A site no longer present)\n" |
| 226 | text t_e_stale "STALE " |
| 227 | text t_e_manual_sp " (manual) :: " |
| 228 | text t_e_colcol " :: " |
| 229 | text t_e_omega_sp " omega " |
| 230 | text t_e_sum1 "R16 loop inventory: sites=" |
| 231 | text t_e_sum2 " unclassified=" |
| 232 | text t_e_sum3 " question=" |
| 233 | text t_e_sum4 " bad_class=" |
| 234 | text t_e_sum5 " a_reachable=" |
| 235 | text t_e_sum6 " stale=" |
| 236 | text t_e_sum7 " map_errors=" |
| 237 | text t_e_sum8 " skipped=" |
| 238 | text t_e_sum9 " -> " |
| 239 | |
| 240 | note ---- globals ---- |
| 241 | global sp uchar * |
| 242 | global sp_len ulong 1 |
| 243 | global sp_cap ulong 1 |
| 244 | |
| 245 | global obuf uchar 65536 |
| 246 | global olen ulong 1 |
| 247 | global ofd int 1 |
| 248 | global ebuf uchar 65536 |
| 249 | global elen ulong 1 |
| 250 | |
| 251 | global st_repo ulong 16384 |
| 252 | global st_po ulong 16384 |
| 253 | global st_pl ulong 16384 |
| 254 | global st_so ulong 16384 |
| 255 | global st_sl ulong 16384 |
| 256 | global st_eo ulong 16384 |
| 257 | global st_el ulong 16384 |
| 258 | global st_to ulong 16384 |
| 259 | global st_tl ulong 16384 |
| 260 | global st_lo ulong 16384 |
| 261 | global st_ll ulong 16384 |
| 262 | global st_fline ulong 16384 |
| 263 | global st_cnt ulong 16384 |
| 264 | global st_row long 16384 |
| 265 | global nsites ulong 1 |
| 266 | |
| 267 | global rw_off ulong 90112 |
| 268 | global rw_len ulong 90112 |
| 269 | global rw_ridx long 8192 |
| 270 | global rw_hits ulong 8192 |
| 271 | global nrows ulong 1 |
| 272 | global map_err ulong 1 |
| 273 | |
| 274 | global defp_o ulong 5 |
| 275 | global defp_l ulong 5 |
| 276 | global head_o ulong 5 |
| 277 | global head_l ulong 5 |
| 278 | global msha_o ulong 5 |
| 279 | global msha_l ulong 5 |
| 280 | global rskip ulong 5 |
| 281 | global thits ulong 160 |
| 282 | global nhits ulong 40 |
| 283 | global percls ulong 40 |
| 284 | |
| 285 | global orig uchar * |
| 286 | global orig_cap ulong 1 |
| 287 | global stripped uchar * |
| 288 | global strip_cap ulong 1 |
| 289 | global lstarts ulong * |
| 290 | global ls_cap ulong 1 |
| 291 | global sym_o ulong * |
| 292 | global sym_l ulong * |
| 293 | global sym_cap ulong 1 |
| 294 | |
| 295 | global gitout uchar * |
| 296 | global gitout_cap ulong 1 |
| 297 | global flist_o ulong * |
| 298 | global flist_l ulong * |
| 299 | global flist_cap ulong 1 |
| 300 | |
| 301 | global tmp1 uchar 8192 |
| 302 | global tmp2 uchar 8192 |
| 303 | global wbuf uchar 640 |
| 304 | global wlen ulong 16 |
| 305 | global pkt uchar 16384 |
| 306 | global mapbuf uchar * |
| 307 | global mapbuf_cap ulong 1 |
| 308 | global mcells_o ulong 16 |
| 309 | global mcells_l ulong 16 |
| 310 | global mrow_tmp uchar 16384 |
| 311 | |
| 312 | note ---- buffered I/O ---- |
| 313 | fn write_all fd int is_err ulong n ulong to void |
| 314 | off = ulong 0 |
| 315 | while lt off n bound 1000000000 |
| 316 | k = long 0 |
| 317 | if eq is_err 0 |
| 318 | k = write fd obuf off sub n off |
| 319 | else |
| 320 | k = write fd ebuf off sub n off |
| 321 | end |
| 322 | if le k 0 |
| 323 | break |
| 324 | end |
| 325 | off = add off ulong k |
| 326 | end |
| 327 | end |
| 328 | |
| 329 | fn oflush to void |
| 330 | n = get olen 0 |
| 331 | if gt n 0 |
| 332 | write_all get ofd 0 0 n |
| 333 | put olen 0 0 |
| 334 | end |
| 335 | end |
| 336 | |
| 337 | fn eflush to void |
| 338 | n = get elen 0 |
| 339 | if gt n 0 |
| 340 | write_all int 2 1 n |
| 341 | put elen 0 0 |
| 342 | end |
| 343 | end |
| 344 | |
| 345 | fn oputc c uchar to void |
| 346 | n = get olen 0 |
| 347 | if ge n 65536 |
| 348 | oflush |
| 349 | n = 0 |
| 350 | end |
| 351 | put obuf n c |
| 352 | put olen 0 add n 1 |
| 353 | end |
| 354 | |
| 355 | fn eputc c uchar to void |
| 356 | n = get elen 0 |
| 357 | if ge n 65536 |
| 358 | eflush |
| 359 | n = 0 |
| 360 | end |
| 361 | put ebuf n c |
| 362 | put elen 0 add n 1 |
| 363 | end |
| 364 | |
| 365 | fn oput_t t view uchar * to void |
| 366 | n = len t |
| 367 | for i ulong n bound 4096 |
| 368 | oputc get t i |
| 369 | end |
| 370 | end |
| 371 | |
| 372 | fn eput_t t view uchar * to void |
| 373 | n = len t |
| 374 | for i ulong n bound 4096 |
| 375 | eputc get t i |
| 376 | end |
| 377 | end |
| 378 | |
| 379 | fn oput_sp off ulong n ulong to void |
| 380 | for i ulong n bound 1000000000 |
| 381 | oputc get sp add off i |
| 382 | end |
| 383 | end |
| 384 | |
| 385 | fn eput_sp off ulong n ulong to void |
| 386 | for i ulong n bound 1000000000 |
| 387 | eputc get sp add off i |
| 388 | end |
| 389 | end |
| 390 | |
| 391 | fn oput_u v ulong to void |
| 392 | d = new uchar 24 0 |
| 393 | k = ulong 0 |
| 394 | x = v |
| 395 | while true bound 24 |
| 396 | put d k uchar add 48 rem x 10 |
| 397 | k = add k 1 |
| 398 | x = div x 10 |
| 399 | if eq x 0 |
| 400 | break |
| 401 | end |
| 402 | end |
| 403 | while gt k 0 bound 24 |
| 404 | k = sub k 1 |
| 405 | oputc get d k |
| 406 | end |
| 407 | end |
| 408 | |
| 409 | fn eput_u v ulong to void |
| 410 | d = new uchar 24 0 |
| 411 | k = ulong 0 |
| 412 | x = v |
| 413 | while true bound 24 |
| 414 | put d k uchar add 48 rem x 10 |
| 415 | k = add k 1 |
| 416 | x = div x 10 |
| 417 | if eq x 0 |
| 418 | break |
| 419 | end |
| 420 | end |
| 421 | while gt k 0 bound 24 |
| 422 | k = sub k 1 |
| 423 | eputc get d k |
| 424 | end |
| 425 | end |
| 426 | |
| 427 | fn die_t msg view uchar * to void |
| 428 | eflush |
| 429 | eput_t t_die_pfx |
| 430 | eput_t msg |
| 431 | eputc 10 |
| 432 | eflush |
| 433 | exit 2 |
| 434 | end |
| 435 | |
| 436 | fn die_sp msg view uchar * off ulong n ulong to void |
| 437 | eflush |
| 438 | eput_t t_die_pfx |
| 439 | eput_t msg |
| 440 | eput_sp off n |
| 441 | eputc 10 |
| 442 | eflush |
| 443 | exit 2 |
| 444 | end |
| 445 | |
| 446 | note ---- string pool ---- |
| 447 | fn sp_reserve need ulong to void |
| 448 | cur = get sp_len 0 |
| 449 | cap = get sp_cap 0 |
| 450 | if le add cur need cap |
| 451 | ret |
| 452 | end |
| 453 | ncap = cap |
| 454 | if eq ncap 0 |
| 455 | ncap = 4194304 |
| 456 | end |
| 457 | while lt ncap add cur need bound 64 |
| 458 | ncap = mul ncap 2 |
| 459 | end |
| 460 | r = enlarge sp ncap |
| 461 | if lt r 0 |
| 462 | die_t t_die_oom |
| 463 | end |
| 464 | put sp_cap 0 ncap |
| 465 | end |
| 466 | |
| 467 | fn sp_add_t t view uchar * to ulong |
| 468 | n = len t |
| 469 | sp_reserve n |
| 470 | off = get sp_len 0 |
| 471 | for i ulong n bound 1000000000 |
| 472 | put sp add off i get t i |
| 473 | end |
| 474 | put sp_len 0 add off n |
| 475 | ret off |
| 476 | end |
| 477 | |
| 478 | fn sp_add_tmp1 n ulong to ulong |
| 479 | sp_reserve n |
| 480 | off = get sp_len 0 |
| 481 | for i ulong n bound 1000000000 |
| 482 | put sp add off i get tmp1 i |
| 483 | end |
| 484 | put sp_len 0 add off n |
| 485 | ret off |
| 486 | end |
| 487 | |
| 488 | fn sp_add_tmp2 n ulong to ulong |
| 489 | sp_reserve n |
| 490 | off = get sp_len 0 |
| 491 | for i ulong n bound 1000000000 |
| 492 | put sp add off i get tmp2 i |
| 493 | end |
| 494 | put sp_len 0 add off n |
| 495 | ret off |
| 496 | end |
| 497 | |
| 498 | fn sp_add_orig off0 ulong n ulong to ulong |
| 499 | sp_reserve n |
| 500 | off = get sp_len 0 |
| 501 | for i ulong n bound 1000000000 |
| 502 | put sp add off i get orig add off0 i |
| 503 | end |
| 504 | put sp_len 0 add off n |
| 505 | ret off |
| 506 | end |
| 507 | |
| 508 | fn sp_add_git off0 ulong n ulong to ulong |
| 509 | sp_reserve n |
| 510 | off = get sp_len 0 |
| 511 | for i ulong n bound 1000000000 |
| 512 | put sp add off i get gitout add off0 i |
| 513 | end |
| 514 | put sp_len 0 add off n |
| 515 | ret off |
| 516 | end |
| 517 | |
| 518 | fn sp_add_mrow off0 ulong n ulong to ulong |
| 519 | sp_reserve n |
| 520 | off = get sp_len 0 |
| 521 | for i ulong n bound 1000000000 |
| 522 | put sp add off i get mrow_tmp add off0 i |
| 523 | end |
| 524 | put sp_len 0 add off n |
| 525 | ret off |
| 526 | end |
| 527 | |
| 528 | note ---- character classifiers ---- |
| 529 | fn is_alpha c uchar to bool |
| 530 | if ge c 65 |
| 531 | if le c 90 |
| 532 | ret true |
| 533 | end |
| 534 | end |
| 535 | if ge c 97 |
| 536 | if le c 122 |
| 537 | ret true |
| 538 | end |
| 539 | end |
| 540 | ret false |
| 541 | end |
| 542 | |
| 543 | fn is_upper c uchar to bool |
| 544 | if ge c 65 |
| 545 | if le c 90 |
| 546 | ret true |
| 547 | end |
| 548 | end |
| 549 | ret false |
| 550 | end |
| 551 | |
| 552 | fn is_lower c uchar to bool |
| 553 | if ge c 97 |
| 554 | if le c 122 |
| 555 | ret true |
| 556 | end |
| 557 | end |
| 558 | ret false |
| 559 | end |
| 560 | |
| 561 | fn is_digit c uchar to bool |
| 562 | if ge c 48 |
| 563 | if le c 57 |
| 564 | ret true |
| 565 | end |
| 566 | end |
| 567 | ret false |
| 568 | end |
| 569 | |
| 570 | fn is_id c uchar to bool |
| 571 | if is_alpha c |
| 572 | ret true |
| 573 | end |
| 574 | if is_digit c |
| 575 | ret true |
| 576 | end |
| 577 | if eq c 95 |
| 578 | ret true |
| 579 | end |
| 580 | ret false |
| 581 | end |
| 582 | |
| 583 | fn is_space c uchar to bool |
| 584 | if eq c 32 |
| 585 | ret true |
| 586 | end |
| 587 | if ge c 9 |
| 588 | if le c 13 |
| 589 | ret true |
| 590 | end |
| 591 | end |
| 592 | ret false |
| 593 | end |
| 594 | |
| 595 | fn to_lower c uchar to uchar |
| 596 | if is_upper c |
| 597 | ret add c 32 |
| 598 | end |
| 599 | ret c |
| 600 | end |
| 601 | |
| 602 | note ---- string comparisons ---- |
| 603 | fn sp_eq ao ulong al ulong bo ulong bl ulong to bool |
| 604 | if ne al bl |
| 605 | ret false |
| 606 | end |
| 607 | for i ulong al bound 1000000000 |
| 608 | if ne get sp add ao i get sp add bo i |
| 609 | ret false |
| 610 | end |
| 611 | end |
| 612 | ret true |
| 613 | end |
| 614 | |
| 615 | fn sp_eq_t ao ulong al ulong t view uchar * to bool |
| 616 | if ne al len t |
| 617 | ret false |
| 618 | end |
| 619 | for i ulong al bound 1000000000 |
| 620 | if ne get sp add ao i get t i |
| 621 | ret false |
| 622 | end |
| 623 | end |
| 624 | ret true |
| 625 | end |
| 626 | |
| 627 | fn sp_starts_t ao ulong al ulong t view uchar * to bool |
| 628 | tl = len t |
| 629 | if lt al tl |
| 630 | ret false |
| 631 | end |
| 632 | for i ulong tl bound 1000000000 |
| 633 | if ne get sp add ao i get t i |
| 634 | ret false |
| 635 | end |
| 636 | end |
| 637 | ret true |
| 638 | end |
| 639 | |
| 640 | fn sp_ends_t ao ulong al ulong t view uchar * to bool |
| 641 | tl = len t |
| 642 | if lt al tl |
| 643 | ret false |
| 644 | end |
| 645 | base = sub al tl |
| 646 | for i ulong tl bound 1000000000 |
| 647 | if ne get sp add ao add base i get t i |
| 648 | ret false |
| 649 | end |
| 650 | end |
| 651 | ret true |
| 652 | end |
| 653 | |
| 654 | fn sp_has_t ao ulong al ulong t view uchar * to bool |
| 655 | tl = len t |
| 656 | if eq tl 0 |
| 657 | ret true |
| 658 | end |
| 659 | if lt al tl |
| 660 | ret false |
| 661 | end |
| 662 | lim = add sub al tl 1 |
| 663 | for i ulong lim bound 1000000000 |
| 664 | if sp_starts_t add ao i tl t |
| 665 | ret true |
| 666 | end |
| 667 | end |
| 668 | ret false |
| 669 | end |
| 670 | |
| 671 | fn sp_has_sp ao ulong al ulong bo ulong bl ulong to bool |
| 672 | if eq bl 0 |
| 673 | ret true |
| 674 | end |
| 675 | if lt al bl |
| 676 | ret false |
| 677 | end |
| 678 | lim = add sub al bl 1 |
| 679 | for i ulong lim bound 1000000000 |
| 680 | if sp_eq add ao i bl bo bl |
| 681 | ret true |
| 682 | end |
| 683 | end |
| 684 | ret false |
| 685 | end |
| 686 | |
| 687 | fn tmp1_eq_t n ulong t view uchar * to bool |
| 688 | if ne n len t |
| 689 | ret false |
| 690 | end |
| 691 | for i ulong n bound 8192 |
| 692 | if ne get tmp1 i get t i |
| 693 | ret false |
| 694 | end |
| 695 | end |
| 696 | ret true |
| 697 | end |
| 698 | |
| 699 | fn tmp1_at_t off ulong t view uchar * to bool |
| 700 | tl = len t |
| 701 | for j ulong tl bound 4096 |
| 702 | if ne get tmp1 add off j get t j |
| 703 | ret false |
| 704 | end |
| 705 | end |
| 706 | ret true |
| 707 | end |
| 708 | |
| 709 | fn tmp1_has_t n ulong t view uchar * to bool |
| 710 | tl = len t |
| 711 | if eq tl 0 |
| 712 | ret true |
| 713 | end |
| 714 | if lt n tl |
| 715 | ret false |
| 716 | end |
| 717 | lim = add sub n tl 1 |
| 718 | for i ulong lim bound 8192 |
| 719 | if tmp1_at_t i t |
| 720 | ret true |
| 721 | end |
| 722 | end |
| 723 | ret false |
| 724 | end |
| 725 | |
| 726 | fn strip_eq_t off ulong n ulong t view uchar * to bool |
| 727 | if ne n len t |
| 728 | ret false |
| 729 | end |
| 730 | for i ulong n bound 4096 |
| 731 | if ne get stripped add off i get t i |
| 732 | ret false |
| 733 | end |
| 734 | end |
| 735 | ret true |
| 736 | end |
| 737 | |
| 738 | fn word_eq_t wi ulong t view uchar * to bool |
| 739 | wl = get wlen wi |
| 740 | if ne wl len t |
| 741 | ret false |
| 742 | end |
| 743 | base = mul wi 40 |
| 744 | for i ulong wl bound 40 |
| 745 | if ne get wbuf add base i get t i |
| 746 | ret false |
| 747 | end |
| 748 | end |
| 749 | ret true |
| 750 | end |
| 751 | |
| 752 | note ---- repo / word lookup helpers ---- |
| 753 | fn repo_name_o r ulong to ulong |
| 754 | if eq r 0 |
| 755 | ret sp_add_t t_r0 |
| 756 | end |
| 757 | if eq r 1 |
| 758 | ret sp_add_t t_r1 |
| 759 | end |
| 760 | if eq r 2 |
| 761 | ret sp_add_t t_r2 |
| 762 | end |
| 763 | if eq r 3 |
| 764 | ret sp_add_t t_r3 |
| 765 | end |
| 766 | ret sp_add_t t_r4 |
| 767 | end |
| 768 | |
| 769 | fn oput_repo r ulong to void |
| 770 | if eq r 0 |
| 771 | oput_t t_r0 |
| 772 | ret |
| 773 | end |
| 774 | if eq r 1 |
| 775 | oput_t t_r1 |
| 776 | ret |
| 777 | end |
| 778 | if eq r 2 |
| 779 | oput_t t_r2 |
| 780 | ret |
| 781 | end |
| 782 | if eq r 3 |
| 783 | oput_t t_r3 |
| 784 | ret |
| 785 | end |
| 786 | oput_t t_r4 |
| 787 | end |
| 788 | |
| 789 | fn eput_repo r ulong to void |
| 790 | if eq r 0 |
| 791 | eput_t t_r0 |
| 792 | ret |
| 793 | end |
| 794 | if eq r 1 |
| 795 | eput_t t_r1 |
| 796 | ret |
| 797 | end |
| 798 | if eq r 2 |
| 799 | eput_t t_r2 |
| 800 | ret |
| 801 | end |
| 802 | if eq r 3 |
| 803 | eput_t t_r3 |
| 804 | ret |
| 805 | end |
| 806 | eput_t t_r4 |
| 807 | end |
| 808 | |
| 809 | fn eput_repo_env r ulong to void |
| 810 | if eq r 0 |
| 811 | eput_t t_e0 |
| 812 | ret |
| 813 | end |
| 814 | if eq r 1 |
| 815 | eput_t t_e1 |
| 816 | ret |
| 817 | end |
| 818 | if eq r 2 |
| 819 | eput_t t_e2 |
| 820 | ret |
| 821 | end |
| 822 | if eq r 3 |
| 823 | eput_t t_e3 |
| 824 | ret |
| 825 | end |
| 826 | eput_t t_e4 |
| 827 | end |
| 828 | |
| 829 | fn repo_index ao ulong al ulong to long |
| 830 | if sp_eq_t ao al t_r0 |
| 831 | ret 0 |
| 832 | end |
| 833 | if sp_eq_t ao al t_r1 |
| 834 | ret 1 |
| 835 | end |
| 836 | if sp_eq_t ao al t_r2 |
| 837 | ret 2 |
| 838 | end |
| 839 | if sp_eq_t ao al t_r3 |
| 840 | ret 3 |
| 841 | end |
| 842 | if sp_eq_t ao al t_r4 |
| 843 | ret 4 |
| 844 | end |
| 845 | ret -1 |
| 846 | end |
| 847 | |
| 848 | fn oput_term t ulong to void |
| 849 | if eq t 0 |
| 850 | oput_t t_bw_poll |
| 851 | ret |
| 852 | end |
| 853 | if eq t 1 |
| 854 | oput_t t_bw_sleep |
| 855 | ret |
| 856 | end |
| 857 | if eq t 2 |
| 858 | oput_t t_bw_wait |
| 859 | ret |
| 860 | end |
| 861 | if eq t 3 |
| 862 | oput_t t_bw_recv |
| 863 | ret |
| 864 | end |
| 865 | if eq t 4 |
| 866 | oput_t t_bw_heartbeat |
| 867 | ret |
| 868 | end |
| 869 | if eq t 5 |
| 870 | oput_t t_bw_tick |
| 871 | ret |
| 872 | end |
| 873 | if eq t 6 |
| 874 | oput_t t_bw_dispatch |
| 875 | ret |
| 876 | end |
| 877 | if eq t 7 |
| 878 | oput_t t_bw_schedule |
| 879 | ret |
| 880 | end |
| 881 | if eq t 8 |
| 882 | oput_t t_bw_orchestrate |
| 883 | ret |
| 884 | end |
| 885 | if eq t 9 |
| 886 | oput_t t_bw_turn |
| 887 | ret |
| 888 | end |
| 889 | if eq t 10 |
| 890 | oput_t t_bw_step |
| 891 | ret |
| 892 | end |
| 893 | if eq t 11 |
| 894 | oput_t t_bw_pulse |
| 895 | ret |
| 896 | end |
| 897 | oput_t t_bw_yield |
| 898 | end |
| 899 | |
| 900 | fn oput_named t ulong to void |
| 901 | if eq t 0 |
| 902 | oput_t t_ns0 |
| 903 | ret |
| 904 | end |
| 905 | if eq t 1 |
| 906 | oput_t t_ns1 |
| 907 | ret |
| 908 | end |
| 909 | oput_t t_ns2 |
| 910 | end |
| 911 | |
| 912 | fn is_body_word wi ulong to bool |
| 913 | if word_eq_t wi t_bw_sleep |
| 914 | ret true |
| 915 | end |
| 916 | if word_eq_t wi t_bw_usleep |
| 917 | ret true |
| 918 | end |
| 919 | if word_eq_t wi t_bw_nanosleep |
| 920 | ret true |
| 921 | end |
| 922 | if word_eq_t wi t_bw_msleep |
| 923 | ret true |
| 924 | end |
| 925 | if word_eq_t wi t_bw_poll |
| 926 | ret true |
| 927 | end |
| 928 | if word_eq_t wi t_bw_recv |
| 929 | ret true |
| 930 | end |
| 931 | if word_eq_t wi t_bw_heartbeat |
| 932 | ret true |
| 933 | end |
| 934 | if word_eq_t wi t_bw_tick |
| 935 | ret true |
| 936 | end |
| 937 | if word_eq_t wi t_bw_dispatch |
| 938 | ret true |
| 939 | end |
| 940 | if word_eq_t wi t_bw_schedule |
| 941 | ret true |
| 942 | end |
| 943 | if word_eq_t wi t_bw_scheduler |
| 944 | ret true |
| 945 | end |
| 946 | if word_eq_t wi t_bw_orchestrate |
| 947 | ret true |
| 948 | end |
| 949 | if word_eq_t wi t_bw_orchestrator |
| 950 | ret true |
| 951 | end |
| 952 | if word_eq_t wi t_bw_turn |
| 953 | ret true |
| 954 | end |
| 955 | if word_eq_t wi t_bw_turns |
| 956 | ret true |
| 957 | end |
| 958 | if word_eq_t wi t_bw_pulse |
| 959 | ret true |
| 960 | end |
| 961 | if word_eq_t wi t_bw_yield |
| 962 | ret true |
| 963 | end |
| 964 | if word_eq_t wi t_bw_epoll |
| 965 | ret true |
| 966 | end |
| 967 | ret false |
| 968 | end |
| 969 | |
| 970 | fn term_word_idx wi ulong to long |
| 971 | if word_eq_t wi t_bw_poll |
| 972 | ret 0 |
| 973 | end |
| 974 | if word_eq_t wi t_bw_sleep |
| 975 | ret 1 |
| 976 | end |
| 977 | if word_eq_t wi t_bw_usleep |
| 978 | ret 1 |
| 979 | end |
| 980 | if word_eq_t wi t_bw_nanosleep |
| 981 | ret 1 |
| 982 | end |
| 983 | if word_eq_t wi t_bw_msleep |
| 984 | ret 1 |
| 985 | end |
| 986 | if word_eq_t wi t_bw_wait |
| 987 | ret 2 |
| 988 | end |
| 989 | if word_eq_t wi t_bw_recv |
| 990 | ret 3 |
| 991 | end |
| 992 | if word_eq_t wi t_bw_heartbeat |
| 993 | ret 4 |
| 994 | end |
| 995 | if word_eq_t wi t_bw_tick |
| 996 | ret 5 |
| 997 | end |
| 998 | if word_eq_t wi t_bw_dispatch |
| 999 | ret 6 |
| 1000 | end |
| 1001 | if word_eq_t wi t_bw_schedule |
| 1002 | ret 7 |
| 1003 | end |
| 1004 | if word_eq_t wi t_bw_scheduler |
| 1005 | ret 7 |
| 1006 | end |
| 1007 | if word_eq_t wi t_bw_sched |
| 1008 | ret 7 |
| 1009 | end |
| 1010 | if word_eq_t wi t_bw_orchestrate |
| 1011 | ret 8 |
| 1012 | end |
| 1013 | if word_eq_t wi t_bw_orchestrator |
| 1014 | ret 8 |
| 1015 | end |
| 1016 | if word_eq_t wi t_bw_orchestration |
| 1017 | ret 8 |
| 1018 | end |
| 1019 | if word_eq_t wi t_bw_turn |
| 1020 | ret 9 |
| 1021 | end |
| 1022 | if word_eq_t wi t_bw_turns |
| 1023 | ret 9 |
| 1024 | end |
| 1025 | if word_eq_t wi t_bw_step |
| 1026 | ret 10 |
| 1027 | end |
| 1028 | if word_eq_t wi t_bw_steps |
| 1029 | ret 10 |
| 1030 | end |
| 1031 | if word_eq_t wi t_bw_pulse |
| 1032 | ret 11 |
| 1033 | end |
| 1034 | if word_eq_t wi t_bw_yield |
| 1035 | ret 12 |
| 1036 | end |
| 1037 | ret -1 |
| 1038 | end |
| 1039 | |
| 1040 | note ---- normalize whitespace into sp ---- |
| 1041 | fn norm_ws_orig off0 ulong n ulong to ulong |
| 1042 | sp_reserve n |
| 1043 | out_o = get sp_len 0 |
| 1044 | k = ulong 0 |
| 1045 | sp_f = ulong 0 |
| 1046 | for i ulong n bound 1000000000 |
| 1047 | c = get orig add off0 i |
| 1048 | if eq c 13 |
| 1049 | continue |
| 1050 | end |
| 1051 | if or eq c 32 eq c 9 |
| 1052 | sp_f = 1 |
| 1053 | continue |
| 1054 | end |
| 1055 | if ne sp_f 0 |
| 1056 | if gt k 0 |
| 1057 | put sp add out_o k 32 |
| 1058 | k = add k 1 |
| 1059 | end |
| 1060 | end |
| 1061 | sp_f = 0 |
| 1062 | put sp add out_o k c |
| 1063 | k = add k 1 |
| 1064 | end |
| 1065 | put sp_len 0 add out_o k |
| 1066 | ret k |
| 1067 | end |
| 1068 | |
| 1069 | fn norm_ws_strip off0 ulong n ulong to ulong |
| 1070 | sp_reserve n |
| 1071 | out_o = get sp_len 0 |
| 1072 | k = ulong 0 |
| 1073 | sp_f = ulong 0 |
| 1074 | for i ulong n bound 1000000000 |
| 1075 | c = get stripped add off0 i |
| 1076 | if eq c 13 |
| 1077 | continue |
| 1078 | end |
| 1079 | if or eq c 32 eq c 9 |
| 1080 | sp_f = 1 |
| 1081 | continue |
| 1082 | end |
| 1083 | if ne sp_f 0 |
| 1084 | if gt k 0 |
| 1085 | put sp add out_o k 32 |
| 1086 | k = add k 1 |
| 1087 | end |
| 1088 | end |
| 1089 | sp_f = 0 |
| 1090 | put sp add out_o k c |
| 1091 | k = add k 1 |
| 1092 | end |
| 1093 | put sp_len 0 add out_o k |
| 1094 | ret k |
| 1095 | end |
| 1096 | |
| 1097 | fn norm_ws_sp off0 ulong n ulong to ulong |
| 1098 | sp_reserve n |
| 1099 | out_o = get sp_len 0 |
| 1100 | k = ulong 0 |
| 1101 | sp_f = ulong 0 |
| 1102 | for i ulong n bound 1000000000 |
| 1103 | c = get sp add off0 i |
| 1104 | if eq c 13 |
| 1105 | continue |
| 1106 | end |
| 1107 | if or eq c 32 eq c 9 |
| 1108 | sp_f = 1 |
| 1109 | continue |
| 1110 | end |
| 1111 | if ne sp_f 0 |
| 1112 | if gt k 0 |
| 1113 | put sp add out_o k 32 |
| 1114 | k = add k 1 |
| 1115 | end |
| 1116 | end |
| 1117 | sp_f = 0 |
| 1118 | put sp add out_o k c |
| 1119 | k = add k 1 |
| 1120 | end |
| 1121 | put sp_len 0 add out_o k |
| 1122 | ret k |
| 1123 | end |
| 1124 | |
| 1125 | note ---- strip_code: blank comments & literals in stripped[0..n) ---- |
| 1126 | fn strip_block_comment i0 ulong n ulong rust ulong to ulong |
| 1127 | i = i0 |
| 1128 | depth = ulong 0 |
| 1129 | while lt i n bound 1000000000 |
| 1130 | if lt add i 1 n |
| 1131 | c0 = get stripped i |
| 1132 | c1 = get stripped add i 1 |
| 1133 | if and eq c0 47 eq c1 42 |
| 1134 | depth = add depth 1 |
| 1135 | put stripped i 32 |
| 1136 | put stripped add i 1 32 |
| 1137 | i = add i 2 |
| 1138 | if eq rust 0 |
| 1139 | depth = 1 |
| 1140 | end |
| 1141 | continue |
| 1142 | end |
| 1143 | if and eq c0 42 eq c1 47 |
| 1144 | depth = sub depth 1 |
| 1145 | put stripped i 32 |
| 1146 | put stripped add i 1 32 |
| 1147 | i = add i 2 |
| 1148 | if eq depth 0 |
| 1149 | break |
| 1150 | end |
| 1151 | continue |
| 1152 | end |
| 1153 | end |
| 1154 | if ne get stripped i 10 |
| 1155 | put stripped i 32 |
| 1156 | end |
| 1157 | i = add i 1 |
| 1158 | if eq depth 0 |
| 1159 | break |
| 1160 | end |
| 1161 | end |
| 1162 | ret i |
| 1163 | end |
| 1164 | |
| 1165 | fn strip_rust_raw i0 ulong n ulong is_b ulong to ulong |
| 1166 | j = add i0 1 |
| 1167 | if ne is_b 0 |
| 1168 | j = add i0 2 |
| 1169 | end |
| 1170 | hashes = ulong 0 |
| 1171 | while lt j n bound 1000000000 |
| 1172 | if ne get stripped j 35 |
| 1173 | break |
| 1174 | end |
| 1175 | hashes = add hashes 1 |
| 1176 | j = add j 1 |
| 1177 | end |
| 1178 | ok_q = false |
| 1179 | if lt j n |
| 1180 | if eq get stripped j 34 |
| 1181 | ok_q = true |
| 1182 | end |
| 1183 | end |
| 1184 | if not ok_q |
| 1185 | ret add i0 1 |
| 1186 | end |
| 1187 | j = add j 1 |
| 1188 | while lt j n bound 1000000000 |
| 1189 | if eq get stripped j 34 |
| 1190 | h = ulong 0 |
| 1191 | while lt h hashes bound 1000000000 |
| 1192 | if ge add add j 1 h n |
| 1193 | break |
| 1194 | end |
| 1195 | if ne get stripped add add j 1 h 35 |
| 1196 | break |
| 1197 | end |
| 1198 | h = add h 1 |
| 1199 | end |
| 1200 | if eq h hashes |
| 1201 | j = add add j 1 h |
| 1202 | break |
| 1203 | end |
| 1204 | end |
| 1205 | j = add j 1 |
| 1206 | end |
| 1207 | k = i0 |
| 1208 | while lt k j bound 1000000000 |
| 1209 | if ge k n |
| 1210 | break |
| 1211 | end |
| 1212 | if ne get stripped k 10 |
| 1213 | put stripped k 32 |
| 1214 | end |
| 1215 | k = add k 1 |
| 1216 | end |
| 1217 | ret j |
| 1218 | end |
| 1219 | |
| 1220 | fn strip_char_lit i0 ulong n ulong rust ulong to ulong |
| 1221 | j = add i0 1 |
| 1222 | lit = ulong 0 |
| 1223 | if lt j n |
| 1224 | if eq get stripped j 92 |
| 1225 | lit = 1 |
| 1226 | else |
| 1227 | k = add j 1 |
| 1228 | lim = add j 4 |
| 1229 | while lt k n bound 8 |
| 1230 | if gt k lim |
| 1231 | break |
| 1232 | end |
| 1233 | if eq get stripped k 39 |
| 1234 | lit = 1 |
| 1235 | break |
| 1236 | end |
| 1237 | k = add k 1 |
| 1238 | end |
| 1239 | if ne rust 0 |
| 1240 | if is_id get stripped j |
| 1241 | qnext = false |
| 1242 | if lt add j 1 n |
| 1243 | if eq get stripped add j 1 39 |
| 1244 | qnext = true |
| 1245 | end |
| 1246 | end |
| 1247 | if not qnext |
| 1248 | lit = 0 |
| 1249 | end |
| 1250 | end |
| 1251 | end |
| 1252 | end |
| 1253 | end |
| 1254 | if eq lit 0 |
| 1255 | ret add i0 1 |
| 1256 | end |
| 1257 | put stripped i0 32 |
| 1258 | i = add i0 1 |
| 1259 | while lt i n bound 1000000000 |
| 1260 | c = get stripped i |
| 1261 | if or eq c 39 eq c 10 |
| 1262 | break |
| 1263 | end |
| 1264 | if eq c 92 |
| 1265 | if lt add i 1 n |
| 1266 | put stripped i 32 |
| 1267 | i = add i 1 |
| 1268 | end |
| 1269 | end |
| 1270 | put stripped i 32 |
| 1271 | i = add i 1 |
| 1272 | end |
| 1273 | if lt i n |
| 1274 | if eq get stripped i 39 |
| 1275 | put stripped i 32 |
| 1276 | i = add i 1 |
| 1277 | end |
| 1278 | end |
| 1279 | ret i |
| 1280 | end |
| 1281 | |
| 1282 | fn strip_code n ulong rust ulong to void |
| 1283 | i = ulong 0 |
| 1284 | while lt i n bound 1000000000 |
| 1285 | c = get stripped i |
| 1286 | if eq c 47 |
| 1287 | if lt add i 1 n |
| 1288 | c2 = get stripped add i 1 |
| 1289 | if eq c2 47 |
| 1290 | while lt i n bound 1000000000 |
| 1291 | if eq get stripped i 10 |
| 1292 | break |
| 1293 | end |
| 1294 | put stripped i 32 |
| 1295 | i = add i 1 |
| 1296 | end |
| 1297 | continue |
| 1298 | end |
| 1299 | if eq c2 42 |
| 1300 | i = strip_block_comment i n rust |
| 1301 | continue |
| 1302 | end |
| 1303 | end |
| 1304 | i = add i 1 |
| 1305 | continue |
| 1306 | end |
| 1307 | if ne rust 0 |
| 1308 | is_r = false |
| 1309 | is_br = false |
| 1310 | if eq c 114 |
| 1311 | is_r = true |
| 1312 | end |
| 1313 | if eq c 98 |
| 1314 | if lt add i 1 n |
| 1315 | if eq get stripped add i 1 114 |
| 1316 | is_br = true |
| 1317 | end |
| 1318 | end |
| 1319 | end |
| 1320 | if or is_r is_br |
| 1321 | prev_ok = true |
| 1322 | if gt i 0 |
| 1323 | if is_id get stripped sub i 1 |
| 1324 | prev_ok = false |
| 1325 | end |
| 1326 | end |
| 1327 | if prev_ok |
| 1328 | ib = ulong 0 |
| 1329 | if is_br |
| 1330 | ib = 1 |
| 1331 | end |
| 1332 | i = strip_rust_raw i n ib |
| 1333 | continue |
| 1334 | end |
| 1335 | end |
| 1336 | end |
| 1337 | if eq c 34 |
| 1338 | put stripped i 32 |
| 1339 | i = add i 1 |
| 1340 | while lt i n bound 1000000000 |
| 1341 | if eq get stripped i 34 |
| 1342 | break |
| 1343 | end |
| 1344 | if eq get stripped i 92 |
| 1345 | if lt add i 1 n |
| 1346 | put stripped i 32 |
| 1347 | i = add i 1 |
| 1348 | end |
| 1349 | end |
| 1350 | if ne get stripped i 10 |
| 1351 | put stripped i 32 |
| 1352 | end |
| 1353 | i = add i 1 |
| 1354 | end |
| 1355 | if lt i n |
| 1356 | put stripped i 32 |
| 1357 | i = add i 1 |
| 1358 | end |
| 1359 | continue |
| 1360 | end |
| 1361 | if eq c 39 |
| 1362 | i = strip_char_lit i n rust |
| 1363 | continue |
| 1364 | end |
| 1365 | i = add i 1 |
| 1366 | end |
| 1367 | end |
| 1368 | |
| 1369 | note ---- identifier splitting & named terms ---- |
| 1370 | fn split_words off0 ulong idlen ulong to ulong |
| 1371 | nw = ulong 0 |
| 1372 | i = ulong 0 |
| 1373 | while lt i idlen bound 10000 |
| 1374 | if ge nw 16 |
| 1375 | break |
| 1376 | end |
| 1377 | while lt i idlen bound 10000 |
| 1378 | if is_alpha get stripped add off0 i |
| 1379 | break |
| 1380 | end |
| 1381 | i = add i 1 |
| 1382 | end |
| 1383 | if ge i idlen |
| 1384 | break |
| 1385 | end |
| 1386 | s = i |
| 1387 | if is_upper get stripped add off0 i |
| 1388 | i = add i 1 |
| 1389 | up2 = false |
| 1390 | if lt i idlen |
| 1391 | if is_upper get stripped add off0 i |
| 1392 | up2 = true |
| 1393 | end |
| 1394 | end |
| 1395 | if up2 |
| 1396 | while lt i idlen bound 10000 |
| 1397 | if not is_upper get stripped add off0 i |
| 1398 | break |
| 1399 | end |
| 1400 | if lt add i 1 idlen |
| 1401 | if is_lower get stripped add off0 add i 1 |
| 1402 | break |
| 1403 | end |
| 1404 | end |
| 1405 | i = add i 1 |
| 1406 | end |
| 1407 | else |
| 1408 | while lt i idlen bound 10000 |
| 1409 | if not is_lower get stripped add off0 i |
| 1410 | break |
| 1411 | end |
| 1412 | i = add i 1 |
| 1413 | end |
| 1414 | end |
| 1415 | else |
| 1416 | while lt i idlen bound 10000 |
| 1417 | if not is_lower get stripped add off0 i |
| 1418 | break |
| 1419 | end |
| 1420 | i = add i 1 |
| 1421 | end |
| 1422 | end |
| 1423 | wl = sub i s |
| 1424 | if gt wl 39 |
| 1425 | wl = 39 |
| 1426 | end |
| 1427 | base = mul nw 40 |
| 1428 | for k ulong wl bound 40 |
| 1429 | put wbuf add base k to_lower get stripped add off0 add s k |
| 1430 | end |
| 1431 | put wlen nw wl |
| 1432 | nw = add nw 1 |
| 1433 | end |
| 1434 | ret nw |
| 1435 | end |
| 1436 | |
| 1437 | fn norm_ident_tmp1 off0 ulong idlen ulong to ulong |
| 1438 | k = ulong 0 |
| 1439 | for i ulong idlen bound 10000 |
| 1440 | if ge k 255 |
| 1441 | break |
| 1442 | end |
| 1443 | c = get stripped add off0 i |
| 1444 | if ne c 95 |
| 1445 | put tmp1 k to_lower c |
| 1446 | k = add k 1 |
| 1447 | end |
| 1448 | end |
| 1449 | ret k |
| 1450 | end |
| 1451 | |
| 1452 | fn named_in_ident off0 ulong idlen ulong to long |
| 1453 | k = norm_ident_tmp1 off0 idlen |
| 1454 | if tmp1_has_t k t_nm0 |
| 1455 | ret 0 |
| 1456 | end |
| 1457 | if tmp1_eq_t k t_nm1 |
| 1458 | ret 1 |
| 1459 | end |
| 1460 | if tmp1_eq_t k t_nm2 |
| 1461 | ret 2 |
| 1462 | end |
| 1463 | ret -1 |
| 1464 | end |
| 1465 | |
| 1466 | fn named_count_in_ident off0 ulong idlen ulong to long |
| 1467 | k = norm_ident_tmp1 off0 idlen |
| 1468 | if tmp1_has_t k t_nm0 |
| 1469 | ret 0 |
| 1470 | end |
| 1471 | if tmp1_has_t k t_nm1 |
| 1472 | ret 1 |
| 1473 | end |
| 1474 | if tmp1_has_t k t_nm2 |
| 1475 | ret 2 |
| 1476 | end |
| 1477 | ret -1 |
| 1478 | end |
| 1479 | |
| 1480 | fn copy_word_tmp2 w ulong to ulong |
| 1481 | wl = get wlen w |
| 1482 | base = mul w 40 |
| 1483 | for k ulong wl bound 40 |
| 1484 | put tmp2 k get wbuf add base k |
| 1485 | end |
| 1486 | ret wl |
| 1487 | end |
| 1488 | |
| 1489 | note find_body_word: returns word length (0 if none), writes word into tmp2[0..wl) |
| 1490 | fn find_body_word a ulong b ulong to ulong |
| 1491 | i = a |
| 1492 | while lt i b bound 1000000000 |
| 1493 | c = get stripped i |
| 1494 | start_id = false |
| 1495 | if is_id c |
| 1496 | if eq i 0 |
| 1497 | start_id = true |
| 1498 | else |
| 1499 | if not is_id get stripped sub i 1 |
| 1500 | start_id = true |
| 1501 | end |
| 1502 | end |
| 1503 | end |
| 1504 | if start_id |
| 1505 | j = i |
| 1506 | while lt j b bound 1000000000 |
| 1507 | if not is_id get stripped j |
| 1508 | break |
| 1509 | end |
| 1510 | j = add j 1 |
| 1511 | end |
| 1512 | nw = split_words i sub j i |
| 1513 | for w ulong nw bound 16 |
| 1514 | if is_body_word w |
| 1515 | ret copy_word_tmp2 w |
| 1516 | end |
| 1517 | end |
| 1518 | i = j |
| 1519 | else |
| 1520 | i = add i 1 |
| 1521 | end |
| 1522 | end |
| 1523 | ret 0 |
| 1524 | end |
| 1525 | |
| 1526 | note ---- add_site ---- |
| 1527 | fn fmt_u_tmp1 v ulong to ulong |
| 1528 | d = new uchar 24 0 |
| 1529 | k = ulong 0 |
| 1530 | x = v |
| 1531 | while true bound 24 |
| 1532 | put d k uchar add 48 rem x 10 |
| 1533 | k = add k 1 |
| 1534 | x = div x 10 |
| 1535 | if eq x 0 |
| 1536 | break |
| 1537 | end |
| 1538 | end |
| 1539 | n = ulong 0 |
| 1540 | while gt k 0 bound 24 |
| 1541 | k = sub k 1 |
| 1542 | put tmp1 n get d k |
| 1543 | n = add n 1 |
| 1544 | end |
| 1545 | ret n |
| 1546 | end |
| 1547 | |
| 1548 | fn append_line_num idx ulong line ulong to void |
| 1549 | old_o = get st_lo idx |
| 1550 | old_l = get st_ll idx |
| 1551 | nl = fmt_u_tmp1 line |
| 1552 | sp_reserve add add old_l 1 nl |
| 1553 | new_o = get sp_len 0 |
| 1554 | for i ulong old_l bound 10000 |
| 1555 | put sp add new_o i get sp add old_o i |
| 1556 | end |
| 1557 | put sp add new_o old_l 44 |
| 1558 | for i ulong nl bound 24 |
| 1559 | put sp add add new_o add old_l 1 i get tmp1 i |
| 1560 | end |
| 1561 | put sp_len 0 add new_o add add old_l 1 nl |
| 1562 | put st_lo idx new_o |
| 1563 | put st_ll idx add add old_l 1 nl |
| 1564 | end |
| 1565 | |
| 1566 | global pend_so ulong 1 |
| 1567 | global pend_sl ulong 1 |
| 1568 | global pend_eo ulong 1 |
| 1569 | global pend_el ulong 1 |
| 1570 | global pend_to ulong 1 |
| 1571 | global pend_tl ulong 1 |
| 1572 | |
| 1573 | fn site_matches_pend ui ulong to bool |
| 1574 | if not sp_eq get st_so ui get st_sl ui get pend_so 0 get pend_sl 0 |
| 1575 | ret false |
| 1576 | end |
| 1577 | ret sp_eq get st_eo ui get st_el ui get pend_eo 0 get pend_el 0 |
| 1578 | end |
| 1579 | |
| 1580 | fn record_site repo ulong po ulong pl ulong line ulong to void |
| 1581 | ns = get nsites 0 |
| 1582 | i = sub long ns 1 |
| 1583 | while ge i 0 bound 16384 |
| 1584 | ui = ulong i |
| 1585 | if ne get st_repo ui repo |
| 1586 | break |
| 1587 | end |
| 1588 | if not sp_eq get st_po ui get st_pl ui po pl |
| 1589 | break |
| 1590 | end |
| 1591 | if site_matches_pend ui |
| 1592 | if eq get st_fline ui line |
| 1593 | ret |
| 1594 | end |
| 1595 | append_line_num ui line |
| 1596 | put st_cnt ui add get st_cnt ui 1 |
| 1597 | ret |
| 1598 | end |
| 1599 | i = sub i 1 |
| 1600 | end |
| 1601 | if ge ns MAX_SITES |
| 1602 | die_t t_die_oom |
| 1603 | end |
| 1604 | put st_repo ns repo |
| 1605 | put st_po ns po |
| 1606 | put st_pl ns pl |
| 1607 | put st_so ns get pend_so 0 |
| 1608 | put st_sl ns get pend_sl 0 |
| 1609 | put st_eo ns get pend_eo 0 |
| 1610 | put st_el ns get pend_el 0 |
| 1611 | put st_to ns get pend_to 0 |
| 1612 | put st_tl ns get pend_tl 0 |
| 1613 | ln = fmt_u_tmp1 line |
| 1614 | lo = sp_add_tmp1 ln |
| 1615 | put st_lo ns lo |
| 1616 | put st_ll ns ln |
| 1617 | put st_fline ns line |
| 1618 | put st_cnt ns 1 |
| 1619 | put st_row ns -1 |
| 1620 | put nsites 0 add ns 1 |
| 1621 | end |
| 1622 | |
| 1623 | fn sp_add_stripped off0 ulong n ulong to ulong |
| 1624 | sp_reserve n |
| 1625 | off = get sp_len 0 |
| 1626 | for q ulong n bound 256 |
| 1627 | put sp add off q get stripped add off0 q |
| 1628 | end |
| 1629 | put sp_len 0 add off n |
| 1630 | ret off |
| 1631 | end |
| 1632 | |
| 1633 | note ---- enclosing symbol per line ---- |
| 1634 | global sc_st ulong 8 |
| 1635 | |
| 1636 | fn rust_fn_on_line a ulong b ulong to void |
| 1637 | i = a |
| 1638 | while lt add i 3 b bound 1000000000 |
| 1639 | if eq get stripped i 102 |
| 1640 | if eq get stripped add i 1 110 |
| 1641 | c2 = get stripped add i 2 |
| 1642 | if or eq c2 32 eq c2 9 |
| 1643 | prev_ok = true |
| 1644 | if gt i 0 |
| 1645 | if is_id get stripped sub i 1 |
| 1646 | prev_ok = false |
| 1647 | end |
| 1648 | end |
| 1649 | if prev_ok |
| 1650 | j = add i 2 |
| 1651 | while lt j b bound 1000000000 |
| 1652 | cj = get stripped j |
| 1653 | if not or eq cj 32 eq cj 9 |
| 1654 | break |
| 1655 | end |
| 1656 | j = add j 1 |
| 1657 | end |
| 1658 | k = j |
| 1659 | while lt k b bound 1000000000 |
| 1660 | if not is_id get stripped k |
| 1661 | break |
| 1662 | end |
| 1663 | k = add k 1 |
| 1664 | end |
| 1665 | if gt k j |
| 1666 | if lt sub k j 128 |
| 1667 | cl = sub k j |
| 1668 | put sc_st 0 sp_add_stripped j cl |
| 1669 | put sc_st 1 cl |
| 1670 | end |
| 1671 | end |
| 1672 | ret |
| 1673 | end |
| 1674 | end |
| 1675 | end |
| 1676 | end |
| 1677 | i = add i 1 |
| 1678 | end |
| 1679 | end |
| 1680 | |
| 1681 | fn build_syms_rust nl ulong n ulong to void |
| 1682 | put sc_st 0 sp_add_t t_dash |
| 1683 | put sc_st 1 1 |
| 1684 | for L ulong nl bound 1000000000 |
| 1685 | a = get lstarts L |
| 1686 | b = sub get lstarts add L 1 1 |
| 1687 | if gt b n |
| 1688 | b = n |
| 1689 | end |
| 1690 | rust_fn_on_line a b |
| 1691 | put sym_o L get sc_st 0 |
| 1692 | put sym_l L get sc_st 1 |
| 1693 | end |
| 1694 | end |
| 1695 | |
| 1696 | fn syms_c_open_paren pos ulong a ulong to void |
| 1697 | k = pos |
| 1698 | while gt k a bound 1000000000 |
| 1699 | cp = get stripped sub k 1 |
| 1700 | if not or eq cp 32 eq cp 9 |
| 1701 | break |
| 1702 | end |
| 1703 | k = sub k 1 |
| 1704 | end |
| 1705 | j = k |
| 1706 | while gt j a bound 1000000000 |
| 1707 | if not is_id get stripped sub j 1 |
| 1708 | break |
| 1709 | end |
| 1710 | j = sub j 1 |
| 1711 | end |
| 1712 | if gt k j |
| 1713 | if lt sub k j 128 |
| 1714 | if eq get sc_st 4 0 |
| 1715 | cl = sub k j |
| 1716 | put sc_st 2 sp_add_stripped j cl |
| 1717 | put sc_st 3 cl |
| 1718 | end |
| 1719 | end |
| 1720 | end |
| 1721 | end |
| 1722 | |
| 1723 | fn syms_c_line L ulong a ulong b ulong to void |
| 1724 | note sc_st: 0=cur_o 1=cur_l 2=cand_o 3=cand_l 4=cand_eq 5=depth 6=pd 7=dash_o |
| 1725 | sso = get sc_st 7 |
| 1726 | ssl = ulong 1 |
| 1727 | if gt get sc_st 5 0 |
| 1728 | sso = get sc_st 0 |
| 1729 | ssl = get sc_st 1 |
| 1730 | end |
| 1731 | for i ulong sub b a bound 1000000000 |
| 1732 | pos = add a i |
| 1733 | c = get stripped pos |
| 1734 | if eq get sc_st 5 0 |
| 1735 | if eq c 41 |
| 1736 | if gt get sc_st 6 0 |
| 1737 | put sc_st 6 sub get sc_st 6 1 |
| 1738 | end |
| 1739 | end |
| 1740 | if eq c 40 |
| 1741 | old_pd = get sc_st 6 |
| 1742 | put sc_st 6 add old_pd 1 |
| 1743 | if eq old_pd 0 |
| 1744 | syms_c_open_paren pos a |
| 1745 | end |
| 1746 | else |
| 1747 | if eq c 59 |
| 1748 | put sc_st 2 get sc_st 7 |
| 1749 | put sc_st 3 1 |
| 1750 | put sc_st 4 0 |
| 1751 | else |
| 1752 | if eq c 61 |
| 1753 | put sc_st 4 1 |
| 1754 | end |
| 1755 | end |
| 1756 | end |
| 1757 | end |
| 1758 | if eq c 123 |
| 1759 | if eq get sc_st 5 0 |
| 1760 | if ne get sc_st 4 0 |
| 1761 | put sc_st 0 get sc_st 7 |
| 1762 | put sc_st 1 1 |
| 1763 | else |
| 1764 | put sc_st 0 get sc_st 2 |
| 1765 | put sc_st 1 get sc_st 3 |
| 1766 | end |
| 1767 | end |
| 1768 | put sc_st 5 add get sc_st 5 1 |
| 1769 | else |
| 1770 | if eq c 125 |
| 1771 | if gt get sc_st 5 0 |
| 1772 | put sc_st 5 sub get sc_st 5 1 |
| 1773 | end |
| 1774 | if eq get sc_st 5 0 |
| 1775 | put sc_st 2 get sc_st 7 |
| 1776 | put sc_st 3 1 |
| 1777 | put sc_st 4 0 |
| 1778 | end |
| 1779 | end |
| 1780 | end |
| 1781 | end |
| 1782 | if gt get sc_st 5 0 |
| 1783 | put sym_o L get sc_st 0 |
| 1784 | put sym_l L get sc_st 1 |
| 1785 | else |
| 1786 | put sym_o L sso |
| 1787 | put sym_l L ssl |
| 1788 | put sc_st 0 get sc_st 7 |
| 1789 | put sc_st 1 1 |
| 1790 | end |
| 1791 | end |
| 1792 | |
| 1793 | fn build_syms_c nl ulong n ulong to void |
| 1794 | dash_o = sp_add_t t_dash |
| 1795 | put sc_st 0 dash_o |
| 1796 | put sc_st 1 1 |
| 1797 | put sc_st 2 dash_o |
| 1798 | put sc_st 3 1 |
| 1799 | put sc_st 4 0 |
| 1800 | put sc_st 5 0 |
| 1801 | put sc_st 6 0 |
| 1802 | put sc_st 7 dash_o |
| 1803 | for L ulong nl bound 1000000000 |
| 1804 | a = get lstarts L |
| 1805 | b = sub get lstarts add L 1 1 |
| 1806 | if gt b n |
| 1807 | b = n |
| 1808 | end |
| 1809 | syms_c_line L a b |
| 1810 | end |
| 1811 | end |
| 1812 | |
| 1813 | note ---- loop scanning helpers ---- |
| 1814 | fn make_named_trig nt ulong to ulong |
| 1815 | sp_reserve 32 |
| 1816 | off = get sp_len 0 |
| 1817 | pl = len t_named_pfx |
| 1818 | for i ulong pl bound 16 |
| 1819 | put sp add off i get t_named_pfx i |
| 1820 | end |
| 1821 | put sp_len 0 add off pl |
| 1822 | if eq nt 0 |
| 1823 | _o = sp_add_t t_ns0 |
| 1824 | ret add pl len t_ns0 |
| 1825 | end |
| 1826 | if eq nt 1 |
| 1827 | _o = sp_add_t t_ns1 |
| 1828 | ret add pl len t_ns1 |
| 1829 | end |
| 1830 | _o = sp_add_t t_ns2 |
| 1831 | ret add pl len t_ns2 |
| 1832 | end |
| 1833 | |
| 1834 | fn make_loop_trig kw_id ulong unb ulong wdl ulong to ulong |
| 1835 | off = get sp_len 0 |
| 1836 | if eq kw_id 1 |
| 1837 | _o = sp_add_t t_kw_while |
| 1838 | end |
| 1839 | if eq kw_id 2 |
| 1840 | _o = sp_add_t t_kw_for |
| 1841 | end |
| 1842 | if eq kw_id 3 |
| 1843 | _o = sp_add_t t_kw_loop |
| 1844 | end |
| 1845 | if eq kw_id 4 |
| 1846 | _o = sp_add_t t_kw_do |
| 1847 | end |
| 1848 | if ne unb 0 |
| 1849 | if gt wdl 0 |
| 1850 | _o = sp_add_t t_unb_plus |
| 1851 | _o = sp_add_tmp2 wdl |
| 1852 | else |
| 1853 | _o = sp_add_t t_unb |
| 1854 | end |
| 1855 | else |
| 1856 | _o = sp_add_t t_body_col |
| 1857 | _o = sp_add_tmp2 wdl |
| 1858 | end |
| 1859 | ret sub get sp_len 0 off |
| 1860 | end |
| 1861 | |
| 1862 | fn rust_for_has_in k ulong n ulong to bool |
| 1863 | q = k |
| 1864 | while lt add q 1 n bound 1000000000 |
| 1865 | c = get stripped q |
| 1866 | if or eq c 123 or eq c 10 eq c 59 |
| 1867 | break |
| 1868 | end |
| 1869 | if and eq c 105 eq get stripped add q 1 110 |
| 1870 | if gt q 0 |
| 1871 | if not is_id get stripped sub q 1 |
| 1872 | after_ok = true |
| 1873 | if lt add q 2 n |
| 1874 | if is_id get stripped add q 2 |
| 1875 | after_ok = false |
| 1876 | end |
| 1877 | end |
| 1878 | if after_ok |
| 1879 | ret true |
| 1880 | end |
| 1881 | end |
| 1882 | end |
| 1883 | end |
| 1884 | q = add q 1 |
| 1885 | end |
| 1886 | ret false |
| 1887 | end |
| 1888 | |
| 1889 | fn check_c_cond kw_id ulong k ulong n ulong to ulong |
| 1890 | note returns packed (unbounded << 48) | e |
| 1891 | q = k |
| 1892 | d = ulong 0 |
| 1893 | while lt q n bound 1000000000 |
| 1894 | c = get stripped q |
| 1895 | if eq c 40 |
| 1896 | d = add d 1 |
| 1897 | else |
| 1898 | if eq c 41 |
| 1899 | d = sub d 1 |
| 1900 | if eq d 0 |
| 1901 | break |
| 1902 | end |
| 1903 | end |
| 1904 | end |
| 1905 | q = add q 1 |
| 1906 | end |
| 1907 | ci = ulong 0 |
| 1908 | r = add k 1 |
| 1909 | while lt r q bound 1000000000 |
| 1910 | if ge ci 63 |
| 1911 | break |
| 1912 | end |
| 1913 | cr = get stripped r |
| 1914 | if not is_space cr |
| 1915 | put tmp1 ci cr |
| 1916 | ci = add ci 1 |
| 1917 | end |
| 1918 | r = add r 1 |
| 1919 | end |
| 1920 | unb = ulong 0 |
| 1921 | if eq kw_id 1 |
| 1922 | if tmp1_eq_t ci t_cond_1 |
| 1923 | unb = 1 |
| 1924 | end |
| 1925 | if tmp1_eq_t ci t_cond_true |
| 1926 | unb = 1 |
| 1927 | end |
| 1928 | if tmp1_eq_t ci t_cond_not0 |
| 1929 | unb = 1 |
| 1930 | end |
| 1931 | end |
| 1932 | if eq kw_id 2 |
| 1933 | if tmp1_eq_t ci t_cond_semi |
| 1934 | unb = 1 |
| 1935 | end |
| 1936 | end |
| 1937 | e = add q 1 |
| 1938 | ret or shl unb 48 e |
| 1939 | end |
| 1940 | |
| 1941 | fn find_body_end e ulong n ulong kw_id ulong to ulong |
| 1942 | par = ulong 0 |
| 1943 | endp = n |
| 1944 | q = e |
| 1945 | while lt q n bound 1000000000 |
| 1946 | c = get stripped q |
| 1947 | if or eq c 40 eq c 91 |
| 1948 | par = add par 1 |
| 1949 | else |
| 1950 | if or eq c 41 eq c 93 |
| 1951 | if gt par 0 |
| 1952 | par = sub par 1 |
| 1953 | end |
| 1954 | else |
| 1955 | if and eq par 0 eq c 59 |
| 1956 | endp = add q 1 |
| 1957 | break |
| 1958 | end |
| 1959 | if and eq par 0 eq c 123 |
| 1960 | d = ulong 0 |
| 1961 | r = q |
| 1962 | while lt r n bound 1000000000 |
| 1963 | cr = get stripped r |
| 1964 | if eq cr 123 |
| 1965 | d = add d 1 |
| 1966 | else |
| 1967 | if eq cr 125 |
| 1968 | d = sub d 1 |
| 1969 | if eq d 0 |
| 1970 | break |
| 1971 | end |
| 1972 | end |
| 1973 | end |
| 1974 | r = add r 1 |
| 1975 | end |
| 1976 | if lt r n |
| 1977 | endp = add r 1 |
| 1978 | else |
| 1979 | endp = n |
| 1980 | end |
| 1981 | if eq kw_id 4 |
| 1982 | while lt endp n bound 1000000000 |
| 1983 | if eq get stripped endp 59 |
| 1984 | break |
| 1985 | end |
| 1986 | endp = add endp 1 |
| 1987 | end |
| 1988 | end |
| 1989 | break |
| 1990 | end |
| 1991 | end |
| 1992 | end |
| 1993 | q = add q 1 |
| 1994 | end |
| 1995 | ret endp |
| 1996 | end |
| 1997 | |
| 1998 | global tok_ctx ulong 8 |
| 1999 | |
| 2000 | fn scan_token_ident i ulong idlen ulong line ulong n ulong to void |
| 2001 | repo = get tok_ctx 0 |
| 2002 | nw = split_words i idlen |
| 2003 | for w ulong nw bound 16 |
| 2004 | ti = term_word_idx w |
| 2005 | if ge ti 0 |
| 2006 | tidx = add mul repo 32 ulong ti |
| 2007 | put thits tidx add get thits tidx 1 |
| 2008 | end |
| 2009 | end |
| 2010 | ntc = named_count_in_ident i idlen |
| 2011 | if ge ntc 0 |
| 2012 | nidx = add mul repo 8 ulong ntc |
| 2013 | put nhits nidx add get nhits nidx 1 |
| 2014 | end |
| 2015 | nt = named_in_ident i idlen |
| 2016 | if ge nt 0 |
| 2017 | la = get lstarts line |
| 2018 | lb = sub get lstarts add line 1 1 |
| 2019 | if gt lb n |
| 2020 | lb = n |
| 2021 | end |
| 2022 | put pend_so 0 get sym_o line |
| 2023 | put pend_sl 0 get sym_l line |
| 2024 | put pend_eo 0 get sp_len 0 |
| 2025 | put pend_el 0 norm_ws_orig la sub lb la |
| 2026 | put pend_to 0 get sp_len 0 |
| 2027 | put pend_tl 0 make_named_trig ulong nt |
| 2028 | record_site repo get tok_ctx 1 get tok_ctx 2 add line 1 |
| 2029 | end |
| 2030 | end |
| 2031 | |
| 2032 | fn classify_loop_kw i ulong idlen ulong rust ulong to ulong |
| 2033 | if strip_eq_t i idlen t_kw_while |
| 2034 | ret 1 |
| 2035 | end |
| 2036 | if strip_eq_t i idlen t_kw_for |
| 2037 | ret 2 |
| 2038 | end |
| 2039 | if ne rust 0 |
| 2040 | if strip_eq_t i idlen t_kw_loop |
| 2041 | ret 3 |
| 2042 | end |
| 2043 | else |
| 2044 | if strip_eq_t i idlen t_kw_do |
| 2045 | ret 4 |
| 2046 | end |
| 2047 | end |
| 2048 | ret 0 |
| 2049 | end |
| 2050 | |
| 2051 | fn loop_head_pos i ulong j ulong kw ulong n ulong to long |
| 2052 | rust = get tok_ctx 3 |
| 2053 | k = j |
| 2054 | while lt k n bound 1000000000 |
| 2055 | if not is_space get stripped k |
| 2056 | break |
| 2057 | end |
| 2058 | k = add k 1 |
| 2059 | end |
| 2060 | if or eq kw 3 eq kw 4 |
| 2061 | if ge k n |
| 2062 | ret -1 |
| 2063 | end |
| 2064 | if ne get stripped k 123 |
| 2065 | ret -1 |
| 2066 | end |
| 2067 | else |
| 2068 | if eq rust 0 |
| 2069 | if ge k n |
| 2070 | ret -1 |
| 2071 | end |
| 2072 | if ne get stripped k 40 |
| 2073 | ret -1 |
| 2074 | end |
| 2075 | else |
| 2076 | if eq kw 2 |
| 2077 | if not rust_for_has_in k n |
| 2078 | ret -1 |
| 2079 | end |
| 2080 | end |
| 2081 | end |
| 2082 | end |
| 2083 | if and eq rust 0 eq kw 1 |
| 2084 | p = i |
| 2085 | while gt p 0 bound 1000000000 |
| 2086 | if not is_space get stripped sub p 1 |
| 2087 | break |
| 2088 | end |
| 2089 | p = sub p 1 |
| 2090 | end |
| 2091 | if gt p 0 |
| 2092 | if eq get stripped sub p 1 125 |
| 2093 | ret -1 |
| 2094 | end |
| 2095 | end |
| 2096 | end |
| 2097 | ret long k |
| 2098 | end |
| 2099 | |
| 2100 | fn rust_while_unb k ulong n ulong to ulong |
| 2101 | q = k |
| 2102 | while lt q n bound 1000000000 |
| 2103 | if not is_space get stripped q |
| 2104 | break |
| 2105 | end |
| 2106 | q = add q 1 |
| 2107 | end |
| 2108 | if le add q 4 n |
| 2109 | if strip_eq_t q 4 t_cond_true |
| 2110 | if lt add q 4 n |
| 2111 | if is_id get stripped add q 4 |
| 2112 | ret 0 |
| 2113 | end |
| 2114 | end |
| 2115 | ret 1 |
| 2116 | end |
| 2117 | end |
| 2118 | ret 0 |
| 2119 | end |
| 2120 | |
| 2121 | fn record_loop_site line ulong n ulong kw ulong unb ulong wdl ulong to void |
| 2122 | la = get lstarts line |
| 2123 | lb = sub get lstarts add line 1 1 |
| 2124 | if gt lb n |
| 2125 | lb = n |
| 2126 | end |
| 2127 | put pend_so 0 get sym_o line |
| 2128 | put pend_sl 0 get sym_l line |
| 2129 | put pend_to 0 get sp_len 0 |
| 2130 | put pend_tl 0 make_loop_trig kw unb wdl |
| 2131 | put pend_eo 0 get sp_len 0 |
| 2132 | put pend_el 0 norm_ws_orig la sub lb la |
| 2133 | record_site get tok_ctx 0 get tok_ctx 1 get tok_ctx 2 add line 1 |
| 2134 | end |
| 2135 | |
| 2136 | fn scan_token_loop i ulong j ulong line ulong n ulong to void |
| 2137 | rust = get tok_ctx 3 |
| 2138 | kw = classify_loop_kw i sub j i rust |
| 2139 | if eq kw 0 |
| 2140 | ret |
| 2141 | end |
| 2142 | kr = loop_head_pos i j kw n |
| 2143 | if lt kr 0 |
| 2144 | ret |
| 2145 | end |
| 2146 | k = ulong kr |
| 2147 | e = k |
| 2148 | unb = ulong 0 |
| 2149 | if eq kw 3 |
| 2150 | unb = 1 |
| 2151 | end |
| 2152 | if eq rust 0 |
| 2153 | if lt k n |
| 2154 | if eq get stripped k 40 |
| 2155 | res = check_c_cond kw k n |
| 2156 | unb = shr res 48 |
| 2157 | e = and res 281474976710655 |
| 2158 | end |
| 2159 | end |
| 2160 | end |
| 2161 | if and ne rust 0 eq kw 1 |
| 2162 | unb = rust_while_unb k n |
| 2163 | end |
| 2164 | endp = find_body_end e n kw |
| 2165 | wdl = find_body_word j endp |
| 2166 | if or ne unb 0 gt wdl 0 |
| 2167 | record_loop_site line n kw unb wdl |
| 2168 | end |
| 2169 | end |
| 2170 | |
| 2171 | fn scan_one_token i ulong j ulong line ulong n ulong to void |
| 2172 | scan_token_ident i sub j i line n |
| 2173 | scan_token_loop i j line n |
| 2174 | end |
| 2175 | |
| 2176 | fn scan_tokens repo ulong po ulong pl ulong n ulong nl ulong to void |
| 2177 | put tok_ctx 0 repo |
| 2178 | put tok_ctx 1 po |
| 2179 | put tok_ctx 2 pl |
| 2180 | rust = ulong 0 |
| 2181 | if sp_ends_t po pl t_rs |
| 2182 | rust = 1 |
| 2183 | end |
| 2184 | put tok_ctx 3 rust |
| 2185 | line = ulong 0 |
| 2186 | i = ulong 0 |
| 2187 | while lt i n bound 1000000000 |
| 2188 | while lt add line 1 nl bound 1000000000 |
| 2189 | if gt get lstarts add line 1 i |
| 2190 | break |
| 2191 | end |
| 2192 | line = add line 1 |
| 2193 | end |
| 2194 | c = get stripped i |
| 2195 | start_id = false |
| 2196 | if is_id c |
| 2197 | if eq i 0 |
| 2198 | start_id = true |
| 2199 | else |
| 2200 | if not is_id get stripped sub i 1 |
| 2201 | start_id = true |
| 2202 | end |
| 2203 | end |
| 2204 | end |
| 2205 | if not start_id |
| 2206 | i = add i 1 |
| 2207 | continue |
| 2208 | end |
| 2209 | j = i |
| 2210 | while lt j n bound 1000000000 |
| 2211 | if not is_id get stripped j |
| 2212 | break |
| 2213 | end |
| 2214 | j = add j 1 |
| 2215 | end |
| 2216 | scan_one_token i j line n |
| 2217 | i = j |
| 2218 | end |
| 2219 | end |
| 2220 | |
| 2221 | fn strip_has_nonws a ulong b ulong to bool |
| 2222 | for q ulong sub b a bound 1000000000 |
| 2223 | cq = get stripped add a q |
| 2224 | if not or eq cq 32 eq cq 9 |
| 2225 | ret true |
| 2226 | end |
| 2227 | end |
| 2228 | ret false |
| 2229 | end |
| 2230 | |
| 2231 | fn scan_climode_line L ulong n ulong to void |
| 2232 | a = get lstarts L |
| 2233 | b = sub get lstarts add L 1 1 |
| 2234 | if gt b n |
| 2235 | b = n |
| 2236 | end |
| 2237 | co = get sp_len 0 |
| 2238 | cl = norm_ws_strip a sub b a |
| 2239 | if not sp_has_t co cl t_argvb |
| 2240 | ret |
| 2241 | end |
| 2242 | eo = get sp_len 0 |
| 2243 | el = norm_ws_orig a sub b a |
| 2244 | has_cli = false |
| 2245 | if sp_has_t eo el t_cli_dem |
| 2246 | has_cli = true |
| 2247 | end |
| 2248 | if sp_has_t eo el t_cli_ref |
| 2249 | has_cli = true |
| 2250 | end |
| 2251 | if sp_has_t eo el t_cli_run |
| 2252 | has_cli = true |
| 2253 | end |
| 2254 | if not has_cli |
| 2255 | ret |
| 2256 | end |
| 2257 | if strip_has_nonws a b |
| 2258 | put pend_so 0 get sym_o L |
| 2259 | put pend_sl 0 get sym_l L |
| 2260 | put pend_eo 0 eo |
| 2261 | put pend_el 0 el |
| 2262 | put pend_to 0 sp_add_t t_climode |
| 2263 | put pend_tl 0 len t_climode |
| 2264 | record_site get tok_ctx 0 get tok_ctx 1 get tok_ctx 2 add L 1 |
| 2265 | end |
| 2266 | end |
| 2267 | |
| 2268 | fn scan_climode repo ulong po ulong pl ulong n ulong nl ulong to void |
| 2269 | put tok_ctx 0 repo |
| 2270 | put tok_ctx 1 po |
| 2271 | put tok_ctx 2 pl |
| 2272 | for L ulong nl bound 1000000000 |
| 2273 | scan_climode_line L n |
| 2274 | end |
| 2275 | end |
| 2276 | |
| 2277 | note ---- file reading into orig ---- |
| 2278 | fn build_path_tmp1 ro ulong rl ulong po ulong pl ulong to ulong |
| 2279 | for i ulong rl bound 4096 |
| 2280 | put tmp1 i get sp add ro i |
| 2281 | end |
| 2282 | put tmp1 rl 47 |
| 2283 | for i ulong pl bound 4096 |
| 2284 | put tmp1 add add rl 1 i get sp add po i |
| 2285 | end |
| 2286 | ret add add rl 1 pl |
| 2287 | end |
| 2288 | |
| 2289 | fn read_file_orig plen ulong to long |
| 2290 | fd = fopen tmp1 0 plen 0 0 |
| 2291 | if lt fd 0 |
| 2292 | ret -1 |
| 2293 | end |
| 2294 | cap = get orig_cap 0 |
| 2295 | if eq cap 0 |
| 2296 | cap = 65536 |
| 2297 | _e = enlarge orig cap |
| 2298 | if lt _e 0 |
| 2299 | _c = fclose int fd |
| 2300 | die_t t_die_oom |
| 2301 | end |
| 2302 | put orig_cap 0 cap |
| 2303 | end |
| 2304 | n = ulong 0 |
| 2305 | while true bound 1000000000 |
| 2306 | if ge add n 4096 cap |
| 2307 | cap = mul cap 2 |
| 2308 | _e = enlarge orig cap |
| 2309 | if lt _e 0 |
| 2310 | _c = fclose int fd |
| 2311 | die_t t_die_oom |
| 2312 | end |
| 2313 | put orig_cap 0 cap |
| 2314 | end |
| 2315 | k = read int fd orig n sub cap n |
| 2316 | if lt k 0 |
| 2317 | _c = fclose int fd |
| 2318 | ret -2 |
| 2319 | end |
| 2320 | if eq k 0 |
| 2321 | break |
| 2322 | end |
| 2323 | n = add n ulong k |
| 2324 | end |
| 2325 | _c = fclose int fd |
| 2326 | ret long n |
| 2327 | end |
| 2328 | |
| 2329 | fn prep_file_bufs n ulong rust ulong to ulong |
| 2330 | if lt get strip_cap 0 add n 1 |
| 2331 | ncap = add n 1 |
| 2332 | if lt ncap 65536 |
| 2333 | ncap = 65536 |
| 2334 | end |
| 2335 | _e = enlarge stripped ncap |
| 2336 | if lt _e 0 |
| 2337 | die_t t_die_oom |
| 2338 | end |
| 2339 | put strip_cap 0 ncap |
| 2340 | end |
| 2341 | for i ulong n bound 1000000000 |
| 2342 | put stripped i get orig i |
| 2343 | end |
| 2344 | strip_code n rust |
| 2345 | nl = ulong 1 |
| 2346 | for i ulong n bound 1000000000 |
| 2347 | if eq get orig i 10 |
| 2348 | nl = add nl 1 |
| 2349 | end |
| 2350 | end |
| 2351 | if lt get ls_cap 0 add nl 1 |
| 2352 | ncap = add nl 1 |
| 2353 | if lt ncap 4096 |
| 2354 | ncap = 4096 |
| 2355 | end |
| 2356 | _e = enlarge lstarts ncap |
| 2357 | if lt _e 0 |
| 2358 | die_t t_die_oom |
| 2359 | end |
| 2360 | put ls_cap 0 ncap |
| 2361 | end |
| 2362 | put lstarts 0 0 |
| 2363 | li = ulong 1 |
| 2364 | for i ulong n bound 1000000000 |
| 2365 | if eq get orig i 10 |
| 2366 | put lstarts li add i 1 |
| 2367 | li = add li 1 |
| 2368 | end |
| 2369 | end |
| 2370 | put lstarts nl add n 1 |
| 2371 | if lt get sym_cap 0 nl |
| 2372 | ncap = nl |
| 2373 | if lt ncap 4096 |
| 2374 | ncap = 4096 |
| 2375 | end |
| 2376 | _e = enlarge sym_o ncap |
| 2377 | _e2 = enlarge sym_l ncap |
| 2378 | if or lt _e 0 lt _e2 0 |
| 2379 | die_t t_die_oom |
| 2380 | end |
| 2381 | put sym_cap 0 ncap |
| 2382 | end |
| 2383 | ret nl |
| 2384 | end |
| 2385 | |
| 2386 | fn scan_file repo ulong ro ulong rl ulong po ulong pl ulong to void |
| 2387 | plen = build_path_tmp1 ro rl po pl |
| 2388 | rn = read_file_orig plen |
| 2389 | if eq rn -1 |
| 2390 | ret |
| 2391 | end |
| 2392 | if lt rn 0 |
| 2393 | fo = sp_add_tmp1 plen |
| 2394 | die_sp t_die_read fo plen |
| 2395 | end |
| 2396 | n = ulong rn |
| 2397 | rust = ulong 0 |
| 2398 | if sp_ends_t po pl t_rs |
| 2399 | rust = 1 |
| 2400 | end |
| 2401 | nl = prep_file_bufs n rust |
| 2402 | if ne rust 0 |
| 2403 | build_syms_rust nl n |
| 2404 | else |
| 2405 | build_syms_c nl n |
| 2406 | end |
| 2407 | scan_tokens repo po pl n nl |
| 2408 | if eq rust 0 |
| 2409 | scan_climode repo po pl n nl |
| 2410 | end |
| 2411 | end |
| 2412 | |
| 2413 | note ---- excluded path check ---- |
| 2414 | fn excluded po ulong pl ulong to bool |
| 2415 | if sp_starts_t po pl t_ex0 |
| 2416 | ret true |
| 2417 | end |
| 2418 | if sp_starts_t po pl t_ex1 |
| 2419 | ret true |
| 2420 | end |
| 2421 | if sp_starts_t po pl t_ex2 |
| 2422 | ret true |
| 2423 | end |
| 2424 | if gt pl 8 |
| 2425 | for i ulong sub pl 7 bound 8192 |
| 2426 | if eq get sp add po i 47 |
| 2427 | if sp_starts_t add po add i 1 sub sub pl i 1 t_ex0 |
| 2428 | ret true |
| 2429 | end |
| 2430 | end |
| 2431 | end |
| 2432 | end |
| 2433 | if gt pl 13 |
| 2434 | for i ulong sub pl 12 bound 8192 |
| 2435 | if eq get sp add po i 47 |
| 2436 | if sp_starts_t add po add i 1 sub sub pl i 1 t_ex1 |
| 2437 | ret true |
| 2438 | end |
| 2439 | end |
| 2440 | end |
| 2441 | end |
| 2442 | ret false |
| 2443 | end |
| 2444 | |
| 2445 | note ---- git subprocess via pipefds + fork + dupfd + execprog + waitpid ---- |
| 2446 | fn pkt_put16 off ulong v ulong to void |
| 2447 | put pkt off uchar and v 255 |
| 2448 | put pkt add off 1 uchar and shr v 8 255 |
| 2449 | end |
| 2450 | |
| 2451 | fn pkt_add_t pos ulong t view uchar * to ulong |
| 2452 | n = len t |
| 2453 | pkt_put16 pos n |
| 2454 | pos = add pos 2 |
| 2455 | for i ulong n bound 4096 |
| 2456 | put pkt add pos i get t i |
| 2457 | end |
| 2458 | ret add pos n |
| 2459 | end |
| 2460 | |
| 2461 | fn pkt_add_sp pos ulong off ulong n ulong to ulong |
| 2462 | pkt_put16 pos n |
| 2463 | pos = add pos 2 |
| 2464 | for i ulong n bound 4096 |
| 2465 | put pkt add pos i get sp add off i |
| 2466 | end |
| 2467 | ret add pos n |
| 2468 | end |
| 2469 | |
| 2470 | fn read_u32_le b view uchar 8 off ulong to uint |
| 2471 | b0 = uint get b off |
| 2472 | b1 = uint get b add off 1 |
| 2473 | b2 = uint get b add off 2 |
| 2474 | b3 = uint get b add off 3 |
| 2475 | ret or or b0 shl b1 8 or shl b2 16 shl b3 24 |
| 2476 | end |
| 2477 | |
| 2478 | note run_git_pkt: runs pkt[0..plen), reads stdout into gitout[0..outlen). |
| 2479 | note Returns outlen if exit==0, else -1 (sets status!=0). |
| 2480 | fn run_git_pkt plen ulong quiet_err ulong to long |
| 2481 | fds = new uchar 8 0 |
| 2482 | if ne pipefds fds 0 8 0 0 |
| 2483 | die_t t_die_pipe |
| 2484 | end |
| 2485 | rfd = int read_u32_le fds 0 |
| 2486 | wfd = int read_u32_le fds 4 |
| 2487 | pid = fork |
| 2488 | if lt pid 0 |
| 2489 | _c1 = fclose rfd |
| 2490 | _c2 = fclose wfd |
| 2491 | die_t t_die_fork |
| 2492 | end |
| 2493 | if eq pid 0 |
| 2494 | _c1 = fclose rfd |
| 2495 | _d1 = dupfd wfd 1 0 |
| 2496 | _c2 = fclose wfd |
| 2497 | if ne quiet_err 0 |
| 2498 | dn = fopen t_devnull 0 len t_devnull 1 0 |
| 2499 | if ge dn 0 |
| 2500 | _d2 = dupfd int dn 2 0 |
| 2501 | _c3 = fclose int dn |
| 2502 | end |
| 2503 | end |
| 2504 | _ex = execprog pkt 0 plen |
| 2505 | exit 127 |
| 2506 | end |
| 2507 | _c2 = fclose wfd |
| 2508 | cap = get gitout_cap 0 |
| 2509 | if eq cap 0 |
| 2510 | cap = 65536 |
| 2511 | _e = enlarge gitout cap |
| 2512 | if lt _e 0 |
| 2513 | die_t t_die_oom |
| 2514 | end |
| 2515 | put gitout_cap 0 cap |
| 2516 | end |
| 2517 | n = ulong 0 |
| 2518 | while true bound 1000000000 |
| 2519 | if ge add n 4096 cap |
| 2520 | cap = mul cap 2 |
| 2521 | _e = enlarge gitout cap |
| 2522 | if lt _e 0 |
| 2523 | die_t t_die_oom |
| 2524 | end |
| 2525 | put gitout_cap 0 cap |
| 2526 | end |
| 2527 | k = read rfd gitout n sub cap n |
| 2528 | if le k 0 |
| 2529 | break |
| 2530 | end |
| 2531 | n = add n ulong k |
| 2532 | end |
| 2533 | _c1 = fclose rfd |
| 2534 | st = new uchar 8 0 |
| 2535 | _w = waitpid int pid st 0 4 0 |
| 2536 | wcode = read_u32_le st 0 |
| 2537 | if ne wcode 0 |
| 2538 | ret -1 |
| 2539 | end |
| 2540 | ret long n |
| 2541 | end |
| 2542 | |
| 2543 | fn parse_git_flist gl ulong to ulong |
| 2544 | nf = ulong 0 |
| 2545 | fcap = get flist_cap 0 |
| 2546 | if eq fcap 0 |
| 2547 | fcap = 4096 |
| 2548 | _e1 = enlarge flist_o fcap |
| 2549 | _e2 = enlarge flist_l fcap |
| 2550 | put flist_cap 0 fcap |
| 2551 | end |
| 2552 | start = ulong 0 |
| 2553 | for i ulong gl bound 1000000000 |
| 2554 | if eq get gitout i 0 |
| 2555 | fl = sub i start |
| 2556 | if gt fl 0 |
| 2557 | po = sp_add_git start fl |
| 2558 | if not excluded po fl |
| 2559 | if ge nf fcap |
| 2560 | fcap = mul fcap 2 |
| 2561 | _e1 = enlarge flist_o fcap |
| 2562 | _e2 = enlarge flist_l fcap |
| 2563 | put flist_cap 0 fcap |
| 2564 | end |
| 2565 | put flist_o nf po |
| 2566 | put flist_l nf fl |
| 2567 | nf = add nf 1 |
| 2568 | end |
| 2569 | end |
| 2570 | start = add i 1 |
| 2571 | end |
| 2572 | end |
| 2573 | ret nf |
| 2574 | end |
| 2575 | |
| 2576 | fn scan_repo r ulong to void |
| 2577 | ro = get defp_o r |
| 2578 | rl = get defp_l r |
| 2579 | pkt_put16 0 5 |
| 2580 | p = ulong 2 |
| 2581 | p = pkt_add_t p t_git |
| 2582 | p = pkt_add_t p t_dashC |
| 2583 | p = pkt_add_sp p ro rl |
| 2584 | p = pkt_add_t p t_revparse |
| 2585 | p = pkt_add_t p t_HEAD |
| 2586 | hn = run_git_pkt p 1 |
| 2587 | if lt hn 0 |
| 2588 | put rskip r 1 |
| 2589 | ret |
| 2590 | end |
| 2591 | hl = ulong hn |
| 2592 | while gt hl 0 bound 256 |
| 2593 | c = get gitout sub hl 1 |
| 2594 | if or eq c 10 eq c 13 |
| 2595 | hl = sub hl 1 |
| 2596 | else |
| 2597 | break |
| 2598 | end |
| 2599 | end |
| 2600 | if eq hl 0 |
| 2601 | put rskip r 1 |
| 2602 | ret |
| 2603 | end |
| 2604 | put head_o r sp_add_git 0 hl |
| 2605 | put head_l r hl |
| 2606 | |
| 2607 | pkt_put16 0 9 |
| 2608 | p = 2 |
| 2609 | p = pkt_add_t p t_git |
| 2610 | p = pkt_add_t p t_dashC |
| 2611 | p = pkt_add_sp p ro rl |
| 2612 | p = pkt_add_t p t_lsfiles |
| 2613 | p = pkt_add_t p t_dashz |
| 2614 | p = pkt_add_t p t_dashdash |
| 2615 | p = pkt_add_t p t_glob_c |
| 2616 | p = pkt_add_t p t_glob_h |
| 2617 | p = pkt_add_t p t_glob_rs |
| 2618 | gn = run_git_pkt p 0 |
| 2619 | if lt gn 0 |
| 2620 | die_sp t_die_gitls ro rl |
| 2621 | end |
| 2622 | nf = parse_git_flist ulong gn |
| 2623 | for i ulong nf bound 1000000000 |
| 2624 | scan_file r ro rl get flist_o i get flist_l i |
| 2625 | end |
| 2626 | end |
| 2627 | |
| 2628 | note ---- map parsing ---- |
| 2629 | fn trim_span off0 ulong n0 ulong to ulong |
| 2630 | note returns packed (new_off << 32) | new_len in mrow_tmp |
| 2631 | a = off0 |
| 2632 | b = add off0 n0 |
| 2633 | while lt a b bound 16384 |
| 2634 | c = get mrow_tmp a |
| 2635 | if or eq c 32 eq c 9 |
| 2636 | a = add a 1 |
| 2637 | else |
| 2638 | break |
| 2639 | end |
| 2640 | end |
| 2641 | while gt b a bound 16384 |
| 2642 | c = get mrow_tmp sub b 1 |
| 2643 | if or eq c 32 or eq c 9 or eq c 13 eq c 10 |
| 2644 | b = sub b 1 |
| 2645 | else |
| 2646 | break |
| 2647 | end |
| 2648 | end |
| 2649 | ret or shl a 32 sub b a |
| 2650 | end |
| 2651 | |
| 2652 | fn untick_span off0 ulong n0 ulong to ulong |
| 2653 | t = trim_span off0 n0 |
| 2654 | a = shr t 32 |
| 2655 | l = and t 4294967295 |
| 2656 | while ge l 2 bound 64 |
| 2657 | if ne get mrow_tmp a 96 |
| 2658 | break |
| 2659 | end |
| 2660 | if ne get mrow_tmp add a sub l 1 96 |
| 2661 | break |
| 2662 | end |
| 2663 | a = add a 1 |
| 2664 | l = sub l 2 |
| 2665 | end |
| 2666 | ret trim_span a l |
| 2667 | end |
| 2668 | |
| 2669 | fn split_md_row line_off ulong line_len ulong to ulong |
| 2670 | p = ulong 0 |
| 2671 | while lt p line_len bound 16384 |
| 2672 | if ne get mapbuf add line_off p 32 |
| 2673 | break |
| 2674 | end |
| 2675 | p = add p 1 |
| 2676 | end |
| 2677 | if ge p line_len |
| 2678 | ret 0 |
| 2679 | end |
| 2680 | if ne get mapbuf add line_off p 124 |
| 2681 | ret 0 |
| 2682 | end |
| 2683 | p = add p 1 |
| 2684 | nc = ulong 0 |
| 2685 | w = ulong 0 |
| 2686 | cstart = ulong 0 |
| 2687 | while lt p line_len bound 16384 |
| 2688 | c = get mapbuf add line_off p |
| 2689 | if eq c 92 |
| 2690 | if lt add p 1 line_len |
| 2691 | if eq get mapbuf add line_off add p 1 124 |
| 2692 | put mrow_tmp w 124 |
| 2693 | w = add w 1 |
| 2694 | p = add p 2 |
| 2695 | continue |
| 2696 | end |
| 2697 | end |
| 2698 | end |
| 2699 | if eq c 124 |
| 2700 | if lt nc 16 |
| 2701 | put mcells_o nc cstart |
| 2702 | put mcells_l nc sub w cstart |
| 2703 | nc = add nc 1 |
| 2704 | end |
| 2705 | p = add p 1 |
| 2706 | cstart = w |
| 2707 | continue |
| 2708 | end |
| 2709 | put mrow_tmp w c |
| 2710 | w = add w 1 |
| 2711 | p = add p 1 |
| 2712 | end |
| 2713 | ret nc |
| 2714 | end |
| 2715 | |
| 2716 | fn mapbuf_at_t off0 ulong t view uchar * to bool |
| 2717 | tl = len t |
| 2718 | for j ulong tl bound 256 |
| 2719 | if ne get mapbuf add off0 j get t j |
| 2720 | ret false |
| 2721 | end |
| 2722 | end |
| 2723 | ret true |
| 2724 | end |
| 2725 | |
| 2726 | fn mapline_has off0 ulong n0 ulong t view uchar * to bool |
| 2727 | tl = len t |
| 2728 | if lt n0 tl |
| 2729 | ret false |
| 2730 | end |
| 2731 | lim = add sub n0 tl 1 |
| 2732 | for i ulong lim bound 16384 |
| 2733 | if mapbuf_at_t add off0 i t |
| 2734 | ret true |
| 2735 | end |
| 2736 | end |
| 2737 | ret false |
| 2738 | end |
| 2739 | |
| 2740 | fn norm_row_ev base ulong to void |
| 2741 | eo0 = get rw_off add base 10 |
| 2742 | el0 = get rw_len add base 10 |
| 2743 | eno = get sp_len 0 |
| 2744 | enl = norm_ws_sp eo0 el0 |
| 2745 | put rw_off add base 10 eno |
| 2746 | put rw_len add base 10 enl |
| 2747 | end |
| 2748 | |
| 2749 | fn load_map_row nc ulong lineno ulong to void |
| 2750 | if lt nc 11 |
| 2751 | eput_t t_e_maperr |
| 2752 | eput_u lineno |
| 2753 | eput_t t_e_maperr2 |
| 2754 | eput_u nc |
| 2755 | eput_t t_e_maperr3 |
| 2756 | put map_err 0 add get map_err 0 1 |
| 2757 | ret |
| 2758 | end |
| 2759 | nr = get nrows 0 |
| 2760 | if ge nr MAX_ROWS |
| 2761 | die_t t_die_oom |
| 2762 | end |
| 2763 | base = mul nr 11 |
| 2764 | for c ulong 11 bound 12 |
| 2765 | uc = untick_span get mcells_o c get mcells_l c |
| 2766 | fl = and uc 4294967295 |
| 2767 | fo = sp_add_mrow shr uc 32 fl |
| 2768 | put rw_off add base c fo |
| 2769 | put rw_len add base c fl |
| 2770 | end |
| 2771 | norm_row_ev base |
| 2772 | ri = repo_index get rw_off add base 1 get rw_len add base 1 |
| 2773 | put rw_ridx nr ri |
| 2774 | put rw_hits nr 0 |
| 2775 | if lt ri 0 |
| 2776 | eput_t t_e_maperr |
| 2777 | eput_u lineno |
| 2778 | eput_t t_e_mapunk |
| 2779 | eput_sp get rw_off add base 1 get rw_len add base 1 |
| 2780 | eputc 39 |
| 2781 | eputc 10 |
| 2782 | put map_err 0 add get map_err 0 1 |
| 2783 | end |
| 2784 | put nrows 0 add nr 1 |
| 2785 | end |
| 2786 | |
| 2787 | fn rw_field_eq bi ulong bj ulong f ulong to bool |
| 2788 | ao = get rw_off add bi f |
| 2789 | al = get rw_len add bi f |
| 2790 | bo = get rw_off add bj f |
| 2791 | bl = get rw_len add bj f |
| 2792 | ret sp_eq ao al bo bl |
| 2793 | end |
| 2794 | |
| 2795 | fn rows_dup_key i ulong j ulong to bool |
| 2796 | if ne get rw_ridx i get rw_ridx j |
| 2797 | ret false |
| 2798 | end |
| 2799 | bi = mul i 11 |
| 2800 | bj = mul j 11 |
| 2801 | if not rw_field_eq bi bj 2 |
| 2802 | ret false |
| 2803 | end |
| 2804 | if not rw_field_eq bi bj 4 |
| 2805 | ret false |
| 2806 | end |
| 2807 | ret rw_field_eq bi bj 10 |
| 2808 | end |
| 2809 | |
| 2810 | fn check_map_dups to void |
| 2811 | nr = get nrows 0 |
| 2812 | for i ulong nr bound 8192 |
| 2813 | j = add i 1 |
| 2814 | while lt j nr bound 8192 |
| 2815 | if rows_dup_key i j |
| 2816 | bi = mul i 11 |
| 2817 | bj = mul j 11 |
| 2818 | eput_t t_e_mapdup |
| 2819 | eput_sp get rw_off bi get rw_len bi |
| 2820 | eput_t t_e_and |
| 2821 | eput_sp get rw_off bj get rw_len bj |
| 2822 | eputc 10 |
| 2823 | put map_err 0 add get map_err 0 1 |
| 2824 | end |
| 2825 | j = add j 1 |
| 2826 | end |
| 2827 | end |
| 2828 | end |
| 2829 | |
| 2830 | fn load_map_sha nc ulong to void |
| 2831 | if lt nc 2 |
| 2832 | ret |
| 2833 | end |
| 2834 | u0 = untick_span get mcells_o 0 get mcells_l 0 |
| 2835 | r0l = and u0 4294967295 |
| 2836 | r0o = sp_add_mrow shr u0 32 r0l |
| 2837 | ri = repo_index r0o r0l |
| 2838 | if ge ri 0 |
| 2839 | u1 = untick_span get mcells_o 1 get mcells_l 1 |
| 2840 | s1l = and u1 4294967295 |
| 2841 | s1o = sp_add_mrow shr u1 32 s1l |
| 2842 | put msha_o ulong ri s1o |
| 2843 | put msha_l ulong ri s1l |
| 2844 | end |
| 2845 | end |
| 2846 | |
| 2847 | fn read_map_file mo ulong ml ulong to ulong |
| 2848 | for i ulong ml bound 4096 |
| 2849 | put tmp1 i get sp add mo i |
| 2850 | end |
| 2851 | fd = fopen tmp1 0 ml 0 0 |
| 2852 | if lt fd 0 |
| 2853 | die_sp t_die_map mo ml |
| 2854 | end |
| 2855 | cap = get mapbuf_cap 0 |
| 2856 | if eq cap 0 |
| 2857 | cap = 65536 |
| 2858 | _e = enlarge mapbuf cap |
| 2859 | put mapbuf_cap 0 cap |
| 2860 | end |
| 2861 | n = ulong 0 |
| 2862 | while true bound 1000000000 |
| 2863 | if ge add n 4096 cap |
| 2864 | cap = mul cap 2 |
| 2865 | _e = enlarge mapbuf cap |
| 2866 | put mapbuf_cap 0 cap |
| 2867 | end |
| 2868 | k = read int fd mapbuf n sub cap n |
| 2869 | if le k 0 |
| 2870 | break |
| 2871 | end |
| 2872 | n = add n ulong k |
| 2873 | end |
| 2874 | _c = fclose int fd |
| 2875 | ret n |
| 2876 | end |
| 2877 | |
| 2878 | fn load_map mo ulong ml ulong to void |
| 2879 | n = read_map_file mo ml |
| 2880 | mode = ulong 0 |
| 2881 | lineno = ulong 0 |
| 2882 | pos = ulong 0 |
| 2883 | while lt pos n bound 1000000000 |
| 2884 | ls = pos |
| 2885 | while lt pos n bound 1000000000 |
| 2886 | if eq get mapbuf pos 10 |
| 2887 | pos = add pos 1 |
| 2888 | break |
| 2889 | end |
| 2890 | pos = add pos 1 |
| 2891 | end |
| 2892 | ll = sub pos ls |
| 2893 | lineno = add lineno 1 |
| 2894 | if mapline_has ls ll t_m_shas |
| 2895 | mode = 1 |
| 2896 | continue |
| 2897 | end |
| 2898 | if mapline_has ls ll t_m_rows |
| 2899 | mode = 2 |
| 2900 | continue |
| 2901 | end |
| 2902 | if mapline_has ls ll t_m_end |
| 2903 | mode = 0 |
| 2904 | continue |
| 2905 | end |
| 2906 | if eq mode 0 |
| 2907 | continue |
| 2908 | end |
| 2909 | if mapline_has ls ll t_m_sep |
| 2910 | continue |
| 2911 | end |
| 2912 | if mapline_has ls ll t_m_hdr1 |
| 2913 | continue |
| 2914 | end |
| 2915 | if mapline_has ls ll t_m_hdr2 |
| 2916 | continue |
| 2917 | end |
| 2918 | nc = split_md_row ls ll |
| 2919 | if eq nc 0 |
| 2920 | continue |
| 2921 | end |
| 2922 | if eq mode 1 |
| 2923 | load_map_sha nc |
| 2924 | continue |
| 2925 | end |
| 2926 | if eq mode 2 |
| 2927 | load_map_row nc lineno |
| 2928 | end |
| 2929 | end |
| 2930 | check_map_dups |
| 2931 | end |
| 2932 | |
| 2933 | note ---- class / idiom / wait / manual helpers ---- |
| 2934 | fn class_ok co ulong cl ulong to bool |
| 2935 | if ne cl 1 |
| 2936 | ret false |
| 2937 | end |
| 2938 | c = get sp co |
| 2939 | if ge c 65 |
| 2940 | if le c 70 |
| 2941 | ret true |
| 2942 | end |
| 2943 | end |
| 2944 | if eq c 78 |
| 2945 | ret true |
| 2946 | end |
| 2947 | ret false |
| 2948 | end |
| 2949 | |
| 2950 | fn class_idx co ulong cl ulong to ulong |
| 2951 | if ne cl 1 |
| 2952 | ret 7 |
| 2953 | end |
| 2954 | c = get sp co |
| 2955 | if ge c 65 |
| 2956 | if le c 70 |
| 2957 | ret ulong sub c 65 |
| 2958 | end |
| 2959 | end |
| 2960 | if eq c 78 |
| 2961 | ret 6 |
| 2962 | end |
| 2963 | ret 7 |
| 2964 | end |
| 2965 | |
| 2966 | fn check_n_reason ro ulong rl ulong to bool |
| 2967 | n = rl |
| 2968 | if gt n 2047 |
| 2969 | n = 2047 |
| 2970 | end |
| 2971 | for i ulong n bound 2048 |
| 2972 | put tmp1 i to_lower get sp add ro i |
| 2973 | end |
| 2974 | if tmp1_has_t n t_id0 |
| 2975 | ret true |
| 2976 | end |
| 2977 | if tmp1_has_t n t_id1 |
| 2978 | ret true |
| 2979 | end |
| 2980 | if tmp1_has_t n t_id2 |
| 2981 | ret true |
| 2982 | end |
| 2983 | if tmp1_has_t n t_id3 |
| 2984 | ret true |
| 2985 | end |
| 2986 | if tmp1_has_t n t_id4 |
| 2987 | ret true |
| 2988 | end |
| 2989 | if tmp1_has_t n t_id5 |
| 2990 | ret true |
| 2991 | end |
| 2992 | if tmp1_has_t n t_id6 |
| 2993 | ret true |
| 2994 | end |
| 2995 | if tmp1_has_t n t_id7 |
| 2996 | ret true |
| 2997 | end |
| 2998 | if tmp1_has_t n t_id8 |
| 2999 | ret true |
| 3000 | end |
| 3001 | if tmp1_has_t n t_id9 |
| 3002 | ret true |
| 3003 | end |
| 3004 | if tmp1_has_t n t_id10 |
| 3005 | ret true |
| 3006 | end |
| 3007 | if tmp1_has_t n t_id11 |
| 3008 | ret true |
| 3009 | end |
| 3010 | if tmp1_has_t n t_id12 |
| 3011 | ret true |
| 3012 | end |
| 3013 | if tmp1_has_t n t_id13 |
| 3014 | ret true |
| 3015 | end |
| 3016 | if tmp1_has_t n t_id14 |
| 3017 | ret true |
| 3018 | end |
| 3019 | if tmp1_has_t n t_id15 |
| 3020 | ret true |
| 3021 | end |
| 3022 | if tmp1_has_t n t_id16 |
| 3023 | ret true |
| 3024 | end |
| 3025 | ret false |
| 3026 | end |
| 3027 | |
| 3028 | fn trigger_has_wait tro ulong tl ulong to bool |
| 3029 | if sp_has_t tro tl t_bw_sleep |
| 3030 | ret true |
| 3031 | end |
| 3032 | if sp_has_t tro tl t_bw_usleep |
| 3033 | ret true |
| 3034 | end |
| 3035 | if sp_has_t tro tl t_bw_nanosleep |
| 3036 | ret true |
| 3037 | end |
| 3038 | if sp_has_t tro tl t_bw_msleep |
| 3039 | ret true |
| 3040 | end |
| 3041 | if sp_has_t tro tl t_bw_poll |
| 3042 | ret true |
| 3043 | end |
| 3044 | if sp_has_t tro tl t_bw_wait |
| 3045 | ret true |
| 3046 | end |
| 3047 | ret false |
| 3048 | end |
| 3049 | |
| 3050 | fn orig_has_line n ulong eo ulong el ulong to bool |
| 3051 | pos = ulong 0 |
| 3052 | while lt pos n bound 1000000000 |
| 3053 | ls = pos |
| 3054 | while lt pos n bound 1000000000 |
| 3055 | if eq get orig pos 10 |
| 3056 | pos = add pos 1 |
| 3057 | break |
| 3058 | end |
| 3059 | pos = add pos 1 |
| 3060 | end |
| 3061 | le_p = pos |
| 3062 | while gt le_p ls bound 4 |
| 3063 | c = get orig sub le_p 1 |
| 3064 | if or eq c 10 eq c 13 |
| 3065 | le_p = sub le_p 1 |
| 3066 | else |
| 3067 | break |
| 3068 | end |
| 3069 | end |
| 3070 | no = get sp_len 0 |
| 3071 | nl = norm_ws_orig ls sub le_p ls |
| 3072 | if sp_eq no nl eo el |
| 3073 | ret true |
| 3074 | end |
| 3075 | end |
| 3076 | ret false |
| 3077 | end |
| 3078 | |
| 3079 | fn manual_present ro ulong rl ulong po ulong pl ulong eo ulong el ulong to bool |
| 3080 | plen = build_path_tmp1 ro rl po pl |
| 3081 | rn = read_file_orig plen |
| 3082 | if lt rn 0 |
| 3083 | ret false |
| 3084 | end |
| 3085 | ret orig_has_line ulong rn eo el |
| 3086 | end |
| 3087 | |
| 3088 | note ---- JSON & Markdown output helpers ---- |
| 3089 | fn oput_jstr_sp off ulong n ulong to void |
| 3090 | oputc 34 |
| 3091 | for i ulong n bound 1000000000 |
| 3092 | c = get sp add off i |
| 3093 | if or eq c 34 eq c 92 |
| 3094 | oputc 92 |
| 3095 | oputc c |
| 3096 | else |
| 3097 | if lt c 32 |
| 3098 | oputc 92 |
| 3099 | oputc 117 |
| 3100 | oputc 48 |
| 3101 | oputc 48 |
| 3102 | oputc get t_hex ulong shr c 4 |
| 3103 | oputc get t_hex ulong and c 15 |
| 3104 | else |
| 3105 | oputc c |
| 3106 | end |
| 3107 | end |
| 3108 | end |
| 3109 | oputc 34 |
| 3110 | end |
| 3111 | |
| 3112 | fn oput_mdcell_sp off ulong n ulong tick ulong to void |
| 3113 | has_bt = false |
| 3114 | if ne tick 0 |
| 3115 | for i ulong n bound 1000000000 |
| 3116 | if eq get sp add off i 96 |
| 3117 | has_bt = true |
| 3118 | break |
| 3119 | end |
| 3120 | end |
| 3121 | if has_bt |
| 3122 | oput_t t_bt2_l |
| 3123 | else |
| 3124 | oput_t t_bt1 |
| 3125 | end |
| 3126 | end |
| 3127 | for i ulong n bound 1000000000 |
| 3128 | c = get sp add off i |
| 3129 | if eq c 124 |
| 3130 | oput_t t_esc_pipe |
| 3131 | else |
| 3132 | oputc c |
| 3133 | end |
| 3134 | end |
| 3135 | if ne tick 0 |
| 3136 | if has_bt |
| 3137 | oput_t t_bt2_r |
| 3138 | else |
| 3139 | oput_t t_bt1 |
| 3140 | end |
| 3141 | end |
| 3142 | end |
| 3143 | |
| 3144 | note ---- environment lookup ---- |
| 3145 | fn sp_add_tmp1_from off0 ulong vl ulong to ulong |
| 3146 | sp_reserve vl |
| 3147 | vo = get sp_len 0 |
| 3148 | for j ulong vl bound 8192 |
| 3149 | put sp add vo j get tmp1 add off0 j |
| 3150 | end |
| 3151 | put sp_len 0 add vo vl |
| 3152 | ret vo |
| 3153 | end |
| 3154 | |
| 3155 | fn env_get name view uchar * to long |
| 3156 | ec = envcnt |
| 3157 | if lt ec 0 |
| 3158 | ret -1 |
| 3159 | end |
| 3160 | nl = len name |
| 3161 | for i ulong ulong ec bound 4096 |
| 3162 | r = envread i tmp1 0 8192 |
| 3163 | if le r 0 |
| 3164 | continue |
| 3165 | end |
| 3166 | rl = ulong r |
| 3167 | if gt rl nl |
| 3168 | if eq get tmp1 nl 61 |
| 3169 | if tmp1_at_t 0 name |
| 3170 | vl = sub sub rl nl 1 |
| 3171 | vo = sp_add_tmp1_from add nl 1 vl |
| 3172 | ret long or shl vo 32 vl |
| 3173 | end |
| 3174 | end |
| 3175 | end |
| 3176 | end |
| 3177 | ret -1 |
| 3178 | end |
| 3179 | |
| 3180 | fn env_get_repo r ulong to long |
| 3181 | if eq r 0 |
| 3182 | ret env_get t_e0 |
| 3183 | end |
| 3184 | if eq r 1 |
| 3185 | ret env_get t_e1 |
| 3186 | end |
| 3187 | if eq r 2 |
| 3188 | ret env_get t_e2 |
| 3189 | end |
| 3190 | if eq r 3 |
| 3191 | ret env_get t_e3 |
| 3192 | end |
| 3193 | ret env_get t_e4 |
| 3194 | end |
| 3195 | |
| 3196 | note ---- skeleton & json emitters ---- |
| 3197 | fn emit_skeleton to void |
| 3198 | oput_t t_skel_hdr |
| 3199 | ns = get nsites 0 |
| 3200 | for i ulong ns bound 16384 |
| 3201 | row = get st_row i |
| 3202 | oput_t t_sp_pipe |
| 3203 | if ge row 0 |
| 3204 | b = mul ulong row 11 |
| 3205 | oput_sp get rw_off b get rw_len b |
| 3206 | else |
| 3207 | oput_t t_new |
| 3208 | end |
| 3209 | oput_t t_pipe_sp |
| 3210 | oput_repo get st_repo i |
| 3211 | oput_t t_pipe_sp |
| 3212 | oput_mdcell_sp get st_po i get st_pl i 1 |
| 3213 | oput_t t_pipe_sp |
| 3214 | oput_sp get st_lo i get st_ll i |
| 3215 | oput_t t_pipe_sp |
| 3216 | oput_mdcell_sp get st_so i get st_sl i 1 |
| 3217 | oput_t t_pipe_sp |
| 3218 | if ge row 0 |
| 3219 | b = mul ulong row 11 |
| 3220 | oput_sp get rw_off add b 5 get rw_len add b 5 |
| 3221 | oput_t t_pipe_sp |
| 3222 | oput_sp get rw_off add b 6 get rw_len add b 6 |
| 3223 | oput_t t_pipe_sp |
| 3224 | oput_sp get rw_off add b 7 get rw_len add b 7 |
| 3225 | oput_t t_pipe_sp |
| 3226 | oput_sp get rw_off add b 8 get rw_len add b 8 |
| 3227 | oput_t t_pipe_sp |
| 3228 | oput_mdcell_sp get rw_off add b 9 get rw_len add b 9 0 |
| 3229 | else |
| 3230 | oput_sp get st_to i get st_tl i |
| 3231 | oput_t t_pipe_sp |
| 3232 | oput_t t_qmark |
| 3233 | oput_t t_pipe_sp |
| 3234 | oput_t t_qmark |
| 3235 | oput_t t_pipe_sp |
| 3236 | oput_t t_qmark |
| 3237 | oput_t t_pipe_sp |
| 3238 | oput_t t_qmark |
| 3239 | end |
| 3240 | oput_t t_pipe_sp |
| 3241 | oput_mdcell_sp get st_eo i get st_el i 1 |
| 3242 | oput_t t_pipe_nl |
| 3243 | end |
| 3244 | oflush |
| 3245 | eflush |
| 3246 | end |
| 3247 | |
| 3248 | fn emit_json_repos to void |
| 3249 | for r ulong NREPO bound 6 |
| 3250 | oput_t t_json_r1 |
| 3251 | oput_repo r |
| 3252 | oput_t t_json_r2 |
| 3253 | oput_jstr_sp get defp_o r get defp_l r |
| 3254 | oput_t t_json_r3 |
| 3255 | oput_jstr_sp get head_o r get head_l r |
| 3256 | oput_t t_json_r4 |
| 3257 | oput_jstr_sp get msha_o r get msha_l r |
| 3258 | oput_t t_json_r5 |
| 3259 | if ne get rskip r 0 |
| 3260 | oput_t t_SKIPPED |
| 3261 | else |
| 3262 | oput_t t_SCANNED |
| 3263 | end |
| 3264 | oput_t t_json_r6 |
| 3265 | for c ulong NCLASS bound 10 |
| 3266 | if gt c 0 |
| 3267 | oputc 44 |
| 3268 | oputc 32 |
| 3269 | end |
| 3270 | oputc 34 |
| 3271 | oputc get t_cls_chars c |
| 3272 | oputc 34 |
| 3273 | oputc 58 |
| 3274 | oputc 32 |
| 3275 | oput_u get percls add mul r 8 c |
| 3276 | end |
| 3277 | oput_t t_json_r7 |
| 3278 | for t ulong 13 bound 16 |
| 3279 | if gt t 0 |
| 3280 | oputc 44 |
| 3281 | oputc 32 |
| 3282 | end |
| 3283 | oputc 34 |
| 3284 | oput_term t |
| 3285 | oputc 34 |
| 3286 | oputc 58 |
| 3287 | oputc 32 |
| 3288 | oput_u get thits add mul r 32 t |
| 3289 | end |
| 3290 | for t ulong 3 bound 4 |
| 3291 | oputc 44 |
| 3292 | oputc 32 |
| 3293 | oputc 34 |
| 3294 | oput_named t |
| 3295 | oputc 34 |
| 3296 | oputc 58 |
| 3297 | oputc 32 |
| 3298 | oput_u get nhits add mul r 8 t |
| 3299 | end |
| 3300 | oputc 125 |
| 3301 | oputc 125 |
| 3302 | if lt add r 1 NREPO |
| 3303 | oputc 44 |
| 3304 | end |
| 3305 | oputc 10 |
| 3306 | end |
| 3307 | end |
| 3308 | |
| 3309 | fn emit_json_sites to void |
| 3310 | ns = get nsites 0 |
| 3311 | for i ulong ns bound 16384 |
| 3312 | row = get st_row i |
| 3313 | oput_t t_json_s1 |
| 3314 | oput_repo get st_repo i |
| 3315 | oput_t t_json_s2 |
| 3316 | oput_jstr_sp get st_po i get st_pl i |
| 3317 | oput_t t_json_s3 |
| 3318 | oput_sp get st_lo i get st_ll i |
| 3319 | oput_t t_json_s4 |
| 3320 | oput_jstr_sp get st_so i get st_sl i |
| 3321 | oput_t t_json_s5 |
| 3322 | oput_jstr_sp get st_to i get st_tl i |
| 3323 | oput_t t_json_s6 |
| 3324 | if ge row 0 |
| 3325 | b = mul ulong row 11 |
| 3326 | oput_jstr_sp get rw_off b get rw_len b |
| 3327 | else |
| 3328 | oput_jstr_sp 0 0 |
| 3329 | end |
| 3330 | oput_t t_json_s7 |
| 3331 | if ge row 0 |
| 3332 | b = mul ulong row 11 |
| 3333 | oput_jstr_sp get rw_off add b 7 get rw_len add b 7 |
| 3334 | else |
| 3335 | oput_jstr_sp 0 0 |
| 3336 | end |
| 3337 | oput_t t_json_s8 |
| 3338 | if ge row 0 |
| 3339 | b = mul ulong row 11 |
| 3340 | oput_jstr_sp get rw_off add b 8 get rw_len add b 8 |
| 3341 | else |
| 3342 | oput_jstr_sp 0 0 |
| 3343 | end |
| 3344 | oput_t t_json_s9 |
| 3345 | oput_jstr_sp get st_eo i get st_el i |
| 3346 | oputc 125 |
| 3347 | if lt add i 1 ns |
| 3348 | oputc 44 |
| 3349 | end |
| 3350 | oputc 10 |
| 3351 | end |
| 3352 | end |
| 3353 | |
| 3354 | note ---- validation counters ---- |
| 3355 | global v_uncls ulong 1 |
| 3356 | global v_qrows ulong 1 |
| 3357 | global v_badcls ulong 1 |
| 3358 | global v_areach ulong 1 |
| 3359 | global v_stale ulong 1 |
| 3360 | global v_skipped ulong 1 |
| 3361 | global v_manual ulong 1 |
| 3362 | global v_cntn ulong 1 |
| 3363 | |
| 3364 | fn is_prod_a po ulong pl ulong so ulong sl ulong to bool |
| 3365 | if sp_has_t po pl t_legacy_oracle |
| 3366 | ret false |
| 3367 | end |
| 3368 | if sp_has_t so sl t_legacy_oracle |
| 3369 | ret false |
| 3370 | end |
| 3371 | if sp_has_t po pl t_reference |
| 3372 | ret false |
| 3373 | end |
| 3374 | if sp_has_t so sl t_reference |
| 3375 | ret false |
| 3376 | end |
| 3377 | ret true |
| 3378 | end |
| 3379 | |
| 3380 | fn site_is_prod_a i ulong to bool |
| 3381 | ret is_prod_a get st_po i get st_pl i get st_so i get st_sl i |
| 3382 | end |
| 3383 | |
| 3384 | fn row_is_prod_a b ulong to bool |
| 3385 | po = get rw_off add b 2 |
| 3386 | pl = get rw_len add b 2 |
| 3387 | so = get rw_off add b 4 |
| 3388 | sl = get rw_len add b 4 |
| 3389 | ret is_prod_a po pl so sl |
| 3390 | end |
| 3391 | |
| 3392 | fn validate_sites to void |
| 3393 | ns = get nsites 0 |
| 3394 | for i ulong ns bound 16384 |
| 3395 | row = get st_row i |
| 3396 | if lt row 0 |
| 3397 | put v_uncls 0 add get v_uncls 0 1 |
| 3398 | eput_t t_e_uncls |
| 3399 | eput_repo get st_repo i |
| 3400 | eputc 32 |
| 3401 | eput_sp get st_po i get st_pl i |
| 3402 | eputc 58 |
| 3403 | eput_sp get st_lo i get st_ll i |
| 3404 | eputc 32 |
| 3405 | eputc 91 |
| 3406 | eput_sp get st_so i get st_sl i |
| 3407 | eputc 93 |
| 3408 | eputc 32 |
| 3409 | eput_sp get st_to i get st_tl i |
| 3410 | eput_t t_e_colcol |
| 3411 | eput_sp get st_eo i get st_el i |
| 3412 | eputc 10 |
| 3413 | continue |
| 3414 | end |
| 3415 | b = mul ulong row 11 |
| 3416 | co = get rw_off add b 7 |
| 3417 | cl = get rw_len add b 7 |
| 3418 | if sp_eq_t co cl t_qmark |
| 3419 | put v_qrows 0 add get v_qrows 0 1 |
| 3420 | eput_t t_e_quest |
| 3421 | eput_sp get rw_off b get rw_len b |
| 3422 | eputc 32 |
| 3423 | eput_repo get st_repo i |
| 3424 | eputc 32 |
| 3425 | eput_sp get st_po i get st_pl i |
| 3426 | eputc 58 |
| 3427 | eput_sp get st_lo i get st_ll i |
| 3428 | eput_t t_e_colcol |
| 3429 | eput_sp get rw_off add b 9 get rw_len add b 9 |
| 3430 | eputc 10 |
| 3431 | continue |
| 3432 | end |
| 3433 | if not class_ok co cl |
| 3434 | put v_badcls 0 add get v_badcls 0 1 |
| 3435 | eput_t t_e_badcls |
| 3436 | eput_sp get rw_off b get rw_len b |
| 3437 | eputc 32 |
| 3438 | eputc 39 |
| 3439 | eput_sp co cl |
| 3440 | eputc 39 |
| 3441 | eputc 10 |
| 3442 | continue |
| 3443 | end |
| 3444 | if eq get sp co 78 |
| 3445 | if not check_n_reason get rw_off add b 9 get rw_len add b 9 |
| 3446 | put v_badcls 0 add get v_badcls 0 1 |
| 3447 | eput_t t_e_nnoid |
| 3448 | eput_sp get rw_off b get rw_len b |
| 3449 | eput_t t_e_nnoid2 |
| 3450 | end |
| 3451 | if trigger_has_wait get st_to i get st_tl i |
| 3452 | put v_badcls 0 add get v_badcls 0 1 |
| 3453 | eput_t t_e_nwait |
| 3454 | eput_sp get rw_off b get rw_len b |
| 3455 | eputc 32 |
| 3456 | eputc 91 |
| 3457 | eput_sp get st_to i get st_tl i |
| 3458 | eput_t t_e_nwait2 |
| 3459 | end |
| 3460 | continue |
| 3461 | end |
| 3462 | if and eq get st_repo i 0 eq get sp co 65 |
| 3463 | if site_is_prod_a i |
| 3464 | put v_areach 0 add get v_areach 0 1 |
| 3465 | eput_t t_e_areach |
| 3466 | eput_sp get rw_off b get rw_len b |
| 3467 | eput_t t_e_omega_sp |
| 3468 | eput_sp get st_po i get st_pl i |
| 3469 | eputc 58 |
| 3470 | eput_sp get st_lo i get st_ll i |
| 3471 | eputc 32 |
| 3472 | eputc 91 |
| 3473 | eput_sp get st_so i get st_sl i |
| 3474 | eput_t t_e_areach2 |
| 3475 | end |
| 3476 | end |
| 3477 | end |
| 3478 | end |
| 3479 | |
| 3480 | fn validate_manual_and_stale to void |
| 3481 | nr = get nrows 0 |
| 3482 | for j ulong nr bound 8192 |
| 3483 | ri = get rw_ridx j |
| 3484 | if lt ri 0 |
| 3485 | continue |
| 3486 | end |
| 3487 | if ne get rskip ulong ri 0 |
| 3488 | continue |
| 3489 | end |
| 3490 | b = mul j 11 |
| 3491 | if ne get rw_hits j 0 |
| 3492 | if sp_starts_t get rw_off add b 3 get rw_len add b 3 t_manual |
| 3493 | co = get rw_off add b 7 |
| 3494 | cl = get rw_len add b 7 |
| 3495 | if sp_eq_t co cl t_qmark |
| 3496 | put v_qrows 0 add get v_qrows 0 1 |
| 3497 | eput_t t_e_quest |
| 3498 | eput_sp get rw_off b get rw_len b |
| 3499 | eputc 32 |
| 3500 | eput_sp get rw_off add b 1 get rw_len add b 1 |
| 3501 | eputc 32 |
| 3502 | eput_sp get rw_off add b 2 get rw_len add b 2 |
| 3503 | eput_t t_e_manual_sp |
| 3504 | eput_sp get rw_off add b 9 get rw_len add b 9 |
| 3505 | eputc 10 |
| 3506 | continue |
| 3507 | end |
| 3508 | if not class_ok co cl |
| 3509 | put v_badcls 0 add get v_badcls 0 1 |
| 3510 | eput_t t_e_badcls |
| 3511 | eput_sp get rw_off b get rw_len b |
| 3512 | eputc 32 |
| 3513 | eputc 39 |
| 3514 | eput_sp co cl |
| 3515 | eputc 39 |
| 3516 | eputc 10 |
| 3517 | continue |
| 3518 | end |
| 3519 | if eq get sp co 78 |
| 3520 | if not check_n_reason get rw_off add b 9 get rw_len add b 9 |
| 3521 | put v_badcls 0 add get v_badcls 0 1 |
| 3522 | eput_t t_e_nnoid |
| 3523 | eput_sp get rw_off b get rw_len b |
| 3524 | eput_t t_e_nnoid_m |
| 3525 | end |
| 3526 | continue |
| 3527 | end |
| 3528 | if and eq ri 0 eq get sp co 65 |
| 3529 | if row_is_prod_a b |
| 3530 | put v_areach 0 add get v_areach 0 1 |
| 3531 | eput_t t_e_areach |
| 3532 | eput_sp get rw_off b get rw_len b |
| 3533 | eput_t t_e_omega_sp |
| 3534 | eput_sp get rw_off add b 2 get rw_len add b 2 |
| 3535 | eputc 32 |
| 3536 | eputc 91 |
| 3537 | eput_sp get rw_off add b 4 get rw_len add b 4 |
| 3538 | eput_t t_e_areach_m |
| 3539 | end |
| 3540 | end |
| 3541 | end |
| 3542 | end |
| 3543 | end |
| 3544 | for j ulong nr bound 8192 |
| 3545 | ri = get rw_ridx j |
| 3546 | if lt ri 0 |
| 3547 | continue |
| 3548 | end |
| 3549 | if ne get rskip ulong ri 0 |
| 3550 | continue |
| 3551 | end |
| 3552 | if eq get rw_hits j 0 |
| 3553 | b = mul j 11 |
| 3554 | co = get rw_off add b 7 |
| 3555 | cl = get rw_len add b 7 |
| 3556 | is_a = false |
| 3557 | if gt cl 0 |
| 3558 | if eq get sp co 65 |
| 3559 | is_a = true |
| 3560 | end |
| 3561 | end |
| 3562 | if is_a |
| 3563 | eput_t t_e_retgone |
| 3564 | eput_sp get rw_off b get rw_len b |
| 3565 | eputc 32 |
| 3566 | eput_sp get rw_off add b 1 get rw_len add b 1 |
| 3567 | eputc 32 |
| 3568 | eput_sp get rw_off add b 2 get rw_len add b 2 |
| 3569 | eput_t t_e_retgone2 |
| 3570 | else |
| 3571 | put v_stale 0 add get v_stale 0 1 |
| 3572 | eput_t t_e_stale |
| 3573 | eput_sp get rw_off b get rw_len b |
| 3574 | eputc 32 |
| 3575 | eput_sp get rw_off add b 1 get rw_len add b 1 |
| 3576 | eputc 32 |
| 3577 | eput_sp get rw_off add b 2 get rw_len add b 2 |
| 3578 | eputc 32 |
| 3579 | eputc 91 |
| 3580 | eput_sp get rw_off add b 4 get rw_len add b 4 |
| 3581 | eputc 93 |
| 3582 | eput_t t_e_colcol |
| 3583 | eput_sp get rw_off add b 10 get rw_len add b 10 |
| 3584 | eputc 10 |
| 3585 | end |
| 3586 | end |
| 3587 | end |
| 3588 | end |
| 3589 | |
| 3590 | fn rw_sp_eq b ulong f ulong so ulong sl ulong to bool |
| 3591 | ao = get rw_off add b f |
| 3592 | al = get rw_len add b f |
| 3593 | ret sp_eq ao al so sl |
| 3594 | end |
| 3595 | |
| 3596 | fn site_matches_row i ulong j ulong to bool |
| 3597 | if ne get rw_ridx j long get st_repo i |
| 3598 | ret false |
| 3599 | end |
| 3600 | b = mul j 11 |
| 3601 | if not rw_sp_eq b 2 get st_po i get st_pl i |
| 3602 | ret false |
| 3603 | end |
| 3604 | if not rw_sp_eq b 4 get st_so i get st_sl i |
| 3605 | ret false |
| 3606 | end |
| 3607 | ret rw_sp_eq b 10 get st_eo i get st_el i |
| 3608 | end |
| 3609 | |
| 3610 | fn manual_present_row ur ulong b ulong to bool |
| 3611 | po = get rw_off add b 2 |
| 3612 | pl = get rw_len add b 2 |
| 3613 | eo = get rw_off add b 10 |
| 3614 | el = get rw_len add b 10 |
| 3615 | ret manual_present get defp_o ur get defp_l ur po pl eo el |
| 3616 | end |
| 3617 | |
| 3618 | fn join_sites_and_manual to void |
| 3619 | ns = get nsites 0 |
| 3620 | nr = get nrows 0 |
| 3621 | for i ulong ns bound 16384 |
| 3622 | for j ulong nr bound 8192 |
| 3623 | if site_matches_row i j |
| 3624 | put st_row i long j |
| 3625 | put rw_hits j add get rw_hits j 1 |
| 3626 | break |
| 3627 | end |
| 3628 | end |
| 3629 | end |
| 3630 | for j ulong nr bound 8192 |
| 3631 | ri = get rw_ridx j |
| 3632 | if lt ri 0 |
| 3633 | continue |
| 3634 | end |
| 3635 | if ne get rskip ulong ri 0 |
| 3636 | continue |
| 3637 | end |
| 3638 | b = mul j 11 |
| 3639 | if not sp_starts_t get rw_off add b 3 get rw_len add b 3 t_manual |
| 3640 | continue |
| 3641 | end |
| 3642 | put v_manual 0 add get v_manual 0 1 |
| 3643 | if eq get rw_hits j 0 |
| 3644 | ur = ulong ri |
| 3645 | if manual_present_row ur b |
| 3646 | put rw_hits j 1 |
| 3647 | end |
| 3648 | end |
| 3649 | end |
| 3650 | end |
| 3651 | |
| 3652 | fn sp_dup_slice ho ulong hl ulong to ulong |
| 3653 | sp_reserve hl |
| 3654 | po = get sp_len 0 |
| 3655 | for k ulong hl bound 4096 |
| 3656 | put sp add po k get sp add ho k |
| 3657 | end |
| 3658 | put sp_len 0 add po hl |
| 3659 | ret po |
| 3660 | end |
| 3661 | |
| 3662 | fn setup_repo_paths to void |
| 3663 | hm = env_get t_env_home |
| 3664 | ho = ulong 0 |
| 3665 | hl = ulong 0 |
| 3666 | if ge hm 0 |
| 3667 | ho = shr ulong hm 32 |
| 3668 | hl = and ulong hm 4294967295 |
| 3669 | else |
| 3670 | ho = sp_add_t t_dot |
| 3671 | hl = 1 |
| 3672 | end |
| 3673 | for r ulong NREPO bound 6 |
| 3674 | ev = env_get_repo r |
| 3675 | has_ev = false |
| 3676 | if ge ev 0 |
| 3677 | if gt and ulong ev 4294967295 0 |
| 3678 | has_ev = true |
| 3679 | end |
| 3680 | end |
| 3681 | if has_ev |
| 3682 | put defp_o r shr ulong ev 32 |
| 3683 | put defp_l r and ulong ev 4294967295 |
| 3684 | else |
| 3685 | if eq r 0 |
| 3686 | put defp_o r sp_add_t t_dot |
| 3687 | put defp_l r 1 |
| 3688 | else |
| 3689 | po = sp_dup_slice ho hl |
| 3690 | _a = sp_add_t t_ws_survey |
| 3691 | _b = repo_name_o r |
| 3692 | put defp_o r po |
| 3693 | put defp_l r sub get sp_len 0 po |
| 3694 | end |
| 3695 | end |
| 3696 | end |
| 3697 | end |
| 3698 | |
| 3699 | fn warn_head_mismatch r ulong to void |
| 3700 | ml = get msha_l r |
| 3701 | if eq ml 0 |
| 3702 | ret |
| 3703 | end |
| 3704 | hl = get head_l r |
| 3705 | same = true |
| 3706 | if lt hl ml |
| 3707 | same = false |
| 3708 | else |
| 3709 | if not sp_eq get head_o r ml get msha_o r ml |
| 3710 | same = false |
| 3711 | end |
| 3712 | end |
| 3713 | if not same |
| 3714 | eput_t t_e_warn |
| 3715 | eput_repo r |
| 3716 | eput_t t_e_warn2 |
| 3717 | h12 = hl |
| 3718 | if gt h12 12 |
| 3719 | h12 = 12 |
| 3720 | end |
| 3721 | eput_sp get head_o r h12 |
| 3722 | eput_t t_e_warn3 |
| 3723 | eput_sp get msha_o r ml |
| 3724 | eputc 10 |
| 3725 | end |
| 3726 | end |
| 3727 | |
| 3728 | fn scan_all_repos to void |
| 3729 | for r ulong NREPO bound 6 |
| 3730 | scan_repo r |
| 3731 | if eq get rskip r 0 |
| 3732 | eput_t t_e_scanned |
| 3733 | eput_repo r |
| 3734 | eput_t t_e_head |
| 3735 | eput_sp get head_o r get head_l r |
| 3736 | eputc 32 |
| 3737 | eputc 40 |
| 3738 | eput_sp get defp_o r get defp_l r |
| 3739 | eputc 41 |
| 3740 | eputc 10 |
| 3741 | warn_head_mismatch r |
| 3742 | else |
| 3743 | put v_skipped 0 add get v_skipped 0 1 |
| 3744 | eput_t t_e_skipped |
| 3745 | eput_repo r |
| 3746 | eput_t t_e_nogit |
| 3747 | eput_sp get defp_o r get defp_l r |
| 3748 | eput_t t_e_set |
| 3749 | eput_repo_env r |
| 3750 | eput_t t_e_notpass |
| 3751 | end |
| 3752 | end |
| 3753 | end |
| 3754 | |
| 3755 | fn emit_json_all mo ulong ml ulong fail ulong to void |
| 3756 | oput_t t_json_p1 |
| 3757 | oput_jstr_sp mo ml |
| 3758 | oput_t t_json_p2 |
| 3759 | emit_json_repos |
| 3760 | oput_t t_json_s0 |
| 3761 | emit_json_sites |
| 3762 | oput_t t_json_f1 |
| 3763 | oput_u get v_manual 0 |
| 3764 | oput_t t_json_f2 |
| 3765 | oput_u get nsites 0 |
| 3766 | oput_t t_json_f3 |
| 3767 | oput_u get v_uncls 0 |
| 3768 | oput_t t_json_f4 |
| 3769 | oput_u get v_qrows 0 |
| 3770 | oput_t t_json_f5 |
| 3771 | oput_u get v_badcls 0 |
| 3772 | oput_t t_json_f6 |
| 3773 | oput_u get v_areach 0 |
| 3774 | oput_t t_json_f7 |
| 3775 | oput_u get v_stale 0 |
| 3776 | oput_t t_json_f8 |
| 3777 | oput_u get map_err 0 |
| 3778 | oput_t t_json_f9 |
| 3779 | oput_u get v_skipped 0 |
| 3780 | oput_t t_json_f10 |
| 3781 | oput_u get v_cntn 0 |
| 3782 | oput_t t_json_f11 |
| 3783 | if ne fail 0 |
| 3784 | oput_t t_FAIL |
| 3785 | else |
| 3786 | oput_t t_PASS |
| 3787 | end |
| 3788 | oput_t t_json_f12 |
| 3789 | oflush |
| 3790 | end |
| 3791 | |
| 3792 | fn emit_stderr_summary fail ulong to void |
| 3793 | eput_t t_e_sum1 |
| 3794 | eput_u get nsites 0 |
| 3795 | eput_t t_e_sum2 |
| 3796 | eput_u get v_uncls 0 |
| 3797 | eput_t t_e_sum3 |
| 3798 | eput_u get v_qrows 0 |
| 3799 | eput_t t_e_sum4 |
| 3800 | eput_u get v_badcls 0 |
| 3801 | eput_t t_e_sum5 |
| 3802 | eput_u get v_areach 0 |
| 3803 | eput_t t_e_sum6 |
| 3804 | eput_u get v_stale 0 |
| 3805 | eput_t t_e_sum7 |
| 3806 | eput_u get map_err 0 |
| 3807 | eput_t t_e_sum8 |
| 3808 | eput_u get v_skipped 0 |
| 3809 | eput_t t_e_sum9 |
| 3810 | if ne fail 0 |
| 3811 | eput_t t_FAIL |
| 3812 | else |
| 3813 | eput_t t_PASS |
| 3814 | end |
| 3815 | eputc 10 |
| 3816 | eflush |
| 3817 | end |
| 3818 | |
| 3819 | global cfg_mo ulong 1 |
| 3820 | global cfg_ml ulong 1 |
| 3821 | global cfg_has_map ulong 1 |
| 3822 | global cfg_jo ulong 1 |
| 3823 | global cfg_jl ulong 1 |
| 3824 | global cfg_has_json ulong 1 |
| 3825 | global cfg_skel ulong 1 |
| 3826 | |
| 3827 | fn parse_cli_args to int |
| 3828 | ac = argcnt |
| 3829 | if lt ac 1 |
| 3830 | ret 2 |
| 3831 | end |
| 3832 | argc = ulong ac |
| 3833 | em = env_get t_env_map |
| 3834 | if ge em 0 |
| 3835 | put cfg_has_map 0 1 |
| 3836 | put cfg_mo 0 shr ulong em 32 |
| 3837 | put cfg_ml 0 and ulong em 4294967295 |
| 3838 | end |
| 3839 | ai = ulong 1 |
| 3840 | while lt ai argc bound 4096 |
| 3841 | al = argread ai tmp1 0 8192 |
| 3842 | if lt al 0 |
| 3843 | eput_t t_usage |
| 3844 | eflush |
| 3845 | ret 2 |
| 3846 | end |
| 3847 | an = ulong al |
| 3848 | if tmp1_eq_t an t_fl_pat |
| 3849 | oput_t t_pat_text |
| 3850 | oflush |
| 3851 | ret -1 |
| 3852 | end |
| 3853 | if tmp1_eq_t an t_fl_skel |
| 3854 | put cfg_skel 0 1 |
| 3855 | ai = add ai 1 |
| 3856 | continue |
| 3857 | end |
| 3858 | if tmp1_eq_t an t_fl_map |
| 3859 | if lt add ai 1 argc |
| 3860 | ai = add ai 1 |
| 3861 | vl = argread ai tmp1 0 8192 |
| 3862 | if lt vl 0 |
| 3863 | eput_t t_usage |
| 3864 | eflush |
| 3865 | ret 2 |
| 3866 | end |
| 3867 | put cfg_ml 0 ulong vl |
| 3868 | put cfg_mo 0 sp_add_tmp1 ulong vl |
| 3869 | put cfg_has_map 0 1 |
| 3870 | ai = add ai 1 |
| 3871 | continue |
| 3872 | end |
| 3873 | end |
| 3874 | if tmp1_eq_t an t_fl_json |
| 3875 | if lt add ai 1 argc |
| 3876 | ai = add ai 1 |
| 3877 | vl = argread ai tmp1 0 8192 |
| 3878 | if lt vl 0 |
| 3879 | eput_t t_usage |
| 3880 | eflush |
| 3881 | ret 2 |
| 3882 | end |
| 3883 | put cfg_jl 0 ulong vl |
| 3884 | put cfg_jo 0 sp_add_tmp1 ulong vl |
| 3885 | put cfg_has_json 0 1 |
| 3886 | ai = add ai 1 |
| 3887 | continue |
| 3888 | end |
| 3889 | end |
| 3890 | eput_t t_usage |
| 3891 | eflush |
| 3892 | ret 2 |
| 3893 | end |
| 3894 | ret 0 |
| 3895 | end |
| 3896 | |
| 3897 | fn tally_percls to void |
| 3898 | ns = get nsites 0 |
| 3899 | for i ulong ns bound 16384 |
| 3900 | c = ulong 7 |
| 3901 | row = get st_row i |
| 3902 | if ge row 0 |
| 3903 | b = mul ulong row 11 |
| 3904 | co = get rw_off add b 7 |
| 3905 | cl = get rw_len add b 7 |
| 3906 | if class_ok co cl |
| 3907 | c = class_idx co cl |
| 3908 | if eq get sp co 78 |
| 3909 | put v_cntn 0 add get v_cntn 0 1 |
| 3910 | end |
| 3911 | end |
| 3912 | end |
| 3913 | pidx = add mul get st_repo i 8 c |
| 3914 | put percls pidx add get percls pidx 1 |
| 3915 | end |
| 3916 | end |
| 3917 | |
| 3918 | fn main to int |
| 3919 | put ofd 0 1 |
| 3920 | prc = parse_cli_args |
| 3921 | if eq prc -1 |
| 3922 | ret 0 |
| 3923 | end |
| 3924 | if ne prc 0 |
| 3925 | ret prc |
| 3926 | end |
| 3927 | if eq get cfg_has_map 0 0 |
| 3928 | put cfg_mo 0 sp_add_t t_defmap |
| 3929 | put cfg_ml 0 len t_defmap |
| 3930 | end |
| 3931 | mo = get cfg_mo 0 |
| 3932 | ml = get cfg_ml 0 |
| 3933 | setup_repo_paths |
| 3934 | if eq get cfg_skel 0 0 |
| 3935 | load_map mo ml |
| 3936 | else |
| 3937 | for k ulong ml bound 4096 |
| 3938 | put tmp1 k get sp add mo k |
| 3939 | end |
| 3940 | tfd = fopen tmp1 0 ml 0 0 |
| 3941 | if ge tfd 0 |
| 3942 | _c = fclose int tfd |
| 3943 | load_map mo ml |
| 3944 | end |
| 3945 | end |
| 3946 | scan_all_repos |
| 3947 | join_sites_and_manual |
| 3948 | if ne get cfg_skel 0 0 |
| 3949 | emit_skeleton |
| 3950 | ret 0 |
| 3951 | end |
| 3952 | validate_sites |
| 3953 | validate_manual_and_stale |
| 3954 | tally_percls |
| 3955 | |
| 3956 | fail = ulong 0 |
| 3957 | if ne get v_uncls 0 0 |
| 3958 | fail = 1 |
| 3959 | end |
| 3960 | if ne get v_qrows 0 0 |
| 3961 | fail = 1 |
| 3962 | end |
| 3963 | if ne get v_badcls 0 0 |
| 3964 | fail = 1 |
| 3965 | end |
| 3966 | if ne get v_areach 0 0 |
| 3967 | fail = 1 |
| 3968 | end |
| 3969 | if ne get v_stale 0 0 |
| 3970 | fail = 1 |
| 3971 | end |
| 3972 | if ne get map_err 0 0 |
| 3973 | fail = 1 |
| 3974 | end |
| 3975 | if ne get v_skipped 0 0 |
| 3976 | fail = 1 |
| 3977 | end |
| 3978 | |
| 3979 | if ne get cfg_has_json 0 0 |
| 3980 | jo = get cfg_jo 0 |
| 3981 | jl = get cfg_jl 0 |
| 3982 | for k ulong jl bound 4096 |
| 3983 | put tmp1 k get sp add jo k |
| 3984 | end |
| 3985 | jfd = fopen tmp1 0 jl 577 420 |
| 3986 | if lt jfd 0 |
| 3987 | die_sp t_die_write jo jl |
| 3988 | end |
| 3989 | put ofd 0 int jfd |
| 3990 | end |
| 3991 | emit_json_all mo ml fail |
| 3992 | if ne get cfg_has_json 0 0 |
| 3993 | _c = fclose get ofd 0 |
| 3994 | end |
| 3995 | emit_stderr_summary fail |
| 3996 | if ne fail 0 |
| 3997 | ret 1 |
| 3998 | end |
| 3999 | ret 0 |
| 4000 | end |