interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / node / code.om

1719 lines · 36782 bytes Raw Blame History
1note seed/node/code.om -- the Omega Node coding workflow (DRA-290): the
2note round40 repair protocol (read, check, edit, check again, answer) driven
3note by the own Omega model through the Node's scheduler, authority and
4note journal, under live operator control (DRA-291). OM-2. Compose after
5note seed/net/http.om, seed/net/notls.om, transport.om, pool.om, super.om,
6note sched.om, seed/authority/action.om, journal.om, auth.om, view.om,
7note seed/node/gram.om, and before one program with fn main (code-main.om
8note or code-test.om).
9note Processes. The creator holds every objective's state; it alone reads
10note model output and decides. Two workers run granted jobs, each one child
11note process in its own process group (auth_wtool): omnode-infer for a model
12note turn, omnode-tool for read_file, omega_check and replace_text, and a
13note review (a fresh omnode-tool check of the edited file). A job's input is
14note the packed argv the creator published on the objective's topic bit;
15note the worker proposes it, the creator grants it (generation, staleness,
16note cancellation, journal START), the worker runs it and returns the
17note child's record (OMNI1 or OMNT1, at most 3968 bytes) with the outcome.
18note One inference at a time: the provider is a single local ollm serve.
19note A turn has 160 new tokens (as round40 sampled) and 900 s, since the CPU
20note server needs minutes for a long prompt on a shared host.
21note Policy, as round40 repair.py jobs_run: at most 7 model turns; the action
22note must name the objective's path; read_file only when unread, omega_check
23note only when read or edited, replace_text only when failed, whose old text
24note must occur exactly once in the source the model was shown and whose
25note result must stay in the repair grammar (checked here before the grant);
26note Tests passed. only when the last check passed (then a review job runs),
27note File not found. only when the read found no file. Anything else ends
28note the objective as failed; nothing is repaired or retried.
29note Results: 1 PASS; failures 10 action not valid in its state, 11 wrong
30note path, 12 out of turns, 13 edit refused, 14 Tests passed. unverified,
31note 15 the file differs from the workflow's source, or the review's fresh check of the saved
32note file did not pass (a test run killed at the 2 s wall clock included), 16 inference failed
33note (exit status in the event line; no fallback), 17 tool failed, 18
34note malformed record, 19 cancelled, 20 prompt too long, 21 outcome UNKNOWN,
35note 22 job input lost, 23 refused by the authority.
36note Restart: the journal releases what the last creator left (auth_recover);
37note jobs still waiting for input are cancelled; an objective whose result
38note the journal holds (RESULT) is reported with it again and never resumed;
39note every other objective resumes from the durable workspace in state
40note unread, with the model turns already performed counted against its
41note budget and its job ids continuing; the committed operator commands are
42note then applied again in order to the objectives still open.
43note Operator (DRA-291): the creator writes a snapshot of its state and an
44note event per change to view.om's page every loop, and takes one posted
45note command per loop. A command is checked against the version the
46note operator saw (stale when its target changed since), committed in the
47note journal (OPER; pause and resume first through auth_pause), then acted
48note on and acknowledged: pause and resume, cancel an objective (its job in
49note flight is cancelled through the authority and the objective ends 19),
50note set its turn budget (0..7; out of turns ends 12), or redirect it to
51note another goal (its job in flight is cancelled and it starts over from
52note unread). A tool job the authority refuses ends its objective with 23.
53note Events on stdout, one line each: CWP (prompt) and CWR (model text) are
54note followed by their bytes and a newline; CWE job events; CWO results;
55note CWV the operator view's port once it listens.
56const CWOBJ ulong 4
57text cwtask "Task: "
58text cwfile "\nFile: "
59text cwgoal "\nGoal: "
60text cwstat "\nState: "
61text cwsrcl "Source:\n"
62text cwtres "Tool result: "
63text cwansw "Answer:\n"
64text cwnl "\n"
65text cwsp " "
66text cwgl1 "calc starts with x and adds "
67text cwgl2 " exactly "
68text cwgl3 " times in a for loop. main calls calc with "
69text cwgl4 "calc returns x "
70text cwplus "plus "
71text cwtims "times "
72text cwgl5 ". main calls calc with "
73text cwdot "."
74text cwsun "unread"
75text cwsrd "read"
76text cwsfl "failed"
77text cwsed "edited"
78text cwsck "checked"
79text cwsms "missing"
80text cwvrd "read"
81text cwvck "check"
82text cwvrp "replace"
83text cwmax "160"
84text cwdl "900"
85text cwo "/o"
86text cwadd "add"
87text cwmul "mul"
88text cwloop "loop"
89text cwhi "OMNI1 "
90text cwht "OMNT1 "
91text cwep "CWP "
92text cwer "CWR "
93text cwee "CWE "
94text cwfpre "code-main: "
95text cwfex ", exit "
96text cwfpool "pool_new failed"
97text cwfsup "sup_init failed"
98text cwfsch "sched_new failed"
99text cwfaut "auth_new failed"
100text cwfjrn "journal refused (exit 30 + 20 fenced, 21 incompatible, 22 other objective, 23 corrupt, 24/25 refused record, 26 directory over 100 bytes, 27 I/O error)"
101text cwfrec "restart recovery refused (exit 30 + 24/25 refused record, 27 I/O error, 28 write, 29 sync, 30 journal failed earlier, 31 the scheduler refused a restore: incarnation, capacities or policy, a job admitted again, or the last FAIR, 32 action record not restored)"
102text cwfvwn "vw_new failed"
103text cwfspn "worker spawn failed"
104text cwfvw "view process not started"
105text cwfcan "restart cleanup could not cancel a job the last creator left waiting or ready (the journal refused its CANCEL, or the RELEASE after a cancel that freed it)"
106text cweo "CWO "
107text cwpass "PASS"
108text cwfail "FAIL"
109text cwsum "CWSUM pass="
110text cwsumf " fail="
111text cwfresult "objective RESULT could not be committed"
112global cwresultbad ulong 1
113global cwcf uchar 8192
114global cwcl ulong 8
115global cwno ulong 1
116global cwos uchar 2048
117global cwob ulong 128
118global cwsrc uchar 16384
119global cwobs uchar 4096
120global cwcan uchar 16384
121global cwinf ulong 1
122global cwgot ulong 64
123global cwt0 ulong 4
124global cwtk ulong 2
125global cwpv ulong 1
126global cwql ulong 1
127global cwtu ulong 1
128text cwcwv "CWV "
129note Objective words shown in the view's rows, as characters '0' + word.
130text cwvw "012367@9:<ABC;"
131
132note ======== objective words: cwob[32 i + w]: 0 kind (1 add, 2 mul, 3 loop),
133note 1 K, 2 N, 3 A, 4 path length, 5 task length, 6 state (0 unread, 1 read,
134note 2 failed, 3 edited, 4 checked, 5 missing), 7 model turns, 8 verified,
135note 9 phase (0 needs a turn, 1 inference, 2 tool, 3 review, 4 finished), 10
136note job in flight, 11 next job seq, 12 result, 13 source length, 14
137note observation length, 15 candidate length, 16 turn budget (7 unless the
138note operator set one), 17 view version of its last change, 18 redirect
139note waiting for the job in flight, 19 operator cancel.
140fn cw_g i ulong w ulong to ulong
141ret get cwob add mul i 32 w
142end
143
144fn cw_s i ulong w ulong v ulong to void
145put cwob add mul i 32 w v
146end
147
148note ======== bytes
149
150fn cw_out o view uchar * n ulong to void
151p = ulong 0
152for it ulong 65536
153if ge p n
154ret
155end
156r = write 1 o p sub n p
157if le r 0
158ret
159end
160p = add p ulong r
161end
162end
163
164note Append a to o at p; past 4096 bytes the result is 5000 (overflow), and
165note an overflowed p stays overflowed.
166fn cw_cat o edit uchar 4096 p ulong a view uchar * to ulong
167if gt add p len a 4096
168ret 5000
169end
170for i ulong len a
171put o add p i get a i
172end
173ret add p len a
174end
175
176fn cw_dec o edit uchar 4096 p ulong v ulong to ulong
177d = new uchar 24 0
178k = ulong 0
179x = v
180for i ulong 24
181put d k uchar add 48 rem x 10
182k = add k 1
183x = div x 10
184if eq x 0
185break
186end
187end
188if gt add p k 4096
189ret 5000
190end
191for j ulong k
192put o add p j get d sub sub k j 1
193end
194ret add p k
195end
196
197fn cw_eq a view uchar * b view uchar * to bool
198if ne len a len b
199ret false
200end
201for i ulong len a
202if ne get a i get b i
203ret false
204end
205end
206ret true
207end
208
209note Occurrences of a in s, without overlap.
210fn cw_count s view uchar * a view uchar * to ulong
211c = ulong 0
212i = ulong 0
213for it ulong add len s 1
214if gt add i len a len s
215ret c
216end
217if cw_eq view part s i len a a
218c = add c 1
219i = add i len a
220else
221i = add i 1
222end
223end
224ret c
225end
226
227note ======== prompt (repair.py prompt and goal)
228
229fn cw_sname o edit uchar 4096 p ulong st ulong to ulong
230if eq st 0
231ret cw_cat o p cwsun
232end
233if eq st 1
234ret cw_cat o p cwsrd
235end
236if eq st 2
237ret cw_cat o p cwsfl
238end
239if eq st 3
240ret cw_cat o p cwsed
241end
242if eq st 4
243ret cw_cat o p cwsck
244end
245ret cw_cat o p cwsms
246end
247
248fn cw_goal o edit uchar 4096 p ulong i ulong to ulong
249if eq cw_g i 0 3
250q = cw_cat o p cwgl1
251q = cw_dec o q cw_g i 1
252q = cw_cat o q cwgl2
253q = cw_dec o q cw_g i 2
254q = cw_cat o q cwgl3
255q = cw_dec o q cw_g i 3
256ret cw_cat o q cwdot
257end
258q = cw_cat o p cwgl4
259if eq cw_g i 0 1
260q = cw_cat o q cwplus
261else
262q = cw_cat o q cwtims
263end
264q = cw_dec o q cw_g i 1
265q = cw_cat o q cwgl5
266q = cw_dec o q cw_g i 3
267ret cw_cat o q cwdot
268end
269
270note Globals are never call arguments, so text kept in them is copied into
271note a local first. sel: 0 path, 1 task, 2 source, 3 observation, 4 edit
272note candidate of objective i; 10 + k config slot k. The length.
273fn cw_ld d edit uchar 4096 sel ulong i ulong to ulong
274if le sel 1
275n = cw_g i add 4 sel
276b = add mul i 512 mul sel 128
277for j ulong n bound 4096
278put d j get cwos add b j
279end
280ret n
281end
282if eq sel 2
283n2 = cw_g i 13
284for j2 ulong n2 bound 4096
285put d j2 get cwsrc add mul i 4096 j2
286end
287ret n2
288end
289if eq sel 3
290n3 = cw_g i 14
291for j3 ulong n3 bound 1024
292put d j3 get cwobs add mul i 1024 j3
293end
294ret n3
295end
296if eq sel 4
297n4 = cw_g i 15
298for j4 ulong n4 bound 4096
299put d j4 get cwcan add mul i 4096 j4
300end
301ret n4
302end
303k = sub sel 10
304n5 = get cwcl k
305for j5 ulong n5 bound 1024
306put d j5 get cwcf add mul k 1024 j5
307end
308ret n5
309end
310
311note Append loaded item sel of objective i to o at p.
312fn cw_catl o edit uchar 4096 p ulong sel ulong i ulong to ulong
313t = new uchar 4096 0
314n = cw_ld t sel i
315ret cw_cat o p view part t 0 n
316end
317
318note The prompt of objective i in its current state; length, 5000 overflow.
319fn cw_prmt o edit uchar 4096 i ulong to ulong
320p = cw_cat o 0 cwtask
321p = cw_catl o p 1 i
322p = cw_cat o p cwfile
323p = cw_catl o p 0 i
324p = cw_cat o p cwgoal
325p = cw_goal o p i
326p = cw_cat o p cwstat
327p = cw_sname o p cw_g i 6
328p = cw_cat o p cwnl
329if gt cw_g i 13 0
330p = cw_cat o p cwsrcl
331p = cw_catl o p 2 i
332end
333if gt cw_g i 14 0
334p = cw_cat o p cwtres
335p = cw_catl o p 3 i
336p = cw_cat o p cwnl
337end
338ret cw_cat o p cwansw
339end
340
341note ======== packed argv (count, then length-prefixed arguments)
342
343fn cw_arg d edit uchar 4096 p ulong a view uchar * to ulong
344if gt add add p 2 len a 4096
345ret 5000
346end
347c = add or ulong get d 0 shl ulong get d 1 8 1
348put d 0 uchar and c 255
349put d 1 uchar shr c 8
350put d p uchar and len a 255
351put d add p 1 uchar shr len a 8
352for i ulong len a
353put d add add p 2 i get a i
354end
355ret add add p 2 len a
356end
357
358note Append loaded item sel of objective i to d as one argument.
359fn cw_argl d edit uchar 4096 p ulong sel ulong i ulong to ulong
360t = new uchar 4096 0
361n = cw_ld t sel i
362ret cw_arg d p view part t 0 n
363end
364
365fn cw_cfg d edit uchar 4096 p ulong k ulong to ulong
366ret cw_argl d p add 10 k 0
367end
368
369fn cw_narg d edit uchar 4096 p ulong v ulong to ulong
370t = new uchar 4096 0
371n = cw_dec t 0 v
372ret cw_arg d p view part t 0 n
373end
374
375note WORK/o<i>, the objective's private compile directory.
376fn cw_wdir t edit uchar 4096 i ulong to ulong
377p = cw_catl t 0 14 0
378p = cw_cat t p cwo
379ret cw_dec t p i
380end
381
382note ======== events
383
384fn cw_ev i ulong id ulong what ulong v ulong to void
385o = new uchar 4096 0
386p = cw_cat o 0 cwee
387p = cw_dec o p i
388p = cw_cat o p cwsp
389p = cw_dec o p id
390p = cw_cat o p cwsp
391p = cw_dec o p what
392p = cw_cat o p cwsp
393p = cw_dec o p v
394p = cw_cat o p cwnl
395cw_out o p
396cw_s i 17 vw_ev 1 i what id v
397end
398
399note A framed transcript record: tag i turn n, newline, the bytes, newline.
400fn cw_rec tag ulong i ulong b view uchar * to void
401o = new uchar 4096 0
402p = ulong 0
403if eq tag 0
404p = cw_cat o 0 cwep
405else
406p = cw_cat o 0 cwer
407end
408p = cw_dec o p i
409p = cw_cat o p cwsp
410p = cw_dec o p cw_g i 7
411p = cw_cat o p cwsp
412p = cw_dec o p len b
413p = cw_cat o p cwnl
414cw_out o p
415cw_out b len b
416cw_out cwnl 1
417end
418
419note Objective i finished with result r (1 PASS, else the failure): RESULT
420note is made durable first. A refusal latches a creator failure and emits no result.
421fn cw_end i ulong r ulong to void
422if ne get cwresultbad 0 0
423ret
424end
425x = jn_result i r cw_g i 7
426if ne x 0
427put cwresultbad 0 x
428ret
429end
430cw_pub i r
431end
432
433note Publish objective i's result r: its CWO line and view event.
434fn cw_pub i ulong r ulong to void
435o = new uchar 4096 0
436cw_s i 12 r
437cw_s i 9 4
438p = cw_cat o 0 cweo
439p = cw_dec o p i
440p = cw_cat o p cwsp
441if eq r 1
442p = cw_cat o p cwpass
443else
444p = cw_cat o p cwfail
445end
446p = cw_cat o p cwsp
447p = cw_dec o p r
448p = cw_cat o p cwsp
449p = cw_dec o p cw_g i 7
450p = cw_cat o p cwnl
451cw_out o p
452cw_s i 17 vw_ev 2 i 0 r cw_g i 7
453end
454
455note ======== creator: issuing jobs
456
457note Admit job kind (1 inference, 2 read, 3 check, 4 replace, 5 review) of
458note objective i with input pk[0, pn), then publish the input on the
459note objective's topic, which makes the job ready. The job id, or 0 when it
460note was not admitted. A refused inference is asked for again at the next
461note step (admission refusals are counted for the view). A refused tool job
462note ends the objective with 23: it cannot be a full queue (a tool job is
463note issued only after its objective's previous job left the queue, so it
464note takes that job's place), and nothing is left waiting unseen.
465fn cw_issue c long i ulong kind ulong pk view uchar 4096 pn ulong to ulong
466if ne get cwresultbad 0 0
467ret 0
468end
469s = cw_g i 11
470if ge s 99
471cw_end i 20
472ret 0
473end
474id = add add mul add i 1 1000 mul s 10 kind
475fl = ulong 1
476if eq kind 4
477fl = 0
478end
479t = shl ulong 1 i
480j = jn_admit id t fl
481if lt j 0
482if eq j neg long 2
483vw_cnt 0 add vw_cget 0 1
484end
485if ne kind 1
486cw_end i 23
487end
488ret 0
489end
490cw_s i 11 add s 1
491v = sched_publish c t pk pn
492if le v 0
493x = auth_cancel c ulong j
494cw_end i 22
495ret 0
496end
497cw_s i 10 id
498put cwt0 i ulong monons
499cw_ev i id 1 kind
500ret id
501end
502
503note Start objective i's next model turn: the prompt as the only input.
504fn cw_turn c long i ulong to void
505pr = new uchar 4096 0
506pk = new uchar 4096 0
507n = cw_prmt pr i
508if gt n 3800
509cw_end i 20
510ret
511end
512p = cw_cfg pk 2 0
513p = cw_cfg pk p 6
514p = cw_arg pk p cwmax
515p = cw_arg pk p cwdl
516p = cw_arg pk p view part pr 0 n
517if gt p 4096
518cw_end i 20
519ret
520end
521id = cw_issue c i 1 pk p
522if gt id 0
523cw_s i 7 add cw_g i 7 1
524cw_s i 9 1
525put cwinf 0 add i 1
526cw_rec 0 i view part pr 0 n
527end
528end
529
530note TOOL verb ROOT PATH into pk; the length.
531fn cw_targ pk edit uchar 4096 i ulong vb ulong to ulong
532p = cw_cfg pk 2 1
533if eq vb 2
534p = cw_arg pk p cwvrd
535end
536if or eq vb 3 eq vb 5
537p = cw_arg pk p cwvck
538end
539if eq vb 4
540p = cw_arg pk p cwvrp
541end
542p = cw_cfg pk p 3
543ret cw_argl pk p 0 i
544end
545
546note A read (2), check (3) or review (5) job for objective i.
547fn cw_tool c long i ulong kind ulong to void
548pk = new uchar 4096 0
549t = new uchar 4096 0
550p = cw_targ pk i kind
551if ne kind 2
552n = cw_wdir t i
553p = cw_arg pk p view part t 0 n
554p = cw_cfg pk p 2
555p = cw_narg pk p cw_g i 0
556p = cw_narg pk p cw_g i 1
557p = cw_narg pk p cw_g i 2
558p = cw_narg pk p cw_g i 3
559end
560id = cw_issue c i kind pk p
561if gt id 0
562cw_s i 9 2
563if eq kind 5
564cw_s i 9 3
565end
566end
567end
568
569note A replace job for objective i: old (h5 bytes at b[o]) and new (h6
570note bytes after it) as the model gave them.
571fn cw_repl c long i ulong b view uchar 4096 o ulong h view ulong 16 to void
572pk = new uchar 4096 0
573p = cw_targ pk i 4
574p = cw_arg pk p view part b o get h 5
575p = cw_arg pk p view part b add o get h 5 get h 6
576id = cw_issue c i 4 pk p
577if gt id 0
578cw_s i 9 2
579end
580end
581
582note ======== creator: records
583
584note Parse k decimal fields of record b after the 6-byte tag into h[0..k);
585note the offset after the header line, or 0 when malformed.
586fn cw_hdr b view uchar 4096 k ulong h edit ulong 16 to ulong
587p = ulong 6
588for f ulong k
589v = ulong 0
590nd = ulong 0
591for it ulong 12
592c = ulong get b p
593if or lt c 48 gt c 57
594break
595end
596v = add mul v 10 sub c 48
597nd = add nd 1
598p = add p 1
599end
600if eq nd 0
601ret 0
602end
603put h f v
604c2 = get b p
605if lt add f 1 k
606if ne c2 32
607ret 0
608end
609else
610if ne c2 10
611ret 0
612end
613end
614p = add p 1
615end
616ret p
617end
618
619fn cw_tag b view uchar 4096 t view uchar * to bool
620for i ulong 6
621if ne get b i get t i
622ret false
623end
624end
625ret true
626end
627
628note Objective i's model record b: the turn's action, checked against the
629note state before anything is granted.
630fn cw_ires c long i ulong b view uchar 4096 to void
631h = new ulong 16 0
632if not cw_tag b cwhi
633cw_end i 18
634ret
635end
636d = cw_hdr b 8 h
637if or eq d 0 gt add add add add d get h 4 get h 5 get h 6 get h 7 3968
638cw_end i 18
639ret
640end
641x = add add add d get h 4 get h 5 get h 6
642cw_rec 1 i view part b x get h 7
643cw_ev i 0 2 get h 0
644cw_act c i b d h
645end
646
647note The policy of repair.py jobs_run for action kind h[0], with path at
648note b[d, d + h4), old after it (h5 bytes), new after that (h6 bytes).
649fn cw_act c long i ulong b view uchar 4096 d ulong h view ulong 16 to void
650u = new uchar 4096 0
651un = cw_ld u 0 i
652k = get h 0
653st = cw_g i 6
654if eq k 4
655if and eq st 4 eq cw_g i 8 1
656cw_tool c i 5
657else
658cw_end i 14
659end
660ret
661end
662if eq k 5
663if eq st 5
664cw_end i 1
665else
666cw_end i 10
667end
668ret
669end
670if or eq k 9 gt k 5
671cw_end i 10
672ret
673end
674if not cw_eq view part b d get h 4 view part u 0 un
675cw_end i 11
676ret
677end
678if and eq k 1 eq st 0
679cw_tool c i 2
680ret
681end
682if and eq k 2 or eq st 1 eq st 3
683cw_tool c i 3
684ret
685end
686if and eq k 3 eq st 2
687cw_edit c i b add d get h 4 h
688ret
689end
690cw_end i 10
691end
692
693note replace_text: the model's old must occur exactly once in the source it
694note was shown and the result must stay in the grammar; the candidate is
695note kept to compare with what the tool saved.
696fn cw_edit c long i ulong b view uchar 4096 o ulong h view ulong 16 to void
697u = new uchar 4096 0
698un = cw_ld u 2 i
699if ne cw_count view part u 0 un view part b o get h 5 1
700cw_end i 13
701ret
702end
703n = cw_cand i b o h
704if gt n 3800
705cw_end i 13
706ret
707end
708cw_repl c i b o h
709end
710
711note The candidate source of objective i into cwcan: its length, or 5000
712note when it is over 3800 bytes or outside the grammar.
713fn cw_cand i ulong b view uchar 4096 o ulong h view ulong 16 to ulong
714t = new uchar 4096 0
715u = new uchar 4096 0
716sn = cw_ld u 2 i
717k = cw_at view part u 0 sn view part b o get h 5
718p = cw_cat t 0 view part u 0 k
719p = cw_cat t p view part b add o get h 5 get h 6
720r = add k get h 5
721p = cw_cat t p view part u r sub sn r
722if gt p 3800
723ret 5000
724end
725if not gr_src t p
726ret 5000
727end
728cw_keep i t p
729ret p
730end
731
732note The first occurrence of a in s (len s when none).
733fn cw_at s view uchar * a view uchar * to ulong
734for k ulong len s
735if le add k len a len s
736if cw_eq view part s k len a a
737ret k
738end
739end
740end
741ret len s
742end
743
744fn cw_keep i ulong t view uchar 4096 n ulong to void
745for j ulong n
746put cwcan add mul i 4096 j get t j
747end
748cw_s i 15 n
749end
750
751note Objective i's tool record b for job kind.
752fn cw_tres c long i ulong kind ulong b view uchar 4096 to void
753h = new ulong 16 0
754if not cw_tag b cwht
755cw_end i 18
756ret
757end
758d = cw_hdr b 3 h
759if or eq d 0 or gt get h 1 1024 gt add add d get h 1 get h 2 3968
760cw_end i 18
761ret
762end
763st = get h 0
764cw_ev i 0 3 st
765if eq kind 2
766cw_read i st b d h
767ret
768end
769if eq kind 4
770cw_saved i st b d h
771ret
772end
773cw_chk i add mul kind 256 st b d h
774end
775
776note A tool record's observation is h1 bytes at b[d], its content the h2
777note bytes after it. cw_same: the content equals loaded item sel.
778fn cw_same i ulong sel ulong b view uchar 4096 d ulong h view ulong 16 to bool
779u = new uchar 4096 0
780un = cw_ld u sel i
781ret cw_eq view part b add d get h 1 get h 2 view part u 0 un
782end
783
784note A check (kind 3) or review (5) record, ks = 256 kind + status: the file
785note checked must be the source the workflow holds.
786fn cw_chk i ulong ks ulong b view uchar 4096 d ulong h view ulong 16 to void
787kind = shr ks 8
788st = and ks 255
789if not cw_same i 2 b d h
790cw_end i 15
791ret
792end
793if eq kind 5
794if eq st 0
795cw_end i 1
796else
797cw_end i 15
798end
799ret
800end
801if eq st 0
802cw_s i 6 4
803cw_s i 8 1
804else
805if ne st 6
806cw_end i 17
807ret
808end
809cw_s i 6 2
810cw_s i 8 0
811end
812cw_seto i view part b d get h 1
813cw_s i 9 0
814end
815
816fn cw_read i ulong st ulong b view uchar 4096 d ulong h view ulong 16 to void
817if eq st 0
818cw_s i 6 1
819cw_setsrc i view part b add d get h 1 get h 2
820cw_seto i view part b d get h 1
821cw_s i 9 0
822ret
823end
824if eq st 1
825cw_s i 6 5
826cw_s i 13 0
827cw_seto i view part b d get h 1
828cw_s i 9 0
829ret
830end
831cw_end i 17
832end
833
834fn cw_saved i ulong st ulong b view uchar 4096 d ulong h view ulong 16 to void
835if eq st 5
836cw_end i 13
837ret
838end
839if ne st 0
840cw_end i 17
841ret
842end
843if not cw_same i 4 b d h
844cw_end i 15
845ret
846end
847cw_s i 6 3
848cw_s i 8 0
849cw_setsrc i view part b add d get h 1 get h 2
850cw_seto i view part b d get h 1
851cw_s i 9 0
852end
853
854fn cw_setsrc i ulong f view uchar * to void
855for j ulong len f
856put cwsrc add mul i 4096 j get f j
857end
858cw_s i 13 len f
859end
860
861fn cw_seto i ulong o view uchar * to void
862for j ulong len o
863put cwobs add mul i 1024 j get o j
864end
865cw_s i 14 len o
866end
867
868note ======== creator: results
869
870note A job of objective i in review: its result bytes are read before it is
871note released and before the next auth_step, so no later job of the same
872note worker (which needs a grant first) can have overwritten them.
873fn cw_done c long j ulong id ulong to void
874b = new uchar 4096 0
875i = sub div id 1000 1
876kind = rem id 10
877if or ge i get cwno 0 ne id cw_g i 10
878ret
879end
880r = sched_result get sjw j b
881o = get sjout j
882cw_s i 10 0
883if eq kind 1
884put cwinf 0 0
885end
886cw_ev i id 4 o
887f = cw_fate o kind
888if eq f 21
889x = vw_ev 7 i 0 id 0
890end
891if cw_oper i
892ret
893end
894if ne f 0
895cw_end i f
896ret
897end
898if eq kind 1
899cw_ires c i b
900ret
901end
902cw_tres c i kind b
903end
904
905note The failure for job outcome word o of a job of kind, 0 when its child
906note ran and exited 0: refused 16 + verdict (cancelled, verdict 6: 19),
907note input lost 90, not performed 1 (cancelled: 19), UNKNOWN 0 or a child
908note killed by a signal (21), a nonzero exit (16 inference, 17 tool).
909fn cw_fate o ulong kind ulong to ulong
910lo = and o 255
911if eq lo 2
912ws = shr o 8
913if ne and ws 127 0
914ret 21
915end
916if eq and shr ws 8 255 0
917ret 0
918end
919if eq kind 1
920ret 16
921end
922ret 17
923end
924if or eq lo 1 eq lo 22
925ret 19
926end
927if eq lo 0
928ret 21
929end
930if eq lo 90
931ret 22
932end
933ret 23
934end
935
936note Collect: every job in review is handled once, then released (again at
937note the next step while its DONE is not yet durable). A job whose worker
938note died mid-job (UNKNOWN) ends its objective; its slot stays UNKNOWN,
939note since only the journal's recovery may settle what may have happened.
940fn cw_coll c long to void
941for j ulong 64
942s = get sjst j
943id = get sjid j
944if and eq s 4 ne get cwgot j id
945put cwgot j id
946cw_done c j id
947end
948if eq s 4
949x = jn_release j
950end
951if and eq s 6 ne get cwgot j id
952put cwgot j id
953cw_lost id
954end
955end
956end
957
958fn cw_lost id ulong to void
959i = sub div id 1000 1
960if and lt i get cwno 0 eq id cw_g i 10
961cw_s i 10 0
962if eq rem id 10 1
963put cwinf 0 0
964end
965x = vw_ev 7 i 0 id 0
966if not cw_oper i
967cw_end i 21
968end
969end
970end
971
972note After objective i's job in flight finished or was lost: an operator
973note cancel ends it (19); a redirect waiting for the job takes effect. True
974note when one of them applied.
975fn cw_oper i ulong to bool
976if ne cw_g i 19 0
977cw_end i 19
978ret true
979end
980if ne cw_g i 18 0
981cw_redo i
982ret true
983end
984ret false
985end
986
987note Objective i starts over from unread with its new goal (a redirect):
988note turns, budget and job ids continue.
989fn cw_redo i ulong to void
990cw_s i 18 0
991cw_s i 6 0
992cw_s i 8 0
993cw_s i 9 0
994cw_s i 13 0
995cw_s i 14 0
996cw_s i 15 0
997end
998
999note ======== creator: planning
1000
1001note Start a turn for one objective that needs one (one inference in flight
1002note at a time); the test hook cwtk cancels an inference after ms. An
1003note objective out of its turn budget ends with 12.
1004fn cw_plan c long to void
1005cw_hook c
1006if gt get cwinf 0 0
1007ret
1008end
1009for i ulong get cwno 0 bound 4
1010if and eq cw_g i 9 0 eq cw_g i 12 0
1011if ge cw_g i 7 cw_g i 16
1012cw_end i 12
1013else
1014cw_turn c i
1015ret
1016end
1017end
1018end
1019end
1020
1021fn cw_hook c long to void
1022if ne get cwtu 0 0
1023cw_hooku
1024end
1025k = get cwtk 0
1026if eq k 0
1027ret
1028end
1029i = sub k 1
1030if or ne cw_g i 9 1 eq cw_g i 10 0
1031ret
1032end
1033if lt sub ulong monons get cwt0 i mul get cwtk 1 1000000
1034ret
1035end
1036for j ulong 64
1037if and eq get sjid j cw_g i 10 eq get sjst j 3
1038x = auth_cancel c j
1039if ge x 0
1040cw_ev i cw_g i 10 5 ulong x
1041put cwtk 0 0
1042end
1043end
1044end
1045end
1046
1047note Test hook cwtu: SIGKILL the worker of the first replace, once, after its
1048note START is durable; whether the edit happened is then unknown to the
1049note creator and to the journal. A job is assigned (state 3) before its
1050note worker's proposal is decided and START journaled, so state 3 alone
1051note could kill a worker whose job holds ADMIT only (DRA-292, job 1054).
1052fn cw_hooku to void
1053for j ulong 64
1054if and and eq get sjst j 3 eq rem get sjid j 10 4 jn_started get sjid j
1055x = killpid int get swpid get sjw j 9
1056put cwtu 0 0
1057ret
1058end
1059end
1060end
1061
1062fn cw_left to ulong
1063n = ulong 0
1064for i ulong get cwno 0 bound 4
1065if eq cw_g i 12 0
1066n = add n 1
1067end
1068end
1069ret n
1070end
1071
1072note Creator loop until every objective finished or dl ns pass: 0 or 62.
1073fn cw_drive c long dl ulong to int
1074for t ulong 1000000000
1075r = sched_step c 5000000
1076cw_coll c
1077if ne get cwresultbad 0 0
1078ret 58
1079end
1080k = auth_step c
1081cw_cmd c
1082if ne get cwresultbad 0 0
1083ret 58
1084end
1085cw_plan c
1086if ne get cwresultbad 0 0
1087ret 58
1088end
1089cw_vsnap c
1090if eq cw_left 0
1091ret 0
1092end
1093if ge ulong monons dl
1094ret 62
1095end
1096end
1097ret 62
1098end
1099
1100note ======== creator: operator view and commands (DRA-291, seed/node/view.om)
1101
1102note The snapshot: generic sections, then the objectives and the limits.
1103fn cw_vsnap c long to void
1104vw_begin
1105vw_gen c
1106vw_s 21 get cwpv 0
1107vw_s 128 get cwno 0
1108for i ulong get cwno 0 bound 4
1109o = add 136 mul i 16
1110for w ulong 14
1111vw_s add o w cw_g i sub ulong get cwvw w 48
1112end
1113end
1114vw_s 200 7
1115vw_s 201 900
1116vw_s 202 160
1117vw_s 203 CWOBJ
1118vw_s 204 64
1119vw_s 205 256
1120vw_end
1121end
1122
1123note One posted command: a committed id is acknowledged again as a
1124note duplicate; otherwise it is checked against the state the operator saw
1125note (stale, invalid), committed (OPER durable, then acted on), and
1126note acknowledged.
1127fn cw_cmd c long to void
1128d = new ulong 8 0
1129if not vw_take d
1130ret
1131end
1132k = jn_ofind get d 0
1133if ge k 0
1134vw_ack 4 jn_opw ulong k 7 get jseq 0
1135ret
1136end
1137st = cw_cchk d
1138if eq st 0
1139st = cw_exec c d
1140end
1141if eq st 0
1142vw_cnt 1 add vw_cget 1 1
1143vw_cnt 3 get d 0
1144vw_ack 0 jn_opw ulong jn_ofind get d 0 7 get jseq 0
1145ret
1146end
1147vw_cnt 2 add vw_cget 2 1
1148vw_ack st vw_ver get jseq 0
1149end
1150
1151note 0 when command d (id, op, target, version, a..d) may run now; 1 stale
1152note (what it targets changed after the version the operator saw, or the
1153note version is not of this incarnation), 2 invalid.
1154fn cw_cchk d view ulong 8 to ulong
1155op = get d 1
1156t = get d 2
1157if eq get d 3 not ulong 0
1158ret 2
1159end
1160if gt get d 3 vw_ver
1161ret 1
1162end
1163if or eq op 1 eq op 2
1164if gt get cwpv 0 get d 3
1165ret 1
1166end
1167if eq get scpause 0 sub 2 op
1168ret 2
1169end
1170ret 0
1171end
1172if or or lt op 3 gt op 5 ge t get cwno 0
1173ret 2
1174end
1175if gt cw_g t 17 get d 3
1176ret 1
1177end
1178if eq cw_g t 9 4
1179ret 2
1180end
1181if and eq op 4 gt get d 4 7
1182ret 2
1183end
1184if eq op 5
1185ret cw_rchk d
1186end
1187ret 0
1188end
1189
1190fn cw_rchk d view ulong 8 to ulong
1191if or lt get d 4 1 gt get d 4 3
1192ret 2
1193end
1194for m ulong 3
1195if gt get d add 5 m 99
1196ret 2
1197end
1198end
1199ret 0
1200end
1201
1202note Commit command d: pause and resume go through auth_pause (which
1203note journals PAUSE) and are then recorded; objective commands are recorded
1204note (OPER durable) and then applied. 0, or 3 refused.
1205fn cw_exec c long d view ulong 8 to ulong
1206a = new ulong 4 0
1207for m ulong 4
1208put a m get d add 4 m
1209end
1210op = get d 1
1211v = add vw_ver 1
1212if le op 2
1213x = auth_pause c eq op 1
1214if ne get jbad 0 0
1215ret 3
1216end
1217end
1218if ne jn_oper get d 0 op get d 2 a v 0
1219ret 3
1220end
1221x = vw_ev 3 get d 2 op get d 0 0
1222if le op 2
1223put cwpv 0 vw_ev 4 0 0 sub 2 op 0
1224ret 0
1225end
1226cw_apply c get d 2 op a
1227ret 0
1228end
1229
1230note Apply objective command op to objective i (also when the journal is
1231note replayed at a restart, when nothing is in flight).
1232fn cw_apply c long i ulong op ulong a view ulong 4 to void
1233if eq op 4
1234cw_s i 16 get a 0
1235cw_s i 17 vw_ver
1236ret
1237end
1238if eq op 5
1239for m ulong 4
1240cw_s i m get a m
1241end
1242end
1243if eq cw_g i 10 0
1244if eq op 3
1245cw_end i 19
1246else
1247cw_redo i
1248end
1249cw_s i 17 vw_ver
1250ret
1251end
1252if eq op 3
1253cw_s i 19 1
1254else
1255cw_s i 18 1
1256end
1257cw_s i 17 vw_ver
1258cw_stop c cw_g i 10
1259end
1260
1261note Cancel job id through the authority wherever it is (waiting, ready or
1262note running); its result then reaches cw_oper.
1263fn cw_stop c long id ulong to void
1264for j ulong 64
1265s = get sjst j
1266if and eq get sjid j id and ge s 1 le s 3
1267x = auth_cancel c j
1268end
1269end
1270end
1271
1272note At a restart: the committed operator commands again, in order.
1273fn cw_replay c long to void
1274a = new ulong 4 0
1275for k ulong jn_nops bound 128
1276for m ulong 4
1277put a m jn_opw k add 3 m
1278end
1279op = jn_opw k 1
1280i = jn_opw k 2
1281if and ge op 3 lt i get cwno 0
1282if ne cw_g i 9 4
1283cw_apply c i op a
1284end
1285end
1286vw_cnt 1 add vw_cget 1 1
1287vw_cnt 3 jn_opw k 0
1288end
1289end
1290
1291note ======== worker
1292
1293note Worker w: the input of its job (objective i): the newest version on the
1294note objective's topic that is not newer than the assignment's version.
1295fn cw_input c long w ulong i ulong dst edit uchar 4096 to long
1296v = sc_cell w 24
1297t = shl ulong 1 i
1298h = pool_hold c w sc_cell w 16
1299if le h 0
1300ret neg long 1
1301end
1302cur = ulong 0
1303last = ulong 0
1304for k ulong 65
1305x = node_next h cur t
1306if le x 0
1307break
1308end
1309if gt ulong x v
1310break
1311end
1312last = ulong x
1313cur = last
1314end
1315n = neg long 1
1316if gt last 0
1317n = node_read h last dst
1318end
1319r = pool_release c w
1320ret n
1321end
1322
1323note Worker w, assignment q: propose, wait for the decision, run the child
1324note when granted, report. Outcome word: the authority's outcome (0 UNKNOWN,
1325note 1 not performed, 2 performed) plus the wait status shifted by 8; 16 +
1326note verdict when refused; 90 when the input was not found.
1327fn cw_job c long w ulong q ulong to void
1328pk = new uchar 4096 0
1329op = new ulong 4 0
1330id = sc_cell w 8
1331n = cw_input c w sub div id 1000 1 pk
1332if le n 0
1333r = sched_wdone w q 90 pk 0
1334ret
1335end
1336put op 0 id
1337put op 1 rem id 10
1338put op 2 div id 1000
1339put op 3 1
1340r = auth_propose w q op cw_class id
1341v = auth_wdecide c w q 30000000000
1342if ne v 0
1343r = sched_wdone w q add 16 ulong v pk 0
1344ret
1345end
1346cw_wrun c w q pk ulong n
1347end
1348
1349note Replace changes the workspace (class 1); the others are rerunnable.
1350fn cw_class id ulong to ulong
1351if eq rem id 10 4
1352ret 1
1353end
1354ret 2
1355end
1356
1357fn cw_wrun c long w ulong q ulong pk view uchar 4096 n ulong to void
1358ob = new uchar 4096 0
1359o = auth_wtool c w q pk n cw_class sc_cell w 8
1360r = auth_wreport w q ulong o
1361m = auth_wout w ob
1362x = or ulong o shl auth_cell w 96 8
1363r = sched_wdone w q x ob m
1364end
1365
1366fn cw_worker c long w ulong to int
1367for it ulong 1000000000
1368q = sched_wjob w
1369if gt q 0
1370cw_job c w q
1371end
1372r = auth_wwait c w neg int 1 1000000000
1373if or eq r 2 eq r 3
1374ret 0
1375end
1376if eq r 4
1377t = auth_wctl w
1378end
1379if lt r 0
1380ret 45
1381end
1382end
1383ret 46
1384end
1385
1386note ======== setup
1387
1388note Objective argument "KIND,K,N,A,PATH,TASK" (KIND add, mul or loop) into
1389note slot i. false when malformed.
1390fn cw_parse i ulong a view uchar * to bool
1391f = new ulong 8 0
1392cw_s i 16 7
1393k = ulong 0
1394for j ulong len a
1395if and lt k 5 eq get a j 44
1396put f k j
1397k = add k 1
1398end
1399end
1400if ne k 5
1401ret false
1402end
1403if cw_eq view part a 0 get f 0 cwadd
1404cw_s i 0 1
1405end
1406if cw_eq view part a 0 get f 0 cwmul
1407cw_s i 0 2
1408end
1409if cw_eq view part a 0 get f 0 cwloop
1410cw_s i 0 3
1411end
1412if eq cw_g i 0 0
1413ret false
1414end
1415for m ulong 3
1416v = cw_pnum a add get f m 1 get f add m 1
1417if gt v 99
1418ret false
1419end
1420cw_s i add m 1 v
1421end
1422ret cw_ptxt i a f
1423end
1424
1425fn cw_pnum a view uchar * s ulong e ulong to ulong
1426if or ge s e gt sub e s 2
1427ret 999
1428end
1429v = ulong 0
1430for j ulong sub e s
1431c = ulong get a add s j
1432if or lt c 48 gt c 57
1433ret 999
1434end
1435v = add mul v 10 sub c 48
1436end
1437ret v
1438end
1439
1440note PATH and TASK of the objective argument a (field ends in f).
1441fn cw_ptxt i ulong a view uchar * f view ulong 8 to bool
1442ps = add get f 3 1
1443pn = sub get f 4 ps
1444ts = add get f 4 1
1445tn = sub len a ts
1446if or or eq pn 0 gt pn 128 or eq tn 0 gt tn 383
1447ret false
1448end
1449cw_put add mul i 512 0 view part a ps pn
1450cw_put add mul i 512 128 view part a ts tn
1451cw_s i 4 pn
1452cw_s i 5 tn
1453ret true
1454end
1455
1456fn cw_put o ulong a view uchar * to void
1457for j ulong len a
1458put cwos add o j get a j
1459end
1460end
1461
1462note Argument ai into config slot k; false when empty or over 1000 bytes.
1463fn cw_carg ai ulong k ulong to bool
1464n = argread ai cwcf mul k 1024 1000
1465if lt n 1
1466ret false
1467end
1468put cwcl k ulong n
1469ret true
1470end
1471
1472note Next job seq and performed model turns of objective i from the journal.
1473fn cw_resume i ulong to void
1474s = ulong 0
1475t = ulong 0
1476for q ulong 99
1477for kd ulong 5
1478id = add add mul add i 1 1000 mul q 10 add kd 1
1479if jn_known id
1480s = add q 1
1481if and eq kd 0 eq and jn_jout id 255 2
1482t = add t 1
1483end
1484end
1485end
1486end
1487cw_s i 11 s
1488cw_s i 7 t
1489end
1490
1491note FNV-1a 64 of the objective arguments, for the journal's identity.
1492fn cw_ident a0 ulong n ulong to ulong
1493b = new uchar 1024 0
1494x = ulong 14695981039346656037
1495for i ulong n
1496m = argread add a0 i b 0 1024
1497for j ulong ulong m
1498x = mul xor x ulong get b j 1099511628211
1499end
1500x = mul xor x 255 1099511628211
1501end
1502ret x
1503end
1504
1505note The journal's objective: tag 0x4f4d4e43 ("OMNC"), the objective count,
1506note the hash of the objective arguments, the issue number. A JDIR over 100
1507note bytes is jn_open's refusal 26 here, before the 128-byte copy (a JDIR of
1508note 129..1000 bytes used to trap 4 in that loop, exit 104 with no cause line).
1509fn cw_jopen ai ulong n ulong to ulong
1510if gt get cwcl 5 100
1511ret 26
1512end
1513d = new uchar 128 0
1514o = new ulong 4 0
1515for j ulong get cwcl 5 bound 128
1516put d j get cwcf add 5120 j
1517end
1518put o 0 1330466371
1519put o 1 n
1520put o 2 cw_ident ai n
1521put o 3 290
1522ret jn_open d get cwcl 5 o 3000
1523end
1524
1525note Make WORK/o<i> for every objective (an existing one is reused).
1526fn cw_dirs to void
1527t = new uchar 4096 0
1528for i ulong get cwno 0 bound 4
1529n = cw_wdir t i
1530x = makedir t 0 n 448
1531end
1532end
1533
1534note omnode-code INFER TOOL OMC ROOT WORK JDIR PORT VIEW OBJ... from
1535note argument k on (1..4 objectives; all paths absolute; VIEW the operator
1536note view's port on 127.0.0.1, 0 for none). Exit 0 all passed, 1 some
1537note failed, 2 usage, 62 out of time, 30 + journal or recovery refusal,
1538note 50.. setup, 57 also a job left waiting or ready by the last creator
1539note that could not be cancelled; the refusals, setup failures and 57 first
1540note write a cause line (cw_fail).
1541fn cw_main k ulong dls ulong to int
1542b = new uchar 1024 0
1543c = ulong argcnt
1544if or lt c add k 9 gt c add k 12
1545ret 2
1546end
1547for a ulong 8
1548if not cw_carg add k a a
1549ret 2
1550end
1551end
1552if gt cw_cnum 7 65535
1553ret 2
1554end
1555put cwno 0 sub c add k 8
1556for i ulong get cwno 0 bound 4
1557m = argread add add k 8 i b 0 1024
1558if lt m 1
1559ret 2
1560end
1561if not cw_parse i view part b 0 ulong m
1562ret 2
1563end
1564end
1565ret cw_run k dls
1566end
1567
1568note Config slot k as a decimal of 1..5 digits; 99999999 otherwise.
1569fn cw_cnum k ulong to ulong
1570n = get cwcl k
1571if or eq n 0 gt n 5
1572ret 99999999
1573end
1574v = ulong 0
1575for j ulong n
1576d = ulong get cwcf add mul k 1024 j
1577if or lt d 48 gt d 57
1578ret 99999999
1579end
1580v = add mul v 10 sub d 48
1581end
1582ret v
1583end
1584
1585note cw_fail r what: "code-main: WHAT, exit R" on stderr, then R. Journal refusals (30 + 20..27)
1586note share numbers with the setup failures 50..56, so the line names which one it was.
1587fn cw_fail r ulong what view uchar * to int
1588o = new uchar 4096 0
1589p = cw_cat o 0 cwfpre
1590p = cw_cat o p what
1591p = cw_cat o p cwfex
1592p = cw_dec o p r
1593p = cw_cat o p cwnl
1594x = write 2 o 0 p
1595ret int r
1596end
1597
1598fn cw_run k ulong dls ulong to int
1599c = pool_new 4 2
1600if le c 0
1601ret cw_fail 50 cwfpool
1602end
1603if ne sup_init c 0
1604ret cw_fail 51 cwfsup
1605end
1606ql = get cwql 0
1607if eq ql 0
1608ql = 8
1609end
1610if ne sched_new c ql 8 0
1611ret cw_fail 52 cwfsch
1612end
1613if ne auth_new c 0
1614ret cw_fail 53 cwfaut
1615end
1616e = cw_jopen add k 8 get cwno 0
1617if ne e 0
1618ret cw_fail add 30 e cwfjrn
1619end
1620e = auth_recover c
1621if ne e 0
1622ret cw_fail add 30 e cwfrec
1623end
1624for j ulong 64
1625s = get sjst j
1626if or eq s 1 eq s 2
1627if lt auth_cancel c j 0
1628ret cw_fail 57 cwfcan
1629end
1630end
1631end
1632if ne vw_new jn_fence 0
1633ret cw_fail 55 cwfvwn
1634end
1635for i ulong get cwno 0 bound 4
1636cw_resume i
1637if ne jn_res i 0
1638cw_s i 7 jn_rturn i
1639cw_pub i jn_res i
1640end
1641end
1642cw_replay c
1643if ne get cwresultbad 0 0
1644sup_closeall
1645jn_close
1646ret cw_fail 58 cwfresult
1647end
1648cw_dirs
1649for w ulong 2
1650p = auth_spawn c w
1651if eq p 0
1652exit cw_worker c w
1653end
1654if le p 0
1655ret cw_fail 54 cwfspn
1656end
1657end
1658if not cw_view c
1659ret cw_fail 56 cwfvw
1660end
1661r = cw_drive c add ulong monons mul dls 1000000000
1662vw_stop
1663x = sched_stop c 2000000000
1664sup_closeall
1665jn_close
1666if eq r 58
1667ret cw_fail 58 cwfresult
1668end
1669ret cw_sum r
1670end
1671
1672note Start the view process when VIEW is not 0 and print CWV port once it
1673note listens; false when it could not.
1674fn cw_view c long to bool
1675o = new uchar 4096 0
1676pt = cw_cnum 7
1677if eq pt 0
1678ret true
1679end
1680cw_vsnap c
1681if le vw_spawn pt 0
1682ret false
1683end
1684for t ulong 3000
1685if ne vw_g 7 0
1686p = cw_cat o 0 cwcwv
1687p = cw_dec o p vw_g 7
1688p = cw_cat o p cwnl
1689cw_out o p
1690ret true
1691end
1692x = sleepns 1000000
1693end
1694vw_stop
1695ret false
1696end
1697
1698fn cw_sum r int to int
1699o = new uchar 4096 0
1700np = ulong 0
1701for i ulong get cwno 0 bound 4
1702if eq cw_g i 12 1
1703np = add np 1
1704end
1705end
1706p = cw_cat o 0 cwsum
1707p = cw_dec o p np
1708p = cw_cat o p cwsumf
1709p = cw_dec o p sub get cwno 0 np
1710p = cw_cat o p cwnl
1711cw_out o p
1712if ne r 0
1713ret r
1714end
1715if eq np get cwno 0
1716ret 0
1717end
1718ret 1
1719end