interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / evidence / allen-omega-L694 / L734 / green1.om

3098 lines · 49987 bytes Raw Blame History
1note L694 fixed-buffer utilities. No platform effects in product functions.
2global In uchar 8192
3global Inlen ulong 1
4global Outb uchar 8192
5global Outlen ulong 1
6global Err ulong 1
7text Digits "0123456789abcdef"
8fn emitb c uchar to void
9n = get Outlen 0
10if ge n len Outb
11put Err 0 1
12else
13put Outb n c
14put Outlen 0 add n 1
15end
16end
17fn emitn v ulong to void
18d = new uchar 20 0
19n = ulong 0
20x = v
21put d n uchar add rem x 10 48
22n = add n 1
23x = div x 10
24while gt x 0
25put d n uchar add rem x 10 48
26n = add n 1
27x = div x 10
28end
29while gt n 0
30n = sub n 1
31emitb get d n
32end
33end
34fn outreset to void
35put Outlen 0 0
36put Err 0 0
37end
38fn ineq at ulong c uchar to bool
39if ge at get Inlen 0
40ret false
41end
42ret eq get In at c
43end
44fn isdigit c uchar to bool
45ret and ge c 48 le c 57
46end
47note Parser cursor P0, number P1, error P2. Never wraps a u32.
48global P ulong 3
49fn number to void
50v = ulong 0
51n = ulong 0
52p = get P 0
53while lt p get Inlen 0
54c = get In p
55if not isdigit c
56put P 0 p
57put P 1 v
58if eq n 0
59put P 2 1
60end
61ret
62end
63if or ge n 10 gt v 429496729
64put P 2 1
65ret
66end
67v = add mul v 10 sub ulong c 48
68if gt v 4294967295
69put P 2 1
70ret
71end
72n = add n 1
73p = add p 1
74end
75put P 0 p
76put P 1 v
77if eq n 0
78put P 2 1
79end
80end
81fn expect c uchar to void
82p = get P 0
83if not ineq p c
84put P 2 1
85else
86put P 0 add p 1
87end
88end
89fn crc off ulong count ulong to uint
90c = uint 4294967295
91for i ulong count
92c = xor c uint get In add off i
93for k ulong 8
94if ne and c 1 0
95c = xor shr c 1 3988292384
96else
97c = shr c 1
98end
99end
100end
101ret not c
102end
103note SPDX-License-Identifier: AGPL-3.0-or-later
104note SHA256 core reused byte-for-byte from native Omega TRN1 at 12251e3403d42931ada27dc1c54b3b610954be5d.
105note Reads stdin up to 8 MiB and emits lowercase hex plus LF only after successful EOF.
106global Buf uchar 8192
107global H uint 8
108global Vv uint 8
109global W uint 64
110global K uint 64
111global Hb uchar 64
112global Hs ulong 2
113global Hash uchar 32
114global Out uchar 65
115text Hex "0123456789abcdef"
116
117fn rotate x uint n uint to uint
118ret or shr x n shl x sub 32 n
119end
120
121fn round i ulong to void
122e = get Vv 4
123a = get Vv 0
124s = xor xor rotate e 6 rotate e 11 rotate e 25
125c = xor and e get Vv 5 and not e get Vv 6
126t = add add get Vv 7 s add c add get K i get W i
127s = xor xor rotate a 2 rotate a 13 rotate a 22
128c = and a get Vv 1
129c = xor c and a get Vv 2
130c = xor c and get Vv 1 get Vv 2
131u = add s c
132put Vv 7 get Vv 6
133put Vv 6 get Vv 5
134put Vv 5 e
135put Vv 4 add get Vv 3 t
136put Vv 3 get Vv 2
137put Vv 2 get Vv 1
138put Vv 1 a
139put Vv 0 add t u
140end
141
142fn block to void
143for i ulong 16
144x = uint 0
145for j ulong 4
146x = or shl x 8 uint get Hb add mul i 4 j
147end
148put W i x
149end
150for j ulong 48
151i = add j 16
152x = get W sub i 15
153y = get W sub i 2
154s = xor xor rotate x 7 rotate x 18 shr x 3
155t = xor xor rotate y 17 rotate y 19 shr y 10
156put W i add add get W sub i 16 s add get W sub i 7 t
157end
158for i ulong 8
159put Vv i get H i
160end
161for i ulong 64
162round i
163end
164for i ulong 8
165put H i add get H i get Vv i
166end
167end
168
169fn hinit to void
170put H 0 1779033703
171put H 1 3144134277
172put H 2 1013904242
173put H 3 2773480762
174put H 4 1359893119
175put H 5 2600822924
176put H 6 528734635
177put H 7 1541459225
178put Hs 0 0
179put Hs 1 0
180end
181
182fn hbyte c uchar to void
183p = get Hs 0
184put Hb p c
185p = add p 1
186put Hs 1 add get Hs 1 1
187if eq p 64
188block
189p = 0
190end
191put Hs 0 p
192end
193
194fn update off ulong count ulong to void
195for i ulong count
196hbyte get Buf add off i
197end
198end
199
200fn finish to void
201bits = mul get Hs 1 8
202hbyte 128
203while ne get Hs 0 56
204hbyte 0
205end
206for i ulong 8
207hbyte uchar and shr bits mul sub 7 i 8 255
208end
209for i ulong 32
210x = get H div i 4
211put Hash i uchar and shr x uint mul sub 3 rem i 4 8 255
212end
213end
214
215fn constants to void
216put K 0 1116352408
217put K 1 1899447441
218put K 2 3049323471
219put K 3 3921009573
220put K 4 961987163
221put K 5 1508970993
222put K 6 2453635748
223put K 7 2870763221
224put K 8 3624381080
225put K 9 310598401
226put K 10 607225278
227put K 11 1426881987
228put K 12 1925078388
229put K 13 2162078206
230put K 14 2614888103
231put K 15 3248222580
232put K 16 3835390401
233put K 17 4022224774
234put K 18 264347078
235put K 19 604807628
236put K 20 770255983
237put K 21 1249150122
238put K 22 1555081692
239put K 23 1996064986
240put K 24 2554220882
241put K 25 2821834349
242put K 26 2952996808
243put K 27 3210313671
244put K 28 3336571891
245put K 29 3584528711
246put K 30 113926993
247put K 31 338241895
248put K 32 666307205
249put K 33 773529912
250put K 34 1294757372
251put K 35 1396182291
252put K 36 1695183700
253put K 37 1986661051
254put K 38 2177026350
255put K 39 2456956037
256put K 40 2730485921
257put K 41 2820302411
258put K 42 3259730800
259put K 43 3345764771
260put K 44 3516065817
261put K 45 3600352804
262put K 46 4094571909
263put K 47 275423344
264put K 48 430227734
265put K 49 506948616
266put K 50 659060556
267put K 51 883997877
268put K 52 958139571
269put K 53 1322822218
270put K 54 1537002063
271put K 55 1747873779
272put K 56 1955562222
273put K 57 2024104815
274put K 58 2227730452
275put K 59 2361852424
276put K 60 2428436474
277put K 61 2756734187
278put K 62 3204031479
279put K 63 3329325298
280end
281
282note R: seq, active, kind (1 chat 2 code 3 more), asked, heard, slow,
283note code-visible, prompt length, answer length, history count, session.
284global R ulong 16
285global Prompt uchar 160
286global Answer uchar 160
287global Hist uchar 5120
288global Hlen ulong 32
289text Ack "I need to code that. Let me send it off to the Spark."
290text Ackmore "Let me take that change to the Spark."
291fn textok to bool
292n = get Inlen 0
293if or eq n 0 gt n 159
294ret false
295end
296for i ulong n
297c = get In i
298if or lt c 32 gt c 126
299ret false
300end
301end
302ret true
303end
304fn histadd which ulong to void
305n = get R 9
306if eq n 32
307for i ulong 4960
308put Hist i get Hist add i 160
309end
310for i ulong 31
311put Hlen i get Hlen add i 1
312end
313n = 31
314end
315size = get R add which 7
316for i ulong size
317if eq which 0
318put Hist add mul n 160 i get Prompt i
319else
320put Hist add mul n 160 i get Answer i
321end
322end
323put Hlen n size
324put R 9 add n 1
325end
326fn start kind ulong now ulong to bool
327if or ne get R 1 0 ge get R 0 4294967295
328ret false
329end
330if or lt kind 1 gt kind 3
331ret false
332end
333if and eq kind 3 eq get R 6 0
334ret false
335end
336if not textok
337ret false
338end
339for i ulong get Inlen 0
340put Prompt i get In i
341end
342put R 7 get Inlen 0
343put R 0 add get R 0 1
344put R 1 1
345put R 2 kind
346put R 3 now
347put R 4 now
348put R 5 0
349put R 8 0
350put R 11 0
351put R 13 0
352if eq kind 2
353for i ulong len Ack
354put Answer i get Ack i
355end
356put R 8 len Ack
357end
358if eq kind 3
359for i ulong len Ackmore
360put Answer i get Ackmore i
361end
362put R 8 len Ackmore
363end
364histadd 0
365ret true
366end
367fn answer seq ulong now ulong to bool
368if or eq get R 1 0 ne seq get R 0
369ret false
370end
371if or lt now get R 4 not textok
372ret false
373end
374for i ulong get Inlen 0
375put Answer i get In i
376end
377put R 8 get Inlen 0
378put R 4 now
379put R 1 0
380histadd 1
381ret true
382end
383fn cancel to void
384put R 1 0
385end
386fn heard seq ulong now ulong to bool
387if or eq get R 1 0 ne seq get R 0
388ret false
389end
390if lt now get R 4
391ret false
392end
393put R 4 now
394ret true
395end
396fn tick now ulong to ulong
397if or eq get R 1 0 lt now get R 4
398ret 0
399end
400if ge sub now get R 4 30000
401cancel
402ret 2
403end
404if and eq get R 5 0 ge sub now get R 3 20000
405put R 5 1
406ret 1
407end
408ret 0
409end
410fn reset to void
411for i ulong 9
412put R add i 1 0
413end
414end
415note Restore one externally decoded transcript line. No live job or ID reuse.
416fn restore to bool
417if or ne get R 1 0 not textok
418ret false
419end
420for i ulong get Inlen 0
421put Answer i get In i
422end
423put R 8 get Inlen 0
424histadd 1
425ret true
426end
427note CODE protocol: C seq, parts, bytes, crc, got. D parsed header.
428global C ulong 8
429global D ulong 8
430global Code uchar 32769
431global Have uchar 256
432global Piece uchar 128
433global Lang uchar 16
434global Newlang uchar 16
435fn codebeg seq ulong to void
436for i ulong 8
437put C i 0
438end
439put C 0 seq
440for i ulong 256
441put Have i 0
442end
443put Code 0 0
444end
445fn decfield slot ulong sep uchar to void
446number
447put D slot get P 1
448expect sep
449end
450fn hexread to void
451v = ulong 0
452for i ulong 8
453p = get P 0
454if ge p get Inlen 0
455put P 2 1
456ret
457end
458c = get In p
459d = ulong 16
460if isdigit c
461d = sub ulong c 48
462else
463if and ge c 97 le c 102
464d = sub ulong c 87
465end
466end
467if ge d 16
468put P 2 1
469ret
470end
471v = add mul v 16 d
472put P 0 add p 1
473end
474put D 4 v
475expect 32
476end
477fn codehead to bool
478put P 0 0
479put P 2 0
480expect 67
481expect 79
482expect 68
483expect 69
484expect 32
485decfield 0 32
486decfield 1 47
487decfield 2 32
488decfield 3 32
489hexread
490if ne get P 2 0
491ret false
492end
493if or ne get D 0 get C 0 eq get D 3 0
494ret false
495end
496if gt get D 3 32768
497ret false
498end
499if ne get D 2 div add get D 3 127 128
500ret false
501end
502if or lt get D 1 1 gt get D 1 get D 2
503ret false
504end
505if ne get C 1 0
506if or ne get C 1 get D 2 ne get C 2 get D 3
507ret false
508end
509if ne get C 3 get D 4
510ret false
511end
512end
513ret true
514end
515fn langread to bool
516for i ulong 16
517put Newlang i 0
518end
519n = ulong 0
520p = get P 0
521while lt p get Inlen 0
522c = get In p
523if eq c 32
524if eq n 0
525ret false
526end
527put P 0 add p 1
528put D 5 n
529ret true
530end
531ok = or and ge c 97 le c 122 isdigit c
532ok = or ok or eq c 43 eq c 35
533ok = or ok or eq c 46 or eq c 95 eq c 45
534if or not ok ge n 15
535ret false
536end
537put Newlang n c
538p = add p 1
539n = add n 1
540end
541ret false
542end
543fn pieceread to ulong
544p = get P 0
545n = ulong 0
546while lt p get Inlen 0
547c = get In p
548p = add p 1
549if eq c 92
550if ge p get Inlen 0
551ret 129
552end
553c = get In p
554p = add p 1
555if eq c 110
556c = 10
557else
558if ne c 92
559ret 129
560end
561end
562else
563if or lt c 32 gt c 126
564ret 129
565end
566end
567if ge n 128
568ret 129
569end
570put Piece n c
571n = add n 1
572end
573ret n
574end
575fn codetake to bool
576if gt get Inlen 0 320
577ret false
578end
579if not codehead
580ret false
581end
582if not langread
583ret false
584end
585n = pieceread
586want = ulong 128
587if eq get D 1 get D 2
588want = sub get D 3 mul sub get D 2 1 128
589end
590if ne n want
591ret false
592end
593slot = sub get D 1 1
594off = mul slot 128
595if ne get C 1 0
596for i ulong 16
597if ne get Lang i get Newlang i
598ret false
599end
600end
601end
602if ne get Have slot 0
603for i ulong n
604if ne get Code add off i get Piece i
605ret false
606end
607end
608ret true
609end
610put C 1 get D 2
611put C 2 get D 3
612put C 3 get D 4
613for i ulong 16
614put Lang i get Newlang i
615end
616for i ulong n
617put Code add off i get Piece i
618end
619put Have slot 1
620put C 4 add get C 4 1
621ret true
622end
623fn codecrc to uint
624c = uint 4294967295
625for i ulong get C 2
626c = xor c uint get Code i
627for k ulong 8
628if ne and c 1 0
629c = xor shr c 1 3988292384
630else
631c = shr c 1
632end
633end
634end
635ret not c
636end
637fn codestat to ulong
638if eq get C 1 0
639ret 0
640end
641if lt get C 4 get C 1
642ret 1
643end
644if ne ulong codecrc get C 3
645ret 3
646end
647lines = ulong 0
648for i ulong get C 2
649c = get Code i
650if eq c 0
651ret 3
652end
653if eq c 10
654lines = add lines 1
655end
656end
657if ne get Code sub get C 2 1 10
658lines = add lines 1
659end
660if gt lines 800
661ret 3
662end
663put Code get C 2 0
664ret 2
665end
666fn missing to ulong
667if eq get C 1 0
668ret 1
669end
670for i ulong get C 1
671if eq get Have i 0
672ret add i 1
673end
674end
675ret 0
676end
677note Display admission is distinct from a model's closing sentence.
678fn codeshow seq ulong to bool
679if eq get R 1 0
680ret false
681end
682if or ne seq get R 0 ne seq get C 0
683ret false
684end
685if ne codestat 2
686ret false
687end
688put R 6 1
689ret true
690end
691note Pure courier datagrams. Q session, current seq, last LINE, head, count.
692global Q ulong 8
693global N ulong 8
694global Queue uchar 2560
695global Qlens ulong 8
696global Jbuf uchar 4096
697global Jhave uchar 5
698global J ulong 3
699text Keys "ALLEN-COURIER v=1 run= kind= seq= part= bytes="
700text Kinds "JOBLINEGOTACKHELLOHI"
701fn keyread off ulong count ulong to void
702for i ulong count
703expect get Keys add off i
704end
705end
706fn keyemit off ulong count ulong to void
707for i ulong count
708emitb get Keys add off i
709end
710end
711fn kindoff k ulong to ulong
712if eq k 1
713ret 0
714end
715if eq k 2
716ret 3
717end
718if eq k 3
719ret 7
720end
721if eq k 4
722ret 10
723end
724if eq k 5
725ret 13
726end
727ret 18
728end
729fn kindlen k ulong to ulong
730if eq k 2
731ret 4
732end
733if eq k 5
734ret 5
735end
736if eq k 6
737ret 2
738end
739ret 3
740end
741fn qbegin run ulong seq ulong to void
742for i ulong 8
743put Q i 0
744end
745put Q 0 run
746put Q 1 seq
747for i ulong 5
748put Jhave i 0
749end
750for i ulong 3
751put J i 0
752end
753end
754note Serializer takes body In/Inlen; Outb/Outlen are published only on success.
755fn packet k ulong seq ulong part ulong total ulong bytes ulong to bool
756if or lt k 1 gt k 6
757ret false
758end
759if gt get Inlen 0 1000
760ret false
761end
762outreset
763keyemit 0 22
764for i ulong 16
765d = and shr get Q 0 mul sub 15 i 4 15
766emitb get Digits d
767end
768keyemit 22 6
769off = kindoff k
770for i ulong kindlen k
771emitb get Kinds add off i
772end
773keyemit 28 5
774emitn seq
775keyemit 33 6
776emitn part
777emitb 47
778emitn total
779keyemit 39 7
780emitn bytes
781emitb 10
782for i ulong get Inlen 0
783emitb get In i
784end
785ret eq get Err 0 0
786end
787fn pkparse to bool
788if or gt get Inlen 0 1200 lt get Inlen 0 65
789ret false
790end
791put P 0 0
792put P 2 0
793keyread 0 22
794run = ulong 0
795for i ulong 16
796p = get P 0
797c = get In p
798d = ulong 16
799if isdigit c
800d = sub ulong c 48
801else
802if and ge c 97 le c 102
803d = sub ulong c 87
804end
805end
806if ge d 16
807ret false
808end
809run = or shl run 4 d
810put P 0 add p 1
811end
812if ne run get Q 0
813ret false
814end
815keyread 22 6
816kind = ulong 0
817for k ulong 6
818at = get P 0
819off = kindoff add k 1
820size = kindlen add k 1
821ok = true
822for i ulong size
823if not ineq add at i get Kinds add off i
824ok = false
825end
826end
827if and ok ineq add at size 32
828kind = add k 1
829end
830end
831if eq kind 0
832ret false
833end
834put N 0 kind
835put P 0 add get P 0 kindlen kind
836keyread 28 5
837number
838put N 1 get P 1
839keyread 33 6
840number
841put N 2 get P 1
842expect 47
843number
844put N 3 get P 1
845keyread 39 7
846number
847put N 4 get P 1
848expect 10
849put N 5 get P 0
850put N 6 sub get Inlen 0 get P 0
851ret eq get P 2 0
852end
853fn jobtake to ulong
854note n via N4
855note part via N2
856note total via N3
857if or eq get N 4 0 gt get N 4 4096
858ret 0
859end
860if ne get N 3 div add get N 4 999 1000
861ret 0
862end
863if or eq get N 2 0 gt get N 2 get N 3
864ret 0
865end
866want = ulong 1000
867if eq get N 2 get N 3
868want = sub get N 4 mul sub get N 3 1 1000
869end
870if ne want get N 6
871ret 0
872end
873if ne get J 0 0
874if or ne get J 0 get N 4 ne get J 1 get N 3
875ret 0
876end
877end
878slot = sub get N 2 1
879off = mul slot 1000
880if ne get Jhave slot 0
881for i ulong want
882if ne get Jbuf add off i get In add get N 5 i
883ret 0
884end
885end
886ret 2
887end
888for i ulong want
889put Jbuf add off i get In add get N 5 i
890end
891put Jhave slot 1
892put J 0 get N 4
893put J 1 get N 3
894put J 2 add get J 2 1
895ret 1
896end
897note Return0 refused,1 accepted,2 duplicate requiring GOT/ACK again.
898fn qreceive to ulong
899if not pkparse
900ret 0
901end
902if ne get N 1 get Q 1
903ret 0
904end
905kind = get N 0
906if eq kind 1
907ret jobtake
908end
909if ne kind 2
910if ne get N 6 0
911ret 0
912end
913ret 1
914end
915note part via N2
916if eq get N 2 0
917ret 0
918end
919if le get N 2 get Q 2
920ret 2
921end
922if or ne get N 2 add get Q 2 1 eq get Q 4 8
923ret 0
924end
925n = get N 6
926if or eq n 0 gt n 319
927ret 0
928end
929slot = rem add get Q 3 get Q 4 8
930for i ulong n
931put Queue add mul slot 320 i get In add get N 5 i
932end
933put Qlens slot n
934put Q 4 add get Q 4 1
935put Q 2 get N 2
936ret 1
937end
938fn qtake to bool
939if eq get Q 4 0
940ret false
941end
942slot = get Q 3
943n = get Qlens slot
944for i ulong n
945put In i get Queue add mul slot 320 i
946end
947put Inlen 0 n
948put Q 3 rem add slot 1 8
949put Q 4 sub get Q 4 1
950ret true
951end
952note Courier client lifecycle; injected monotonic milliseconds, no host clock/socket.
953note T lastclock, HIvalid, HIat, HELLOvalid, HELLOat, active, acked, jobat,
954note joblength, cursor, pendingkind, pendingpart, reserved, GOTpart, reserved, reserved.
955note Serialized API: qnext publishes one datagram; qsent records actual send result.
956note Consume Outb before another serializer; failed sends leave retries due.
957global T ulong 16
958global JobOut uchar 4096
959fn qstart run ulong now ulong to bool
960if eq run 0
961ret false
962end
963qbegin run 0
964for i ulong 16
965put T i 0
966end
967put T 0 now
968ret true
969end
970fn qready now ulong to bool
971if or eq get Q 0 0 lt now get T 0
972ret false
973end
974if eq get T 1 0
975ret false
976end
977ret lt sub now get T 2 30000
978end
979fn qsubmit now ulong to bool
980if or eq get Q 0 0 lt now get T 0
981ret false
982end
983if ne get T 10 0
984ret false
985end
986if and ne get T 5 0 eq get T 6 0
987ret false
988end
989n = get Inlen 0
990if or eq n 0 gt n 4096
991ret false
992end
993if ge get Q 1 4294967295
994ret false
995end
996seq = add get Q 1 1
997qbegin get Q 0 seq
998for i ulong n
999c = get In i
1000if or eq c 10 eq c 13
1001c = uchar 32
1002end
1003put JobOut i c
1004end
1005put T 0 now
1006put T 5 1
1007put T 6 0
1008put T 7 now
1009put T 8 n
1010put T 9 1
1011put T 13 0
1012ret true
1013end
1014fn qnext now ulong link bool to bool
1015if or eq get Q 0 0 lt now get T 0
1016ret false
1017end
1018if ne get T 10 0
1019ret false
1020end
1021put T 0 now
1022if not link
1023ret false
1024end
1025if ne get T 13 0
1026put Inlen 0 0
1027if not packet 3 get Q 1 get T 13 0 0
1028ret false
1029end
1030put T 10 3
1031put T 11 get T 13
1032ret true
1033end
1034delay = ulong 2000
1035if qready now
1036delay = ulong 10000
1037end
1038if or eq get T 3 0 ge sub now get T 4 delay
1039put Inlen 0 0
1040if not packet 5 0 0 0 0
1041ret false
1042end
1043put T 10 5
1044put T 11 0
1045ret true
1046end
1047if or eq get T 5 0 ne get T 6 0
1048ret false
1049end
1050part = get T 9
1051if eq part 0
1052if lt sub now get T 7 2000
1053ret false
1054end
1055part = ulong 1
1056end
1057n = get T 8
1058total = div add n 999 1000
1059off = mul sub part 1 1000
1060size = sub n off
1061if gt size 1000
1062size = ulong 1000
1063end
1064for i ulong size
1065put In i get JobOut add off i
1066end
1067put Inlen 0 size
1068if not packet 1 get Q 1 part total n
1069ret false
1070end
1071put T 10 1
1072put T 11 part
1073ret true
1074end
1075fn qsent now ulong ok bool to bool
1076if or eq get T 10 0 lt now get T 0
1077ret false
1078end
1079kind = get T 10
1080part = get T 11
1081put T 0 now
1082put T 10 0
1083put T 11 0
1084if not ok
1085ret true
1086end
1087if eq kind 5
1088put T 3 1
1089put T 4 now
1090end
1091if eq kind 3
1092if eq get T 13 part
1093put T 13 0
1094end
1095end
1096if eq kind 1
1097if or ne get T 6 0 ge part div add get T 8 999 1000
1098put T 9 0
1099put T 7 now
1100else
1101put T 9 add part 1
1102end
1103end
1104ret true
1105end
1106fn qincoming now ulong to ulong
1107if or eq get Q 0 0 lt now get T 0
1108ret 0
1109end
1110if not pkparse
1111ret 0
1112end
1113kind = get N 0
1114if eq kind 6
1115if or ne get N 1 0 ne get N 2 0
1116ret 0
1117end
1118if or ne get N 3 0 ne get N 4 0
1119ret 0
1120end
1121if ne get N 6 0
1122ret 0
1123end
1124put T 0 now
1125put T 1 1
1126put T 2 now
1127ret 1
1128end
1129if or eq get T 5 0 ne get N 1 get Q 1
1130ret 0
1131end
1132if eq kind 4
1133if or ne get N 2 0 ne get N 3 0
1134ret 0
1135end
1136if or ne get N 4 0 ne get N 6 0
1137ret 0
1138end
1139put T 0 now
1140put T 6 1
1141put T 9 0
1142ret 1
1143end
1144if ne kind 2
1145ret 0
1146end
1147if or ne get N 3 0 ne get N 4 0
1148ret 0
1149end
1150if and ne get T 13 0 ne get T 13 get N 2
1151ret 0
1152end
1153result = qreceive
1154if eq result 0
1155ret 0
1156end
1157put T 0 now
1158put T 6 1
1159put T 9 0
1160put T 13 get N 2
1161ret result
1162end
1163fn qcancel to void
1164put T 5 0
1165put T 6 0
1166put T 8 0
1167put T 9 0
1168put T 10 0
1169put T 11 0
1170put T 13 0
1171put Q 3 0
1172put Q 4 0
1173end
1174note Legacy application record codec; SHA is unkeyed integrity ONLY.
1175global Unit uchar 4096
1176global Enc uchar 4096
1177global Mem uchar 3692
1178global Md ulong 3
1179global Note uchar 128
1180global Ns ulong 4
1181text Magic "AIENALM1"
1182text Nmagic "AIENNOT1"
1183fn get32 off ulong to ulong
1184v = ulong 0
1185for i ulong 4
1186v = or v shl ulong get Unit add off i mul i 8
1187end
1188ret v
1189end
1190fn get64 off ulong to ulong
1191ret or get32 off shl get32 add off 4 32
1192end
1193fn put32 off ulong v ulong to void
1194for i ulong 4
1195put Unit add off i uchar and shr v mul i 8 255
1196end
1197end
1198fn put64 off ulong v ulong to void
1199put32 off and v 4294967295
1200put32 add off 4 shr v 32
1201end
1202fn mem32 off ulong to ulong
1203v = ulong 0
1204for i ulong 4
1205v = or v shl ulong get Mem add off i mul i 8
1206end
1207ret v
1208end
1209fn mset32 off ulong v ulong to void
1210for i ulong 4
1211put Mem add off i uchar and shr v mul i 8 255
1212end
1213end
1214fn zeroend off ulong to bool
1215for i ulong sub ulong 4096 off
1216if ne get Unit add off i 0
1217ret false
1218end
1219end
1220ret true
1221end
1222fn fieldok off ulong cap ulong name bool to bool
1223n = ulong 0
1224while lt n cap
1225if eq get Unit add off n 0
1226for j ulong sub cap n
1227if ne get Unit add add off n j 0
1228ret false
1229end
1230end
1231ret true
1232end
1233c = get Unit add off n
1234lower = and ge c 97 le c 122
1235digit = isdigit c
1236if name
1237if eq n 0
1238if not or and ge c 65 le c 90 digit
1239ret false
1240end
1241else
1242if not or lower digit
1243ret false
1244end
1245end
1246else
1247if eq c 32
1248if or eq n 0 eq n sub cap 1
1249ret false
1250end
1251if eq get Unit add off add n 1 0
1252ret false
1253end
1254if eq get Unit add off sub n 1 32
1255ret false
1256end
1257else
1258if not or lower digit
1259ret false
1260end
1261end
1262end
1263n = add n 1
1264end
1265ret false
1266end
1267fn digest count ulong to void
1268hinit
1269for i ulong 32
1270hbyte get Unit i
1271end
1272for i ulong count
1273hbyte get Unit add i 64
1274end
1275finish
1276end
1277fn hashok count ulong to bool
1278digest count
1279d = uchar 0
1280for i ulong 32
1281d = or d xor get Hash i get Unit add i 32
1282end
1283ret eq d 0
1284end
1285fn seal count ulong to void
1286digest count
1287for i ulong 32
1288put Unit add i 32 get Hash i
1289end
1290end
1291fn memvalid to bool
1292for i ulong 8
1293if ne get Unit i get Magic i
1294ret false
1295end
1296end
1297ver = get32 8
1298if or lt ver 2 gt ver 4
1299ret false
1300end
1301n = get32 96
1302if or gt n 32 gt get32 100 512
1303ret false
1304end
1305size = add 40 mul n 113
1306if ge ver 3
1307size = add size 24
1308end
1309if eq ver 4
1310size = add size 12
1311end
1312if or ne size get32 12 eq get64 16 0
1313ret false
1314end
1315for i ulong 8
1316if ne get Unit add i 24 0
1317ret false
1318end
1319end
1320if not zeroend add 64 size
1321ret false
1322end
1323if not hashok size
1324ret false
1325end
1326if not fieldok 72 24 true
1327ret false
1328end
1329for i ulong n
1330off = add 104 mul i 113
1331if or eq get Unit off 0 eq get Unit add off 48 0
1332ret false
1333end
1334if not fieldok off 48 false
1335ret false
1336end
1337if not fieldok add off 48 64 false
1338ret false
1339end
1340if gt get Unit add off 112 1
1341ret false
1342end
1343end
1344off = add 104 mul n 113
1345if ge ver 3
1346if not fieldok off 24 true
1347ret false
1348end
1349end
1350if eq ver 4
1351if ne get Unit add off 27 0
1352ret false
1353end
1354end
1355ret true
1356end
1357fn memdec to bool
1358if not memvalid
1359ret false
1360end
1361size = get32 12
1362for i ulong 3692
1363put Mem i 0
1364end
1365for i ulong size
1366put Mem i get Unit add i 64
1367end
1368put Md 0 get64 16
1369put Md 1 get32 8
1370put Md 2 size
1371ret true
1372end
1373fn memenc gen ulong to bool
1374n = mem32 32
1375if or gt n 32 eq gen 0
1376ret false
1377end
1378size = add 76 mul n 113
1379for i ulong 4096
1380put Unit i 0
1381end
1382for i ulong 8
1383put Unit i get Magic i
1384end
1385put32 8 4
1386put32 12 size
1387put64 16 gen
1388for i ulong size
1389put Unit add i 64 get Mem i
1390end
1391seal size
1392if not memvalid
1393ret false
1394end
1395for i ulong 4096
1396put Enc i get Unit i
1397end
1398ret true
1399end
1400fn noteval index ulong to bool
1401for i ulong 8
1402if ne get Unit i get Nmagic i
1403ret false
1404end
1405end
1406n = get32 12
1407if or eq n 0 ge n 128
1408ret false
1409end
1410if or ne get32 8 1 ne get32 16 index
1411ret false
1412end
1413if or gt get32 24 1 ne get32 28 0
1414ret false
1415end
1416if not zeroend add n 64
1417ret false
1418end
1419for i ulong n
1420c = get Unit add i 64
1421if or lt c 32 gt c 126
1422ret false
1423end
1424end
1425ret hashok n
1426end
1427fn notedec index ulong to bool
1428if not noteval index
1429ret false
1430end
1431n = get32 12
1432for i ulong 128
1433put Note i 0
1434end
1435for i ulong n
1436put Note i get Unit add i 64
1437end
1438put Ns 0 n
1439put Ns 1 index
1440put Ns 2 get32 20
1441put Ns 3 get32 24
1442ret true
1443end
1444fn noteenc to bool
1445n = get Ns 0
1446if or eq n 0 ge n 128
1447ret false
1448end
1449if or gt get Ns 1 511 gt get Ns 2 4294967295
1450ret false
1451end
1452if gt get Ns 3 1
1453ret false
1454end
1455for i ulong n
1456c = get Note i
1457if or lt c 32 gt c 126
1458ret false
1459end
1460end
1461for i ulong 4096
1462put Unit i 0
1463end
1464for i ulong 8
1465put Unit i get Nmagic i
1466end
1467put32 8 1
1468put32 12 n
1469put32 16 get Ns 1
1470put32 20 get Ns 2
1471put32 24 get Ns 3
1472for i ulong n
1473put Unit add i 64 get Note i
1474end
1475seal n
1476for i ulong 4096
1477put Enc i get Unit i
1478end
1479ret true
1480end
1481note Store St gen,newest,valid. Tx phase,target,newgen. Provider owns actual I/O.
1482global St ulong 3
1483global Nt ulong 2
1484global Load ulong 1
1485global Tx ulong 3
1486fn txbegin to bool
1487if ne get Nt 0 0
1488ret false
1489end
1490if or ne get Tx 0 0 eq get St 0 18446744073709551615
1491ret false
1492end
1493if not memenc add get St 0 1
1494ret false
1495end
1496put Tx 1 0
1497if ne get St 0 0
1498put Tx 1 sub ulong 1 get St 1
1499end
1500put Tx 2 add get St 0 1
1501put Tx 0 1
1502ret true
1503end
1504fn txwrite ok bool to bool
1505if ne get Tx 0 1
1506ret false
1507end
1508if not ok
1509put Tx 0 0
1510ret false
1511end
1512put Tx 0 2
1513ret true
1514end
1515fn txflush ok bool to bool
1516if ne get Tx 0 2
1517ret false
1518end
1519if not ok
1520put Tx 0 0
1521ret false
1522end
1523put Tx 0 3
1524ret true
1525end
1526fn txread ok bool to bool
1527if ne get Tx 0 3
1528ret false
1529end
1530put Tx 0 0
1531if not ok
1532ret false
1533end
1534d = uchar 0
1535for i ulong 4096
1536d = or d xor get Unit i get Enc i
1537end
1538if ne d 0
1539ret false
1540end
1541put St 0 get Tx 2
1542put St 1 get Tx 1
1543if lt get St 2 2
1544put St 2 add get St 2 1
1545end
1546ret true
1547end
1548note Load each copy once into Unit. Caller resets St and calls loadcopy0,1.
1549fn loadbeg to void
1550for i ulong 3
1551put St i 0
1552end
1553put Load 0 0
1554end
1555fn loadcopy slot ulong to bool
1556if gt slot 1
1557ret false
1558end
1559if ne and get Load 0 shl ulong 1 slot 0
1560ret false
1561end
1562if not memvalid
1563ret false
1564end
1565put Load 0 or get Load 0 shl ulong 1 slot
1566put St 2 add get St 2 1
1567if gt get64 16 get St 0
1568b = memdec
1569put St 0 get Md 0
1570put St 1 slot
1571end
1572ret true
1573end
1574note Note transaction completes before the parent copy may publish its count.
1575fn nbegin to bool
1576if or ne get Nt 0 0 ne get Tx 0 0
1577ret false
1578end
1579if not noteenc
1580ret false
1581end
1582put Nt 1 get Ns 1
1583put Nt 0 1
1584ret true
1585end
1586fn nwrite ok bool to bool
1587if ne get Nt 0 1
1588ret false
1589end
1590if not ok
1591put Nt 0 0
1592ret false
1593end
1594put Nt 0 2
1595ret true
1596end
1597fn nflush ok bool to bool
1598if ne get Nt 0 2
1599ret false
1600end
1601if not ok
1602put Nt 0 0
1603ret false
1604end
1605put Nt 0 3
1606ret true
1607end
1608fn nread ok bool to bool
1609if ne get Nt 0 3
1610ret false
1611end
1612put Nt 0 0
1613if not ok
1614ret false
1615end
1616d = uchar 0
1617for i ulong 4096
1618d = or d xor get Enc i get Unit i
1619end
1620if ne d 0
1621ret false
1622end
1623ret noteval get Nt 1
1624end
1625note Intent vocabulary frozen from svc/allen_intent.c. It selects jobs, never answers.
1626global Fold uchar 160
1627global Fn ulong 2
1628text Lists "please|can you|could you|would you|will you|i d like you to|i want you to|i need you to|allen|hey allen|ok|okay\nwrite|make|build|create|code|program|generate|implement|develop|give me a|i need a|i want a\ncode|program|programs|script|scripts|function|functions|app|apps|application|game|games|website|web page|webpage|calculator|converter|parser|compiler|interpreter|algorithm|class|api|server|bot|regex|unit test|unit tests|cli|command line tool|snake|tetris|pong|todo app|to do app|to do list app|timer app|stopwatch|python|javascript|typescript|rust|golang|java|kotlin|swift|ruby|php|html|css|sql|bash|shell script|c program|c code|in c|c plus plus|cpp|mojo|zig|haskell|lua|perl\npoem|poems|haiku|story|stories|song|songs|letter|email|essay|joke|jokes|limerick|speech\ncode|program|script\nnow|add|also|and|change|make it|make the|rename|remove|delete|replace|use|fix|put|give it|let it|instead|then|next|can it|could it|it should|the|move|turn|show|split|convert it|rewrite|port it|translate it|explain it\nwrite|make|build|create|code|program|draft|compose|generate|design|implement|invent|name|give me a|i need a|i want a\na poem|a haiku|a story|a song|a script|a function|a program|a list of|some code|a letter|an email|a plan for|a name for\nexplain|what is|what are|whats|what s|why|how does|how do|how is|how are|describe|tell me about|what does|who was|who is|define|when was|when did|where is|is it true\ndifference between|mean|means\ndo|run|fix|find|search|look up|check|open|send|start|stop|install|set up|plan|schedule|calculate|work out|convert|translate|summarize|summarise|list|sort|count|compare|turn|go\n"
1629fn foldin to void
1630n = ulong 0
1631space = false
1632for i ulong get Inlen 0
1633c = get In i
1634if and ge c 65 le c 90
1635c = add sub c 65 97
1636end
1637if or and ge c 97 le c 122 isdigit c
1638if and space gt n 0
1639put Fold n uchar 32
1640n = add n 1
1641end
1642put Fold n c
1643n = add n 1
1644space = false
1645else
1646space = true
1647end
1648end
1649put Fn 0 n
1650put Fn 1 0
1651end
1652fn phrase at ulong off ulong size ulong to bool
1653if gt add at size get Fn 0
1654ret false
1655end
1656for i ulong size
1657if ne get Fold add at i get Lists add off i
1658ret false
1659end
1660end
1661if lt add at size get Fn 0
1662if ne get Fold add at size 32
1663ret false
1664end
1665end
1666ret true
1667end
1668fn inphrase off ulong size ulong anypos bool to bool
1669if not anypos
1670ret phrase get Fn 1 off size
1671end
1672count = sub get Fn 0 get Fn 1
1673for i ulong count
1674at = add i get Fn 1
1675ok = eq at get Fn 1
1676if gt at 0
1677ok = or ok eq get Fold sub at 1 32
1678end
1679if ok
1680if phrase at off size
1681ret true
1682end
1683end
1684end
1685ret false
1686end
1687fn listed group ulong anypos bool to ulong
1688g = ulong 0
1689s = ulong 0
1690for p ulong len Lists
1691c = get Lists p
1692if or eq c 124 eq c 10
1693if eq g group
1694if inphrase s sub p s anypos
1695ret sub p s
1696end
1697end
1698s = add p 1
1699if eq c 10
1700g = add g 1
1701end
1702end
1703end
1704ret 0
1705end
1706fn classify to ulong
1707if not textok
1708ret 0
1709end
1710foldin
1711skip = listed 0 false
1712while gt skip 0
1713if ge add get Fn 1 skip get Fn 0
1714skip = 0
1715else
1716put Fn 1 add add get Fn 1 skip 1
1717skip = listed 0 false
1718end
1719end
1720if and ne get R 6 0 gt listed 5 false 0
1721ret 3
1722end
1723plain = listed 4 false
1724if or eq plain 4 eq plain 7
1725ret 2
1726end
1727if and gt listed 3 true 0 eq listed 4 true 0
1728ret 1
1729end
1730if and gt listed 1 false 0 gt listed 2 true 0
1731ret 2
1732end
1733ret 1
1734end
1735note Ordinary want enum0chat,1make,2explain,3do.
1736fn jobwant to ulong
1737if gt listed 8 false 0
1738ret 2
1739end
1740if or gt listed 6 false 0 gt listed 7 true 0
1741ret 1
1742end
1743if gt listed 10 false 0
1744ret 3
1745end
1746if gt listed 9 true 0
1747ret 2
1748end
1749ret 0
1750end
1751text Job "JOB "
1752text Codeask " asked "
1753text Forcode " for code.\t"
1754text Formore " to change the code just shown.\t"
1755text Wantstr "chatmakeexplaindo"
1756text Intro "You are the far hands of "
1757text Home ", a quiet presence living in AIENOS on "
1758text Comp "'s computer. You answer as "
1759text Sees "; "
1760text Words " sees only your words, as if "
1761text Said " said them. Plain English, short sentences, no headings, no lists, no greetings, no apologies. Plain letters and punctuation only: no dashes, no curly quotes, no symbols. Never mention a model, a prompt or instructions. "
1762text Make " asked for something to be made. Make it whole and correct. Begin with one short sentence saying what you made, then the work itself."
1763text Explain " asked to understand something. Explain it in three plain sentences at most, the heart of it first, no more than is needed."
1764text Doing " asked for something to be done. "
1765text Cannot " cannot yet act outside this computer, so say in two or three short sentences what you would do, in order, and what you would need."
1766text Chat " said something in passing. Answer in one or two warm, plain sentences."
1767text Allen "Allen"
1768text Person "the person"
1769fn selfemit to void
1770off = add 40 mul mem32 32 113
1771if eq get Mem off 0
1772for i ulong len Allen
1773emitb get Allen i
1774end
1775else
1776for i ulong 24
1777c = get Mem add off i
1778if eq c 0
1779ret
1780end
1781emitb c
1782end
1783end
1784end
1785fn whoemit to void
1786if eq get Mem 8 0
1787for i ulong len Person
1788emitb get Person i
1789end
1790else
1791for i ulong 24
1792c = get Mem add i 8
1793if eq c 0
1794ret
1795end
1796emitb c
1797end
1798end
1799end
1800fn jobbuild kind ulong seq ulong to bool
1801if or lt kind 1 gt kind 3
1802ret false
1803end
1804if or eq seq 0 gt seq 4294967295
1805ret false
1806end
1807if not textok
1808ret false
1809end
1810outreset
1811for i ulong len Job
1812emitb get Job i
1813end
1814emitn seq
1815emitb 32
1816if gt kind 1
1817emitb 99
1818emitb 111
1819emitb 100
1820emitb 101
1821if eq kind 3
1822emitb 45
1823emitb 109
1824emitb 111
1825emitb 114
1826emitb 101
1827end
1828emitb 32
1829whoemit
1830for i ulong len Codeask
1831emitb get Codeask i
1832end
1833selfemit
1834if eq kind 3
1835for i ulong len Formore
1836emitb get Formore i
1837end
1838else
1839for i ulong len Forcode
1840emitb get Forcode i
1841end
1842end
1843else
1844w = jobwant
1845off = ulong 0
1846size = ulong 4
1847if eq w 1
1848off = 4
1849end
1850if eq w 2
1851off = 8
1852size = 7
1853end
1854if eq w 3
1855off = 15
1856size = 2
1857end
1858for i ulong size
1859emitb get Wantstr add off i
1860end
1861emitb 32
1862for i ulong len Intro
1863emitb get Intro i
1864end
1865selfemit
1866for i ulong len Home
1867emitb get Home i
1868end
1869whoemit
1870for i ulong len Comp
1871emitb get Comp i
1872end
1873selfemit
1874for i ulong len Sees
1875emitb get Sees i
1876end
1877whoemit
1878for i ulong len Words
1879emitb get Words i
1880end
1881selfemit
1882for i ulong len Said
1883emitb get Said i
1884end
1885whoemit
1886if eq w 0
1887for i ulong len Chat
1888emitb get Chat i
1889end
1890end
1891if eq w 1
1892for i ulong len Make
1893emitb get Make i
1894end
1895end
1896if eq w 2
1897for i ulong len Explain
1898emitb get Explain i
1899end
1900end
1901if eq w 3
1902for i ulong len Doing
1903emitb get Doing i
1904end
1905selfemit
1906for i ulong len Cannot
1907emitb get Cannot i
1908end
1909end
1910emitb 9
1911end
1912for i ulong get Inlen 0
1913emitb get In i
1914end
1915ret le get Outlen 0 4096
1916end
1917note SAY/WAIT parser, staged folded bytes. Native CODE receive remains separate.
1918global Say uchar 160
1919global S ulong 5
1920fn sayhead to bool
1921put P 0 0
1922put P 2 0
1923if ineq 0 87
1924expect 87
1925expect 65
1926expect 73
1927expect 84
1928expect 32
1929number
1930put S 0 get P 1
1931put S 1 0
1932put S 2 0
1933if ne get P 0 get Inlen 0
1934ret false
1935end
1936ret eq get P 2 0
1937end
1938expect 83
1939expect 65
1940expect 89
1941expect 32
1942number
1943put S 0 get P 1
1944expect 32
1945if ne get P 2 0
1946ret false
1947end
1948put S 1 1
1949put S 2 1
1950save = get P 0
1951number
1952part = get P 1
1953if ineq get P 0 47
1954expect 47
1955number
1956put S 2 get P 1
1957expect 32
1958if or ne get P 2 0 eq part 0
1959ret false
1960end
1961put S 1 part
1962else
1963put P 0 save
1964put P 2 0
1965end
1966put S 3 get P 0
1967ret eq get P 2 0
1968end
1969fn sayfold to bool
1970n = ulong 0
1971p = get S 3
1972space = true
1973while lt p get Inlen 0
1974c = get In p
1975p = add p 1
1976if eq c 92
1977if or ineq p 110 ineq p 116
1978c = 32
1979p = add p 1
1980end
1981end
1982if or lt c 32 ge c 127
1983c = 32
1984end
1985if eq c 32
1986if not space
1987if ge n 159
1988ret false
1989end
1990put Say n c
1991n = add n 1
1992end
1993space = true
1994else
1995if ge n 159
1996ret false
1997end
1998put Say n c
1999n = add n 1
2000space = false
2001end
2002end
2003if gt n 0
2004if eq get Say sub n 1 32
2005n = sub n 1
2006end
2007end
2008put S 4 n
2009ret true
2010end
2011note Return1 accepted,2 request AGAIN,3 give up after retry;0 rejected.
2012fn saytake now ulong to ulong
2013if or eq get R 1 0 gt get Inlen 0 319
2014ret 0
2015end
2016if not sayhead
2017ret 0
2018end
2019if or ne get S 0 get R 0 lt now get R 4
2020ret 0
2021end
2022if eq get S 1 0
2023b = heard get S 0 now
2024ret 1
2025end
2026if not sayfold
2027ret 0
2028end
2029if gt get R 2 1
2030if eq get S 2 0
2031ret 0
2032end
2033if ne get C 0 get R 0
2034ret 0
2035end
2036if ne codestat 2
2037if eq get R 13 0
2038put R 13 1
2039outreset
2040emitb 65
2041emitb 71
2042emitb 65
2043emitb 73
2044emitb 78
2045emitb 32
2046emitn get R 0
2047ret 2
2048end
2049cancel
2050ret 3
2051end
2052else
2053if ne get S 1 add get R 11 1
2054ret 0
2055end
2056if and ne get S 2 0 ne get S 2 get S 1
2057ret 0
2058end
2059end
2060n = get R 8
2061if or eq get S 1 1 gt get R 2 1
2062n = 0
2063end
2064join = ulong 0
2065if and gt n 0 gt get S 4 0
2066join = 1
2067end
2068if gt add add n join get S 4 159
2069ret 0
2070end
2071if gt get R 2 1
2072if not codeshow get R 0
2073ret 0
2074end
2075end
2076if eq join 1
2077put Answer n uchar 32
2078n = add n 1
2079end
2080for i ulong get S 4
2081put Answer add n i get Say i
2082end
2083put R 8 add n get S 4
2084put R 11 get S 1
2085put R 4 now
2086if ne get S 2 0
2087put R 1 0
2088histadd 1
2089end
2090ret 1
2091end
2092note Exact legacy code row wrapping, at most4096 rows; full code retained.
2093global Rowst ulong 4096
2094global Rowlen ulong 4096
2095global Rowline ulong 4096
2096global View ulong 4
2097global Vwork ulong 6
2098note Vwork cols,maxrows,line,start,end.
2099fn onerow s ulong first bool to ulong
2100take = sub get Vwork 4 s
2101cols = get Vwork 0
2102if gt take cols
2103take = cols
2104j = cols
2105while gt j div cols 2
2106if eq get Code sub add s j 1 32
2107take = j
2108j = 0
2109else
2110j = sub j 1
2111end
2112end
2113end
2114slot = get View 0
2115put Rowst slot s
2116put Rowlen slot take
2117put Rowline slot 0
2118if first
2119put Rowline slot get Vwork 2
2120end
2121put View 0 add slot 1
2122ret add s take
2123end
2124fn rowroom pos ulong to bool
2125ret and lt pos get C 2 lt get View 0 get Vwork 1
2126end
2127fn moreline s ulong to bool
2128ret and lt s get Vwork 4 lt get View 0 get Vwork 1
2129end
2130fn rows cols ulong maxrows ulong to bool
2131if or eq cols 0 gt maxrows 4096
2132ret false
2133end
2134if ne codestat 2
2135ret false
2136end
2137put Vwork 0 cols
2138put Vwork 1 maxrows
2139put Vwork 2 1
2140put View 0 0
2141put View 1 0
2142pos = ulong 0
2143while rowroom pos
2144stop = pos
2145while lt stop get C 2
2146if eq get Code stop 10
2147put Vwork 4 stop
2148stop = get C 2
2149else
2150stop = add stop 1
2151put Vwork 4 stop
2152end
2153end
2154s = pos
2155if lt get View 0 maxrows
2156s = onerow s true
2157end
2158while moreline s
2159s = onerow s false
2160end
2161pos = add get Vwork 4 1
2162put Vwork 2 add get Vwork 2 1
2163end
2164ret true
2165end
2166fn scroll delta long page ulong to ulong
2167last = ulong 0
2168if gt get View 0 page
2169last = sub get View 0 page
2170end
2171if gt get View 1 last
2172put View 1 last
2173end
2174top = long get View 1
2175if lt delta 0
2176if lt delta neg top
2177put View 1 0
2178ret 0
2179end
2180else
2181if gt ulong delta sub last get View 1
2182put View 1 last
2183ret last
2184end
2185end
2186top = add top delta
2187put View 1 ulong top
2188ret ulong top
2189end
2190note Scene state: tone,water,has-say,nthings,used,lines,rejected,over.
2191global Sc ulong 8
2192global Things ulong 64
2193global Stext uchar 2304
2194global Sw ulong 4
2195global Fields uchar 1536
2196global Flens ulong 6
2197global Soffs ulong 6
2198text Vocab "mood|say|note|list|number|quote|person|timer|picture|video|left|right|above|warm|quiet|bloom|rise|fade|to|from|night|dawn|deep|clear|slow|still|lively|"
2199fn scword beg ulong size ulong to ulong
2200s = ulong 0
2201word = ulong 1
2202for i ulong len Vocab
2203if eq get Vocab i 124
2204if eq sub i s size
2205same = true
2206for j ulong size
2207if ne get In add beg j get Vocab add s j
2208same = false
2209end
2210end
2211if same
2212ret word
2213end
2214end
2215word = add word 1
2216s = add i 1
2217end
2218end
2219ret 0
2220end
2221fn fieldcap kind ulong field ulong to ulong
2222if eq kind 2
2223if eq field 0
2224ret 48
2225end
2226ret 64
2227end
2228if eq kind 1
2229if eq field 0
2230ret 48
2231end
2232ret 240
2233end
2234if eq kind 3
2235if eq field 0
2236ret 16
2237end
2238ret 64
2239end
2240if eq kind 4
2241if eq field 0
2242ret 220
2243end
2244ret 48
2245end
2246if eq kind 5
2247if eq field 0
2248ret 32
2249end
2250ret 200
2251end
2252if eq kind 6
2253if eq field 0
2254ret 24
2255end
2256ret 64
2257end
2258if eq field 0
2259ret 120
2260end
2261ret 64
2262end
2263fn scfield slot ulong beg ulong stop ulong kind ulong to bool
2264s = beg
2265e = stop
2266while lt s e
2267if eq get In s 32
2268s = add s 1
2269else
2270ret fieldend slot s e kind
2271end
2272end
2273put Flens slot 0
2274ret true
2275end
2276fn fieldend slot ulong s ulong stop ulong kind ulong to bool
2277e = stop
2278while gt e s
2279if eq get In sub e 1 32
2280e = sub e 1
2281else
2282n = sub e s
2283if gt n fieldcap kind slot
2284ret false
2285end
2286for i ulong n
2287c = get In add s i
2288if or lt c 32 gt c 126
2289ret false
2290end
2291put Fields add mul slot 256 i c
2292end
2293put Flens slot n
2294ret true
2295end
2296end
2297put Flens slot 0
2298ret true
2299end
2300fn scfields beg ulong stop ulong kind ulong to ulong
2301slot = ulong 0
2302s = beg
2303for i ulong sub stop beg
2304p = add beg i
2305if eq get In p 124
2306if ge slot 5
2307ret 0
2308end
2309if not scfield slot s p kind
2310ret 0
2311end
2312slot = add slot 1
2313s = add p 1
2314end
2315end
2316if not scfield slot s stop kind
2317ret 0
2318end
2319n = add slot 1
2320if and ne kind 2 gt n 2
2321ret 0
2322end
2323if eq get Flens 0 0
2324ret 0
2325end
2326if eq kind 5
2327if or lt n 2 eq get Flens 1 0
2328ret 0
2329end
2330end
2331if eq kind 3
2332hasdigit = false
2333for i ulong get Flens 0
2334if isdigit get Fields i
2335hasdigit = true
2336end
2337end
2338if not hasdigit
2339ret 0
2340end
2341end
2342ret n
2343end
2344fn scput slot ulong to ulong
2345off = get Sc 4
2346n = get Flens slot
2347for i ulong n
2348put Stext add off i get Fields add mul slot 256 i
2349end
2350put Stext add off n 0
2351put Sc 4 add add off n 1
2352ret off
2353end
2354fn scmod word ulong base ulong to void
2355if and ge word 11 le word 13
2356put Things add base 1 sub word 10
2357end
2358if and ge word 16 le word 18
2359put Things add base 2 sub word 16
2360end
2361if and ge word 19 le word 20
2362put Things add base 3 sub word 18
2363end
2364if eq word 14
2365put Things add base 4 1
2366end
2367if eq word 15
2368put Things add base 5 1
2369end
2370end
2371fn scsay beg ulong stop ulong to bool
2372if ne get Sc 2 0
2373ret false
2374end
2375n = sub stop beg
2376if or eq n 0 gt n 159
2377ret false
2378end
2379for i ulong n
2380c = get In add beg i
2381if or lt c 32 gt c 126
2382ret false
2383end
2384put Fields i c
2385end
2386put Flens 0 n
2387put Sc 2 1
2388put Sw 3 scput 0
2389ret true
2390end
2391fn scln beg ulong stop ulong to bool
2392p = beg
2393while lt p stop
2394if or eq get In p 32 eq get In p 58
2395ret scbody beg p stop
2396end
2397p = add p 1
2398end
2399ret false
2400end
2401fn scbody beg ulong wordend ulong stop ulong to bool
2402word = scword beg sub wordend beg
2403if eq word 2
2404s = add wordend 1
2405if lt s stop
2406if eq get In s 58
2407s = add s 1
2408end
2409end
2410while lt s stop
2411if eq get In s 32
2412s = add s 1
2413else
2414ret scsay s stop
2415end
2416end
2417ret false
2418end
2419if eq word 1
2420s = add wordend 1
2421for p ulong sub stop s
2422at = add add wordend 1 p
2423if eq get In at 32
2424w = scword s sub at s
2425if and ge w 21 le w 24
2426put Sc 0 sub w 21
2427end
2428if and ge w 25 le w 27
2429put Sc 1 sub w 25
2430end
2431s = add at 1
2432end
2433end
2434w = scword s sub stop s
2435if and ge w 21 le w 24
2436put Sc 0 sub w 21
2437end
2438if and ge w 25 le w 27
2439put Sc 1 sub w 25
2440end
2441ret true
2442end
2443if or lt word 3 gt word 10
2444ret false
2445end
2446if ge get Sc 3 4
2447put Sc 7 add get Sc 7 1
2448ret false
2449end
2450put Sw 0 sub word 2
2451colon = wordend
2452while lt colon stop
2453if eq get In colon 58
2454put Sw 1 wordend
2455put Sw 2 colon
2456ret scthing add colon 1 stop
2457end
2458colon = add colon 1
2459end
2460ret false
2461end
2462fn scthing beg ulong stop ulong to bool
2463n = scfields beg stop get Sw 0
2464if eq n 0
2465ret false
2466end
2467need = n
2468for i ulong n
2469need = add need get Flens i
2470end
2471if gt add get Sc 4 need 2304
2472ret false
2473end
2474base = mul get Sc 3 16
2475put Things base get Sw 0
2476put Things add base 6 n
2477s = get Sw 1
2478for p ulong sub get Sw 2 s
2479at = add get Sw 1 p
2480if eq get In at 32
2481w = scword s sub at s
2482scmod w base
2483s = add at 1
2484end
2485end
2486w = scword s sub get Sw 2 s
2487scmod w base
2488for i ulong n
2489put Things add add base 7 i scput i
2490end
2491put Sc 3 add get Sc 3 1
2492ret true
2493end
2494fn scene to bool
2495for i ulong 8
2496put Sc i 0
2497end
2498for i ulong 64
2499put Things i 0
2500end
2501put Sw 3 0
2502n = get Inlen 0
2503if gt n 2048
2504n = 2048
2505end
2506s = ulong 0
2507for p ulong n
2508if eq get In p 10
2509if gt p s
2510if lt get Sc 5 12
2511put Sc 5 add get Sc 5 1
2512if not scln s p
2513put Sc 6 add get Sc 6 1
2514end
2515else
2516put Sc 7 add get Sc 7 1
2517end
2518end
2519s = add p 1
2520end
2521end
2522if and lt s n lt get Sc 5 12
2523put Sc 5 add get Sc 5 1
2524if not scln s n
2525put Sc 6 add get Sc 6 1
2526end
2527end
2528ret or ne get Sc 2 0 ne get Sc 3 0
2529end
2530note Handwritten Omega port of paint.h ck_add, ck_scale, ck_mix and paint.c ck_glow.
2531note Bounded192x128 RAM canvas. This is rendering core, not full sky/font/device UI.
2532global Frame uint 24576
2533global G ulong 6
2534global Fb uchar 73728
2535fn channel c uint shift uint to uint
2536ret and shr c shift 255
2537end
2538fn addcolor d uint c uint a uint to uint
2539v = uint 0
2540for i uint 3
2541s = mul i 8
2542n = add channel d s shr mul channel c s a 8
2543if gt n 255
2544n = 255
2545end
2546v = or v shl n s
2547end
2548ret v
2549end
2550fn scale c uint f uint to uint
2551ret or and shr mul and c 16711935 f 8 16711935 and shr mul and c 65280 f 8 65280
2552end
2553fn mix d uint c uint a uint to uint
2554if ge a 256
2555ret c
2556end
2557ret add scale d sub uint 256 a scale c a
2558end
2559fn distance x ulong y ulong to ulong
2560dx = sub add mul long x 16 8 long get G 0
2561dy = sub add mul long y 16 8 long get G 1
2562ret ulong add mul dx dx mul dy dy
2563end
2564fn weight d2 ulong r2 ulong to ulong
2565inv = div ulong 1099511627776 r2
2566f = sub ulong 256 shr mul d2 inv 32
2567w = shr mul shr mul f f 8 f 8
2568ret shr mul w get G 4 8
2569end
2570fn glowpix x ulong y ulong to void
2571d2 = distance x y
2572r2 = mul get G 2 get G 2
2573if ge d2 r2
2574ret
2575end
2576a = uint weight d2 r2
2577at = add mul y 192 x
2578put Frame at addcolor get Frame at uint get G 3 a
2579end
2580fn glow cx ulong cy ulong radius ulong color ulong alpha ulong to bool
2581if or eq radius 0 gt radius 8192
2582ret false
2583end
2584if or gt cx 8192 gt cy 8192
2585ret false
2586end
2587if or gt color 16777215 gt alpha 512
2588ret false
2589end
2590put G 0 cx
2591put G 1 cy
2592put G 2 radius
2593put G 3 color
2594put G 4 alpha
2595for y ulong 128
2596for x ulong 192
2597glowpix x y
2598end
2599end
2600ret true
2601end
2602fn render to void
2603for i ulong 24576
2604put Frame i 0
2605end
2606note Frozen component pose; same halo and heart colors/weights as ck_mind_draw.
2607b = glow 1536 1024 1088 3951314 68
2608b = glow 1536 1024 640 7363839 46
2609b = glow 1536 1024 400 16765610 89
2610b = glow 1536 1024 160 16772310 218
2611b = glow 1536 1024 50 16775920 230
2612end
2613fn frameout to bool
2614for i ulong 24576
2615c = get Frame i
2616put Fb mul i 3 uchar channel c 16
2617put Fb add mul i 3 1 uchar channel c 8
2618put Fb add mul i 3 2 uchar channel c 0
2619end
2620n = ulong 0
2621while lt n len Fb
2622w = write 1 Fb n sub len Fb n
2623if le w 0
2624ret false
2625end
2626n = add n ulong w
2627end
2628ret true
2629end
2630note Native application binding: conversation state, courier lifecycle and reply/code.
2631note A initialized, queued AGAIN bytes, per-call event, reserved.
2632note Events:0 none,1 visible answer/ack,2 AGAIN queued,3 code give-up,
2633note 4 refused LINE payload,5 slow notice,6 silence timeout.
2634note Transport acceptance is separate from payload acceptance: appreceive true
2635note means envelope accepted; inspect A2 for malformed payload, never invent text.
2636global A ulong 4
2637global Appjob uchar 4096
2638global Askin uchar 160
2639fn appinit run ulong now ulong to bool
2640if or ne get A 0 0 ne get R 0 0
2641ret false
2642end
2643if ne get Q 0 0
2644ret false
2645end
2646if not qstart run now
2647ret false
2648end
2649constants
2650put A 0 1
2651put A 1 0
2652put A 2 0
2653ret true
2654end
2655fn appclock now ulong to bool
2656if eq get A 0 0
2657ret false
2658end
2659ret and ge now get T 0 ge now get R 4
2660end
2661fn appask now ulong to bool
2662if not appclock now
2663ret false
2664end
2665if or ne get R 1 0 ne get A 1 0
2666ret false
2667end
2668if or ne get T 10 0 ne get T 13 0
2669ret false
2670end
2671if and ne get T 5 0 eq get T 6 0
2672ret false
2673end
2674if or ge get R 0 4294967295 ge get Q 1 4294967295
2675ret false
2676end
2677if not textok
2678ret false
2679end
2680kind = classify
2681if or lt kind 1 gt kind 3
2682ret false
2683end
2684if and eq kind 3 eq get R 6 0
2685ret false
2686end
2687if not jobbuild kind add get R 0 1
2688ret false
2689end
2690n = get Inlen 0
2691size = get Outlen 0
2692for i ulong n
2693put Askin i get In i
2694end
2695for i ulong size
2696put Appjob i get Outb i
2697end
2698for i ulong size
2699put In i get Appjob i
2700end
2701put Inlen 0 size
2702queued = qsubmit now
2703for i ulong n
2704put In i get Askin i
2705end
2706put Inlen 0 n
2707if not queued
2708ret false
2709end
2710note start preconditions were checked before qsubmit; no concurrent calls permitted.
2711if not start kind now
2712qcancel
2713ret false
2714end
2715put A 2 0
2716if gt kind 1
2717codebeg get R 0
2718put A 2 1
2719end
2720ret true
2721end
2722fn appcancel to void
2723cancel
2724qcancel
2725put A 1 0
2726put A 2 0
2727end
2728fn appreset to void
2729appcancel
2730reset
2731end
2732fn apppoll now ulong link bool to bool
2733if not appclock now
2734ret false
2735end
2736put A 2 0
2737put T 0 now
2738status = tick now
2739if eq status 1
2740put A 2 5
2741end
2742if eq status 2
2743qcancel
2744put A 1 0
2745put A 2 6
2746end
2747note First acknowledge the triggering LINE; only then submit AGAIN under a new
2748note wire sequence. Its body keeps the original conversation ID.
2749if and gt get A 1 0 and eq get T 10 0 eq get T 13 0
2750put Inlen 0 get A 1
2751for i ulong get A 1
2752put In i get Appjob i
2753end
2754if not qsubmit now
2755appcancel
2756put A 2 3
2757ret false
2758end
2759put A 1 0
2760end
2761ret qnext now link
2762end
2763fn appsent now ulong ok bool to bool
2764if not appclock now
2765ret false
2766end
2767if not qsent now ok
2768ret false
2769end
2770put A 2 0
2771ret true
2772end
2773fn appreceive now ulong to bool
2774if not appclock now
2775ret false
2776end
2777result = qincoming now
2778if eq result 0
2779ret false
2780end
2781put A 2 0
2782if not qtake
2783ret true
2784end
2785if eq get R 1 0
2786put A 2 4
2787ret true
2788end
2789if ineq 0 67
2790if codetake
2791if heard get C 0 now
2792ret true
2793end
2794end
2795put A 2 4
2796ret true
2797end
2798if or ineq 0 83 ineq 0 87
2799status = saytake now
2800if eq status 1
2801if ne get S 1 0
2802put A 2 1
2803end
2804ret true
2805end
2806if eq status 2
2807n = get Outlen 0
2808if or eq n 0 gt n 4096
2809cancel
2810put A 1 0
2811put A 2 3
2812ret true
2813end
2814for i ulong n
2815put Appjob i get Outb i
2816end
2817put A 1 n
2818put A 2 2
2819ret true
2820end
2821if eq status 3
2822put A 1 0
2823put A 2 3
2824ret true
2825end
2826end
2827put A 2 4
2828ret true
2829end
2830global Fails ulong 1
2831global Checks ulong 1
2832fn check ok bool id ulong to void
2833put Checks 0 add get Checks 0 1
2834outreset
2835emitn id
2836if ok
2837emitb 32
2838emitb 48
2839else
2840put Fails 0 add get Fails 0 1
2841emitb 32
2842emitb 49
2843end
2844emitb 10
2845w = write 1 Outb 0 get Outlen 0
2846end
2847note End-to-end application core over real Omega protocol bytes; no socket simulation claim.
2848text Smallask "hello"
2849text Codeaskt "Please make me a calculator"
2850text Finaltxt " 1/1 Model answer."
2851text Codetxt " 1/1 9 3ce11e06 python print(1)\\n"
2852text Prefixes "SAY WAIT CODE "
2853text Againexp "AGAIN 2"
2854global SavedOut uchar 8192
2855fn test ok bool to void
2856n = get Outlen 0
2857e = get Err 0
2858for i ulong n
2859put SavedOut i get Outb i
2860end
2861check ok add get Checks 0 1
2862for i ulong n
2863put Outb i get SavedOut i
2864end
2865put Outlen 0 n
2866put Err 0 e
2867end
2868fn copyout to void
2869put Inlen 0 get Outlen 0
2870for i ulong get Outlen 0
2871put In i get Outb i
2872end
2873end
2874fn prompt code bool to void
2875if code
2876put Inlen 0 len Codeaskt
2877for i ulong len Codeaskt
2878put In i get Codeaskt i
2879end
2880else
2881put Inlen 0 len Smallask
2882for i ulong len Smallask
2883put In i get Smallask i
2884end
2885end
2886end
2887fn incoming part ulong seq ulong kind ulong to void
2888outreset
2889off = ulong 0
2890size = ulong 4
2891if eq kind 1
2892off = ulong 4
2893size = ulong 5
2894end
2895if eq kind 2
2896off = ulong 9
2897size = ulong 5
2898end
2899for i ulong size
2900emitb get Prefixes add off i
2901end
2902emitn seq
2903if eq kind 0
2904for i ulong len Finaltxt
2905emitb get Finaltxt i
2906end
2907end
2908if eq kind 2
2909for i ulong len Codetxt
2910emitb get Codetxt i
2911end
2912end
2913copyout
2914b = packet 2 get Q 1 part 0 0
2915copyout
2916end
2917fn main to int
2918test not appinit 0 100
2919test appinit 42 100
2920test not appinit 43 100
2921test eq get Q 0 42
2922prompt false
2923test appask 100
2924test eq get R 0 1
2925test eq get Q 1 1
2926test eq get R 9 1
2927test eq get R 1 1
2928test eq get A 2 0
2929prompt false
2930test not appask 101
2931test eq get R 9 1
2932test apppoll 100 true
2933test eq get T 10 5
2934test appsent 100 true
2935test apppoll 100 true
2936test eq get T 10 1
2937copyout
2938test pkparse
2939test eq get N 1 1
2940test eq get In get N 5 74
2941test appsent 100 true
2942incoming 1 1 0
2943test appreceive 101
2944test eq get A 2 1
2945test eq get R 1 0
2946test eq get R 8 13
2947test eq get R 9 2
2948test eq get Answer 0 77
2949prompt true
2950test not appask 102
2951test eq get R 0 1
2952test apppoll 102 true
2953test eq get T 10 3
2954test appsent 102 true
2955note Code acknowledgement is visible immediately, but missing code requests AGAIN.
2956prompt true
2957test appask 103
2958test eq get R 0 2
2959test eq get Q 1 2
2960test eq get R 2 2
2961test eq get A 2 1
2962test eq get R 8 len Ack
2963test apppoll 103 true
2964test appsent 103 false
2965test apppoll 104 true
2966test eq get T 10 1
2967test appsent 104 true
2968incoming 1 2 0
2969test appreceive 105
2970test eq get A 2 2
2971test eq get A 1 len Againexp
2972test eq get R 1 1
2973test eq get R 13 1
2974test apppoll 105 true
2975test eq get T 10 3
2976test eq get Q 1 2
2977test appsent 105 true
2978test apppoll 106 true
2979test eq get T 10 1
2980test eq get Q 1 3
2981test eq get R 0 2
2982copyout
2983test pkparse
2984test eq get N 6 len Againexp
2985bad = ulong 0
2986for i ulong len Againexp
2987if ne get In add get N 5 i get Againexp i
2988bad = add bad 1
2989end
2990end
2991test eq bad 0
2992test appsent 106 true
2993incoming 1 2 0
2994test appreceive 107
2995test eq get A 2 3
2996test eq get R 1 0
2997test eq get A 1 0
2998note Reset cancels pending delivery without reusing either counter.
2999appreset
3000test eq get R 0 2
3001test eq get Q 1 3
3002test eq get R 9 0
3003prompt false
3004test appask 108
3005test eq get R 0 3
3006test eq get Q 1 4
3007test apppoll 108 true
3008test appsent 108 true
3009incoming 1 2 0
3010test appreceive 109
3011test eq get A 2 4
3012test eq get R 1 1
3013test eq get R 8 0
3014test apppoll 109 true
3015test appsent 109 true
3016incoming 2 3 0
3017test appreceive 110
3018test eq get A 2 1
3019test eq get R 1 0
3020test eq get R 9 2
3021test apppoll 110 true
3022test appsent 110 true
3023note Cancellation drops an outstanding send and stale response safely.
3024prompt false
3025test appask 111
3026test apppoll 111 true
3027appcancel
3028test eq get R 1 0
3029test eq get T 5 0
3030test not appsent 111 true
3031incoming 1 4 0
3032test not appreceive 112
3033note Complete CODE bytes must arrive before a code response becomes visible.
3034prompt true
3035test appask 113
3036test eq get R 0 5
3037test eq get Q 1 6
3038test apppoll 113 true
3039test appsent 113 true
3040incoming 1 5 2
3041test appreceive 114
3042test eq get A 2 0
3043test eq codestat 2
3044test eq get R 6 0
3045test apppoll 114 true
3046test appsent 114 true
3047incoming 2 5 0
3048test appreceive 115
3049test eq get A 2 1
3050test eq get R 6 1
3051test eq get R 1 0
3052test eq get Code 6 49
3053test apppoll 115 true
3054test appsent 115 true
3055note WAIT updates silence deadline, no answer; slow and timeout cancel both layers.
3056prompt false
3057test appask 116
3058test eq get R 0 6
3059test apppoll 116 true
3060test appsent 116 true
3061incoming 1 6 1
3062test appreceive 117
3063test eq get A 2 0
3064test eq get R 4 117
3065test apppoll 117 true
3066test appsent 117 true
3067v = apppoll 20116 true
3068test eq get A 2 5
3069test eq get R 1 1
3070if v
3071test appsent 20116 true
3072end
3073v = apppoll 30116 true
3074test eq get R 1 1
3075if v
3076test appsent 30116 true
3077end
3078v = apppoll 30117 true
3079test eq get A 2 6
3080test eq get R 1 0
3081test eq get T 5 0
3082test eq get A 1 0
3083if v
3084test appsent 30117 true
3085end
3086n = get R 9
3087prompt false
3088test not appask 30116
3089test eq get R 9 n
3090test not apppoll 30116 true
3091note Invalid prompt never becomes a pending job or transcript line.
3092put Inlen 0 160
3093test not appask 30118
3094test eq get R 9 n
3095test eq get R 0 6
3096test eq get Q 1 7
3097ret int get Fails 0
3098end