Fixing some bugs, with-template argument order reversed

slava 2006-04-25 22:25:39 +00:00
parent 8eca428594
commit b458d58b91
3 changed files with 69 additions and 80 deletions

View File

@ -6,65 +6,65 @@ inference kernel kernel-internals lists math math-internals
namespaces sequences words ; namespaces sequences words ;
\ slot [ \ slot [
H{ [
{ +input { { f "obj" } { f "n" } } }
{ +output { "obj" } }
} [
"obj" get %untag , "obj" get %untag ,
"n" get "obj" get %slot , "n" get "obj" get %slot ,
] with-template ] H{
{ +input { { f "obj" } { f "n" } } }
{ +output { "obj" } }
} with-template
] "intrinsic" set-word-prop ] "intrinsic" set-word-prop
\ set-slot [ \ set-slot [
H{ [
{ +input { { f "val" } { f "obj" } { f "slot" } } }
{ +clobber { "obj" } }
} [
"obj" get %untag , "obj" get %untag ,
"val" get "obj" get "slot" get %set-slot , "val" get "obj" get "slot" get %set-slot ,
finalize-contents finalize-contents
"obj" get %write-barrier , "obj" get %write-barrier ,
] with-template ] H{
{ +input { { f "val" } { f "obj" } { f "slot" } } }
{ +clobber { "obj" } }
} with-template
] "intrinsic" set-word-prop ] "intrinsic" set-word-prop
\ char-slot [ \ char-slot [
H{ [
"n" get "str" get %char-slot ,
] H{
{ +input { { f "n" } { f "str" } } } { +input { { f "n" } { f "str" } } }
{ +output { "str" } } { +output { "str" } }
} [ } with-template
"n" get "str" get %char-slot ,
] with-template
] "intrinsic" set-word-prop ] "intrinsic" set-word-prop
\ set-char-slot [ \ set-char-slot [
H{ [
{ +input { { f "ch" } { f "n" } { f "str" } } }
} [
"ch" get "str" get "n" get %set-char-slot , "ch" get "str" get "n" get %set-char-slot ,
] with-template ] H{
{ +input { { f "ch" } { f "n" } { f "str" } } }
} with-template
] "intrinsic" set-word-prop ] "intrinsic" set-word-prop
\ type [ \ type [
H{ [ finalize-contents "in" get %type , ] H{
{ +input { { f "in" } } } { +input { { f "in" } } }
{ +output { "in" } } { +output { "in" } }
} [ finalize-contents "in" get %type , ] with-template } with-template
] "intrinsic" set-word-prop ] "intrinsic" set-word-prop
\ tag [ \ tag [
H{ [ "in" get %tag , ] H{
{ +input { { f "in" } } } { +input { { f "in" } } }
{ +output { "in" } } { +output { "in" } }
} [ "in" get %tag , ] with-template } with-template
] "intrinsic" set-word-prop ] "intrinsic" set-word-prop
: binary-op ( op -- ) : binary-op ( op -- )
H{ [
finalize-contents >r "y" get "x" get dup r> execute ,
] H{
{ +input { { 0 "x" } { 1 "y" } } } { +input { { 0 "x" } { 1 "y" } } }
{ +output { "x" } } { +output { "x" } }
} [ } with-template ; inline
finalize-contents >r "y" get "x" get dup r> execute ,
] with-template ; inline
{ {
{ fixnum+ %fixnum+ } { fixnum+ %fixnum+ }
@ -77,12 +77,12 @@ namespaces sequences words ;
] each ] each
: binary-op-fast ( op -- ) : binary-op-fast ( op -- )
H{ [
>r "y" get "x" get dup r> execute ,
] H{
{ +input { { f "x" } { f "y" } } } { +input { { f "x" } { f "y" } } }
{ +output { "x" } } { +output { "x" } }
} [ } with-template ; inline
>r "y" get "x" get dup r> execute ,
] with-template ; inline
{ {
{ fixnum-bitand %fixnum-bitand } { fixnum-bitand %fixnum-bitand }
@ -96,11 +96,11 @@ namespaces sequences words ;
] each ] each
: binary-jump ( label op -- ) : binary-jump ( label op -- )
H{ [
{ +input { { f "x" } { f "y" } } }
} [
end-basic-block >r >r "y" get "x" get r> r> execute , end-basic-block >r >r "y" get "x" get r> r> execute ,
] with-template ; inline ] H{
{ +input { { f "x" } { f "y" } } }
} with-template ; inline
{ {
{ fixnum<= %jump-fixnum<= } { fixnum<= %jump-fixnum<= }
@ -117,33 +117,33 @@ namespaces sequences words ;
! This is not clever. Because of x86, %fixnum-mod is ! This is not clever. Because of x86, %fixnum-mod is
! hard-coded to put its output in vreg 2, which happends to ! hard-coded to put its output in vreg 2, which happends to
! be EDX there. ! be EDX there.
H{ [
{ +input { { 0 "x" } { 1 "y" } } }
{ +output { "out" } }
} [
finalize-contents finalize-contents
T{ vreg f 2 } "out" set T{ vreg f 2 } "out" set
"y" get "x" get "out" get %fixnum-mod , "y" get "x" get "out" get %fixnum-mod ,
] with-template ] H{
{ +input { { 0 "x" } { 1 "y" } } }
{ +output { "out" } }
} with-template
] "intrinsic" set-word-prop ] "intrinsic" set-word-prop
\ fixnum/mod [ \ fixnum/mod [
! See the remark on fixnum-mod for vreg usage ! See the remark on fixnum-mod for vreg usage
H{ [
{ +input { { 0 "x" } { 1 "y" } } }
{ +output { "quo" "rem" } }
} [
finalize-contents finalize-contents
T{ vreg f 0 } "quo" set T{ vreg f 0 } "quo" set
T{ vreg f 2 } "rem" set T{ vreg f 2 } "rem" set
"y" get "x" get 2array "y" get "x" get 2array
"rem" get "quo" get 2array %fixnum/mod , "rem" get "quo" get 2array %fixnum/mod ,
] with-template ] H{
{ +input { { 0 "x" } { 1 "y" } } }
{ +output { "quo" "rem" } }
} with-template
] "intrinsic" set-word-prop ] "intrinsic" set-word-prop
\ fixnum-bitnot [ \ fixnum-bitnot [
H{ [ "x" get dup %fixnum-bitnot , ] H{
{ +input { { f "x" } } } { +input { { f "x" } } }
{ +output { "x" } } { +output { "x" } }
} [ "x" get dup %fixnum-bitnot , ] with-template } with-template
] "intrinsic" set-word-prop ] "intrinsic" set-word-prop

