Merge branch 'row-polymorphism' of git://factorcode.org/git/factor into row-polymorphism
commit
977f8e1d2c
|
@ -10,27 +10,21 @@ stack-checker.values
|
||||||
stack-checker.visitor ;
|
stack-checker.visitor ;
|
||||||
IN: stack-checker.row-polymorphism
|
IN: stack-checker.row-polymorphism
|
||||||
|
|
||||||
:: with-inner-d ( quot -- inner-d )
|
: with-inner-d ( quot -- inner-d )
|
||||||
inner-d-index get :> old-inner-d-index
|
inner-d-index get
|
||||||
meta-d length inner-d-index set
|
[ meta-d length inner-d-index set call ] dip
|
||||||
quot call
|
inner-d-index get [ min inner-d-index set ] keep ; inline
|
||||||
inner-d-index get :> new-inner-d-index
|
|
||||||
old-inner-d-index new-inner-d-index min inner-d-index set
|
|
||||||
new-inner-d-index ; inline
|
|
||||||
|
|
||||||
:: with-effect-here ( quot -- effect )
|
:: (effect-here) ( inner-d old-meta-d-length old-input-count -- effect )
|
||||||
input-count get :> old-input-count
|
old-meta-d-length inner-d - input-count get old-input-count - +
|
||||||
meta-d length :> old-meta-d-length
|
meta-d length inner-d -
|
||||||
|
[ "x" <array> ] bi@ terminated? get <terminated-effect> ; inline
|
||||||
|
|
||||||
quot with-inner-d :> inner-d
|
: with-effect-here ( quot -- effect )
|
||||||
|
meta-d length input-count get
|
||||||
|
[ with-inner-d ] 2dip (effect-here) ; inline
|
||||||
|
|
||||||
input-count get :> new-input-count
|
:: (check-variable) ( actual-count declared-count variable vars -- difference ? )
|
||||||
old-meta-d-length inner-d -
|
|
||||||
new-input-count old-input-count - + :> in
|
|
||||||
meta-d length inner-d - :> out
|
|
||||||
in "x" <array> out "x" <array> terminated? get <terminated-effect> ; inline
|
|
||||||
|
|
||||||
:: check-variable ( actual-count declared-count variable vars -- difference ? )
|
|
||||||
actual-count declared-count -
|
actual-count declared-count -
|
||||||
variable [
|
variable [
|
||||||
variable vars at* nip
|
variable vars at* nip
|
||||||
|
@ -44,20 +38,25 @@ IN: stack-checker.row-polymorphism
|
||||||
[ at+ ]
|
[ at+ ]
|
||||||
[ 3drop ] if ; inline
|
[ 3drop ] if ; inline
|
||||||
|
|
||||||
:: check-variables ( vars declared actual -- ? )
|
:: check-variable ( vars declared actual slot var-slot -- diff ok? var )
|
||||||
actual terminated?>> [ t ] [
|
actual declared [ slot call length ] bi@ declared var-slot call
|
||||||
actual declared [ in>> length ] bi@ declared in-var>>
|
[ vars (check-variable) ] keep ; inline
|
||||||
[ vars check-variable ] keep :> ( in-diff in-ok? in-var )
|
|
||||||
actual declared [ out>> length ] bi@ declared out-var>>
|
:: unify-variables ( in-diff in-ok? in-var out-diff out-ok? out-var vars -- ? )
|
||||||
[ vars check-variable ] keep :> ( out-diff out-ok? out-var )
|
|
||||||
{ [ in-ok? ] [ out-ok? ] [ in-diff out-diff = ] } 0&&
|
{ [ in-ok? ] [ out-ok? ] [ in-diff out-diff = ] } 0&&
|
||||||
dup [
|
dup [
|
||||||
in-var [ in-diff swap vars adjust-variable ] when*
|
in-var [ in-diff swap vars adjust-variable ] when*
|
||||||
out-var [ out-diff swap vars adjust-variable ] when*
|
out-var [ out-diff swap vars adjust-variable ] when*
|
||||||
] when
|
] when ;
|
||||||
|
|
||||||
|
: check-variables ( vars declared actual -- ? )
|
||||||
|
dup terminated?>> [ 3drop t ] [
|
||||||
|
[ [ in>> ] [ in-var>> ] check-variable ]
|
||||||
|
[ [ out>> ] [ out-var>> ] check-variable ]
|
||||||
|
[ 2drop ] 3tri unify-variables
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
: complex-unbalanced-branches-error ( known -- * )
|
: combinator-unbalanced-branches-error ( known -- * )
|
||||||
[ word>> ] [
|
[ word>> ] [
|
||||||
branches>> <reversed>
|
branches>> <reversed>
|
||||||
[ [ known>callable ] { } map-as ]
|
[ [ known>callable ] { } map-as ]
|
||||||
|
@ -68,5 +67,5 @@ IN: stack-checker.row-polymorphism
|
||||||
: check-declared-effect ( known effect -- )
|
: check-declared-effect ( known effect -- )
|
||||||
[ >>actual ] keep
|
[ >>actual ] keep
|
||||||
2dup [ [ variables>> ] [ effect>> ] bi ] dip check-variables
|
2dup [ [ variables>> ] [ effect>> ] bi ] dip check-variables
|
||||||
[ 2drop ] [ drop complex-unbalanced-branches-error ] if ;
|
[ 2drop ] [ drop combinator-unbalanced-branches-error ] if ;
|
||||||
|
|
||||||
|
|
|
@ -13,28 +13,35 @@ ERROR: stack-effect-omits-dashes ;
|
||||||
|
|
||||||
SYMBOL: effect-var
|
SYMBOL: effect-var
|
||||||
|
|
||||||
: parse-var ( first? var name -- var )
|
<PRIVATE
|
||||||
|
: end-token? ( end token -- token ? ) [ nip ] [ = ] 2bi ; inline
|
||||||
|
: effect-opener? ( token -- token ? ) dup { f "(" "((" "--" } member? ; inline
|
||||||
|
: effect-closer? ( token -- token ? ) dup { ")" "))" } member? ; inline
|
||||||
|
: effect-variable? ( token -- token' ? ) ".." ?head ; inline
|
||||||
|
|
||||||
|
: parse-effect-var ( first? var name -- var )
|
||||||
nip
|
nip
|
||||||
[ ":" ?tail [ effect-variable-can't-have-type ] when ] curry
|
[ ":" ?tail [ effect-variable-can't-have-type ] when ] curry
|
||||||
[ invalid-effect-variable ] if ;
|
[ invalid-effect-variable ] if ;
|
||||||
|
|
||||||
: parse-effect-token ( first? var end -- var more? )
|
: parse-effect-value ( token -- value )
|
||||||
scan [ nip ] [ = ] 2bi [ drop nip f ] [
|
|
||||||
dup { f "(" "((" "--" } member? [ bad-effect ] [
|
|
||||||
dup { ")" "))" } member? [ stack-effect-omits-dashes ] [
|
|
||||||
".." ?head [ parse-var t ] [
|
|
||||||
[ drop ] 2dip
|
|
||||||
":" ?tail [
|
":" ?tail [
|
||||||
scan {
|
scan {
|
||||||
{ [ dup "(" = ] [ drop ")" parse-effect ] }
|
{ [ dup "(" = ] [ drop ")" parse-effect ] }
|
||||||
{ [ dup f = ] [ ")" unexpected-eof ] }
|
{ [ dup f = ] [ ")" unexpected-eof ] }
|
||||||
[ parse-word dup class? [ bad-effect ] unless ]
|
[ parse-word dup class? [ bad-effect ] unless ]
|
||||||
} cond 2array
|
} cond 2array
|
||||||
] when , t
|
] when ;
|
||||||
] if
|
PRIVATE>
|
||||||
] if
|
|
||||||
] if
|
: parse-effect-token ( first? var end -- var more? )
|
||||||
] if ;
|
scan {
|
||||||
|
{ [ end-token? ] [ drop nip f ] }
|
||||||
|
{ [ effect-opener? ] [ bad-effect ] }
|
||||||
|
{ [ effect-closer? ] [ stack-effect-omits-dashes ] }
|
||||||
|
{ [ effect-variable? ] [ parse-effect-var t ] }
|
||||||
|
[ [ drop ] 2dip parse-effect-value , t ]
|
||||||
|
} cond ;
|
||||||
|
|
||||||
: parse-effect-tokens ( end -- var tokens )
|
: parse-effect-tokens ( end -- var tokens )
|
||||||
[
|
[
|
||||||
|
|
Loading…
Reference in New Issue