1 ! (c)Joe Groff bsd license
2 USING: accessors alien assocs classes classes.struct
3 combinators kernel math prettyprint.backend prettyprint.custom
4 prettyprint.sections see.private sequences strings words ;
5 IN: classes.struct.prettyprint
9 : struct-definer-word ( class -- word )
10 struct-slots dup length 2 >=
11 [ second offset>> 0 = \ UNION-STRUCT: \ STRUCT: ? ]
12 [ drop \ STRUCT: ] if ;
14 : struct>assoc ( struct -- assoc )
15 [ class struct-slots ] [ struct-slot-values ] bi zip filter-tuple-assoc ;
17 : pprint-struct-slot ( slot -- )
21 [ c-type>> dup string? [ text ] [ pprint* ] if ]
22 [ read-only>> [ \ read-only pprint-word ] when ]
23 [ initial>> [ \ initial: pprint-word pprint* ] when* ]
25 \ } pprint-word block> ;
27 : pprint-struct ( struct -- )
28 [ [ \ S{ ] dip [ class ] [ struct>assoc ] bi \ } (pprint-tuple) ] ?pprint-tuple ;
30 : pprint-struct-pointer ( struct -- )
33 [ >c-ptr pprint* ] bi ;
37 M: struct-class see-class*
38 <colon dup struct-definer-word pprint-word dup pprint-word
39 <block struct-slots [ pprint-struct-slot ] each
40 block> pprint-; block> ;
42 M: struct pprint-delims
45 M: struct >pprint-sequence
46 [ class ] [ struct-slot-values ] bi class-slot-sequence ;
50 [ pprint-struct-pointer ] pprint-c-object ;