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 / intent-edge-red.om

2395 lines · 38606 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 Legacy application record codec; SHA is unkeyed integrity ONLY.
953global Unit uchar 4096
954global Enc uchar 4096
955global Mem uchar 3692
956global Md ulong 3
957global Note uchar 128
958global Ns ulong 4
959text Magic "AIENALM1"
960text Nmagic "AIENNOT1"
961fn get32 off ulong to ulong
962v = ulong 0
963for i ulong 4
964v = or v shl ulong get Unit add off i mul i 8
965end
966ret v
967end
968fn get64 off ulong to ulong
969ret or get32 off shl get32 add off 4 32
970end
971fn put32 off ulong v ulong to void
972for i ulong 4
973put Unit add off i uchar and shr v mul i 8 255
974end
975end
976fn put64 off ulong v ulong to void
977put32 off and v 4294967295
978put32 add off 4 shr v 32
979end
980fn mem32 off ulong to ulong
981v = ulong 0
982for i ulong 4
983v = or v shl ulong get Mem add off i mul i 8
984end
985ret v
986end
987fn mset32 off ulong v ulong to void
988for i ulong 4
989put Mem add off i uchar and shr v mul i 8 255
990end
991end
992fn zeroend off ulong to bool
993for i ulong sub ulong 4096 off
994if ne get Unit add off i 0
995ret false
996end
997end
998ret true
999end
1000fn fieldok off ulong cap ulong name bool to bool
1001n = ulong 0
1002while lt n cap
1003if eq get Unit add off n 0
1004for j ulong sub cap n
1005if ne get Unit add add off n j 0
1006ret false
1007end
1008end
1009ret true
1010end
1011c = get Unit add off n
1012lower = and ge c 97 le c 122
1013digit = isdigit c
1014if name
1015if eq n 0
1016if not or and ge c 65 le c 90 digit
1017ret false
1018end
1019else
1020if not or lower digit
1021ret false
1022end
1023end
1024else
1025if eq c 32
1026if or eq n 0 eq n sub cap 1
1027ret false
1028end
1029if eq get Unit add off add n 1 0
1030ret false
1031end
1032if eq get Unit add off sub n 1 32
1033ret false
1034end
1035else
1036if not or lower digit
1037ret false
1038end
1039end
1040end
1041n = add n 1
1042end
1043ret false
1044end
1045fn digest count ulong to void
1046hinit
1047for i ulong 32
1048hbyte get Unit i
1049end
1050for i ulong count
1051hbyte get Unit add i 64
1052end
1053finish
1054end
1055fn hashok count ulong to bool
1056digest count
1057d = uchar 0
1058for i ulong 32
1059d = or d xor get Hash i get Unit add i 32
1060end
1061ret eq d 0
1062end
1063fn seal count ulong to void
1064digest count
1065for i ulong 32
1066put Unit add i 32 get Hash i
1067end
1068end
1069fn memvalid to bool
1070for i ulong 8
1071if ne get Unit i get Magic i
1072ret false
1073end
1074end
1075ver = get32 8
1076if or lt ver 2 gt ver 4
1077ret false
1078end
1079n = get32 96
1080if or gt n 32 gt get32 100 512
1081ret false
1082end
1083size = add 40 mul n 113
1084if ge ver 3
1085size = add size 24
1086end
1087if eq ver 4
1088size = add size 12
1089end
1090if or ne size get32 12 eq get64 16 0
1091ret false
1092end
1093for i ulong 8
1094if ne get Unit add i 24 0
1095ret false
1096end
1097end
1098if not zeroend add 64 size
1099ret false
1100end
1101if not hashok size
1102ret false
1103end
1104if not fieldok 72 24 true
1105ret false
1106end
1107for i ulong n
1108off = add 104 mul i 113
1109if or eq get Unit off 0 eq get Unit add off 48 0
1110ret false
1111end
1112if not fieldok off 48 false
1113ret false
1114end
1115if not fieldok add off 48 64 false
1116ret false
1117end
1118if gt get Unit add off 112 1
1119ret false
1120end
1121end
1122off = add 104 mul n 113
1123if ge ver 3
1124if not fieldok off 24 true
1125ret false
1126end
1127end
1128if eq ver 4
1129if ne get Unit add off 27 0
1130ret false
1131end
1132end
1133ret true
1134end
1135fn memdec to bool
1136if not memvalid
1137ret false
1138end
1139size = get32 12
1140for i ulong 3692
1141put Mem i 0
1142end
1143for i ulong size
1144put Mem i get Unit add i 64
1145end
1146put Md 0 get64 16
1147put Md 1 get32 8
1148put Md 2 size
1149ret true
1150end
1151fn memenc gen ulong to bool
1152n = mem32 32
1153if or gt n 32 eq gen 0
1154ret false
1155end
1156size = add 76 mul n 113
1157for i ulong 4096
1158put Unit i 0
1159end
1160for i ulong 8
1161put Unit i get Magic i
1162end
1163put32 8 4
1164put32 12 size
1165put64 16 gen
1166for i ulong size
1167put Unit add i 64 get Mem i
1168end
1169seal size
1170if not memvalid
1171ret false
1172end
1173for i ulong 4096
1174put Enc i get Unit i
1175end
1176ret true
1177end
1178fn noteval index ulong to bool
1179for i ulong 8
1180if ne get Unit i get Nmagic i
1181ret false
1182end
1183end
1184n = get32 12
1185if or eq n 0 ge n 128
1186ret false
1187end
1188if or ne get32 8 1 ne get32 16 index
1189ret false
1190end
1191if or gt get32 24 1 ne get32 28 0
1192ret false
1193end
1194if not zeroend add n 64
1195ret false
1196end
1197for i ulong n
1198c = get Unit add i 64
1199if or lt c 32 gt c 126
1200ret false
1201end
1202end
1203ret hashok n
1204end
1205fn notedec index ulong to bool
1206if not noteval index
1207ret false
1208end
1209n = get32 12
1210for i ulong 128
1211put Note i 0
1212end
1213for i ulong n
1214put Note i get Unit add i 64
1215end
1216put Ns 0 n
1217put Ns 1 index
1218put Ns 2 get32 20
1219put Ns 3 get32 24
1220ret true
1221end
1222fn noteenc to bool
1223n = get Ns 0
1224if or eq n 0 ge n 128
1225ret false
1226end
1227if gt get Ns 3 1
1228ret false
1229end
1230for i ulong n
1231c = get Note i
1232if or lt c 32 gt c 126
1233ret false
1234end
1235end
1236for i ulong 4096
1237put Unit i 0
1238end
1239for i ulong 8
1240put Unit i get Nmagic i
1241end
1242put32 8 1
1243put32 12 n
1244put32 16 get Ns 1
1245put32 20 get Ns 2
1246put32 24 get Ns 3
1247for i ulong n
1248put Unit add i 64 get Note i
1249end
1250seal n
1251for i ulong 4096
1252put Enc i get Unit i
1253end
1254ret true
1255end
1256note Store St gen,newest,valid. Tx phase,target,newgen. Provider owns actual I/O.
1257global St ulong 3
1258global Tx ulong 3
1259fn txbegin to bool
1260if or ne get Tx 0 0 eq get St 0 18446744073709551615
1261ret false
1262end
1263if not memenc add get St 0 1
1264ret false
1265end
1266put Tx 1 0
1267if ne get St 0 0
1268put Tx 1 sub ulong 1 get St 1
1269end
1270put Tx 2 add get St 0 1
1271put Tx 0 1
1272ret true
1273end
1274fn txwrite ok bool to bool
1275if ne get Tx 0 1
1276ret false
1277end
1278if not ok
1279put Tx 0 0
1280ret false
1281end
1282put Tx 0 2
1283ret true
1284end
1285fn txflush ok bool to bool
1286if ne get Tx 0 2
1287ret false
1288end
1289if not ok
1290put Tx 0 0
1291ret false
1292end
1293put Tx 0 3
1294ret true
1295end
1296fn txread ok bool to bool
1297if ne get Tx 0 3
1298ret false
1299end
1300put Tx 0 0
1301if not ok
1302ret false
1303end
1304d = uchar 0
1305for i ulong 4096
1306d = or d xor get Unit i get Enc i
1307end
1308if ne d 0
1309ret false
1310end
1311put St 0 get Tx 2
1312put St 1 get Tx 1
1313if lt get St 2 2
1314put St 2 add get St 2 1
1315end
1316ret true
1317end
1318note Load each copy once into Unit. Caller resets St and calls loadcopy0,1.
1319fn loadcopy slot ulong to bool
1320if gt slot 1
1321ret false
1322end
1323if not memvalid
1324ret false
1325end
1326put St 2 add get St 2 1
1327if gt get64 16 get St 0
1328b = memdec
1329put St 0 get Md 0
1330put St 1 slot
1331end
1332ret true
1333end
1334note Intent vocabulary frozen from svc/allen_intent.c. It selects jobs, never answers.
1335global Fold uchar 160
1336global Fn ulong 2
1337text 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"
1338fn foldin to void
1339n = ulong 0
1340space = false
1341for i ulong get Inlen 0
1342c = get In i
1343if and ge c 65 le c 90
1344c = add sub c 65 97
1345end
1346if or and ge c 97 le c 122 isdigit c
1347if and space gt n 0
1348put Fold n uchar 32
1349n = add n 1
1350end
1351put Fold n c
1352n = add n 1
1353space = false
1354else
1355space = true
1356end
1357end
1358put Fn 0 n
1359put Fn 1 0
1360end
1361fn phrase at ulong off ulong size ulong to bool
1362if gt add at size get Fn 0
1363ret false
1364end
1365for i ulong size
1366if ne get Fold add at i get Lists add off i
1367ret false
1368end
1369end
1370if lt add at size get Fn 0
1371if ne get Fold add at size 32
1372ret false
1373end
1374end
1375ret true
1376end
1377fn inphrase off ulong size ulong anypos bool to bool
1378if not anypos
1379ret phrase get Fn 1 off size
1380end
1381count = sub get Fn 0 get Fn 1
1382for i ulong count
1383at = add i get Fn 1
1384ok = eq at get Fn 1
1385if gt at 0
1386ok = or ok eq get Fold sub at 1 32
1387end
1388if ok
1389if phrase at off size
1390ret true
1391end
1392end
1393end
1394ret false
1395end
1396fn listed group ulong anypos bool to ulong
1397g = ulong 0
1398s = ulong 0
1399for p ulong len Lists
1400c = get Lists p
1401if or eq c 124 eq c 10
1402if eq g group
1403if inphrase s sub p s anypos
1404ret sub p s
1405end
1406end
1407s = add p 1
1408if eq c 10
1409g = add g 1
1410end
1411end
1412end
1413ret 0
1414end
1415fn classify to ulong
1416if not textok
1417ret 0
1418end
1419foldin
1420skip = listed 0 false
1421while gt skip 0
1422if ge add get Fn 1 skip get Fn 0
1423skip = 0
1424else
1425put Fn 1 add add get Fn 1 skip 1
1426skip = listed 0 false
1427end
1428end
1429if and ne get R 6 0 gt listed 5 false 0
1430ret 3
1431end
1432if gt listed 4 false 0
1433ret 2
1434end
1435if and gt listed 3 true 0 eq listed 4 true 0
1436ret 1
1437end
1438if and gt listed 1 false 0 gt listed 2 true 0
1439ret 2
1440end
1441ret 1
1442end
1443note Ordinary want enum0chat,1make,2explain,3do.
1444fn jobwant to ulong
1445if gt listed 8 false 0
1446ret 2
1447end
1448if or gt listed 6 false 0 gt listed 7 true 0
1449ret 1
1450end
1451if gt listed 10 false 0
1452ret 3
1453end
1454if gt listed 9 true 0
1455ret 2
1456end
1457ret 0
1458end
1459text Job "JOB "
1460text Codeask " asked "
1461text Forcode " for code.\t"
1462text Formore " to change the code just shown.\t"
1463text Wantstr "chatmakeexplaindo"
1464text Intro "You are the far hands of "
1465text Home ", a quiet presence living in AIENOS on "
1466text Comp "'s computer. You answer as "
1467text Sees "; "
1468text Words " sees only your words, as if "
1469text 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. "
1470text 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."
1471text Explain " asked to understand something. Explain it in three plain sentences at most, the heart of it first, no more than is needed."
1472text Doing " asked for something to be done. "
1473text 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."
1474text Chat " said something in passing. Answer in one or two warm, plain sentences."
1475text Allen "Allen"
1476text Person "the person"
1477fn selfemit to void
1478off = add 40 mul mem32 32 113
1479if eq get Mem off 0
1480for i ulong len Allen
1481emitb get Allen i
1482end
1483else
1484for i ulong 24
1485c = get Mem add off i
1486if eq c 0
1487ret
1488end
1489emitb c
1490end
1491end
1492end
1493fn whoemit to void
1494if eq get Mem 8 0
1495for i ulong len Person
1496emitb get Person i
1497end
1498else
1499for i ulong 24
1500c = get Mem add i 8
1501if eq c 0
1502ret
1503end
1504emitb c
1505end
1506end
1507end
1508fn jobbuild kind ulong seq ulong to bool
1509if or lt kind 1 gt kind 3
1510ret false
1511end
1512if or eq seq 0 gt seq 4294967295
1513ret false
1514end
1515if not textok
1516ret false
1517end
1518outreset
1519for i ulong len Job
1520emitb get Job i
1521end
1522emitn seq
1523emitb 32
1524if gt kind 1
1525emitb 99
1526emitb 111
1527emitb 100
1528emitb 101
1529if eq kind 3
1530emitb 45
1531emitb 109
1532emitb 111
1533emitb 114
1534emitb 101
1535end
1536emitb 32
1537whoemit
1538for i ulong len Codeask
1539emitb get Codeask i
1540end
1541selfemit
1542if eq kind 3
1543for i ulong len Formore
1544emitb get Formore i
1545end
1546else
1547for i ulong len Forcode
1548emitb get Forcode i
1549end
1550end
1551else
1552w = jobwant
1553off = ulong 0
1554size = ulong 4
1555if eq w 1
1556off = 4
1557end
1558if eq w 2
1559off = 8
1560size = 7
1561end
1562if eq w 3
1563off = 15
1564size = 2
1565end
1566for i ulong size
1567emitb get Wantstr add off i
1568end
1569emitb 32
1570for i ulong len Intro
1571emitb get Intro i
1572end
1573selfemit
1574for i ulong len Home
1575emitb get Home i
1576end
1577whoemit
1578for i ulong len Comp
1579emitb get Comp i
1580end
1581selfemit
1582for i ulong len Sees
1583emitb get Sees i
1584end
1585whoemit
1586for i ulong len Words
1587emitb get Words i
1588end
1589selfemit
1590for i ulong len Said
1591emitb get Said i
1592end
1593whoemit
1594if eq w 0
1595for i ulong len Chat
1596emitb get Chat i
1597end
1598end
1599if eq w 1
1600for i ulong len Make
1601emitb get Make i
1602end
1603end
1604if eq w 2
1605for i ulong len Explain
1606emitb get Explain i
1607end
1608end
1609if eq w 3
1610for i ulong len Doing
1611emitb get Doing i
1612end
1613selfemit
1614for i ulong len Cannot
1615emitb get Cannot i
1616end
1617end
1618emitb 9
1619end
1620for i ulong get Inlen 0
1621emitb get In i
1622end
1623ret le get Outlen 0 4096
1624end
1625note SAY/WAIT parser, staged folded bytes. Native CODE receive remains separate.
1626global Say uchar 160
1627global S ulong 5
1628fn sayhead to bool
1629put P 0 0
1630put P 2 0
1631if ineq 0 87
1632expect 87
1633expect 65
1634expect 73
1635expect 84
1636expect 32
1637number
1638put S 0 get P 1
1639put S 1 0
1640put S 2 0
1641if ne get P 0 get Inlen 0
1642ret false
1643end
1644ret eq get P 2 0
1645end
1646expect 83
1647expect 65
1648expect 89
1649expect 32
1650number
1651put S 0 get P 1
1652expect 32
1653if ne get P 2 0
1654ret false
1655end
1656put S 1 1
1657put S 2 1
1658save = get P 0
1659number
1660part = get P 1
1661if ineq get P 0 47
1662expect 47
1663number
1664put S 2 get P 1
1665expect 32
1666if or ne get P 2 0 eq part 0
1667ret false
1668end
1669put S 1 part
1670else
1671put P 0 save
1672put P 2 0
1673end
1674put S 3 get P 0
1675ret eq get P 2 0
1676end
1677fn sayfold to bool
1678n = ulong 0
1679p = get S 3
1680space = true
1681while lt p get Inlen 0
1682c = get In p
1683p = add p 1
1684if eq c 92
1685if or ineq p 110 ineq p 116
1686c = 32
1687p = add p 1
1688end
1689end
1690if or lt c 32 ge c 127
1691c = 32
1692end
1693if eq c 32
1694if not space
1695if ge n 159
1696ret false
1697end
1698put Say n c
1699n = add n 1
1700end
1701space = true
1702else
1703if ge n 159
1704ret false
1705end
1706put Say n c
1707n = add n 1
1708space = false
1709end
1710end
1711if gt n 0
1712if eq get Say sub n 1 32
1713n = sub n 1
1714end
1715end
1716put S 4 n
1717ret true
1718end
1719note Return1 accepted,2 request AGAIN,3 give up after retry;0 rejected.
1720fn saytake now ulong to ulong
1721if or eq get R 1 0 gt get Inlen 0 319
1722ret 0
1723end
1724if not sayhead
1725ret 0
1726end
1727if or ne get S 0 get R 0 lt now get R 4
1728ret 0
1729end
1730if eq get S 1 0
1731b = heard get S 0 now
1732ret 1
1733end
1734if not sayfold
1735ret 0
1736end
1737if gt get R 2 1
1738if eq get S 2 0
1739ret 0
1740end
1741if ne get C 0 get R 0
1742ret 0
1743end
1744if ne codestat 2
1745if eq get R 13 0
1746put R 13 1
1747outreset
1748emitb 65
1749emitb 71
1750emitb 65
1751emitb 73
1752emitb 78
1753emitb 32
1754emitn get R 0
1755ret 2
1756end
1757cancel
1758ret 3
1759end
1760else
1761if ne get S 1 add get R 11 1
1762ret 0
1763end
1764if and ne get S 2 0 ne get S 2 get S 1
1765ret 0
1766end
1767end
1768n = get R 8
1769if or eq get S 1 1 gt get R 2 1
1770n = 0
1771end
1772join = ulong 0
1773if and gt n 0 gt get S 4 0
1774join = 1
1775end
1776if gt add add n join get S 4 159
1777ret 0
1778end
1779if gt get R 2 1
1780if not codeshow get R 0
1781ret 0
1782end
1783end
1784if eq join 1
1785put Answer n uchar 32
1786n = add n 1
1787end
1788for i ulong get S 4
1789put Answer add n i get Say i
1790end
1791put R 8 add n get S 4
1792put R 11 get S 1
1793put R 4 now
1794if ne get S 2 0
1795put R 1 0
1796histadd 1
1797end
1798ret 1
1799end
1800note Exact legacy code row wrapping, at most4096 rows; full code retained.
1801global Rowst ulong 4096
1802global Rowlen ulong 4096
1803global Rowline ulong 4096
1804global View ulong 4
1805global Vwork ulong 6
1806note Vwork cols,maxrows,line,start,end.
1807fn onerow s ulong first bool to ulong
1808take = sub get Vwork 4 s
1809cols = get Vwork 0
1810if gt take cols
1811take = cols
1812j = cols
1813while gt j div cols 2
1814if eq get Code sub add s j 1 32
1815take = j
1816j = 0
1817else
1818j = sub j 1
1819end
1820end
1821end
1822slot = get View 0
1823put Rowst slot s
1824put Rowlen slot take
1825put Rowline slot 0
1826if first
1827put Rowline slot get Vwork 2
1828end
1829put View 0 add slot 1
1830ret add s take
1831end
1832fn rowroom pos ulong to bool
1833ret and lt pos get C 2 lt get View 0 get Vwork 1
1834end
1835fn moreline s ulong to bool
1836ret and lt s get Vwork 4 lt get View 0 get Vwork 1
1837end
1838fn rows cols ulong maxrows ulong to bool
1839if or eq cols 0 gt maxrows 4096
1840ret false
1841end
1842if ne codestat 2
1843ret false
1844end
1845put Vwork 0 cols
1846put Vwork 1 maxrows
1847put Vwork 2 1
1848put View 0 0
1849put View 1 0
1850pos = ulong 0
1851while rowroom pos
1852stop = pos
1853while lt stop get C 2
1854if eq get Code stop 10
1855put Vwork 4 stop
1856stop = get C 2
1857else
1858stop = add stop 1
1859put Vwork 4 stop
1860end
1861end
1862s = pos
1863if lt get View 0 maxrows
1864s = onerow s true
1865end
1866while moreline s
1867s = onerow s false
1868end
1869pos = add get Vwork 4 1
1870put Vwork 2 add get Vwork 2 1
1871end
1872ret true
1873end
1874fn scroll delta long page ulong to ulong
1875last = ulong 0
1876if gt get View 0 page
1877last = sub get View 0 page
1878end
1879if gt get View 1 last
1880put View 1 last
1881end
1882top = long get View 1
1883if lt delta 0
1884if lt delta neg top
1885put View 1 0
1886ret 0
1887end
1888else
1889if gt ulong delta sub last get View 1
1890put View 1 last
1891ret last
1892end
1893end
1894top = add top delta
1895put View 1 ulong top
1896ret ulong top
1897end
1898note Scene state: tone,water,has-say,nthings,used,lines,rejected,over.
1899global Sc ulong 8
1900global Things ulong 64
1901global Stext uchar 2304
1902global Sw ulong 4
1903global Fields uchar 1536
1904global Flens ulong 6
1905global Soffs ulong 6
1906text 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|"
1907fn scword beg ulong size ulong to ulong
1908s = ulong 0
1909word = ulong 1
1910for i ulong len Vocab
1911if eq get Vocab i 124
1912if eq sub i s size
1913same = true
1914for j ulong size
1915if ne get In add beg j get Vocab add s j
1916same = false
1917end
1918end
1919if same
1920ret word
1921end
1922end
1923word = add word 1
1924s = add i 1
1925end
1926end
1927ret 0
1928end
1929fn fieldcap kind ulong field ulong to ulong
1930if eq kind 2
1931if eq field 0
1932ret 48
1933end
1934ret 64
1935end
1936if eq kind 1
1937if eq field 0
1938ret 48
1939end
1940ret 240
1941end
1942if eq kind 3
1943if eq field 0
1944ret 16
1945end
1946ret 64
1947end
1948if eq kind 4
1949if eq field 0
1950ret 220
1951end
1952ret 48
1953end
1954if eq kind 5
1955if eq field 0
1956ret 32
1957end
1958ret 200
1959end
1960if eq kind 6
1961if eq field 0
1962ret 24
1963end
1964ret 64
1965end
1966if eq field 0
1967ret 120
1968end
1969ret 64
1970end
1971fn scfield slot ulong beg ulong stop ulong kind ulong to bool
1972s = beg
1973e = stop
1974while lt s e
1975if eq get In s 32
1976s = add s 1
1977else
1978ret fieldend slot s e kind
1979end
1980end
1981put Flens slot 0
1982ret true
1983end
1984fn fieldend slot ulong s ulong stop ulong kind ulong to bool
1985e = stop
1986while gt e s
1987if eq get In sub e 1 32
1988e = sub e 1
1989else
1990n = sub e s
1991if gt n fieldcap kind slot
1992ret false
1993end
1994for i ulong n
1995c = get In add s i
1996if or lt c 32 gt c 126
1997ret false
1998end
1999put Fields add mul slot 256 i c
2000end
2001put Flens slot n
2002ret true
2003end
2004end
2005put Flens slot 0
2006ret true
2007end
2008fn scfields beg ulong stop ulong kind ulong to ulong
2009slot = ulong 0
2010s = beg
2011for i ulong sub stop beg
2012p = add beg i
2013if eq get In p 124
2014if ge slot 5
2015ret 0
2016end
2017if not scfield slot s p kind
2018ret 0
2019end
2020slot = add slot 1
2021s = add p 1
2022end
2023end
2024if not scfield slot s stop kind
2025ret 0
2026end
2027n = add slot 1
2028if and ne kind 2 gt n 2
2029ret 0
2030end
2031if eq get Flens 0 0
2032ret 0
2033end
2034if eq kind 5
2035if or lt n 2 eq get Flens 1 0
2036ret 0
2037end
2038end
2039if eq kind 3
2040hasdigit = false
2041for i ulong get Flens 0
2042if isdigit get Fields i
2043hasdigit = true
2044end
2045end
2046if not hasdigit
2047ret 0
2048end
2049end
2050ret n
2051end
2052fn scput slot ulong to ulong
2053off = get Sc 4
2054n = get Flens slot
2055for i ulong n
2056put Stext add off i get Fields add mul slot 256 i
2057end
2058put Stext add off n 0
2059put Sc 4 add add off n 1
2060ret off
2061end
2062fn scmod word ulong base ulong to void
2063if and ge word 11 le word 13
2064put Things add base 1 sub word 10
2065end
2066if and ge word 16 le word 18
2067put Things add base 2 sub word 16
2068end
2069if and ge word 19 le word 20
2070put Things add base 3 sub word 18
2071end
2072if eq word 14
2073put Things add base 4 1
2074end
2075if eq word 15
2076put Things add base 5 1
2077end
2078end
2079fn scsay beg ulong stop ulong to bool
2080if ne get Sc 2 0
2081ret false
2082end
2083n = sub stop beg
2084if or eq n 0 gt n 159
2085ret false
2086end
2087for i ulong n
2088c = get In add beg i
2089if or lt c 32 gt c 126
2090ret false
2091end
2092put Fields i c
2093end
2094put Flens 0 n
2095put Sc 2 1
2096put Sw 3 scput 0
2097ret true
2098end
2099fn scln beg ulong stop ulong to bool
2100p = beg
2101while lt p stop
2102if or eq get In p 32 eq get In p 58
2103ret scbody beg p stop
2104end
2105p = add p 1
2106end
2107ret false
2108end
2109fn scbody beg ulong wordend ulong stop ulong to bool
2110word = scword beg sub wordend beg
2111if eq word 2
2112s = add wordend 1
2113if lt s stop
2114if eq get In s 58
2115s = add s 1
2116end
2117end
2118while lt s stop
2119if eq get In s 32
2120s = add s 1
2121else
2122ret scsay s stop
2123end
2124end
2125ret false
2126end
2127if eq word 1
2128s = add wordend 1
2129for p ulong sub stop s
2130at = add add wordend 1 p
2131if eq get In at 32
2132w = scword s sub at s
2133if and ge w 21 le w 24
2134put Sc 0 sub w 21
2135end
2136if and ge w 25 le w 27
2137put Sc 1 sub w 25
2138end
2139s = add at 1
2140end
2141end
2142w = scword s sub stop s
2143if and ge w 21 le w 24
2144put Sc 0 sub w 21
2145end
2146if and ge w 25 le w 27
2147put Sc 1 sub w 25
2148end
2149ret true
2150end
2151if or lt word 3 gt word 10
2152ret false
2153end
2154if ge get Sc 3 4
2155put Sc 7 add get Sc 7 1
2156ret false
2157end
2158put Sw 0 sub word 2
2159colon = wordend
2160while lt colon stop
2161if eq get In colon 58
2162put Sw 1 wordend
2163put Sw 2 colon
2164ret scthing add colon 1 stop
2165end
2166colon = add colon 1
2167end
2168ret false
2169end
2170fn scthing beg ulong stop ulong to bool
2171n = scfields beg stop get Sw 0
2172if eq n 0
2173ret false
2174end
2175need = n
2176for i ulong n
2177need = add need get Flens i
2178end
2179if gt add get Sc 4 need 2304
2180ret false
2181end
2182base = mul get Sc 3 16
2183put Things base get Sw 0
2184put Things add base 6 n
2185s = get Sw 1
2186for p ulong sub get Sw 2 s
2187at = add get Sw 1 p
2188if eq get In at 32
2189w = scword s sub at s
2190scmod w base
2191s = add at 1
2192end
2193end
2194w = scword s sub get Sw 2 s
2195scmod w base
2196for i ulong n
2197put Things add add base 7 i scput i
2198end
2199put Sc 3 add get Sc 3 1
2200ret true
2201end
2202fn scene to bool
2203for i ulong 8
2204put Sc i 0
2205end
2206for i ulong 64
2207put Things i 0
2208end
2209put Sw 3 0
2210n = get Inlen 0
2211if gt n 2048
2212n = 2048
2213end
2214s = ulong 0
2215for p ulong n
2216if eq get In p 10
2217if gt p s
2218if lt get Sc 5 12
2219put Sc 5 add get Sc 5 1
2220if not scln s p
2221put Sc 6 add get Sc 6 1
2222end
2223else
2224put Sc 7 add get Sc 7 1
2225end
2226end
2227s = add p 1
2228end
2229end
2230if and lt s n lt get Sc 5 12
2231put Sc 5 add get Sc 5 1
2232if not scln s n
2233put Sc 6 add get Sc 6 1
2234end
2235end
2236ret or ne get Sc 2 0 ne get Sc 3 0
2237end
2238note Handwritten Omega port of paint.h ck_add, ck_scale, ck_mix and paint.c ck_glow.
2239note Bounded192x128 RAM canvas. This is rendering core, not full sky/font/device UI.
2240global Frame uint 24576
2241global G ulong 6
2242global Fb uchar 73728
2243fn channel c uint shift uint to uint
2244ret and shr c shift 255
2245end
2246fn addcolor d uint c uint a uint to uint
2247v = uint 0
2248for i uint 3
2249s = mul i 8
2250n = add channel d s shr mul channel c s a 8
2251if gt n 255
2252n = 255
2253end
2254v = or v shl n s
2255end
2256ret v
2257end
2258fn scale c uint f uint to uint
2259ret or and shr mul and c 16711935 f 8 16711935 and shr mul and c 65280 f 8 65280
2260end
2261fn mix d uint c uint a uint to uint
2262if ge a 256
2263ret c
2264end
2265ret add scale d sub uint 256 a scale c a
2266end
2267fn distance x ulong y ulong to ulong
2268dx = sub add mul long x 16 8 long get G 0
2269dy = sub add mul long y 16 8 long get G 1
2270ret ulong add mul dx dx mul dy dy
2271end
2272fn weight d2 ulong r2 ulong to ulong
2273inv = div ulong 1099511627776 r2
2274f = sub ulong 256 shr mul d2 inv 32
2275w = shr mul shr mul f f 8 f 8
2276ret shr mul w get G 4 8
2277end
2278fn glowpix x ulong y ulong to void
2279d2 = distance x y
2280r2 = mul get G 2 get G 2
2281if ge d2 r2
2282ret
2283end
2284a = uint weight d2 r2
2285at = add mul y 192 x
2286put Frame at addcolor get Frame at uint get G 3 a
2287end
2288fn glow cx ulong cy ulong radius ulong color ulong alpha ulong to bool
2289if or eq radius 0 gt radius 8192
2290ret false
2291end
2292if or gt cx 8192 gt cy 8192
2293ret false
2294end
2295if or gt color 16777215 gt alpha 512
2296ret false
2297end
2298put G 0 cx
2299put G 1 cy
2300put G 2 radius
2301put G 3 color
2302put G 4 alpha
2303for y ulong 128
2304for x ulong 192
2305glowpix x y
2306end
2307end
2308ret true
2309end
2310fn render to void
2311for i ulong 24576
2312put Frame i 0
2313end
2314note Frozen component pose; same halo and heart colors/weights as ck_mind_draw.
2315b = glow 1536 1024 1088 3951314 68
2316b = glow 1536 1024 640 7363839 46
2317b = glow 1536 1024 400 16765610 89
2318b = glow 1536 1024 160 16772310 218
2319b = glow 1536 1024 50 16775920 230
2320end
2321fn frameout to bool
2322for i ulong 24576
2323c = get Frame i
2324put Fb mul i 3 uchar channel c 16
2325put Fb add mul i 3 1 uchar channel c 8
2326put Fb add mul i 3 2 uchar channel c 0
2327end
2328n = ulong 0
2329while lt n len Fb
2330w = write 1 Fb n sub len Fb n
2331if le w 0
2332ret false
2333end
2334n = add n ulong w
2335end
2336ret true
2337end
2338global Fails ulong 1
2339global Checks ulong 1
2340fn check ok bool id ulong to void
2341put Checks 0 add get Checks 0 1
2342outreset
2343emitn id
2344if ok
2345emitb 32
2346emitb 48
2347else
2348put Fails 0 add get Fails 0 1
2349emitb 32
2350emitb 49
2351end
2352emitb 10
2353w = write 1 Outb 0 get Outlen 0
2354end
2355text Askcode "Please make me a calculator"
2356text Askpoem "Write a poem about python"
2357text Askmore "Now add a square root key"
2358text Expected "JOB 9 code the person asked Allen for code.\tPlease make me a calculator"
2359text Nscript "script a poem"
2360fn main to int
2361put Inlen 0 len Askcode
2362for i ulong len Askcode
2363put In i get Askcode i
2364end
2365check eq classify 2 501
2366b = jobbuild 2 9
2367same = eq get Outlen 0 len Expected
2368for i ulong len Expected
2369if ne get Outb i get Expected i
2370same = false
2371end
2372end
2373check b 502
2374check same 503
2375put Inlen 0 len Askpoem
2376for i ulong len Askpoem
2377put In i get Askpoem i
2378end
2379check eq classify 1 504
2380check eq jobwant 1 505
2381put Inlen 0 len Askmore
2382for i ulong len Askmore
2383put In i get Askmore i
2384end
2385check eq classify 1 506
2386put R 6 1
2387check eq classify 3 507
2388put R 6 0
2389put Inlen 0 len Nscript
2390for i ulong len Nscript
2391put In i get Nscript i
2392end
2393check eq classify 1 508
2394ret int get Fails 0
2395end