2005-07-27 01:46:06 -04:00
|
|
|
IN: inference
|
2005-07-28 15:17:31 -04:00
|
|
|
USING: generic hashtables inference io kernel kernel-internals
|
2005-08-21 01:17:37 -04:00
|
|
|
lists math namespaces prettyprint sequences styles vectors words ;
|
2005-07-27 01:46:06 -04:00
|
|
|
|
|
|
|
! A simple tool for turning dataflow IR into quotations, for
|
|
|
|
! debugging purposes.
|
|
|
|
|
|
|
|
GENERIC: node>quot ( node -- )
|
|
|
|
|
2005-08-02 06:32:48 -04:00
|
|
|
TUPLE: comment node text ;
|
2005-07-27 01:46:06 -04:00
|
|
|
|
2005-08-21 01:17:37 -04:00
|
|
|
M: comment pprint* ( ann -- )
|
2005-08-02 06:32:48 -04:00
|
|
|
"( " over comment-text " )" append3
|
2005-08-26 00:55:56 -04:00
|
|
|
swap comment-node presented swons unit text ;
|
2005-08-02 06:32:48 -04:00
|
|
|
|
|
|
|
: comment, ( ? node text -- )
|
|
|
|
rot [ <comment> , ] [ 2drop ] ifte ;
|
2005-07-27 01:46:06 -04:00
|
|
|
|
2005-07-28 15:17:31 -04:00
|
|
|
: value-str ( classes values -- str )
|
2005-08-11 19:08:22 -04:00
|
|
|
[ swap hash [ object ] unless* ] map-with
|
2005-07-28 15:17:31 -04:00
|
|
|
[ word-name ] map
|
|
|
|
" " join ;
|
2005-07-27 01:46:06 -04:00
|
|
|
|
|
|
|
: effect-str ( node -- str )
|
|
|
|
[
|
2005-07-28 15:17:31 -04:00
|
|
|
dup node-classes swap
|
|
|
|
2dup node-in-d value-str %
|
|
|
|
"--" %
|
2005-07-27 01:46:06 -04:00
|
|
|
node-out-d value-str %
|
2005-08-25 15:27:38 -04:00
|
|
|
] "" make ;
|
2005-07-27 01:46:06 -04:00
|
|
|
|
2005-08-02 06:32:48 -04:00
|
|
|
M: #push node>quot ( ? node -- )
|
2005-08-04 00:48:07 -04:00
|
|
|
node-out-d [ literal-value literalize ] map % drop ;
|
2005-07-27 01:46:06 -04:00
|
|
|
|
2005-08-02 06:32:48 -04:00
|
|
|
M: #drop node>quot ( ? node -- )
|
2005-07-27 01:46:06 -04:00
|
|
|
node-in-d length dup 3 > [
|
2005-07-27 20:13:11 -04:00
|
|
|
\ drop <repeated>
|
2005-07-27 01:46:06 -04:00
|
|
|
] [
|
2005-07-27 20:13:11 -04:00
|
|
|
{ f [ drop ] [ 2drop ] [ 3drop ] } nth
|
2005-08-02 06:32:48 -04:00
|
|
|
] ifte % drop ;
|
2005-07-27 01:46:06 -04:00
|
|
|
|
|
|
|
DEFER: dataflow>quot
|
|
|
|
|
2005-08-04 17:39:39 -04:00
|
|
|
: #call>quot ( ? node -- )
|
2005-08-07 18:11:20 -04:00
|
|
|
dup node-param dup
|
|
|
|
[ , dup effect-str comment, ] [ 3drop ] ifte ;
|
2005-07-27 01:46:06 -04:00
|
|
|
|
2005-08-04 17:39:39 -04:00
|
|
|
M: #call node>quot ( ? node -- ) #call>quot ;
|
|
|
|
|
|
|
|
M: #call-label node>quot ( ? node -- ) #call>quot ;
|
2005-07-27 01:46:06 -04:00
|
|
|
|
2005-08-02 06:32:48 -04:00
|
|
|
M: #label node>quot ( ? node -- )
|
|
|
|
[ "#label: " over node-param word-name append comment, ] 2keep
|
2005-09-04 01:09:46 -04:00
|
|
|
node-child swap dataflow>quot , \ call , ;
|
2005-07-27 01:46:06 -04:00
|
|
|
|
2005-08-02 06:32:48 -04:00
|
|
|
M: #ifte node>quot ( ? node -- )
|
|
|
|
[ "#ifte" comment, ] 2keep
|
|
|
|
node-children [ swap dataflow>quot ] map-with % \ ifte , ;
|
2005-07-27 01:46:06 -04:00
|
|
|
|
2005-08-02 06:32:48 -04:00
|
|
|
M: #dispatch node>quot ( ? node -- )
|
|
|
|
[ "#dispatch" comment, ] 2keep
|
|
|
|
node-children [ swap dataflow>quot ] map-with , \ dispatch , ;
|
2005-07-27 01:46:06 -04:00
|
|
|
|
2005-08-02 06:32:48 -04:00
|
|
|
M: #return node>quot ( ? node -- ) "#return" comment, ;
|
2005-07-27 01:46:06 -04:00
|
|
|
|
2005-08-02 06:32:48 -04:00
|
|
|
M: #values node>quot ( ? node -- ) "#values" comment, ;
|
2005-07-27 01:46:06 -04:00
|
|
|
|
2005-08-02 06:32:48 -04:00
|
|
|
M: #merge node>quot ( ? node -- ) "#merge" comment, ;
|
2005-07-27 01:46:06 -04:00
|
|
|
|
2005-08-04 17:39:39 -04:00
|
|
|
M: #entry node>quot ( ? node -- ) "#entry" comment, ;
|
|
|
|
|
2005-08-02 06:32:48 -04:00
|
|
|
: (dataflow>quot) ( ? node -- )
|
|
|
|
dup [
|
|
|
|
2dup node>quot node-successor (dataflow>quot)
|
|
|
|
] [
|
|
|
|
2drop
|
|
|
|
] ifte ;
|
2005-07-27 01:46:06 -04:00
|
|
|
|
2005-08-02 06:32:48 -04:00
|
|
|
: dataflow>quot ( node ? -- quot )
|
2005-08-25 15:27:38 -04:00
|
|
|
[ swap (dataflow>quot) ] [ ] make ;
|
2005-07-27 01:46:06 -04:00
|
|
|
|
2005-08-02 06:32:48 -04:00
|
|
|
: dataflow. ( quot ? -- )
|
|
|
|
#! Print dataflow IR for a quotation. Flag indicates if
|
|
|
|
#! annotations should be printed or not.
|
2005-08-21 14:40:12 -04:00
|
|
|
>r dataflow optimize r> dataflow>quot . ;
|