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 / build / units.om

1138 lines · 23007 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note seed/build/units.om: Pure seeded-Omega C-Binding & Units Regenerator.
3note Replaces om/units.sh completely with exact byte-for-byte parity. Zero shell, zero sed/tr/wc/cmp.
4note Build: cat seed/build/common.om seed/build/units.om | seed/out/omc > build/om-units
5note Usage: om-units [--check]
6note Env:
7note OMEGA_OMC pinned omc binary (default checked against seed/out/omc.sha256 or OMEGA_OMC_PIN)
8note OMEGA_BRIDGE omega-bridge checkout (src/native.om pinned against OMEGA_NATIVE_PIN)
9note OMEGA_UNITS optional space-separated unit override
10note OMEGA_UNITS_DEST optional output directory (default src)
11
12text un_fcheck "--check"
13text un_env_omc "OMEGA_OMC"
14text un_env_br "OMEGA_BRIDGE"
15text un_env_units "OMEGA_UNITS"
16text un_env_dest "OMEGA_UNITS_DEST"
17text un_env_omcpin "OMEGA_OMC_PIN"
18text un_env_natpin "OMEGA_NATIVE_PIN"
19text un_def_natpin "9788b27a92c8dd365de7052439653de62f89634189a34cb6b3f582cae65dda83"
20text un_pin_file "seed/out/omc.sha256"
21text un_nat_rel "/src/native.om"
22text un_def_dest "src"
23text un_nr_env "NOT_RUN: set OMEGA_OMC and OMEGA_BRIDGE\n"
24text un_nr_omc "NOT_RUN: omc is not the pinned compiler\n"
25text un_nr_nat "NOT_RUN: native.om is not the pinned generator\n"
26text un_fail_io "FAIL: units I/O or tool error\n"
27text un_fail_diff1 "FAIL "
28text un_fail_diff2 " differs from the pinned tools' output\n"
29text un_pass_chk "PASS src/{omega_om_units.c,omega_native.h,omega_api_decl.h,omega_om_units.ident,omega_om_units_fs.c} regenerate byte for byte\n"
30text un_wrote1 "wrote "
31text un_wrote2 "/{omega_om_units.c,omega_native.h,omega_api_decl.h,omega_om_units.ident,omega_om_units_fs.c}\n"
32text un_nofs "/* No freestanding GPU units selected. */\n"
33
34text un_def_units "om/arboris_arena.om om/arboris_spread.om om/arboris_spread_plan.om om/arboris_spread_cpu.om om/bw_arboris_spread_emit.om om/arboris_gated.om om/blackwell_arboris_emit.om om/blackwell_arboris_qmd.om gpu/nvidia/om/codegen/bw_hazard.om om/sha256/sha256-om2.om om/blake3/b3unit.om om/encoder/bw_enc_sm121.om om/aarch64/aarch64_om2.om om/visor/canonical_om2.om om/visor/validate_om2.om om/visor/codec_om2.om om/visor/verify_om2.om om/gpu/bw_qmd.om om/gpu/bw_sched.om om/gpu/bw_regalloc.om om/gpu/bw_vecadd.om om/gpu/cg_matmul.om om/gpu/cg_gpu_gemm.om om/gpu/cg_gpu_attn.om om/gpu/q38_plan.om om/gpu/moe_plan.om om/gpu/cg_pf.om om/gpu/cg_bf16.om om/gpu/cg_gemm.om om/gpu/cg_moe2.om om/gpu/cg_moe.om om/gpu/cg_qmma.om om/gpu/cg_pfhost.om om/gpu/cg_tgemm.om om/gpu/cg_tc2.om om/gpu/cg_qg.om om/gpu/cg_tc.om om/gpu/cg_pattn256.om om/gpu/cg_router.om om/gpu/cg_pattn.om om/gpu/cg_attn.om om/gpu/cg_tern.om om/gpu/cg_attn256.om om/gpu/cg_dec.om om/gpu/cg_gdn.om om/runtime/rx_regulate.om om/runtime/rx_mid.om om/runtime/rx_cortex_rec.om om/runtime/rx_plan_core.om om/runtime/rx_projection.om om/runtime/rx_capq_core.om om/runtime/rx_costmodel_core.om om/runtime/rx_route_core.om om/runtime/rx_world_core.om om/runtime/rx_coherent_om2.om om/runtime/rx_semantic_om2.om om/runtime/rx_skillroute_core.om om/runtime/rx_fusion_core.om seed/authority/cap_table_om2.om seed/authority/aegis_om2.om om/compiler/osc_literal.om om/compiler/osc_type.om om/compiler/osc_expr.om om/compiler/osc_scalar.om om/compiler/osc_a64_fields.om om/compiler/osc_statement.om om/compiler/osc_ownership.om om/compiler/osc_scope.om om/compiler/osc_pool.om om/compiler/osc_trace.om om/compiler/osc_lifetimes.om om/compiler/osc_flow.om om/compiler/osc_artifact.om src/tensor/tensor_shape.om src/tensor/tensor_ops.om src/train/sgd_update.om src/train/generation.om src/autodiff/gradient_shape.om src/allen/allen_core.om src/path/rx_path_core.om src/ans/ans_core.om src/reservoir/reservoir_readout.om src/crumbline/cl_core.om src/dual/rx_dual_core.om src/dual_experiment/applic_core.om src/estimation/est_core.om src/searchtrace/st_core.om src/language/lang_core.om src/visor/visor_core.om src/fabric/fab_core.om src/algebra/oma_core.om src/physics0/pd0_core.om src/turing/turing_core.om src/polyglot/omx_core.om src/osh/osh_core.om"
35
36note Special composed unit paths & helpers
37text un_p_as "om/arboris_spread.om"
38text un_p_ao "om/arboris_ontology.om"
39text un_p_sha2 "om/tls/sha2.om"
40text un_p_ar "om/arboris_records.om"
41text un_p_ag "om/arboris_gated.om"
42text un_p_aa "om/arboris_arena.om"
43text un_p_num "gpu/nvidia/om/numeric/numeric.om"
44text un_p_bae "om/blackwell_arboris_emit.om"
45text un_p_enc "om/encoder/bw_enc_sm121.om"
46text un_p_bage "om/blackwell_arboris_gated_emit.om"
47text un_p_baq "om/blackwell_arboris_qmd.om"
48text un_p_qmd "om/gpu/bw_qmd.om"
49text un_p_bse "om/bw_arboris_spread_emit.om"
50text un_p_bhz "gpu/nvidia/om/codegen/bw_hazard.om"
51text un_om2_ln "om2\n"
52text un_exp_fn "export fn "
53text un_fn_sp "fn "
54text un_hz_from "fn hz_chk "
55text un_hz_to "export fn hz_chk "
56text un_note_w "note"
57text un_om2_w "om2"
58text un_om_ext ".om"
59
60note Leaf unit paths (use caller-stack freest/fapic ABI)
61text un_l01 "om/blackwell_arboris_emit.om"
62text un_l02 "om/blackwell_arboris_qmd.om"
63text un_l03 "om/arboris_spread.om"
64text un_l04 "om/arboris_arena.om"
65text un_l05 "src/tensor/tensor_shape.om"
66text un_l06 "om/compiler/osc_flow.om"
67text un_l07 "src/train/generation.om"
68text un_l08 "om/compiler/osc_statement.om"
69text un_l09 "om/compiler/osc_artifact.om"
70text un_l10 "src/autodiff/gradient_shape.om"
71
72note FS unit paths (freestanding GPU link)
73text un_fs01 "om/sha256/sha256-om2.om"
74text un_fs02 "om/gpu/bw_qmd.om"
75text un_fs03 "om/gpu/bw_regalloc.om"
76text un_fs04 "om/gpu/bw_vecadd.om"
77text un_fs05 "om/gpu/cg_matmul.om"
78text un_fs06 "om/gpu/cg_gpu_attn.om"
79
80note Native generator commands & output filenames
81text un_cmd_c "c"
82text un_cmd_apic "apic"
83text un_cmd_freest "freest"
84text un_cmd_fapic "fapic"
85text un_cmd_h "h"
86text un_cmd_apih "apih"
87text un_f_c "/omega_om_units.c"
88text un_f_h "/omega_native.h"
89text un_f_apih "/omega_api_decl.h"
90text un_f_id "/omega_om_units.ident"
91text un_f_fs "/omega_om_units_fs.c"
92text un_tdir "build/om-units-work-"
93text un_tnat "/native"
94text un_tsrc "/u.src.om"
95text un_tbin "/u.bin"
96text un_tuin "/u.in"
97text un_tunits "/units.in"
98text un_thost "/host.in"
99text un_tleaf "/leaf.in"
100text un_tfs "/fs.in"
101text un_tleafc "/leaf.c"
102text un_tc1 "/c1.tmp"
103text un_tc2 "/c2.tmp"
104text un_id_1 "omega-ident 1 unit="
105text un_id_2 " abi="
106text un_id_3 " profile="
107text un_id_4 " src="
108text un_id_5 " omc="
109text un_id_6 " path="
110text un_om1_p "OM-1"
111text un_om2_p "OM-2"
112text un_tag_pre "omega-unit "
113text un_ombr "ombr"
114text un_ombr_leaf "ombr_leaf"
115
116global un_omc uchar 4096
117global un_omcl ulong 1
118global un_br uchar 4096
119global un_brl ulong 1
120global un_dest uchar 4096
121global un_destl ulong 1
122global un_omcpin uchar 64
123global un_natpin uchar 64
124global un_ulist uchar *
125global un_uln ulong 1
126global un_tmp uchar 4096
127global un_tmpl ulong 1
128global un_cur uchar 4096
129global un_curl ulong 1
130global un_name uchar 256
131global un_namel ulong 1
132global un_chk ulong 1
133global un_has_host ulong 1
134global un_has_leaf ulong 1
135global un_has_fs ulong 1
136
137fn un_die msg view uchar * code int to void
138un_cleanup
139cb_err msg
140exit code
141end
142
143fn un_tpath suf view uchar * to void
144cb_pa_clr
145for i ulong get un_tmpl 0 bound 4096
146cb_pa_ch get un_tmp i
147end
148cb_pa_tx suf
149end
150
151fn un_tbpath suf view uchar * to void
152cb_pb_clr
153for i ulong get un_tmpl 0 bound 4096
154cb_pb_ch get un_tmp i
155end
156cb_pb_tx suf
157end
158
159fn un_dpath name view uchar * to void
160cb_pb_clr
161for i ulong get un_destl 0 bound 4096
162cb_pb_ch get un_dest i
163end
164cb_pb_tx name
165end
166
167fn un_hex_eq_pin is_omc bool to bool
168for j ulong 64
169if is_omc
170if ne get cb_shex j get un_omcpin j
171ret false
172end
173else
174if ne get cb_shex j get un_natpin j
175ret false
176end
177end
178end
179ret true
180end
181
182fn un_cur_eq t view uchar * to bool
183n = get un_curl 0
184if ne n len t
185ret false
186end
187for i ulong n bound 4096
188if ne get un_cur i get t i
189ret false
190end
191end
192ret true
193end
194
195fn un_cur_ends t view uchar * to bool
196n = get un_curl 0
197m = len t
198if lt n m
199ret false
200end
201off = sub n m
202for i ulong m bound 4096
203if ne get un_cur add off i get t i
204ret false
205end
206end
207if eq off 0
208ret true
209end
210ret eq get un_cur sub off 1 47
211end
212
213fn un_is_leaf to bool
214if un_cur_ends un_l01
215ret true
216end
217if un_cur_ends un_l02
218ret true
219end
220if un_cur_ends un_l03
221ret true
222end
223if un_cur_ends un_l04
224ret true
225end
226if un_cur_ends un_l05
227ret true
228end
229if un_cur_ends un_l06
230ret true
231end
232if un_cur_ends un_l07
233ret true
234end
235if un_cur_ends un_l08
236ret true
237end
238if un_cur_ends un_l09
239ret true
240end
241ret un_cur_ends un_l10
242end
243
244fn un_is_fs to bool
245if un_cur_eq un_fs01
246ret true
247end
248if un_cur_eq un_fs02
249ret true
250end
251if un_cur_eq un_fs03
252ret true
253end
254if un_cur_eq un_fs04
255ret true
256end
257if un_cur_eq un_fs05
258ret true
259end
260ret un_cur_eq un_fs06
261end
262
263fn un_rb_line_starts pos ulong endp ulong t view uchar * to bool
264m = len t
265if lt sub endp pos m
266ret false
267end
268for j ulong m bound 64
269if ne get cb_rb add pos j get t j
270ret false
271end
272end
273ret true
274end
275
276note Append file at cb_pa to cb_wb with optional transforms:
277note mode 0 = raw, 1 = sed 's/^export fn /fn /', 2 = sed '/^om2$/d; s/^export fn /fn /', 3 = sed 's/^fn hz_chk /export fn hz_chk /'
278fn un_app_xform mode ulong to void
279if eq mode 0
280if not cb_append_pa_to_wb
281un_die un_fail_io 1
282end
283ret
284end
285if not cb_read_pa
286un_die un_fail_io 1
287end
288n = get cb_n 0
289i = ulong 0
290while lt i n bound 9223372036854775807
291e = i
292while lt e n bound 9223372036854775807
293if eq get cb_rb e 10
294break
295end
296e = add e 1
297end
298has_nl = lt e n
299skip = false
300if eq mode 2
301if and eq sub e i 3 un_rb_line_starts i e un_om2_w
302skip = true
303end
304end
305if not skip
306if and or eq mode 1 eq mode 2 un_rb_line_starts i e un_exp_fn
307cb_wb_tx un_fn_sp
308cb_wb_rb add i 10 sub sub e i 10
309else
310if and eq mode 3 un_rb_line_starts i e un_hz_from
311cb_wb_tx un_hz_to
312cb_wb_rb add i 10 sub sub e i 10
313else
314cb_wb_rb i sub e i
315end
316end
317if has_nl
318cb_wb_ch 10
319end
320end
321i = add e 1
322end
323end
324
325fn un_pa_set_cur to void
326cb_pa_clr
327for i ulong get un_curl 0 bound 4096
328cb_pa_ch get un_cur i
329end
330end
331
332note Compose current unit source into cb_wb
333fn un_compose_unit to void
334cb_wb_clr
335if un_cur_ends un_p_as
336cb_pa_set un_p_ao
337un_app_xform 0
338cb_pa_set un_p_sha2
339un_app_xform 0
340cb_pa_set un_p_ar
341un_app_xform 0
342un_pa_set_cur
343un_app_xform 0
344ret
345end
346if un_cur_ends un_p_ag
347cb_pa_set un_p_aa
348un_app_xform 1
349cb_pa_set un_p_num
350un_app_xform 0
351un_pa_set_cur
352un_app_xform 0
353ret
354end
355if un_cur_ends un_p_bae
356cb_wb_tx un_om2_ln
357cb_pa_set un_p_enc
358un_app_xform 0
359un_pa_set_cur
360un_app_xform 0
361cb_pa_set un_p_bage
362un_app_xform 0
363ret
364end
365if un_cur_ends un_p_baq
366cb_pa_set un_p_qmd
367un_app_xform 1
368un_pa_set_cur
369un_app_xform 0
370ret
371end
372if un_cur_ends un_p_bse
373cb_wb_tx un_om2_ln
374cb_pa_set un_p_enc
375un_app_xform 0
376cb_pa_set un_p_qmd
377un_app_xform 2
378un_pa_set_cur
379un_app_xform 0
380ret
381end
382if un_cur_ends un_p_bhz
383cb_wb_tx un_om2_ln
384un_pa_set_cur
385un_app_xform 3
386ret
387end
388un_pa_set_cur
389un_app_xform 0
390end
391
392fn un_is_name_ch c uchar to bool
393if and ge c 48 le c 57
394ret true
395end
396if and ge c 65 le c 90
397ret true
398end
399if and ge c 97 le c 122
400ret true
401end
402ret eq c 95
403end
404
405note Derive unit name: basename(cur, .om) with non-[A-Za-z0-9_] mapped to '_'
406fn un_derive_name to void
407n = get un_curl 0
408s = ulong 0
409for i ulong n bound 4096
410if eq get un_cur i 47
411s = add i 1
412end
413end
414e = n
415if ge sub e s 3
416if eq get un_cur sub e 3 46
417if eq get un_cur sub e 2 111
418if eq get un_cur sub e 1 109
419e = sub e 3
420end
421end
422end
423end
424m = sub e s
425if gt m 255
426m = 255
427end
428for i ulong m bound 256
429c = get un_cur add s i
430if un_is_name_ch c
431put un_name i c
432else
433put un_name i 95
434end
435end
436put un_namel 0 m
437end
438
439note Detect OM-2 profile from cb_wb[0..cb_n[1]): first non-blank, non-note line equals "om2"
440fn un_detect_om2 to bool
441n = get cb_n 1
442i = ulong 0
443while lt i n bound 9223372036854775807
444e = i
445while lt e n bound 9223372036854775807
446if eq get cb_wb e 10
447break
448end
449e = add e 1
450end
451p = i
452while lt p e bound 9223372036854775807
453if eq get cb_wb p 32
454p = add p 1
455else
456break
457end
458end
459if lt p e
460note check if starts with "note" followed by end-of-line or space
461is_n = false
462if ge sub e p 4
463if eq get cb_wb p 110
464if eq get cb_wb add p 1 111
465if eq get cb_wb add p 2 116
466if eq get cb_wb add p 3 101
467if eq sub e p 4
468is_n = true
469else
470if eq get cb_wb add p 4 32
471is_n = true
472end
473end
474end
475end
476end
477end
478end
479if not is_n
480if eq sub e i 3
481if eq get cb_wb i 111
482if eq get cb_wb add i 1 109
483if eq get cb_wb add i 2 50
484ret true
485end
486end
487end
488end
489ret false
490end
491end
492i = add e 1
493end
494ret false
495end
496
497fn un_append_file_to_file src_suf view uchar * dst_suf view uchar * to void
498un_tpath src_suf
499fdi = fopen cb_pa 0 get cb_n 3 524288 0
500if lt fdi 0
501un_die un_fail_io 1
502end
503un_tbpath dst_suf
504fdo = fopen cb_pb 0 get cb_n 4 525377 420
505if lt fdo 0
506z0 = fclose int fdi
507un_die un_fail_io 1
508end
509while true bound 9223372036854775807
510k = read int fdi cb_chunk1 0 65536
511if lt k 0
512un_die un_fail_io 1
513end
514if eq k 0
515break
516end
517o = ulong 0
518kl = ulong k
519while lt o kl bound 65537
520w = write int fdo cb_chunk1 o sub kl o
521if le w 0
522un_die un_fail_io 1
523end
524o = add o ulong w
525end
526end
527z1 = fclose int fdi
528z2 = fclose int fdo
529end
530
531fn un_run_native cmd view uchar * in_suf view uchar * out_suf view uchar * to void
532un_tpath in_suf
533fi = fopen cb_pa 0 get cb_n 3 524288 0
534if lt fi 0
535un_die un_fail_io 1
536end
537un_tbpath out_suf
538z0 = unlink cb_pb 0 get cb_n 4
539fo = fopen cb_pb 0 get cb_n 4 524865 420
540if lt fo 0
541z1 = fclose int fi
542un_die un_fail_io 1
543end
544cb_av_clr
545un_tpath un_tnat
546cb_av_push_pa
547cb_av_push_tx cmd
548rc = cb_spawn_fds int fi int fo -1 false
549if ne rc 0
550un_die un_fail_io 1
551end
552end
553
554fn un_run_native_app cmd view uchar * in_suf view uchar * out_suf view uchar * to void
555un_tpath in_suf
556fi = fopen cb_pa 0 get cb_n 3 524288 0
557if lt fi 0
558un_die un_fail_io 1
559end
560un_tbpath out_suf
561fo = fopen cb_pb 0 get cb_n 4 525377 420
562if lt fo 0
563z1 = fclose int fi
564un_die un_fail_io 1
565end
566cb_av_clr
567un_tpath un_tnat
568cb_av_push_pa
569cb_av_push_tx cmd
570rc = cb_spawn_fds int fi int fo -1 false
571if ne rc 0
572un_die un_fail_io 1
573end
574end
575
576fn un_is_ident_eq c uchar to bool
577if and ge c 48 le c 57
578ret true
579end
580if and ge c 65 le c 90
581ret true
582end
583if and ge c 97 le c 122
584ret true
585end
586if or eq c 95 eq c 61
587ret true
588end
589ret false
590end
591
592fn un_is_alnum_u c uchar to bool
593if and ge c 48 le c 57
594ret true
595end
596if and ge c 65 le c 90
597ret true
598end
599if and ge c 97 le c 122
600ret true
601end
602ret eq c 95
603end
604
605fn un_rb_is_ombr i ulong to bool
606if ne get cb_rb i 111
607ret false
608end
609if ne get cb_rb add i 1 109
610ret false
611end
612if ne get cb_rb add i 2 98
613ret false
614end
615ret eq get cb_rb add i 3 114
616end
617
618note Pure-Omega equivalent of:
619note sed -E 's/(^|\n|[^[:alnum:]_=])ombr(2?_[[:alnum:]_]+)/\1ombr_leaf\2/g'
620note Reads leaf.c into cb_rb and appends transformed bytes to omega_om_units.c
621fn un_append_leaf_ns to void
622un_tpath un_tleafc
623if not cb_read_pa
624un_die un_fail_io 1
625end
626n = get cb_n 0
627cb_wb_clr
628i = ulong 0
629while lt i n bound 9223372036854775807
630matched = false
631if le add i 6 n
632if un_rb_is_ombr i
633note check left boundary: start-of-line, or \n escape, or non-[[:alnum:]_=]
634lb = false
635if eq i 0
636lb = true
637else
638prev = get cb_rb sub i 1
639if eq prev 10
640lb = true
641else
642if not un_is_ident_eq prev
643lb = true
644else
645if and ge i 2 and eq get cb_rb sub i 2 92 eq prev 110
646lb = true
647end
648end
649end
650end
651if lb
652note check right side: (2?_[[:alnum:]_]+)
653k = add i 4
654if and lt k n eq get cb_rb k 50
655k = add k 1
656end
657if and lt add k 1 n and eq get cb_rb k 95 un_is_alnum_u get cb_rb add k 1
658matched = true
659end
660end
661end
662end
663if matched
664cb_wb_tx un_ombr_leaf
665i = add i 4
666else
667cb_wb_ch get cb_rb i
668i = add i 1
669end
670end
671un_tpath un_tc2
672if not cb_write_wb_pa 420
673un_die un_fail_io 1
674end
675un_append_file_to_file un_tc2 un_f_c
676end
677
678fn un_process_one to void
679un_compose_unit
680un_derive_name
681is_om2 = un_detect_om2
682un_tpath un_tsrc
683if not cb_write_wb_pa 420
684un_die un_fail_io 1
685end
686note Hash composed source
687if not cb_sha_file_pa
688un_die un_fail_io 1
689end
690note Save source hex in cb_pc[0..64) temporarily? No, use un_write_ident after compile; copy hex into cb_chunk2[0..64)
691for j ulong 64
692put cb_chunk2 j get cb_shex j
693end
694note Compile source with pinned OMC
695for i ulong get un_omcl 0 bound 4096
696put cb_pc i get un_omc i
697end
698un_tpath un_tsrc
699un_tbpath un_tbin
700rc = cb_run_omc get un_omcl 0 420 -1
701if ne rc 0
702un_die un_fail_io 1
703end
704note Build framed u.in: src + \0 + %08d(bin_len) + bin + (if om2: "omega-unit NAME OMC_PIN\n")
705un_tpath un_tbin
706bsz = cb_file_size_pa
707if lt bsz 0
708un_die un_fail_io 1
709end
710cb_wb_clr
711un_tpath un_tsrc
712if not cb_append_pa_to_wb
713un_die un_fail_io 1
714end
715cb_wb_ch 0
716note 8-digit zero-padded decimal bsz
717d = ulong bsz
718for q ulong 8
719put cb_numbuf sub 7 q uchar add 48 rem d 10
720d = div d 10
721end
722for q ulong 8
723cb_wb_ch get cb_numbuf q
724end
725un_tpath un_tbin
726if not cb_append_pa_to_wb
727un_die un_fail_io 1
728end
729if is_om2
730cb_wb_tx un_tag_pre
731for j ulong get un_namel 0 bound 256
732cb_wb_ch get un_name j
733end
734cb_wb_ch 32
735for j ulong 64
736cb_wb_ch get un_omcpin j
737end
738cb_wb_ch 10
739end
740un_tpath un_tuin
741if not cb_write_wb_pa 420
742un_die un_fail_io 1
743end
744un_append_file_to_file un_tuin un_tunits
745if un_is_leaf
746un_append_file_to_file un_tuin un_tleaf
747put un_has_leaf 0 1
748else
749un_append_file_to_file un_tuin un_thost
750put un_has_host 0 1
751end
752if un_is_fs
753un_append_file_to_file un_tuin un_tfs
754put un_has_fs 0 1
755end
756note Append ident line
757cb_wb_clr
758cb_wb_tx un_id_1
759for j ulong get un_namel 0 bound 256
760cb_wb_ch get un_name j
761end
762cb_wb_tx un_id_2
763if is_om2
764cb_wb_ch 50
765else
766cb_wb_ch 49
767end
768cb_wb_tx un_id_3
769if is_om2
770cb_wb_tx un_om2_p
771else
772cb_wb_tx un_om1_p
773end
774cb_wb_tx un_id_4
775for j ulong 64
776cb_wb_ch get cb_chunk2 j
777end
778cb_wb_tx un_id_5
779for j ulong 64
780cb_wb_ch get un_omcpin j
781end
782cb_wb_tx un_id_6
783for j ulong get un_curl 0 bound 4096
784cb_wb_ch get un_cur j
785end
786cb_wb_ch 10
787un_tpath un_tc1
788if not cb_write_wb_pa 420
789un_die un_fail_io 1
790end
791un_append_file_to_file un_tc1 un_f_id
792end
793
794fn un_check_one name view uchar * to bool
795cb_pa_clr
796for i ulong get un_tmpl 0 bound 4096
797cb_pa_ch get un_tmp i
798end
799cb_pa_tx name
800un_dpath name
801if not cb_cmp_pa_pb
802cb_out un_fail_diff1
803cb_wbuf_pb 1
804cb_out un_fail_diff2
805ret false
806end
807ret true
808end
809
810fn un_install_one name view uchar * to void
811cb_pa_clr
812for i ulong get un_tmpl 0 bound 4096
813cb_pa_ch get un_tmp i
814end
815cb_pa_tx name
816un_dpath name
817if not cb_copy_pa_to_pb 420
818un_die un_fail_io 1
819end
820end
821
822fn un_load_pins to void
823if cb_getenv un_env_omcpin
824if eq get cb_n 4 64
825for j ulong 64
826put un_omcpin j get cb_pb j
827end
828else
829un_die un_nr_omc 3
830end
831else
832cb_pa_set un_pin_file
833if not cb_read_pa
834un_die un_nr_omc 3
835end
836if lt get cb_n 0 64
837un_die un_nr_omc 3
838end
839for j ulong 64
840put un_omcpin j get cb_rb j
841end
842end
843if cb_getenv un_env_natpin
844if eq get cb_n 4 64
845for j ulong 64
846put un_natpin j get cb_pb j
847end
848else
849un_die un_nr_nat 3
850end
851else
852for j ulong 64
853put un_natpin j get un_def_natpin j
854end
855end
856end
857
858fn un_load_ulist to void
859if cb_getenv un_env_units
860vlen = get cb_n 4
861if gt vlen 0
862ze1 = enlarge un_ulist vlen
863if ne ze1 0
864un_die un_fail_io 1
865end
866for j ulong vlen bound 65536
867put un_ulist j get cb_pb j
868end
869put un_uln 0 vlen
870ret
871end
872end
873dl = len un_def_units
874ze2 = enlarge un_ulist dl
875if ne ze2 0
876un_die un_fail_io 1
877end
878for j ulong dl bound 65536
879put un_ulist j get un_def_units j
880end
881put un_uln 0 dl
882end
883
884fn un_is_ws c uchar to bool
885if eq c 32
886ret true
887end
888if eq c 9
889ret true
890end
891ret eq c 10
892end
893
894fn un_skip_ws p ulong uln ulong to ulong
895x = p
896while lt x uln bound 9223372036854775807
897if un_is_ws get un_ulist x
898x = add x 1
899else
900break
901end
902end
903ret x
904end
905
906fn un_scan_word p ulong uln ulong to ulong
907x = p
908while lt x uln bound 9223372036854775807
909if un_is_ws get un_ulist x
910break
911end
912x = add x 1
913end
914ret x
915end
916
917fn un_process_all to void
918un_load_ulist
919uln = get un_uln 0
920p = un_skip_ws 0 uln
921while lt p uln bound 9223372036854775807
922q = un_scan_word p uln
923ulen = sub q p
924for i ulong ulen bound 4096
925put un_cur i get un_ulist add p i
926end
927put un_curl 0 ulen
928un_process_one
929p = un_skip_ws q uln
930end
931end
932
933fn un_init_tmp to void
934cb_pa_set un_tdir
935x = ulong getpid
936k = ulong 32
937for j ulong 21
938k = sub k 1
939put cb_numbuf k uchar add 48 rem x 10
940x = div x 10
941if eq x 0
942break
943end
944end
945for j ulong sub 32 k bound 32
946cb_pa_ch get cb_numbuf add k j
947end
948for i ulong get cb_n 3 bound 4096
949put un_tmp i get cb_pa i
950end
951put un_tmpl 0 get cb_n 3
952if not cb_mkdir_p_pa
953un_die un_fail_io 1
954end
955cb_wb_clr
956un_tpath un_tunits
957z0 = cb_write_wb_pa 420
958un_tpath un_thost
959z0 = cb_write_wb_pa 420
960un_tpath un_tleaf
961z0 = cb_write_wb_pa 420
962un_tpath un_tfs
963z0 = cb_write_wb_pa 420
964un_tpath un_f_id
965z0 = cb_write_wb_pa 420
966un_tpath un_f_c
967z0 = cb_write_wb_pa 420
968put un_has_host 0 0
969put un_has_leaf 0 0
970put un_has_fs 0 0
971end
972
973fn un_compile_native to void
974for i ulong get un_omcl 0 bound 4096
975put cb_pc i get un_omc i
976end
977cb_pa_clr
978for i ulong get un_brl 0 bound 4096
979cb_pa_ch get un_br i
980end
981cb_pa_tx un_nat_rel
982un_tbpath un_tnat
983if ne cb_run_omc get un_omcl 0 493 -1 0
984un_die un_fail_io 1
985end
986end
987
988fn un_emit_all to void
989if ne get un_has_host 0 0
990un_run_native un_cmd_c un_thost un_f_c
991un_run_native_app un_cmd_apic un_thost un_f_c
992end
993if ne get un_has_leaf 0 0
994un_run_native un_cmd_freest un_tleaf un_tleafc
995un_run_native_app un_cmd_fapic un_tleaf un_tleafc
996un_append_leaf_ns
997end
998un_run_native un_cmd_h un_tunits un_f_h
999un_run_native un_cmd_apih un_tunits un_f_apih
1000if ne get un_has_fs 0 0
1001un_run_native un_cmd_freest un_tfs un_f_fs
1002un_run_native_app un_cmd_fapic un_tfs un_f_fs
1003else
1004cb_wb_clr
1005cb_wb_tx un_nofs
1006un_tpath un_f_fs
1007z6 = cb_write_wb_pa 420
1008end
1009end
1010
1011fn un_cleanup to void
1012if eq get un_tmpl 0 0
1013ret
1014end
1015cb_pa_clr
1016for i ulong get un_tmpl 0 bound 4096
1017cb_pa_ch get un_tmp i
1018end
1019cb_rm_flat_pa
1020put un_tmpl 0 0
1021end
1022
1023fn main to int
1024put un_chk 0 0
1025if ge argcnt 2
1026if cb_pa_arg 1
1027if cb_pa_eq un_fcheck
1028put un_chk 0 1
1029end
1030end
1031end
1032if not cb_getenv un_env_omc
1033cb_out un_nr_env
1034ret 3
1035end
1036if eq get cb_n 4 0
1037cb_out un_nr_env
1038ret 3
1039end
1040for i ulong get cb_n 4 bound 4096
1041put un_omc i get cb_pb i
1042end
1043put un_omcl 0 get cb_n 4
1044if not cb_getenv un_env_br
1045cb_out un_nr_env
1046ret 3
1047end
1048if eq get cb_n 4 0
1049cb_out un_nr_env
1050ret 3
1051end
1052for i ulong get cb_n 4 bound 4096
1053put un_br i get cb_pb i
1054end
1055put un_brl 0 get cb_n 4
1056if cb_getenv un_env_dest
1057if gt get cb_n 4 0
1058for i ulong get cb_n 4 bound 4096
1059put un_dest i get cb_pb i
1060end
1061put un_destl 0 get cb_n 4
1062end
1063end
1064if eq get un_destl 0 0
1065for i ulong len un_def_dest bound 4096
1066put un_dest i get un_def_dest i
1067end
1068put un_destl 0 len un_def_dest
1069end
1070
1071un_load_pins
1072cb_pa_clr
1073for i ulong get un_omcl 0 bound 4096
1074cb_pa_ch get un_omc i
1075end
1076if not cb_sha_file_pa
1077cb_out un_nr_omc
1078ret 3
1079end
1080if not un_hex_eq_pin true
1081cb_out un_nr_omc
1082ret 3
1083end
1084cb_pa_clr
1085for i ulong get un_brl 0 bound 4096
1086cb_pa_ch get un_br i
1087end
1088cb_pa_tx un_nat_rel
1089if not cb_sha_file_pa
1090cb_out un_nr_nat
1091ret 3
1092end
1093if not un_hex_eq_pin false
1094cb_out un_nr_nat
1095ret 3
1096end
1097
1098un_init_tmp
1099un_compile_native
1100un_process_all
1101un_emit_all
1102
1103if ne get un_chk 0 0
1104bad = ulong 0
1105if not un_check_one un_f_c
1106bad = 1
1107end
1108if not un_check_one un_f_h
1109bad = 1
1110end
1111if not un_check_one un_f_apih
1112bad = 1
1113end
1114if not un_check_one un_f_id
1115bad = 1
1116end
1117if not un_check_one un_f_fs
1118bad = 1
1119end
1120un_cleanup
1121if ne bad 0
1122ret 1
1123end
1124cb_out un_pass_chk
1125ret 0
1126end
1127
1128un_install_one un_f_c
1129un_install_one un_f_h
1130un_install_one un_f_apih
1131un_install_one un_f_id
1132un_install_one un_f_fs
1133un_cleanup
1134cb_out un_wrote1
1135r = write 1 un_dest 0 get un_destl 0
1136cb_out un_wrote2
1137ret 0
1138end