1 ! Copyright (C) 2005, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel continuations sequences vectors arrays system math
4 io.backend alien.strings memory.private ;
7 : (each-object) ( quot: ( obj -- ) -- )
9 swap [ call ] keep (each-object)
10 ] [ 2drop ] if ; inline recursive
12 : each-object ( quot -- )
13 gc begin-scan [ (each-object) ] [ end-scan ] [ ] cleanup ; inline
15 : count-instances ( quot -- n )
16 0 swap [ 1 0 ? + ] compose each-object ; inline
18 : instances ( quot -- seq )
19 #! To ensure we don't need to grow the vector while scanning
20 #! the heap, we do two scans, the first one just counts the
21 #! number of objects that satisfy the predicate.
22 [ count-instances 100 + <vector> ] keep swap
23 [ [ push-if ] 2curry each-object ] keep >array ; inline
25 : save-image ( path -- )
26 normalize-path native-string>alien (save-image) ;
28 : save-image-and-exit ( path -- )
29 normalize-path native-string>alien (save-image-and-exit) ;
31 : save ( -- ) image save-image ;