1 USING: accessors alien.c-types alien.data arrays assocs
2 bit-arrays.private classes.struct fry grouping io io.encodings.binary
3 io.streams.byte-array kernel math math.statistics sequences
4 sequences.repeating splitting tools.image-analyzer.utils vm ;
5 IN: tools.image-analyzer.gc-info
8 : read-ints ( count -- seq )
11 : read-bits ( bit-count -- bit-array )
12 [ bits>bytes read byte-array>bit-array ] keep head ;
14 : (cut-points) ( counts times -- seq )
15 <repeats> cum-sum but-last ;
17 : reshape-sequence ( seq counts times -- seqs )
18 [ (cut-points) split-indices ] keep <groups> flip ;
20 : read-struct-safe ( struct -- instance/f )
21 dup heap-size read [ swap memory>struct ] [ drop f ] if* ;
24 : return-addresses ( gc-info -- seq )
25 return-address-count>> read-ints ;
27 : base-pointers ( gc-info -- seq )
28 [ return-address-count>> ] keep derived-root-count>>
29 '[ _ read-ints ] replicate ;
31 : bit-counts ( gc-info -- counts )
32 struct-slot-values 3 head ;
34 : (read-scrub-bits) ( gc-info -- seq )
35 [ bit-counts sum ] [ return-address-count>> ] bi * read-bits ;
37 : scrub-bits ( gc-info -- seq )
38 [ (read-scrub-bits) ] [ bit-counts ] [ return-address-count>> ] tri
39 [ 2drop { } ] [ reshape-sequence ] if-zero ;
41 : byte-array>gc-maps ( byte-array -- gc-maps )
42 binary <byte-reader> <backwards-reader> [
43 gc-info read-struct-safe [
44 [ return-addresses ] [ base-pointers ] [ scrub-bits ] tri