factor/library/tools/debugger.factor

113 lines
2.8 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.
USING: arrays definitions generic hashtables help tools io
2006-08-25 00:02:30 -04:00
kernel 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 )
M: object error. . ;
M: object error-help drop f ;
2006-08-01 04:45:05 -04:00
M: tuple error. describe ;
M: tuple error-help class ;
2006-08-01 04:45:05 -04:00
M: string error. print ;
2006-08-01 17:56:20 -04:00
SYMBOL: restarts
2005-09-27 00:24:42 -04:00
2006-08-16 21:55:53 -04:00
: :s ( -- )
error-continuation get continuation-data stack. ;
: :r ( -- )
error-continuation get continuation-retain stack. ;
: :c ( -- )
error-continuation get continuation-call callstack. ;
: :get ( variable -- value )
error-continuation get continuation-name hash-stack ;
: :res ( n -- )
restarts get nth first3 continue-with ;
2006-08-25 00:02:30 -04:00
: :edit ( -- )
2006-08-25 21:29:23 -04:00
error get
dup parse-error-file ?resource-path
swap parse-error-line
2006-08-25 00:02:30 -04:00
edit-location ;
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
: restart. ( restart n -- )
[ [ # " :res " % first % ] "" make ] keep
2006-10-04 00:40:10 -04:00
[ :res ] curry print-quot ;
: 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-10-04 00:40:10 -04:00
":help - documentation for this error" [ :help ] print-quot
":s - data stack at exception time" [ :s ] print-quot
":r - retain stack at exception time" [ :r ] print-quot
":c - call stack at exception time" [ :c ] print-quot
2006-08-25 00:02:30 -04:00
error get [ parse-error? ] is? [
2006-10-04 00:40:10 -04:00
":edit - jump to source location" [ :edit ] print-quot
2006-08-25 00:02:30 -04:00
] when
":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
2006-08-15 04:57:12 -04: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 ;