f throw no longer a no-op

cvs
Slava Pestov 2005-09-18 02:25:18 +00:00
parent 9193b4fecb
commit fa1e1a4801
18 changed files with 57 additions and 45 deletions

View File

@ -162,6 +162,6 @@ M: compound (uncrossref)
over "infer" word-prop or [ over "infer" word-prop or [
drop drop
] [ ] [
dup { "infer-effect" "base-case" "no-effect" } dup { "infer-effect" "base-case" "no-effect" "terminates" }
reset-props update-xt reset-props update-xt
] ifte ; ] ifte ;

View File

@ -2,8 +2,8 @@
! See http://factor.sf.net/license.txt for BSD license. ! See http://factor.sf.net/license.txt for BSD license.
USING: alien assembler command-line compiler compiler-backend USING: alien assembler command-line compiler compiler-backend
errors generic hashtables io io-internals kernel errors generic hashtables io io-internals kernel
kernel-internals lists math memory namespaces parser sequences kernel-internals lists math memory namespaces optimizer parser
sequences-internals words ; sequences sequences-internals words ;
: pull-in ( ? list -- ) : pull-in ( ? list -- )
swap [ swap [
@ -78,7 +78,8 @@ compile? [
{ {
uncons 1+ 1- + <= > >= mod length uncons 1+ 1- + <= > >= mod length
nth-unsafe set-nth-unsafe nth-unsafe set-nth-unsafe
= string>number number>string scan (generate) = string>number number>string scan solve-recursion
kill-set kill-node (generate)
} [ compile ] each } [ compile ] each
] when ] when

View File

@ -167,8 +167,7 @@ M: f ' ( obj -- ptr )
0 emit ; 0 emit ;
: word-error ( word msg -- ) : word-error ( word msg -- )
[ % dup word-vocabulary % " " % word-name % ] "" make [ % dup word-vocabulary % " " % word-name % ] "" make throw ;
throw ; inline
: transfer-word ( word -- word ) : transfer-word ( word -- word )
#! This is a hack. See doc/bootstrap.txt. #! This is a hack. See doc/bootstrap.txt.

View File

@ -156,7 +156,7 @@ IN: kernel
#! Push the number of elements on the datastack. #! Push the number of elements on the datastack.
datastack length ; datastack length ;
: no-cond "cond fall-through" throw ; inline : no-cond "cond fall-through" throw ;
: cond ( conditions -- ) : cond ( conditions -- )
#! Conditions is a sequence of quotation pairs. #! Conditions is a sequence of quotation pairs.

View File

@ -45,7 +45,7 @@ GENERIC: resize ( n seq -- seq )
TUPLE: bounds-error index seq ; TUPLE: bounds-error index seq ;
: bounds-error <bounds-error> throw ; inline : bounds-error <bounds-error> throw ;
: growable-check ( n seq -- fx seq ) : growable-check ( n seq -- fx seq )
>r >fixnum dup 0 fixnum< >r >fixnum dup 0 fixnum<

View File

@ -11,7 +11,7 @@ USING: kernel-internals lists ;
TUPLE: no-method object generic ; TUPLE: no-method object generic ;
: no-method ( object generic -- ) <no-method> throw ; inline : no-method ( object generic -- ) <no-method> throw ;
: catchstack ( -- cs ) 6 getenv ; : catchstack ( -- cs ) 6 getenv ;
: set-catchstack ( cs -- ) 6 setenv ; : set-catchstack ( cs -- ) 6 setenv ;

View File

@ -31,7 +31,7 @@ math namespaces sequences words ;
TUPLE: no-math-method left right generic ; TUPLE: no-math-method left right generic ;
: no-math-method ( left right generic -- ) : no-math-method ( left right generic -- )
3dup <no-math-method> throw ; inline 3dup <no-math-method> throw ;
: applicable-method ( generic class -- quot ) : applicable-method ( generic class -- quot )
over "methods" word-prop hash [ ] [ over "methods" word-prop hash [ ] [

View File

@ -83,8 +83,7 @@ namespaces parser prettyprint sequences strings vectors words ;
] make-hash ; ] make-hash ;
: (infer-branches) ( branchlist -- list ) : (infer-branches) ( branchlist -- list )
[ infer-branch ] map dup unify-effects [ infer-branch ] map dup unify-effects unify-dataflow ;
unify-dataflow ;
: infer-branches ( branches node -- ) : infer-branches ( branches node -- )
#! Recursive stack effect inference is done here. If one of #! Recursive stack effect inference is done here. If one of

View File

@ -55,8 +55,8 @@ M: node = eq? ;
: empty-node f { } { } { } { } ; : empty-node f { } { } { } { } ;
: param-node ( label) { } { } { } { } ; : param-node ( label) { } { } { } { } ;
: in-d-node ( inputs) >r f r> { } { } { } ; : in-node ( inputs) >r f r> { } { } { } ;
: out-d-node ( outputs) >r f { } r> { } { } ; : out-node ( outputs) >r f { } r> { } { } ;
: d-tail ( n -- list ) meta-d get tail* ; : d-tail ( n -- list ) meta-d get tail* ;
: r-tail ( n -- list ) meta-r get tail* ; : r-tail ( n -- list ) meta-r get tail* ;
@ -69,7 +69,7 @@ C: #label make-node ;
TUPLE: #entry ; TUPLE: #entry ;
C: #entry make-node ; C: #entry make-node ;
: #entry ( -- node ) meta-d get clone in-d-node <#entry> ; : #entry ( -- node ) meta-d get clone in-node <#entry> ;
TUPLE: #call ; TUPLE: #call ;
C: #call make-node ; C: #call make-node ;
@ -82,31 +82,35 @@ C: #call-label make-node ;
TUPLE: #shuffle ; TUPLE: #shuffle ;
C: #shuffle make-node ; C: #shuffle make-node ;
: #shuffle ( -- node ) empty-node <#shuffle> ; : #shuffle ( -- node ) empty-node <#shuffle> ;
: #push ( outputs -- node ) d-tail out-d-node <#shuffle> ; : #push ( outputs -- node ) d-tail out-node <#shuffle> ;
TUPLE: #values ; TUPLE: #values ;
C: #values make-node ; C: #values make-node ;
: #values ( -- node ) meta-d get clone in-d-node <#values> ; : #values ( -- node ) meta-d get clone in-node <#values> ;
TUPLE: #return ; TUPLE: #return ;
C: #return make-node ; C: #return make-node ;
: #return ( label -- node ) : #return ( label -- node )
#! The parameter is the label we are returning from, or if #! The parameter is the label we are returning from, or if
#! f, this is a top-level return. #! f, this is a top-level return.
meta-d get clone in-d-node <#return> meta-d get clone in-node <#return>
[ set-node-param ] keep ; [ set-node-param ] keep ;
TUPLE: #ifte ; TUPLE: #ifte ;
C: #ifte make-node ; C: #ifte make-node ;
: #ifte ( in -- node ) 1 d-tail in-d-node <#ifte> ; : #ifte ( in -- node ) 1 d-tail in-node <#ifte> ;
TUPLE: #dispatch ; TUPLE: #dispatch ;
C: #dispatch make-node ; C: #dispatch make-node ;
: #dispatch ( in -- node ) 1 d-tail in-d-node <#dispatch> ; : #dispatch ( in -- node ) 1 d-tail in-node <#dispatch> ;
TUPLE: #merge ; TUPLE: #merge ;
C: #merge make-node ; C: #merge make-node ;
: #merge ( -- node ) meta-d get clone out-d-node <#merge> ; : #merge ( -- node ) meta-d get clone out-node <#merge> ;
TUPLE: #terminate ;
C: #terminate make-node ;
: #terminate ( -- node ) empty-node <#terminate> ;
: node-inputs ( d-count r-count node -- ) : node-inputs ( d-count r-count node -- )
tuck tuck
@ -169,10 +173,10 @@ SYMBOL: current-node
] ifte ; ] ifte ;
: drop-inputs ( node -- #shuffle ) : drop-inputs ( node -- #shuffle )
node-in-d clone in-d-node <#shuffle> ; node-in-d clone in-node <#shuffle> ;
: #drop ( n -- #shuffle ) : #drop ( n -- #shuffle )
d-tail in-d-node <#shuffle> ; d-tail in-node <#shuffle> ;
: each-node ( node quot -- | quot: node -- ) : each-node ( node quot -- | quot: node -- )
over [ over [

View File

@ -15,7 +15,7 @@ TUPLE: inference-error message rstate data-stack call-stack ;
: inference-error ( msg -- ) : inference-error ( msg -- )
recursive-state get meta-d get meta-r get recursive-state get meta-d get meta-r get
<inference-error> throw ; inline <inference-error> throw ;
M: inference-error error. ( error -- ) M: inference-error error. ( error -- )
"! Inference error:" print "! Inference error:" print
@ -78,11 +78,11 @@ M: wrapper apply-object wrapped apply-literal ;
: active? ( -- ? ) : active? ( -- ? )
#! Is this branch not terminated? #! Is this branch not terminated?
d-in get meta-d get and ; meta-d get meta-r get and ;
: terminate ( -- ) : terminate ( -- )
#! Ignore this branch's stack effect. #! Ignore this branch's stack effect.
meta-d off meta-r off d-in off ; meta-d off meta-r off #terminate node, ;
: infer-quot ( quot -- ) : infer-quot ( quot -- )
#! Recursive calls to this word are made for nested #! Recursive calls to this word are made for nested

View File

@ -41,15 +41,16 @@ hashtables parser prettyprint ;
] with-nesting ] with-nesting
] with-recursive-state ; ] with-recursive-state ;
: infer-compound ( word base-case -- effect ) : infer-compound ( word base-case -- terminates? effect )
#! Infer a word's stack effect in a separate inferencer #! Infer a word's stack effect in a separate inferencer
#! instance. #! instance. Outputs a boolean if the word terminates
#! control flow by throwing an exception or restoring a
#! continuation.
[ [
inferring-base-case set inferring-base-case set
recursive-state get init-inference recursive-state get init-inference
dup inline-block drop [ inline-block drop active? not effect ] keep
effect ] with-scope over consume/produce over [ terminate ] when ;
] with-scope [ consume/produce ] keep ;
GENERIC: apply-word GENERIC: apply-word
@ -60,7 +61,9 @@ M: object apply-word ( word -- )
M: compound apply-word ( word -- ) M: compound apply-word ( word -- )
#! Infer a compound word's stack effect. #! Infer a compound word's stack effect.
[ [
dup f infer-compound "infer-effect" set-word-prop dup dup f infer-compound
>r "terminates" set-word-prop r>
"infer-effect" set-word-prop
] [ ] [
[ swap t "no-effect" set-word-prop rethrow ] when* [ swap t "no-effect" set-word-prop rethrow ] when*
] catch ; ] catch ;
@ -73,7 +76,8 @@ M: compound apply-word ( word -- )
over "infer" word-prop [ over "infer" word-prop [
swap first length ensure-values call drop swap first length ensure-values call drop
] [ ] [
consume/produce dupd consume/produce
"terminates" word-prop [ terminate ] when
] ifte* ] ifte*
] [ ] [
apply-word apply-word
@ -93,7 +97,7 @@ M: symbol apply-object ( word -- )
[ #call-label ] [ #call ] ?ifte [ #call-label ] [ #call ] ?ifte
r> over set-node-in-d node, r> over set-node-in-d node,
] [ ] [
drop dup t infer-compound "base-case" set-word-prop drop dup t infer-compound nip "base-case" set-word-prop
] ifte ; ] ifte ;
: base-case ( word label -- ) : base-case ( word label -- )

