2008-03-01 17:00:45 -05:00
|
|
|
IN: inference.class.tests
|
2007-09-20 18:09:08 -04:00
|
|
|
USING: arrays math.private kernel math compiler inference
|
|
|
|
inference.dataflow optimizer tools.test kernel.private generic
|
|
|
|
sequences words inference.class quotations alien
|
|
|
|
alien.c-types strings sbufs sequences.private
|
2008-01-13 17:07:59 -05:00
|
|
|
slots.private combinators definitions compiler.units
|
2008-03-18 21:24:29 -04:00
|
|
|
system layouts vectors ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
! Make sure these compile even though this is invalid code
|
|
|
|
[ ] [ [ 10 mod 3.0 /i ] dataflow optimize drop ] unit-test
|
|
|
|
[ ] [ [ 10 mod 3.0 shift ] dataflow optimize drop ] unit-test
|
|
|
|
|
|
|
|
! Ensure type inference works as it is supposed to by checking
|
|
|
|
! if various methods get inlined
|
|
|
|
|
2008-04-17 13:22:24 -04:00
|
|
|
: inlined? ( quot seq/word -- ? )
|
|
|
|
dup word? [ 1array ] when
|
2007-09-20 18:09:08 -04:00
|
|
|
swap dataflow optimize
|
2008-04-17 13:22:24 -04:00
|
|
|
[ node-param swap member? ] with node-exists? not ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
GENERIC: mynot ( x -- y )
|
|
|
|
|
|
|
|
M: f mynot drop t ;
|
|
|
|
|
2008-04-02 22:27:49 -04:00
|
|
|
M: object mynot drop f ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
GENERIC: detect-f ( x -- y )
|
|
|
|
|
|
|
|
M: f detect-f ;
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ dup [ mynot ] [ ] if detect-f ] \ detect-f inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ ] [ [ fixnum< ] dataflow optimize drop ] unit-test
|
|
|
|
|
|
|
|
[ ] [ [ fixnum< [ ] [ ] if ] dataflow optimize drop ] unit-test
|
|
|
|
|
|
|
|
GENERIC: xyz ( n -- n )
|
|
|
|
|
|
|
|
M: integer xyz ;
|
|
|
|
|
|
|
|
M: object xyz ;
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ { integer } declare xyz ] \ xyz inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ dup fixnum? [ xyz ] [ drop "hi" ] if ]
|
|
|
|
\ xyz inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
: (fx-repeat) ( i n quot -- )
|
2008-01-11 17:02:44 -05:00
|
|
|
2over fixnum>= [
|
2007-09-20 18:09:08 -04:00
|
|
|
3drop
|
|
|
|
] [
|
|
|
|
[ swap >r call 1 fixnum+fast r> ] keep (fx-repeat)
|
|
|
|
] if ; inline
|
|
|
|
|
|
|
|
: fx-repeat ( n quot -- )
|
|
|
|
0 -rot (fx-repeat) ; inline
|
|
|
|
|
|
|
|
! The + should be optimized into fixnum+, if it was not, then
|
|
|
|
! the type of the loop index was not inferred correctly
|
|
|
|
[ t ] [
|
|
|
|
[ [ dup 2 + drop ] fx-repeat ] \ + inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
: (i-repeat) ( i n quot -- )
|
2008-01-11 17:02:44 -05:00
|
|
|
2over dup xyz drop >= [
|
2007-09-20 18:09:08 -04:00
|
|
|
3drop
|
|
|
|
] [
|
|
|
|
[ swap >r call 1+ r> ] keep (i-repeat)
|
|
|
|
] if ; inline
|
|
|
|
|
|
|
|
: i-repeat >r { integer } declare r> 0 -rot (i-repeat) ; inline
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ [ dup xyz drop ] i-repeat ] \ xyz inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ { fixnum } declare dup 100 >= [ 1 + ] unless ] \ fixnum+ inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ { fixnum fixnum } declare dupd < [ 1 + 1 + ] when ]
|
|
|
|
\ + inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ { fixnum fixnum } declare dupd < [ 1 + 1 + ] when ]
|
|
|
|
\ + inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ { fixnum } declare [ ] times ] \ >= inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ { fixnum } declare [ ] times ] \ 1+ inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ { fixnum } declare [ ] times ] \ + inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ { fixnum } declare [ ] times ] \ fixnum+ inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ f ] [
|
|
|
|
[ { integer fixnum } declare dupd < [ 1 + ] when ]
|
|
|
|
\ + inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ f ] [ [ dup 0 < [ neg ] when ] \ neg inlined? ] unit-test
|
|
|
|
|
|
|
|
[ f ] [
|
|
|
|
[
|
|
|
|
[ no-cond ] 1
|
|
|
|
[ 1array dup quotation? [ >quotation ] unless ] times
|
2008-04-02 01:28:07 -04:00
|
|
|
] \ quotation? inlined?
|
2007-09-20 18:09:08 -04:00
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ f ] [ [ <reversed> length ] \ slot inlined? ] unit-test
|
|
|
|
|
|
|
|
! We don't want to use = to compare literals
|
|
|
|
: foo reverse ;
|
|
|
|
|
|
|
|
\ foo [
|
|
|
|
[
|
|
|
|
fixnum 0 `output class,
|
|
|
|
V{ } dup dup push 0 `input literal,
|
|
|
|
] set-constraints
|
|
|
|
] "constraints" set-word-prop
|
|
|
|
|
2007-12-27 17:26:39 -05:00
|
|
|
DEFER: blah
|
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
[ t ] [
|
2007-12-27 17:26:39 -05:00
|
|
|
[
|
|
|
|
\ blah
|
2008-01-02 19:36:36 -05:00
|
|
|
[ dup V{ } eq? [ foo ] when ] dup second dup push define
|
2007-12-27 17:26:39 -05:00
|
|
|
] with-compilation-unit
|
|
|
|
|
|
|
|
\ blah compiled?
|
2007-09-20 18:09:08 -04:00
|
|
|
] unit-test
|
|
|
|
|
|
|
|
GENERIC: detect-fx ( n -- n )
|
|
|
|
|
|
|
|
M: fixnum detect-fx ;
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[
|
|
|
|
[ uchar-nth ] 2keep [ uchar-nth ] 2keep uchar-nth
|
|
|
|
>r >r 298 * r> 100 * - r> 208 * - 128 + -8 shift
|
|
|
|
255 min 0 max detect-fx
|
|
|
|
] \ detect-fx inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ f ] [
|
|
|
|
[
|
|
|
|
1000000000000000000000000000000000 [ ] times
|
|
|
|
] \ 1+ inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ f ] [
|
|
|
|
[ { bignum } declare [ ] times ] \ 1+ inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ { string sbuf } declare push-all ] \ push-all inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ { string sbuf } declare push-all ] \ + inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ { string sbuf } declare push-all ] \ fixnum+ inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ { string sbuf } declare push-all ] \ >fixnum inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ { array-capacity } declare 0 < ] \ < inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ { array-capacity } declare 0 < ] \ fixnum< inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ { array-capacity } declare 1 fixnum- ] \ fixnum- inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ 5000 [ 5000 [ ] times ] times ] \ 1+ inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ 5000 [ [ ] times ] each ] \ 1+ inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ 5000 0 [ dup 2 - swap [ 2drop ] curry each ] reduce ]
|
|
|
|
\ 1+ inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
GENERIC: annotate-entry-test-1 ( x -- )
|
|
|
|
|
|
|
|
M: fixnum annotate-entry-test-1 drop ;
|
|
|
|
|
|
|
|
: (annotate-entry-test-2) ( from to quot -- )
|
2008-01-11 17:02:44 -05:00
|
|
|
2over >= [
|
2007-09-20 18:09:08 -04:00
|
|
|
3drop
|
|
|
|
] [
|
|
|
|
[ swap >r call dup annotate-entry-test-1 1+ r> ] keep (annotate-entry-test-2)
|
|
|
|
] if ; inline
|
|
|
|
|
|
|
|
: annotate-entry-test-2 0 -rot (annotate-entry-test-2) ; inline
|
|
|
|
|
|
|
|
[ f ] [
|
|
|
|
[ { bignum } declare [ ] annotate-entry-test-2 ]
|
|
|
|
\ annotate-entry-test-1 inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ { float } declare 10 [ 2.3 * ] times >float ]
|
|
|
|
\ >float inlined?
|
|
|
|
] unit-test
|
|
|
|
|
2008-04-03 05:58:37 -04:00
|
|
|
GENERIC: detect-float ( a -- b )
|
|
|
|
|
|
|
|
M: float detect-float ;
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ { real float } declare + detect-float ]
|
|
|
|
\ detect-float inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ { float real } declare + detect-float ]
|
|
|
|
\ detect-float inlined?
|
|
|
|
] unit-test
|
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
[ t ] [
|
|
|
|
[ 3 + = ] \ equal? inlined?
|
|
|
|
] unit-test
|
2008-01-12 21:37:44 -05:00
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ { fixnum fixnum } declare 7 bitand neg shift ]
|
|
|
|
\ shift inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ { fixnum fixnum } declare 7 bitand neg shift ]
|
|
|
|
\ fixnum-shift inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ { fixnum fixnum } declare 1 swap 7 bitand shift ]
|
|
|
|
\ fixnum-shift inlined?
|
|
|
|
] unit-test
|
|
|
|
|
2008-01-13 17:07:59 -05:00
|
|
|
cell-bits 32 = [
|
|
|
|
[ t ] [
|
|
|
|
[ { fixnum fixnum } declare 1 swap 31 bitand shift ]
|
|
|
|
\ shift inlined?
|
|
|
|
] unit-test
|
2008-01-12 21:37:44 -05:00
|
|
|
|
2008-01-13 17:07:59 -05:00
|
|
|
[ f ] [
|
|
|
|
[ { fixnum fixnum } declare 1 swap 31 bitand shift ]
|
|
|
|
\ fixnum-shift inlined?
|
|
|
|
] unit-test
|
|
|
|
] when
|
2008-02-08 02:48:51 -05:00
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ B{ 1 0 } *short 0 number= ]
|
|
|
|
\ number= inlined?
|
|
|
|
] unit-test
|
|
|
|
|
2008-02-10 21:32:48 -05:00
|
|
|
[ t ] [
|
|
|
|
[ B{ 1 0 } *short 0 { number number } declare number= ]
|
|
|
|
\ number= inlined?
|
|
|
|
] unit-test
|
|
|
|
|
2008-02-08 02:48:51 -05:00
|
|
|
[ t ] [
|
|
|
|
[ B{ 1 0 } *short 0 = ]
|
|
|
|
\ number= inlined?
|
|
|
|
] unit-test
|
2008-02-10 21:32:48 -05:00
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ B{ 1 0 } *short dup number? [ 0 number= ] [ drop f ] if ]
|
|
|
|
\ number= inlined?
|
|
|
|
] unit-test
|
2008-02-16 19:47:53 -05:00
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ HEX: ff bitand 0 HEX: ff between? ]
|
|
|
|
\ >= inlined?
|
|
|
|
] unit-test
|
2008-02-21 15:15:45 -05:00
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[ HEX: ff swap HEX: ff bitand >= ]
|
|
|
|
\ >= inlined?
|
|
|
|
] unit-test
|
|
|
|
|
2008-03-18 18:46:25 -04:00
|
|
|
[ t ] [
|
|
|
|
[ { vector } declare nth-unsafe ] \ nth-unsafe inlined?
|
|
|
|
] unit-test
|
2008-04-02 22:27:49 -04:00
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[
|
|
|
|
dup integer? [
|
|
|
|
dup fixnum? [
|
|
|
|
1 +
|
|
|
|
] [
|
|
|
|
2 +
|
|
|
|
] if
|
|
|
|
] when
|
|
|
|
] \ + inlined?
|
|
|
|
] unit-test
|
2008-04-17 13:22:24 -04:00
|
|
|
|
|
|
|
[ f ] [
|
|
|
|
[
|
|
|
|
256 mod
|
|
|
|
] { mod fixnum-mod } inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ f ] [
|
|
|
|
[
|
|
|
|
dup 0 >= [ 256 mod ] when
|
|
|
|
] { mod fixnum-mod } inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[
|
|
|
|
{ integer } declare dup 0 >= [ 256 mod ] when
|
|
|
|
] { mod fixnum-mod } inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[
|
|
|
|
{ integer } declare 256 rem
|
|
|
|
] { mod fixnum-mod } inlined?
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
! [ t ] [
|
|
|
|
! [
|
|
|
|
! { integer } declare [ 256 mod ] map
|
|
|
|
! ] { mod fixnum-mod } inlined?
|
|
|
|
! ] unit-test
|
|
|
|
!
|
|
|
|
! [ t ] [
|
|
|
|
! [
|
|
|
|
! { integer } declare [ 0 >= ] map
|
|
|
|
! ] { >= fixnum>= } inlined?
|
|
|
|
! ] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
[
|
|
|
|
{ integer } declare
|
|
|
|
dup 0 >= [
|
|
|
|
615949 * 797807 + 20 2^ mod dup 19 2^ -
|
|
|
|
] [ dup ] if
|
|
|
|
] { * + shift mod fixnum-mod fixnum* fixnum+ fixnum- } inlined?
|
|
|
|
] unit-test
|