new describe tool is useful stand-alone

cvs
Slava Pestov 2005-09-26 01:56:48 +00:00
parent a5d1b36114
commit 3f6893eb29
3 changed files with 52 additions and 47 deletions

View File

@ -95,6 +95,7 @@ sequences io vectors words ;
"/library/syntax/prettyprint.factor" "/library/syntax/prettyprint.factor"
"/library/tools/interpreter.factor" "/library/tools/interpreter.factor"
"/library/tools/describe.factor"
"/library/tools/debugger.factor" "/library/tools/debugger.factor"
"/library/tools/memory.factor" "/library/tools/memory.factor"
"/library/tools/listener.factor" "/library/tools/listener.factor"

View File

@ -0,0 +1,49 @@
! 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 )
[ [ pprint-short ] string-out ] map
[ 0 [ length max ] reduce ] keep
[ swap CHAR: \s pad-right ] map-with ;
: format-sheet ( sheet -- list )
[ format-column ] map flip [ " " join ] map ;
: describe ( object -- )
sheet dup format-sheet swap peek
[ dup [ describe ] curry write-outliner ] 2each ;
: word. ( word -- )
dup word-name swap dup [ see ] curry write-outliner ;
: vocab. ( vocab -- )
f over [ words [ word. ] each ] curry write-outliner ;
: browser ( -- )
#! Outlining word browser.
vocabs [ vocab. ] each ;
: stack. ( seq -- seq )
reverse-slice >array describe ;
: .s datastack stack. ;
: .r callstack stack. ;

View File

@ -1,53 +1,8 @@
! Copyright (C) 2005 Slava Pestov. ! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license. ! See http://factor.sf.net/license.txt for BSD license.
IN: inspector IN: inspector
USING: arrays generic hashtables io kernel kernel-internals USING: arrays generic io kernel listener memory namespaces
listener lists math memory namespaces prettyprint sequences prettyprint sequences words ;
strings styles test 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 )
[ [ pprint-short ] string-out ] map
[ 0 [ length max ] reduce ] keep
[ swap CHAR: \s pad-right ] map-with ;
: format-sheet ( sheet -- list )
[ format-column ] map flip [ " " join ] map ;
: describe ( object -- )
sheet dup format-sheet swap peek
[ dup [ describe ] curry write-outliner ] 2each ;
: word. ( word -- )
dup word-name swap dup [ see ] curry write-outliner ;
: vocab. ( vocab -- )
f over [ words [ word. ] each ] curry write-outliner ;
: browser ( -- )
#! Outlining word browser.
vocabs [ vocab. ] each ;
: stack. ( seq -- seq )
reverse-slice >array describe ;
: .s datastack stack. ;
: .r callstack stack. ;
! Interactive inspector ! Interactive inspector
GENERIC: extra-banner ( obj -- ) GENERIC: extra-banner ( obj -- )