]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/tree/normalization/introductions/introductions.factor
Fix comments to be ! not #!.
[factor.git] / basis / compiler / tree / normalization / introductions / introductions.factor
1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors compiler.tree kernel math math.order namespaces
4 sequences ;
5 IN: compiler.tree.normalization.introductions
6
7 SYMBOL: introductions
8
9 GENERIC: count-introductions* ( node -- )
10
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.
15     [
16         0 introductions set
17         [ count-introductions* ] each
18         introductions get
19     ] with-scope ;
20
21 : introductions+ ( n -- ) introductions [ + ] change ;
22
23 M: #introduce count-introductions*
24     out-d>> length introductions+ ;
25
26 M: #branch count-introductions*
27     children>>
28     [ count-introductions ] [ max ] map-reduce
29     introductions+ ;
30
31 M: #recursive count-introductions*
32     [ label>> ] [ child>> count-introductions ] bi
33     >>introductions
34     drop ;
35
36 M: node count-introductions* drop ;