factor/library/tools/inspector.factor

49 lines
1.2 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 ;
SYMBOL: inspector-slots
: sheet-numbers ( sheet -- sheet )
dup empty? [
dup first length >array 1array swap append
dup peek inspector-slots set
] unless ;
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 sheet-numbers sheet. ;
2005-08-23 22:27:05 -04:00
: inspector-help ( -- )
terpri
2005-08-23 22:27:05 -04:00
"Object inspector." print
terpri
2005-08-23 22:27:05 -04:00
"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)
2006-07-30 21:32:21 -04:00
] listener ;
2005-08-23 22:27:05 -04:00
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) ;