2005-09-25 21:56:48 -04:00
|
|
|
! Copyright (C) 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
|
|
|
IN: inspector
|
2006-01-06 23:10:02 -05:00
|
|
|
USING: arrays generic hashtables help io kernel kernel-internals
|
2006-05-18 22:07:00 -04:00
|
|
|
math namespaces prettyprint sequences strings vectors words ;
|
2005-09-25 21:56:48 -04:00
|
|
|
|
2005-10-03 20:54:05 -04:00
|
|
|
GENERIC: summary ( object -- string )
|
|
|
|
|
|
|
|
: sign-string ( n -- string )
|
|
|
|
0 > "a positive " "a negative " ? ;
|
|
|
|
|
|
|
|
M: integer summary
|
2006-04-14 03:53:45 -04:00
|
|
|
dup zero? [
|
|
|
|
"a " "zero "
|
|
|
|
] [
|
|
|
|
dup sign-string over 2 mod zero? "even " "odd " ?
|
|
|
|
] if rot class word-name append3 ;
|
2005-10-03 20:54:05 -04:00
|
|
|
|
|
|
|
M: real summary
|
|
|
|
dup sign-string swap class word-name append ;
|
|
|
|
|
|
|
|
M: complex summary
|
|
|
|
"a complex number in the "
|
2005-10-29 23:25:38 -04:00
|
|
|
swap quadrant { "first" "second" "fourth" "third" } nth
|
2005-10-03 20:54:05 -04:00
|
|
|
" quadrant" append3 ;
|
|
|
|
|
2005-09-25 21:56:48 -04:00
|
|
|
GENERIC: sheet ( obj -- sheet )
|
|
|
|
|
2005-10-03 20:54:05 -04:00
|
|
|
M: object summary
|
|
|
|
"an instance of the " swap class word-name " class" append3 ;
|
|
|
|
|
2006-01-06 02:04:42 -05:00
|
|
|
: slot-sheet ( obj -- sheet )
|
2005-09-25 21:56:48 -04:00
|
|
|
dup class "slots" word-prop
|
2006-05-02 03:05:57 -04:00
|
|
|
dup [ third ] map -rot
|
2005-09-25 21:56:48 -04:00
|
|
|
[ first slot ] map-with
|
|
|
|
2array ;
|
|
|
|
|
2006-01-06 02:04:42 -05:00
|
|
|
M: object sheet ( obj -- sheet ) slot-sheet ;
|
|
|
|
|
2005-10-03 20:54:05 -04:00
|
|
|
M: sequence summary
|
|
|
|
dup length 1 = [
|
2005-10-11 23:28:17 -04:00
|
|
|
drop "a sequence containing 1 element"
|
2005-10-03 20:54:05 -04:00
|
|
|
] [
|
2005-10-11 23:28:17 -04:00
|
|
|
"a sequence containing " swap length number>string
|
2005-10-03 20:54:05 -04:00
|
|
|
" elements" append3
|
|
|
|
] if ;
|
|
|
|
|
2006-05-15 01:01:47 -04:00
|
|
|
M: quotation sheet 1array ;
|
2005-09-25 21:56:48 -04:00
|
|
|
|
|
|
|
M: vector sheet 1array ;
|
|
|
|
|
|
|
|
M: array sheet 1array ;
|
|
|
|
|
2005-10-03 20:54:05 -04:00
|
|
|
M: hashtable summary
|
|
|
|
"a hashtable storing " swap hash-size number>string
|
|
|
|
" keys" append3 ;
|
|
|
|
|
2006-01-26 23:01:14 -05:00
|
|
|
M: hashtable sheet hash>alist flip ;
|
2005-09-25 21:56:48 -04:00
|
|
|
|
2005-10-03 20:54:05 -04:00
|
|
|
M: word summary ( word -- )
|
|
|
|
dup word-vocabulary [
|
|
|
|
dup interned?
|
|
|
|
"a word in the " "a word orphaned from the " ?
|
|
|
|
swap word-vocabulary " vocabulary" append3
|
|
|
|
] [
|
|
|
|
drop "a uniquely generated symbol"
|
|
|
|
] if ;
|
|
|
|
|
2005-09-27 14:35:30 -04:00
|
|
|
: format-column ( list ? -- list )
|
2005-10-04 03:16:50 -04:00
|
|
|
>r [ unparse-short ] map r> [
|
2005-09-27 14:35:30 -04:00
|
|
|
[ 0 [ length max ] reduce ] keep
|
|
|
|
[ swap CHAR: \s pad-right ] map-with
|
|
|
|
] unless ;
|
2005-09-25 21:56:48 -04:00
|
|
|
|
|
|
|
: format-sheet ( sheet -- list )
|
2005-09-27 14:35:30 -04:00
|
|
|
#! We use an idiom to notify format-column if it is
|
|
|
|
#! formatting the last column.
|
2006-05-14 23:25:34 -04:00
|
|
|
dup length <reversed> [ zero? format-column ] 2map
|
2005-09-27 14:35:30 -04:00
|
|
|
flip [ " " join ] map ;
|
2005-09-25 21:56:48 -04:00
|
|
|
|
2005-09-25 21:59:22 -04:00
|
|
|
DEFER: describe
|
|
|
|
|
|
|
|
: sheet. ( sheet -- )
|
2006-02-03 13:20:22 -05:00
|
|
|
dup empty? [
|
|
|
|
drop
|
|
|
|
] [
|
|
|
|
dup format-sheet swap peek
|
|
|
|
[ dup [ describe ] curry simple-outliner terpri ] 2each
|
|
|
|
] if ;
|
2005-09-25 21:56:48 -04:00
|
|
|
|
2005-10-03 20:54:05 -04:00
|
|
|
: describe ( object -- ) dup summary print sheet sheet. ;
|
2005-09-25 21:59:22 -04:00
|
|
|
|
2006-05-18 22:00:11 -04:00
|
|
|
: sequence-outliner ( strings objects quot -- )
|
|
|
|
over curry-each 3array flip
|
|
|
|
[ first3 simple-outliner terpri ] each ;
|
2005-09-25 21:56:48 -04:00
|
|
|
|
2006-05-18 22:00:11 -04:00
|
|
|
: unparse-outliner ( seq quot -- | quot: obj -- )
|
2006-05-19 00:19:08 -04:00
|
|
|
>r natural-sort [ [ unparse-short ] map ] keep
|
|
|
|
r> sequence-outliner ;
|
2005-09-25 22:20:29 -04:00
|
|
|
|
2006-05-18 22:00:11 -04:00
|
|
|
: word-outliner ( seq quot -- )
|
|
|
|
>r natural-sort [ [ synopsis ] map ] keep
|
|
|
|
r> sequence-outliner ;
|
2005-09-25 21:56:48 -04:00
|
|
|
|
2006-05-18 22:00:11 -04:00
|
|
|
: words. ( vocab -- ) words [ (help) ] unparse-outliner ;
|
2005-09-25 22:20:29 -04:00
|
|
|
|
2006-05-18 22:00:11 -04:00
|
|
|
: vocabs. ( -- ) vocabs [ words. ] unparse-outliner ;
|
|
|
|
|
|
|
|
: usage. ( word -- ) usage [ usage. ] word-outliner ;
|
|
|
|
|
|
|
|
: uses. ( word -- ) uses [ uses. ] word-outliner ;
|
2005-09-25 22:20:29 -04:00
|
|
|
|
2006-05-14 23:25:34 -04:00
|
|
|
: stack. ( seq -- seq ) <reversed> >array describe ;
|
2005-09-27 00:24:42 -04:00
|
|
|
|
2005-09-25 21:56:48 -04:00
|
|
|
: .s datastack stack. ;
|
2006-05-14 23:09:47 -04:00
|
|
|
: .r retainstack stack. ;
|
2006-05-18 22:07:00 -04:00
|
|
|
|
|
|
|
: callframe. ( seq pos -- )
|
|
|
|
[
|
2006-05-19 00:19:08 -04:00
|
|
|
hilite-index set dup hilite-quotation set .
|
2006-05-18 22:07:00 -04:00
|
|
|
] with-scope ;
|
|
|
|
|
|
|
|
: callstack. ( seq -- seq )
|
2006-05-19 00:19:08 -04:00
|
|
|
3 swap group <reversed> [ first2 1- callframe. ] each ;
|
2006-05-18 22:07:00 -04:00
|
|
|
|
|
|
|
: .c callstack callstack. ;
|
2006-05-18 22:00:11 -04:00
|
|
|
|
|
|
|
: apropos ( substring -- )
|
|
|
|
all-words completions natural-sort
|
|
|
|
[ (help) ] word-outliner ;
|