2006-04-03 02:18:56 -04:00
|
|
|
USING: arrays assembler compiler generic
|
2006-05-15 01:01:47 -04:00
|
|
|
hashtables inference kernel kernel-internals math
|
2005-11-22 21:41:41 -05:00
|
|
|
optimizer prettyprint sequences strings test vectors words
|
|
|
|
sequences-internals ;
|
2006-05-05 21:41:57 -04:00
|
|
|
IN: temporary
|
2004-12-05 21:17:09 -05:00
|
|
|
|
2005-09-08 00:37:17 -04:00
|
|
|
: kill-1
|
2006-08-11 16:55:43 -04:00
|
|
|
[ 1 2 3 ] [ + ] over drop drop ;
|
2005-09-08 00:37:17 -04:00
|
|
|
|
|
|
|
[ [ 1 2 3 ] ] [ kill-1 ] unit-test
|
|
|
|
|
|
|
|
: kill-2
|
2006-08-11 16:55:43 -04:00
|
|
|
[ + ] [ 1 2 3 ] over drop nip ;
|
2005-09-08 00:37:17 -04:00
|
|
|
|
|
|
|
[ [ 1 2 3 ] ] [ kill-2 ] unit-test
|
|
|
|
|
|
|
|
: kill-3
|
|
|
|
[ + ] dup over 3drop ;
|
|
|
|
|
|
|
|
[ ] [ kill-3 ] unit-test
|
|
|
|
|
|
|
|
: kill-4
|
2006-08-11 16:55:43 -04:00
|
|
|
[ 1 2 3 ] [ + ] [ - ] pick >r 2drop r> ;
|
2005-09-08 00:37:17 -04:00
|
|
|
|
|
|
|
[ [ 1 2 3 ] [ 1 2 3 ] ] [ kill-4 ] unit-test
|
|
|
|
|
|
|
|
: kill-5
|
2006-08-11 16:55:43 -04:00
|
|
|
[ + ] [ - ] [ 1 2 3 ] pick pick 2drop >r 2drop r> ;
|
2005-09-08 00:37:17 -04:00
|
|
|
|
|
|
|
[ [ 1 2 3 ] ] [ kill-5 ] unit-test
|
|
|
|
|
|
|
|
: kill-6
|
2006-08-11 16:55:43 -04:00
|
|
|
[ 1 2 3 ] [ 4 5 6 ] [ + ] pick >r drop r> ;
|
2005-09-08 00:37:17 -04:00
|
|
|
|
|
|
|
[ [ 1 2 3 ] [ 4 5 6 ] [ 1 2 3 ] ] [ kill-6 ] unit-test
|
|
|
|
|
2005-09-17 04:15:05 -04:00
|
|
|
: subset? swap [ swap member? ] all-with? ;
|
|
|
|
|
|
|
|
: set= 2dup subset? >r swap subset? r> and ;
|
|
|
|
|
2006-05-05 21:41:57 -04:00
|
|
|
USE: optimizer
|
|
|
|
|
2006-03-04 18:46:49 -05:00
|
|
|
: kill-set dup live-values swap literals hash-diff ;
|
|
|
|
|
|
|
|
: kill-set=
|
|
|
|
dataflow kill-set hash-keys [ value-literal ] map set= ;
|
|
|
|
|
|
|
|
: foo 1 2 3 ;
|
|
|
|
|
|
|
|
[ H{ } ] [ \ foo word-def dataflow kill-set ] unit-test
|
|
|
|
|
|
|
|
[ t ] [ [ [ 1 ] [ 2 ] ] [ [ 1 ] [ 2 ] if ] kill-set= ] unit-test
|
|
|
|
|
|
|
|
[ t ] [ [ [ 1 ] [ 2 ] ] [ [ 1 ] [ 2 ] if ] kill-set= ] unit-test
|
|
|
|
|
|
|
|
|
2006-08-11 16:55:43 -04:00
|
|
|
: literal-kill-test-1 4 cell 2 cells - ;
|
2005-05-15 21:17:56 -04:00
|
|
|
|
|
|
|
[ 4 ] [ literal-kill-test-1 drop ] unit-test
|
|
|
|
|
2006-08-11 16:55:43 -04:00
|
|
|
: literal-kill-test-2 3 cell 2 cells - ;
|
2005-05-15 21:17:56 -04:00
|
|
|
|
|
|
|
[ 3 ] [ literal-kill-test-2 drop ] unit-test
|
|
|
|
|
2006-08-11 16:55:43 -04:00
|
|
|
: literal-kill-test-3 10 3 /mod drop ;
|
2005-05-15 21:17:56 -04:00
|
|
|
|
|
|
|
[ 3 ] [ literal-kill-test-3 ] unit-test
|
2005-05-22 21:07:24 -04:00
|
|
|
|
|
|
|
: literal-kill-test-4
|
2006-08-11 16:55:43 -04:00
|
|
|
5 swap [ 3 ] [ dup ] if 2drop ;
|
2005-05-22 21:07:24 -04:00
|
|
|
|
|
|
|
[ ] [ t literal-kill-test-4 ] unit-test
|
|
|
|
[ ] [ f literal-kill-test-4 ] unit-test
|
|
|
|
|
|
|
|
: literal-kill-test-5
|
2006-08-11 16:55:43 -04:00
|
|
|
5 swap [ 5 ] [ dup ] if 2drop ;
|
2005-05-22 21:07:24 -04:00
|
|
|
|
|
|
|
[ ] [ t literal-kill-test-5 ] unit-test
|
|
|
|
[ ] [ f literal-kill-test-5 ] unit-test
|
|
|
|
|
|
|
|
: literal-kill-test-6
|
2006-08-11 16:55:43 -04:00
|
|
|
5 swap [ dup ] [ dup ] if 2drop ;
|
2005-05-22 21:07:24 -04:00
|
|
|
|
|
|
|
[ ] [ t literal-kill-test-6 ] unit-test
|
|
|
|
[ ] [ f literal-kill-test-6 ] unit-test
|
|
|
|
|
2006-03-04 18:46:49 -05:00
|
|
|
[ t ] [ [
|
|
|
|
5 [ dup ] [ dup ] ] \ literal-kill-test-6 word-def kill-set=
|
|
|
|
] unit-test
|
|
|
|
|
2005-07-25 01:04:33 -04:00
|
|
|
: literal-kill-test-7
|
2006-08-11 16:55:43 -04:00
|
|
|
[ 1 2 3 ] >r + r> drop ;
|
2005-07-25 01:04:33 -04:00
|
|
|
|
|
|
|
[ 4 ] [ 2 2 literal-kill-test-7 ] unit-test
|
2005-08-01 16:22:53 -04:00
|
|
|
|
2006-08-15 05:24:30 -04:00
|
|
|
: literal-kill-test-8 ( a b -- )
|
2005-11-22 21:41:41 -05:00
|
|
|
dup [ >r dup slip r> literal-kill-test-8 ] [ 2drop ] if ; inline
|
|
|
|
|
2006-03-04 18:46:49 -05:00
|
|
|
[ t ] [
|
|
|
|
[ [ ] swap literal-kill-test-8 ] dataflow
|
|
|
|
live-values hash-values [ value? ] subset empty?
|
|
|
|
] unit-test
|
|
|
|
|
2005-08-06 02:44:25 -04:00
|
|
|
! Test method inlining
|
2005-11-27 17:45:48 -05:00
|
|
|
[ f ] [ fixnum { } min-class ] unit-test
|
|
|
|
|
2005-08-04 00:48:07 -04:00
|
|
|
[ string ] [
|
2005-08-01 16:22:53 -04:00
|
|
|
\ string
|
2005-12-24 18:29:31 -05:00
|
|
|
[ integer string array reversed sbuf
|
2006-05-15 01:01:47 -04:00
|
|
|
slice vector quotation ]
|
2005-11-27 17:45:48 -05:00
|
|
|
[ class-compare ] sort min-class
|
2005-08-01 16:22:53 -04:00
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ f ] [
|
|
|
|
\ fixnum
|
|
|
|
[ fixnum integer letter ]
|
2005-11-27 17:45:48 -05:00
|
|
|
[ class-compare ] sort 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-11-27 17:45:48 -05:00
|
|
|
[ class-compare ] sort 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 ]
|
2005-11-27 17:45:48 -05:00
|
|
|
[ class-compare ] sort min-class
|
2005-08-02 06:32:48 -04:00
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ object ] [
|
|
|
|
\ word
|
|
|
|
[ integer float object ]
|
2005-11-27 17:45:48 -05:00
|
|
|
[ class-compare ] sort min-class
|
2005-08-01 16:22:53 -04:00
|
|
|
] unit-test
|
2005-08-02 22:40:12 -04:00
|
|
|
|
2006-09-08 02:32:14 -04:00
|
|
|
FORGET: xyz
|
2006-08-18 01:35:04 -04:00
|
|
|
GENERIC: xyz ( obj -- obj )
|
2006-05-15 18:15:35 -04:00
|
|
|
M: array xyz xyz ;
|
2005-08-02 22:40:12 -04:00
|
|
|
|
|
|
|
[ ] [ \ xyz compile ] unit-test
|
2005-08-03 18:47:32 -04:00
|
|
|
|
|
|
|
! Test predicate inlining
|
|
|
|
: pred-test-1
|
|
|
|
dup fixnum? [
|
2005-09-24 15:21:17 -04:00
|
|
|
dup integer? [ "integer" ] [ "nope" ] if
|
2005-08-03 18:47:32 -04:00
|
|
|
] [
|
|
|
|
"not a fixnum"
|
2006-08-11 16:55:43 -04:00
|
|
|
] if ;
|
2005-08-03 18:47:32 -04:00
|
|
|
|
2006-05-15 01:01:47 -04:00
|
|
|
[ 1 "integer" ] [ 1 pred-test-1 ] unit-test
|
2005-08-03 18:47:32 -04:00
|
|
|
|
|
|
|
TUPLE: pred-test ;
|
|
|
|
|
2006-05-15 01:01:47 -04:00
|
|
|
: pred-test-2
|
2005-08-03 18:47:32 -04:00
|
|
|
dup tuple? [
|
2005-09-24 15:21:17 -04:00
|
|
|
dup pred-test? [ "pred-test" ] [ "nope" ] if
|
2005-08-03 18:47:32 -04:00
|
|
|
] [
|
|
|
|
"not a tuple"
|
2006-08-11 16:55:43 -04:00
|
|
|
] if ;
|
2005-08-03 18:47:32 -04:00
|
|
|
|
2006-05-15 01:01:47 -04:00
|
|
|
[ T{ pred-test } "pred-test" ] [ T{ pred-test } pred-test-2 ] unit-test
|
2005-08-03 18:47:32 -04:00
|
|
|
|
2006-05-15 01:01:47 -04:00
|
|
|
: pred-test-3
|
2005-08-03 18:47:32 -04:00
|
|
|
dup pred-test? [
|
2005-09-24 15:21:17 -04:00
|
|
|
dup tuple? [ "pred-test" ] [ "nope" ] if
|
2005-08-03 18:47:32 -04:00
|
|
|
] [
|
|
|
|
"not a tuple"
|
2006-08-11 16:55:43 -04:00
|
|
|
] if ;
|
2005-08-03 18:47:32 -04:00
|
|
|
|
2006-05-15 01:01:47 -04:00
|
|
|
[ T{ pred-test } "pred-test" ] [ T{ pred-test } pred-test-3 ] unit-test
|
2005-08-12 23:54:29 -04:00
|
|
|
|
2005-10-18 20:35:41 -04:00
|
|
|
! : inline-test
|
2006-08-11 16:55:43 -04:00
|
|
|
! "nom" = ;
|
2005-10-18 20:35:41 -04:00
|
|
|
!
|
|
|
|
! [ t ] [ "nom" inline-test ] unit-test
|
|
|
|
! [ f ] [ "shayin" inline-test ] unit-test
|
|
|
|
! [ f ] [ 3 inline-test ] unit-test
|
2005-08-13 23:39:46 -04:00
|
|
|
|
2006-08-11 16:55:43 -04:00
|
|
|
: fixnum-declarations >fixnum 24 shift 1234 bitxor ;
|
2005-08-13 23:39:46 -04:00
|
|
|
|
|
|
|
[ ] [ 1000000 fixnum-declarations . ] unit-test
|
2005-09-03 22:28:46 -04:00
|
|
|
|
|
|
|
! regression
|
|
|
|
|
2006-08-11 16:55:43 -04:00
|
|
|
: literal-not-branch 0 not [ ] [ ] if ;
|
2005-09-03 22:28:46 -04:00
|
|
|
|
|
|
|
[ ] [ literal-not-branch ] unit-test
|
2005-09-07 17:21:11 -04:00
|
|
|
|
|
|
|
! regression
|
|
|
|
|
2005-09-24 15:21:17 -04:00
|
|
|
: bad-kill-1 [ 3 f ] [ dup bad-kill-1 ] if ; inline
|
2006-08-11 16:55:43 -04:00
|
|
|
: bad-kill-2 bad-kill-1 drop ;
|
2005-09-07 17:21:11 -04:00
|
|
|
|
|
|
|
[ 3 ] [ t bad-kill-2 ] unit-test
|
2005-09-10 02:56:33 -04:00
|
|
|
|
2005-11-19 04:09:30 -05:00
|
|
|
! regression
|
|
|
|
: (the-test) dup 0 > [ 1- (the-test) ] when ; inline
|
2006-08-11 16:55:43 -04:00
|
|
|
: the-test 2 dup (the-test) ;
|
2005-11-19 04:09:30 -05:00
|
|
|
|
|
|
|
[ 2 0 ] [ the-test ] unit-test
|
2005-11-22 21:41:41 -05:00
|
|
|
|
|
|
|
! regression
|
|
|
|
: (double-recursion) ( start end -- )
|
|
|
|
< [
|
|
|
|
6 1 (double-recursion)
|
|
|
|
3 2 (double-recursion)
|
|
|
|
] when ; inline
|
|
|
|
|
2006-08-11 16:55:43 -04:00
|
|
|
: double-recursion 0 2 (double-recursion) ;
|
2005-11-22 21:41:41 -05:00
|
|
|
|
|
|
|
[ ] [ double-recursion ] unit-test
|
|
|
|
|
2005-11-27 17:45:48 -05:00
|
|
|
! regression
|
2005-11-22 21:41:41 -05:00
|
|
|
: double-label-1
|
|
|
|
[ f double-label-1 ] [ swap nth-unsafe ] if ; inline
|
|
|
|
: double-label-2
|
2006-08-11 16:55:43 -04:00
|
|
|
dup array? [ ] [ ] if 0 t double-label-1 ;
|
2005-11-22 21:41:41 -05:00
|
|
|
|
|
|
|
[ 0 ] [ 10 double-label-2 ] unit-test
|
2005-11-27 17:45:48 -05:00
|
|
|
|
|
|
|
! regression
|
2006-08-18 01:35:04 -04:00
|
|
|
GENERIC: void-generic ( obj -- * )
|
2005-11-27 17:45:48 -05:00
|
|
|
: breakage "hi" void-generic ;
|
|
|
|
[ ] [ \ breakage compile ] unit-test
|
|
|
|
[ breakage ] unit-test-fails
|
2006-02-25 01:45:51 -05:00
|
|
|
|
|
|
|
! regression
|
|
|
|
: test-0 dup 0 = [ drop ] [ 1- test-0 ] if ; inline
|
|
|
|
: test-1 t [ test-0 ] [ delegate dup [ test-1 ] [ drop ] if ] if ; inline
|
2006-08-11 16:55:43 -04:00
|
|
|
: test-2 5 test-1 ;
|
2006-02-25 01:45:51 -05:00
|
|
|
|
|
|
|
[ f ] [ f test-2 ] unit-test
|
2006-08-06 20:31:15 -04:00
|
|
|
|
|
|
|
: branch-fold-regression-0
|
|
|
|
t [ ] [ 1+ branch-fold-regression-0 ] if ; inline
|
|
|
|
|
|
|
|
: branch-fold-regression-1
|
2006-08-11 16:55:43 -04:00
|
|
|
10 branch-fold-regression-0 ;
|
2006-08-06 20:31:15 -04:00
|
|
|
|
|
|
|
[ 10 ] [ branch-fold-regression-1 ] unit-test
|
|
|
|
|
|
|
|
! another regression
|
2006-08-09 18:09:10 -04:00
|
|
|
: constant-branch-fold-0 "hey" ; foldable
|
|
|
|
: constant-branch-fold-1 constant-branch-fold-0 "hey" = ; inline
|
|
|
|
[ 1 ] [ [ constant-branch-fold-1 [ 1 ] [ 2 ] if ] compile-1 ] unit-test
|
2006-09-02 17:27:39 -04:00
|
|
|
|
|
|
|
! another regression
|
|
|
|
: foo f ;
|
|
|
|
: bar foo 4 4 = and ;
|
|
|
|
[ f ] [ bar ] unit-test
|