inferencer fixes
parent
15a07f6f40
commit
8c23dbb554
|
@ -93,12 +93,12 @@ DEFER: (infer)
|
||||||
: recursive-branch ( quot -- ? )
|
: recursive-branch ( quot -- ? )
|
||||||
#! Set base case if inference didn't fail.
|
#! Set base case if inference didn't fail.
|
||||||
[
|
[
|
||||||
car infer-branch drop recursive-state get set-base t
|
car infer-branch drop recursive-state get set-base t
|
||||||
] [
|
] [
|
||||||
[ drop f ] when
|
[ drop f ] when
|
||||||
] catch ;
|
] catch ;
|
||||||
|
|
||||||
: infer-branches ( consume instruction brachlist -- )
|
: infer-branches ( consume instruction branchlist -- )
|
||||||
#! Recursive stack effect inference is done here. If one of
|
#! Recursive stack effect inference is done here. If one of
|
||||||
#! the branches has an undecidable stack effect, we set the
|
#! the branches has an undecidable stack effect, we set the
|
||||||
#! base case to this stack effect and try again.
|
#! base case to this stack effect and try again.
|
||||||
|
|
|
@ -53,7 +53,7 @@ SYMBOL: 2GENERIC
|
||||||
unit cons cons dataflow-graph cons@ ;
|
unit cons cons dataflow-graph cons@ ;
|
||||||
|
|
||||||
: dataflow-literal, ( lit -- )
|
: dataflow-literal, ( lit -- )
|
||||||
>r 0 PUSH r> dataflow, ;
|
>r f PUSH r> dataflow, ;
|
||||||
|
|
||||||
: dataflow-word, ( in word -- )
|
: dataflow-word, ( in word -- )
|
||||||
>r count CALL r> dataflow, ;
|
>r count CALL r> dataflow, ;
|
||||||
|
|
|
@ -138,9 +138,13 @@ DEFER: apply-word
|
||||||
|
|
||||||
: set-base ( [ in | stack ] rstate -- )
|
: set-base ( [ in | stack ] rstate -- )
|
||||||
#! Set the base case of the current word.
|
#! Set the base case of the current word.
|
||||||
>r uncons vector-length cons r> car cdr [
|
dup [
|
||||||
entry-effect get swap decompose base-case set
|
>r uncons vector-length cons r> car cdr [
|
||||||
] bind ;
|
entry-effect get swap decompose base-case set
|
||||||
|
] bind
|
||||||
|
] [
|
||||||
|
2drop
|
||||||
|
] ifte ;
|
||||||
|
|
||||||
: infer ( quot -- [ in | out ] )
|
: infer ( quot -- [ in | out ] )
|
||||||
#! Stack effect of a quotation.
|
#! Stack effect of a quotation.
|
||||||
|
|
|
@ -193,3 +193,5 @@ SYMBOL: sym-test
|
||||||
|
|
||||||
[ [ 1 | 0 ] ] [ [ >n ] infer ] unit-test
|
[ [ 1 | 0 ] ] [ [ >n ] infer ] unit-test
|
||||||
[ [ 0 | 1 ] ] [ [ n> ] infer ] unit-test
|
[ [ 0 | 1 ] ] [ [ n> ] infer ] unit-test
|
||||||
|
|
||||||
|
[ [ 1 | 1 ] ] [ [ get ] infer ] unit-test
|
||||||
|
|
Loading…
Reference in New Issue