UNION: immediate fixnum POSTPONE: f ;
: generate-push ( node -- )
- >#push< dup length dup ensure-vregs
- alloc-reg# [ <int-vreg> ] map
- [ [ load-literal ] 2each ] keep
+ >#push< dup length ensure-vregs
+ [ T{ int-regs } alloc-reg [ load-literal ] keep ] map
phantom-d get phantom-append ;
M: #push generate-node ( #push -- )
namespaces prettyprint sequences vectors words ;
! Register allocation
-SYMBOL: free-vregs
-: alloc-reg ( -- n )
- free-vregs get pop ;
+! Hash mapping reg-classes to mutable vectors
+SYMBOL: free-vregs
-: alloc-reg# ( n -- regs )
- free-vregs [ cut ] change ;
+: alloc-reg ( reg-class -- vreg )
+ >r free-vregs get pop r> <vreg> ;
: requested-vregs ( template -- n )
0 [ [ 1+ ] unless ] reduce ;
[ requested-vregs ] 2apply + ;
: alloc-vregs ( template -- template )
- [ first [ alloc-reg ] unless* ] map ;
+ [ first [ <int-vreg> ] [ T{ int-regs } alloc-reg ] if* ] map ;
: adjust-free-vregs ( seq -- )
free-vregs [ diff ] change ;
: finalize-heights ( -- )
phantoms [ finalize-height ] 2apply ;
-: stack>vreg ( vreg# loc -- operand )
- >r <int-vreg> dup r> %peek ;
-
: stack>new-vreg ( loc -- vreg )
- alloc-reg swap stack>vreg ;
+ T{ int-regs } alloc-reg [ swap %peek ] keep ;
: vreg>stack ( value loc -- )
over loc? [
: stack>vregs ( phantom template -- values )
[
alloc-vregs dup length rot phantom-locs
- [ stack>vreg ] 2map
+ [ dupd %peek ] 2map
] 2keep length neg swap adjust-phantom ;
: compatible-values? ( value template -- ? )
+input get { } additional-vregs# +scratch get length + ;
: alloc-scratch ( -- )
- +scratch get [ alloc-vregs [ <int-vreg> ] map ] keep
- phantom-vregs ;
+ +scratch get [ alloc-vregs ] keep phantom-vregs ;
: template-inputs ( -- )
! Ensure we have enough to hold any new stack elements we