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: generic hashtables io kernel kernel-internals lists math
|
|
|
|
memory namespaces prettyprint sequences strings test unparser
|
|
|
|
vectors words ;
|
|
|
|
|
|
|
|
SYMBOL: inspecting
|
|
|
|
|
|
|
|
GENERIC: sheet ( obj -- sheet )
|
|
|
|
|
|
|
|
M: object sheet ( obj -- sheet )
|
|
|
|
dup class "slots" word-prop
|
|
|
|
[ second ] map
|
|
|
|
tuck [ execute ] map-with 2list ;
|
|
|
|
|
|
|
|
PREDICATE: list nonvoid cons? ;
|
|
|
|
|
|
|
|
M: nonvoid sheet >list unit ;
|
|
|
|
|
|
|
|
M: vector sheet >list unit ;
|
|
|
|
|
|
|
|
M: array sheet >list unit ;
|
|
|
|
|
|
|
|
M: hashtable sheet hash>alist unzip 2list ;
|
|
|
|
|
|
|
|
: column ( list -- list )
|
|
|
|
[ unparse ] map
|
|
|
|
[ [ length ] map 0 [ max ] reduce ] keep
|
|
|
|
[ swap CHAR: \s pad-right ] map-with ;
|
|
|
|
|
2005-07-06 03:29:42 -04:00
|
|
|
: describe ( obj -- list )
|
|
|
|
sheet dup first length count swons
|
2005-07-24 22:59:23 -04:00
|
|
|
dup peek over first [ set ] 2each
|
2005-07-06 03:29:42 -04:00
|
|
|
[ column ] map
|
|
|
|
seq-transpose
|
|
|
|
[ " | " join ] map ;
|
|
|
|
|
2005-07-06 01:56:01 -04:00
|
|
|
: vocab-banner ( word -- )
|
|
|
|
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
|
|
|
|
] ifte
|
|
|
|
word-vocabulary unparse write " vocabulary." print
|
|
|
|
] [
|
|
|
|
drop
|
|
|
|
"The word is a uniquely generated symbol." print
|
|
|
|
] ifte ;
|
|
|
|
|
2005-07-06 03:29:42 -04:00
|
|
|
GENERIC: extra-banner ( obj -- )
|
|
|
|
|
2005-07-06 01:56:01 -04:00
|
|
|
M: word extra-banner ( obj -- )
|
2005-07-24 22:44:33 -04:00
|
|
|
dup vocab-banner
|
|
|
|
metaclass [
|
|
|
|
"This is a class whose behavior is specifed by the " write
|
|
|
|
unparse. " metaclass." print
|
|
|
|
] when* ;
|
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-07-13 22:51:43 -04:00
|
|
|
"You are looking at an instance of the " write dup class unparse.
|
|
|
|
" class:" print
|
|
|
|
" " write dup unparse. terpri
|
2005-07-24 22:44:33 -04:00
|
|
|
"It takes up " write dup size unparse write " bytes of memory." print
|
|
|
|
extra-banner ;
|
2005-07-06 01:28:45 -04:00
|
|
|
|
|
|
|
: inspect ( obj -- )
|
|
|
|
dup inspecting set
|
2005-07-06 03:29:42 -04:00
|
|
|
dup inspect-banner describe [ print ] each ;
|