factor/core/errors.factor

76 lines
1.8 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
USING: arrays generic namespaces sequences math ;
: >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
SYMBOL: error-stack-trace
SYMBOL: restarts
2006-08-15 21:23:05 -04:00
: catch ( try -- error/f )
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 -- )
2006-09-08 02:32:14 -04:00
catchstack* empty?
[ die ] [ dup error set-global c> continue-with ] if ;
2006-08-15 16:29:35 -04:00
: cleanup ( try cleanup -- )
[ >c >r call c> drop r> call ]
2006-09-08 02:32:14 -04:00
[ >r nip call r> rethrow ] ifcc ;
2006-01-07 16:03:31 -05:00
inline
2005-09-21 01:12:16 -04:00
2006-08-15 16:29:35 -04:00
: recover ( try recovery -- )
[ >c drop call c> drop ]
2006-09-08 02:32:14 -04:00
[ rot drop swap call ] ifcc ; inline
2005-03-25 21:43:06 -05:00
2006-11-30 02:15:42 -05:00
TUPLE: condition restarts continuation ;
C: condition ( error restarts cc -- condition )
2006-11-30 02:15:42 -05:00
[ set-condition-continuation ] keep
[ set-condition-restarts ] keep
[ set-delegate ] keep ;
2006-05-24 18:42:30 -04:00
: condition ( error restarts -- restart )
[ <condition> throw ] callcc1 2nip ;
2006-11-30 02:15:42 -05:00
TUPLE: restart name obj continuation ;
: restart ( restart -- )
dup restart-obj swap restart-continuation continue-with ;
2006-08-15 04:57:12 -04:00
GENERIC: compute-restarts ( error -- seq )
M: object compute-restarts drop { } ;
M: tuple compute-restarts delegate compute-restarts ;
M: condition compute-restarts
[ delegate compute-restarts ] keep
2006-11-30 02:15:42 -05:00
[ condition-continuation ] keep
condition-restarts [ first2 rot <restart> ] map-with
append ;
2006-08-02 15:17:13 -04:00
PREDICATE: array kernel-error ( obj -- ? )
2006-12-12 15:39:19 -05:00
dup first \ kernel-error eq? [
second 0 19 between?
2006-12-12 15:39:19 -05:00
] [
drop f
] if ;
TUPLE: assert got expect ;
: assert ( got expect -- * ) <assert> throw ;
: assert= ( a b -- ) 2dup = [ 2drop ] [ assert ] if ;
: assert-depth ( quot -- ) depth slip depth swap assert= ;
2006-08-02 15:17:13 -04:00
DEFER: try