factor/library/tools/inspector.factor

53 lines
1.3 KiB
Factor
Raw Normal View History

2005-07-06 01:28:45 -04:00
! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: inspector
USING: arrays generic io kernel listener memory namespaces
prettyprint sequences words ;
! Interactive inspector
SYMBOL: inspector-slots
: sheet-numbers ( sheet -- sheet )
dup first length >array 1array swap append
dup peek inspector-slots set ;
2005-07-24 23:09:43 -04:00
2005-08-23 22:27:05 -04:00
SYMBOL: inspector-stack
: inspecting ( -- obj ) inspector-stack get peek ;
: (inspect) ( obj -- )
dup inspector-stack get push
2005-10-03 20:54:05 -04:00
dup summary print
sheet dup empty? [ drop ] [ sheet-numbers sheet. ] if ;
2005-08-23 22:27:05 -04:00
: inspector-help ( -- )
"Object inspector." print
"inspecting ( -- obj ) push current object" print
"go ( n -- ) inspect nth slot" print
"up -- return to previous object" print
"bye -- exit inspector" print ;
: inspector ( obj -- )
[
inspector-help
terpri
"inspector " listener-prompt set
V{ } clone inspector-stack set
2005-08-23 22:27:05 -04:00
(inspect)
listener
] with-scope ;
2005-07-06 01:28:45 -04:00
: inspect ( obj -- )
2005-08-23 22:27:05 -04:00
#! Start an inspector if its not already running.
2005-09-24 15:21:17 -04:00
inspector-stack get [ (inspect) ] [ inspector ] if ;
2005-08-23 22:27:05 -04:00
: go ( n -- ) inspector-slots get nth (inspect) ;
2005-09-14 00:37:50 -04:00
: up ( -- ) inspector-stack get dup pop* pop (inspect) ;
2006-01-23 21:03:22 -05:00
! Another feature.
IN: errors
: :error ( -- ) error get inspect ;
: :cc ( -- ) error-continuation get inspect ;