 
 : expire-old-intervals ( n -- )
     active-intervals get
-    swap '[ end>> _ = ] partition
-    active-intervals set
+    [ swap '[ end>> _ = ] partition ] change-seq drop
     [ insert-spill ] each ;
 
 : insert-reload ( live-interval -- )

    [ defs-vregs ] [ temp-vregs ] [ uses-vregs ] tri 3append ;

M: vreg-insn assign-registers-in-insn
    active-intervals get over all-vregs '[ vreg>> _ member? ] filter
    [ [ vreg>> ] [ reg>> ] bi ] { } map>assoc
    >>regs drop ;

M: insn assign-registers-in-insn drop ;

: init-assignment ( live-intervals -- )
    V{ } clone active-intervals set
    <min-heap> unhandled-intervals set
    init-unhandled ;


! but since we never have too many machine registers (around 30
! at most) and we probably won't have that many live at any one
! time anyway, it is not a problem to check each element.
TUPLE: active-intervals seq ;

: add-active ( live-interval -- )
    active-intervals get seq>> push ;

: lookup-register ( vreg -- reg )
    active-intervals get seq>> [ vreg>> = ] with find nip reg>> ;

! Minheap of live intervals which still need a register allocation
SYMBOL: unhandled-intervals
