2006-03-21 00:44:19 -05:00
|
|
|
! Copyright (C) 2003, 2006 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2004-11-25 21:08:09 -05:00
|
|
|
IN: prettyprint
|
2006-05-15 01:01:47 -04:00
|
|
|
USING: arrays generic hashtables io kernel math namespaces
|
2005-10-25 21:52:26 -04:00
|
|
|
sequences strings styles words ;
|
2004-11-25 21:08:09 -05:00
|
|
|
|
2005-08-21 01:17:37 -04:00
|
|
|
: declaration. ( word prop -- )
|
2005-09-24 15:21:17 -04:00
|
|
|
tuck word-name word-prop [ pprint-word ] [ drop ] if ;
|
2004-11-25 21:08:09 -05:00
|
|
|
|
2005-08-21 01:17:37 -04:00
|
|
|
: declarations. ( word -- )
|
2005-11-29 23:49:59 -05:00
|
|
|
{
|
2005-08-12 18:02:03 -04:00
|
|
|
POSTPONE: parsing
|
|
|
|
POSTPONE: inline
|
|
|
|
POSTPONE: foldable
|
2005-11-29 23:49:59 -05:00
|
|
|
} [ declaration. ] each-with ;
|
2004-11-25 21:08:09 -05:00
|
|
|
|
2006-07-09 19:50:56 -04:00
|
|
|
: write-vocab ( vocab -- )
|
|
|
|
dup <vocab-link> presented associate styled-text ;
|
|
|
|
|
2005-12-28 20:25:17 -05:00
|
|
|
: in. ( word -- )
|
2006-05-30 18:57:34 -04:00
|
|
|
word-vocabulary [
|
2006-07-09 19:50:56 -04:00
|
|
|
<block \ IN: pprint-word write-vocab block;
|
2006-05-30 18:57:34 -04:00
|
|
|
] when* ;
|
2005-12-28 20:25:17 -05:00
|
|
|
|
|
|
|
: (synopsis) ( word -- )
|
|
|
|
dup in. dup definer pprint-word pprint-word ;
|
|
|
|
|
2005-07-17 14:48:55 -04:00
|
|
|
: comment. ( comment -- )
|
2006-05-19 00:19:08 -04:00
|
|
|
[ H{ { font-style italic } } [ text ] with-style ] when* ;
|
2005-02-07 13:14:55 -05:00
|
|
|
|
2006-01-05 00:33:12 -05:00
|
|
|
: stack-picture ( seq -- string )
|
2006-03-29 17:19:58 -05:00
|
|
|
[ [ % CHAR: \s , ] each ] "" make ;
|
2004-12-12 23:49:44 -05:00
|
|
|
|
2005-08-21 01:17:37 -04:00
|
|
|
: effect>string ( effect -- string )
|
2005-08-21 20:50:14 -04:00
|
|
|
[
|
2006-01-19 18:19:55 -05:00
|
|
|
"( " %
|
2006-01-05 00:33:12 -05:00
|
|
|
dup first stack-picture %
|
2006-03-29 17:19:58 -05:00
|
|
|
"-- " %
|
2006-01-05 00:33:12 -05:00
|
|
|
second stack-picture %
|
2006-03-29 17:19:58 -05:00
|
|
|
")" %
|
2005-08-25 15:27:38 -04:00
|
|
|
] "" make ;
|
2004-11-25 21:08:09 -05:00
|
|
|
|
2005-08-21 01:17:37 -04:00
|
|
|
: stack-effect ( word -- string )
|
|
|
|
dup "stack-effect" word-prop [ ] [
|
2006-03-29 17:19:58 -05:00
|
|
|
"infer-effect" word-prop dup [
|
|
|
|
[
|
|
|
|
dup integer? [ object <array> ] when
|
|
|
|
[ word-name ] map
|
|
|
|
] map effect>string
|
|
|
|
] when
|
2005-09-24 15:21:17 -04:00
|
|
|
] ?if ;
|
2005-03-26 20:12:14 -05:00
|
|
|
|
2005-10-10 21:12:53 -04:00
|
|
|
: synopsis ( word -- string )
|
2005-12-28 20:25:17 -05:00
|
|
|
[
|
|
|
|
0 margin set [
|
|
|
|
dup (synopsis) stack-effect comment.
|
|
|
|
] with-pprint
|
|
|
|
] string-out ;
|
2005-10-03 19:53:32 -04:00
|
|
|
|
2005-08-21 01:17:37 -04:00
|
|
|
GENERIC: (see) ( word -- )
|
2005-03-26 20:12:14 -05:00
|
|
|
|
2005-10-03 19:53:32 -04:00
|
|
|
M: word (see) drop ;
|
2005-03-26 20:12:14 -05:00
|
|
|
|
2005-08-21 20:50:14 -04:00
|
|
|
: pprint-; \ ; pprint-word ;
|
2005-08-21 14:25:05 -04:00
|
|
|
|
2005-08-21 01:17:37 -04:00
|
|
|
: see-body ( quot word -- )
|
2005-12-28 20:25:17 -05:00
|
|
|
<block swap pprint-elements pprint-; declarations. block; ;
|
2005-03-26 20:12:14 -05:00
|
|
|
|
2005-08-21 01:17:37 -04:00
|
|
|
M: compound (see)
|
2005-10-03 19:53:32 -04:00
|
|
|
dup word-def swap see-body ;
|
2005-03-26 20:12:14 -05:00
|
|
|
|
2005-11-27 17:45:48 -05:00
|
|
|
: method. ( word class method -- )
|
2005-08-29 01:00:55 -04:00
|
|
|
\ M: pprint-word
|
2005-11-27 17:45:48 -05:00
|
|
|
>r pprint-word pprint-word r>
|
|
|
|
<block pprint-elements pprint-; block; ;
|
2005-08-21 01:17:37 -04:00
|
|
|
|
|
|
|
M: generic (see)
|
2005-10-03 19:53:32 -04:00
|
|
|
dup dup "combination" word-prop swap see-body
|
2005-11-27 17:45:48 -05:00
|
|
|
dup methods [ newline first2 method. ] each-with ;
|
2005-03-26 20:12:14 -05:00
|
|
|
|
2005-08-21 14:25:05 -04:00
|
|
|
GENERIC: class. ( word -- )
|
|
|
|
|
|
|
|
: methods. ( class -- )
|
|
|
|
#! List all methods implemented for this class.
|
2005-09-16 02:39:33 -04:00
|
|
|
dup class? [
|
2005-08-21 14:25:05 -04:00
|
|
|
dup implementors [
|
2005-10-05 02:01:06 -04:00
|
|
|
newline
|
2006-07-09 19:50:56 -04:00
|
|
|
tuck dupd "methods" word-prop hash method.
|
2005-08-21 14:25:05 -04:00
|
|
|
] each-with
|
|
|
|
] [
|
|
|
|
drop
|
2005-09-24 15:21:17 -04:00
|
|
|
] if ;
|
2005-08-21 14:25:05 -04:00
|
|
|
|
|
|
|
M: union class.
|
2005-10-05 02:01:06 -04:00
|
|
|
newline
|
2005-08-29 01:00:55 -04:00
|
|
|
\ UNION: pprint-word
|
|
|
|
dup pprint-word
|
2005-10-05 02:01:06 -04:00
|
|
|
members pprint-elements pprint-; ;
|
2005-08-21 14:25:05 -04:00
|
|
|
|
|
|
|
M: predicate class.
|
2005-10-05 02:01:06 -04:00
|
|
|
newline
|
2005-08-29 01:00:55 -04:00
|
|
|
\ PREDICATE: pprint-word
|
2005-09-16 02:39:33 -04:00
|
|
|
dup superclass pprint-word
|
2005-08-29 01:00:55 -04:00
|
|
|
dup pprint-word
|
2005-08-21 14:25:05 -04:00
|
|
|
<block
|
|
|
|
"definition" word-prop pprint-elements
|
2005-10-05 02:01:06 -04:00
|
|
|
pprint-; block; ;
|
2005-08-21 14:25:05 -04:00
|
|
|
|
|
|
|
M: tuple-class class.
|
2005-10-05 02:01:06 -04:00
|
|
|
newline
|
2005-08-29 01:00:55 -04:00
|
|
|
\ TUPLE: pprint-word
|
|
|
|
dup pprint-word
|
2006-05-19 00:19:08 -04:00
|
|
|
"slot-names" word-prop [ text ] each
|
2005-10-05 02:01:06 -04:00
|
|
|
pprint-; ;
|
2005-08-21 14:25:05 -04:00
|
|
|
|
|
|
|
M: word class. drop ;
|
|
|
|
|
2005-03-26 20:12:14 -05:00
|
|
|
: see ( word -- )
|
2005-10-03 19:53:32 -04:00
|
|
|
[
|
|
|
|
dup (synopsis)
|
|
|
|
dup (see)
|
|
|
|
dup class.
|
|
|
|
methods.
|
2005-10-05 02:01:06 -04:00
|
|
|
newline
|
2005-10-03 19:53:32 -04:00
|
|
|
] with-pprint ;
|