factor/library/tools/inspector.factor

46 lines
1.1 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
2006-08-01 18:42:53 -04:00
USING: arrays generic io kernel listener math memory namespaces
prettyprint sequences words ;
SYMBOL: inspector-slots
: sheet-numbers ( sheet -- sheet )
2006-08-01 18:42:53 -04:00
dup [ peek ] map inspector-slots set
dup length [ 1+ add* ] 2map ;
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-09-24 15:21:17 -04:00
inspector-stack get [ (inspect) ] [ inspector ] if ;
2005-08-23 22:27:05 -04:00
2006-08-01 18:42:53 -04:00
: go ( n -- ) 1- inspector-slots get nth (inspect) ;
2005-08-23 22:27:05 -04:00
2005-09-14 00:37:50 -04:00
: up ( -- ) inspector-stack get dup pop* pop (inspect) ;