2009-08-12 10:37:09 -04:00
|
|
|
! (c)Joe Groff bsd license
|
2009-08-31 21:32:00 -04:00
|
|
|
USING: accessors alien alien.c-types arrays assocs classes
|
|
|
|
classes.struct combinators continuations fry kernel make math
|
|
|
|
math.parser mirrors prettyprint.backend prettyprint.custom
|
|
|
|
prettyprint.sections see.private sequences strings
|
|
|
|
summary words ;
|
2009-08-12 10:37:09 -04:00
|
|
|
IN: classes.struct.prettyprint
|
|
|
|
|
2009-08-19 19:53:44 -04:00
|
|
|
<PRIVATE
|
|
|
|
|
|
|
|
: struct-definer-word ( class -- word )
|
|
|
|
struct-slots dup length 2 >=
|
|
|
|
[ second offset>> 0 = \ UNION-STRUCT: \ STRUCT: ? ]
|
|
|
|
[ drop \ STRUCT: ] if ;
|
|
|
|
|
|
|
|
: struct>assoc ( struct -- assoc )
|
2009-08-31 19:51:47 -04:00
|
|
|
[ class struct-slots ] [ struct-slot-values ] bi zip ;
|
2009-08-19 19:53:44 -04:00
|
|
|
|
2009-08-25 14:03:43 -04:00
|
|
|
: pprint-struct-slot ( slot -- )
|
|
|
|
<flow \ { pprint-word
|
|
|
|
{
|
|
|
|
[ name>> text ]
|
2009-08-27 22:39:43 -04:00
|
|
|
[ c-type>> dup string? [ text ] [ pprint* ] if ]
|
2009-08-25 14:03:43 -04:00
|
|
|
[ read-only>> [ \ read-only pprint-word ] when ]
|
|
|
|
[ initial>> [ \ initial: pprint-word pprint* ] when* ]
|
|
|
|
} cleave
|
|
|
|
\ } pprint-word block> ;
|
|
|
|
|
2009-08-30 21:46:31 -04:00
|
|
|
: pprint-struct ( struct -- )
|
|
|
|
[ [ \ S{ ] dip [ class ] [ struct>assoc ] bi \ } (pprint-tuple) ] ?pprint-tuple ;
|
|
|
|
|
|
|
|
: pprint-struct-pointer ( struct -- )
|
2009-08-31 20:56:36 -04:00
|
|
|
\ S@ [ [ class pprint-word ] [ >c-ptr pprint* ] bi ] pprint-prefix ;
|
2009-08-30 21:46:31 -04:00
|
|
|
|
2009-08-19 19:53:44 -04:00
|
|
|
PRIVATE>
|
|
|
|
|
2009-08-12 10:37:09 -04:00
|
|
|
M: struct-class see-class*
|
2009-08-19 19:53:44 -04:00
|
|
|
<colon dup struct-definer-word pprint-word dup pprint-word
|
2009-08-25 14:03:43 -04:00
|
|
|
<block struct-slots [ pprint-struct-slot ] each
|
2009-08-12 10:37:09 -04:00
|
|
|
block> pprint-; block> ;
|
|
|
|
|
2009-08-12 15:59:33 -04:00
|
|
|
M: struct pprint-delims
|
|
|
|
drop \ S{ \ } ;
|
|
|
|
|
2009-08-19 19:53:44 -04:00
|
|
|
M: struct >pprint-sequence
|
|
|
|
[ class ] [ struct-slot-values ] bi class-slot-sequence ;
|
|
|
|
|
|
|
|
M: struct pprint*
|
2009-08-30 21:46:31 -04:00
|
|
|
[ pprint-struct ]
|
|
|
|
[ pprint-struct-pointer ] pprint-c-object ;
|
2009-08-31 21:32:00 -04:00
|
|
|
|
|
|
|
M: struct summary
|
|
|
|
[
|
|
|
|
dup class name>> %
|
|
|
|
" struct of " %
|
|
|
|
byte-length #
|
|
|
|
" bytes " %
|
|
|
|
] "" make ;
|
|
|
|
|
|
|
|
M: struct make-mirror
|
|
|
|
[
|
|
|
|
[ drop "underlying" ] [ (underlying)>> ] bi 2array 1array
|
|
|
|
] [
|
|
|
|
'[
|
|
|
|
_ struct>assoc
|
|
|
|
[ [ [ name>> ] [ c-type>> ] bi 2array ] dip ] assoc-map
|
|
|
|
] [ drop { } ] recover
|
|
|
|
] bi append ;
|