2005-08-04 17:39:39 -04:00
|
|
|
! Copyright (C) 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
|
|
|
IN: inference
|
|
|
|
USING: kernel namespaces prettyprint sequences vectors ;
|
|
|
|
|
|
|
|
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.
|
|
|
|
[ [ collect-recursion* ] each-node-with ] make-vector ;
|
|
|
|
|
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-04 23:59:45 -04:00
|
|
|
M: #label solve-recursion* ( node -- )
|
|
|
|
dup node-param over collect-recursion >r
|
|
|
|
node-children first dup node-in-d r> swap add
|
|
|
|
unify-stacks swap [ node-in-d ] keep
|
|
|
|
node-successor 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.
|
|
|
|
( [ solve-recursion* ] each-node ) drop ;
|