1 ! Copyright (C) 2008 Slava Pestov.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: accessors compiler.tree kernel math math.order namespaces
5 IN: compiler.tree.normalization.introductions
9 GENERIC: count-introductions* ( node -- )
11 : count-introductions ( nodes -- n )
12 ! Note: we use each, not each-node, since the #branch
13 ! method recurses into children directly and we don't
14 ! recurse into #recursive at all.
17 [ count-introductions* ] each
21 : introductions+ ( n -- ) introductions [ + ] change ;
23 M: #introduce count-introductions*
24 out-d>> length introductions+ ;
26 M: #branch count-introductions*
28 [ count-introductions ] [ max ] map-reduce
31 M: #recursive count-introductions*
32 [ label>> ] [ child>> count-introductions ] bi
36 M: node count-introductions* drop ;