factor/library/tools/describe.factor

67 lines
1.5 KiB
Factor
Raw Normal View History

! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: inspector
USING: arrays generic hashtables io kernel kernel-internals
lists math prettyprint sequences strings vectors words ;
GENERIC: sheet ( obj -- sheet )
M: object sheet ( obj -- sheet )
dup class "slots" word-prop
dup [ second ] map -rot
[ first slot ] map-with
2array ;
M: list sheet 1array ;
M: vector sheet 1array ;
M: array sheet 1array ;
M: hashtable sheet dup hash-keys swap hash-values 2array ;
: format-column ( list -- list )
2005-09-25 22:25:54 -04:00
[ unparse-short ] map
[ 0 [ length max ] reduce ] keep
[ swap CHAR: \s pad-right ] map-with ;
: format-sheet ( sheet -- list )
[ format-column ] map flip [ " " join ] map ;
2005-09-25 21:59:22 -04:00
DEFER: describe
: sheet. ( sheet -- )
dup format-sheet swap peek
[ dup [ describe ] curry write-outliner ] 2each ;
2005-09-25 21:59:22 -04:00
: describe ( object -- ) sheet sheet. ;
: word. ( word -- )
dup word-name swap dup [ see ] curry write-outliner ;
2005-09-25 22:25:54 -04:00
: object-outline ( seq quot -- )
2005-09-25 22:20:29 -04:00
swap [
2005-09-25 22:25:54 -04:00
[ unparse-short ] keep rot dupd curry write-outliner
2005-09-25 22:20:29 -04:00
] each-with ;
2005-09-25 22:20:29 -04:00
: words. ( vocab -- )
2005-09-25 22:25:54 -04:00
words [ see ] object-outline ;
2005-09-25 22:20:29 -04:00
: vocabs. ( -- )
#! Outlining word browser.
2005-09-25 22:20:29 -04:00
vocabs [ f over [ words. ] curry write-outliner ] each ;
2005-09-25 22:20:29 -04:00
: usage. ( word -- )
#! Outlining usages browser.
2005-09-25 22:25:54 -04:00
usage [ usage. ] object-outline ;
2005-09-25 22:20:29 -04:00
: uses. ( word -- )
#! Outlining call hierarchy browser.
2005-09-25 22:25:54 -04:00
uses [ uses. ] object-outline ;
2005-09-25 22:20:29 -04:00
2005-09-27 00:24:42 -04:00
: stack. ( seq -- seq )
reverse-slice >array describe ;
: .s datastack stack. ;
: .r callstack stack. ;