View File

@ -99,19 +99,18 @@ M: #call-label linearize* ( node -- next )
node-param renamed-label linearize-call ; node-param renamed-label linearize-call ;
M: #if linearize* ( node -- next ) M: #if linearize* ( node -- next )
H{ [
{ +input { { 0 "flag" } } }
} [
end-basic-block end-basic-block
<label> dup "flag" get %jump-t , <label> dup "flag" get %jump-t ,
] with-template linearize-if ; ] H{
{ +input { { 0 "flag" } } }
} with-template linearize-if ;
: dispatch-head ( node -- label/node ) : dispatch-head ( node -- label/node )
#! Output the jump table insn and return a list of #! Output the jump table insn and return a list of
#! label/branch pairs. #! label/branch pairs.
H{ [ end-basic-block "n" get %dispatch , ]
{ +input { { 0 "n" } } } H{ { +input { { 0 "n" } } } } with-template
} [ end-basic-block "n" get %dispatch , ] with-template
node-children [ <label> dup %target-label , 2array ] map ; node-children [ <label> dup %target-label , 2array ] map ;
: dispatch-body ( label/node -- ) : dispatch-body ( label/node -- )

View File

@ -128,10 +128,8 @@ SYMBOL: phantom-r
: phantoms ( -- phantom phantom ) phantom-d get phantom-r get ; : phantoms ( -- phantom phantom ) phantom-d get phantom-r get ;
: flush-locs ( phantom phantom -- ) : flush-locs ( phantom phantom -- )
[
2dup live-locs \ live-locs set 2dup live-locs \ live-locs set
[ dup phantom-locs* [ lazy-store ] 2each ] 2apply [ dup phantom-locs* [ lazy-store ] 2each ] 2apply ;
] with-scope ;
: finalize-contents ( -- ) : finalize-contents ( -- )
phantoms 2dup flush-locs [ vregs>stack ] 2apply ; phantoms 2dup flush-locs [ vregs>stack ] 2apply ;
@ -214,8 +212,7 @@ SYMBOL: phantom-r
over length over adjust-phantom swap nappend ; over length over adjust-phantom swap nappend ;
: (template-outputs) ( seq stack -- ) : (template-outputs) ( seq stack -- )
phantoms swapd phantom-append phantom-append phantoms swapd phantom-append phantom-append ;
compute-free-vregs ;
SYMBOL: +input SYMBOL: +input
SYMBOL: +output SYMBOL: +output
@ -230,41 +227,34 @@ SYMBOL: +clobber
{ +clobber { } } { +clobber { } }
} swap hash-union ; } swap hash-union ;
: adjust-free-vregs ( -- ) : adjust-free-vregs ( seq -- ) free-vregs [ diff ] change ;
used-vregs free-vregs [ diff ] change ;
: output-vregs ( -- seq seq ) : output-vregs ( -- seq seq )
+output get +clobber get [ [ get ] map ] 2apply ; +output +clobber [ get [ get ] map ] 2apply ;
: outputs-clash? ( -- ? ) : outputs-clash? ( -- ? )
output-vregs append phantoms append output-vregs append phantoms append
[ swap member? ] contains-with? ; [ swap member? ] contains-with? ;
: finalize-carefully ( -- )
#! If the phantom callstack has datastack locations on it,
#! we cannot rearrange the datastack and expect meaningful
#! results.
phantom-r get [ ds-loc? ] contains? [
finalize-contents
] [
phantom-d get dup { } flush-locs vregs>stack
] if ;
: slow-input ( template -- ) : slow-input ( template -- )
dup empty? dup empty? [ finalize-contents ] unless
[ finalize-carefully ] unless outputs-clash? [ finalize-contents ] when
outputs-clash?
[ finalize-contents ] when
phantom-d get swap [ stack>vregs ] keep phantom-vregs ; phantom-d get swap [ stack>vregs ] keep phantom-vregs ;
: input-vregs ( -- seq )
+input +scratch [ get [ second get vreg-n ] map ] 2apply
append ;
: template-inputs ( -- ) : template-inputs ( -- )
+input get dup { } additional-vregs# ensure-vregs +input get dup { } additional-vregs# ensure-vregs
match-template fast-input adjust-free-vregs slow-input ; match-template fast-input
used-vregs adjust-free-vregs
slow-input
input-vregs adjust-free-vregs ;
: template-outputs ( -- ) : template-outputs ( -- )
+output get [ get ] map { } (template-outputs) ; +output get [ get ] map { } (template-outputs) ;
: with-template ( spec quot -- ) : with-template ( quot spec -- )
swap fix-spec fix-spec [ template-inputs call template-outputs ] bind
[ template-inputs call template-outputs ] bind
compute-free-vregs ; inline compute-free-vregs ; inline