2005-09-09 00:17:19 -04:00
|
|
|
IN: optimizer
|
2005-07-28 15:17:31 -04:00
|
|
|
USING: generic hashtables inference io kernel kernel-internals
|
2006-05-15 01:01:47 -04:00
|
|
|
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
|
2006-05-29 06:09:31 -04:00
|
|
|
swap comment-node presented associate
|
|
|
|
[ text ] with-style ;
|
2005-08-02 06:32:48 -04:00
|
|
|
|
|
|
|
: comment, ( ? node text -- )
|
2005-09-24 15:21:17 -04:00
|
|
|
rot [ <comment> , ] [ 2drop ] if ;
|
2005-07-27 01:46:06 -04:00
|
|
|
|
2005-09-07 22:50:08 -04:00
|
|
|
: values% ( prefix values -- )
|
|
|
|
[
|
|
|
|
swap %
|
2006-01-22 16:40:18 -05:00
|
|
|
dup value? [
|
|
|
|
value-literal unparse %
|
2006-01-21 16:16:49 -05:00
|
|
|
] [
|
2006-01-22 16:40:18 -05:00
|
|
|
"@" % #
|
2006-01-21 16:16:49 -05:00
|
|
|
] if
|
2005-09-07 22:50:08 -04:00
|
|
|
] each-with ;
|
2005-07-27 01:46:06 -04:00
|
|
|
|
|
|
|
: effect-str ( node -- str )
|
|
|
|
[
|
2005-09-07 22:50:08 -04:00
|
|
|
" " over node-in-d values%
|
|
|
|
" r: " over node-in-r values%
|
2005-09-04 19:24:24 -04:00
|
|
|
" --" %
|
2005-09-07 22:50:08 -04:00
|
|
|
" " over node-out-d values%
|
|
|
|
" r: " swap node-out-r values%
|
2006-07-29 20:36:25 -04:00
|
|
|
] "" make 1 tail ;
|
2005-07-27 01:46:06 -04:00
|
|
|
|
2005-09-04 17:07:59 -04:00
|
|
|
M: #shuffle node>quot ( ? node -- )
|
|
|
|
>r drop t r> dup effect-str "#shuffle: " swap append comment, ;
|
2005-07-27 01:46:06 -04:00
|
|
|
|
2006-04-17 17:17:34 -04:00
|
|
|
M: #push node>quot ( ? node -- ) nip >#push< % ;
|
|
|
|
|
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
|
2005-09-24 15:21:17 -04:00
|
|
|
[ , dup effect-str comment, ] [ 3drop ] if ;
|
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-09-24 15:21:17 -04:00
|
|
|
M: #if node>quot ( ? node -- )
|
|
|
|
[ "#if" comment, ] 2keep
|
|
|
|
node-children [ swap dataflow>quot ] map-with % \ if , ;
|
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-09-10 00:55:46 -04:00
|
|
|
M: #return node>quot ( ? node -- )
|
|
|
|
dup node-param unparse "#return " swap append comment, ;
|
2005-07-27 01:46:06 -04:00
|
|
|
|
2006-05-02 06:05:58 -04:00
|
|
|
M: object node>quot ( ? node -- ) dup class word-name comment, ;
|
2005-09-18 01:37:28 -04:00
|
|
|
|
2005-08-02 06:32:48 -04:00
|
|
|
: (dataflow>quot) ( ? node -- )
|
|
|
|
dup [
|
|
|
|
2dup node>quot node-successor (dataflow>quot)
|
|
|
|
] [
|
|
|
|
2drop
|
2005-09-24 15:21:17 -04:00
|
|
|
] if ;
|
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 . ;
|