interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / tools / r16_loop_inventory.om

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