on 99bdb21 help sign in
504 lines 7.6 kB history raw
1+++
2title = "5a: Compiler Utilities"
3weight = 43
4template = "doc.html"
5+++
7These functions are used internally by the compiler. They should not be used
8directly and are only listed here for completeness.
10## `++musk`
12Nock with block set
14#### Source
16This function is extremely large, please refer to `hoon.hoon` for the source.
18---
20## `++bool`
22Make loobean
24#### Source
26```hoon
27++ bool `type`(fork [%atom %f `0] [%atom %f `1] ~)
28```
30---
32## `++cell`
34Make `%cell` type
36#### Source
38```hoon
39++ cell
40 ~/ %cell
41 |= [hed=type tal=type]
42 ^- type
43 ?:(=(%void hed) %void ?:(=(%void tal) %void [%cell hed tal]))
44```
46---
48## `++core`
50Make `%core` type
52#### Source
54```hoon
55++ core
56 ~/ %core
57 |= [pac=type con=coil]
58 ^- type
59 ?:(=(%void pac) %void [%core pac con])
60```
62---
64## `++hint`
66Make `%hint` type
68#### Source
70```hoon
71++ hint
72 |= [p=(pair type note) q=type]
73 ^- type
74 ?: =(%void q) %void
75 ?: =(%noun q) %noun
76 [%hint p q]
77```
79---
81## `++face`
83Make `%face` type
85#### Source
87```hoon
88++ face
89 ~/ %face
90 |= [giz=$@(term tune) der=type]
91 ^- type
92 ?: =(%void der)
93 %void
94 [%face giz der]
95```
97---
99## `++fork`
101Make `%fork` type
103#### Source
105```hoon
106++ fork
107 ~/ %fork
108 |= yed=(list type)
109 =| lez=(set type)
110 |- ^- type
111 ?~ yed
112 ?~ lez %void
113 ?: ?=([* ~ ~] lez) n.lez
114 [%fork lez]
115 %= $
116 yed t.yed
117 lez
118 ?: =(%void i.yed) lez
119 ?: ?=([%fork *] i.yed) (~(uni in lez) p.i.yed)
120 (~(put in lez) i.yed)
121 ==
122```
124---
126## `++cove`
128Extract [0 *] axis
130#### Source
132```hoon
133++ cove
134 |= nug=nock
135 ?- nug
136 [%0 *] p.nug
137 [%11 *] $(nug q.nug)
138 * ~_(leaf+"cove" !!)
139 ==
140```
142---
144## `++comb`
146Combine two formulas
148#### Source
150```hoon
151++ comb
152 ~/ %comb
153 |= [mal=nock buz=nock]
154 ^- nock
155 ?: ?&(?=([%0 *] mal) !=(0 p.mal))
156 ?: ?&(?=([%0 *] buz) !=(0 p.buz))
157 [%0 (peg p.mal p.buz)]
158 ?: ?=([%2 [%0 *] [%0 *]] buz)
159 [%2 [%0 (peg p.mal p.p.buz)] [%0 (peg p.mal p.q.buz)]]
160 [%7 mal buz]
161 ?: ?=([^ [%0 %1]] mal)
162 [%8 p.mal buz]
163 ?: =([%0 %1] buz)
164 mal
165 [%7 mal buz]
166```
168---
170## `++cond`
172`?:` compile
174#### Source
176```hoon
177++ cond
178 ~/ %cond
179 |= [pex=nock yom=nock woq=nock]
180 ^- nock
181 ?- pex
182 [%1 %0] yom
183 [%1 %1] woq
184 * [%6 pex yom woq]
185 ==
186```
188---
190## `++cons`
192Make formula cell
194#### Source
196```hoon
197++ cons
198 ~/ %cons
199 |= [vur=nock sed=nock]
200 ^- nock
201 :: this optimization can remove crashes which are essential
202 ::
203 :: ?: ?=([[%0 *] [%0 *]] +<)
204 :: ?: ?&(=(+(p.vur) p.sed) =((div p.vur 2) (div p.sed 2)))
205 :: [%0 (div p.vur 2)]
206 :: [vur sed]
207 ?: ?=([[%1 *] [%1 *]] +<)
208 [%1 p.vur p.sed]
209 [vur sed]
210```
212---
214## `++fitz`
216Aura compatibility
218#### Source
220```hoon
221++ fitz
222 ~/ %fitz
223 |= [yaz=term wix=term]
224 =+ ^= fiz
225 |= mot=@ta ^- [p=@ q=@ta]
226 =+ len=(met 3 mot)
227 ?: =(0 len)
228 [0 %$]
229 =+ tyl=(rsh [3 (dec len)] mot)
230 ?: &((gte tyl 'A') (lte tyl 'Z'))
231 [(sub tyl 64) (end [3 (dec len)] mot)]
232 [0 mot]
233 =+ [yoz=(fiz yaz) wux=(fiz wix)]
234 ?& ?| =(0 p.yoz)
235 =(0 p.wux)
236 &(!=(0 p.wux) (lte p.wux p.yoz))
237 ==
238 |- ?| =(%$ p.yoz)
239 =(%$ p.wux)
240 ?& =((end 3 p.yoz) (end 3 p.wux))
241 $(p.yoz (rsh 3 p.yoz), p.wux (rsh 3 p.wux))
242 ==
243 ==
244 ==
245```
247---
249## `++flan`
251Loobean &
253#### Source
255```hoon
256++ flan
257 ~/ %flan
258 |= [bos=nock nif=nock]
259 ^- nock
260 ?: =(bos nif) bos
261 ?: =([%0 0] bos) nif
262 ?: =([%0 0] nif) bos
263 ?- bos
264 [%1 %1] bos
265 [%1 %0] nif
266 *
267 ?- nif
268 [%1 %1] nif
269 [%1 %0] bos
270 * [%6 bos nif [%1 1]]
271 ==
272 ==
273```
275---
277## `++flip`
279Loobean negation
281#### Source
283```hoon
284++ flip
285 ~/ %flip
286 |= dyr=nock
287 ?: =([%0 0] dyr) dyr
288 [%6 dyr [%1 1] [%1 0]]
289```
291---
293## `++flor`
295Loobean |
297#### Source
299```hoon
300++ flor
301 ~/ %flor
302 |= [bos=nock nif=nock]
303 ^- nock
304 ?: =(bos nif) bos
305 ?: =([%0 0] bos) nif
306 ?: =([%0 0] nif) bos
307 ?- bos
308 [%1 %1] nif
309 [%1 %0] bos
310 *
311 ?- nif
312 [%1 %1] bos
313 [%1 %0] nif
314 * [%6 bos [%1 0] nif]
315 ==
316 ==
317```
319---
321## `++hike`
323Compiler utility
325#### Source
327```hoon
328++ hike
329 ~/ %hike
330 |= [a=axis pac=(list (pair axis nock))]
331 |^ =/ rel=(map axis nock) (roll pac insert)
332 =/ ord=(list axis) (sort ~(tap in ~(key by rel)) gth)
333 |- ^- nock
334 ?~ ord
335 [%0 a]
336 =/ b=axis i.ord
337 =/ c=nock (~(got by rel) b)
338 =/ d=nock $(ord t.ord)
339 [%10 [b c] d]
340 ::
341 ++ contains
342 |= [container=axis contained=axis]
343 ^- ?
344 =/ big=@ (met 0 container)
345 =/ small=@ (met 0 contained)
346 ?: (lte small big) |
347 =/ dif=@ (sub small big)
348 =(container (rsh [0 dif] contained))
349 ::
350 ++ parent
351 |= a=axis
352 `axis`(rsh 0 a)
353 ::
354 ++ sibling
355 |= a=axis
356 ^- axis
357 ?~ (mod a 2)
358 +(a)
359 (dec a)
360 ::
361 ++ insert
362 |= [e=[axe=axis fol=nock] n=(map axis nock)]
363 ^- (map axis nock)
364 ?: =/ a=axis axe.e
365 |- ^- ?
366 ?: =(1 a) |
367 ?: (~(has by n) a)
368 &
369 $(a (parent a))
370 :: parent already in
371 n
372 =. n
373 :: remove children
374 %+ roll ~(tap by n)
375 |= [[axe=axis fol=nock] m=_n]
376 ?. (contains axe.e axe) m
377 (~(del by m) axe)
378 =/ sib (sibling axe.e)
379 =/ un (~(get by n) sib)
380 ?~ un (~(put by n) axe.e fol.e)
381 :: replace sibling with parent
382 %= $
383 n (~(del by n) sib)
384 e :- (parent sib)
385 ?: (gth sib axe.e)
386 (cons fol.e u.un)
387 (cons u.un fol.e)
388 ==
389 --
390```
392---
394## `++jock`
396Compiler utility
398#### Source
400```hoon
401++ jock
402 |= rad=?
403 |= lot=coin ^- hoon
404 ?- -.lot
405 ~
406 ?:(rad [%rock p.lot] [%sand p.lot])
407 ::
408 %blob
409 ?: rad
410 [%rock %$ p.lot]
411 ?@(p.lot [%sand %$ p.lot] [$(p.lot -.p.lot) $(p.lot +.p.lot)])
412 ::
413 %many
414 [%cltr (turn p.lot |=(a=coin ^$(lot a)))]
415 ==
416```
418---
420## `++look`
422Compiler utility
424#### Source
426```hoon
427++ look
428 ~/ %look
429 |= [cog=term dab=(map term hoon)]
430 =+ axe=1
431 |- ^- (unit [p=axis q=hoon])
432 ?- dab
433 ~ ~
434 ::
435 [* ~ ~]
436 ?:(=(cog p.n.dab) [~ axe q.n.dab] ~)
437 ::
438 [* ~ *]
439 ?: =(cog p.n.dab)
440 [~ (peg axe 2) q.n.dab]
441 ?: (gor cog p.n.dab)
442 ~
443 $(axe (peg axe 3), dab r.dab)
444 ::
445 [* * ~]
446 ?: =(cog p.n.dab)
447 [~ (peg axe 2) q.n.dab]
448 ?: (gor cog p.n.dab)
449 $(axe (peg axe 3), dab l.dab)
450 ~
451 ::
452 [* * *]
453 ?: =(cog p.n.dab)
454 [~ (peg axe 2) q.n.dab]
455 ?: (gor cog p.n.dab)
456 $(axe (peg axe 6), dab l.dab)
457 $(axe (peg axe 7), dab r.dab)
458 ==
459```
461---
463## `++loot`
465Compiler utility
467#### Source
469```hoon
470++ loot
471 ~/ %loot
472 |= [cog=term dom=(map term tome)]
473 =+ axe=1
474 |- ^- (unit [p=axis q=hoon])
475 ?- dom
476 ~ ~
477 ::
478 [* ~ ~]
479 %+ bind (look cog q.q.n.dom)
480 |=((pair axis hoon) [(peg axe p) q])
481 ::
482 [* ~ *]
483 =+ yep=(look cog q.q.n.dom)
484 ?^ yep
485 [~ (peg (peg axe 2) p.u.yep) q.u.yep]
486 $(axe (peg axe 3), dom r.dom)
487 ::
488 [* * ~]
489 =+ yep=(look cog q.q.n.dom)
490 ?^ yep
491 [~ (peg (peg axe 2) p.u.yep) q.u.yep]
492 $(axe (peg axe 3), dom l.dom)
493 ::
494 [* * *]
495 =+ yep=(look cog q.q.n.dom)
496 ?^ yep
497 [~ (peg (peg axe 2) p.u.yep) q.u.yep]
498 =+ pey=$(axe (peg axe 6), dom l.dom)
499 ?^ pey pey
500 $(axe (peg axe 7), dom r.dom)
501 ==
502```
504---