2014-12-27 07:18:58 -05:00
|
|
|
USING: accessors alien alien.accessors arrays assocs byte-arrays
|
|
|
|
combinators.short-circuit compiler.cfg compiler.cfg.builder compiler.cfg.checker
|
|
|
|
compiler.cfg.debugger compiler.cfg.instructions compiler.cfg.optimizer
|
2015-03-19 13:03:49 -04:00
|
|
|
compiler.cfg.predecessors compiler.cfg.registers compiler.cfg.representations
|
|
|
|
compiler.cfg.rpo compiler.cfg.stacks compiler.cfg.stacks.local
|
2015-03-26 18:46:37 -04:00
|
|
|
compiler.cfg.utilities compiler.test compiler.tree compiler.tree.builder
|
2015-05-07 07:23:28 -04:00
|
|
|
compiler.tree.optimizer fry hashtables io kernel kernel.private locals make math
|
2015-03-26 18:46:37 -04:00
|
|
|
math.partial-dispatch math.private namespaces prettyprint sbufs sequences
|
|
|
|
sequences.private slots.private strings strings.private tools.test vectors
|
|
|
|
words ;
|
2009-10-21 19:44:00 -04:00
|
|
|
FROM: alien.c-types => int ;
|
2009-08-13 20:21:44 -04:00
|
|
|
IN: compiler.cfg.builder.tests
|
2008-08-11 03:49:37 -04:00
|
|
|
|
2008-09-10 23:11:03 -04:00
|
|
|
! Just ensure that various CFGs build correctly.
|
2010-04-30 18:40:34 -04:00
|
|
|
: unit-test-builder ( quot -- )
|
2014-12-11 15:48:43 -05:00
|
|
|
'[
|
|
|
|
_ test-builder [
|
|
|
|
[
|
|
|
|
[ optimize-cfg ] [ check-cfg ] bi
|
|
|
|
] with-cfg
|
|
|
|
] each
|
|
|
|
] [ ] swap unit-test ;
|
2008-10-20 06:55:20 -04:00
|
|
|
|
2009-07-22 20:17:21 -04:00
|
|
|
: blahblah ( nodes -- ? )
|
|
|
|
{ fixnum } declare [
|
|
|
|
dup 3 bitand 1 = [ drop t ] [
|
|
|
|
dup 3 bitand 2 = [
|
|
|
|
blahblah
|
|
|
|
] [ drop f ] if
|
|
|
|
] if
|
|
|
|
] any? ; inline recursive
|
|
|
|
|
2009-07-27 20:24:13 -04:00
|
|
|
: more? ( x -- ? ) ;
|
|
|
|
|
|
|
|
: test-case-1 ( -- ? ) f ;
|
|
|
|
|
|
|
|
: test-case-2 ( -- )
|
|
|
|
test-case-1 [ test-case-2 ] [ ] if ; inline recursive
|
|
|
|
|
2008-09-10 23:11:03 -04:00
|
|
|
{
|
|
|
|
[ ]
|
|
|
|
[ dup ]
|
|
|
|
[ swap ]
|
2008-12-17 20:17:37 -05:00
|
|
|
[ [ ] dip ]
|
2008-09-10 23:11:03 -04:00
|
|
|
[ fixnum+ ]
|
2008-10-20 06:55:20 -04:00
|
|
|
[ fixnum+fast ]
|
|
|
|
[ 3 fixnum+fast ]
|
|
|
|
[ fixnum*fast ]
|
|
|
|
[ 3 fixnum*fast ]
|
2009-07-01 00:01:44 -04:00
|
|
|
[ 3 swap fixnum*fast ]
|
2008-10-20 06:55:20 -04:00
|
|
|
[ fixnum-shift-fast ]
|
|
|
|
[ 10 fixnum-shift-fast ]
|
|
|
|
[ -10 fixnum-shift-fast ]
|
|
|
|
[ 0 fixnum-shift-fast ]
|
2009-07-01 00:01:44 -04:00
|
|
|
[ 10 swap fixnum-shift-fast ]
|
|
|
|
[ -10 swap fixnum-shift-fast ]
|
|
|
|
[ 0 swap fixnum-shift-fast ]
|
2008-10-20 06:55:20 -04:00
|
|
|
[ fixnum-bitnot ]
|
|
|
|
[ eq? ]
|
|
|
|
[ "hi" eq? ]
|
2008-09-10 23:11:03 -04:00
|
|
|
[ fixnum< ]
|
2008-10-20 06:55:20 -04:00
|
|
|
[ 5 fixnum< ]
|
|
|
|
[ float+ ]
|
|
|
|
[ 3.0 float+ ]
|
|
|
|
[ float<= ]
|
|
|
|
[ fixnum>bignum ]
|
|
|
|
[ bignum>fixnum ]
|
|
|
|
[ fixnum>float ]
|
|
|
|
[ float>fixnum ]
|
|
|
|
[ 3 f <array> ]
|
2008-09-10 23:11:03 -04:00
|
|
|
[ [ 1 ] [ 2 ] if ]
|
|
|
|
[ fixnum< [ 1 ] [ 2 ] if ]
|
|
|
|
[ float+ [ 2.0 float* ] [ 3.0 float* ] bi float/f ]
|
|
|
|
[ { [ 1 ] [ 2 ] [ 3 ] } dispatch ]
|
|
|
|
[ [ t ] loop ]
|
|
|
|
[ [ dup ] loop ]
|
|
|
|
[ [ 2 ] [ 3 throw ] if 4 ]
|
2009-10-21 19:44:00 -04:00
|
|
|
[ int f "malloc" { int } alien-invoke ]
|
2010-03-31 22:20:35 -04:00
|
|
|
[ int { int } cdecl alien-indirect ]
|
|
|
|
[ int { int } cdecl [ ] alien-callback ]
|
2009-07-19 21:12:04 -04:00
|
|
|
[ swap - + * ]
|
|
|
|
[ swap slot ]
|
2009-07-22 20:17:21 -04:00
|
|
|
[ blahblah ]
|
2009-07-27 20:24:13 -04:00
|
|
|
[ 1000 [ dup [ reverse ] when ] times ]
|
|
|
|
[ 1array ]
|
|
|
|
[ 1 2 ? ]
|
|
|
|
[ { array } declare [ ] map ]
|
|
|
|
[ { array } declare dup 1 slot [ 1 slot ] when ]
|
|
|
|
[ [ dup more? ] [ dup ] produce ]
|
|
|
|
[ vector new over test-case-1 [ test-case-2 ] [ ] if ]
|
|
|
|
[ [ [ nth-unsafe ".." = 0 ] dip set-nth-unsafe ] 2curry (each-integer) ]
|
|
|
|
[
|
|
|
|
{ fixnum sbuf } declare 2dup 3 slot fixnum> [
|
|
|
|
over 3 fixnum* over dup [ 2 slot resize-string ] dip 2 set-slot
|
|
|
|
] [ ] if
|
|
|
|
]
|
|
|
|
[ [ 2 fixnum* ] when 3 ]
|
|
|
|
[ [ 2 fixnum+ ] when 3 ]
|
|
|
|
[ [ 2 fixnum- ] when 3 ]
|
|
|
|
[ 10000 [ ] times ]
|
|
|
|
[
|
|
|
|
over integer? [
|
|
|
|
over dup 16 <-integer-fixnum
|
|
|
|
[ 0 >=-integer-fixnum ] [ drop f ] if [
|
|
|
|
nip dup
|
|
|
|
[ ] [ ] if
|
|
|
|
] [ 2drop f ] if
|
|
|
|
] [ 2drop f ] if
|
|
|
|
]
|
|
|
|
[
|
|
|
|
pick 10 fixnum>= [ [ 123 fixnum-bitand ] 2dip ] [ ] if
|
|
|
|
set-string-nth-fast
|
|
|
|
]
|
2008-09-10 23:11:03 -04:00
|
|
|
} [
|
2010-04-30 18:40:34 -04:00
|
|
|
unit-test-builder
|
2008-09-10 23:11:03 -04:00
|
|
|
] each
|
|
|
|
|
|
|
|
: test-1 ( -- ) test-1 ;
|
|
|
|
: test-2 ( -- ) 3 . test-2 ;
|
|
|
|
: test-3 ( a -- b ) dup [ test-3 ] when ;
|
|
|
|
|
|
|
|
{
|
|
|
|
test-1
|
|
|
|
test-2
|
|
|
|
test-3
|
2010-04-30 18:40:34 -04:00
|
|
|
} [ unit-test-builder ] each
|
2008-10-20 06:55:20 -04:00
|
|
|
|
|
|
|
{
|
|
|
|
byte-array
|
|
|
|
alien
|
|
|
|
POSTPONE: f
|
|
|
|
} [| class |
|
|
|
|
{
|
|
|
|
alien-signed-1
|
|
|
|
alien-signed-2
|
|
|
|
alien-signed-4
|
|
|
|
alien-unsigned-1
|
|
|
|
alien-unsigned-2
|
|
|
|
alien-unsigned-4
|
|
|
|
alien-cell
|
|
|
|
alien-float
|
|
|
|
alien-double
|
|
|
|
} [| word |
|
2010-04-30 18:40:34 -04:00
|
|
|
{ class } word '[ _ declare 10 _ execute ] unit-test-builder
|
|
|
|
{ class fixnum } word '[ _ declare _ execute ] unit-test-builder
|
2008-10-20 06:55:20 -04:00
|
|
|
] each
|
2014-12-27 07:18:58 -05:00
|
|
|
|
2008-10-20 06:55:20 -04:00
|
|
|
{
|
|
|
|
set-alien-signed-1
|
|
|
|
set-alien-signed-2
|
|
|
|
set-alien-signed-4
|
|
|
|
set-alien-unsigned-1
|
|
|
|
set-alien-unsigned-2
|
|
|
|
set-alien-unsigned-4
|
|
|
|
} [| word |
|
2010-04-30 18:40:34 -04:00
|
|
|
{ fixnum class } word '[ _ declare 10 _ execute ] unit-test-builder
|
|
|
|
{ fixnum class fixnum } word '[ _ declare _ execute ] unit-test-builder
|
2008-10-20 06:55:20 -04:00
|
|
|
] each
|
2014-12-27 07:18:58 -05:00
|
|
|
|
2010-04-30 18:40:34 -04:00
|
|
|
{ float class } \ set-alien-float '[ _ declare 10 _ execute ] unit-test-builder
|
|
|
|
{ float class fixnum } \ set-alien-float '[ _ declare _ execute ] unit-test-builder
|
2014-12-27 07:18:58 -05:00
|
|
|
|
2010-04-30 18:40:34 -04:00
|
|
|
{ float class } \ set-alien-double '[ _ declare 10 _ execute ] unit-test-builder
|
|
|
|
{ float class fixnum } \ set-alien-double '[ _ declare _ execute ] unit-test-builder
|
2014-12-27 07:18:58 -05:00
|
|
|
|
2010-04-30 18:40:34 -04:00
|
|
|
{ pinned-c-ptr class } \ set-alien-cell '[ _ declare 10 _ execute ] unit-test-builder
|
|
|
|
{ pinned-c-ptr class fixnum } \ set-alien-cell '[ _ declare _ execute ] unit-test-builder
|
2008-09-10 23:11:03 -04:00
|
|
|
] each
|
2009-08-19 17:56:26 -04:00
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{ t } [ [ swap ] [ ##replace? ] contains-insn? ] unit-test
|
2009-08-19 17:56:26 -04:00
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{ f } [ [ swap swap ] [ ##replace? ] contains-insn? ] unit-test
|
2009-08-19 17:56:26 -04:00
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{ t } [
|
2009-08-19 17:56:26 -04:00
|
|
|
[ { fixnum byte-array fixnum } declare set-alien-unsigned-1 ]
|
2010-04-24 02:38:54 -04:00
|
|
|
[ [ ##store-memory? ] [ ##store-memory-imm? ] bi or ] contains-insn?
|
2009-08-19 17:56:26 -04:00
|
|
|
] unit-test
|
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{ t } [
|
2009-08-19 17:56:26 -04:00
|
|
|
[ { fixnum byte-array fixnum } declare [ dup * dup * ] 2dip set-alien-unsigned-1 ]
|
2010-04-24 02:38:54 -04:00
|
|
|
[ [ ##store-memory? ] [ ##store-memory-imm? ] bi or ] contains-insn?
|
2009-08-19 17:56:26 -04:00
|
|
|
] unit-test
|
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{ f } [
|
2009-08-19 17:56:26 -04:00
|
|
|
[ { byte-array fixnum } declare set-alien-unsigned-1 ]
|
2010-04-24 02:38:54 -04:00
|
|
|
[ [ ##store-memory? ] [ ##store-memory-imm? ] bi or ] contains-insn?
|
2010-04-23 18:42:09 -04:00
|
|
|
] unit-test
|
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{ t t } [
|
2010-04-23 18:42:09 -04:00
|
|
|
[ { byte-array fixnum } declare alien-cell ]
|
2010-04-24 02:38:54 -04:00
|
|
|
[ [ [ ##load-memory? ] [ ##load-memory-imm? ] bi or ] contains-insn? ]
|
2010-04-23 18:42:09 -04:00
|
|
|
[ [ ##box-alien? ] contains-insn? ]
|
|
|
|
bi
|
|
|
|
] unit-test
|
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{ f } [
|
2010-04-23 18:42:09 -04:00
|
|
|
[ { byte-array integer } declare alien-cell ]
|
2010-04-24 02:38:54 -04:00
|
|
|
[ [ ##load-memory? ] [ ##load-memory-imm? ] bi or ] contains-insn?
|
2009-08-22 18:15:10 -04:00
|
|
|
] unit-test
|
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{ f } [
|
2015-04-08 02:08:17 -04:00
|
|
|
[ 1000 [ ] times ] [ ##peek? ] contains-insn?
|
2009-08-28 06:21:16 -04:00
|
|
|
] unit-test
|
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{ f t } [
|
2009-11-02 04:25:39 -05:00
|
|
|
[ { fixnum alien } declare <displaced-alien> 0 alien-cell ]
|
2009-08-28 06:21:16 -04:00
|
|
|
[ [ ##unbox-any-c-ptr? ] contains-insn? ]
|
2009-09-03 22:22:43 -04:00
|
|
|
[ [ ##unbox-alien? ] contains-insn? ] bi
|
|
|
|
] unit-test
|
|
|
|
|
2009-09-14 00:12:47 -04:00
|
|
|
\ alien-float "intrinsic" word-prop [
|
|
|
|
[ f t ] [
|
|
|
|
[ { byte-array fixnum } declare alien-cell 4 alien-float ]
|
|
|
|
[ [ ##box-alien? ] contains-insn? ]
|
2009-10-01 20:41:23 -04:00
|
|
|
[ [ ##allot? ] contains-insn? ] bi
|
2009-09-14 00:12:47 -04:00
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ f t ] [
|
2009-11-02 04:25:39 -05:00
|
|
|
[ { byte-array fixnum } declare alien-cell { alien } declare 4 alien-float ]
|
2009-09-14 00:12:47 -04:00
|
|
|
[ [ ##box-alien? ] contains-insn? ]
|
2009-10-01 20:41:23 -04:00
|
|
|
[ [ ##allot? ] contains-insn? ] bi
|
2009-09-14 00:12:47 -04:00
|
|
|
] unit-test
|
2014-12-27 07:18:58 -05:00
|
|
|
|
2010-04-23 18:42:09 -04:00
|
|
|
[ 1 ] [ [ dup float+ ] [ ##load-memory-imm? ] count-insns ] unit-test
|
2009-09-25 19:50:08 -04:00
|
|
|
] when
|
|
|
|
|
|
|
|
! Regression. Make sure everything is inlined correctly
|
2015-07-03 12:39:59 -04:00
|
|
|
{ f } [ M\ hashtable set-at [ { [ ##call? ] [ word>> \ set-slot eq? ] } 1&& ] contains-insn? ] unit-test
|
2011-02-27 19:43:26 -05:00
|
|
|
|
|
|
|
! Regression. Make sure branch splitting works.
|
2015-07-03 12:39:59 -04:00
|
|
|
{ 2 } [ [ 1 2 ? ] [ ##return? ] count-insns ] unit-test
|
2011-10-29 20:10:51 -04:00
|
|
|
|
|
|
|
! Make sure fast union predicates don't have conditionals.
|
2015-07-03 12:39:59 -04:00
|
|
|
{ f } [
|
2011-10-29 20:10:51 -04:00
|
|
|
[ tag 1 swap fixnum-shift-fast ]
|
|
|
|
[ ##compare-integer-imm-branch? ] contains-insn?
|
|
|
|
] unit-test
|
2014-12-27 07:18:58 -05:00
|
|
|
|
|
|
|
! make-input-map
|
|
|
|
{
|
2015-08-13 18:23:10 -04:00
|
|
|
{ { 37 D: 2 } { 81 D: 1 } { 92 D: 0 } }
|
2014-12-27 07:18:58 -05:00
|
|
|
} [
|
|
|
|
T{ #shuffle { in-d { 37 81 92 } } } make-input-map
|
|
|
|
] unit-test
|
|
|
|
|
2015-05-07 07:23:28 -04:00
|
|
|
! emit-call
|
|
|
|
{
|
2015-05-16 21:11:32 -04:00
|
|
|
V{ T{ ##call { word print } } T{ ##branch } }
|
2015-05-07 07:23:28 -04:00
|
|
|
} [
|
|
|
|
[ \ print 4 emit-call ] V{ } make drop
|
|
|
|
basic-block get successors>> first instructions>>
|
|
|
|
] cfg-unit-test
|
|
|
|
|
2014-12-27 07:18:58 -05:00
|
|
|
! emit-node
|
|
|
|
{
|
|
|
|
{ T{ ##load-integer { dst 78 } { val 0 } } }
|
|
|
|
} [
|
|
|
|
77 vreg-counter set-global
|
|
|
|
[
|
|
|
|
T{ #push { literal 0 } { out-d { 8537399 } } } emit-node
|
|
|
|
] { } make
|
2015-03-26 18:46:37 -04:00
|
|
|
] cfg-unit-test
|
2014-12-27 07:18:58 -05:00
|
|
|
|
|
|
|
{
|
2015-03-15 19:14:41 -04:00
|
|
|
{ { 1 1 } { 0 0 } }
|
2015-08-13 18:23:10 -04:00
|
|
|
H{ { D: -1 4 } { D: 0 4 } }
|
2014-12-27 07:18:58 -05:00
|
|
|
} [
|
2015-08-13 18:23:10 -04:00
|
|
|
4 D: 0 replace-loc
|
2014-12-27 07:18:58 -05:00
|
|
|
T{ #shuffle
|
|
|
|
{ mapping { { 2 4 } { 3 4 } } }
|
|
|
|
{ in-d V{ 4 } }
|
|
|
|
{ out-d V{ 2 3 } }
|
|
|
|
} emit-node
|
2015-03-15 19:14:41 -04:00
|
|
|
height-state get
|
2015-04-07 09:05:34 -04:00
|
|
|
replaces get
|
2015-03-26 18:46:37 -04:00
|
|
|
] cfg-unit-test
|
2015-03-15 19:14:41 -04:00
|
|
|
|
|
|
|
{ 1 } [
|
2015-03-26 18:46:37 -04:00
|
|
|
V{ } 0 insns>block basic-block set init-cfg-test
|
2015-03-15 19:14:41 -04:00
|
|
|
V{ } 1 insns>block [ emit-loop-call ] V{ } make drop
|
|
|
|
basic-block get successors>> length
|
|
|
|
] unit-test
|
2015-03-19 13:03:49 -04:00
|
|
|
|
2015-03-26 09:19:57 -04:00
|
|
|
! emit-loop-call
|
|
|
|
{ "bar" } [
|
2015-03-26 18:46:37 -04:00
|
|
|
V{ } "foo" insns>block basic-block set init-cfg-test
|
|
|
|
[ V{ } "bar" insns>block emit-loop-call ] V{ } make drop
|
|
|
|
basic-block get successors>> first number>>
|
2015-03-26 09:19:57 -04:00
|
|
|
] unit-test
|
|
|
|
|
2015-03-24 12:38:42 -04:00
|
|
|
! begin-cfg
|
|
|
|
SYMBOL: foo
|
|
|
|
|
|
|
|
{ foo } [
|
2015-03-26 18:46:37 -04:00
|
|
|
\ foo f begin-cfg word>>
|
|
|
|
] cfg-unit-test
|
2015-03-24 12:38:42 -04:00
|
|
|
|
2015-03-19 13:03:49 -04:00
|
|
|
! store-shuffle
|
|
|
|
{
|
2015-08-13 18:23:10 -04:00
|
|
|
H{ { D: 2 1 } }
|
2015-03-19 13:03:49 -04:00
|
|
|
} [
|
|
|
|
T{ #shuffle { in-d { 7 3 0 } } { out-d { 55 } } { mapping { { 55 3 } } } }
|
2015-04-07 09:05:34 -04:00
|
|
|
emit-node replaces get
|
2015-03-26 18:46:37 -04:00
|
|
|
] cfg-unit-test
|
2015-03-19 13:03:49 -04:00
|
|
|
|
|
|
|
{
|
2015-08-13 18:23:10 -04:00
|
|
|
H{ { D: -1 1 } { D: 0 1 } }
|
2015-03-19 13:03:49 -04:00
|
|
|
} [
|
|
|
|
T{ #shuffle
|
|
|
|
{ in-d { 7 } }
|
|
|
|
{ out-d { 55 77 } }
|
|
|
|
{ mapping { { 55 7 } { 77 7 } } }
|
2015-04-07 09:05:34 -04:00
|
|
|
} emit-node replaces get
|
2015-03-26 18:46:37 -04:00
|
|
|
] cfg-unit-test
|