interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / om / site / build.om

212 lines · 3326 bytes Raw Blame History
1note Native build conductor: ./build-tool MODULE_MANIFEST OUTPUT_BINARY
2note Run from the repository root. The pinned omc is the sole compiler dependency.
3note Manifest is newline-separated relative .om source paths. One OM-2 directive is prepended.
4note Compilation writes only the requested new output; a failed compile removes that incomplete file.
5global bline uchar 4096
6global blen ulong 1
7global bout uchar 4096
8global boutn ulong 1
9global bargs uchar 4096
10global bbuf uchar 65536
11global bstat uchar 4
12text bcomp "om/site/omc"
13text bunit "build/site-unit.om"
14text bdir "build"
15text bmode "om2\n"
16text bfail "SITE-BUILD refused input or failed I/O\n"
17text bok "SITE-BUILD compiled\n"
18
19fn build_fail to void
20n = write 2 bfail 0 len bfail
21exit 80
22end
23
24fn build_write fd int n ulong to void
25p = ulong 0
26while lt p n bound 65536
27k = write fd bbuf p sub n p
28if le k 0
29build_fail
30end
31p = add p ulong k
32end
33end
34
35fn build_source fd int to void
36n = get blen 0
37if eq n 0
38build_fail
39end
40if eq get bline 0 47
41build_fail
42end
43for i ulong n
44c = get bline i
45if or eq c 0 eq c 92
46build_fail
47end
48if eq c 46
49if lt add i 1 n
50if eq get bline add i 1 46
51build_fail
52end
53end
54end
55end
56src = fopen bline 0 n 0 0
57if lt src 0
58build_fail
59end
60more = true
61while more bound 65536
62k = read int src bbuf 0 len bbuf
63if lt k 0
64build_fail
65end
66if eq k 0
67more = false
68else
69build_write fd ulong k
70end
71end
72rc = fclose int src
73if ne rc 0
74build_fail
75end
76put bbuf 0 10
77build_write fd 1
78put blen 0 0
79end
80
81fn build_manifest fd int mf int to void
82one = new uchar 1 0
83more = true
84while more bound 65536
85k = read mf one 0 1
86if lt k 0
87build_fail
88end
89if eq k 0
90if ne get blen 0 0
91build_fail
92end
93more = false
94else
95c = get one 0
96if eq c 10
97build_source fd
98else
99n = get blen 0
100if ge n len bline
101build_fail
102end
103put bline n c
104put blen 0 add n 1
105end
106end
107end
108end
109
110fn build_child infd int outfd int to void
111rc = dupfd infd 0 0
112if lt rc 0
113build_fail
114end
115rc = dupfd outfd 1 0
116if lt rc 0
117build_fail
118end
119put bargs 0 1
120put bargs 1 0
121put bargs 2 uchar len bcomp
122put bargs 3 0
123for i ulong len bcomp
124put bargs add i 4 get bcomp i
125end
126rc = execprog bargs 0 add len bcomp 4
127build_fail
128end
129
130fn build_compile to int
131inf = fopen bunit 0 len bunit 0 0
132if lt inf 0
133build_fail
134end
135outf = fopen bout 0 get boutn 0 193 493
136if lt outf 0
137build_fail
138end
139pid = fork
140if lt pid 0
141build_fail
142end
143if eq pid 0
144build_child int inf int outf
145end
146rc = fclose int inf
147if ne rc 0
148build_fail
149end
150rc = fclose int outf
151if ne rc 0
152build_fail
153end
154rc = waitpid int pid bstat 0 len bstat 0
155if ne rc pid
156build_fail
157end
158status = or uint get bstat 0 shl uint get bstat 1 8
159if ne status 0
160rc = unlink bout 0 get boutn 0
161if ne rc 0
162build_fail
163end
164ret 81
165end
166n = write 1 bok 0 len bok
167if ne n long len bok
168build_fail
169end
170ret 0
171end
172
173fn main to int
174if ne argcnt 3
175build_fail
176end
177n = argread 1 bline 0 len bline
178if le n 0
179build_fail
180end
181mf = fopen bline 0 ulong n 0 0
182if lt mf 0
183build_fail
184end
185n = argread 2 bout 0 len bout
186if le n 0
187build_fail
188end
189put boutn 0 ulong n
190rc = makedir bdir 0 len bdir 493
191if and ne rc 0 ne rc -17
192build_fail
193end
194unit = fopen bunit 0 len bunit 577 420
195if lt unit 0
196build_fail
197end
198n = write int unit bmode 0 len bmode
199if ne n long len bmode
200build_fail
201end
202build_manifest int unit int mf
203rc = fclose int mf
204if ne rc 0
205build_fail
206end
207rc = fclose int unit
208if ne rc 0
209build_fail
210end
211ret build_compile
212end