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 sorting strings summary words
10 words.symbol words.constant words.alias vocabs slots ;
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-word ]
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* ;
94 M: word summary synopsis ;
96 GENERIC: declarations. ( obj -- )
98 M: object declarations. drop ;
100 : declaration. ( word prop -- )
101 [ nip ] [ name>> word-prop ] 2bi
102 [ pprint-word ] [ drop ] if ;
104 M: word declarations.
112 } [ declaration. ] with each ;
114 : pprint-; ( -- ) \ ; pprint-word ;
121 <block dup definition pprint-elements block>
122 dup definer nip [ pprint-word ] when* declarations.
126 GENERIC: see-class* ( word -- )
128 M: union-class see-class*
129 <colon \ UNION: pprint-word
131 members pprint-elements pprint-; block> ;
133 M: intersection-class see-class*
134 <colon \ INTERSECTION: pprint-word
136 participants pprint-elements pprint-; block> ;
138 M: mixin-class see-class*
139 <block \ MIXIN: pprint-word
140 dup pprint-word <block
143 \ INSTANCE: pprint-word pprint-word pprint-word
144 ] with each block> block> ;
146 M: predicate-class see-class*
147 <colon \ PREDICATE: pprint-word
150 dup superclass pprint-word
152 "predicate-definition" word-prop pprint-elements
153 pprint-; block> block> ;
155 M: singleton-class see-class* ( class -- )
156 \ SINGLETON: pprint-word pprint-word ;
158 GENERIC: pprint-slot-name ( object -- )
160 M: string pprint-slot-name text ;
162 M: array pprint-slot-name
163 <flow \ { pprint-word
164 f <inset unclip text pprint-elements block>
165 \ } pprint-word block> ;
167 : unparse-slot ( slot-spec -- array )
170 dup class>> object eq? [
176 dup [ class>> object eq? not ] [ initial>> ] bi or [
183 : pprint-slot ( slot-spec -- )
185 dup length 1 = [ first ] when
188 : tuple-declarations. ( class -- )
189 \ final declaration. ;
191 : superclass. ( class -- )
192 superclass dup tuple eq? [ drop ] [ "<" text pprint-word ] if ;
194 M: tuple-class see-class*
195 <colon \ TUPLE: pprint-word
199 [ <block "slots" word-prop [ pprint-slot ] each block> pprint-; ]
200 [ tuple-declarations. ]
204 M: word see-class* drop ;
206 M: builtin-class see-class*
207 drop "! Built-in class" comment. ;
209 : see-class ( class -- )
212 [ seeing-word ] [ see-class* ] bi
218 [ [ class? ] [ symbol? not ] bi and [ nl nl ] when ]
220 dup [ class? ] [ symbol? ] bi and
221 [ drop ] [ call-next-method ] if
224 : seeing-implementors ( class -- seq )
226 [ [ reader? ] [ writer? ] bi or not ] filter
227 [ lookup-method ] with map
230 : seeing-methods ( generic -- seq )
231 "methods" word-prop values natural-sort ;
236 natural-sort [ nl nl ] [ see* ] interleave ;
238 : methods ( word -- seq )
240 dup class? [ dup seeing-implementors % ] when
241 dup generic? [ dup seeing-methods % ] when
243 ] { } make set-members ;
245 : see-methods ( word -- )