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
|
|
|
|
math namespaces prettyprint sequences 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-02 06:32:48 -04:00
|
|
|
M: comment prettyprint* ( ann -- )
|
|
|
|
"( " over comment-text " )" append3
|
|
|
|
swap comment-node object. ;
|
|
|
|
|
|
|
|
: 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-07-28 18:20:31 -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 %
|
|
|
|
] make-string ;
|
|
|
|
|
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-02 06:32:48 -04:00
|
|
|
dup node-param , dup effect-str comment, ;
|
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
|
|
|
|
node-children first swap dataflow>quot , \ call , ;
|
2005-07-27 01:46:06 -04:00
|
|
|
|
2005-08-03 18:47:32 -04:00
|
|
|
M: #simple-label node>quot ( ? node -- )
|
|
|
|
node-children first swap dataflow>quot % ;
|
|
|
|
|
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 )
|
|
|
|
[ swap (dataflow>quot) ] make-list ;
|
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.
|
|
|
|
>r dataflow optimize r> dataflow>quot prettyprint ;
|