factor/library/tools/debugger.factor

96 lines
2.6 KiB
Factor
Raw Normal View History

2006-01-09 01:34:23 -05:00
! Copyright (C) 2004, 2006 Slava Pestov.
2006-05-15 00:03:55 -04:00
! See http://factorcode.org/license.txt for BSD license.
2006-08-01 04:45:05 -04:00
USING: arrays generic hashtables help inspector io kernel
2006-05-15 00:03:55 -04:00
kernel-internals math namespaces parser prettyprint sequences
sequences-internals strings styles vectors words ;
IN: errors
2004-11-25 21:51:47 -05:00
2006-08-01 17:56:20 -04:00
PREDICATE: array kernel-error ( obj -- ? )
dup first \ kernel-error eq? swap second 0 18 between? and ;
2006-08-01 04:45:05 -04:00
GENERIC: error. ( error -- )
GENERIC: error-help ( error -- topic )
2006-08-01 17:56:20 -04:00
M: object error. ( error -- ) . ;
2006-08-01 04:45:05 -04:00
M: object error-help ( error -- topic ) drop f ;
2006-08-01 17:56:20 -04:00
M: tuple error. ( error -- ) describe ;
2006-08-01 04:45:05 -04:00
M: tuple error-help ( error -- topic ) class ;
2006-08-01 17:56:20 -04:00
M: string error. ( error -- ) print ;
SYMBOL: restarts
2005-09-27 00:24:42 -04:00
2006-08-01 17:56:20 -04:00
: :s error-continuation get continuation-data stack. ;
: :r error-continuation get continuation-retain stack. ;
: :c error-continuation get continuation-call callstack. ;
: :get error-continuation get continuation-name hash-stack ;
: :res restarts get nth first3 continue-with ;
2006-08-01 18:14:22 -04:00
: (:help-multi)
"This error has multiple delegates:" print help-outliner ;
: (:help-none)
drop "No help for this error. " print ;
2006-08-01 04:45:05 -04:00
: :help ( -- )
error get delegates [ error-help ] map [ ] subset
2006-08-01 18:14:22 -04:00
{
{ [ dup empty? ] [ (:help-none) ] }
{ [ dup length 1 = ] [ first help ] }
{ [ t ] [ (:help-multi) ] }
} cond ;
2006-08-01 04:45:05 -04:00
: (debug-help) ( string quot -- )
<input> write-object terpri ;
: restart. ( restart n -- )
[ [ # " :res " % first % ] "" make ] keep
[ :res ] curry (debug-help) ;
: restarts. ( -- )
restarts get dup empty? [
drop
] [
terpri
"The following restarts are available:" print
terpri
dup length [ restart. ] 2each
] if ;
2004-12-25 21:28:47 -05:00
: debug-help ( -- )
terpri
"Debugger commands:" print
terpri
2006-08-01 04:45:05 -04:00
":help - documentation for this error" [ :help ] (debug-help)
":s - data stack at exception time" [ :s ] (debug-help)
":r - retain stack at exception time" [ :r ] (debug-help)
":c - call stack at exception time" [ :c ] (debug-help)
":get ( var -- value ) accesses variables at time of the error" print
2005-12-16 21:12:35 -05:00
flush ;
2004-12-25 21:28:47 -05:00
: print-error ( error -- )
[
dup error.
restarts.
debug-help
] [
"Error in print-error!" print
] recover drop ;
: try ( quot -- ) [ print-error ] recover ;
2004-11-26 22:23:57 -05:00
2005-09-27 00:24:42 -04:00
: save-error ( error continuation -- )
error-continuation set-global
dup error set-global
compute-restarts restarts set-global ;
2005-03-21 14:39:46 -05:00
2005-09-28 20:09:10 -04:00
: error-handler ( error -- )
dup continuation save-error rethrow ;
2004-11-26 22:23:57 -05:00
: init-error-handler ( -- )
V{ } clone set-catchstack
2005-03-21 14:39:46 -05:00
( kernel calls on error )
2005-09-28 20:09:10 -04:00
[ error-handler ] 5 setenv
2006-08-01 04:45:05 -04:00
\ kernel-error 12 setenv ;