2006-05-24 18:42:30 -04:00
|
|
|
! Copyright (C) 2004, 2006 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2006-05-20 02:37:35 -04:00
|
|
|
IN: kernel-internals
|
2006-05-24 04:29:25 -04:00
|
|
|
USING: generic sequences ;
|
2005-02-24 20:52:17 -05:00
|
|
|
|
2005-11-12 00:37:24 -05:00
|
|
|
: >c ( continuation -- ) catchstack* push ;
|
|
|
|
: c> ( -- continuation ) catchstack* pop ;
|
2004-07-17 18:35:09 -04:00
|
|
|
|
2006-05-20 02:37:35 -04:00
|
|
|
IN: errors
|
|
|
|
USING: kernel ;
|
|
|
|
|
2006-01-07 16:03:31 -05:00
|
|
|
: catch ( try -- error | try: -- )
|
2005-09-18 23:22:58 -04:00
|
|
|
[ >c call f c> drop f ] callcc1 nip ; inline
|
2005-09-14 00:37:50 -04:00
|
|
|
|
2006-01-07 19:10:52 -05:00
|
|
|
: rethrow ( error -- )
|
2006-07-31 16:12:29 -04:00
|
|
|
catchstack* empty? [
|
|
|
|
die
|
|
|
|
] [
|
|
|
|
c> dup quotation? [ call ] [ continue-with ] if
|
|
|
|
] if ;
|
2006-01-07 19:10:52 -05:00
|
|
|
|
2005-09-20 20:18:01 -04:00
|
|
|
: cleanup ( try cleanup -- | try: -- | cleanup: -- )
|
2005-09-22 21:01:55 -04:00
|
|
|
[ >c >r call c> drop r> call ]
|
2006-01-07 16:03:31 -05:00
|
|
|
[ drop (continue-with) >r nip call r> rethrow ] ifcc ;
|
|
|
|
inline
|
2005-09-21 01:12:16 -04:00
|
|
|
|
2005-09-22 16:21:36 -04:00
|
|
|
: recover ( try recovery -- | try: -- | recovery: error -- )
|
2005-09-22 21:01:55 -04:00
|
|
|
[ >c drop call c> drop ]
|
2005-09-22 23:18:12 -04:00
|
|
|
[ drop (continue-with) rot drop swap call ] ifcc ; inline
|
2005-03-25 21:43:06 -05:00
|
|
|
|
2006-05-24 04:29:25 -04:00
|
|
|
TUPLE: condition restarts cc ;
|
|
|
|
|
|
|
|
C: condition ( error restarts cc -- condition )
|
|
|
|
[ set-condition-cc ] keep
|
|
|
|
[ set-condition-restarts ] keep
|
|
|
|
[ set-delegate ] keep ;
|
|
|
|
|
2006-05-24 18:42:30 -04:00
|
|
|
: condition ( error restarts -- restart )
|
2006-05-24 04:29:25 -04:00
|
|
|
[ <condition> throw ] callcc1 2nip ;
|
|
|
|
|
|
|
|
GENERIC: compute-restarts
|
|
|
|
|
|
|
|
M: object compute-restarts drop { } ;
|
|
|
|
|
|
|
|
M: tuple compute-restarts delegate compute-restarts ;
|
|
|
|
|
|
|
|
M: condition compute-restarts
|
|
|
|
[ delegate compute-restarts ] keep
|
|
|
|
[ condition-cc ] keep
|
|
|
|
condition-restarts [ swap add ] map-with append ;
|