Code cleanups, fix #if intrinsic linearization, faster repeat combinator
parent
b458d58b91
commit
973ed2c7ea
|
@ -123,6 +123,7 @@ namespaces sequences words ;
|
||||||
"y" get "x" get "out" get %fixnum-mod ,
|
"y" get "x" get "out" get %fixnum-mod ,
|
||||||
] H{
|
] H{
|
||||||
{ +input { { 0 "x" } { 1 "y" } } }
|
{ +input { { 0 "x" } { 1 "y" } } }
|
||||||
|
! { +scratch { { 2 "out" } } }
|
||||||
{ +output { "out" } }
|
{ +output { "out" } }
|
||||||
} with-template
|
} with-template
|
||||||
] "intrinsic" set-word-prop
|
] "intrinsic" set-word-prop
|
||||||
|
@ -131,13 +132,13 @@ namespaces sequences words ;
|
||||||
! See the remark on fixnum-mod for vreg usage
|
! See the remark on fixnum-mod for vreg usage
|
||||||
[
|
[
|
||||||
finalize-contents
|
finalize-contents
|
||||||
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 "x" get 2array %fixnum/mod ,
|
||||||
] H{
|
] H{
|
||||||
{ +input { { 0 "x" } { 1 "y" } } }
|
{ +input { { 0 "x" } { 1 "y" } } }
|
||||||
{ +output { "quo" "rem" } }
|
! { +scratch { { 2 "rem" } } }
|
||||||
|
{ +output { "x" "rem" } }
|
||||||
} with-template
|
} with-template
|
||||||
] "intrinsic" set-word-prop
|
] "intrinsic" set-word-prop
|
||||||
|
|
||||||
|
|
|
@ -15,10 +15,23 @@ DEFER: #terminal?
|
||||||
|
|
||||||
PREDICATE: #merge #terminal-merge node-successor #terminal? ;
|
PREDICATE: #merge #terminal-merge node-successor #terminal? ;
|
||||||
|
|
||||||
UNION: #terminal POSTPONE: f #return #values #terminal-merge ;
|
: intrinsic ( #call -- quot ) node-param "intrinsic" word-prop ;
|
||||||
|
|
||||||
|
: if-intrinsic ( #call -- quot )
|
||||||
|
dup node-successor #if?
|
||||||
|
[ node-param "if-intrinsic" word-prop ] [ drop f ] if ;
|
||||||
|
|
||||||
|
PREDICATE: #call #terminal-call
|
||||||
|
dup node-successor node-successor #terminal?
|
||||||
|
swap if-intrinsic and ;
|
||||||
|
|
||||||
|
UNION: #terminal
|
||||||
|
POSTPONE: f #return #values #terminal-merge ;
|
||||||
|
|
||||||
: tail-call? ( -- ? )
|
: tail-call? ( -- ? )
|
||||||
node-stack get [ node-successor ] map [ #terminal? ] all? ;
|
node-stack get [
|
||||||
|
dup #terminal-call? swap node-successor #terminal? or
|
||||||
|
] all? ;
|
||||||
|
|
||||||
GENERIC: linearize* ( node -- next )
|
GENERIC: linearize* ( node -- next )
|
||||||
|
|
||||||
|
@ -74,12 +87,6 @@ M: #label linearize* ( node -- next )
|
||||||
dup node-param dup linearize-call-label >r
|
dup node-param dup linearize-call-label >r
|
||||||
renamed-label swap node-child linearize-1 r> ;
|
renamed-label swap node-child linearize-1 r> ;
|
||||||
|
|
||||||
: intrinsic ( #call -- quot ) node-param "intrinsic" word-prop ;
|
|
||||||
|
|
||||||
: if-intrinsic ( #call -- quot )
|
|
||||||
dup node-successor #if?
|
|
||||||
[ node-param "if-intrinsic" word-prop ] [ drop f ] if ;
|
|
||||||
|
|
||||||
: linearize-if ( node label -- next )
|
: linearize-if ( node label -- next )
|
||||||
<label> [
|
<label> [
|
||||||
>r >r node-children first2 linearize-child
|
>r >r node-children first2 linearize-child
|
||||||
|
|
|
@ -12,6 +12,8 @@ TUPLE: ds-loc n ;
|
||||||
! A call stack location.
|
! A call stack location.
|
||||||
TUPLE: cs-loc n ;
|
TUPLE: cs-loc n ;
|
||||||
|
|
||||||
|
UNION: loc ds-loc cs-loc ;
|
||||||
|
|
||||||
TUPLE: phantom-stack height ;
|
TUPLE: phantom-stack height ;
|
||||||
|
|
||||||
C: phantom-stack ( -- stack )
|
C: phantom-stack ( -- stack )
|
||||||
|
@ -75,18 +77,17 @@ M: phantom-stack cut-phantom ( n phantom -- seq )
|
||||||
SYMBOL: phantom-d
|
SYMBOL: phantom-d
|
||||||
SYMBOL: phantom-r
|
SYMBOL: phantom-r
|
||||||
|
|
||||||
|
: phantoms ( -- phantom phantom ) phantom-d get phantom-r get ;
|
||||||
|
|
||||||
: init-templates ( -- )
|
: init-templates ( -- )
|
||||||
<phantom-datastack> phantom-d set
|
<phantom-datastack> phantom-d set
|
||||||
<phantom-callstack> phantom-r set ;
|
<phantom-callstack> phantom-r set ;
|
||||||
|
|
||||||
: finalize-heights ( -- )
|
: finalize-heights ( -- )
|
||||||
phantom-d get finalize-height
|
phantoms [ finalize-height ] 2apply ;
|
||||||
phantom-r get finalize-height ;
|
|
||||||
|
|
||||||
: alloc-reg ( -- n ) free-vregs get pop ;
|
: alloc-reg ( -- n ) free-vregs get pop ;
|
||||||
|
|
||||||
: loc? ( obj -- ? ) dup ds-loc? swap cs-loc? or ;
|
|
||||||
|
|
||||||
: stack>vreg ( vreg# loc -- operand )
|
: stack>vreg ( vreg# loc -- operand )
|
||||||
>r <vreg> dup r> %peek , ;
|
>r <vreg> dup r> %peek , ;
|
||||||
|
|
||||||
|
@ -125,8 +126,6 @@ SYMBOL: phantom-r
|
||||||
2drop
|
2drop
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
: 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 ;
|
||||||
|
|
|
@ -53,12 +53,25 @@ M: object zero? drop f ;
|
||||||
|
|
||||||
: ceiling ( x -- y ) neg floor neg ; foldable
|
: ceiling ( x -- y ) neg floor neg ; foldable
|
||||||
|
|
||||||
: (repeat) ( i n quot -- )
|
G: repeat 1 standard-combination ; inline
|
||||||
pick pick >=
|
|
||||||
[ 3drop ] [ [ swap >r call 1+ r> ] keep (repeat) ] if ;
|
|
||||||
inline
|
|
||||||
|
|
||||||
: repeat ( n quot -- | quot: n -- n ) 0 -rot (repeat) ; inline
|
: (repeat-fixnum) ( i n quot -- )
|
||||||
|
pick pick fixnum>= [
|
||||||
|
3drop
|
||||||
|
] [
|
||||||
|
[ swap >r call 1 fixnum+fast r> ] keep (repeat-fixnum)
|
||||||
|
] if ; inline
|
||||||
|
|
||||||
|
M: fixnum repeat 0 -rot (repeat-fixnum) ;
|
||||||
|
|
||||||
|
: (repeat-bignum) ( i n quot -- )
|
||||||
|
pick pick bignum>= [
|
||||||
|
3drop
|
||||||
|
] [
|
||||||
|
[ swap >r call 1 bignum+ r> ] keep (repeat-bignum)
|
||||||
|
] if ; inline
|
||||||
|
|
||||||
|
M: bignum repeat 0 -rot (repeat-bignum) ;
|
||||||
|
|
||||||
: times ( n quot -- | quot: -- )
|
: times ( n quot -- | quot: -- )
|
||||||
swap [ >r dup slip r> ] repeat drop ; inline
|
swap [ >r dup slip r> ] repeat drop ; inline
|
||||||
|
|
Loading…
Reference in New Issue