1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: assocs fry kernel accessors sequences sequences.deep arrays
4 stack-checker.inlining namespaces compiler.tree ;
5 IN: compiler.tree.combinators
7 : each-node ( nodes quot: ( node -- ) -- )
11 children>> [ , each-node ] each
18 ] each ; inline recursive
20 : map-nodes ( nodes quot: ( node -- node' ) -- nodes )
24 [ [ , map-nodes ] map ] change-children
27 [ , map-nodes ] change-child
30 ] map flatten ; inline recursive
32 : contains-node? ( nodes quot: ( node -- ? ) -- ? )
34 , keep swap [ drop t ] [
36 children>> [ , contains-node? ] contains?
39 child>> , contains-node?
43 ] contains? ; inline recursive
45 : select-children ( seq flags -- seq' )
46 [ [ drop f ] unless ] 2map ;
48 : sift-children ( seq flags -- seq' )
49 zip [ nip ] assoc-filter keys ;
51 : (3each) [ 3array flip ] dip [ first3 ] prepose ; inline
53 : 3each ( seq1 seq2 seq3 quot -- seq ) (3each) each ; inline
55 : 3map ( seq1 seq2 seq3 quot -- seq ) (3each) map ; inline
57 : until-fixed-point ( #recursive quot: ( node -- ) -- )
58 over label>> t >>fixed-point drop
60 over label>> fixed-point>> [ 2drop ] [ until-fixed-point ] if ;