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
11 : test-unboxing ( quot -- )
21 TUPLE: cons { car read-only } { cdr read-only } ;
26 [ 1 2 cons boa [ car>> ] [ cdr>> ] bi ]
27 [ empty-tuple boa drop ]
28 [ cons boa [ car>> ] [ cdr>> ] bi ]
29 [ [ 1 cons boa ] [ 2 cons boa ] if car>> ]
30 [ dup cons boa 10 [ nip dup cons boa ] each-integer car>> ]
31 [ 2 cons boa { [ ] [ ] } dispatch ]
32 [ dup [ drop f ] [ "A" throw ] if ]
33 [ [ ] [ ] curry curry dup 2 slot swap 3 slot dup 2 slot swap 3 slot drop ]
34 [ [ ] [ ] curry curry call ]
35 [ <complex> <complex> dup 1 slot drop 2 slot drop ]
36 [ 1 cons boa over [ "A" throw ] when car>> ]
38 [ [ <=> ] with search ]
39 } [ [ ] swap [ test-unboxing ] curry unit-test ] each
41 ! A more complicated example
42 : impeach-node ( quot: ( node -- ) -- )
43 dup slip impeach-node ; inline recursive
45 : bleach-node ( quot: ( node -- ) -- )
46 [ bleach-node ] curry [ ] compose impeach-node ; inline recursive
48 [ ] [ [ [ ] bleach-node ] test-unboxing ] unit-test
50 TUPLE: box { i read-only } ;
53 dup box-test i>> swap box-test drop box boa ; inline recursive
55 [ ] [ [ T{ box f 34 } box-test i>> ] test-unboxing ] unit-test