]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/tree/normalization/normalization-tests.factor
Merge branch 'master' into new_optimizer
[factor.git] / basis / compiler / tree / normalization / normalization-tests.factor
1 IN: compiler.tree.normalization.tests
2 USING: compiler.tree.builder compiler.tree.normalization
3 compiler.tree sequences accessors tools.test kernel math ;
4
5 \ count-introductions must-infer
6 \ normalize must-infer
7
8 [ 3 ] [ [ 3drop 1 2 3 ] build-tree count-introductions ] unit-test
9
10 [ 4 ] [ [ 3drop 1 2 3 3drop drop ] build-tree count-introductions ] unit-test
11
12 [ 3 ] [ [ [ drop ] [ 2drop 3 ] if ] build-tree count-introductions ] unit-test
13
14 [ 2 ] [ [ 3 [ drop ] [ 2drop 3 ] if ] build-tree count-introductions ] unit-test
15
16 : foo ( -- ) swap ; inline recursive
17
18 : recursive-inputs ( nodes -- n )
19     [ #recursive? ] find nip child>> first in-d>> length ;
20
21 [ 0 2 ] [
22     [ foo ] build-tree
23     [ recursive-inputs ]
24     [ normalize recursive-inputs ] bi
25 ] unit-test
26
27 [ ] [ [ [ 1 ] [ 2 ] if + * ] build-tree normalize drop ] unit-test
28
29 DEFER: bbb
30 : aaa ( x -- ) dup [ dup >r bbb r> aaa ] [ drop ] if ; inline recursive
31 : bbb ( x -- ) >r drop 0 r> aaa ; inline recursive
32
33 [ ] [ [ bbb ] build-tree normalize drop ] unit-test
34
35 : ccc ( -- ) ccc drop 1 ; inline recursive
36
37 [ ] [ [ ccc ] build-tree normalize drop ] unit-test
38
39 DEFER: eee
40 : ddd ( -- ) eee ; inline recursive
41 : eee ( -- ) swap ddd ; inline recursive
42
43 [ ] [ [ eee ] build-tree normalize drop ] unit-test