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 ;
12 FROM: classes => members ;
13 RENAME: members sets => set-members
16 GENERIC: synopsis* ( defspec -- )
18 GENERIC: see* ( defspec -- )
20 : see ( defspec -- ) see* nl ;
22 : synopsis ( defspec -- str )
27 ] with-string-writer ;
29 : definer. ( defspec -- )
30 definer drop pprint-word ;
32 : comment. ( text -- )
33 H{ { font-style italic } } styled-text ;
35 GENERIC: print-stack-effect? ( word -- ? )
37 M: parsing-word print-stack-effect? drop f ;
38 M: symbol print-stack-effect? drop f ;
39 M: constant print-stack-effect? drop f ;
40 M: alias print-stack-effect? drop f ;
41 M: word print-stack-effect? drop t ;
43 : stack-effect. ( word -- )
44 [ print-stack-effect? ] [ stack-effect ] bi and
45 [ pprint-effect ] when* ;
49 : seeing-word ( word -- )
50 vocabulary>> dup [ lookup-vocab ] when pprinter-in set ;
52 : word-synopsis ( word -- )
60 M: word synopsis* word-synopsis ;
62 M: simple-generic synopsis* word-synopsis ;
64 M: standard-generic synopsis*
73 M: hook-generic synopsis*
78 [ "combination" word-prop var>> pprint* ]
84 [ "method-class" word-prop pprint-class ]
85 [ "method-generic" word-prop pprint-word ] tri ;
87 M: mixin-instance synopsis*
89 [ class>> pprint-word ]
90 [ mixin>> pprint-word ] tri ;
92 M: pathname synopsis* pprint* ;
96 0 margin set 1 line-limit set
102 [ stack-effect pprint-effect ]
105 ] with-string-writer ;
107 M: word summary synopsis ;
109 GENERIC: declarations. ( obj -- )
111 M: object declarations. drop ;
113 : declaration. ( word prop -- )
114 [ nip ] [ name>> word-prop ] 2bi
115 [ pprint-word ] [ drop ] if ;
117 M: word declarations.
125 } [ declaration. ] with each ;
127 : pprint-; ( -- ) \ ; pprint-word ;
134 <block dup definition pprint-elements block>
135 dup definer nip [ pprint-word ] when* declarations.
139 GENERIC: see-class* ( word -- )
141 M: union-class see-class*
142 <colon \ UNION: pprint-word
144 members pprint-elements pprint-; block> ;
146 M: intersection-class see-class*
147 <colon \ INTERSECTION: pprint-word
149 participants pprint-elements pprint-; block> ;
151 M: mixin-class see-class*
152 <block \ MIXIN: pprint-word
153 dup pprint-word <block
156 \ INSTANCE: pprint-word pprint-word pprint-word
157 ] with each block> block> ;
159 M: predicate-class see-class*
160 <colon \ PREDICATE: pprint-word
163 dup superclass pprint-word
165 "predicate-definition" word-prop pprint-elements
166 pprint-; block> block> ;
168 M: singleton-class see-class* ( class -- )
169 \ SINGLETON: pprint-word pprint-word ;
171 GENERIC: pprint-slot-name ( object -- )
173 M: string pprint-slot-name text ;
175 M: array pprint-slot-name
176 <flow \ { pprint-word
177 f <inset unclip text pprint-elements block>
178 \ } pprint-word block> ;
180 : unparse-slot ( slot-spec -- array )
183 dup class>> object eq? [
189 dup [ class>> object eq? not ] [ initial>> ] bi or [
196 : pprint-slot ( slot-spec -- )
198 dup length 1 = [ first ] when
201 : tuple-declarations. ( class -- )
202 \ final declaration. ;
204 : superclass. ( class -- )
205 superclass dup tuple eq? [ drop ] [ "<" text pprint-word ] if ;
207 M: tuple-class see-class*
208 <colon \ TUPLE: pprint-word
212 [ <block "slots" word-prop [ pprint-slot ] each block> pprint-; ]
213 [ tuple-declarations. ]
217 M: word see-class* drop ;
219 M: builtin-class see-class*
221 \ BUILTIN: pprint-word
223 [ <block "slots" word-prop [ pprint-slot ] each pprint-; block> ] bi
226 : see-class ( class -- )
229 [ seeing-word ] [ see-class* ] bi
235 [ [ class? ] [ symbol? not ] bi and [ nl nl ] when ]
237 dup [ class? ] [ symbol? ] bi and
238 [ drop ] [ call-next-method ] if
241 : seeing-implementors ( class -- seq )
243 [ [ reader? ] [ writer? ] bi or not ] filter
244 [ lookup-method ] with map
247 : seeing-methods ( generic -- seq )
248 "methods" word-prop values natural-sort ;
253 natural-sort [ nl nl ] [ see* ] interleave ;
255 : methods ( word -- seq )
257 dup class? [ dup seeing-implementors % ] when
258 dup generic? [ dup seeing-methods % ] when
260 ] { } make set-members ;
262 : see-methods ( word -- )