2005-02-06 00:21:26 -05:00
|
|
|
! Copyright (C) 2003, 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
2004-11-25 21:08:09 -05:00
|
|
|
IN: prettyprint
|
2005-06-19 17:50:35 -04:00
|
|
|
USING: generic hashtables io kernel lists namespaces sequences
|
2005-06-27 03:47:22 -04:00
|
|
|
streams strings styles unparser words ;
|
2004-11-25 21:08:09 -05:00
|
|
|
|
2004-12-29 03:35:46 -05:00
|
|
|
: prettyprint-IN: ( word -- )
|
2005-07-14 00:32:52 -04:00
|
|
|
\ IN: unparse. bl word-vocabulary write terpri ;
|
2004-11-25 21:08:09 -05:00
|
|
|
|
|
|
|
: prettyprint-prop ( word prop -- )
|
2005-03-05 14:45:23 -05:00
|
|
|
tuck word-name word-prop [
|
2005-07-13 22:51:43 -04:00
|
|
|
bl unparse.
|
2004-11-25 21:08:09 -05:00
|
|
|
] [
|
|
|
|
drop
|
|
|
|
] ifte ;
|
|
|
|
|
|
|
|
: prettyprint-plist ( word -- )
|
|
|
|
dup
|
|
|
|
\ parsing prettyprint-prop
|
|
|
|
\ inline prettyprint-prop ;
|
|
|
|
|
2005-07-17 14:48:55 -04:00
|
|
|
: comment. ( comment -- )
|
2005-07-21 21:43:37 -04:00
|
|
|
[ [[ font-style italic ]] ] format ;
|
2005-02-07 13:14:55 -05:00
|
|
|
|
2005-03-23 22:49:40 -05:00
|
|
|
: infer-effect. ( effect -- )
|
2005-02-07 13:14:55 -05:00
|
|
|
[
|
2005-07-17 14:48:55 -04:00
|
|
|
"(" %
|
|
|
|
2unlist >r [ " " % unparse % ] each r>
|
|
|
|
" --" %
|
|
|
|
[ " " % unparse % ] each
|
|
|
|
" )" %
|
2005-02-07 13:14:55 -05:00
|
|
|
] make-string comment. ;
|
|
|
|
|
2005-03-23 22:49:40 -05:00
|
|
|
: stack-effect. ( word -- )
|
2005-03-05 14:45:23 -05:00
|
|
|
dup "stack-effect" word-prop [
|
2005-07-17 14:48:55 -04:00
|
|
|
[ CHAR: ( , % CHAR: ) , ] make-string
|
2005-02-07 13:14:55 -05:00
|
|
|
comment.
|
2005-02-07 12:16:39 -05:00
|
|
|
] [
|
2005-03-05 14:45:23 -05:00
|
|
|
"infer-effect" word-prop dup [
|
2005-02-07 12:16:39 -05:00
|
|
|
infer-effect.
|
|
|
|
] [
|
2005-02-07 13:14:55 -05:00
|
|
|
drop
|
2005-02-07 12:16:39 -05:00
|
|
|
] ifte
|
|
|
|
] ?ifte ;
|
2004-11-25 21:08:09 -05:00
|
|
|
|
|
|
|
: documentation. ( indent word -- indent )
|
2005-03-05 14:45:23 -05:00
|
|
|
"documentation" word-prop [
|
2004-11-25 21:08:09 -05:00
|
|
|
"\n" split [
|
2005-05-18 16:26:22 -04:00
|
|
|
"#!" swap append comment.
|
2004-11-25 21:08:09 -05:00
|
|
|
dup prettyprint-newline
|
|
|
|
] each
|
|
|
|
] when* ;
|
|
|
|
|
2005-07-13 22:51:43 -04:00
|
|
|
: definer. ( word -- ) dup definer unparse. bl unparse. bl ;
|
2005-03-26 20:12:14 -05:00
|
|
|
|
|
|
|
GENERIC: (see) ( word -- )
|
2004-12-12 23:49:44 -05:00
|
|
|
|
2005-03-26 20:12:14 -05:00
|
|
|
M: compound (see) ( word -- )
|
2005-03-23 22:49:40 -05:00
|
|
|
tab-size get dup indent swap
|
|
|
|
[ documentation. ] keep
|
2005-07-13 22:51:43 -04:00
|
|
|
[ word-def prettyprint-elements \ ; unparse. ] keep
|
2005-03-26 20:12:14 -05:00
|
|
|
prettyprint-plist terpri drop ;
|
2004-11-25 21:08:09 -05:00
|
|
|
|
2005-04-10 18:58:30 -04:00
|
|
|
: prettyprint-M: ( -- indent )
|
2005-07-13 22:51:43 -04:00
|
|
|
\ M: unparse. bl tab-size get ;
|
2005-03-26 20:12:14 -05:00
|
|
|
|
2005-07-13 22:51:43 -04:00
|
|
|
: prettyprint-; \ ; unparse. terpri ;
|
2005-03-23 22:49:40 -05:00
|
|
|
|
2005-04-10 18:58:30 -04:00
|
|
|
: method. ( word [[ class method ]] -- )
|
2005-07-13 22:51:43 -04:00
|
|
|
uncons >r >r >r prettyprint-M: r> r> unparse. bl unparse. bl
|
2005-04-10 18:58:30 -04:00
|
|
|
dup prettyprint-newline r> prettyprint-elements
|
|
|
|
prettyprint-; drop ;
|
2005-02-24 20:52:17 -05:00
|
|
|
|
2005-05-14 21:15:50 -04:00
|
|
|
M: generic (see) ( word -- )
|
|
|
|
tab-size get dup indent [
|
|
|
|
one-line on
|
|
|
|
over "picker" word-prop prettyprint* bl
|
|
|
|
over "dispatcher" word-prop prettyprint* bl
|
|
|
|
] with-scope
|
|
|
|
drop
|
2005-07-13 22:51:43 -04:00
|
|
|
\ ; unparse. terpri
|
2005-05-14 21:15:50 -04:00
|
|
|
dup methods [ method. ] each-with ;
|
2005-03-26 20:12:14 -05:00
|
|
|
|
|
|
|
M: word (see) drop ;
|
|
|
|
|
|
|
|
GENERIC: class.
|
|
|
|
|
|
|
|
M: union class.
|
2005-07-13 22:51:43 -04:00
|
|
|
\ UNION: unparse. bl
|
|
|
|
dup unparse. bl
|
2005-03-26 20:12:14 -05:00
|
|
|
0 swap "members" word-prop prettyprint-elements drop
|
|
|
|
prettyprint-; ;
|
|
|
|
|
|
|
|
M: complement class.
|
2005-07-13 22:51:43 -04:00
|
|
|
\ COMPLEMENT: unparse. bl
|
|
|
|
dup unparse. bl
|
|
|
|
"complement" word-prop unparse. terpri ;
|
2005-03-26 20:12:14 -05:00
|
|
|
|
|
|
|
M: builtin class.
|
2005-07-13 22:51:43 -04:00
|
|
|
\ BUILTIN: unparse. bl
|
|
|
|
dup unparse. bl
|
2005-05-02 00:18:34 -04:00
|
|
|
dup "builtin-type" word-prop unparse write bl
|
2005-03-26 20:12:14 -05:00
|
|
|
0 swap "slots" word-prop prettyprint-elements drop
|
|
|
|
prettyprint-; ;
|
|
|
|
|
|
|
|
M: predicate class.
|
2005-07-13 22:51:43 -04:00
|
|
|
\ PREDICATE: unparse. bl
|
|
|
|
dup "superclass" word-prop unparse. bl
|
|
|
|
dup unparse. bl
|
2005-03-26 20:12:14 -05:00
|
|
|
tab-size get dup prettyprint-newline swap
|
|
|
|
"definition" word-prop prettyprint-elements drop
|
|
|
|
prettyprint-; ;
|
|
|
|
|
|
|
|
M: tuple-class class.
|
2005-07-13 22:51:43 -04:00
|
|
|
\ TUPLE: unparse. bl
|
|
|
|
dup unparse. bl
|
2005-05-02 00:18:34 -04:00
|
|
|
"slot-names" word-prop [ write bl ] each
|
2005-03-26 20:12:14 -05:00
|
|
|
prettyprint-; ;
|
|
|
|
|
|
|
|
M: word class. drop ;
|
|
|
|
|
|
|
|
: see ( word -- )
|
2005-03-26 20:40:29 -05:00
|
|
|
dup prettyprint-IN: dup definer.
|
2005-03-26 20:12:14 -05:00
|
|
|
dup stack-effect. terpri dup (see) class. ;
|
2005-04-10 18:58:30 -04:00
|
|
|
|
|
|
|
: methods. ( class -- )
|
|
|
|
#! List all methods implemented for this class.
|
|
|
|
dup class.
|
|
|
|
dup implementors [
|
|
|
|
dup prettyprint-IN:
|
|
|
|
[ "methods" word-prop hash* ] keep swap method.
|
|
|
|
] each-with ;
|