Fix #dispatch generation
parent
37047a3b8e
commit
5f93ab74e4
|
@ -82,7 +82,8 @@ GENERIC: emit-node ( node -- next )
|
|||
: (build-cfg) ( nodes word label -- )
|
||||
[
|
||||
begin-word
|
||||
[ emit-nodes ] with-node-iterator
|
||||
V{ } clone node-stack set
|
||||
emit-nodes
|
||||
] with-cfg-builder ;
|
||||
|
||||
: build-cfg ( nodes word -- procedures )
|
||||
|
@ -152,14 +153,17 @@ M: #if emit-node
|
|||
|
||||
! #dispatch
|
||||
: dispatch-branch ( nodes word -- label )
|
||||
#! The order here is important, dispatch-branches must
|
||||
#! run after ##dispatch, so that each branch gets the
|
||||
#! correct register state
|
||||
gensym [
|
||||
[
|
||||
V{ } clone node-stack set
|
||||
init-phantoms
|
||||
##prologue
|
||||
[ emit-nodes ] with-node-iterator
|
||||
emit-nodes
|
||||
basic-block get [
|
||||
##epilogue
|
||||
##return
|
||||
end-basic-block
|
||||
] when
|
||||
] with-cfg-builder
|
||||
] keep ;
|
||||
|
||||
|
|
|
@ -19,9 +19,6 @@ SYMBOL: node-stack
|
|||
[ swap >node call node> drop ] keep iterate-nodes
|
||||
] if ; inline recursive
|
||||
|
||||
: with-node-iterator ( quot -- )
|
||||
>r V{ } clone node-stack r> with-variable ; inline
|
||||
|
||||
DEFER: (tail-call?)
|
||||
|
||||
: tail-phi? ( cursor -- ? )
|
||||
|
|
|
@ -78,22 +78,21 @@ SYMBOL: quotations
|
|||
V{ } clone meta-r set
|
||||
d-in [ ] change ;
|
||||
|
||||
: infer-branch ( literal quot -- namespace )
|
||||
: infer-branch ( literal -- namespace )
|
||||
[
|
||||
copy-inference
|
||||
nest-visitor
|
||||
[ [ value>> quotation set ] [ infer-literal-quot ] bi ] dip
|
||||
[ value>> quotation set ] [ infer-literal-quot ] bi
|
||||
check->r
|
||||
call
|
||||
] H{ } make-assoc ; inline
|
||||
|
||||
: infer-branches ( branches quot -- input children data )
|
||||
[ pop-d ] 2dip
|
||||
[ infer-branch ] curry map
|
||||
: infer-branches ( branches -- input children data )
|
||||
[ pop-d ] dip
|
||||
[ infer-branch ] map
|
||||
[ stack-visitor branch-variable ] keep ; inline
|
||||
|
||||
: (infer-if) ( branches -- )
|
||||
[ ] infer-branches
|
||||
infer-branches
|
||||
[ first2 #if, ] dip compute-phi-function ;
|
||||
|
||||
: infer-if ( -- )
|
||||
|
@ -108,5 +107,5 @@ SYMBOL: quotations
|
|||
|
||||
: infer-dispatch ( -- )
|
||||
pop-literal nip [ <literal> ] map
|
||||
[ f #return, ] infer-branches
|
||||
infer-branches
|
||||
[ #dispatch, ] dip compute-phi-function ;
|
||||
|
|
Loading…
Reference in New Issue