: recursive-branch ( quot -- ? )
#! 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
] catch ;
-: infer-branches ( consume instruction brachlist -- )
+: infer-branches ( consume instruction branchlist -- )
#! Recursive stack effect inference is done here. If one of
#! the branches has an undecidable stack effect, we set the
#! base case to this stack effect and try again.
unit cons cons dataflow-graph cons@ ;
: dataflow-literal, ( lit -- )
- >r 0 PUSH r> dataflow, ;
+ >r f PUSH r> dataflow, ;
: dataflow-word, ( in word -- )
>r count CALL r> dataflow, ;
: set-base ( [ in | stack ] rstate -- )
#! Set the base case of the current word.
- >r uncons vector-length cons r> car cdr [
- entry-effect get swap decompose base-case set
- ] bind ;
+ dup [
+ >r uncons vector-length cons r> car cdr [
+ entry-effect get swap decompose base-case set
+ ] bind
+ ] [
+ 2drop
+ ] ifte ;
: infer ( quot -- [ in | out ] )
#! Stack effect of a quotation.
[ [ 1 | 0 ] ] [ [ >n ] infer ] unit-test
[ [ 0 | 1 ] ] [ [ n> ] infer ] unit-test
+
+[ [ 1 | 1 ] ] [ [ get ] infer ] unit-test