2008-07-20 05:24:37 -04:00
|
|
|
! Copyright (C) 2008 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-07-27 23:47:40 -04:00
|
|
|
USING: fry kernel accessors sequences sequences.deep
|
|
|
|
compiler.tree ;
|
2008-07-20 05:24:37 -04:00
|
|
|
IN: compiler.tree.combinators
|
|
|
|
|
2008-07-27 21:25:42 -04:00
|
|
|
: each-node ( nodes quot -- )
|
|
|
|
dup dup '[
|
|
|
|
, [
|
|
|
|
dup #branch? [
|
|
|
|
children>> [ , each-node ] each
|
|
|
|
] [
|
|
|
|
dup #recursive? [
|
|
|
|
child>> , each-node
|
|
|
|
] [ drop ] if
|
|
|
|
] if
|
|
|
|
] bi
|
|
|
|
] each ; inline
|
2008-07-27 23:47:40 -04:00
|
|
|
|
|
|
|
: map-nodes ( nodes quot: ( node -- node' ) -- nodes )
|
|
|
|
dup dup '[
|
|
|
|
@
|
|
|
|
dup #branch? [
|
|
|
|
[ [ , map-nodes ] map ] change-children
|
|
|
|
] [
|
|
|
|
dup #recursive? [
|
|
|
|
[ , map-nodes ] change-child
|
|
|
|
] when
|
|
|
|
] if
|
|
|
|
] map flatten ; inline recursive
|