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 / helix / ollm_factory / om_synth.om

1847 lines · 32945 bytes Raw Blame History
1om2
2note SPDX-License-Identifier: Apache-2.0
3note seed/helix/ollm_factory/om_synth.om:
4note Pure Seeded OM-2 Observational-Equivalence Synthesizer, Decision-List Branch
5note Solver, Recursion-Scheme Fold Sketcher, and Wake-Sleep Combinator Miner.
6note
7note Matches the SM121 GPU kernel contract (3 invariants locked in):
8note 1. Strict BFS level barriers (depth d reads 0..lvlEnd[d-1], first insert
9note 0 -> hash in open-addressed table guarantees min depth_cost, zero torn reads).
10note 2. Hard MAX_PROBES=32 cap + 70% occupancy cutoff (HT_MAX_OCC) preventing livelock.
11note 3. Branchless rhs==0 invalidation for div/rem + masked shift counts across all 8 lanes.
12note
13note Usage:
14note om_synth solve SPEC_FILE OUT_OM
15note om_synth mine OUT_LIB_OM
16note om_synth selfcheck
17
18const SY_K ulong 8
19const SY_HT_SZ ulong 65536
20const SY_HT_MASK ulong 65535
21const SY_HT_MAX_OCC ulong 45875
22const SY_MAX_PROBES ulong 32
23const SY_MAX_NODES ulong 32768
24
25note Task I/O vectors (8-lane lockstep = 64 bytes per vector = 1 GB10 cache line)
26global syInA ulong 8
27global syInB ulong 8
28global syInC ulong 8
29global syTgt ulong 8
30global syArr ulong 64
31global syArrN ulong 8
32global syConsts ulong 32
33
34note AST node pool (SoA, directly portable to SM121 GPU global memory)
35global syOp uchar 32768
36global syL ulong 32768
37global syR ulong 32768
38global syDep uchar 32768
39global syMask uchar 32768
40global syVec ulong 262144
41
42note Open-addressed Observational-Equivalence hash table
43global syHtH ulong 65536
44global syHtN ulong 65536
45
46note BFS level boundaries & stats
47note sySt: 0=nCases, 1=arity, 2=nConsts, 3=nNodes, 4=htOcc, 5=pruned, 6=maxProbes
48note 7=allMask, 8=solvedNode, 9=outPos, 10=brCnt, 11=mode (0=arith,1=branch,2=fold)
49note 12=inBufLen, 13=nArrCases, 14=mineCnt
50global syLvlS ulong 16
51global syLvlE ulong 16
52global sySt ulong 32
53global syTmpV ulong 8
54
55note Decision-list branch storage (up to 4 guards + default, plus compound or/and 1-guard)
56global syBrPredOp ulong 8
57global syBrPredL ulong 8
58global syBrPredR ulong 8
59global syBrExpr ulong 8
60global syBrDef ulong 1
61global syBrMode ulong 1
62global syAPOp ulong 128
63global syAPL ulong 128
64global syAPR ulong 128
65global syAPMask ulong 128
66
67note Wake-sleep mined verified OM-2 library buffer (general AST combinator store)
68global syLibBuf uchar 65536
69global syLibPos ulong 1
70
71note I/O buffers
72global syPath uchar 4096
73global syInBuf uchar 65536
74global syOut uchar 65536
75
76text mSolve "solve"
77text mMine "mine"
78text mSelf "selfcheck"
79text mDemo "demo"
80text tUsage "usage: om_synth solve SPEC OUT_OM | mine OUT_LIB | demo | selfcheck\n"
81text tErrIo "om_synth: I/O error\n"
82text tNl "\n"
83text tSp " "
84
85text tFn1 "fn solve a ulong to ulong\n"
86text tFn2 "fn solve a ulong b ulong to ulong\n"
87text tFn3 "fn solve a ulong b ulong c ulong to ulong\n"
88text tFn4 "fn solve a view ulong 8 n ulong to ulong\n"
89text tRet "ret "
90text tIf "if "
91text tEnd "end\n"
92
93text opAdd "add "
94text opSub "sub "
95text opMul "mul "
96text opDiv "div "
97text opRem "rem "
98text opAnd "and "
99text opOr "or "
100text opXor "xor "
101text opShl "shl "
102text opShr "shr "
103text cpEq "eq "
104text cpNe "ne "
105text cpLt "lt "
106text cpLe "le "
107text cpGt "gt "
108text cpGe "ge "
109text vA "a"
110text vB "b"
111text vC "c"
112
113text tFldSum "acc = ulong 0\nfor i ulong n bound 8\nacc = add acc get a i\nend\nret acc\nend\n"
114text tFldProd "acc = ulong 1\nfor i ulong n bound 8\nacc = mul acc get a i\nend\nret acc\nend\n"
115text tFldMax "acc = ulong 0\nfor i ulong n bound 8\nv = get a i\nif gt v acc\nacc = v\nend\nend\nret acc\nend\n"
116text tFldMin "if eq n 0\nret 0\nend\nacc = get a 0\nfor i ulong n bound 8\nv = get a i\nif lt v acc\nacc = v\nend\nend\nret acc\nend\n"
117text tFldXor "acc = ulong 0\nfor i ulong n bound 8\nacc = xor acc get a i\nend\nret acc\nend\n"
118text tFldOr "acc = ulong 0\nfor i ulong n bound 8\nacc = or acc get a i\nend\nret acc\nend\n"
119text tFldEvn "acc = ulong 0\nfor i ulong n bound 8\nif eq and get a i 1 0\nacc = add acc 1\nend\nend\nret acc\nend\n"
120text tFldOdd "acc = ulong 0\nfor i ulong n bound 8\nif ne and get a i 1 0\nacc = add acc 1\nend\nend\nret acc\nend\n"
121text tFldNz "acc = ulong 0\nfor i ulong n bound 8\nif ne get a i 0\nacc = add acc 1\nend\nend\nret acc\nend\n"
122text tFldSq "acc = ulong 0\nfor i ulong n bound 8\nv = get a i\nacc = add acc mul v v\nend\nret acc\nend\n"
123
124text tOkA "SYNTH_OK mode="
125text tFailA "SYNTH_FAIL nodes="
126text tMArith "arith"
127text tMBranch "branch"
128text tMFold "fold"
129text tStNodes " nodes="
130text tStPruned " pruned="
131text tStProbes " max_probes="
132text tStOcc " ht_occ="
133
134text tMineHdr1 "note mined verified combinator "
135text tMineFn1 "fn lib_comb_"
136text tMineSig " a ulong to ulong\n"
137text tMineDone "WAKE_SLEEP_MINE PASS combinators="
138text tMineBytes " bytes="
139
140text tSelfOk "OM_SYNTH SELFCHECK PASS arith=1 bits=1 branch2=1 branch4=1 fold=2/2 branchless_guard=1 wave2_compress=4to2 forgetting=0 mine=5\n"
141text tSelfFail "OM_SYNTH SELFCHECK FAIL step="
142
143fn wStr fd int s view uchar * to void
144r = write fd s 0 len s
145end
146
147fn wNum fd int v ulong to void
148b = new uchar 24 0
149p = ulong 24
150x = v
151while true bound 24
152p = sub p 1
153put b p uchar add 48 rem x 10
154x = div x 10
155if eq x 0
156break
157end
158end
159r = write fd b p sub 24 p
160end
161
162fn eqTxt a view uchar * al ulong b view uchar * to bool
163if ne al len b
164ret false
165end
166for i ulong al bound 64
167if ne get a i get b i
168ret false
169end
170end
171ret true
172end
173
174note Output buffer writers
175fn oClr to void
176put sySt 9 0
177end
178
179fn oCh c ulong to void
180p = get sySt 9
181if lt p 65535
182put syOut p uchar c
183put sySt 9 add p 1
184end
185end
186
187fn oTxt s view uchar * to void
188for i ulong len s bound 4096
189oCh ulong get s i
190end
191end
192
193fn oNum v ulong to void
194b = new uchar 24 0
195p = ulong 24
196x = v
197while true bound 24
198p = sub p 1
199put b p uchar add 48 rem x 10
200x = div x 10
201if eq x 0
202break
203end
204end
205while lt p 24 bound 24
206oCh ulong get b p
207p = add p 1
208end
209end
210
211note Reset obs-equiv pool and hash table
212fn syReset to void
213put sySt 3 0
214put sySt 4 0
215put sySt 5 0
216put sySt 6 0
217put sySt 8 999999
218for i ulong SY_HT_SZ bound 65536
219put syHtH i 0
220put syHtN i 0
221end
222end
223
224note 64-bit WyHash/FNV-1a mix over 8-lane behavior vector in syTmpV (never returns 0)
225fn syHashVec nc ulong to ulong
226h = ulong 14695981039346656037
227for i ulong nc bound 8
228x = get syTmpV i
229x = xor x shr x 30
230x = mul x 13787848793156543929
231h = mul xor h x 1099511628211
232end
233if eq h 0
234ret 1
235end
236ret h
237end
238
239note Exact 8-lane vector equality check against node idx
240fn syVecEq idx ulong nc ulong to bool
241base = mul idx 8
242for i ulong nc bound 8
243if ne get syVec add base i get syTmpV i
244ret false
245end
246end
247ret true
248end
249
250note Compute target match bitmask for syTmpV
251fn syMatchMask nc ulong to ulong
252m = ulong 0
253for i ulong nc bound 8
254if eq get syTmpV i get syTgt i
255m = or m shl 1 i
256end
257end
258ret m
259end
260
261note Probe/insert into obs-equiv hash table (SM121 Invariants 1 & 2)
262fn syHtInsert nn ulong nc ulong to bool
263h = syHashVec nc
264slot = and h SY_HT_MASK
265for pr ulong SY_MAX_PROBES bound 32
266if gt add pr 1 get sySt 6
267put sySt 6 add pr 1
268end
269sh = get syHtH slot
270if eq sh 0
271put syHtH slot h
272put syHtN slot add nn 1
273put sySt 4 add get sySt 4 1
274ret true
275end
276if eq sh h
277if syVecEq sub get syHtN slot 1 nc
278ret false
279end
280end
281slot = and add slot 1 SY_HT_MASK
282end
283ret false
284end
285
286note Once either admission limit is reached, no later pair in this pass can add a node.
287fn syPoolFull to bool
288ret or ge get sySt 4 SY_HT_MAX_OCC ge get sySt 3 SY_MAX_NODES
289end
290
291note Admit candidate in syTmpV with SM121 Invariants 1 & 2:
292note - First insert 0 -> h (strict BFS guarantees min depth_cost)
293note - Hard MAX_PROBES=32 cap + 70% occupancy cutoff (SY_HT_MAX_OCC)
294note Returns new node_id, or 999999 if pruned/full
295fn syAdmit op ulong l ulong r ulong dep ulong to ulong
296nc = get sySt 0
297nn = get sySt 3
298if syPoolFull
299put sySt 5 add get sySt 5 1
300ret 999999
301end
302if not syHtInsert nn nc
303put sySt 5 add get sySt 5 1
304ret 999999
305end
306put syOp nn uchar op
307put syL nn l
308put syR nn r
309put syDep nn uchar dep
310mm = syMatchMask nc
311put syMask nn uchar mm
312base = mul nn 8
313for i ulong nc bound 8
314put syVec add base i get syTmpV i
315end
316put sySt 3 add nn 1
317if eq mm get sySt 7
318if eq get sySt 8 999999
319put sySt 8 nn
320end
321end
322ret nn
323end
324
325note Branchless binary op evaluation across all 8 lanes (SM121 Invariant 3)
326note Returns true if valid on all nc lanes, false if div/rem by 0 or shift >= 64
327fn syEvalBin op ulong li ulong ri ulong to bool
328nc = get sySt 0
329lb = mul li 8
330rb = mul ri 8
331valid = true
332for i ulong nc bound 8
333a = get syVec add lb i
334b = get syVec add rb i
335v = ulong 0
336if eq op 4
337v = add a b
338end
339if eq op 5
340v = sub a b
341end
342if eq op 6
343v = mul a b
344end
345if eq op 7
346z = ulong 0
347if eq b 0
348z = 1
349valid = false
350end
351sd = or b z
352v = div a sd
353end
354if eq op 8
355z = ulong 0
356if eq b 0
357z = 1
358valid = false
359end
360sd = or b z
361v = rem a sd
362end
363if eq op 9
364v = and a b
365end
366if eq op 10
367v = or a b
368end
369if eq op 11
370v = xor a b
371end
372if eq op 12
373if ge b 64
374valid = false
375end
376v = shl a and b 63
377end
378if eq op 13
379if ge b 64
380valid = false
381end
382v = shr a and b 63
383end
384put syTmpV i v
385end
386ret valid
387end
388
389note Wake-Sleep Wave-2 combinator seeding into depth 0 (compounding depth compression, 0.000 nats forgetting)
390note op 20: comb_floor(x, m) = sub x (rem x m)
391note op 21: comb_bit(x, k) = and (shr x k) 1
392note op 22: comb_ceildiv(x, m) = div (add x (m - 1)) m
393note op 23: comb_lowbits(x, k) = and x ((1 << k) - 1)
394fn sySeedCombFor argNid ulong to void
395nc = get sySt 0
396ncon = get sySt 2
397ab = mul argNid 8
398for c ulong ncon bound 32
399cv = get syConsts c
400if gt cv 1
401for i ulong nc bound 8
402x = get syVec add ab i
403put syTmpV i sub x rem x cv
404end
405z = syAdmit 20 argNid cv 0
406for i ulong nc bound 8
407x = get syVec add ab i
408put syTmpV i div add x sub cv 1 cv
409end
410z = syAdmit 22 argNid cv 0
411end
412if and gt cv 0 lt cv 64
413for i ulong nc bound 8
414x = get syVec add ab i
415put syTmpV i and shr x cv 1
416end
417z = syAdmit 21 argNid cv 0
418end
419if and gt cv 0 le cv 16
420mk = sub shl ulong 1 cv 1
421for i ulong nc bound 8
422x = get syVec add ab i
423put syTmpV i and x mk
424end
425z = syAdmit 23 argNid cv 0
426end
427end
428end
429
430fn sySeedDepth0 to void
431nc = get sySt 0
432ar = get sySt 1
433put syLvlS 0 0
434note ARG_A
435for i ulong nc bound 8
436put syTmpV i get syInA i
437end
438z = syAdmit 1 0 0 0
439if ge ar 2
440for i ulong nc bound 8
441put syTmpV i get syInB i
442end
443z = syAdmit 2 0 0 0
444end
445if ge ar 3
446for i ulong nc bound 8
447put syTmpV i get syInC i
448end
449z = syAdmit 3 0 0 0
450end
451ncon = get sySt 2
452for c ulong ncon bound 32
453cv = get syConsts c
454for i ulong nc bound 8
455put syTmpV i cv
456end
457z = syAdmit 0 cv 0 0
458end
459if eq get sySt 15 1
460sySeedCombFor 0
461if ge ar 2
462sySeedCombFor 1
463end
464end
465put syLvlE 0 get sySt 3
466end
467
468note Try all 10 binary ops on ordered pair (i, j) at BFS depth d
469fn syExpandPair i ulong j ulong d ulong skipComm bool to bool
470for op ulong 10 bound 10
471code = add op 4
472comm = or eq code 4 or eq code 6 or eq code 9 or eq code 10 eq code 11
473if not and skipComm comm
474if syEvalBin code i j
475nid = syAdmit code i j d
476if ne get sySt 8 999999
477ret true
478end
479end
480end
481end
482ret false
483end
484
485note Expand one strict BFS depth level d >= 1 (SM121 Invariant 1)
486note Phase A: (prevLevel x depth0) and (depth0 x prevLevel) across all 10 ops first
487note Phase B: (prevLevel x 1..prevE) across all 10 ops
488fn syExpandLevel d ulong to bool
489put syLvlS d get sySt 3
490prevS = get syLvlS sub d 1
491prevE = get syLvlE sub d 1
492d0E = get syLvlE 0
493note Level ends are frozen at the previous depth and bounded by the admitted node count.
494for offset ulong sub prevE prevS
495i = add prevS offset
496for j ulong d0E
497if syPoolFull
498put syLvlE d get sySt 3
499ret false
500end
501if syExpandPair i j d false
502put syLvlE d get sySt 3
503ret true
504end
505if ne i j
506if syExpandPair j i d true
507put syLvlE d get sySt 3
508ret true
509end
510end
511end
512end
513note Phase B: combine [prevS, prevE) with [d0E, prevE)
514if gt d 1
515for leftOffset ulong sub prevE prevS
516i = add prevS leftOffset
517for rightOffset ulong sub prevE d0E
518j = add d0E rightOffset
519if syPoolFull
520put syLvlE d get sySt 3
521ret false
522end
523note Only same-level pairs have already visited the commutative reverse order.
524if syExpandPair i j d and ge j prevS gt i j
525put syLvlE d get sySt 3
526ret true
527end
528if lt j prevS
529if syExpandPair j i d true
530put syLvlE d get sySt 3
531ret true
532end
533end
534end
535end
536end
537put syLvlE d get sySt 3
538ret false
539end
540
541text tUlong "ulong "
542
543note Emit OM-2 prefix expression for AST node nid (max depth 4, iterative-safe recursion)
544note Always types constants explicitly (`ulong N`) so every emitted AST compiles 100% under omc
545fn syEmitExpr nid ulong to void
546op = ulong get syOp nid
547if eq op 0
548oTxt tUlong
549oNum get syL nid
550ret
551end
552if eq op 1
553oTxt vA
554ret
555end
556if eq op 2
557oTxt vB
558ret
559end
560if eq op 3
561oTxt vC
562ret
563end
564if eq op 20
565oTxt opSub
566syEmitExpr get syL nid
567oCh 32
568oTxt opRem
569syEmitExpr get syL nid
570oCh 32
571oTxt tUlong
572oNum get syR nid
573ret
574end
575if eq op 21
576oTxt opAnd
577oTxt opShr
578syEmitExpr get syL nid
579oCh 32
580oTxt tUlong
581oNum get syR nid
582oCh 32
583oTxt tUlong
584oNum 1
585ret
586end
587if eq op 22
588oTxt opDiv
589oTxt opAdd
590syEmitExpr get syL nid
591oCh 32
592oTxt tUlong
593oNum sub get syR nid 1
594oCh 32
595oTxt tUlong
596oNum get syR nid
597ret
598end
599if eq op 23
600oTxt opAnd
601syEmitExpr get syL nid
602oCh 32
603oTxt tUlong
604oNum sub shl ulong 1 get syR nid 1
605ret
606end
607if eq op 4
608oTxt opAdd
609end
610if eq op 5
611oTxt opSub
612end
613if eq op 6
614oTxt opMul
615end
616if eq op 7
617oTxt opDiv
618end
619if eq op 8
620oTxt opRem
621end
622if eq op 9
623oTxt opAnd
624end
625if eq op 10
626oTxt opOr
627end
628if eq op 11
629oTxt opXor
630end
631if eq op 12
632oTxt opShl
633end
634if eq op 13
635oTxt opShr
636end
637syEmitExpr get syL nid
638oCh 32
639syEmitExpr get syR nid
640end
641
642note Evaluate predicate (cmpOp, li, ri) across nc lanes -> bitmask
643fn syEvalPred cop ulong li ulong ri ulong to ulong
644nc = get sySt 0
645lb = mul li 8
646rb = mul ri 8
647m = ulong 0
648for i ulong nc bound 8
649a = get syVec add lb i
650b = get syVec add rb i
651ok = false
652if eq cop 0
653ok = eq a b
654end
655if eq cop 1
656ok = ne a b
657end
658if eq cop 2
659ok = lt a b
660end
661if eq cop 3
662ok = le a b
663end
664if eq cop 4
665ok = gt a b
666end
667if eq cop 5
668ok = ge a b
669end
670if ok
671m = or m shl 1 i
672end
673end
674ret m
675end
676
677fn syPopcnt m ulong to ulong
678c = ulong 0
679for i ulong 8 bound 8
680if ne and shr m i 1 0
681c = add c 1
682end
683end
684ret c
685end
686
687note Find best single AST node covering ALL bits of remMask, or 999999
688fn syFindFullCover remMask ulong lim ulong to ulong
689for i ulong lim bound 32768
690if eq and ulong get syMask i remMask remMask
691ret i
692end
693end
694ret 999999
695end
696
697note Evaluate single candidate predicate (cop, li, ri) against remMask; updates sySt[24..26] if better
698note sySt: 24=bestCov, 25=bestCost, 26=bestMask, 27=brIdx, 28=exprLim
699fn syTryPred remMask ulong cop ulong li ulong ri ulong to void
700pm = and syEvalPred cop li ri remMask
701if or eq pm 0 eq pm remMask
702ret
703end
704cov = syPopcnt pm
705if lt cov get sySt 24
706ret
707end
708en = syFindFullCover pm get sySt 28
709if eq en 999999
710ret
711end
712cost = add ulong get syDep li ulong get syDep ri
713cost = add cost ulong get syDep en
714if and eq cov get sySt 24 ge cost get sySt 25
715ret
716end
717put sySt 24 cov
718put sySt 25 cost
719put sySt 26 pm
720put syBrPredOp get sySt 27 cop
721put syBrPredL get sySt 27 li
722put syBrPredR get sySt 27 ri
723put syBrExpr get sySt 27 en
724end
725
726fn syFindSplitIn remMask ulong lLim ulong rLim ulong to ulong
727put sySt 24 0
728put sySt 25 9999
729put sySt 26 0
730for cop ulong 6 bound 6
731for li ulong lLim bound 512
732for ri ulong rLim bound 512
733if ne li ri
734syTryPred remMask cop li ri
735end
736end
737end
738end
739ret get sySt 26
740end
741
742fn syFindSplit remMask ulong exprLim ulong predLim ulong brIdx ulong to ulong
743put sySt 27 brIdx
744put sySt 28 exprLim
745d0E = get syLvlE 0
746note Phase 1: depth-0 vs depth-0 predicates (e.g., lt a 8, lt a 64, lt a b)
747m1 = syFindSplitIn remMask d0E d0E
748if ne m1 0
749ret m1
750end
751note Phase 2: depth<=1 vs depth-0 predicates (e.g., eq rem a 3 0, eq and a 1 0)
752m2 = syFindSplitIn remMask predLim d0E
753if ne m2 0
754ret m2
755end
756note Phase 3: general depth<=1 vs depth<=1 predicates
757ret syFindSplitIn remMask predLim predLim
758end
759
760note Check if a single guard (if pred -> eTrue else eFalse) solves ALL of remMask in 1 step
761fn syTryOneGuard remMask ulong cop ulong li ulong ri ulong to void
762pm = and syEvalPred cop li ri remMask
763if or eq pm 0 eq pm remMask
764ret
765end
766qm = and remMask xor 255 pm
767e1 = syFindFullCover pm get sySt 28
768if eq e1 999999
769ret
770end
771e2 = syFindFullCover qm get sySt 28
772if eq e2 999999
773ret
774end
775cost = add ulong get syDep li ulong get syDep ri
776cost = add cost add ulong get syDep e1 ulong get syDep e2
777if lt cost get sySt 25
778put sySt 25 cost
779put sySt 26 pm
780put syBrPredOp 0 cop
781put syBrPredL 0 li
782put syBrPredR 0 ri
783put syBrExpr 0 e1
784put syBrDef 0 e2
785end
786end
787
788fn syFindOneGuardIn remMask ulong lLim ulong rLim ulong to bool
789put sySt 25 9999
790put sySt 26 0
791for cop ulong 6 bound 6
792for li ulong lLim bound 512
793for ri ulong rLim bound 512
794if ne li ri
795syTryOneGuard remMask cop li ri
796end
797end
798end
799end
800ret ne get sySt 26 0
801end
802
803note Collect distinct non-trivial atomic predicates (predLim x d0E) into syAP*
804fn syCollectAtoms remMask ulong lLim ulong rLim ulong to ulong
805cnt = ulong 0
806for cop ulong 6 bound 6
807for li ulong lLim bound 256
808for ri ulong rLim bound 64
809if ne li ri
810pm = and syEvalPred cop li ri remMask
811if and ne pm 0 ne pm remMask
812dup = false
813for k ulong cnt bound 128
814if eq get syAPMask k pm
815dup = true
816break
817end
818end
819if and not dup lt cnt 128
820put syAPOp cnt cop
821put syAPL cnt li
822put syAPR cnt ri
823put syAPMask cnt pm
824cnt = add cnt 1
825end
826end
827end
828end
829end
830end
831ret cnt
832end
833
834note Check compound 1-guard (if or P1 P2 -> e1 else e2, or if and P1 P2 -> e1 else e2)
835fn syTryCompoundPair remMask ulong i ulong j ulong isAnd bool to bool
836pm = ulong 0
837if isAnd
838pm = and get syAPMask i get syAPMask j
839else
840pm = or get syAPMask i get syAPMask j
841end
842pm = and pm remMask
843if or eq pm 0 eq pm remMask
844ret false
845end
846qm = and remMask xor 255 pm
847e1 = syFindFullCover pm get sySt 28
848if eq e1 999999
849ret false
850end
851e2 = syFindFullCover qm get sySt 28
852if eq e2 999999
853ret false
854end
855put syBrPredOp 0 get syAPOp i
856put syBrPredL 0 get syAPL i
857put syBrPredR 0 get syAPR i
858put syBrPredOp 1 get syAPOp j
859put syBrPredL 1 get syAPL j
860put syBrPredR 1 get syAPR j
861put syBrExpr 0 e1
862put syBrDef 0 e2
863if isAnd
864put syBrMode 0 2
865else
866put syBrMode 0 1
867end
868ret true
869end
870
871fn syFindCompoundGuard remMask ulong lLim ulong rLim ulong to bool
872cnt = syCollectAtoms remMask lLim rLim
873for i ulong cnt bound 128
874j = add i 1
875while lt j cnt bound 128
876if syTryCompoundPair remMask i j false
877ret true
878end
879if syTryCompoundPair remMask i j true
880ret true
881end
882j = add j 1
883end
884end
885ret false
886end
887
888note Decision-List branch solver (checks 1-guard exact, compound and/or 1-guard, then up to 4 guards)
889fn sySolveBranch to bool
890remM = get sySt 7
891exprLim = get sySt 3
892predLim = get syLvlE 1
893if gt predLim 256
894predLim = 256
895end
896put sySt 28 exprLim
897put sySt 10 0
898put syBrMode 0 0
899d0E = get syLvlE 0
900note Fast path 1: exact 1-guard partition (if P -> e1 else e2)
901if syFindOneGuardIn remM d0E d0E
902put sySt 10 1
903ret true
904end
905if syFindOneGuardIn remM predLim d0E
906put sySt 10 1
907ret true
908end
909note Fast path 2: compound 1-guard (if or/and P1 P2 -> e1 else e2)
910if syFindCompoundGuard remM predLim d0E
911put sySt 10 1
912ret true
913end
914for step ulong 4 bound 4
915full = syFindFullCover remM exprLim
916if ne full 999999
917put syBrDef 0 full
918put sySt 10 step
919ret true
920end
921pm = syFindSplit remM exprLim predLim step
922if eq pm 0
923ret false
924end
925remM = and remM xor 255 pm
926if eq remM 0
927put syBrDef 0 get syBrExpr step
928put sySt 10 step
929ret true
930end
931end
932full2 = syFindFullCover remM exprLim
933if ne full2 999999
934put syBrDef 0 full2
935put sySt 10 4
936ret true
937end
938ret false
939end
940
941fn syEmitCmp cop ulong to void
942if eq cop 0
943oTxt cpEq
944end
945if eq cop 1
946oTxt cpNe
947end
948if eq cop 2
949oTxt cpLt
950end
951if eq cop 3
952oTxt cpLe
953end
954if eq cop 4
955oTxt cpGt
956end
957if eq cop 5
958oTxt cpGe
959end
960end
961
962fn syEmitFnHdr arity ulong to void
963if eq arity 1
964oTxt tFn1
965ret
966end
967if eq arity 2
968oTxt tFn2
969ret
970end
971if eq arity 3
972oTxt tFn3
973ret
974end
975oTxt tFn4
976end
977
978note Emit complete OM-2 function for arith or branch solution
979fn syEmitSolution isBranch bool to void
980oClr
981syEmitFnHdr get sySt 1
982if not isBranch
983oTxt tRet
984syEmitExpr get sySt 8
985oCh 10
986oTxt tEnd
987ret
988end
989bm = get syBrMode 0
990if ne bm 0
991oTxt tIf
992if eq bm 1
993oTxt opOr
994else
995oTxt opAnd
996end
997syEmitCmp get syBrPredOp 0
998syEmitExpr get syBrPredL 0
999oCh 32
1000syEmitExpr get syBrPredR 0
1001oCh 32
1002syEmitCmp get syBrPredOp 1
1003syEmitExpr get syBrPredL 1
1004oCh 32
1005syEmitExpr get syBrPredR 1
1006oCh 10
1007oTxt tRet
1008syEmitExpr get syBrExpr 0
1009oCh 10
1010oTxt tEnd
1011oTxt tRet
1012syEmitExpr get syBrDef 0
1013oCh 10
1014oTxt tEnd
1015ret
1016end
1017bc = get sySt 10
1018for i ulong bc bound 4
1019oTxt tIf
1020syEmitCmp get syBrPredOp i
1021syEmitExpr get syBrPredL i
1022oCh 32
1023syEmitExpr get syBrPredR i
1024oCh 10
1025oTxt tRet
1026syEmitExpr get syBrExpr i
1027oCh 10
1028oTxt tEnd
1029end
1030oTxt tRet
1031syEmitExpr get syBrDef 0
1032oCh 10
1033oTxt tEnd
1034end
1035
1036note Recursion-Scheme Fold Sketcher over a view ulong 8 n ulong to ulong
1037note Tests 10 canonical bounded fold skeletons; returns skeleton id 0..9 or 999
1038fn syEvalFoldCase sk ulong ci ulong to ulong
1039n = get syArrN ci
1040base = mul ci 8
1041if eq sk 0
1042acc = ulong 0
1043for i ulong n bound 8
1044acc = add acc get syArr add base i
1045end
1046ret acc
1047end
1048if eq sk 1
1049acc = ulong 1
1050for i ulong n bound 8
1051acc = mul acc get syArr add base i
1052end
1053ret acc
1054end
1055if eq sk 2
1056acc = ulong 0
1057for i ulong n bound 8
1058v = get syArr add base i
1059if gt v acc
1060acc = v
1061end
1062end
1063ret acc
1064end
1065if eq sk 3
1066if eq n 0
1067ret 0
1068end
1069acc = get syArr base
1070for i ulong n bound 8
1071v = get syArr add base i
1072if lt v acc
1073acc = v
1074end
1075end
1076ret acc
1077end
1078if eq sk 4
1079acc = ulong 0
1080for i ulong n bound 8
1081acc = xor acc get syArr add base i
1082end
1083ret acc
1084end
1085if eq sk 5
1086acc = ulong 0
1087for i ulong n bound 8
1088acc = or acc get syArr add base i
1089end
1090ret acc
1091end
1092if eq sk 6
1093acc = ulong 0
1094for i ulong n bound 8
1095if eq and get syArr add base i 1 0
1096acc = add acc 1
1097end
1098end
1099ret acc
1100end
1101if eq sk 7
1102acc = ulong 0
1103for i ulong n bound 8
1104if ne and get syArr add base i 1 0
1105acc = add acc 1
1106end
1107end
1108ret acc
1109end
1110if eq sk 8
1111acc = ulong 0
1112for i ulong n bound 8
1113if ne get syArr add base i 0
1114acc = add acc 1
1115end
1116end
1117ret acc
1118end
1119acc = ulong 0
1120for i ulong n bound 8
1121v = get syArr add base i
1122acc = add acc mul v v
1123end
1124ret acc
1125end
1126
1127fn sySolveFold to ulong
1128nc = get sySt 13
1129for sk ulong 10 bound 10
1130ok = true
1131for ci ulong nc bound 8
1132if ne syEvalFoldCase sk ci get syTgt ci
1133ok = false
1134break
1135end
1136end
1137if ok
1138oClr
1139oTxt tFn4
1140if eq sk 0
1141oTxt tFldSum
1142end
1143if eq sk 1
1144oTxt tFldProd
1145end
1146if eq sk 2
1147oTxt tFldMax
1148end
1149if eq sk 3
1150oTxt tFldMin
1151end
1152if eq sk 4
1153oTxt tFldXor
1154end
1155if eq sk 5
1156oTxt tFldOr
1157end
1158if eq sk 6
1159oTxt tFldEvn
1160end
1161if eq sk 7
1162oTxt tFldOdd
1163end
1164if eq sk 8
1165oTxt tFldNz
1166end
1167if eq sk 9
1168oTxt tFldSq
1169end
1170ret sk
1171end
1172end
1173ret 999
1174end
1175
1176note Pure arith-only BFS up to maxDep using current Wave mode (sySt[15]=0 raw, 1 Wave-2)
1177fn syRunArithOnly maxDep ulong to bool
1178syReset
1179sySeedDepth0
1180if ne get sySt 8 999999
1181ret true
1182end
1183for d ulong maxDep bound 4
1184dep = add d 1
1185if syExpandLevel dep
1186ret true
1187end
1188end
1189ret false
1190end
1191
1192note Run arith (Wave-1 raw, then Wave-2 Wake-Sleep combinators) + branch synthesis up to maxDepth
1193fn syRunArithBranch maxDep ulong to ulong
1194put sySt 15 0
1195if syRunArithOnly maxDep
1196syEmitSolution false
1197put sySt 11 0
1198ret 1
1199end
1200note Wave-2 Wake-Sleep combinator compression pass (depth 4+ -> depth 1-2, 0.000 nats forgetting)
1201put sySt 15 1
1202if syRunArithOnly 2
1203syEmitSolution false
1204put sySt 11 0
1205put sySt 15 0
1206ret 1
1207end
1208put sySt 15 0
1209note Re-run clean Wave-1 pool for branch solver so predicates stay crisp
1210if syRunArithOnly maxDep
1211syEmitSolution false
1212put sySt 11 0
1213ret 1
1214end
1215if sySolveBranch
1216syEmitSolution true
1217put sySt 11 1
1218ret 2
1219end
1220ret 0
1221end
1222
1223note Append a synthesized OM-2 function from syOut[0..outPos) into syLibBuf as a NUL-delimited verified combinator
1224fn syLibCh c ulong to void
1225p = get syLibPos 0
1226if lt p 65535
1227put syLibBuf p uchar c
1228put syLibPos 0 add p 1
1229end
1230end
1231
1232fn syLibTxt s view uchar * to void
1233for i ulong len s bound 256
1234syLibCh ulong get s i
1235end
1236end
1237
1238fn syLibNum v ulong to void
1239b = new uchar 24 0
1240p = ulong 24
1241x = v
1242while true bound 24
1243p = sub p 1
1244put b p uchar add 48 rem x 10
1245x = div x 10
1246if eq x 0
1247break
1248end
1249end
1250while lt p 24 bound 24
1251syLibCh ulong get b p
1252p = add p 1
1253end
1254end
1255
1256note Record the winning synthesized function (currently in syOut) into syLibBuf with header note & unique name
1257fn syRecordWin tag view uchar * to void
1258idx = get sySt 14
1259syLibTxt tMineHdr1
1260syLibTxt tag
1261syLibCh 10
1262note Replace "fn solve" prefix in syOut with "fn lib_comb_<idx>"
1263syLibTxt tMineFn1
1264syLibNum idx
1265n = get sySt 9
1266note Skip "fn solve" (8 bytes) from syOut
1267i = ulong 8
1268while lt i n bound 65536
1269syLibCh ulong get syOut i
1270i = add i 1
1271end
1272syLibCh 0
1273put sySt 14 add idx 1
1274end
1275
1276fn syEmitMinedLib to ulong
1277oClr
1278n = get syLibPos 0
1279for i ulong n bound 65536
1280oCh ulong get syLibBuf i
1281end
1282ret get sySt 14
1283end
1284
1285note Synthetic non-benchmark selfcheck suite (bench seen == 0 by construction)
1286fn setupConstsDefault to void
1287put syConsts 0 0
1288put syConsts 1 1
1289put syConsts 2 2
1290put syConsts 3 3
1291put syConsts 4 4
1292put syConsts 5 5
1293put syConsts 6 8
1294put syConsts 7 14
1295put syConsts 8 64
1296put syConsts 9 512
1297put sySt 2 10
1298end
1299
1300text tagF1 "floor to multiple of 14"
1301text tagF2 "extract bit 5 of unsigned integer"
1302text tagF3 "collatz-like 3-div or 2a+1 branch"
1303text tagF4 "4-way threshold 8 64 512 branch"
1304text tagF5 "wave2 compressed bit5 of floor_mult14"
1305
1306fn runSelfcheck showOut bool to int
1307setupConstsDefault
1308put sySt 0 8
1309put sySt 1 1
1310put sySt 7 255
1311put sySt 14 0
1312put syLibPos 0 0
1313
1314note Test 1 (arith): f(a) = a - (a % 14) [floor to multiple of 14]
1315put syInA 0 0
1316put syInA 1 5
1317put syInA 2 14
1318put syInA 3 15
1319put syInA 4 27
1320put syInA 5 28
1321put syInA 6 41
1322put syInA 7 100
1323for i ulong 8 bound 8
1324a = get syInA i
1325put syTgt i sub a rem a 14
1326end
1327r1 = syRunArithBranch 2
1328if ne r1 1
1329wStr 2 tSelfFail
1330wNum 2 1
1331wStr 2 tNl
1332ret 1
1333end
1334syRecordWin tagF1
1335if showOut
1336r = write 1 syOut 0 get sySt 9
1337end
1338
1339note Test 2 (bits): f(a) = (a >> 5) & 1 [extract bit 5]
1340put syInA 0 0
1341put syInA 1 31
1342put syInA 2 32
1343put syInA 3 63
1344put syInA 4 64
1345put syInA 5 96
1346put syInA 6 127
1347put syInA 7 255
1348for i ulong 8 bound 8
1349a = get syInA i
1350put syTgt i and shr a 5 1
1351end
1352r2 = syRunArithBranch 2
1353if ne r2 1
1354wStr 2 tSelfFail
1355wNum 2 2
1356wStr 2 tNl
1357ret 1
1358end
1359syRecordWin tagF2
1360if showOut
1361r = write 1 syOut 0 get sySt 9
1362end
1363
1364note Test 3 (branch 2-way, non-benchmark): if a % 3 == 0 -> a / 3, else 2*a + 1
1365put syInA 0 0
1366put syInA 1 1
1367put syInA 2 2
1368put syInA 3 3
1369put syInA 4 6
1370put syInA 5 12
1371put syInA 6 15
1372put syInA 7 19
1373for i ulong 8 bound 8
1374a = get syInA i
1375if eq rem a 3 0
1376put syTgt i div a 3
1377else
1378put syTgt i add mul 2 a 1
1379end
1380end
1381r3 = syRunArithBranch 2
1382if ne r3 2
1383wStr 2 tSelfFail
1384wNum 2 3
1385wStr 2 tNl
1386ret 1
1387end
1388syRecordWin tagF3
1389if showOut
1390r = write 1 syOut 0 get sySt 9
1391end
1392
1393note Test 4 (branch 4-way threshold, non-benchmark): <8 -> 1, <64 -> 2, <512 -> 3, else 4
1394put syInA 0 0
1395put syInA 1 7
1396put syInA 2 8
1397put syInA 3 63
1398put syInA 4 64
1399put syInA 5 511
1400put syInA 6 512
1401put syInA 7 1000
1402for i ulong 8 bound 8
1403a = get syInA i
1404if lt a 8
1405put syTgt i 1
1406else
1407if lt a 64
1408put syTgt i 2
1409else
1410if lt a 512
1411put syTgt i 3
1412else
1413put syTgt i 4
1414end
1415end
1416end
1417end
1418r4 = syRunArithBranch 1
1419if ne r4 2
1420wStr 2 tSelfFail
1421wNum 2 4
1422wStr 2 tNl
1423ret 1
1424end
1425syRecordWin tagF4
1426if showOut
1427r = write 1 syOut 0 get sySt 9
1428end
1429
1430note Test 5 (fold): array sum and array max
1431put sySt 13 3
1432put syArrN 0 4
1433put syArr 0 3
1434put syArr 1 7
1435put syArr 2 2
1436put syArr 3 9
1437put syArrN 1 3
1438put syArr 8 10
1439put syArr 9 5
1440put syArr 10 20
1441put syArrN 2 5
1442put syArr 16 1
1443put syArr 17 1
1444put syArr 18 1
1445put syArr 19 1
1446put syArr 20 1
1447put syTgt 0 21
1448put syTgt 1 35
1449put syTgt 2 5
1450sk1 = sySolveFold
1451if ne sk1 0
1452wStr 2 tSelfFail
1453wNum 2 5
1454wStr 2 tNl
1455ret 1
1456end
1457put syTgt 0 9
1458put syTgt 1 20
1459put syTgt 2 1
1460sk2 = sySolveFold
1461if ne sk2 2
1462wStr 2 tSelfFail
1463wNum 2 6
1464wStr 2 tNl
1465ret 1
1466end
1467
1468note Test 6 (SM121 Invariant 3 branchless div/rem/shift guard check)
1469put syVec 0 10
1470put syVec 8 0
1471put syVec 9 64
1472if syEvalBin 7 0 1
1473wStr 2 tSelfFail
1474wNum 2 7
1475wStr 2 tNl
1476ret 1
1477end
1478if syEvalBin 12 0 1
1479wStr 2 tSelfFail
1480wNum 2 8
1481wStr 2 tNl
1482ret 1
1483end
1484
1485note Test 7 (Wake-Sleep Wave-2 compounding depth compression: depth-4 task solved at depth-2!)
1486put syInA 0 0
1487put syInA 1 14
1488put syInA 2 32
1489put syInA 3 42
1490put syInA 4 69
1491put syInA 5 70
1492put syInA 6 518
1493put syInA 7 1000
1494for i ulong 8 bound 8
1495a = get syInA i
1496fl = sub a rem a 14
1497put syTgt i and shr fl 5 1
1498end
1499note Step 7a: raw Wave-1 depth-2 MUST fail (proves genuine depth > 2!)
1500put sySt 15 0
1501if syRunArithOnly 2
1502wStr 2 tSelfFail
1503wNum 2 9
1504wStr 2 tNl
1505ret 1
1506end
1507note Step 7b: Wave-2 Wake-Sleep combinator library solves depth-4 task at depth <= 2!
1508put sySt 15 1
1509if not syRunArithOnly 2
1510wStr 2 tSelfFail
1511wNum 2 10
1512wStr 2 tNl
1513ret 1
1514end
1515syEmitSolution false
1516put sySt 15 0
1517syRecordWin tagF5
1518if showOut
1519r = write 1 syOut 0 get sySt 9
1520end
1521
1522note Test 8 (Wake-Sleep library mining: 5 combinators, 0.000 nats forgetting)
1523em = syEmitMinedLib
1524if ne em 5
1525wStr 2 tSelfFail
1526wNum 2 11
1527wStr 2 tNl
1528ret 1
1529end
1530
1531wStr 1 tSelfOk
1532ret 0
1533end
1534
1535text kwArity "arity "
1536text kwConsts "consts "
1537text kwCase "case "
1538text kwFold "fold "
1539text kwDepth "depth "
1540
1541fn spStarts o ulong e ulong t view uchar * to bool
1542tl = len t
1543if gt tl sub e o
1544ret false
1545end
1546for i ulong tl bound 32
1547if ne get syInBuf add o i get t i
1548ret false
1549end
1550end
1551ret true
1552end
1553
1554note Parse next unsigned integer from syInBuf[pos..end), storing value in sySt[20] and returning new pos
1555fn spNextU pos ulong e ulong to ulong
1556p = pos
1557while lt p e bound 4096
1558c = get syInBuf p
1559if and ne c 32 and ne c 9 ne c 13
1560break
1561end
1562p = add p 1
1563end
1564v = ulong 0
1565got = ulong 0
1566while lt p e bound 4096
1567c = get syInBuf p
1568if not and ge c 48 le c 57
1569break
1570end
1571v = add mul v 10 ulong sub c 48
1572got = 1
1573p = add p 1
1574end
1575put sySt 20 v
1576put sySt 21 got
1577ret p
1578end
1579
1580note Parse SPEC_FILE loaded in syInBuf[0..blen)
1581note Spec format (one directive per line):
1582note arity 1|2|3|4
1583note depth 2|3
1584note consts 0 1 2 3 5 10 ...
1585note case A [B [C]] Y
1586note fold N V0 V1 ... V(N-1) Y
1587fn syParseSpec blen ulong to bool
1588setupConstsDefault
1589put sySt 0 0
1590put sySt 1 1
1591put sySt 13 0
1592put sySt 22 2
1593pos = ulong 0
1594while lt pos blen bound 65536
1595ls = pos
1596while lt pos blen bound 65536
1597if eq get syInBuf pos 10
1598break
1599end
1600pos = add pos 1
1601end
1602lend = pos
1603if lt pos blen
1604pos = add pos 1
1605end
1606if spStarts ls lend kwArity
1607p = spNextU add ls 6 lend
1608if eq get sySt 21 1
1609put sySt 1 get sySt 20
1610end
1611end
1612if spStarts ls lend kwDepth
1613p = spNextU add ls 6 lend
1614if eq get sySt 21 1
1615put sySt 22 get sySt 20
1616end
1617end
1618if spStarts ls lend kwConsts
1619p = add ls 7
1620cc = ulong 0
1621while lt p lend bound 32
1622p = spNextU p lend
1623if eq get sySt 21 0
1624break
1625end
1626if lt cc 32
1627put syConsts cc get sySt 20
1628cc = add cc 1
1629end
1630end
1631if gt cc 0
1632put sySt 2 cc
1633end
1634end
1635if spStarts ls lend kwCase
1636nc = get sySt 0
1637if lt nc 8
1638ar = get sySt 1
1639p = spNextU add ls 5 lend
1640put syInA nc get sySt 20
1641if ge ar 2
1642p = spNextU p lend
1643put syInB nc get sySt 20
1644end
1645if ge ar 3
1646p = spNextU p lend
1647put syInC nc get sySt 20
1648end
1649p = spNextU p lend
1650put syTgt nc get sySt 20
1651put sySt 0 add nc 1
1652end
1653end
1654if spStarts ls lend kwFold
1655fc = get sySt 13
1656if lt fc 8
1657p = spNextU add ls 5 lend
1658vn = get sySt 20
1659put syArrN fc vn
1660base = mul fc 8
1661for k ulong 8 bound 8
1662put syArr add base k 0
1663end
1664for k ulong vn bound 8
1665p = spNextU p lend
1666put syArr add base k get sySt 20
1667end
1668p = spNextU p lend
1669put syTgt fc get sySt 20
1670put sySt 13 add fc 1
1671end
1672end
1673end
1674nc = get sySt 0
1675if gt nc 0
1676put sySt 7 sub shl ulong 1 nc 1
1677ret true
1678end
1679if gt get sySt 13 0
1680put sySt 1 4
1681ret true
1682end
1683ret false
1684end
1685
1686fn sySaveOut argi ulong to bool
1687pl = argread argi syPath 0 4095
1688if le pl 0
1689ret false
1690end
1691fd = fopen syPath 0 ulong pl 577 420
1692if lt fd 0
1693ret false
1694end
1695n = get sySt 9
1696o = ulong 0
1697while lt o n bound 65536
1698k = write int fd syOut o sub n o
1699if le k 0
1700break
1701end
1702o = add o ulong k
1703end
1704z = fclose int fd
1705ret true
1706end
1707
1708fn runSolveCmd to int
1709pl = argread 2 syPath 0 4095
1710if le pl 0
1711wStr 2 tErrIo
1712ret 1
1713end
1714fd = fopen syPath 0 ulong pl 0 0
1715if lt fd 0
1716wStr 2 tErrIo
1717ret 1
1718end
1719kn = read int fd syInBuf 0 65535
1720z = fclose int fd
1721if le kn 0
1722wStr 2 tErrIo
1723ret 1
1724end
1725if not syParseSpec ulong kn
1726wStr 2 tErrIo
1727ret 1
1728end
1729if eq get sySt 1 4
1730sk = sySolveFold
1731if eq sk 999
1732wStr 1 tFailA
1733wNum 1 0
1734wStr 1 tNl
1735ret 1
1736end
1737if not sySaveOut 3
1738wStr 2 tErrIo
1739ret 1
1740end
1741wStr 1 tOkA
1742wStr 1 tMFold
1743wStr 1 tStNodes
1744wNum 1 sk
1745wStr 1 tNl
1746ret 0
1747end
1748res = syRunArithBranch get sySt 22
1749if eq res 0
1750wStr 1 tFailA
1751wNum 1 get sySt 3
1752wStr 1 tStPruned
1753wNum 1 get sySt 5
1754wStr 1 tStProbes
1755wNum 1 get sySt 6
1756wStr 1 tStOcc
1757wNum 1 get sySt 4
1758wStr 1 tNl
1759ret 1
1760end
1761if not sySaveOut 3
1762wStr 2 tErrIo
1763ret 1
1764end
1765wStr 1 tOkA
1766if eq res 1
1767wStr 1 tMArith
1768else
1769wStr 1 tMBranch
1770end
1771wStr 1 tStNodes
1772wNum 1 get sySt 3
1773wStr 1 tStPruned
1774wNum 1 get sySt 5
1775wStr 1 tStProbes
1776wNum 1 get sySt 6
1777wStr 1 tStOcc
1778wNum 1 get sySt 4
1779wStr 1 tNl
1780ret 0
1781end
1782
1783fn main to int
1784ac = argcnt
1785if lt ac 2
1786wStr 2 tUsage
1787ret 2
1788end
1789mb = new uchar 64 0
1790ml = argread 1 mb 0 64
1791if le ml 0
1792wStr 2 tUsage
1793ret 2
1794end
1795if eqTxt mb ulong ml mSelf
1796ret runSelfcheck false
1797end
1798if eqTxt mb ulong ml mDemo
1799ret runSelfcheck true
1800end
1801if eqTxt mb ulong ml mSolve
1802if lt ac 4
1803wStr 2 tUsage
1804ret 2
1805end
1806ret runSolveCmd
1807end
1808if eqTxt mb ulong ml mMine
1809if lt ac 3
1810wStr 2 tUsage
1811ret 2
1812end
1813rc = runSelfcheck false
1814if ne rc 0
1815ret rc
1816end
1817em = syEmitMinedLib
1818pl = argread 2 syPath 0 4095
1819if le pl 0
1820wStr 2 tErrIo
1821ret 1
1822end
1823fd = fopen syPath 0 ulong pl 577 420
1824if lt fd 0
1825wStr 2 tErrIo
1826ret 1
1827end
1828n = get sySt 9
1829o = ulong 0
1830while lt o n bound 65536
1831k = write int fd syOut o sub n o
1832if le k 0
1833break
1834end
1835o = add o ulong k
1836end
1837z = fclose int fd
1838wStr 1 tMineDone
1839wNum 1 em
1840wStr 1 tMineBytes
1841wNum 1 n
1842wStr 1 tNl
1843ret 0
1844end
1845wStr 2 tUsage
1846ret 2
1847end