: set-successors ( branches -- )
! Set the successor of each branch's final basic block to the
! current block.
- basic-block get dup [
- '[ [ [ _ ] dip first successors>> push ] when* ] each
- ] [ 2drop ] if ;
-
-: merge-heights ( branches -- )
- ! If all elements are f, that means every branch ended with a backward
- ! jump so the height is irrelevant since this block is unreachable.
- [ ] find nip [ second current-height set ] [ end-basic-block ] if* ;
+ [ [ [ basic-block get ] dip first successors>> push ] when* ] each ;
: emit-conditional ( branches -- )
! branches is a sequence of pairs as above
end-basic-block
- [ merge-heights begin-basic-block ]
- [ set-successors ]
- bi ;
+ dup [ ] find nip dup [
+ second current-height set
+ begin-basic-block
+ set-successors
+ ] [ 2drop ] if ;