1 ! Copyright (C) 2005, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel continuations sequences vectors arrays system math ;
6 : (each-object) ( quot: ( obj -- ) -- )
8 swap [ call ] keep (each-object)
9 ] [ 2drop ] if ; inline recursive
11 : each-object ( quot -- )
12 gc begin-scan [ (each-object) ] [ end-scan ] [ ] cleanup ; inline
14 : count-instances ( quot -- n )
15 0 swap [ 1 0 ? + ] compose each-object ; inline
17 : instances ( quot -- seq )
18 #! To ensure we don't need to grow the vector while scanning
19 #! the heap, we do two scans, the first one just counts the
20 #! number of objects that satisfy the predicate.
21 [ count-instances 100 + <vector> ] keep swap
22 [ [ push-if ] 2curry each-object ] keep >array ; inline
24 : save ( -- ) image save-image ;