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 \ unbox-tuples must-infer
13 : test-unboxing ( quot -- )
23 TUPLE: cons { car read-only } { cdr read-only } ;
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>> ]
40 [ [ <=> ] with search ]
41 } [ [ ] swap [ test-unboxing ] curry unit-test ] each
43 ! A more complicated example
44 : impeach-node ( quot: ( node -- ) -- )
45 dup slip impeach-node ; inline recursive
47 : bleach-node ( quot: ( node -- ) -- )
48 [ bleach-node ] curry [ ] compose impeach-node ; inline recursive
50 [ ] [ [ [ ] bleach-node ] test-unboxing ] unit-test
52 TUPLE: box { i read-only } ;
55 dup box-test i>> swap box-test drop box boa ; inline recursive
57 [ ] [ [ T{ box f 34 } box-test i>> ] test-unboxing ] unit-test