View File

@ -21,7 +21,7 @@ M: number = ( n n -- ? ) number= ;
over real? over real? and [ over real? over real? and [
(rect>) (rect>)
] [ ] [
"Complex number must have real components" throw drop "Complex number must have real components" throw
] ifte ; inline ] ifte ; inline
: >rect ( x -- xr xi ) dup real swap imaginary ; inline : >rect ( x -- xr xi ) dup real swap imaginary ; inline

View File

@ -31,8 +31,7 @@ IN: math-internals
: fraction> ( a b -- a/b ) : fraction> ( a b -- a/b )
dup 1 number= [ drop ] [ (fraction>) ] ifte ; inline dup 1 number= [ drop ] [ (fraction>) ] ifte ; inline
: division-by-zero ( x y -- ) : division-by-zero ( x y -- ) "Division by zero" throw ;
"Division by zero" throw drop ; inline
M: integer / ( x y -- x/y ) M: integer / ( x y -- x/y )
dup 0 number= [ dup 0 number= [

View File

@ -6,7 +6,7 @@ strings ;
! Number parsing ! Number parsing
: not-a-number "Not a number" throw ; inline : not-a-number "Not a number" throw ;
GENERIC: digit> ( ch -- n ) GENERIC: digit> ( ch -- n )
M: digit digit> CHAR: 0 - ; M: digit digit> CHAR: 0 - ;

View File

@ -1,5 +1,4 @@
IN: temporary IN: temporary
USING: memory ;
USE: errors USE: errors
USE: kernel USE: kernel
USE: namespaces USE: namespaces
@ -7,6 +6,7 @@ USE: test
USE: lists USE: lists
USE: parser USE: parser
USE: io USE: io
USE: memory
[ f ] [ [ ] [ ] catch ] unit-test [ f ] [ [ ] [ ] catch ] unit-test

View File

@ -1,6 +1,6 @@
IN: temporary IN: temporary
USING: arrays generic inference kernel lists math math-internals USING: arrays errors generic inference kernel lists math
namespaces parser sequences test vectors ; math-internals namespaces parser sequences test vectors ;
[ [
<< shuffle f { "a" } { } { "a" } { "a" } >> << shuffle f { "a" } { } { "a" } { "a" } >>
@ -57,6 +57,14 @@ namespaces parser sequences test vectors ;
[ [ 2 2 fixnum+ ] ] [ [ 2 2 fixnum* ] ] ifte call [ [ 2 2 fixnum+ ] ] [ [ 2 2 fixnum* ] ] ifte call
] unit-test-fails ] unit-test-fails
! Test inference of termination of control flow
: termination-test-1
"foo" throw ;
: termination-test-2 [ termination-test-1 ] [ 3 ] ifte ;
[ @{ 1 1 }@ ] [ [ termination-test-2 ] infer ] unit-test
: infinite-loop infinite-loop ; : infinite-loop infinite-loop ;
: simple-recursion-1 : simple-recursion-1

View File

@ -74,7 +74,7 @@ M: port set-timeout ( timeout port -- )
: >port< dup port-handle swap delegate ; : >port< dup port-handle swap delegate ;
: pending-error ( port -- ) : pending-error ( port -- )
dup port-error f rot set-port-error throw ; dup port-error f rot set-port-error [ throw ] when* ;
: report-error ( error port -- ) : report-error ( error port -- )
[ "Error on fd " % dup port-handle # ": " % swap % ] "" make [ "Error on fd " % dup port-handle # ": " % swap % ] "" make

View File

@ -50,9 +50,7 @@ void throw_error(CELL error, bool keep_stacks)
void primitive_throw(void) void primitive_throw(void)
{ {
CELL error = dpop(); throw_error(dpop(),true);
if(error != F)
throw_error(error,true);
} }
void primitive_die(void) void primitive_die(void)