2009-07-19 21:12:04 -04:00
|
|
|
USING: tools.test kernel sequences words sequences.private fry
|
|
|
|
prettyprint alien alien.accessors math.private compiler.tree.builder
|
|
|
|
compiler.tree.optimizer compiler.cfg.builder compiler.cfg.debugger
|
2009-07-23 21:54:38 -04:00
|
|
|
compiler.cfg.optimizer compiler.cfg.predecessors compiler.cfg.checker
|
2009-08-08 21:02:56 -04:00
|
|
|
compiler.cfg arrays locals byte-arrays kernel.private math
|
|
|
|
slots.private vectors sbufs strings math.partial-dispatch
|
|
|
|
strings.private ;
|
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.
|
2009-07-19 21:12:04 -04:00
|
|
|
: unit-test-cfg ( quot -- )
|
2009-08-08 21:02:56 -04:00
|
|
|
'[ _ test-cfg [ [ optimize-cfg check-cfg ] 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 ]
|
|
|
|
[ "int" f "malloc" { "int" } alien-invoke ]
|
|
|
|
[ "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
|
|
|
} [
|
2008-10-20 06:55:20 -04:00
|
|
|
unit-test-cfg
|
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
|
2008-10-20 06:55:20 -04:00
|
|
|
} [ unit-test-cfg ] each
|
|
|
|
|
|
|
|
{
|
|
|
|
byte-array
|
|
|
|
simple-alien
|
|
|
|
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 |
|
|
|
|
{ class } word '[ _ declare 10 _ execute ] unit-test-cfg
|
|
|
|
{ class fixnum } word '[ _ declare _ execute ] unit-test-cfg
|
|
|
|
] each
|
|
|
|
|
|
|
|
{
|
|
|
|
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 |
|
|
|
|
{ fixnum class } word '[ _ declare 10 _ execute ] unit-test-cfg
|
|
|
|
{ fixnum class fixnum } word '[ _ declare _ execute ] unit-test-cfg
|
|
|
|
] each
|
|
|
|
|
|
|
|
{ float class } \ set-alien-float '[ _ declare 10 _ execute ] unit-test-cfg
|
|
|
|
{ float class fixnum } \ set-alien-float '[ _ declare _ execute ] unit-test-cfg
|
|
|
|
|
|
|
|
{ float class } \ set-alien-double '[ _ declare 10 _ execute ] unit-test-cfg
|
|
|
|
{ float class fixnum } \ set-alien-double '[ _ declare _ execute ] unit-test-cfg
|
|
|
|
|
|
|
|
{ pinned-c-ptr class } \ set-alien-cell '[ _ declare 10 _ execute ] unit-test-cfg
|
|
|
|
{ pinned-c-ptr class fixnum } \ set-alien-cell '[ _ declare _ execute ] unit-test-cfg
|
2008-09-10 23:11:03 -04:00
|
|
|
] each
|