]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/tree/tuple-unboxing/tuple-unboxing-tests.factor
81ba01f1e2b0adb54e70ed0a3b009ff1a18462a6
[factor.git] / basis / compiler / tree / tuple-unboxing / tuple-unboxing-tests.factor
1 IN: compiler.tree.tuple-unboxing.tests
2 USING: tools.test compiler.tree.tuple-unboxing compiler.tree
3 compiler.tree.builder compiler.tree.recursive
4 compiler.tree.normalization compiler.tree.propagation
5 compiler.tree.cleanup compiler.tree.escape-analysis
6 compiler.tree.tuple-unboxing compiler.tree.checker
7 compiler.tree.def-use kernel accessors sequences math
8 math.private sorting math.order binary-search sequences.private
9 slots.private ;
10
11 \ unbox-tuples must-infer
12
13 : test-unboxing ( quot -- )
14     build-tree
15     analyze-recursive
16     normalize
17     propagate
18     cleanup
19     escape-analysis
20     unbox-tuples
21     check-nodes ;
22
23 TUPLE: cons { car read-only } { cdr read-only } ;
24
25 TUPLE: empty-tuple ;
26
27 {
28     [ 1 2 cons boa [ car>> ] [ cdr>> ] bi ]
29     [ empty-tuple boa drop ]
30     [ cons boa [ car>> ] [ cdr>> ] bi ]
31     [ [ 1 cons boa ] [ 2 cons boa ] if car>> ]
32     [ dup cons boa 10 [ nip dup cons boa ] each-integer car>> ]
33     [ 2 cons boa { [ ] [ ] } dispatch ]
34     [ dup [ drop f ] [ "A" throw ] if ]
35     [ [ ] [ ] curry curry dup 2 slot swap 3 slot dup 2 slot swap 3 slot drop ]
36     [ [ ] [ ] curry curry call ]
37     [ <complex> <complex> dup 1 slot drop 2 slot drop ]
38     [ 1 cons boa over [ "A" throw ] when car>> ]
39     [ [ <=> ] sort ]
40     [ [ <=> ] with search ]
41 } [ [ ] swap [ test-unboxing ] curry unit-test ] each
42
43 ! A more complicated example
44 : impeach-node ( quot: ( node -- ) -- )
45     dup slip impeach-node ; inline recursive
46
47 : bleach-node ( quot: ( node -- ) -- )
48     [ bleach-node ] curry [ ] compose impeach-node ; inline recursive
49
50 [ ] [ [ [ ] bleach-node ] test-unboxing ] unit-test
51
52 TUPLE: box { i read-only } ;
53
54 : box-test ( m -- n )
55     dup box-test i>> swap box-test drop box boa ; inline recursive
56
57 [ ] [ [ T{ box f 34 } box-test i>> ] test-unboxing ] unit-test