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 / si / architecture / tools / name-check / namecheck.om

779 lines · 14849 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note namecheck: refuse new uses of the retired project names (ADR 0038), seeded native Omega.
3note usage: git -c core.quotePath=false diff --no-color --no-ext-diff -U0 BASE HEAD | namecheck
4note Reads a git unified diff on stdin. A file's path is taken from its +++ line inside the header
5note (after diff --git, before the first @@), so added text cannot name another path.
6note Every ADDED line of a judged path is checked; a line FAILs
7note when, with its quoted text removed, it names the project with a retired word:
8note Aienix / AIENIX retired everywhere outside quoted text, also inside a word or identifier
9note AIENOS / Aienos retired in prose (the kernel is Aienux, the whole system AienOS)
10note A retired word counts only when it stands as a word: no letter, digit or _ beside it, nothing
11note of - / . @ $ \ before it (a hyphen after a lowercase letter is prose: non-AIENOS), not followed
12note by \ or by . and a letter or digit (a path part or file name), and not followed by - or / and a
13note token of uppercase letters or digits that holds a digit or runs on to the next - / or _ (a label
14note or path part). So
15note lowercase names (paths, crates, URLs), identifiers (AIENOS_DISK, AienosCapRef) and labels (AIENOS-PKV-ENVID-KEY-V1,
16note AIENOS/M5/CORTEX-V1) are code and pass, while AIENOS-based or AIENOS/kernel is prose.
17note Quoted text keeps its words: `code spans` (a run of backticks closes at the next run of the same
18note length; one left open runs to the end of the line, as a Markdown span may wrap), then
19note "double quotes", then curly quotes (U+201C .. U+201D), removed in that order.
20note Never judged (history is never rewritten): evidence/, */evidence/*, receipts/, */receipts/*,
21note docs/history/, docs/archive/, CHANGELOG*, */CHANGELOG*, docs/adr/0038-names-aienux-kernel-aienos-system.md
22note (that exact path), tools/name-check/*, and added
23note lines that start with _Avoid_: (glossary lines naming the retired words on purpose).
24note Output: one line per finding, then "name-check: FAIL" (exit 1) or "name-check: PASS" (exit 0);
25note a refusal prints one line that names its reason (exit 2).
26note Exit 2: stdin unreadable, an added line or hunk before any diff --git header, a +++ header
27note that is neither +++ b/PATH nor +++ /dev/null (diff.noprefix, a C-quoted name), a path longer than 4096 bytes (PATH_MAX, a Linux boundary), or one
28note diff line longer than 16777216 bytes (the largest array this compiler builds, OMEGESE 8).
29
30text wtbl "Aienix\nAIENIX\nAIENOS\nAienos\n"
31text atbl "evidence/\nreceipts/\ndocs/history/\ndocs/archive/\nCHANGELOG\ndocs/adr/0038-names-aienux-kernel-aienos-system.md\ntools/name-check/\n/evidence/\n/receipts/\n/CHANGELOG\n"
32text tpre "name-check: "
33text tret ": retired name '"
34text tuse "' (use Aienux for the kernel, AienOS for the whole system)\n"
35text tfail "name-check: FAIL\n"
36text tpass1 "name-check: PASS ("
37text tpass2 " added lines checked)\n"
38text trf "name-check: refused, nothing judged (exit 2): "
39text tr1 "a +++ header is neither +++ b/PATH nor +++ /dev/null (diff.noprefix, or a file name git C-quotes)\n"
40text tr2 "an added line or a hunk comes before any diff --git header: the input is not a git diff\n"
41text tr3 "a path is longer than 4096 bytes (PATH_MAX)\n"
42text tr4 "a line is longer than 16777216 bytes (the largest array the compiler builds)\n"
43text tr5 "standard input could not be read\n"
44text tr6 "the input is longer than 999998^3 reads of 65536 bytes\n"
45text tcol ":"
46text tav "+_Avoid_:"
47text thdr "+++ b/"
48text tat "@@ "
49text tdg "diff --git "
50text tnul "+++ /dev/null"
51
52global lb uchar 16777216
53global ub uchar 16777216
54global tb uchar 16777216
55global cb uchar 65536
56global pb uchar 4096
57global st ulong 9
58
59note st: 0 line length, 1 path length (0 = no judged path), 2 new-side line number,
60note 3 findings, 4 added lines checked, 5 word id of the last hit, 6 unquoted length, 7 refusal
61note reason (0 none; 1..6 as the tr texts),
62note 8 where we are: 2 before any diff --git (an added line there is exit 2), 1 inside a file
63note header (after diff --git, before the first @@), 0 inside the hunks
64
65fn wr a ulong to void
66note write one decimal number to stdout
67d = new uchar 24 0
68n = ulong 0
69v = a
70while true bound 24
71put d sub 23 n uchar add 48 rem v 10
72n = add n 1
73v = div v 10
74if eq v 0
75break
76end
77end
78k = write 1 d sub 24 n n
79end
80
81fn isaln c ulong to bool
82if and ge c 48 le c 57
83ret true
84end
85if and ge c 65 le c 90
86ret true
87end
88if and ge c 97 le c 122
89ret true
90end
91ret false
92end
93
94fn iswc c ulong to bool
95if isaln c
96ret true
97end
98ret eq c 95
99end
100
101fn isleft c ulong to bool
102note the bytes that may not stand before a retired word: [A-Za-z0-9_] and - / . @ $ \
103if iswc c
104ret true
105end
106if eq c 92
107ret true
108end
109if or eq c 45 eq c 47
110ret true
111end
112if or eq c 46 eq c 64
113ret true
114end
115ret eq c 36
116end
117
118fn tstart k ulong to ulong
119note start of entry k of atbl
120s = ulong 0
121j = ulong 0
122while lt j k bound 4096
123if eq get atbl s 10
124j = add j 1
125end
126s = add s 1
127end
128ret s
129end
130
131fn pfxat k ulong o ulong to bool
132note entry k of atbl equals pb at offset at
133s = tstart k
134i = ulong 0
135pl = get st 1
136while ne get atbl add s i 10 bound 64
137if ge add o i pl
138ret false
139end
140if ne get pb add o i get atbl add s i
141ret false
142end
143i = add i 1
144end
145ret true
146end
147
148fn allowed to bool
149for k ulong 7
150if pfxat k 0
151if ne k 5
152ret true
153end
154note entry 5 is ADR 0038's own file: exempt only under its exact path
155if eq get st 1 sub sub tstart 6 tstart 5 1
156ret true
157end
158end
159end
160pl = get st 1
161o = ulong 0
162while lt o pl bound 4096
163for k2 ulong 3
164if pfxat add k2 7 o
165ret true
166end
167end
168o = add o 1
169end
170ret false
171end
172
173fn wordid i ulong to ulong
174note 1..4 when a retired word (wtbl entry) starts at ub[i], else 0
175n = get st 6
176if gt add i 6 n
177ret 0
178end
179for k ulong 4
180ok = true
181for j ulong 6
182if ne get ub add i j get wtbl add mul k 7 j
183ok = false
184end
185end
186if ok
187ret add k 1
188end
189end
190ret 0
191end
192
193fn prefix i ulong p ulong to bool
194note a hyphen with a lowercase letter before it joins prose: non-AIENOS
195if ne p 45
196ret false
197end
198if lt i 2
199ret false
200end
201q = ulong get ub sub i 2
202ret and ge q 97 le q 122
203end
204
205fn isupd c ulong to bool
206if and ge c 65 le c 90
207ret true
208end
209ret and ge c 48 le c 57
210end
211
212fn islabel k ulong n ulong to bool
213note ub[k..) is a token of [A-Z0-9] that holds a digit, or runs on to - / or _ (a token is read up
214note to 4095 bytes; past that it is prose)
215m = k
216dg = false
217while and lt m n lt sub m k 4095 bound 4096
218c0 = ulong get ub m
219if not isupd c0
220break
221end
222if le c0 57
223dg = true
224end
225m = add m 1
226end
227if eq m k
228ret false
229end
230if dg
231ret true
232end
233if ge m n
234ret false
235end
236c = ulong get ub m
237if or eq c 45 eq c 47
238ret true
239end
240ret eq c 95
241end
242
243fn bounded i ulong to bool
244note the word at ub[i..i+6) stands as a word
245n = get st 6
246if gt i 0
247p = ulong get ub sub i 1
248if isleft p
249if not prefix i p
250ret false
251end
252end
253end
254j = add i 6
255if lt j n
256c = ulong get ub j
257if iswc c
258ret false
259end
260if eq c 92
261note a path part: \EFI\AIENOS\MODEL.MAP
262ret false
263end
264if lt add j 1 n
265d = ulong get ub add j 1
266if eq c 46
267note a file name or extension: AIENOS.md
268if isaln d
269ret false
270end
271end
272if or eq c 45 eq c 47
273note a label or path part: AIENOS-PKV-ENVID-..., AIENOS/M5/CORTEX-V1, AIENOS-PI5: a token of
274note uppercase letters or digits that holds a digit or runs on to the next - / or _; anything else
275note is prose (AIENOS-based, AIENOS-Omega, AIENOS/Aienux)
276if islabel add j 1 n
277ret false
278end
279end
280end
281end
282ret true
283end
284
285fn lim i ulong n ulong to ulong
286note end of one inner pass: min(n, i + 999998), so an inner loop never reaches its bound and the
287note outer loop carries on; 17 outer passes x 999998 >= 16777216 bytes
288m = add i 999998
289if lt n m
290ret n
291end
292ret m
293end
294
295fn hit to bool
296note first retired word in ub[0..st6); word id in st5
297n = get st 6
298i = ulong 0
299while lt i n bound 17
300e = lim i n
301while lt i e bound 999999
302w = wordid i
303if ne w 0
304if le w 2
305note Aienix and AIENIX are retired even inside a word or identifier
306put st 5 w
307ret true
308end
309if bounded i
310put st 5 w
311ret true
312end
313end
314i = add i 1
315end
316end
317ret false
318end
319
320fn nextlb i ulong n ulong ch ulong to ulong
321note first j >= i with lb[j] = ch, else n
322j = i
323while lt j n bound 17
324e = lim j n
325while lt j e bound 999999
326if eq ulong get lb j ch
327ret j
328end
329j = add j 1
330end
331end
332ret n
333end
334
335fn nexttb i ulong n ulong ch ulong to ulong
336note first j >= i with tb[j] = ch, else n
337j = i
338while lt j n bound 17
339e = lim j n
340while lt j e bound 999999
341if eq ulong get tb j ch
342ret j
343end
344j = add j 1
345end
346end
347ret n
348end
349
350fn iscq i ulong n ulong last ulong to bool
351note U+201C (last 156) or U+201D (last 157) at ub[i]
352if gt add i 3 n
353ret false
354end
355if ne get ub i 226
356ret false
357end
358if ne get ub add i 1 128
359ret false
360end
361ret eq ulong get ub add i 2 last
362end
363
364fn nextcq i ulong n ulong to ulong
365note first j >= i where U+201D starts in ub, else n
366j = i
367while lt j n bound 17
368e = lim j n
369while lt j e bound 999999
370if iscq j n 157
371ret j
372end
373j = add j 1
374end
375end
376ret n
377end
378
379fn btend i ulong n ulong to ulong
380note end of the run of backticks that starts at lb[i]
381j = i
382while lt j n bound 17
383e = lim j n
384while lt j e bound 999999
385if ne ulong get lb j 96
386ret j
387end
388j = add j 1
389end
390end
391ret n
392end
393
394fn btclose i ulong n ulong ln ulong to ulong
395note start of the first run of exactly ln backticks at or after lb[i], else n
396j = i
397while lt j n bound 17
398e = lim j n
399while lt j e bound 999999
400if eq ulong get lb j 96
401k = btend j n
402if eq sub k j ln
403ret j
404end
405j = k
406continue
407end
408j = add j 1
409end
410end
411ret n
412end
413
414fn unbt n ulong to ulong
415note lb[1..n) -> tb with `code spans` removed: a run of backticks closes at the next run of the same
416note length (``x`` and `x` are spans, as in Markdown); an unmatched run cuts the rest of the line,
417note because a Markdown code span may wrap onto the next line
418o = ulong 0
419i = ulong 1
420while lt i n bound 17
421e = lim i n
422while lt i e bound 999999
423c = get lb i
424if eq c 96
425k = btend i n
426j = btclose k n sub k i
427if ge j n
428ret o
429end
430i = add j sub k i
431continue
432end
433put tb o c
434o = add o 1
435i = add i 1
436end
437end
438ret o
439end
440
441fn undq n ulong to ulong
442note tb[0..n) -> ub with "double quoted" spans removed; an unmatched quote stays
443o = ulong 0
444i = ulong 0
445while lt i n bound 17
446e = lim i n
447while lt i e bound 999999
448c = get tb i
449if eq c 34
450j = nexttb add i 1 n 34
451if lt j n
452i = add j 1
453continue
454end
455end
456put ub o c
457o = add o 1
458i = add i 1
459end
460end
461ret o
462end
463
464fn cpback o ulong to void
465note tb[0..o) -> ub
466k = ulong 0
467while lt k o bound 17
468e = lim k o
469while lt k e bound 999999
470put ub k get tb k
471k = add k 1
472end
473end
474end
475
476fn uncq n ulong to ulong
477note ub[0..n) -> tb with curly quoted spans removed, then copied back to ub
478o = ulong 0
479i = ulong 0
480nc = false
481while lt i n bound 17
482e = lim i n
483while lt i e bound 999999
484if not nc
485if iscq i n 156
486j = nextcq add i 3 n
487if lt j n
488i = add j 3
489continue
490end
491note no closing quote after i, so none after any later opening quote: the scan stays linear
492nc = true
493end
494end
495put tb o get ub i
496o = add o 1
497i = add i 1
498end
499end
500cpback o
501ret o
502end
503
504fn isavoid n ulong to bool
505note lb = "+_Avoid_:" ...
506if lt n 9
507ret false
508end
509for i ulong 9
510if ne get lb i get tav i
511ret false
512end
513end
514ret true
515end
516
517fn startsw n ulong k ulong to bool
518note lb starts with "+++ b/" (k 6) or "+++ " (k 4) or "@@ " (k 3, compared at its own text)
519if lt n k
520ret false
521end
522if eq k 3
523for i ulong 3
524if ne get lb i get tat i
525ret false
526end
527end
528ret true
529end
530i2 = ulong 0
531while lt i2 k bound 6
532if ne get lb i2 get thdr i2
533ret false
534end
535i2 = add i2 1
536end
537ret true
538end
539
540fn hunk n ulong to void
541note @@ -a,b +c,d @@: the new-side start c
542i = nextlb 3 n 43
543v = ulong 0
544i = add i 1
545while lt i n bound 32
546c = ulong get lb i
547if or lt c 48 gt c 57
548break
549end
550v = add mul v 10 sub c 48
551i = add i 1
552end
553put st 2 v
554end
555
556fn setpath n ulong to void
557m = sub n 6
558note git ends a +++ path that holds a space with a TAB; it is not part of the name
559if gt m 0
560if eq get lb sub n 1 9
561m = sub m 1
562end
563end
564if gt m 4096
565put st 7 3
566put st 1 0
567ret
568end
569i = ulong 0
570while lt i m bound 4096
571put pb i get lb add i 6
572i = add i 1
573end
574put st 1 m
575if allowed
576put st 1 0
577end
578end
579
580fn report to void
581k = write 1 tpre 0 len tpre
582k = write 1 pb 0 get st 1
583k = write 1 tcol 0 1
584wr get st 2
585k = write 1 tret 0 len tret
586w = sub get st 5 1
587k = write 1 wtbl mul w 7 6
588k = write 1 tuse 0 len tuse
589put st 3 add get st 3 1
590end
591
592fn added n ulong to void
593if gt get st 1 0
594put st 4 add get st 4 1
595m = unbt n
596m = undq m
597put st 6 m
598m = uncq m
599put st 6 m
600if hit
601report
602end
603end
604put st 2 add get st 2 1
605end
606
607fn isdg n ulong to bool
608note lb starts with "diff --git "
609if lt n 11
610ret false
611end
612for i ulong 11
613if ne get lb i get tdg i
614ret false
615end
616end
617ret true
618end
619
620fn isnull n ulong to bool
621note lb = "+++ /dev/null"
622if ne n 13
623ret false
624end
625for i ulong 13
626if ne get lb i get tnul i
627ret false
628end
629end
630ret true
631end
632
633fn line n ulong to void
634note a +++ line names the file only inside its header, so added text cannot change the path
635if eq n 0
636ret
637end
638c = get lb 0
639if isdg n
640put st 8 1
641put st 1 0
642ret
643end
644if eq get st 8 1
645if startsw n 6
646setpath n
647ret
648end
649if startsw n 4
650note +++ /dev/null (a deleted file) names no path; any other form (no b/ prefix from
651note diff.noprefix, or a C-quoted name) cannot be judged and is refused, never skipped
652put st 1 0
653if not isnull n
654put st 7 1
655end
656ret
657end
658end
659if startsw n 3
660if eq get st 8 2
661put st 7 2
662ret
663end
664put st 8 0
665hunk n
666ret
667end
668if eq c 43
669if eq get st 8 2
670note an added line before any diff --git header: not a git diff
671put st 7 2
672ret
673end
674if isavoid n
675put st 2 add get st 2 1
676ret
677end
678added n
679ret
680end
681if eq c 32
682put st 2 add get st 2 1
683end
684end
685
686fn refuse to void
687note the one line that says why nothing was judged
688k = write 1 trf 0 len trf
689w = get st 7
690if eq w 1
691k1 = write 1 tr1 0 len tr1
692end
693if eq w 2
694k2 = write 1 tr2 0 len tr2
695end
696if eq w 3
697k3 = write 1 tr3 0 len tr3
698end
699if eq w 4
700k4 = write 1 tr4 0 len tr4
701end
702if eq w 5
703k5 = write 1 tr5 0 len tr5
704end
705if eq w 6
706k6 = write 1 tr6 0 len tr6
707end
708end
709
710fn chunk to int
711note read one block of stdin into lines: 0 more input, 1 end of input, 2 error
712k = read 0 cb 0 65536
713if lt k long 0
714put st 7 5
715ret 2
716end
717if eq k long 0
718ret 1
719end
720kn = ulong k
721i = ulong 0
722while lt i kn bound 65536
723c = get cb i
724i = add i 1
725if eq c 10
726line get st 0
727put st 0 0
728else
729n = get st 0
730if ge n 16777216
731put st 7 4
732ret 2
733end
734put lb n c
735put st 0 add n 1
736end
737end
738if ne get st 7 0
739ret 2
740end
741ret 0
742end
743
744fn main to int
745put st 8 2
746note each level stops one pass below its bound; 999998^3 reads of up to 65536 bytes cover any input
747r = int 0
748c1 = ulong 0
749while and eq r 0 lt c1 999998 bound 999999
750c2 = ulong 0
751while and eq r 0 lt c2 999998 bound 999999
752c3 = ulong 0
753while and eq r 0 lt c3 999998 bound 999999
754r = chunk
755c3 = add c3 1
756end
757c2 = add c2 1
758end
759c1 = add c1 1
760end
761if eq r 0
762put st 7 6
763end
764if eq get st 7 0
765line get st 0
766end
767if ne get st 7 0
768refuse
769ret 2
770end
771if gt get st 3 0
772k6 = write 1 tfail 0 len tfail
773ret 1
774end
775k7 = write 1 tpass1 0 len tpass1
776wr get st 4
777k8 = write 1 tpass2 0 len tpass2
778ret 0
779end