Merge pull request #3434 from urbit/jb/stir-tail-hoon

hoon: rewrites +stir using tail-recursion and +roll
This commit is contained in:
Joe Bryan 2020-09-11 13:38:48 -07:00 committed by GitHub
commit db18acb829
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5509,16 +5509,30 @@
::
++ stir
~/ %stir
|* {rud/* raq/_=>(~ |*({a/* b/*} [a b])) fel/rule}
|* [rud=* raq=_=>(~ |*([a=* b=*] [a b])) fel=rule]
~/ %fun
|= tub/nail
|= tub=nail
^- (like _rud)
=+ vex=(fel tub)
?~ q.vex
[p.vex [~ rud tub]]
=+ wag=$(tub q.u.q.vex)
?> ?=(^ q.wag)
[(last p.vex p.wag) [~ (raq p.u.q.vex p.u.q.wag) q.u.q.wag]]
::
:: lef: successful interim parse results (per .fel)
:: wag: initial accumulator (.rud in .tub at farthest success)
::
=+ ^= [lef wag]
=| lef=(list _(fel tub))
|- ^- [_lef (pair hair [~ u=(pair _rud nail)])]
=+ vex=(fel tub)
?~ q.vex
:- lef
[p.vex [~ rud tub]]
$(lef [vex lef], tub q.u.q.vex)
::
:: fold .lef into .wag, combining results with .raq
::
%+ roll lef
|= _[vex=(fel tub) wag=wag] :: q.vex is always (some)
^+ wag
:- (last p.vex p.wag)
[~ (raq p.u.+.q.vex p.u.q.wag) q.u.q.wag]
::
++ stun :: parse several times
|* {lig/{@ @} fel/rule}