factor/library/errors.factor

55 lines
1.4 KiB
Factor
Raw Normal View History

2006-05-24 18:42:30 -04:00
! Copyright (C) 2004, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: kernel-internals
2006-08-01 18:14:22 -04:00
USING: generic namespaces sequences ;
: >c ( continuation -- ) catchstack* push ;
: c> ( -- continuation ) catchstack* pop ;
2004-07-17 18:35:09 -04:00
IN: errors
USING: kernel ;
SYMBOL: error
SYMBOL: error-continuation
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
: rethrow ( error -- )
catchstack* empty? [
die
] [
2006-08-01 18:14:22 -04:00
dup error set-global
c> dup quotation? [ call ] [ continue-with ] if
] if ;
: cleanup ( try cleanup -- | try: -- | cleanup: -- )
[ >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 -- )
[ >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
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 )
[ <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 ;