2005-08-04 17:39:39 -04:00
|
|
|
! Copyright (C) 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
2005-09-09 00:17:19 -04:00
|
|
|
IN: optimizer
|
|
|
|
USING: inference kernel namespaces prettyprint sequences vectors ;
|
2005-08-04 17:39:39 -04:00
|
|
|
|
|
|
|
GENERIC: collect-recursion* ( label node -- )
|
|
|
|
|
|
|
|
M: node collect-recursion* ( label node -- ) 2drop ;
|
|
|
|
|
|
|
|
M: #call-label collect-recursion* ( label node -- )
|
|
|
|
tuck node-param = [ node-in-d , ] [ drop ] ifte ;
|
|
|
|
|
|
|
|
: collect-recursion ( label node -- seq )
|
|
|
|
#! Collect the input stacks of all #call-label nodes that
|
|
|
|
#! call given label.
|
2005-08-25 15:27:38 -04:00
|
|
|
[ [ collect-recursion* ] each-node-with ] { } make ;
|
2005-08-04 17:39:39 -04:00
|
|
|
|
2005-08-04 23:59:45 -04:00
|
|
|
GENERIC: solve-recursion*
|
|
|
|
|
|
|
|
M: node solve-recursion* ( node -- ) drop ;
|
2005-08-04 17:39:39 -04:00
|
|
|
|
2005-08-07 18:11:20 -04:00
|
|
|
: join-values ( calls entry -- new old )
|
|
|
|
add unify-lengths [ unify-stacks ] keep peek ;
|
|
|
|
|
2005-08-04 23:59:45 -04:00
|
|
|
M: #label solve-recursion* ( node -- )
|
|
|
|
dup node-param over collect-recursion >r
|
2005-09-04 01:09:46 -04:00
|
|
|
node-child dup node-in-d r> swap
|
2005-08-07 18:11:20 -04:00
|
|
|
join-values rot subst-values ;
|
2005-08-04 17:39:39 -04:00
|
|
|
|
2005-08-04 23:59:45 -04:00
|
|
|
: solve-recursion ( node -- )
|
|
|
|
#! Figure out which values survive inner recursions in
|
|
|
|
#! #labels, and those that don't should be fudged.
|
2005-08-06 01:59:49 -04:00
|
|
|
[ solve-recursion* ] each-node ;
|