factor/library/test/compiler/optimizer.factor

169 lines
3.7 KiB
Factor
Raw Normal View History

2005-08-04 00:48:07 -04:00
IN: temporary
2005-08-01 16:22:53 -04:00
USING: generic kernel-internals strings vectors ;
2004-12-05 21:17:09 -05:00
USE: test
2005-05-15 21:17:56 -04:00
USE: assembler
2004-12-05 21:17:09 -05:00
USE: compiler
USE: compiler-frontend
2004-12-05 21:17:09 -05:00
USE: inference
USE: words
USE: math
USE: kernel
2004-12-19 22:53:41 -05:00
USE: lists
USE: sequences
2004-12-05 21:17:09 -05:00
! Some dataflow tests
2005-08-13 04:01:21 -04:00
! [ 3 ] [ 1 2 3 (subst-value) ] unit-test
! [ 1 ] [ 1 2 2 (subst-value) ] unit-test
!
! [ { "one" "one" "three" "three" } ]
! [
! { "one" "two" "three" } { 1 2 3 } { 1 1 3 3 }
! clone [ (subst-values) ] keep
! ] unit-test
!
! [ << meet f { "one" 2 3 } >> ]
! [ "one" 1 << meet f { 1 2 3 } >> clone (subst-value) ] unit-test
! Literal kill tests
2005-05-22 21:07:24 -04:00
: kill-set*
dataflow kill-set [ literal-value ] map ;
2004-12-05 21:17:09 -05:00
: foo 1 2 3 ;
2005-08-07 00:00:57 -04:00
[ { } ] [ \ foo word-def dataflow kill-set ] unit-test
2005-08-07 00:00:57 -04:00
[ { [ 1 ] [ 2 ] } ] [ [ [ 1 ] [ 2 ] ifte ] kill-set* ] unit-test
2005-08-07 00:00:57 -04:00
[ { [ 1 ] [ 2 ] } ] [ [ [ 1 ] [ 2 ] ifte ] kill-set* ] unit-test
2005-07-25 01:04:33 -04:00
[ [ t t f ] ] [
2005-08-05 00:05:04 -04:00
[ 1 2 3 ] [ <literal> ] map
2005-07-25 01:04:33 -04:00
[ [ literal-value 2 <= ] subset ] keep in-d-node <#drop> kill-mask
2005-05-22 21:07:24 -04:00
] unit-test
2005-01-17 15:33:12 -05:00
2005-05-15 21:17:56 -04:00
: literal-kill-test-1 4 compiled-offset cell 2 * - ; compiled
[ 4 ] [ literal-kill-test-1 drop ] unit-test
: literal-kill-test-2 3 compiled-offset cell 2 * - ; compiled
[ 3 ] [ literal-kill-test-2 drop ] unit-test
: literal-kill-test-3 10 3 /mod drop ; compiled
[ 3 ] [ literal-kill-test-3 ] unit-test
2005-05-22 21:07:24 -04:00
2005-08-13 04:01:21 -04:00
[ { [ 3 ] [ dup ] 3 } ] [ [ [ 3 ] [ dup ] ifte drop ] kill-set* ] unit-test
2005-05-22 21:07:24 -04:00
: literal-kill-test-4
5 swap [ 3 ] [ dup ] ifte 2drop ; compiled
[ ] [ t literal-kill-test-4 ] unit-test
[ ] [ f literal-kill-test-4 ] unit-test
2005-08-13 04:01:21 -04:00
[ { 5 [ 3 ] [ dup ] 3 } ] [ \ literal-kill-test-4 word-def kill-set* ] unit-test
2005-05-22 21:07:24 -04:00
: literal-kill-test-5
5 swap [ 5 ] [ dup ] ifte 2drop ; compiled
[ ] [ t literal-kill-test-5 ] unit-test
[ ] [ f literal-kill-test-5 ] unit-test
2005-08-13 04:01:21 -04:00
[ { 5 [ 5 ] [ dup ] 5 } ] [ \ literal-kill-test-5 word-def kill-set* ] unit-test
2005-05-22 21:07:24 -04:00
: literal-kill-test-6
5 swap [ dup ] [ dup ] ifte 2drop ; compiled
[ ] [ t literal-kill-test-6 ] unit-test
[ ] [ f literal-kill-test-6 ] unit-test
2005-08-07 00:00:57 -04:00
[ { 5 [ dup ] [ dup ] } ] [ \ literal-kill-test-6 word-def kill-set* ] unit-test
2005-05-22 21:07:24 -04:00
2005-07-25 01:04:33 -04:00
: literal-kill-test-7
[ 1 2 3 ] >r + r> drop ; compiled
[ 4 ] [ 2 2 literal-kill-test-7 ] unit-test
2005-08-01 16:22:53 -04:00
! Test method inlining
2005-08-04 00:48:07 -04:00
[ string ] [
2005-08-01 16:22:53 -04:00
\ string
[ range repeated integer string mirror array reversed sbuf
slice vector diagonal general-list ]
2005-08-04 00:48:07 -04:00
min-class
2005-08-01 16:22:53 -04:00
] unit-test
[ f ] [
\ fixnum
[ fixnum integer letter ]
2005-08-02 06:32:48 -04:00
min-class
2005-08-01 16:22:53 -04:00
] unit-test
2005-08-02 06:32:48 -04:00
[ fixnum ] [
2005-08-01 16:22:53 -04:00
\ fixnum
[ fixnum integer object ]
2005-08-02 06:32:48 -04:00
min-class
2005-08-01 16:22:53 -04:00
] unit-test
2005-08-02 06:32:48 -04:00
[ integer ] [
2005-08-01 16:22:53 -04:00
\ fixnum
2005-08-02 06:32:48 -04:00
[ integer float object ]
min-class
] unit-test
[ object ] [
\ word
[ integer float object ]
min-class
2005-08-01 16:22:53 -04:00
] unit-test
2005-08-02 22:40:12 -04:00
GENERIC: xyz
M: cons xyz xyz ;
[ ] [ \ xyz compile ] unit-test
! Test predicate inlining
: pred-test-1
dup cons? [
dup general-list? [ "general-list" ] [ "nope" ] ifte
] [
"not a cons"
] ifte ; compiled
[ [[ 1 2 ]] "general-list" ] [ [[ 1 2 ]] pred-test-1 ] unit-test
: pred-test-2
dup fixnum? [
dup integer? [ "integer" ] [ "nope" ] ifte
] [
"not a fixnum"
] ifte ; compiled
[ 1 "integer" ] [ 1 pred-test-2 ] unit-test
TUPLE: pred-test ;
: pred-test-3
dup tuple? [
dup pred-test? [ "pred-test" ] [ "nope" ] ifte
] [
"not a tuple"
] ifte ; compiled
2005-08-04 00:48:07 -04:00
[ << pred-test >> "pred-test" ] [ << pred-test >> pred-test-3 ] unit-test
: pred-test-4
dup pred-test? [
dup tuple? [ "pred-test" ] [ "nope" ] ifte
] [
"not a tuple"
] ifte ; compiled
[ << pred-test >> "pred-test" ] [ << pred-test >> pred-test-4 ] unit-test
: inline-test
"nom" = ; compiled
[ t ] [ "nom" inline-test ] unit-test
2005-08-13 04:01:21 -04:00
[ f ] [ "shayin" inline-test ] unit-test
[ f ] [ 3 inline-test ] unit-test