1 USING: tools.test compiler.tree
2 compiler.tree.builder compiler.tree.recursive
3 compiler.tree.normalization compiler.tree.propagation
4 compiler.tree.cleanup compiler.tree.escape-analysis
5 compiler.tree.tuple-unboxing compiler.tree.checker
6 compiler.tree.def-use kernel accessors sequences math
7 math.private sorting math.order binary-search sequences.private
9 IN: compiler.tree.tuple-unboxing.tests
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 [ 1 cons boa over [ "A" throw ] when car>> ]
37 [ [ <=> ] with search ]
38 } [ [ ] swap [ test-unboxing ] curry unit-test ] each
40 ! A more complicated example
41 : impeach-node ( quot: ( node -- ) -- )
42 [ call ] keep impeach-node ; inline recursive
44 : bleach-node ( quot: ( node -- ) -- )
45 [ bleach-node ] curry [ ] compose impeach-node ; inline recursive
47 [ ] [ [ [ ] bleach-node ] test-unboxing ] unit-test
49 TUPLE: box { i read-only } ;
52 dup box-test i>> swap box-test drop box boa ; inline recursive
54 [ ] [ [ T{ box f 34 } box-test i>> ] test-unboxing ] unit-test