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
|
2005-09-25 21:56:48 -04:00
|
|
|
USING: arrays generic io kernel listener memory namespaces
|
|
|
|
prettyprint sequences words ;
|
2005-09-25 21:54:25 -04:00
|
|
|
|
|
|
|
! Interactive inspector
|
2005-09-16 02:39:33 -04:00
|
|
|
GENERIC: extra-banner ( obj -- )
|
|
|
|
|
|
|
|
M: word extra-banner ( word -- )
|
2005-07-06 01:56:01 -04:00
|
|
|
dup word-vocabulary [
|
|
|
|
dup interned? [
|
|
|
|
"This word is located in the " write
|
|
|
|
] [
|
|
|
|
"This is an orphan not part of the dictionary." print
|
|
|
|
"It claims to belong to the " write
|
2005-09-24 15:21:17 -04:00
|
|
|
] if
|
2005-08-21 14:40:12 -04:00
|
|
|
word-vocabulary pprint " vocabulary." print
|
2005-07-06 01:56:01 -04:00
|
|
|
] [
|
|
|
|
drop
|
|
|
|
"The word is a uniquely generated symbol." print
|
2005-09-24 15:21:17 -04:00
|
|
|
] if ;
|
2005-07-06 01:56:01 -04:00
|
|
|
|
|
|
|
M: object extra-banner ( obj -- ) drop ;
|
|
|
|
|
2005-07-06 01:28:45 -04:00
|
|
|
: inspect-banner ( obj -- )
|
2005-08-21 01:17:37 -04:00
|
|
|
"You are looking at an instance of the " write dup class pprint
|
2005-07-13 22:51:43 -04:00
|
|
|
" class:" print
|
2005-08-21 14:40:12 -04:00
|
|
|
" " write dup pprint-short terpri
|
2005-08-21 01:17:37 -04:00
|
|
|
"It takes up " write dup size pprint " bytes of memory." print
|
2005-07-24 22:44:33 -04:00
|
|
|
extra-banner ;
|
2005-07-06 01:28:45 -04:00
|
|
|
|
2005-09-25 21:54:25 -04:00
|
|
|
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-09-25 21:54:25 -04:00
|
|
|
dup inspect-banner
|
|
|
|
sheet sheet-numbers sheet. ;
|
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
|
2005-08-26 18:18:07 -04:00
|
|
|
[ inspector-stack get "Inspector history:" ] callstack-hook set
|
2005-08-25 15:27:38 -04:00
|
|
|
{ } 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) ;
|