factor/basis/compiler/tree/tuple-unboxing/tuple-unboxing-tests.factor

55 lines
1.6 KiB
Factor
Raw Normal View History

USING: tools.test compiler.tree
compiler.tree.builder compiler.tree.recursive
compiler.tree.normalization compiler.tree.propagation
compiler.tree.cleanup compiler.tree.escape-analysis
compiler.tree.tuple-unboxing compiler.tree.checker
compiler.tree.def-use kernel accessors sequences math
math.private sorting math.order binary-search sequences.private
slots.private ;
IN: compiler.tree.tuple-unboxing.tests
2008-08-08 14:14:36 -04:00
: test-unboxing ( quot -- )
build-tree
analyze-recursive
2008-08-08 14:14:36 -04:00
normalize
propagate
cleanup
escape-analysis
unbox-tuples
2008-08-10 00:00:27 -04:00
check-nodes ;
2008-08-08 14:14:36 -04:00
TUPLE: cons { car read-only } { cdr read-only } ;
TUPLE: empty-tuple ;
{
2008-08-08 17:04:33 -04:00
[ 1 2 cons boa [ car>> ] [ cdr>> ] bi ]
2008-08-08 14:14:36 -04:00
[ empty-tuple boa drop ]
[ cons boa [ car>> ] [ cdr>> ] bi ]
[ [ 1 cons boa ] [ 2 cons boa ] if car>> ]
[ dup cons boa 10 [ nip dup cons boa ] each-integer car>> ]
2008-08-10 00:00:27 -04:00
[ 2 cons boa { [ ] [ ] } dispatch ]
[ dup [ drop f ] [ "A" throw ] if ]
2008-09-03 04:46:56 -04:00
[ [ ] [ ] curry curry dup 2 slot swap 3 slot dup 2 slot swap 3 slot drop ]
2008-08-10 00:00:27 -04:00
[ [ ] [ ] curry curry call ]
[ 1 cons boa over [ "A" throw ] when car>> ]
2008-08-08 17:04:33 -04:00
[ [ <=> ] sort ]
[ [ <=> ] with search ]
2008-08-08 14:14:36 -04:00
} [ [ ] swap [ test-unboxing ] curry unit-test ] each
2008-08-18 16:47:49 -04:00
! A more complicated example
: impeach-node ( quot: ( node -- ) -- )
[ call ] keep impeach-node ; inline recursive
2008-08-18 16:47:49 -04:00
: bleach-node ( quot: ( node -- ) -- )
[ bleach-node ] curry [ ] compose impeach-node ; inline recursive
[ ] [ [ [ ] bleach-node ] test-unboxing ] unit-test
TUPLE: box { i read-only } ;
: box-test ( m -- n )
dup box-test i>> swap box-test drop box boa ; inline recursive
[ ] [ [ T{ box f 34 } box-test i>> ] test-unboxing ] unit-test