factor/library/test/dataflow.factor

100 lines
2.4 KiB
Factor
Raw Normal View History

IN: scratchpad
USE: inference
USE: lists
USE: math
USE: test
2004-11-29 23:14:12 -05:00
USE: hashtables
USE: kernel
USE: vectors
USE: namespaces
2004-11-30 23:56:01 -05:00
USE: prettyprint
2004-12-02 22:44:36 -05:00
USE: words
USE: kernel
2004-12-24 02:52:02 -05:00
USE: kernel-internals
USE: generic
2004-11-29 23:14:12 -05:00
: dataflow-contains-op? ( object list -- ? )
#! Check if some dataflow node contains a given operation.
[ node-op swap hash = ] some-with? ;
2004-11-29 23:14:12 -05:00
: dataflow-contains-param? ( object list -- ? )
#! Check if some dataflow node contains a given operation.
2004-12-04 23:45:41 -05:00
[
[
2004-12-04 23:45:41 -05:00
node-op get #label = [
node-param get dataflow-contains-param?
] [
node-param get =
] ifte
] bind
] some-with? ;
2004-11-29 23:14:12 -05:00
[ t ] [
\ + [ 2 2 + ] dataflow dataflow-contains-param? >boolean
] unit-test
: inline-test
car car ; inline
2004-12-31 02:17:45 -05:00
! [ t ] [
! \ slot [ inline-test ] dataflow dataflow-contains-param? >boolean
! ] unit-test
2004-11-29 23:14:12 -05:00
[ t ] [
\ ifte [ [ drop ] [ + ] ifte ] dataflow dataflow-contains-op? >boolean
2004-11-29 23:14:12 -05:00
] unit-test
: dataflow-consume-d-len ( object -- n )
2004-12-02 22:44:36 -05:00
[ node-consume-d get length ] bind ;
2004-11-29 23:14:12 -05:00
: dataflow-produce-d-len ( object -- n )
2004-12-02 22:44:36 -05:00
[ node-produce-d get length ] bind ;
2004-11-29 23:14:12 -05:00
[ t ] [ [ drop ] dataflow car dataflow-consume-d-len 1 = ] unit-test
[ t ] [ [ 2 ] dataflow car dataflow-produce-d-len 1 = ] unit-test
: dataflow-ifte-node-consume-d ( list -- node )
\ ifte swap dataflow-contains-op? car [ node-consume-d get ] bind ;
2004-11-29 23:14:12 -05:00
[ t ] [
[ [ swap ] [ nip "hi" ] ifte ] dataflow
2004-12-02 22:44:36 -05:00
dataflow-ifte-node-consume-d length 1 =
2004-11-29 23:14:12 -05:00
] unit-test
2004-11-30 23:56:01 -05:00
2004-12-16 19:57:03 -05:00
! [ t ] [
! [ { [ drop ] [ undefined-method ] [ drop ] [ undefined-method ] } generic ] dataflow
! \ dispatch swap dataflow-contains-op? car [
2004-12-16 19:57:03 -05:00
! node-param get [
! [ [ node-param get \ undefined-method = ] bind ] some?
! ] some?
! ] bind >boolean
! ] unit-test
2004-12-02 22:44:36 -05:00
SYMBOL: #test
#test f "foobar" set-word-prop
2004-12-02 22:44:36 -05:00
[ 6 ] [
{{
[[ node-op #test ]]
[[ node-param 5 ]]
}} "foobar" [ [ node-param get ] bind 1 + ] apply-dataflow
2004-12-02 22:44:36 -05:00
] unit-test
#test [ [ node-param get ] bind sq ] "foobar" set-word-prop
2004-12-02 22:44:36 -05:00
[ 25 ] [
{{
[[ node-op #test ]]
[[ node-param 5 ]]
}} "foobar" [ [ node-param get ] bind 1 + ] apply-dataflow
2004-12-02 22:44:36 -05:00
] unit-test
2004-12-04 23:45:41 -05:00
! Somebody (cough) got the order of ifte nodes wrong.
[ t ] [
\ ifte [ [ 1 ] [ 2 ] ifte ] dataflow dataflow-contains-op? car
2004-12-04 23:45:41 -05:00
[ node-param get ] bind car car [ node-param get ] bind 1 =
] unit-test