Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them.
Page: /drakestapleton/aienux/blob/main/evidence/allen-omega-L694/L756/independent-review/probes/presentation-test.om
# aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
Sign in to star 0 stars 0 watching
About Files History Releases Proposed changes Issues For developers
branch `main` Branches Tags History
`aienux / evidence / allen-omega-L694 / L756 / independent-review / probes / presentation-test.om`
4071 lines ยท 63449 bytes Raw Blame History
1 note L694 fixed-buffer utilities. No platform effects in product functions.
2 global In uchar 8192
3 global Inlen ulong 1
4 global Outb uchar 8192
5 global Outlen ulong 1
6 global Err ulong 1
7 text Digits "`0123456789abcdef`"
8 fn emitb c uchar to void
9 n = get Outlen 0
10 if ge n len Outb
11 put Err 0 1
12 else
13 put Outb n c
14 put Outlen 0 add n 1
15 end
16 end
17 fn emitn v ulong to void
18 d = new uchar 20 0
19 n = ulong 0
20 x = v
21 put d n uchar add rem x 10 48
22 n = add n 1
23 x = div x 10
24 while gt x 0
25 put d n uchar add rem x 10 48
26 n = add n 1
27 x = div x 10
28 end
29 while gt n 0
30 n = sub n 1
31 emitb get d n
32 end
33 end
34 fn outreset to void
35 put Outlen 0 0
36 put Err 0 0
37 end
38 fn ineq at ulong c uchar to bool
39 if ge at get Inlen 0
40 ret false
41 end
42 ret eq get In at c
43 end
44 fn isdigit c uchar to bool
45 ret and ge c 48 le c 57
46 end
47 note Parser cursor P0, number P1, error P2. Never wraps a u32.
48 global P ulong 3
49 fn number to void
50 v = ulong 0
51 n = ulong 0
52 p = get P 0
53 while lt p get Inlen 0
54 c = get In p
55 if not isdigit c
56 put P 0 p
57 put P 1 v
58 if eq n 0
59 put P 2 1
60 end
61 ret
62 end
63 if or ge n 10 gt v `429496729`
64 put P 2 1
65 ret
66 end
67 v = add mul v 10 sub ulong c 48
68 if gt v `4294967295`
69 put P 2 1
70 ret
71 end
72 n = add n 1
73 p = add p 1
74 end
75 put P 0 p
76 put P 1 v
77 if eq n 0
78 put P 2 1
79 end
80 end
81 fn expect c uchar to void
82 p = get P 0
83 if not ineq p c
84 put P 2 1
85 else
86 put P 0 add p 1
87 end
88 end
89 fn crc off ulong count ulong to uint
90 c = uint `4294967295`
91 for i ulong count
92 c = xor c uint get In add off i
93 for k ulong 8
94 if ne and c 1 0
95 c = xor shr c 1 `3988292384`
96 else
97 c = shr c 1
98 end
99 end
100 end
101 ret not c
102 end
103 note SPDX-License-Identifier: AGPL-3.0-or-later
104 note SHA256 core reused byte-for-byte from native Omega TRN1 at `12251e3403d42931ada27dc1c54b3b610954be5d`.
105 note Reads stdin up to 8 MiB and emits lowercase hex plus LF only after successful EOF.
106 global Buf uchar 8192
107 global H uint 8
108 global Vv uint 8
109 global W uint 64
110 global K uint 64
111 global Hb uchar 64
112 global Hs ulong 2
113 global Hash uchar 32
114 global Out uchar 65
115 text Hex "`0123456789abcdef`"
116
117 fn rotate x uint n uint to uint
118 ret or shr x n shl x sub 32 n
119 end
120
121 fn round i ulong to void
122 e = get Vv 4
123 a = get Vv 0
124 s = xor xor rotate e 6 rotate e 11 rotate e 25
125 c = xor and e get Vv 5 and not e get Vv 6
126 t = add add get Vv 7 s add c add get K i get W i
127 s = xor xor rotate a 2 rotate a 13 rotate a 22
128 c = and a get Vv 1
129 c = xor c and a get Vv 2
130 c = xor c and get Vv 1 get Vv 2
131 u = add s c
132 put Vv 7 get Vv 6
133 put Vv 6 get Vv 5
134 put Vv 5 e
135 put Vv 4 add get Vv 3 t
136 put Vv 3 get Vv 2
137 put Vv 2 get Vv 1
138 put Vv 1 a
139 put Vv 0 add t u
140 end
141
142 fn block to void
143 for i ulong 16
144 x = uint 0
145 for j ulong 4
146 x = or shl x 8 uint get Hb add mul i 4 j
147 end
148 put W i x
149 end
150 for j ulong 48
151 i = add j 16
152 x = get W sub i 15
153 y = get W sub i 2
154 s = xor xor rotate x 7 rotate x 18 shr x 3
155 t = xor xor rotate y 17 rotate y 19 shr y 10
156 put W i add add get W sub i 16 s add get W sub i 7 t
157 end
158 for i ulong 8
159 put Vv i get H i
160 end
161 for i ulong 64
162 round i
163 end
164 for i ulong 8
165 put H i add get H i get Vv i
166 end
167 end
168
169 fn hinit to void
170 put H 0 `1779033703`
171 put H 1 `3144134277`
172 put H 2 `1013904242`
173 put H 3 `2773480762`
174 put H 4 `1359893119`
175 put H 5 `2600822924`
176 put H 6 `528734635`
177 put H 7 `1541459225`
178 put Hs 0 0
179 put Hs 1 0
180 end
181
182 fn hbyte c uchar to void
183 p = get Hs 0
184 put Hb p c
185 p = add p 1
186 put Hs 1 add get Hs 1 1
187 if eq p 64
188 block
189 p = 0
190 end
191 put Hs 0 p
192 end
193
194 fn update off ulong count ulong to void
195 for i ulong count
196 hbyte get Buf add off i
197 end
198 end
199
200 fn finish to void
201 bits = mul get Hs 1 8
202 hbyte 128
203 while ne get Hs 0 56
204 hbyte 0
205 end
206 for i ulong 8
207 hbyte uchar and shr bits mul sub 7 i 8 255
208 end
209 for i ulong 32
210 x = get H div i 4
211 put Hash i uchar and shr x uint mul sub 3 rem i 4 8 255
212 end
213 end
214
215 fn constants to void
216 put K 0 `1116352408`
217 put K 1 `1899447441`
218 put K 2 `3049323471`
219 put K 3 `3921009573`
220 put K 4 `961987163`
221 put K 5 `1508970993`
222 put K 6 `2453635748`
223 put K 7 `2870763221`
224 put K 8 `3624381080`
225 put K 9 `310598401`
226 put K 10 `607225278`
227 put K 11 `1426881987`
228 put K 12 `1925078388`
229 put K 13 `2162078206`
230 put K 14 `2614888103`
231 put K 15 `3248222580`
232 put K 16 `3835390401`
233 put K 17 `4022224774`
234 put K 18 `264347078`
235 put K 19 `604807628`
236 put K 20 `770255983`
237 put K 21 `1249150122`
238 put K 22 `1555081692`
239 put K 23 `1996064986`
240 put K 24 `2554220882`
241 put K 25 `2821834349`
242 put K 26 `2952996808`
243 put K 27 `3210313671`
244 put K 28 `3336571891`
245 put K 29 `3584528711`
246 put K 30 `113926993`
247 put K 31 `338241895`
248 put K 32 `666307205`
249 put K 33 `773529912`
250 put K 34 `1294757372`
251 put K 35 `1396182291`
252 put K 36 `1695183700`
253 put K 37 `1986661051`
254 put K 38 `2177026350`
255 put K 39 `2456956037`
256 put K 40 `2730485921`
257 put K 41 `2820302411`
258 put K 42 `3259730800`
259 put K 43 `3345764771`
260 put K 44 `3516065817`
261 put K 45 `3600352804`
262 put K 46 `4094571909`
263 put K 47 `275423344`
264 put K 48 `430227734`
265 put K 49 `506948616`
266 put K 50 `659060556`
267 put K 51 `883997877`
268 put K 52 `958139571`
269 put K 53 `1322822218`
270 put K 54 `1537002063`
271 put K 55 `1747873779`
272 put K 56 `1955562222`
273 put K 57 `2024104815`
274 put K 58 `2227730452`
275 put K 59 `2361852424`
276 put K 60 `2428436474`
277 put K 61 `2756734187`
278 put K 62 `3204031479`
279 put K 63 `3329325298`
280 end
281
282 note R: seq, active, kind (1 chat 2 code 3 more), asked, heard, slow,
283 note code-visible, prompt length, answer length, history count, session.
284 global R ulong 16
285 global Prompt uchar 160
286 global Answer uchar 160
287 global Hist uchar 5120
288 global Hlen ulong 32
289 text Ack "I need to code that. Let me send it off to the Spark."
290 text Ackmore "Let me take that change to the Spark."
291 fn textok to bool
292 n = get Inlen 0
293 if or eq n 0 gt n 159
294 ret false
295 end
296 for i ulong n
297 c = get In i
298 if or lt c 32 gt c 126
299 ret false
300 end
301 end
302 ret true
303 end
304 fn histadd which ulong to void
305 n = get R 9
306 if eq n 32
307 for i ulong 4960
308 put Hist i get Hist add i 160
309 end
310 for i ulong 31
311 put Hlen i get Hlen add i 1
312 end
313 n = 31
314 end
315 size = get R add which 7
316 for i ulong size
317 if eq which 0
318 put Hist add mul n 160 i get Prompt i
319 else
320 put Hist add mul n 160 i get Answer i
321 end
322 end
323 put Hlen n size
324 put R 9 add n 1
325 end
326 fn start kind ulong now ulong to bool
327 if or ne get R 1 0 ge get R 0 `4294967295`
328 ret false
329 end
330 if or lt kind 1 gt kind 3
331 ret false
332 end
333 if and eq kind 3 eq get R 6 0
334 ret false
335 end
336 if not textok
337 ret false
338 end
339 for i ulong get Inlen 0
340 put Prompt i get In i
341 end
342 put R 7 get Inlen 0
343 put R 0 add get R 0 1
344 put R 1 1
345 put R 2 kind
346 put R 3 now
347 put R 4 now
348 put R 5 0
349 put R 8 0
350 put R 11 0
351 put R 13 0
352 if eq kind 2
353 for i ulong len Ack
354 put Answer i get Ack i
355 end
356 put R 8 len Ack
357 end
358 if eq kind 3
359 for i ulong len Ackmore
360 put Answer i get Ackmore i
361 end
362 put R 8 len Ackmore
363 end
364 histadd 0
365 ret true
366 end
367 fn answer seq ulong now ulong to bool
368 if or eq get R 1 0 ne seq get R 0
369 ret false
370 end
371 if or lt now get R 4 not textok
372 ret false
373 end
374 for i ulong get Inlen 0
375 put Answer i get In i
376 end
377 put R 8 get Inlen 0
378 put R 4 now
379 put R 1 0
380 histadd 1
381 ret true
382 end
383 fn cancel to void
384 put R 1 0
385 end
386 fn heard seq ulong now ulong to bool
387 if or eq get R 1 0 ne seq get R 0
388 ret false
389 end
390 if lt now get R 4
391 ret false
392 end
393 put R 4 now
394 ret true
395 end
396 fn tick now ulong to ulong
397 if or eq get R 1 0 lt now get R 4
398 ret 0
399 end
400 if ge sub now get R 4 30000
401 cancel
402 ret 2
403 end
404 if and eq get R 5 0 ge sub now get R 3 20000
405 put R 5 1
406 ret 1
407 end
408 ret 0
409 end
410 fn reset to void
411 for i ulong 9
412 put R add i 1 0
413 end
414 end
415 note Restore one externally decoded transcript line. No live job or ID reuse.
416 fn restore to bool
417 if or ne get R 1 0 not textok
418 ret false
419 end
420 for i ulong get Inlen 0
421 put Answer i get In i
422 end
423 put R 8 get Inlen 0
424 histadd 1
425 ret true
426 end
427 note CODE protocol: C seq, parts, bytes, crc, got. D parsed header.
428 global C ulong 8
429 global D ulong 8
430 global Code uchar 32769
431 global Have uchar 256
432 global Piece uchar 128
433 global Lang uchar 16
434 global Newlang uchar 16
435 fn codebeg seq ulong to void
436 for i ulong 8
437 put C i 0
438 end
439 put C 0 seq
440 for i ulong 256
441 put Have i 0
442 end
443 put Code 0 0
444 end
445 fn decfield slot ulong sep uchar to void
446 number
447 put D slot get P 1
448 expect sep
449 end
450 fn hexread to void
451 v = ulong 0
452 for i ulong 8
453 p = get P 0
454 if ge p get Inlen 0
455 put P 2 1
456 ret
457 end
458 c = get In p
459 d = ulong 16
460 if isdigit c
461 d = sub ulong c 48
462 else
463 if and ge c 97 le c 102
464 d = sub ulong c 87
465 end
466 end
467 if ge d 16
468 put P 2 1
469 ret
470 end
471 v = add mul v 16 d
472 put P 0 add p 1
473 end
474 put D 4 v
475 expect 32
476 end
477 fn codehead to bool
478 put P 0 0
479 put P 2 0
480 expect 67
481 expect 79
482 expect 68
483 expect 69
484 expect 32
485 decfield 0 32
486 decfield 1 47
487 decfield 2 32
488 decfield 3 32
489 hexread
490 if ne get P 2 0
491 ret false
492 end
493 if or ne get D 0 get C 0 eq get D 3 0
494 ret false
495 end
496 if gt get D 3 32768
497 ret false
498 end
499 if ne get D 2 div add get D 3 127 128
500 ret false
501 end
502 if or lt get D 1 1 gt get D 1 get D 2
503 ret false
504 end
505 if ne get C 1 0
506 if or ne get C 1 get D 2 ne get C 2 get D 3
507 ret false
508 end
509 if ne get C 3 get D 4
510 ret false
511 end
512 end
513 ret true
514 end
515 fn langread to bool
516 for i ulong 16
517 put Newlang i 0
518 end
519 n = ulong 0
520 p = get P 0
521 while lt p get Inlen 0
522 c = get In p
523 if eq c 32
524 if eq n 0
525 ret false
526 end
527 put P 0 add p 1
528 put D 5 n
529 ret true
530 end
531 ok = or and ge c 97 le c 122 isdigit c
532 ok = or ok or eq c 43 eq c 35
533 ok = or ok or eq c 46 or eq c 95 eq c 45
534 if or not ok ge n 15
535 ret false
536 end
537 put Newlang n c
538 p = add p 1
539 n = add n 1
540 end
541 ret false
542 end
543 fn pieceread to ulong
544 p = get P 0
545 n = ulong 0
546 while lt p get Inlen 0
547 c = get In p
548 p = add p 1
549 if eq c 92
550 if ge p get Inlen 0
551 ret 129
552 end
553 c = get In p
554 p = add p 1
555 if eq c 110
556 c = 10
557 else
558 if ne c 92
559 ret 129
560 end
561 end
562 else
563 if or lt c 32 gt c 126
564 ret 129
565 end
566 end
567 if ge n 128
568 ret 129
569 end
570 put Piece n c
571 n = add n 1
572 end
573 ret n
574 end
575 fn codetake to bool
576 if gt get Inlen 0 320
577 ret false
578 end
579 if not codehead
580 ret false
581 end
582 if not langread
583 ret false
584 end
585 n = pieceread
586 want = ulong 128
587 if eq get D 1 get D 2
588 want = sub get D 3 mul sub get D 2 1 128
589 end
590 if ne n want
591 ret false
592 end
593 slot = sub get D 1 1
594 off = mul slot 128
595 if ne get C 1 0
596 for i ulong 16
597 if ne get Lang i get Newlang i
598 ret false
599 end
600 end
601 end
602 if ne get Have slot 0
603 for i ulong n
604 if ne get Code add off i get Piece i
605 ret false
606 end
607 end
608 ret true
609 end
610 put C 1 get D 2
611 put C 2 get D 3
612 put C 3 get D 4
613 for i ulong 16
614 put Lang i get Newlang i
615 end
616 for i ulong n
617 put Code add off i get Piece i
618 end
619 put Have slot 1
620 put C 4 add get C 4 1
621 ret true
622 end
623 fn codecrc to uint
624 c = uint `4294967295`
625 for i ulong get C 2
626 c = xor c uint get Code i
627 for k ulong 8
628 if ne and c 1 0
629 c = xor shr c 1 `3988292384`
630 else
631 c = shr c 1
632 end
633 end
634 end
635 ret not c
636 end
637 fn codestat to ulong
638 if eq get C 1 0
639 ret 0
640 end
641 if lt get C 4 get C 1
642 ret 1
643 end
644 if ne ulong codecrc get C 3
645 ret 3
646 end
647 lines = ulong 0
648 for i ulong get C 2
649 c = get Code i
650 if eq c 0
651 ret 3
652 end
653 if eq c 10
654 lines = add lines 1
655 end
656 end
657 if ne get Code sub get C 2 1 10
658 lines = add lines 1
659 end
660 if gt lines 800
661 ret 3
662 end
663 put Code get C 2 0
664 ret 2
665 end
666 fn missing to ulong
667 if eq get C 1 0
668 ret 1
669 end
670 for i ulong get C 1
671 if eq get Have i 0
672 ret add i 1
673 end
674 end
675 ret 0
676 end
677 note Display admission is distinct from a model's closing sentence.
678 fn codeshow seq ulong to bool
679 if eq get R 1 0
680 ret false
681 end
682 if or ne seq get R 0 ne seq get C 0
683 ret false
684 end
685 if ne codestat 2
686 ret false
687 end
688 put R 6 1
689 ret true
690 end
691 note Pure courier datagrams. Q session, current seq, last LINE, head, count.
692 global Q ulong 8
693 global N ulong 8
694 global Queue uchar 2560
695 global Qlens ulong 8
696 global Jbuf uchar 4096
697 global Jhave uchar 5
698 global J ulong 3
699 text Keys "ALLEN-COURIER v=1 run= kind= seq= part= bytes="
700 text Kinds "JOBLINEGOTACKHELLOHI"
701 fn keyread off ulong count ulong to void
702 for i ulong count
703 expect get Keys add off i
704 end
705 end
706 fn keyemit off ulong count ulong to void
707 for i ulong count
708 emitb get Keys add off i
709 end
710 end
711 fn kindoff k ulong to ulong
712 if eq k 1
713 ret 0
714 end
715 if eq k 2
716 ret 3
717 end
718 if eq k 3
719 ret 7
720 end
721 if eq k 4
722 ret 10
723 end
724 if eq k 5
725 ret 13
726 end
727 ret 18
728 end
729 fn kindlen k ulong to ulong
730 if eq k 2
731 ret 4
732 end
733 if eq k 5
734 ret 5
735 end
736 if eq k 6
737 ret 2
738 end
739 ret 3
740 end
741 fn qbegin run ulong seq ulong to void
742 for i ulong 8
743 put Q i 0
744 end
745 put Q 0 run
746 put Q 1 seq
747 for i ulong 5
748 put Jhave i 0
749 end
750 for i ulong 3
751 put J i 0
752 end
753 end
754 note Serializer takes body In/Inlen; Outb/Outlen are published only on success.
755 fn packet k ulong seq ulong part ulong total ulong bytes ulong to bool
756 if or lt k 1 gt k 6
757 ret false
758 end
759 if gt get Inlen 0 1000
760 ret false
761 end
762 outreset
763 keyemit 0 22
764 for i ulong 16
765 d = and shr get Q 0 mul sub 15 i 4 15
766 emitb get Digits d
767 end
768 keyemit 22 6
769 off = kindoff k
770 for i ulong kindlen k
771 emitb get Kinds add off i
772 end
773 keyemit 28 5
774 emitn seq
775 keyemit 33 6
776 emitn part
777 emitb 47
778 emitn total
779 keyemit 39 7
780 emitn bytes
781 emitb 10
782 for i ulong get Inlen 0
783 emitb get In i
784 end
785 ret eq get Err 0 0
786 end
787 fn pkparse to bool
788 if or gt get Inlen 0 1200 lt get Inlen 0 65
789 ret false
790 end
791 put P 0 0
792 put P 2 0
793 keyread 0 22
794 run = ulong 0
795 for i ulong 16
796 p = get P 0
797 c = get In p
798 d = ulong 16
799 if isdigit c
800 d = sub ulong c 48
801 else
802 if and ge c 97 le c 102
803 d = sub ulong c 87
804 end
805 end
806 if ge d 16
807 ret false
808 end
809 run = or shl run 4 d
810 put P 0 add p 1
811 end
812 if ne run get Q 0
813 ret false
814 end
815 keyread 22 6
816 kind = ulong 0
817 for k ulong 6
818 at = get P 0
819 off = kindoff add k 1
820 size = kindlen add k 1
821 ok = true
822 for i ulong size
823 if not ineq add at i get Kinds add off i
824 ok = false
825 end
826 end
827 if and ok ineq add at size 32
828 kind = add k 1
829 end
830 end
831 if eq kind 0
832 ret false
833 end
834 put N 0 kind
835 put P 0 add get P 0 kindlen kind
836 keyread 28 5
837 number
838 put N 1 get P 1
839 keyread 33 6
840 number
841 put N 2 get P 1
842 expect 47
843 number
844 put N 3 get P 1
845 keyread 39 7
846 number
847 put N 4 get P 1
848 expect 10
849 put N 5 get P 0
850 put N 6 sub get Inlen 0 get P 0
851 ret eq get P 2 0
852 end
853 fn jobtake to ulong
854 note n via N4
855 note part via N2
856 note total via N3
857 if or eq get N 4 0 gt get N 4 4096
858 ret 0
859 end
860 if ne get N 3 div add get N 4 999 1000
861 ret 0
862 end
863 if or eq get N 2 0 gt get N 2 get N 3
864 ret 0
865 end
866 want = ulong 1000
867 if eq get N 2 get N 3
868 want = sub get N 4 mul sub get N 3 1 1000
869 end
870 if ne want get N 6
871 ret 0
872 end
873 if ne get J 0 0
874 if or ne get J 0 get N 4 ne get J 1 get N 3
875 ret 0
876 end
877 end
878 slot = sub get N 2 1
879 off = mul slot 1000
880 if ne get Jhave slot 0
881 for i ulong want
882 if ne get Jbuf add off i get In add get N 5 i
883 ret 0
884 end
885 end
886 ret 2
887 end
888 for i ulong want
889 put Jbuf add off i get In add get N 5 i
890 end
891 put Jhave slot 1
892 put J 0 get N 4
893 put J 1 get N 3
894 put J 2 add get J 2 1
895 ret 1
896 end
897 note Return0 refused,1 accepted,2 duplicate requiring GOT/ACK again.
898 fn qreceive to ulong
899 if not pkparse
900 ret 0
901 end
902 if ne get N 1 get Q 1
903 ret 0
904 end
905 kind = get N 0
906 if eq kind 1
907 ret jobtake
908 end
909 if ne kind 2
910 if ne get N 6 0
911 ret 0
912 end
913 ret 1
914 end
915 note part via N2
916 if eq get N 2 0
917 ret 0
918 end
919 if le get N 2 get Q 2
920 ret 2
921 end
922 if or ne get N 2 add get Q 2 1 eq get Q 4 8
923 ret 0
924 end
925 n = get N 6
926 if or eq n 0 gt n 319
927 ret 0
928 end
929 slot = rem add get Q 3 get Q 4 8
930 for i ulong n
931 put Queue add mul slot 320 i get In add get N 5 i
932 end
933 put Qlens slot n
934 put Q 4 add get Q 4 1
935 put Q 2 get N 2
936 ret 1
937 end
938 fn qtake to bool
939 if eq get Q 4 0
940 ret false
941 end
942 slot = get Q 3
943 n = get Qlens slot
944 for i ulong n
945 put In i get Queue add mul slot 320 i
946 end
947 put Inlen 0 n
948 put Q 3 rem add slot 1 8
949 put Q 4 sub get Q 4 1
950 ret true
951 end
952 note Courier client lifecycle; injected monotonic milliseconds, no host clock/socket.
953 note T lastclock, HIvalid, HIat, HELLOvalid, HELLOat, active, acked, jobat,
954 note joblength, cursor, pendingkind, pendingpart, reserved, GOTpart, reserved, reserved.
955 note Serialized API: qnext publishes one datagram; qsent records actual send result.
956 note Consume Outb before another serializer; failed sends leave retries due.
957 global T ulong 16
958 global JobOut uchar 4096
959 fn qstart run ulong now ulong to bool
960 if eq run 0
961 ret false
962 end
963 qbegin run 0
964 for i ulong 16
965 put T i 0
966 end
967 put T 0 now
968 ret true
969 end
970 fn qready now ulong to bool
971 if or eq get Q 0 0 lt now get T 0
972 ret false
973 end
974 if eq get T 1 0
975 ret false
976 end
977 ret lt sub now get T 2 30000
978 end
979 fn qsubmit now ulong to bool
980 if or eq get Q 0 0 lt now get T 0
981 ret false
982 end
983 if ne get T 10 0
984 ret false
985 end
986 if and ne get T 5 0 eq get T 6 0
987 ret false
988 end
989 n = get Inlen 0
990 if or eq n 0 gt n 4096
991 ret false
992 end
993 if ge get Q 1 `4294967295`
994 ret false
995 end
996 seq = add get Q 1 1
997 qbegin get Q 0 seq
998 for i ulong n
999 c = get In i
1000 if or eq c 10 eq c 13
1001 c = uchar 32
1002 end
1003 put JobOut i c
1004 end
1005 put T 0 now
1006 put T 5 1
1007 put T 6 0
1008 put T 7 now
1009 put T 8 n
1010 put T 9 1
1011 put T 13 0
1012 ret true
1013 end
1014 fn qnext now ulong link bool to bool
1015 if or eq get Q 0 0 lt now get T 0
1016 ret false
1017 end
1018 if ne get T 10 0
1019 ret false
1020 end
1021 put T 0 now
1022 if not link
1023 ret false
1024 end
1025 if ne get T 13 0
1026 put Inlen 0 0
1027 if not packet 3 get Q 1 get T 13 0 0
1028 ret false
1029 end
1030 put T 10 3
1031 put T 11 get T 13
1032 ret true
1033 end
1034 delay = ulong 2000
1035 if qready now
1036 delay = ulong 10000
1037 end
1038 if or eq get T 3 0 ge sub now get T 4 delay
1039 put Inlen 0 0
1040 if not packet 5 0 0 0 0
1041 ret false
1042 end
1043 put T 10 5
1044 put T 11 0
1045 ret true
1046 end
1047 if or eq get T 5 0 ne get T 6 0
1048 ret false
1049 end
1050 part = get T 9
1051 if eq part 0
1052 if lt sub now get T 7 2000
1053 ret false
1054 end
1055 part = ulong 1
1056 end
1057 n = get T 8
1058 total = div add n 999 1000
1059 off = mul sub part 1 1000
1060 size = sub n off
1061 if gt size 1000
1062 size = ulong 1000
1063 end
1064 for i ulong size
1065 put In i get JobOut add off i
1066 end
1067 put Inlen 0 size
1068 if not packet 1 get Q 1 part total n
1069 ret false
1070 end
1071 put T 10 1
1072 put T 11 part
1073 ret true
1074 end
1075 fn qsent now ulong ok bool to bool
1076 if or eq get T 10 0 lt now get T 0
1077 ret false
1078 end
1079 kind = get T 10
1080 part = get T 11
1081 put T 0 now
1082 put T 10 0
1083 put T 11 0
1084 if not ok
1085 ret true
1086 end
1087 if eq kind 5
1088 put T 3 1
1089 put T 4 now
1090 end
1091 if eq kind 3
1092 if eq get T 13 part
1093 put T 13 0
1094 end
1095 end
1096 if eq kind 1
1097 if or ne get T 6 0 ge part div add get T 8 999 1000
1098 put T 9 0
1099 put T 7 now
1100 else
1101 put T 9 add part 1
1102 end
1103 end
1104 ret true
1105 end
1106 fn qincoming now ulong to ulong
1107 if or eq get Q 0 0 lt now get T 0
1108 ret 0
1109 end
1110 if not pkparse
1111 ret 0
1112 end
1113 kind = get N 0
1114 if eq kind 6
1115 if or ne get N 1 0 ne get N 2 0
1116 ret 0
1117 end
1118 if or ne get N 3 0 ne get N 4 0
1119 ret 0
1120 end
1121 if ne get N 6 0
1122 ret 0
1123 end
1124 put T 0 now
1125 put T 1 1
1126 put T 2 now
1127 ret 1
1128 end
1129 if or eq get T 5 0 ne get N 1 get Q 1
1130 ret 0
1131 end
1132 if eq kind 4
1133 if or ne get N 2 0 ne get N 3 0
1134 ret 0
1135 end
1136 if or ne get N 4 0 ne get N 6 0
1137 ret 0
1138 end
1139 put T 0 now
1140 put T 6 1
1141 put T 9 0
1142 ret 1
1143 end
1144 if ne kind 2
1145 ret 0
1146 end
1147 if or ne get N 3 0 ne get N 4 0
1148 ret 0
1149 end
1150 if and ne get T 13 0 ne get T 13 get N 2
1151 ret 0
1152 end
1153 result = qreceive
1154 if eq result 0
1155 ret 0
1156 end
1157 put T 0 now
1158 put T 6 1
1159 put T 9 0
1160 put T 13 get N 2
1161 ret result
1162 end
1163 fn qcancel to void
1164 put T 5 0
1165 put T 6 0
1166 put T 8 0
1167 put T 9 0
1168 put T 10 0
1169 put T 11 0
1170 put T 13 0
1171 put Q 3 0
1172 put Q 4 0
1173 end
1174 note Legacy application record codec; SHA is unkeyed integrity ONLY.
1175 global Unit uchar 4096
1176 global Enc uchar 4096
1177 global Mem uchar 3692
1178 global Md ulong 3
1179 global Note uchar 128
1180 global Ns ulong 4
1181 text Magic "AIENALM1"
1182 text Nmagic "AIENNOT1"
1183 fn get32 off ulong to ulong
1184 v = ulong 0
1185 for i ulong 4
1186 v = or v shl ulong get Unit add off i mul i 8
1187 end
1188 ret v
1189 end
1190 fn get64 off ulong to ulong
1191 ret or get32 off shl get32 add off 4 32
1192 end
1193 fn put32 off ulong v ulong to void
1194 for i ulong 4
1195 put Unit add off i uchar and shr v mul i 8 255
1196 end
1197 end
1198 fn put64 off ulong v ulong to void
1199 put32 off and v `4294967295`
1200 put32 add off 4 shr v 32
1201 end
1202 fn mem32 off ulong to ulong
1203 v = ulong 0
1204 for i ulong 4
1205 v = or v shl ulong get Mem add off i mul i 8
1206 end
1207 ret v
1208 end
1209 fn mset32 off ulong v ulong to void
1210 for i ulong 4
1211 put Mem add off i uchar and shr v mul i 8 255
1212 end
1213 end
1214 fn zeroend off ulong to bool
1215 for i ulong sub ulong 4096 off
1216 if ne get Unit add off i 0
1217 ret false
1218 end
1219 end
1220 ret true
1221 end
1222 fn fieldok off ulong cap ulong name bool to bool
1223 n = ulong 0
1224 while lt n cap
1225 if eq get Unit add off n 0
1226 for j ulong sub cap n
1227 if ne get Unit add add off n j 0
1228 ret false
1229 end
1230 end
1231 ret true
1232 end
1233 c = get Unit add off n
1234 lower = and ge c 97 le c 122
1235 digit = isdigit c
1236 if name
1237 if eq n 0
1238 if not or and ge c 65 le c 90 digit
1239 ret false
1240 end
1241 else
1242 if not or lower digit
1243 ret false
1244 end
1245 end
1246 else
1247 if eq c 32
1248 if or eq n 0 eq n sub cap 1
1249 ret false
1250 end
1251 if eq get Unit add off add n 1 0
1252 ret false
1253 end
1254 if eq get Unit add off sub n 1 32
1255 ret false
1256 end
1257 else
1258 if not or lower digit
1259 ret false
1260 end
1261 end
1262 end
1263 n = add n 1
1264 end
1265 ret false
1266 end
1267 fn digest count ulong to void
1268 hinit
1269 for i ulong 32
1270 hbyte get Unit i
1271 end
1272 for i ulong count
1273 hbyte get Unit add i 64
1274 end
1275 finish
1276 end
1277 fn hashok count ulong to bool
1278 digest count
1279 d = uchar 0
1280 for i ulong 32
1281 d = or d xor get Hash i get Unit add i 32
1282 end
1283 ret eq d 0
1284 end
1285 fn seal count ulong to void
1286 digest count
1287 for i ulong 32
1288 put Unit add i 32 get Hash i
1289 end
1290 end
1291 fn memvalid to bool
1292 for i ulong 8
1293 if ne get Unit i get Magic i
1294 ret false
1295 end
1296 end
1297 ver = get32 8
1298 if or lt ver 2 gt ver 4
1299 ret false
1300 end
1301 n = get32 96
1302 if or gt n 32 gt get32 100 512
1303 ret false
1304 end
1305 size = add 40 mul n 113
1306 if ge ver 3
1307 size = add size 24
1308 end
1309 if eq ver 4
1310 size = add size 12
1311 end
1312 if or ne size get32 12 eq get64 16 0
1313 ret false
1314 end
1315 for i ulong 8
1316 if ne get Unit add i 24 0
1317 ret false
1318 end
1319 end
1320 if not zeroend add 64 size
1321 ret false
1322 end
1323 if not hashok size
1324 ret false
1325 end
1326 if not fieldok 72 24 true
1327 ret false
1328 end
1329 for i ulong n
1330 off = add 104 mul i 113
1331 if or eq get Unit off 0 eq get Unit add off 48 0
1332 ret false
1333 end
1334 if not fieldok off 48 false
1335 ret false
1336 end
1337 if not fieldok add off 48 64 false
1338 ret false
1339 end
1340 if gt get Unit add off 112 1
1341 ret false
1342 end
1343 end
1344 off = add 104 mul n 113
1345 if ge ver 3
1346 if not fieldok off 24 true
1347 ret false
1348 end
1349 end
1350 if eq ver 4
1351 if ne get Unit add off 27 0
1352 ret false
1353 end
1354 end
1355 ret true
1356 end
1357 fn memdec to bool
1358 if not memvalid
1359 ret false
1360 end
1361 size = get32 12
1362 for i ulong 3692
1363 put Mem i 0
1364 end
1365 for i ulong size
1366 put Mem i get Unit add i 64
1367 end
1368 put Md 0 get64 16
1369 put Md 1 get32 8
1370 put Md 2 size
1371 ret true
1372 end
1373 fn memenc gen ulong to bool
1374 n = mem32 32
1375 if or gt n 32 eq gen 0
1376 ret false
1377 end
1378 size = add 76 mul n 113
1379 for i ulong 4096
1380 put Unit i 0
1381 end
1382 for i ulong 8
1383 put Unit i get Magic i
1384 end
1385 put32 8 4
1386 put32 12 size
1387 put64 16 gen
1388 for i ulong size
1389 put Unit add i 64 get Mem i
1390 end
1391 seal size
1392 if not memvalid
1393 ret false
1394 end
1395 for i ulong 4096
1396 put Enc i get Unit i
1397 end
1398 ret true
1399 end
1400 fn noteval index ulong to bool
1401 for i ulong 8
1402 if ne get Unit i get Nmagic i
1403 ret false
1404 end
1405 end
1406 n = get32 12
1407 if or eq n 0 ge n 128
1408 ret false
1409 end
1410 if or ne get32 8 1 ne get32 16 index
1411 ret false
1412 end
1413 if or gt get32 24 1 ne get32 28 0
1414 ret false
1415 end
1416 if not zeroend add n 64
1417 ret false
1418 end
1419 for i ulong n
1420 c = get Unit add i 64
1421 if or lt c 32 gt c 126
1422 ret false
1423 end
1424 end
1425 ret hashok n
1426 end
1427 fn notedec index ulong to bool
1428 if not noteval index
1429 ret false
1430 end
1431 n = get32 12
1432 for i ulong 128
1433 put Note i 0
1434 end
1435 for i ulong n
1436 put Note i get Unit add i 64
1437 end
1438 put Ns 0 n
1439 put Ns 1 index
1440 put Ns 2 get32 20
1441 put Ns 3 get32 24
1442 ret true
1443 end
1444 fn noteenc to bool
1445 n = get Ns 0
1446 if or eq n 0 ge n 128
1447 ret false
1448 end
1449 if or gt get Ns 1 511 gt get Ns 2 `4294967295`
1450 ret false
1451 end
1452 if gt get Ns 3 1
1453 ret false
1454 end
1455 for i ulong n
1456 c = get Note i
1457 if or lt c 32 gt c 126
1458 ret false
1459 end
1460 end
1461 for i ulong 4096
1462 put Unit i 0
1463 end
1464 for i ulong 8
1465 put Unit i get Nmagic i
1466 end
1467 put32 8 1
1468 put32 12 n
1469 put32 16 get Ns 1
1470 put32 20 get Ns 2
1471 put32 24 get Ns 3
1472 for i ulong n
1473 put Unit add i 64 get Note i
1474 end
1475 seal n
1476 for i ulong 4096
1477 put Enc i get Unit i
1478 end
1479 ret true
1480 end
1481 note Store St gen,newest,valid. Tx phase,target,newgen. Provider owns actual I/O.
1482 global St ulong 3
1483 global Nt ulong 2
1484 global Load ulong 1
1485 global Tx ulong 3
1486 fn txbegin to bool
1487 if ne get Nt 0 0
1488 ret false
1489 end
1490 if or ne get Tx 0 0 eq get St 0 `18446744073709551615`
1491 ret false
1492 end
1493 if not memenc add get St 0 1
1494 ret false
1495 end
1496 put Tx 1 0
1497 if ne get St 0 0
1498 put Tx 1 sub ulong 1 get St 1
1499 end
1500 put Tx 2 add get St 0 1
1501 put Tx 0 1
1502 ret true
1503 end
1504 fn txwrite ok bool to bool
1505 if ne get Tx 0 1
1506 ret false
1507 end
1508 if not ok
1509 put Tx 0 0
1510 ret false
1511 end
1512 put Tx 0 2
1513 ret true
1514 end
1515 fn txflush ok bool to bool
1516 if ne get Tx 0 2
1517 ret false
1518 end
1519 if not ok
1520 put Tx 0 0
1521 ret false
1522 end
1523 put Tx 0 3
1524 ret true
1525 end
1526 fn txread ok bool to bool
1527 if ne get Tx 0 3
1528 ret false
1529 end
1530 put Tx 0 0
1531 if not ok
1532 ret false
1533 end
1534 d = uchar 0
1535 for i ulong 4096
1536 d = or d xor get Unit i get Enc i
1537 end
1538 if ne d 0
1539 ret false
1540 end
1541 put St 0 get Tx 2
1542 put St 1 get Tx 1
1543 if lt get St 2 2
1544 put St 2 add get St 2 1
1545 end
1546 ret true
1547 end
1548 note Load each copy once into Unit. Caller resets St and calls loadcopy0,1.
1549 fn loadbeg to void
1550 for i ulong 3
1551 put St i 0
1552 end
1553 put Load 0 0
1554 end
1555 fn loadcopy slot ulong to bool
1556 if gt slot 1
1557 ret false
1558 end
1559 if ne and get Load 0 shl ulong 1 slot 0
1560 ret false
1561 end
1562 if not memvalid
1563 ret false
1564 end
1565 put Load 0 or get Load 0 shl ulong 1 slot
1566 put St 2 add get St 2 1
1567 if gt get64 16 get St 0
1568 b = memdec
1569 put St 0 get Md 0
1570 put St 1 slot
1571 end
1572 ret true
1573 end
1574 note Note transaction completes before the parent copy may publish its count.
1575 fn nbegin to bool
1576 if or ne get Nt 0 0 ne get Tx 0 0
1577 ret false
1578 end
1579 if not noteenc
1580 ret false
1581 end
1582 put Nt 1 get Ns 1
1583 put Nt 0 1
1584 ret true
1585 end
1586 fn nwrite ok bool to bool
1587 if ne get Nt 0 1
1588 ret false
1589 end
1590 if not ok
1591 put Nt 0 0
1592 ret false
1593 end
1594 put Nt 0 2
1595 ret true
1596 end
1597 fn nflush ok bool to bool
1598 if ne get Nt 0 2
1599 ret false
1600 end
1601 if not ok
1602 put Nt 0 0
1603 ret false
1604 end
1605 put Nt 0 3
1606 ret true
1607 end
1608 fn nread ok bool to bool
1609 if ne get Nt 0 3
1610 ret false
1611 end
1612 put Nt 0 0
1613 if not ok
1614 ret false
1615 end
1616 d = uchar 0
1617 for i ulong 4096
1618 d = or d xor get Enc i get Unit i
1619 end
1620 if ne d 0
1621 ret false
1622 end
1623 ret noteval get Nt 1
1624 end
1625 note Intent vocabulary frozen from svc/allen_intent.c. It selects jobs, never answers.
1626 global Fold uchar 160
1627 global Fn ulong 2
1628 text 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"
1629 fn foldin to void
1630 n = ulong 0
1631 space = false
1632 for i ulong get Inlen 0
1633 c = get In i
1634 if and ge c 65 le c 90
1635 c = add sub c 65 97
1636 end
1637 if or and ge c 97 le c 122 isdigit c
1638 if and space gt n 0
1639 put Fold n uchar 32
1640 n = add n 1
1641 end
1642 put Fold n c
1643 n = add n 1
1644 space = false
1645 else
1646 space = true
1647 end
1648 end
1649 put Fn 0 n
1650 put Fn 1 0
1651 end
1652 fn phrase at ulong off ulong size ulong to bool
1653 if gt add at size get Fn 0
1654 ret false
1655 end
1656 for i ulong size
1657 if ne get Fold add at i get Lists add off i
1658 ret false
1659 end
1660 end
1661 if lt add at size get Fn 0
1662 if ne get Fold add at size 32
1663 ret false
1664 end
1665 end
1666 ret true
1667 end
1668 fn inphrase off ulong size ulong anypos bool to bool
1669 if not anypos
1670 ret phrase get Fn 1 off size
1671 end
1672 count = sub get Fn 0 get Fn 1
1673 for i ulong count
1674 at = add i get Fn 1
1675 ok = eq at get Fn 1
1676 if gt at 0
1677 ok = or ok eq get Fold sub at 1 32
1678 end
1679 if ok
1680 if phrase at off size
1681 ret true
1682 end
1683 end
1684 end
1685 ret false
1686 end
1687 fn listed group ulong anypos bool to ulong
1688 g = ulong 0
1689 s = ulong 0
1690 for p ulong len Lists
1691 c = get Lists p
1692 if or eq c 124 eq c 10
1693 if eq g group
1694 if inphrase s sub p s anypos
1695 ret sub p s
1696 end
1697 end
1698 s = add p 1
1699 if eq c 10
1700 g = add g 1
1701 end
1702 end
1703 end
1704 ret 0
1705 end
1706 fn classify to ulong
1707 if not textok
1708 ret 0
1709 end
1710 foldin
1711 skip = listed 0 false
1712 while gt skip 0
1713 if ge add get Fn 1 skip get Fn 0
1714 skip = 0
1715 else
1716 put Fn 1 add add get Fn 1 skip 1
1717 skip = listed 0 false
1718 end
1719 end
1720 if and ne get R 6 0 gt listed 5 false 0
1721 ret 3
1722 end
1723 plain = listed 4 false
1724 if or eq plain 4 eq plain 7
1725 ret 2
1726 end
1727 if and gt listed 3 true 0 eq listed 4 true 0
1728 ret 1
1729 end
1730 if and gt listed 1 false 0 gt listed 2 true 0
1731 ret 2
1732 end
1733 ret 1
1734 end
1735 note Ordinary want enum0chat,1make,2explain,3do.
1736 fn jobwant to ulong
1737 if gt listed 8 false 0
1738 ret 2
1739 end
1740 if or gt listed 6 false 0 gt listed 7 true 0
1741 ret 1
1742 end
1743 if gt listed 10 false 0
1744 ret 3
1745 end
1746 if gt listed 9 true 0
1747 ret 2
1748 end
1749 ret 0
1750 end
1751 text Job "JOB "
1752 text Codeask " asked "
1753 text Forcode " for code.\t"
1754 text Formore " to change the code just shown.\t"
1755 text Wantstr "chatmakeexplaindo"
1756 text Intro "You are the far hands of "
1757 text Home ", a quiet presence living in AIENOS on "
1758 text Comp "'s computer. You answer as "
1759 text Sees "; "
1760 text Words " sees only your words, as if "
1761 text 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. "
1762 text 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."
1763 text Explain " asked to understand something. Explain it in three plain sentences at most, the heart of it first, no more than is needed."
1764 text Doing " asked for something to be done. "
1765 text 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."
1766 text Chat " said something in passing. Answer in one or two warm, plain sentences."
1767 text Allen "Allen"
1768 text Person "the person"
1769 fn selfemit to void
1770 off = add 40 mul mem32 32 113
1771 if eq get Mem off 0
1772 for i ulong len Allen
1773 emitb get Allen i
1774 end
1775 else
1776 for i ulong 24
1777 c = get Mem add off i
1778 if eq c 0
1779 ret
1780 end
1781 emitb c
1782 end
1783 end
1784 end
1785 fn whoemit to void
1786 if eq get Mem 8 0
1787 for i ulong len Person
1788 emitb get Person i
1789 end
1790 else
1791 for i ulong 24
1792 c = get Mem add i 8
1793 if eq c 0
1794 ret
1795 end
1796 emitb c
1797 end
1798 end
1799 end
1800 fn jobbuild kind ulong seq ulong to bool
1801 if or lt kind 1 gt kind 3
1802 ret false
1803 end
1804 if or eq seq 0 gt seq `4294967295`
1805 ret false
1806 end
1807 if not textok
1808 ret false
1809 end
1810 outreset
1811 for i ulong len Job
1812 emitb get Job i
1813 end
1814 emitn seq
1815 emitb 32
1816 if gt kind 1
1817 emitb 99
1818 emitb 111
1819 emitb 100
1820 emitb 101
1821 if eq kind 3
1822 emitb 45
1823 emitb 109
1824 emitb 111
1825 emitb 114
1826 emitb 101
1827 end
1828 emitb 32
1829 whoemit
1830 for i ulong len Codeask
1831 emitb get Codeask i
1832 end
1833 selfemit
1834 if eq kind 3
1835 for i ulong len Formore
1836 emitb get Formore i
1837 end
1838 else
1839 for i ulong len Forcode
1840 emitb get Forcode i
1841 end
1842 end
1843 else
1844 w = jobwant
1845 off = ulong 0
1846 size = ulong 4
1847 if eq w 1
1848 off = 4
1849 end
1850 if eq w 2
1851 off = 8
1852 size = 7
1853 end
1854 if eq w 3
1855 off = 15
1856 size = 2
1857 end
1858 for i ulong size
1859 emitb get Wantstr add off i
1860 end
1861 emitb 32
1862 for i ulong len Intro
1863 emitb get Intro i
1864 end
1865 selfemit
1866 for i ulong len Home
1867 emitb get Home i
1868 end
1869 whoemit
1870 for i ulong len Comp
1871 emitb get Comp i
1872 end
1873 selfemit
1874 for i ulong len Sees
1875 emitb get Sees i
1876 end
1877 whoemit
1878 for i ulong len Words
1879 emitb get Words i
1880 end
1881 selfemit
1882 for i ulong len Said
1883 emitb get Said i
1884 end
1885 whoemit
1886 if eq w 0
1887 for i ulong len Chat
1888 emitb get Chat i
1889 end
1890 end
1891 if eq w 1
1892 for i ulong len Make
1893 emitb get Make i
1894 end
1895 end
1896 if eq w 2
1897 for i ulong len Explain
1898 emitb get Explain i
1899 end
1900 end
1901 if eq w 3
1902 for i ulong len Doing
1903 emitb get Doing i
1904 end
1905 selfemit
1906 for i ulong len Cannot
1907 emitb get Cannot i
1908 end
1909 end
1910 emitb 9
1911 end
1912 for i ulong get Inlen 0
1913 emitb get In i
1914 end
1915 ret le get Outlen 0 4096
1916 end
1917 note SAY/WAIT parser, staged folded bytes. Native CODE receive remains separate.
1918 global Say uchar 160
1919 global S ulong 5
1920 fn sayhead to bool
1921 put P 0 0
1922 put P 2 0
1923 if ineq 0 87
1924 expect 87
1925 expect 65
1926 expect 73
1927 expect 84
1928 expect 32
1929 number
1930 put S 0 get P 1
1931 put S 1 0
1932 put S 2 0
1933 if ne get P 0 get Inlen 0
1934 ret false
1935 end
1936 ret eq get P 2 0
1937 end
1938 expect 83
1939 expect 65
1940 expect 89
1941 expect 32
1942 number
1943 put S 0 get P 1
1944 expect 32
1945 if ne get P 2 0
1946 ret false
1947 end
1948 put S 1 1
1949 put S 2 1
1950 save = get P 0
1951 number
1952 part = get P 1
1953 if ineq get P 0 47
1954 expect 47
1955 number
1956 put S 2 get P 1
1957 expect 32
1958 if or ne get P 2 0 eq part 0
1959 ret false
1960 end
1961 put S 1 part
1962 else
1963 put P 0 save
1964 put P 2 0
1965 end
1966 put S 3 get P 0
1967 ret eq get P 2 0
1968 end
1969 fn sayfold to bool
1970 n = ulong 0
1971 p = get S 3
1972 space = true
1973 while lt p get Inlen 0
1974 c = get In p
1975 p = add p 1
1976 if eq c 92
1977 if or ineq p 110 ineq p 116
1978 c = 32
1979 p = add p 1
1980 end
1981 end
1982 if or lt c 32 ge c 127
1983 c = 32
1984 end
1985 if eq c 32
1986 if not space
1987 if ge n 159
1988 ret false
1989 end
1990 put Say n c
1991 n = add n 1
1992 end
1993 space = true
1994 else
1995 if ge n 159
1996 ret false
1997 end
1998 put Say n c
1999 n = add n 1
2000 space = false
2001 end
2002 end
2003 if gt n 0
2004 if eq get Say sub n 1 32
2005 n = sub n 1
2006 end
2007 end
2008 put S 4 n
2009 ret true
2010 end
2011 note Return1 accepted,2 request AGAIN,3 give up after retry;0 rejected.
2012 fn saytake now ulong to ulong
2013 if or eq get R 1 0 gt get Inlen 0 319
2014 ret 0
2015 end
2016 if not sayhead
2017 ret 0
2018 end
2019 if or ne get S 0 get R 0 lt now get R 4
2020 ret 0
2021 end
2022 if eq get S 1 0
2023 b = heard get S 0 now
2024 ret 1
2025 end
2026 if not sayfold
2027 ret 0
2028 end
2029 if gt get R 2 1
2030 if eq get S 2 0
2031 ret 0
2032 end
2033 if ne get C 0 get R 0
2034 ret 0
2035 end
2036 if ne codestat 2
2037 if eq get R 13 0
2038 put R 13 1
2039 outreset
2040 emitb 65
2041 emitb 71
2042 emitb 65
2043 emitb 73
2044 emitb 78
2045 emitb 32
2046 emitn get R 0
2047 ret 2
2048 end
2049 cancel
2050 ret 3
2051 end
2052 else
2053 if ne get S 1 add get R 11 1
2054 ret 0
2055 end
2056 if and ne get S 2 0 ne get S 2 get S 1
2057 ret 0
2058 end
2059 end
2060 n = get R 8
2061 if or eq get S 1 1 gt get R 2 1
2062 n = 0
2063 end
2064 join = ulong 0
2065 if and gt n 0 gt get S 4 0
2066 join = 1
2067 end
2068 if gt add add n join get S 4 159
2069 ret 0
2070 end
2071 if gt get R 2 1
2072 if not codeshow get R 0
2073 ret 0
2074 end
2075 end
2076 if eq join 1
2077 put Answer n uchar 32
2078 n = add n 1
2079 end
2080 for i ulong get S 4
2081 put Answer add n i get Say i
2082 end
2083 put R 8 add n get S 4
2084 put R 11 get S 1
2085 put R 4 now
2086 if ne get S 2 0
2087 put R 1 0
2088 histadd 1
2089 end
2090 ret 1
2091 end
2092 note Exact legacy code row wrapping, at most4096 rows; full code retained.
2093 global Rowst ulong 4096
2094 global Rowlen ulong 4096
2095 global Rowline ulong 4096
2096 global View ulong 4
2097 global Vwork ulong 6
2098 note Vwork cols,maxrows,line,start,end.
2099 fn onerow s ulong first bool to ulong
2100 take = sub get Vwork 4 s
2101 cols = get Vwork 0
2102 if gt take cols
2103 take = cols
2104 j = cols
2105 while gt j div cols 2
2106 if eq get Code sub add s j 1 32
2107 take = j
2108 j = 0
2109 else
2110 j = sub j 1
2111 end
2112 end
2113 end
2114 slot = get View 0
2115 put Rowst slot s
2116 put Rowlen slot take
2117 put Rowline slot 0
2118 if first
2119 put Rowline slot get Vwork 2
2120 end
2121 put View 0 add slot 1
2122 ret add s take
2123 end
2124 fn rowroom pos ulong to bool
2125 ret and lt pos get C 2 lt get View 0 get Vwork 1
2126 end
2127 fn moreline s ulong to bool
2128 ret and lt s get Vwork 4 lt get View 0 get Vwork 1
2129 end
2130 fn rows cols ulong maxrows ulong to bool
2131 if or eq cols 0 gt maxrows 4096
2132 ret false
2133 end
2134 if ne codestat 2
2135 ret false
2136 end
2137 put Vwork 0 cols
2138 put Vwork 1 maxrows
2139 put Vwork 2 1
2140 put View 0 0
2141 put View 1 0
2142 pos = ulong 0
2143 while rowroom pos
2144 stop = pos
2145 while lt stop get C 2
2146 if eq get Code stop 10
2147 put Vwork 4 stop
2148 stop = get C 2
2149 else
2150 stop = add stop 1
2151 put Vwork 4 stop
2152 end
2153 end
2154 s = pos
2155 if lt get View 0 maxrows
2156 s = onerow s true
2157 end
2158 while moreline s
2159 s = onerow s false
2160 end
2161 pos = add get Vwork 4 1
2162 put Vwork 2 add get Vwork 2 1
2163 end
2164 ret true
2165 end
2166 fn scroll delta long page ulong to ulong
2167 last = ulong 0
2168 if gt get View 0 page
2169 last = sub get View 0 page
2170 end
2171 if gt get View 1 last
2172 put View 1 last
2173 end
2174 top = long get View 1
2175 if lt delta 0
2176 if lt delta neg top
2177 put View 1 0
2178 ret 0
2179 end
2180 else
2181 if gt ulong delta sub last get View 1
2182 put View 1 last
2183 ret last
2184 end
2185 end
2186 top = add top delta
2187 put View 1 ulong top
2188 ret ulong top
2189 end
2190 note Scene state: tone,water,has-say,nthings,used,lines,rejected,over.
2191 global Sc ulong 8
2192 global Things ulong 64
2193 global Stext uchar 2304
2194 global Sw ulong 4
2195 global Fields uchar 1536
2196 global Flens ulong 6
2197 global Soffs ulong 6
2198 text 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|"
2199 fn scword beg ulong size ulong to ulong
2200 s = ulong 0
2201 word = ulong 1
2202 for i ulong len Vocab
2203 if eq get Vocab i 124
2204 if eq sub i s size
2205 same = true
2206 for j ulong size
2207 if ne get In add beg j get Vocab add s j
2208 same = false
2209 end
2210 end
2211 if same
2212 ret word
2213 end
2214 end
2215 word = add word 1
2216 s = add i 1
2217 end
2218 end
2219 ret 0
2220 end
2221 fn fieldcap kind ulong field ulong to ulong
2222 if eq kind 2
2223 if eq field 0
2224 ret 48
2225 end
2226 ret 64
2227 end
2228 if eq kind 1
2229 if eq field 0
2230 ret 48
2231 end
2232 ret 240
2233 end
2234 if eq kind 3
2235 if eq field 0
2236 ret 16
2237 end
2238 ret 64
2239 end
2240 if eq kind 4
2241 if eq field 0
2242 ret 220
2243 end
2244 ret 48
2245 end
2246 if eq kind 5
2247 if eq field 0
2248 ret 32
2249 end
2250 ret 200
2251 end
2252 if eq kind 6
2253 if eq field 0
2254 ret 24
2255 end
2256 ret 64
2257 end
2258 if eq field 0
2259 ret 120
2260 end
2261 ret 64
2262 end
2263 fn scfield slot ulong beg ulong stop ulong kind ulong to bool
2264 s = beg
2265 e = stop
2266 while lt s e
2267 if eq get In s 32
2268 s = add s 1
2269 else
2270 ret fieldend slot s e kind
2271 end
2272 end
2273 put Flens slot 0
2274 ret true
2275 end
2276 fn fieldend slot ulong s ulong stop ulong kind ulong to bool
2277 e = stop
2278 while gt e s
2279 if eq get In sub e 1 32
2280 e = sub e 1
2281 else
2282 n = sub e s
2283 if gt n fieldcap kind slot
2284 ret false
2285 end
2286 for i ulong n
2287 c = get In add s i
2288 if or lt c 32 gt c 126
2289 ret false
2290 end
2291 put Fields add mul slot 256 i c
2292 end
2293 put Flens slot n
2294 ret true
2295 end
2296 end
2297 put Flens slot 0
2298 ret true
2299 end
2300 fn scfields beg ulong stop ulong kind ulong to ulong
2301 slot = ulong 0
2302 s = beg
2303 for i ulong sub stop beg
2304 p = add beg i
2305 if eq get In p 124
2306 if ge slot 5
2307 ret 0
2308 end
2309 if not scfield slot s p kind
2310 ret 0
2311 end
2312 slot = add slot 1
2313 s = add p 1
2314 end
2315 end
2316 if not scfield slot s stop kind
2317 ret 0
2318 end
2319 n = add slot 1
2320 if and ne kind 2 gt n 2
2321 ret 0
2322 end
2323 if eq get Flens 0 0
2324 ret 0
2325 end
2326 if eq kind 5
2327 if or lt n 2 eq get Flens 1 0
2328 ret 0
2329 end
2330 end
2331 if eq kind 3
2332 hasdigit = false
2333 for i ulong get Flens 0
2334 if isdigit get Fields i
2335 hasdigit = true
2336 end
2337 end
2338 if not hasdigit
2339 ret 0
2340 end
2341 end
2342 ret n
2343 end
2344 fn scput slot ulong to ulong
2345 off = get Sc 4
2346 n = get Flens slot
2347 for i ulong n
2348 put Stext add off i get Fields add mul slot 256 i
2349 end
2350 put Stext add off n 0
2351 put Sc 4 add add off n 1
2352 ret off
2353 end
2354 fn scmod word ulong base ulong to void
2355 if and ge word 11 le word 13
2356 put Things add base 1 sub word 10
2357 end
2358 if and ge word 16 le word 18
2359 put Things add base 2 sub word 16
2360 end
2361 if and ge word 19 le word 20
2362 put Things add base 3 sub word 18
2363 end
2364 if eq word 14
2365 put Things add base 4 1
2366 end
2367 if eq word 15
2368 put Things add base 5 1
2369 end
2370 end
2371 fn scsay beg ulong stop ulong to bool
2372 if ne get Sc 2 0
2373 ret false
2374 end
2375 n = sub stop beg
2376 if or eq n 0 gt n 159
2377 ret false
2378 end
2379 for i ulong n
2380 c = get In add beg i
2381 if or lt c 32 gt c 126
2382 ret false
2383 end
2384 put Fields i c
2385 end
2386 put Flens 0 n
2387 put Sc 2 1
2388 put Sw 3 scput 0
2389 ret true
2390 end
2391 fn scln beg ulong stop ulong to bool
2392 p = beg
2393 while lt p stop
2394 if or eq get In p 32 eq get In p 58
2395 ret scbody beg p stop
2396 end
2397 p = add p 1
2398 end
2399 ret false
2400 end
2401 fn scbody beg ulong wordend ulong stop ulong to bool
2402 word = scword beg sub wordend beg
2403 if eq word 2
2404 s = add wordend 1
2405 if lt s stop
2406 if eq get In s 58
2407 s = add s 1
2408 end
2409 end
2410 while lt s stop
2411 if eq get In s 32
2412 s = add s 1
2413 else
2414 ret scsay s stop
2415 end
2416 end
2417 ret false
2418 end
2419 if eq word 1
2420 s = add wordend 1
2421 for p ulong sub stop s
2422 at = add add wordend 1 p
2423 if eq get In at 32
2424 w = scword s sub at s
2425 if and ge w 21 le w 24
2426 put Sc 0 sub w 21
2427 end
2428 if and ge w 25 le w 27
2429 put Sc 1 sub w 25
2430 end
2431 s = add at 1
2432 end
2433 end
2434 w = scword s sub stop s
2435 if and ge w 21 le w 24
2436 put Sc 0 sub w 21
2437 end
2438 if and ge w 25 le w 27
2439 put Sc 1 sub w 25
2440 end
2441 ret true
2442 end
2443 if or lt word 3 gt word 10
2444 ret false
2445 end
2446 if ge get Sc 3 4
2447 put Sc 7 add get Sc 7 1
2448 ret false
2449 end
2450 put Sw 0 sub word 2
2451 colon = wordend
2452 while lt colon stop
2453 if eq get In colon 58
2454 put Sw 1 wordend
2455 put Sw 2 colon
2456 ret scthing add colon 1 stop
2457 end
2458 colon = add colon 1
2459 end
2460 ret false
2461 end
2462 fn scthing beg ulong stop ulong to bool
2463 n = scfields beg stop get Sw 0
2464 if eq n 0
2465 ret false
2466 end
2467 need = n
2468 for i ulong n
2469 need = add need get Flens i
2470 end
2471 if gt add get Sc 4 need 2304
2472 ret false
2473 end
2474 base = mul get Sc 3 16
2475 put Things base get Sw 0
2476 put Things add base 6 n
2477 s = get Sw 1
2478 for p ulong sub get Sw 2 s
2479 at = add get Sw 1 p
2480 if eq get In at 32
2481 w = scword s sub at s
2482 scmod w base
2483 s = add at 1
2484 end
2485 end
2486 w = scword s sub get Sw 2 s
2487 scmod w base
2488 for i ulong n
2489 put Things add add base 7 i scput i
2490 end
2491 put Sc 3 add get Sc 3 1
2492 ret true
2493 end
2494 fn scene to bool
2495 for i ulong 8
2496 put Sc i 0
2497 end
2498 for i ulong 64
2499 put Things i 0
2500 end
2501 put Sw 3 0
2502 n = get Inlen 0
2503 if gt n 2048
2504 n = 2048
2505 end
2506 s = ulong 0
2507 for p ulong n
2508 if eq get In p 10
2509 if gt p s
2510 if lt get Sc 5 12
2511 put Sc 5 add get Sc 5 1
2512 if not scln s p
2513 put Sc 6 add get Sc 6 1
2514 end
2515 else
2516 put Sc 7 add get Sc 7 1
2517 end
2518 end
2519 s = add p 1
2520 end
2521 end
2522 if and lt s n lt get Sc 5 12
2523 put Sc 5 add get Sc 5 1
2524 if not scln s n
2525 put Sc 6 add get Sc 6 1
2526 end
2527 end
2528 ret or ne get Sc 2 0 ne get Sc 3 0
2529 end
2530 note Handwritten Omega port of paint.h ck_add, ck_scale, ck_mix and paint.c ck_glow.
2531 note Bounded192x128 RAM canvas. This is rendering core, not full sky/font/device UI.
2532 global Frame uint 24576
2533 global G ulong 6
2534 global Fb uchar 73728
2535 fn channel c uint shift uint to uint
2536 ret and shr c shift 255
2537 end
2538 fn addcolor d uint c uint a uint to uint
2539 v = uint 0
2540 for i uint 3
2541 s = mul i 8
2542 n = add channel d s shr mul channel c s a 8
2543 if gt n 255
2544 n = 255
2545 end
2546 v = or v shl n s
2547 end
2548 ret v
2549 end
2550 fn scale c uint f uint to uint
2551 ret or and shr mul and c `16711935` f 8 `16711935` and shr mul and c 65280 f 8 65280
2552 end
2553 fn mix d uint c uint a uint to uint
2554 if ge a 256
2555 ret c
2556 end
2557 ret add scale d sub uint 256 a scale c a
2558 end
2559 fn distance x ulong y ulong to ulong
2560 dx = sub add mul long x 16 8 long get G 0
2561 dy = sub add mul long y 16 8 long get G 1
2562 ret ulong add mul dx dx mul dy dy
2563 end
2564 fn weight d2 ulong r2 ulong to ulong
2565 inv = div ulong `1099511627776` r2
2566 f = sub ulong 256 shr mul d2 inv 32
2567 w = shr mul shr mul f f 8 f 8
2568 ret shr mul w get G 4 8
2569 end
2570 fn glowpix x ulong y ulong to void
2571 d2 = distance x y
2572 r2 = mul get G 2 get G 2
2573 if ge d2 r2
2574 ret
2575 end
2576 a = uint weight d2 r2
2577 at = add mul y 192 x
2578 put Frame at addcolor get Frame at uint get G 3 a
2579 end
2580 fn glow cx ulong cy ulong radius ulong color ulong alpha ulong to bool
2581 if or eq radius 0 gt radius 8192
2582 ret false
2583 end
2584 if or gt cx 8192 gt cy 8192
2585 ret false
2586 end
2587 if or gt color `16777215` gt alpha 512
2588 ret false
2589 end
2590 put G 0 cx
2591 put G 1 cy
2592 put G 2 radius
2593 put G 3 color
2594 put G 4 alpha
2595 for y ulong 128
2596 for x ulong 192
2597 glowpix x y
2598 end
2599 end
2600 ret true
2601 end
2602 fn render to void
2603 for i ulong 24576
2604 put Frame i 0
2605 end
2606 note Frozen component pose; same halo and heart colors/weights as ck_mind_draw.
2607 b = glow 1536 1024 1088 `3951314` 68
2608 b = glow 1536 1024 640 `7363839` 46
2609 b = glow 1536 1024 400 `16765610` 89
2610 b = glow 1536 1024 160 `16772310` 218
2611 b = glow 1536 1024 50 `16775920` 230
2612 end
2613 fn frameout to bool
2614 for i ulong 24576
2615 c = get Frame i
2616 put Fb mul i 3 uchar channel c 16
2617 put Fb add mul i 3 1 uchar channel c 8
2618 put Fb add mul i 3 2 uchar channel c 0
2619 end
2620 n = ulong 0
2621 while lt n len Fb
2622 w = write 1 Fb n sub len Fb n
2623 if le w 0
2624 ret false
2625 end
2626 n = add n ulong w
2627 end
2628 ret true
2629 end
2630 note Native application binding: conversation state, courier lifecycle and reply/code.
2631 note A initialized, queued AGAIN bytes, per-call event, reserved.
2632 note Events:0 none,1 visible answer/ack,2 AGAIN queued,3 code give-up,
2633 note 4 refused LINE payload,5 slow notice,6 silence timeout.
2634 note Transport acceptance is separate from payload acceptance: appreceive true
2635 note means envelope accepted; inspect A2 for malformed payload, never invent text.
2636 global A ulong 4
2637 global Appjob uchar 4096
2638 global Appwire uchar 8192
2639 global Askin uchar 160
2640 fn appinit run ulong now ulong to bool
2641 if or ne get A 0 0 ne get R 0 0
2642 ret false
2643 end
2644 if ne get Q 0 0
2645 ret false
2646 end
2647 if not qstart run now
2648 ret false
2649 end
2650 constants
2651 put A 0 1
2652 put A 1 0
2653 put A 2 0
2654 ret true
2655 end
2656 fn appclock now ulong to bool
2657 if eq get A 0 0
2658 ret false
2659 end
2660 ret and ge now get T 0 ge now get R 4
2661 end
2662 fn appask now ulong to bool
2663 if not appclock now
2664 ret false
2665 end
2666 if or ne get R 1 0 ne get A 1 0
2667 ret false
2668 end
2669 if or ne get T 10 0 ne get T 13 0
2670 ret false
2671 end
2672 if and ne get T 5 0 eq get T 6 0
2673 ret false
2674 end
2675 if or ge get R 0 `4294967295` ge get Q 1 `4294967295`
2676 ret false
2677 end
2678 if not textok
2679 ret false
2680 end
2681 kind = classify
2682 if or lt kind 1 gt kind 3
2683 ret false
2684 end
2685 if and eq kind 3 eq get R 6 0
2686 ret false
2687 end
2688 note Validate restored context before jobbuild reads its variable-layout names.
2689 if not ctxmeta 6
2690 ret false
2691 end
2692 if not jobbuild kind add get R 0 1
2693 ret false
2694 end
2695 if not ctxappend
2696 ret false
2697 end
2698 n = get Inlen 0
2699 size = get Outlen 0
2700 for i ulong n
2701 put Askin i get In i
2702 end
2703 for i ulong size
2704 put Appjob i get Outb i
2705 end
2706 for i ulong size
2707 put In i get Appjob i
2708 end
2709 put Inlen 0 size
2710 queued = qsubmit now
2711 for i ulong n
2712 put In i get Askin i
2713 end
2714 put Inlen 0 n
2715 if not queued
2716 ret false
2717 end
2718 note start preconditions were checked before qsubmit; no concurrent calls permitted.
2719 if not start kind now
2720 qcancel
2721 ret false
2722 end
2723 put A 2 0
2724 if gt kind 1
2725 codebeg get R 0
2726 put A 2 1
2727 end
2728 ret true
2729 end
2730 fn appcancel to void
2731 cancel
2732 qcancel
2733 put A 1 0
2734 put A 2 0
2735 end
2736 fn appreset to void
2737 appcancel
2738 reset
2739 end
2740 note First acknowledge the triggering LINE, then submit AGAIN with a new wire
2741 note sequence while retaining the original conversation ID in its body.
2742 fn appqueue now ulong to bool
2743 if eq get A 1 0
2744 ret true
2745 end
2746 if or ne get T 10 0 ne get T 13 0
2747 ret true
2748 end
2749 put Inlen 0 get A 1
2750 for i ulong get A 1
2751 put In i get Appjob i
2752 end
2753 if not qsubmit now
2754 ret false
2755 end
2756 put A 1 0
2757 ret true
2758 end
2759 fn apppoll now ulong link bool to bool
2760 if not appclock now
2761 ret false
2762 end
2763 put A 2 0
2764 put T 0 now
2765 status = tick now
2766 if eq status 1
2767 put A 2 5
2768 end
2769 if eq status 2
2770 qcancel
2771 put A 1 0
2772 put A 2 6
2773 end
2774 if not appqueue now
2775 appcancel
2776 put A 2 3
2777 ret false
2778 end
2779 ret qnext now link
2780 end
2781 fn appsent now ulong ok bool to bool
2782 if not appclock now
2783 ret false
2784 end
2785 if not qsent now ok
2786 ret false
2787 end
2788 put A 2 0
2789 ret true
2790 end
2791 fn appbody now ulong to bool
2792 if eq get R 1 0
2793 put A 2 4
2794 ret true
2795 end
2796 if ineq 0 67
2797 if or le get R 2 1 ne get C 0 get R 0
2798 put A 2 4
2799 ret true
2800 end
2801 if codetake
2802 if heard get C 0 now
2803 ret true
2804 end
2805 end
2806 put A 2 4
2807 ret true
2808 end
2809 if or ineq 0 83 ineq 0 87
2810 status = saytake now
2811 if eq status 1
2812 if eq get R 1 0
2813 put A 1 0
2814 end
2815 if ne get S 1 0
2816 put A 2 1
2817 end
2818 ret true
2819 end
2820 if eq status 2
2821 n = get Outlen 0
2822 if or eq n 0 gt n 4096
2823 cancel
2824 put A 1 0
2825 put A 2 3
2826 ret true
2827 end
2828 for i ulong n
2829 put Appjob i get Outb i
2830 end
2831 put A 1 n
2832 put A 2 2
2833 ret true
2834 end
2835 if eq status 3
2836 put A 1 0
2837 put A 2 3
2838 ret true
2839 end
2840 end
2841 put A 2 4
2842 ret true
2843 end
2844 note Reply parsing can serialize AGAIN internally. Preserve the already offered
2845 note datagram until the provider records its send result, including on refusal.
2846 fn appreceive now ulong to bool
2847 if not appclock now
2848 ret false
2849 end
2850 result = qincoming now
2851 if eq result 0
2852 ret false
2853 end
2854 put A 2 0
2855 if not qtake
2856 ret true
2857 end
2858 n = get Outlen 0
2859 e = get Err 0
2860 for i ulong n
2861 put Appwire i get Outb i
2862 end
2863 ok = appbody now
2864 for i ulong n
2865 put Outb i get Appwire i
2866 end
2867 put Outlen 0 n
2868 put Err 0 e
2869 ret ok
2870 end
2871 note Bounded model scene input. Existing scene stays the strict canonical parser.
2872 note Nm thinking,normalized bytes,tidying count,hidden lines,line bytes,mood seen,
2873 note invalid/overflow,plain candidate bytes,canonical line count. Input restored.
2874 global Nm ulong 9
2875 global Nraw uchar 2048
2876 global Nline uchar 2048
2877 global Nnorm uchar 2048
2878 global Nplain uchar 160
2879 text Ntags ""
2880 fn nlow c uchar to uchar
2881 if and ge c 65 le c 90
2882 ret add sub c 65 97
2883 end
2884 ret c
2885 end
2886 fn nalpha c uchar to bool
2887 v = nlow c
2888 ret and ge v 97 le v 122
2889 end
2890 fn nmatch at ulong off ulong size ulong to bool
2891 if gt add at size get Nm 4
2892 ret false
2893 end
2894 for i ulong size
2895 if ne nlow get Nline add at i get Ntags add off i
2896 ret false
2897 end
2898 end
2899 ret true
2900 end
2901 fn nemit c uchar to void
2902 n = get Nm 1
2903 if ge n 2048
2904 put Nm 6 1
2905 ret
2906 end
2907 put Nnorm n c
2908 put Nm 1 add n 1
2909 end
2910 fn nmark c uchar to bool
2911 if or eq c 45 eq c 42
2912 ret true
2913 end
2914 if or eq c 35 eq c 62
2915 ret true
2916 end
2917 ret eq c 34
2918 end
2919 fn nlead c uchar to bool
2920 if or eq c 32 eq c 42
2921 ret true
2922 end
2923 if eq c 35
2924 ret true
2925 end
2926 ret nalpha c
2927 end
2928 fn ndigits p ulong to ulong
2929 while lt p get Nm 4
2930 if not isdigit get Nline p
2931 ret p
2932 end
2933 p = add p 1
2934 end
2935 ret p
2936 end
2937 fn nspaces p ulong to ulong
2938 while lt p get Nm 4
2939 if ne get Nline p 32
2940 ret p
2941 end
2942 p = add p 1
2943 end
2944 ret p
2945 end
2946 fn npstep s ulong to ulong
2947 n = get Nm 4
2948 c = get Nline s
2949 if nmark c
2950 if eq add s 1 n
2951 ret n
2952 end
2953 if nlead get Nline add s 1
2954 ret add s 1
2955 end
2956 ret s
2957 end
2958 if not isdigit c
2959 ret s
2960 end
2961 p = ndigits s
2962 if ge add p 1 n
2963 ret s
2964 end
2965 if not or eq get Nline p 46 eq get Nline p 41
2966 ret s
2967 end
2968 if ne get Nline add p 1 32
2969 ret s
2970 end
2971 ret add p 2
2972 end
2973 fn nprefix to ulong
2974 s = ulong 0
2975 while lt s get Nm 4
2976 next = npstep s
2977 if eq next s
2978 ret s
2979 end
2980 put Nm 2 add get Nm 2 1
2981 s = nspaces next
2982 end
2983 ret s
2984 end
2985 fn nfinish to void
2986 n = get Nm 4
2987 while gt n 0
2988 if eq get Nline sub n 1 32
2989 n = sub n 1
2990 else
2991 nprocess n
2992 ret
2993 end
2994 end
2995 end
2996 fn nprocess n ulong to void
2997 put Nm 4 n
2998 hide = ne get Nm 0 0
2999 for i ulong n
3000 if nmatch i 0 7
3001 put Nm 0 1
3002 hide = true
3003 end
3004 if nmatch i 7 8
3005 put Nm 0 0
3006 hide = true
3007 end
3008 end
3009 if hide
3010 put Nm 3 add get Nm 3 1
3011 ret
3012 end
3013 if ge n 3
3014 if and eq get Nline 0 96 eq get Nline 1 96
3015 if eq get Nline 2 96
3016 put Nm 2 add get Nm 2 1
3017 ret
3018 end
3019 end
3020 end
3021 s = nprefix
3022 if ge s n
3023 ret
3024 end
3025 w = s
3026 while lt w n
3027 if nalpha get Nline w
3028 w = add w 1
3029 else
3030 nword s w n
3031 ret
3032 end
3033 end
3034 nword s w n
3035 end
3036 fn nword s ulong w ulong n ulong to void
3037 for i ulong sub w s
3038 put In add s i nlow get Nline add s i
3039 end
3040 word = scword s sub w s
3041 if gt word 10
3042 word = 0
3043 end
3044 r = w
3045 while lt r n
3046 c = get Nline r
3047 if or eq c 42 eq c 34
3048 r = add r 1
3049 put Nm 2 add get Nm 2 1
3050 else
3051 nappend s w r n word
3052 ret
3053 end
3054 end
3055 nappend s w r n word
3056 end
3057 fn nappend s ulong w ulong r ulong n ulong word ulong to void
3058 if lt r n
3059 if not or eq get Nline r 32 eq get Nline r 58
3060 word = 0
3061 end
3062 end
3063 if eq word 0
3064 size = sub n s
3065 if and eq get Nm 7 0 le size 159
3066 if lt get Nm 8 12
3067 for i ulong size
3068 put Nplain i get Nline add s i
3069 end
3070 put Nm 7 size
3071 end
3072 end
3073 for i ulong size
3074 nemit get Nline add s i
3075 end
3076 else
3077 if eq word 1
3078 if lt get Nm 8 12
3079 put Nm 5 1
3080 end
3081 end
3082 for i ulong sub w s
3083 nemit nlow get Nline add s i
3084 end
3085 head = ne word 2
3086 for i ulong sub n r
3087 c = get Nline add r i
3088 if eq c 58
3089 if ne word 1
3090 head = false
3091 end
3092 end
3093 if head
3094 c = nlow c
3095 end
3096 nemit c
3097 end
3098 end
3099 nemit 10
3100 put Nm 8 add get Nm 8 1
3101 end
3102 fn nclear to void
3103 for i ulong 8
3104 put Sc i 0
3105 end
3106 for i ulong 64
3107 put Things i 0
3108 end
3109 put Sw 3 0
3110 end
3111 fn scdecode to bool
3112 for i ulong 9
3113 put Nm i 0
3114 end
3115 nclear
3116 n = get Inlen 0
3117 if gt n 2048
3118 put Nm 6 1
3119 ret false
3120 end
3121 for i ulong n
3122 if eq get In i 0
3123 put Nm 6 1
3124 ret false
3125 end
3126 put Nraw i get In i
3127 end
3128 for i ulong n
3129 c = get Nraw i
3130 if eq c 10
3131 nfinish
3132 put Nm 4 0
3133 else
3134 if eq c 9
3135 c = uchar 32
3136 put Nm 2 add get Nm 2 1
3137 end
3138 if and ge c 32 le c 126
3139 p = get Nm 4
3140 keep = true
3141 if eq c 32
3142 if eq p 0
3143 keep = false
3144 else
3145 if eq get Nline sub p 1 32
3146 keep = false
3147 end
3148 end
3149 end
3150 if keep
3151 put Nline p c
3152 put Nm 4 add p 1
3153 else
3154 put Nm 2 add get Nm 2 1
3155 end
3156 else
3157 put Nm 2 add get Nm 2 1
3158 end
3159 end
3160 end
3161 nfinish
3162 ok = false
3163 if eq get Nm 6 0
3164 for i ulong get Nm 1
3165 put In i get Nnorm i
3166 end
3167 put Inlen 0 get Nm 1
3168 ok = scene
3169 if ne get Nm 5 0
3170 ok = true
3171 end
3172 if not ok
3173 if gt get Nm 7 0
3174 for i ulong get Nm 7
3175 put In i get Nplain i
3176 end
3177 put Inlen 0 get Nm 7
3178 ok = scsay 0 get Nm 7
3179 end
3180 end
3181 else
3182 nclear
3183 end
3184 for i ulong n
3185 put In i get Nraw i
3186 end
3187 put Inlen 0 n
3188 ret ok
3189 end
3190 note Restored note catalog and bounded model-job context. No storage provider.
3191 note Cx declared count,visited count,ready,damaged,loading. Damaged notes stay gone.
3192 global Cx ulong 5
3193 global Ctxtext uchar 65536
3194 global Ctxlen ulong 512
3195 global Ctxgone uchar 512
3196 global Ctxseen uchar 512
3197 global Ctxstart ulong 512
3198 global Meta uchar 4096
3199 global Mx ulong 2
3200 global Mdigits uchar 20
3201 text Mtself "\tself="
3202 text Mtname "\tname="
3203 text Mtstart "\tstarts="
3204 text Mtfact "\tfact "
3205 text Mtis " is "
3206 text Mtare " are "
3207 text Mtnote "\tnote "
3208 fn ctxidle to bool
3209 if ne get R 1 0
3210 ret false
3211 end
3212 ret and eq get Tx 0 0 eq get Nt 0 0
3213 end
3214 fn ctxbegin to bool
3215 if not ctxidle
3216 ret false
3217 end
3218 n = mem32 36
3219 if gt n 512
3220 ret false
3221 end
3222 for i ulong 512
3223 put Ctxlen i 0
3224 put Ctxgone i 1
3225 put Ctxseen i 0
3226 put Ctxstart i 0
3227 end
3228 put Cx 0 n
3229 put Cx 1 0
3230 put Cx 2 0
3231 put Cx 3 0
3232 put Cx 4 1
3233 if eq n 0
3234 put Cx 2 1
3235 put Cx 4 0
3236 end
3237 ret true
3238 end
3239 note Returns0 refused without visit,1 valid record retained,2 damaged visit retained.
3240 fn ctxtake index ulong to ulong
3241 if not ctxidle
3242 ret 0
3243 end
3244 if or eq get Cx 4 0 ge index get Cx 0
3245 ret 0
3246 end
3247 if ne get Ctxseen index 0
3248 ret 0
3249 end
3250 status = ulong 2
3251 if notedec index
3252 n = get Ns 0
3253 for i ulong n
3254 put Ctxtext add mul index 128 i get Note i
3255 end
3256 put Ctxlen index n
3257 put Ctxgone index uchar get Ns 3
3258 put Ctxstart index get Ns 2
3259 status = 1
3260 else
3261 put Cx 3 add get Cx 3 1
3262 end
3263 put Ctxseen index 1
3264 put Cx 1 add get Cx 1 1
3265 if eq get Cx 1 get Cx 0
3266 put Cx 2 1
3267 put Cx 4 0
3268 end
3269 ret status
3270 end
3271 fn mtemit c uchar to void
3272 if ne get Mx 1 0
3273 ret
3274 end
3275 n = get Mx 0
3276 if ge n 4096
3277 put Mx 1 1
3278 ret
3279 end
3280 put Meta n c
3281 put Mx 0 add n 1
3282 end
3283 fn mtnum v ulong to void
3284 n = ulong 0
3285 while gt v 9
3286 put Mdigits n uchar rem v 10
3287 v = div v 10
3288 n = add n 1
3289 end
3290 put Mdigits n uchar v
3291 n = add n 1
3292 for i ulong n
3293 mtemit add uchar 48 get Mdigits sub sub n 1 i
3294 end
3295 end
3296 note Memory fields are length-bounded; require a terminator and printable bytes.
3297 fn mtfield off ulong cap ulong to bool
3298 for i ulong cap
3299 c = get Mem add off i
3300 if eq c 0
3301 if eq i 0
3302 put Mx 1 1
3303 ret false
3304 end
3305 ret true
3306 end
3307 if or lt c 32 gt c 126
3308 put Mx 1 1
3309 ret false
3310 end
3311 mtemit c
3312 end
3313 put Mx 1 1
3314 ret false
3315 end
3316 fn mtfacts count ulong to bool
3317 for k ulong count
3318 off = add 40 mul k 113
3319 for i ulong len Mtfact
3320 mtemit get Mtfact i
3321 end
3322 if not mtfield off 48
3323 ret false
3324 end
3325 are = get Mem add off 112
3326 if gt are 1
3327 put Mx 1 1
3328 ret false
3329 end
3330 if eq are 1
3331 for i ulong len Mtare
3332 mtemit get Mtare i
3333 end
3334 else
3335 for i ulong len Mtis
3336 mtemit get Mtis i
3337 end
3338 end
3339 if not mtfield add off 48 64
3340 ret false
3341 end
3342 end
3343 ret eq get Mx 1 0
3344 end
3345 fn mtnotes count ulong limit ulong to void
3346 given = ulong 0
3347 for k ulong count
3348 index = sub sub count 1 k
3349 if and eq get Ctxgone index 0 lt given limit
3350 for i ulong len Mtnote
3351 mtemit get Mtnote i
3352 end
3353 for i ulong get Ctxlen index
3354 mtemit get Ctxtext add mul index 128 i
3355 end
3356 given = add given 1
3357 end
3358 end
3359 end
3360 fn ctxmeta limit ulong to bool
3361 put Mx 0 0
3362 put Mx 1 1
3363 facts = mem32 32
3364 notes = mem32 36
3365 if or gt facts 32 gt notes 512
3366 ret false
3367 end
3368 if gt limit 512
3369 ret false
3370 end
3371 if gt notes 0
3372 if or eq get Cx 2 0 ne get Cx 0 notes
3373 ret false
3374 end
3375 end
3376 put Mx 1 0
3377 for i ulong len Mtself
3378 mtemit get Mtself i
3379 end
3380 off = add 40 mul facts 113
3381 if eq get Mem off 0
3382 for i ulong len Allen
3383 mtemit get Allen i
3384 end
3385 else
3386 if not mtfield off 24
3387 ret false
3388 end
3389 end
3390 if ne get Mem 8 0
3391 for i ulong len Mtname
3392 mtemit get Mtname i
3393 end
3394 if not mtfield 8 24
3395 ret false
3396 end
3397 end
3398 for i ulong len Mtstart
3399 mtemit get Mtstart i
3400 end
3401 mtnum mem32 0
3402 if not mtfacts facts
3403 ret false
3404 end
3405 mtnotes notes limit
3406 ret eq get Mx 1 0
3407 end
3408 note Publish all metadata or none; preserve outgoing bytes/length/error on refusal.
3409 fn ctxappend to bool
3410 if or ne get Mx 1 0 ne get Err 0 0
3411 ret false
3412 end
3413 n = get Outlen 0
3414 size = get Mx 0
3415 if or gt n 4096 gt size 4096
3416 ret false
3417 end
3418 if gt add n size 4096
3419 ret false
3420 end
3421 for i ulong size
3422 put Outb add n i get Meta i
3423 end
3424 put Outlen 0 add n size
3425 ret true
3426 end
3427 note Host provider stream core. PROVIDER.md is the framing/state contract.
3428 global Ph uchar 40
3429 global Pb uchar 4096
3430 global Pv ulong 4
3431 global Pc ulong 2
3432 global Pe ulong 2
3433 global Pout uchar 65536
3434 global Pn ulong 1
3435 text Prmagic "ALNPRV01"
3436 fn prshape to bool
3437 op = get Pv 0
3438 now = get Pv 1
3439 arg = get Pv 2
3440 n = get Pv 3
3441 if eq op 1
3442 ret and gt arg 0 eq n 0
3443 end
3444 if eq op 2
3445 if ne arg 0
3446 ret false
3447 end
3448 ret and gt n 0 le n 159
3449 end
3450 if or eq op 3 eq op 4
3451 ret and le arg 1 eq n 0
3452 end
3453 if eq op 5
3454 if ne arg 0
3455 ret false
3456 end
3457 ret and ge n 65 le n 1200
3458 end
3459 if ne now 0
3460 ret false
3461 end
3462 if or eq op 6 eq op 7
3463 ret and eq arg 0 eq n 0
3464 end
3465 if eq op 8
3466 ret and le arg 1 eq n 4096
3467 end
3468 if eq op 9
3469 ret and le arg 511 eq n 4096
3470 end
3471 if eq op 10
3472 ret and eq arg 0 eq n 0
3473 end
3474 ret false
3475 end
3476 fn prparse to bool
3477 for i ulong 8
3478 if ne get Ph i get Prmagic i
3479 ret false
3480 end
3481 end
3482 for k ulong 4
3483 v = ulong 0
3484 for i ulong 8
3485 off = add add 8 mul k 8 i
3486 v = or v shl ulong get Ph off mul i 8
3487 end
3488 put Pv k v
3489 end
3490 ret prshape
3491 end
3492 fn prbyte c uchar to void
3493 put Pout get Pn 0 c
3494 put Pn 0 add get Pn 0 1
3495 end
3496 fn prword v ulong to void
3497 for i ulong 8
3498 prbyte uchar and shr v mul i 8 255
3499 end
3500 end
3501 fn prhead op ulong status ulong event ulong size ulong to void
3502 for i ulong 8
3503 prbyte get Prmagic i
3504 end
3505 prword op
3506 prword status
3507 prword event
3508 prword size
3509 end
3510 fn prreply status ulong to void
3511 put Pn 0 0
3512 kind = get Pe 1
3513 size = ulong 0
3514 if eq kind 1
3515 size = get Outlen 0
3516 end
3517 if eq kind 2
3518 size = get R 8
3519 end
3520 prhead get Pv 0 status get Pe 0 size
3521 for i ulong size
3522 if eq kind 1
3523 prbyte get Outb i
3524 else
3525 prbyte get Answer i
3526 end
3527 end
3528 if eq kind 2
3529 if and gt get R 2 1 eq get R 1 0
3530 if and ne get R 6 0 eq codestat 2
3531 prhead 11 1 1 get C 2
3532 for i ulong get C 2
3533 prbyte get Code i
3534 end
3535 end
3536 end
3537 end
3538 end
3539 fn prevent to void
3540 put Pe 0 get A 2
3541 if eq get A 2 1
3542 put Pe 1 2
3543 end
3544 end
3545 fn prload to ulong
3546 if or ne get A 0 0 not ctxidle
3547 ret 0
3548 end
3549 constants
3550 for i ulong 3692
3551 put Mem i 0
3552 end
3553 loadbeg
3554 b = ctxbegin
3555 put Pc 0 1
3556 put Pc 1 0
3557 ret 1
3558 end
3559 fn prcopy to ulong
3560 if or ne get A 0 0 ne get Pc 0 1
3561 ret 0
3562 end
3563 if not ctxidle
3564 ret 0
3565 end
3566 slot = get Pv 2
3567 bit = shl ulong 1 slot
3568 if ne and get Pc 1 bit 0
3569 ret 0
3570 end
3571 for i ulong 4096
3572 put Unit i get Pb i
3573 end
3574 status = ulong 2
3575 if loadcopy slot
3576 status = 1
3577 end
3578 put Pc 1 or get Pc 1 bit
3579 if eq get Pc 1 3
3580 if not ctxbegin
3581 ret 0
3582 end
3583 put Pc 0 2
3584 if ne get Cx 2 0
3585 put Pc 0 3
3586 end
3587 end
3588 ret status
3589 end
3590 fn prnote to ulong
3591 if or ne get A 0 0 ne get Pc 0 2
3592 ret 0
3593 end
3594 if not ctxidle
3595 ret 0
3596 end
3597 for i ulong 4096
3598 put Unit i get Pb i
3599 end
3600 status = ctxtake get Pv 2
3601 if ne get Cx 2 0
3602 put Pc 0 3
3603 end
3604 ret status
3605 end
3606 fn prapply to ulong
3607 op = get Pv 0
3608 now = get Pv 1
3609 arg = get Pv 2
3610 if eq op 10
3611 ret prload
3612 end
3613 if eq op 8
3614 ret prcopy
3615 end
3616 if eq op 9
3617 ret prnote
3618 end
3619 if eq op 1
3620 if or eq get Pc 0 1 eq get Pc 0 2
3621 ret 0
3622 end
3623 if appinit arg now
3624 ret 1
3625 end
3626 ret 0
3627 end
3628 if eq get A 0 0
3629 ret 0
3630 end
3631 if eq op 6
3632 appcancel
3633 ret 1
3634 end
3635 if eq op 7
3636 appreset
3637 ret 1
3638 end
3639 if not appclock now
3640 ret 0
3641 end
3642 if eq op 3
3643 offer = apppoll now ne arg 0
3644 prevent
3645 if offer
3646 put Pe 1 1
3647 ret 3
3648 end
3649 ret 1
3650 end
3651 if eq op 4
3652 if appsent now ne arg 0
3653 ret 1
3654 end
3655 ret 0
3656 end
3657 for i ulong get Pv 3
3658 put In i get Pb i
3659 end
3660 put Inlen 0 get Pv 3
3661 if eq op 2
3662 if not appask now
3663 ret 0
3664 end
3665 else
3666 if not appreceive now
3667 ret 0
3668 end
3669 end
3670 prevent
3671 ret 1
3672 end
3673 fn prdo to bool
3674 if not prparse
3675 ret false
3676 end
3677 put Pe 0 0
3678 put Pe 1 0
3679 status = prapply
3680 prreply status
3681 ret true
3682 end
3683 note Stable application presentation; see PRESENTATION.md for scope and ownership.
3684 global Ds ulong 8
3685 global Dt ulong 64
3686 global Dtext uchar 2304
3687 global Dsay ulong 1
3688 global Dm ulong 3
3689 global Dcode uchar 32768
3690 global Dstart ulong 4096
3691 global Dlen ulong 4096
3692 global Dline ulong 4096
3693 global Dview ulong 3
3694 global Din uchar 8192
3695 fn dscene to bool
3696 n = get Inlen 0
3697 for i ulong 8192
3698 put Din i get In i
3699 end
3700 for i ulong get R 8
3701 put In i get Answer i
3702 end
3703 put Inlen 0 get R 8
3704 ok = scdecode
3705 for i ulong 8192
3706 put In i get Din i
3707 end
3708 put Inlen 0 n
3709 if not ok
3710 ret false
3711 end
3712 for i ulong 8
3713 put Ds i get Sc i
3714 end
3715 for i ulong 64
3716 put Dt i get Things i
3717 end
3718 for i ulong 2304
3719 put Dtext i 0
3720 end
3721 for i ulong get Sc 4
3722 put Dtext i get Stext i
3723 end
3724 put Dsay 0 get Sw 3
3725 put Dm 0 1
3726 ret true
3727 end
3728 fn dcode to bool
3729 if or le get R 2 1 ne get R 1 0
3730 ret false
3731 end
3732 if or eq get R 6 0 ne get C 0 get R 0
3733 ret false
3734 end
3735 if not rows 80 4096
3736 ret false
3737 end
3738 for i ulong 32768
3739 put Dcode i 0
3740 end
3741 for i ulong get C 2
3742 put Dcode i get Code i
3743 end
3744 for i ulong 4096
3745 put Dstart i 0
3746 put Dlen i 0
3747 put Dline i 0
3748 end
3749 for i ulong get View 0
3750 put Dstart i get Rowst i
3751 put Dlen i get Rowlen i
3752 put Dline i get Rowline i
3753 end
3754 put Dview 0 get View 0
3755 put Dview 1 0
3756 put Dview 2 get C 2
3757 put Dm 1 1
3758 ret true
3759 end
3760 fn dpresent to bool
3761 if or eq get A 0 0 ne get A 2 1
3762 ret false
3763 end
3764 if or gt get R 8 159 gt get Inlen 0 8192
3765 ret false
3766 end
3767 shown = dscene
3768 coded = dcode
3769 if or shown coded
3770 put Dm 2 get R 0
3771 ret true
3772 end
3773 ret false
3774 end
3775 fn dask now ulong to bool
3776 if not appask now
3777 ret false
3778 end
3779 b = dpresent
3780 ret true
3781 end
3782 fn drecv now ulong to bool
3783 if not appreceive now
3784 ret false
3785 end
3786 b = dpresent
3787 ret true
3788 end
3789 fn dreset to void
3790 appreset
3791 for i ulong 8
3792 put Ds i 0
3793 end
3794 for i ulong 64
3795 put Dt i 0
3796 end
3797 for i ulong 2304
3798 put Dtext i 0
3799 end
3800 put Dsay 0 0
3801 for i ulong 3
3802 put Dm i 0
3803 put Dview i 0
3804 end
3805 for i ulong 32768
3806 put Dcode i 0
3807 end
3808 for i ulong 4096
3809 put Dstart i 0
3810 put Dlen i 0
3811 put Dline i 0
3812 end
3813 for i ulong 8192
3814 put Din i 0
3815 end
3816 end
3817 global Fails ulong 1
3818 global Checks ulong 1
3819 fn check ok bool id ulong to void
3820 put Checks 0 add get Checks 0 1
3821 outreset
3822 emitn id
3823 if ok
3824 emitb 32
3825 emitb 48
3826 else
3827 put Fails 0 add get Fails 0 1
3828 emitb 32
3829 emitb 49
3830 end
3831 emitb 10
3832 w = write 1 Outb 0 get Outlen 0
3833 end
3834 text Prompt1 "hello"
3835 text Leak "LEAK"
3836 text Scene1 "SAY 1 1/1 note left: Heading | Body"
3837 text Hidden1 "private"
3838 text Badscene "number: nope"
3839 text Prompt2 "write a calculator"
3840 text Code2 "CODE 2 1/1 2 `d8932aac` text hi"
3841 text Done2 "SAY 2 1/1 Done."
3842 global Saved uchar 8192
3843 global Keep ulong 2
3844 global Before uchar 8192
3845 global Wire uchar 8192
3846 fn test ok bool to void
3847 put Keep 0 get Outlen 0
3848 put Keep 1 get Err 0
3849 for i ulong get Outlen 0
3850 put Saved i get Outb i
3851 end
3852 check ok add get Checks 0 1
3853 for i ulong get Keep 0
3854 put Outb i get Saved i
3855 end
3856 put Outlen 0 get Keep 0
3857 put Err 0 get Keep 1
3858 end
3859 fn inbound part ulong to void
3860 n = get Outlen 0
3861 e = get Err 0
3862 for i ulong n
3863 put Before i get Outb i
3864 end
3865 b = packet 2 get Q 1 part 0 0
3866 size = get Outlen 0
3867 for i ulong size
3868 put In i get Outb i
3869 end
3870 put Inlen 0 size
3871 for i ulong n
3872 put Outb i get Before i
3873 end
3874 put Outlen 0 n
3875 put Err 0 e
3876 end
3877 fn main to int
3878 test not dpresent
3879 test appinit 77 0
3880 put Inlen 0 len Prompt1
3881 for i ulong len Prompt1
3882 put In i get Prompt1 i
3883 end
3884 test dask 1
3885 test eq get R 0 1
3886 test eq get Dm 0 0
3887 test apppoll 1 true
3888 n = get Outlen 0
3889 for i ulong n
3890 put Wire i get Outb i
3891 end
3892 for i ulong len Scene1
3893 put In i get Scene1 i
3894 end
3895 put Inlen 0 len Scene1
3896 inbound 1
3897 size = get Inlen 0
3898 for i ulong size
3899 put Before i get In i
3900 end
3901 test drecv 2
3902 test eq get A 2 1
3903 test eq get Dm 0 1
3904 test eq get Dm 2 1
3905 test eq get Ds 3 1
3906 test eq get Dt 0 1
3907 test eq get Dt 1 1
3908 test eq get Dtext get Dt 7 72
3909 test eq get Dtext get Dt 8 66
3910 test eq get Outlen 0 n
3911 same = true
3912 for i ulong n
3913 if ne get Outb i get Wire i
3914 same = false
3915 end
3916 end
3917 test same
3918 test eq get T 10 5
3919 note appreceive replaces In with its payload; only dpresent must preserve that.
3920 size = get Inlen 0
3921 for i ulong size
3922 put Before i get In i
3923 end
3924 test dpresent
3925 test eq get Inlen 0 size
3926 same = true
3927 for i ulong size
3928 if ne get Before i get In i
3929 same = false
3930 end
3931 end
3932 test same
3933 note Even bytes outside current Inlen survive decoder scratch expansion.
3934 for i ulong 8192
3935 put In i 165
3936 put Before i 165
3937 end
3938 put Inlen 0 1
3939 test dpresent
3940 test eq get Inlen 0 1
3941 same = true
3942 for i ulong 8192
3943 if ne get In i get Before i
3944 same = false
3945 end
3946 end
3947 test same
3948 put Inlen 0 8193
3949 test not dpresent
3950 put Inlen 0 1
3951 note Hidden or invalid scene text cannot erase the last admitted presentation.
3952 for i ulong len Hidden1
3953 put Answer i get Hidden1 i
3954 end
3955 put R 8 len Hidden1
3956 test not dpresent
3957 test eq get Ds 3 1
3958 test eq get Dtext get Dt 7 72
3959 for i ulong len Badscene
3960 put Answer i get Badscene i
3961 end
3962 put R 8 len Badscene
3963 test not dpresent
3964 test eq get Ds 3 1
3965 put A 2 0
3966 test not dpresent
3967 put A 2 1
3968 put R 8 160
3969 test not dpresent
3970 put R 8 0
3971 test not dpresent
3972 note Refused receive cannot publish a stale event1.
3973 for i ulong len Leak
3974 put Answer i get Leak i
3975 end
3976 put R 8 len Leak
3977 put Inlen 0 1
3978 put In 0 88
3979 test not drecv 2
3980 test eq get Ds 3 1
3981 test appsent 2 true
3982 test apppoll 2 true
3983 test appsent 2 true
3984 put Inlen 0 len Prompt2
3985 for i ulong len Prompt2
3986 put In i get Prompt2 i
3987 end
3988 test dask 3
3989 test eq get R 0 2
3990 test eq get Ds 2 1
3991 test eq get Dtext get Dsay 0 73
3992 for i ulong len Code2
3993 put In i get Code2 i
3994 end
3995 put Inlen 0 len Code2
3996 inbound 1
3997 test drecv 4
3998 test eq get Dm 1 0
3999 test apppoll 4 true
4000 test appsent 4 true
4001 for i ulong len Done2
4002 put In i get Done2 i
4003 end
4004 put Inlen 0 len Done2
4005 inbound 2
4006 test drecv 5
4007 test eq get Dm 1 1
4008 test eq get Dm 2 2
4009 test eq get Dview 0 1
4010 test eq get Dview 1 0
4011 test eq get Dview 2 2
4012 test eq get Dstart 0 0
4013 test eq get Dlen 0 2
4014 test eq get Dline 0 1
4015 test eq get Dcode 0 104
4016 test eq get Dcode 1 105
4017 test eq get Dtext get Dsay 0 68
4018 note Code completion does not require a nonempty closing sentence.
4019 put R 8 0
4020 test dpresent
4021 test eq get Dm 1 1
4022 test eq get Dcode 0 104
4023 put Code 0 88
4024 test not dpresent
4025 test eq get Dcode 0 104
4026 test eq get Dlen 0 2
4027 put Code 0 104
4028 note Later assembly may reuse Code; the displayed snapshot cannot alias it.
4029 codebeg 3
4030 put Code 0 88
4031 test eq get Dcode 0 104
4032 put A 2 0
4033 test not dpresent
4034 test eq get Dm 1 1
4035 put Dtext 2303 88
4036 put Dcode 32767 88
4037 put Dstart 4095 88
4038 put Dlen 4095 88
4039 put Dline 4095 88
4040 dreset
4041 test eq get Dm 0 0
4042 test eq get Dm 1 0
4043 test eq get Dview 0 0
4044 test eq get R 0 2
4045 test eq get Q 1 2
4046 same = true
4047 for i ulong 2304
4048 if ne get Dtext i 0
4049 same = false
4050 end
4051 end
4052 test same
4053 same = true
4054 for i ulong 32768
4055 if ne get Dcode i 0
4056 same = false
4057 end
4058 end
4059 test same
4060 same = true
4061 for i ulong 4096
4062 if ne or or get Dstart i get Dlen i get Dline i 0
4063 same = false
4064 end
4065 end
4066 test same
4067 if ne get Fails 0 0
4068 ret 1
4069 end
4070 ret 0
4071 end