\ slot [
drop
- { { 0 "obj" } { 1 "n" } } { "obj" } [
+ { { any-reg "obj" } { any-reg "n" } } { "obj" } [
"obj" %get %untag ,
"n" %get "obj" %get %slot ,
] with-template
\ set-slot [
drop
- { { 0 "val" } { 1 "obj" } { 2 "slot" } } { } [
+ { { any-reg "val" } { any-reg "obj" } { any-reg "slot" } }
+ { } [
"obj" %get %untag ,
"val" %get "obj" %get "slot" %get %set-slot ,
+ end-basic-block
+ "obj" get %write-barrier ,
] with-template
- end-basic-block
- T{ vreg f 1 } %write-barrier ,
] "intrinsic" set-word-prop
\ char-slot [
drop
- { { 0 "n" } { 1 "str" } } { "str" } [
+ { { any-reg "n" } { any-reg "str" } } { "str" } [
"n" %get "str" %get %char-slot ,
] with-template
] "intrinsic" set-word-prop
\ set-char-slot [
drop
- { { 0 "ch" } { 1 "n" } { 2 "str" } } { } [
+ { { any-reg "ch" } { any-reg "n" } { any-reg "str" } } { } [
"ch" %get "str" %get "n" %get %set-char-slot ,
] with-template
] "intrinsic" set-word-prop
\ fixnum-bitnot [
drop
- { { 0 "x" } } { "x" } [
+ { { any-reg "x" } } { "x" } [
"x" %get dup %fixnum-bitnot ,
] with-template
] "intrinsic" set-word-prop
pick ?nth dupd ( eq? ) 2drop f [ <clean> ] when
] 2map nip ;
-: linearize-shuffle ( node -- )
- compute-free-vregs node-shuffle
+: linearize-shuffle ( shuffle -- )
dup shuffle-in-d over shuffle-out-d
shuffle-out-template live-d set
dup shuffle-in-r over shuffle-out-r
live-d get live-r get template-outputs ;
M: #shuffle linearize* ( #shuffle -- )
- linearize-shuffle iterate-next ;
+ node-shuffle linearize-shuffle iterate-next ;
+
+: ensure-vregs ( n -- )
+ sufficient-vregs?
+ [ end-basic-block compute-free-vregs ] unless ;
: linearize-push ( node -- )
compute-free-vregs
- >#push< dup length alloc-reg# [ <vreg> ] map
+ >#push< dup length dup ensure-vregs
+ alloc-reg# [ <vreg> ] map
[ [ load-literal ] 2each ] keep
phantom-d get phantom-append ;
: requested-vregs ( template -- n )
[ any-reg eq? ] subset length ;
-: sufficient-vregs? ( template template -- ? )
- [ requested-vregs ] 2apply + free-vregs get length <= ;
+: sufficient-vregs? ( n -- ? ) free-vregs get length <= ;
+
+: template-vreg# ( template template -- n )
+ [ requested-vregs ] 2apply + ;
: alloc-regs ( template -- template )
free-vregs get swap [
] if ;
: templates-match? ( template template -- ? )
- 2dup sufficient-vregs? [
+ 2dup template-vreg# sufficient-vregs? [
phantom-r get template-match?
>r phantom-d get template-match? r> and
] [
swap phantom-vregs ;
: template-input ( template phantom -- )
- dup vregs>stack swap [ stack>vregs ] keep phantom-vregs ;
+ swap [ stack>vregs ] keep phantom-vregs ;
: template-inputs ( template template -- )
2dup templates-match? [
phantom-r get optimized-input
phantom-d get optimized-input
+ compute-free-vregs
] [
+ phantom-r get vregs>stack
+ phantom-d get vregs>stack
+ compute-free-vregs
phantom-r get template-input
phantom-d get template-input
] if ;
phantom-d get template-output ;
: with-template ( in out quot -- )
- compute-free-vregs swap >r
- >r { } template-inputs r> call r> { } template-outputs ;
- inline
+ swap >r >r { } template-inputs
+ r> call r> { } template-outputs ; inline
[ 5000 ] [ [ 5000 ] compile-1 ] unit-test
[ "hi" ] [ [ "hi" ] compile-1 ] unit-test
+[ 1 2 3 4 ] [ [ 1 2 3 4 ] compile-1 ] unit-test
+
[ 1 1 ] [ 1 [ dup ] compile-1 ] unit-test
[ 0 ] [ 3 [ tag ] compile-1 ] unit-test
[ 0 3 ] [ 3 [ [ tag ] keep ] compile-1 ] unit-test