1 ! Copyright (C) 2009, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays assocs classes classes.builtin
4 classes.intersection classes.mixin classes.predicate classes.singleton
5 classes.tuple classes.union combinators definitions effects generic
6 generic.single generic.standard generic.hook io io.pathnames
7 io.streams.string io.styles kernel make namespaces prettyprint
8 prettyprint.backend prettyprint.config prettyprint.custom
9 prettyprint.sections sequences sets slots sorting strings summary
10 words words.symbol words.constant words.alias vocabs ;
11 FROM: namespaces => set ;
14 GENERIC: synopsis* ( defspec -- )
16 GENERIC: see* ( defspec -- )
18 : see ( defspec -- ) see* nl ;
20 : synopsis ( defspec -- str )
26 ] with-string-writer ;
28 : definer. ( defspec -- )
29 definer drop pprint-word ;
31 : comment. ( text -- )
32 H{ { font-style italic } } styled-text ;
34 GENERIC: print-stack-effect? ( word -- ? )
36 M: parsing-word print-stack-effect? drop f ;
37 M: symbol print-stack-effect? drop f ;
38 M: constant print-stack-effect? drop f ;
39 M: alias print-stack-effect? drop f ;
40 M: word print-stack-effect? drop t ;
42 : stack-effect. ( word -- )
43 [ print-stack-effect? ] [ stack-effect ] bi and
44 [ pprint-effect ] when* ;
48 : seeing-word ( word -- )
49 vocabulary>> dup [ lookup-vocab ] when pprinter-in set ;
51 : word-synopsis ( word -- )
59 M: word synopsis* word-synopsis ;
61 M: simple-generic synopsis* word-synopsis ;
63 M: standard-generic synopsis*
72 M: hook-generic synopsis*
77 [ "combination" word-prop var>> pprint* ]
83 [ "method-class" word-prop pprint-class ]
84 [ "method-generic" word-prop pprint-word ] tri ;
86 M: mixin-instance synopsis*
88 [ class>> pprint-word ]
89 [ mixin>> pprint-word ] tri ;
91 M: pathname synopsis* pprint* ;
95 0 margin set 1 line-limit set
101 [ stack-effect pprint-effect ]
104 ] with-string-writer ;
106 M: word summary synopsis ;
108 GENERIC: declarations. ( obj -- )
110 M: object declarations. drop ;
112 : declaration. ( word prop -- )
113 [ nip ] [ name>> word-prop ] 2bi
114 [ pprint-word ] [ drop ] if ;
116 M: word declarations.
124 } [ declaration. ] with each ;
126 : pprint-; ( -- ) \ ; pprint-word ;
133 <block dup definition pprint-elements block>
134 dup definer nip [ pprint-word ] when* declarations.
138 GENERIC: see-class* ( word -- )
140 M: union-class see-class*
141 <colon \ UNION: pprint-word
143 class-members pprint-elements pprint-; block> ;
145 M: intersection-class see-class*
146 <colon \ INTERSECTION: pprint-word
148 class-participants pprint-elements pprint-; block> ;
150 M: mixin-class see-class*
151 <block \ MIXIN: pprint-word
152 dup pprint-word <block
155 \ INSTANCE: pprint-word pprint-word pprint-word
156 ] with each block> block> ;
158 M: predicate-class see-class*
159 <colon \ PREDICATE: pprint-word
162 dup superclass pprint-word
164 "predicate-definition" word-prop pprint-elements
165 pprint-; block> block> ;
167 M: singleton-class see-class* ( class -- )
168 \ SINGLETON: pprint-word pprint-word ;
170 GENERIC: pprint-slot-name ( object -- )
172 M: string pprint-slot-name text ;
174 M: array pprint-slot-name
175 <flow \ { pprint-word
176 f <inset unclip text pprint-elements block>
177 \ } pprint-word block> ;
179 : unparse-slot ( slot-spec -- array )
182 dup class>> object eq? [
188 dup [ class>> object eq? not ] [ initial>> ] bi or [
195 : pprint-slot ( slot-spec -- )
197 dup length 1 = [ first ] when
200 : tuple-declarations. ( class -- )
201 \ final declaration. ;
203 : superclass. ( class -- )
204 superclass dup tuple eq? [ drop ] [ "<" text pprint-word ] if ;
206 M: tuple-class see-class*
207 <colon \ TUPLE: pprint-word
211 [ <block "slots" word-prop [ pprint-slot ] each block> pprint-; ]
212 [ tuple-declarations. ]
216 M: word see-class* drop ;
218 M: builtin-class see-class*
220 \ BUILTIN: pprint-word
222 [ <block "slots" word-prop [ pprint-slot ] each pprint-; block> ] bi
225 : see-class ( class -- )
228 [ seeing-word ] [ see-class* ] bi
234 [ [ class? ] [ symbol? not ] bi and [ nl nl ] when ]
236 dup [ class? ] [ symbol? ] bi and
237 [ drop ] [ call-next-method ] if
240 : seeing-implementors ( class -- seq )
242 [ [ reader? ] [ writer? ] bi or ] reject
243 [ lookup-method ] with map
246 : seeing-methods ( generic -- seq )
247 "methods" word-prop values natural-sort ;
252 natural-sort [ nl nl ] [ see* ] interleave ;
254 : methods ( word -- seq )
256 dup class? [ dup seeing-implementors % ] when
257 dup generic? [ dup seeing-methods % ] when
261 : see-methods ( word -- )