factor/library/tools/describe.factor

64 lines
1.5 KiB
Factor
Raw Normal View History

2006-05-20 16:42:33 -04:00
! Copyright (C) 2005, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: tools
USING: arrays generic hashtables io kernel kernel-internals
math namespaces prettyprint sequences strings styles vectors
words ;
2006-08-16 21:55:53 -04:00
GENERIC: sheet ( object -- sheet )
2006-08-16 21:55:53 -04:00
: slot-sheet ( object -- sheet )
2006-08-01 18:42:53 -04:00
dup class "slots" word-prop [
dup third -rot first slot 2array
] map-with ;
M: object sheet slot-sheet ;
2006-01-06 02:04:42 -05:00
M: tuple sheet
2006-08-01 18:42:53 -04:00
dup slot-sheet swap delegate [ 1 tail ] unless ;
2005-10-03 20:54:05 -04:00
M: sequence summary
2006-05-20 16:42:33 -04:00
[ dup length # " element " % class word-name % ] "" make ;
2005-10-03 20:54:05 -04:00
2006-08-01 18:42:53 -04:00
: sequence-sheet [ 1array ] map ;
2006-08-01 18:42:53 -04:00
M: quotation sheet sequence-sheet ;
M: vector sheet sequence-sheet ;
M: array sheet sequence-sheet ;
2005-10-03 20:54:05 -04:00
M: hashtable summary
"a hashtable storing " swap hash-size number>string
" keys" append3 ;
2006-08-01 18:42:53 -04:00
M: hashtable sheet hash>alist ;
2005-09-25 21:59:22 -04:00
: sheet. ( sheet -- )
2006-08-01 18:42:53 -04:00
dup empty? [
2006-07-31 21:08:25 -04:00
drop
] [
dup first length 1 =
{ 0 0 } { 10 0 } ? table-gap associate
[ dup unparse-short swap write-object ]
tabular-output
] if ;
2005-10-03 20:54:05 -04:00
: describe ( object -- ) dup summary print sheet sheet. ;
2005-09-25 21:59:22 -04:00
2006-08-16 21:55:53 -04:00
: stack. ( seq -- ) <reversed> >array sheet sheet. ;
2005-09-27 00:24:42 -04:00
2006-08-16 21:55:53 -04:00
: .s ( -- ) datastack stack. ;
: .r ( -- ) retainstack stack. ;
: callframe. ( seq pos -- )
[
2006-07-30 22:05:44 -04:00
hilite-index set dup hilite-quotation set
1 nesting-limit set
2006-07-30 22:20:52 -04:00
pprint
terpri
] with-scope ;
2006-08-16 21:55:53 -04:00
: callstack. ( seq -- )
3 group <reversed> [ first2 1- callframe. ] each ;
2006-08-16 21:55:53 -04:00
: .c ( -- ) callstack callstack. ;