interplane.Get Omega
Read in your language

babel

aien-dev/babel

Brought by drakestapleton

branch main Branches Tags History

babel / src / 30-pipe.om

613 lines · 8600 bytes Raw Blame History
1note babel 30-pipe: configuration, paths, adapter runs per unit (import, lower, Omega check, export).
2global Rt0 ulong 1
3global Rtn ulong 1
4global Isf ulong 1
5global Ot0 ulong 1
6global Otn ulong 1
7global Ad0 ulong 1
8global Adn ulong 1
9global Lg ulong 1
10global Tl0 ulong 8
11global Tln ulong 8
12global Tv0 ulong 8
13global Tvn ulong 8
14global Pg0 ulong 1
15global Pgn ulong 1
16global Nid ulong 1
17global Jsn ulong 1
18global Col ulong 1
19text AdDir "/tools/adapters/"
20text OmcRel "/build/T624/seed/seed/out/omc"
21text OmcPin "734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61"
22text Slash "/"
23text NL "\n"
24text Wk ".work/"
25text WkIn "unit.c"
26text WkUp "up.omsa"
27text WkC "c.omsa"
28text WkT "t.omsa"
29text WkErr "err.txt"
30text WkOut "out.txt"
31text WkBin "check.bin"
32text DOmega "omega/"
33text ExOm ".om"
34text ExOmsa ".omsa"
35text AdCi "c-import"
36text AdRt "retarget"
37text AdLo "lower"
38text ArgC "c"
39text ArgRs "rust"
40text ArgPy "python"
41text ArgCpp "cpp"
42text ArgZig "zig"
43text ArgGo "go"
44text AdRsE "rust-export"
45text AdPyE "python-export"
46text AdCE "c-export"
47text AdCpE "cpp-export"
48text AdZgE "zig-export"
49text AdGoE "go-export"
50text RsDup "BABEL_DUPLICATE_NAME: a unit with this name was already translated in this run; babel packages one flat namespace per target"
51text RsExit "exit "
52text RsEmpty " with empty stderr"
53text RsOmc "omc (pinned 734f0a39) refused the lowered unit: "
54text RsLow "lower refused the imported unit: "
55text RsTool "adapter environment failure (not a profile refusal): "
56text RsNoTl "target toolchain not found; export written but never built or run: "
57text Ext_rs ".rs"
58text Ext_py ".py"
59text Ext_c ".c"
60text Ext_cp ".cpp"
61text Ext_zg ".zig"
62text Ext_go ".go"
63text URs "rust/src/units/"
64text UCc "c/units/"
65text UCp "cpp/units/"
66text UZg "zig/units/"
67text UGo "go/"
68text UGoF "/calc.go"
69text UPy "/units/"
70text DPy "python/"
71text HdStd "#include <stdint.h>\n"
72
73fn bout to void
74bpl get Ot0 0 get Otn 0
75end
76
77note <out>/<s>
78fn bouts s view uchar * to void
79bout
80bc 47
81bs s
82end
83
84note <out>/.work/<s>
85fn bwk s view uchar * to void
86bout
87bc 47
88bs Wk
89bs s
90end
91
92note <adapters>/tools/adapters/<s>
93fn bad s view uchar * to void
94bpl get Ad0 0 get Adn 0
95bs AdDir
96bs s
97end
98
99fn bname u ulong to void
100bpl get Un0 u get Unn u
101end
102
103fn rset i ulong a ulong b ulong to void
104put Rio i a
105put Rio add i 1 b
106end
107
108note stdin, stdout and stderr from three .work names; argv must already hold the program
109fn rwork si view uchar * so view uchar * to void
110a = mark
111bwk si
112b = mark
113bwk so
114c = mark
115bwk WkErr
116d = mark
117rset 0 a b
118rset 2 b c
119rset 4 c d
120end
121
122note first line of .work/err.txt as the unit reason, prefixed by s
123fn errwhy u ulong s view uchar * rc ulong to void
124m = mark
125bs s
126k = mark
127bwk WkErr
128e = mark
129r = rfile k e
130reset k
131n = ulong 0
132if gt r 0
133n = ulong r
134end
135j = ulong 0
136while lt j n bound 999999
137if eq get Fb j 10
138break
139end
140j = add j 1
141end
142if gt j 400
143j = 400
144end
145if eq j 0
146bs RsExit
147bu rc
148bs RsEmpty
149else
150bfb 0 j
151end
152ureasob u m
153end
154
155fn kad s view uchar * to void
156m = mark
157bad s
158e = mark
159kob m sub e m
160reset m
161end
162
163note c-import with stdin .work/unit.c and stdout .work/up.omsa
164fn adimport to ulong
165m = mark
166rclr
167kenv
168kad AdCi
169rwork WkIn WkUp
170r = spawn
171reset m
172ret r
173end
174
175note copy .work/up.omsa to <out>/omega/<name>.omsa
176fn wkomsa u ulong to long
177m = mark
178bwk WkUp
179a = mark
180bouts DOmega
181bname u
182bs ExOmsa
183b = mark
184r = cphash m a a b
185reset m
186ret r
187end
188
189fn isrefusal rc ulong to bool
190if ge rc 65
191ret le rc 72
192end
193ret false
194end
195
196fn setst u ulong st ulong sg ulong rc ulong to void
197put Ust u st
198put Usg u sg
199put Urc u rc
200end
201
202note unit text with the adapter rename, prefixed by the S1 header
203fn bunit u ulong to void
204bs HdStd
205o = get Ut0 u
206n = get Utn u
207k = get Uno u
208bpl o k
209if not renamed u
210bs NmPfx
211end
212bpl add o k sub n k
213bc 10
214end
215
216fn renamed u ulong to bool
217o = get Un0 u
218n = get Unn u
219if plteq o n NmCalc
220ret true
221end
222ret plpre o n NmPfx
223end
224
225fn setaname u ulong to void
226m = mark
227if not renamed u
228bs NmPfx
229end
230bname u
231put Ua0 u psave m sub mark m
232put Uan u sub mark m
233reset m
234end
235
236fn dupname u ulong to bool
237for i ulong u
238if ge get Ust i 7
239if pleq get Un0 i get Unn i get Un0 u get Unn u
240ret true
241end
242end
243end
244ret false
245end
246
247note import stage: write .work/unit.c and omega/<name>.c, run c-import
248fn stimport u ulong to bool
249setaname u
250m = mark
251bunit u
252c1 = mark
253bwk WkIn
254p1 = mark
255w = wfile m c1 c1 p1
256reset c1
257r = adimport
258if ne r 0
259if isrefusal r
260setst u 2 2 r
261else
262setst u 4 2 r
263end
264if isrefusal r
265errwhy u NL r
266else
267errwhy u RsTool r
268end
269trimnl u
270reset m
271ret false
272end
273if dupname u
274setst u 3 2 0
275ureason u RsDup
276reset m
277ret false
278end
279bouts DOmega
280bname u
281bs Ext_c
282p2 = mark
283w = wfile m c1 c1 p2
284reset m
285c = wkomsa u
286ret true
287end
288
289note drop the leading newline errwhy uses as an empty prefix
290fn trimnl u ulong to void
291if gt get Urn u 0
292if eq get Pl get Ur0 u 10
293put Ur0 u add get Ur0 u 1
294put Urn u sub get Urn u 1
295end
296end
297end
298
299note <out>/omega/<name>.omsa as stdin, a .work file as stdout
300fn romsa u ulong so view uchar * to void
301a = mark
302bouts DOmega
303bname u
304bs ExOmsa
305b = mark
306bwk so
307c = mark
308bwk WkErr
309d = mark
310rset 0 a b
311rset 2 b c
312rset 4 c d
313end
314
315note lower stage: retarget c then lower NAME into omega/<name>.om, then the function-mode Omega check
316fn stlower u ulong to bool
317m = mark
318rclr
319kenv
320kad AdRt
321ktx ArgC
322romsa u WkC
323r = spawn
324reset m
325if ne r 0
326setst u 4 3 r
327errwhy u RsLow r
328ret false
329end
330r = lowerto u get Un0 u get Unn u
331if eq r 64
332r = lowerto u get Ua0 u get Uan u
333put Uw0 u get Ua0 u
334put Uwn u get Uan u
335else
336put Uw0 u get Un0 u
337put Uwn u get Unn u
338end
339if ne r 0
340setst u 4 3 r
341errwhy u RsLow r
342ret false
343end
344r = omccheck u
345if ne r 0
346setst u 4 4 r
347errwhy u RsOmc r
348ret false
349end
350ret true
351end
352
353fn lowerto u ulong no ulong nn ulong to ulong
354m = mark
355rclr
356kenv
357kad AdLo
358kpl no nn
359a = mark
360bwk WkC
361b = mark
362bouts DOmega
363bname u
364bs ExOm
365c = mark
366bwk WkErr
367d = mark
368rset 0 a b
369rset 2 b c
370rset 4 c d
371r = spawn
372reset m
373ret r
374end
375
376fn bomc to void
377bpl get Ad0 0 get Adn 0
378bs OmcRel
379end
380
381fn omccheck u ulong to ulong
382m = mark
383rclr
384krst
385k = mark
386bomc
387e = mark
388kob k sub e k
389reset k
390a = mark
391bouts DOmega
392bname u
393bs ExOm
394b = mark
395bwk WkBin
396c = mark
397bwk WkErr
398d = mark
399rset 0 a b
400rset 2 b c
401rset 4 c d
402r = spawn
403reset m
404ret r
405end
406
407note export stage for the selected target
408fn stexport u ulong to bool
409g = get Lg 0
410r = ulong 0
411if eq g 2
412r = exp2 u AdRsE ArgRs
413end
414if eq g 3
415r = exp2 u AdPyE ArgPy
416end
417if eq g 1
418r = expc u
419end
420if eq g 6
421r = exp1 u AdCpE
422end
423if eq g 5
424r = exp1 u AdZgE
425end
426if eq g 4
427r = expgo u
428end
429if ne r 0
430if isrefusal r
431setst u 2 5 r
432errwhy u NL r
433trimnl u
434else
435setst u 4 5 r
436errwhy u RsTool r
437end
438ret false
439end
440put Uid u get Nid 0
441put Nid 0 add get Nid 0 1
442setst u 7 5 0
443ret true
444end
445
446note unit output path of the selected target: <out>/<lang dir><name><ext>
447fn bupath u ulong to void
448g = get Lg 0
449if eq g 2
450bouts URs
451end
452if eq g 3
453bouts DPy
454bpl get Pg0 0 get Pgn 0
455bs UPy
456end
457if eq g 1
458bouts UCc
459end
460if eq g 6
461bouts UCp
462end
463if eq g 5
464bouts UZg
465end
466bname u
467bext
468end
469
470fn bext to void
471g = get Lg 0
472if eq g 2
473bs Ext_rs
474end
475if eq g 3
476bs Ext_py
477end
478if eq g 1
479bs Ext_c
480end
481if eq g 6
482bs Ext_cp
483end
484if eq g 5
485bs Ext_zg
486end
487end
488
489note retarget to the target, then the target exporter without arguments
490fn exp2 u ulong ad view uchar * arg view uchar * to ulong
491m = mark
492rclr
493kenv
494kad AdRt
495ktx arg
496romsa u WkT
497r = spawn
498reset m
499if ne r 0
500ret r
501end
502rclr
503kenv
504kad ad
505a = mark
506bwk WkT
507b = mark
508bupath u
509c = mark
510bwk WkErr
511d = mark
512rset 0 a b
513rset 2 b c
514rset 4 c d
515r = spawn
516reset m
517ret r
518end
519
520note exporters that read the upper envelope directly (cpp, zig)
521fn exp1 u ulong ad view uchar * to ulong
522m = mark
523rclr
524kenv
525kad ad
526a = mark
527bouts DOmega
528bname u
529bs ExOmsa
530b = mark
531bupath u
532c = mark
533bwk WkErr
534d = mark
535rset 0 a b
536rset 2 b c
537rset 4 c d
538r = spawn
539reset m
540ret r
541end
542
543note C: .work/c.omsa (retarget c from the lower stage) into c-export with the adapter name
544fn expc u ulong to ulong
545m = mark
546rclr
547kenv
548kad AdCE
549kpl get Ua0 u get Uan u
550a = mark
551bwk WkC
552b = mark
553bupath u
554c = mark
555bwk WkErr
556d = mark
557rset 0 a b
558rset 2 b c
559rset 4 c d
560r = spawn
561reset m
562ret r
563end
564
565note Go: one package-main directory per unit, go/<name>/calc.go
566fn expgo u ulong to ulong
567m = mark
568bouts UGo
569bname u
570e = mark
571q = mkdirs m e
572reset m
573rclr
574kenv
575kad AdGoE
576a = mark
577bouts DOmega
578bname u
579bs ExOmsa
580b = mark
581bouts UGo
582bname u
583bs UGoF
584c = mark
585bwk WkErr
586d = mark
587rset 0 a b
588rset 2 b c
589rset 4 c d
590r = spawn
591reset m
592ret r
593end
594
595note run every function unit through import, lower, Omega check and export
596fn pipeline to void
597for u ulong get Nu 0
598if ne get Ukd u 1
599continue
600end
601if ne get Ust u 0
602continue
603end
604progress u
605if not stimport u
606continue
607end
608if not stlower u
609continue
610end
611ok = stexport u
612end
613end