]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/tree/def-use/def-use-tests.factor
8dec477aae677d28e120845174a21985a323d321
[factor.git] / basis / compiler / tree / def-use / def-use-tests.factor
1 USING: accessors namespaces assocs kernel sequences math
2 tools.test words sets combinators.short-circuit
3 stack-checker.state compiler.tree compiler.tree.builder
4 compiler.tree.recursive compiler.tree.normalization
5 compiler.tree.propagation compiler.tree.cleanup
6 compiler.tree.def-use arrays kernel.private sorting math.order
7 binary-search compiler.tree.checker ;
8 IN: compiler.tree.def-use.tests
9
10 [ t ] [
11     [ 1 2 3 ] build-tree compute-def-use drop
12     def-use get {
13         [ assoc-size 3 = ]
14         [ values [ uses>> [ #return? ] all? ] all? ]
15     } 1&&
16 ] unit-test
17
18 : test-def-use ( quot -- )
19     build-tree
20     analyze-recursive
21     normalize
22     propagate
23     cleanup-tree
24     compute-def-use
25     check-nodes ;
26
27 : too-deep ( a b -- c )
28     dup [ drop ] [ 2dup too-deep too-deep drop ] if ; inline recursive
29
30 [ ] [
31     [ too-deep ]
32     build-tree
33     analyze-recursive
34     normalize
35     compute-def-use
36     check-nodes
37 ] unit-test
38
39 ! compute-def-use checks for SSA violations, so we use that to
40 ! ensure we generate some common patterns correctly.
41 {
42     [ [ drop ] each-integer ]
43     [ [ 2drop ] curry each-integer ]
44     [ [ 1 ] [ 2 ] if drop ]
45     [ [ 1 ] [ dup ] if ]
46     [ [ 1 ] [ dup ] if drop ]
47     [ { array } declare swap ]
48     [ [ ] curry call ]
49     [ [ 1 ] [ 2 ] compose call + ]
50     [ [ 1 ] 2 [ + ] curry compose call + ]
51     [ [ 1 ] [ call 2 ] curry call + ]
52     [ [ 1 ] [ 2 ] compose swap [ 1 ] [ 2 ] if + * ]
53     [ dup slice? [ dup array? [ ] [ ] if ] [ ] if ]
54     [ dup [ drop f ] [ "A" throw ] if ]
55     [ [ <=> ] sort ]
56     [ [ <=> ] with search ]
57 } [
58     [ ] swap [ test-def-use ] curry unit-test
59 ] each