[ "<tuple>" "kernel-internals" [ [ number ] [ tuple ] ] ]
[ ">array" "kernel-internals" [ [ object ] [ array ] ] ]
[ ">tuple" "kernel-internals" [ [ object ] [ tuple ] ] ]
- [ "(instances)" "memory" [ [ integer ] [ general-list ] ] ]
[ "begin-scan" "memory" [ [ ] [ ] ] ]
[ "next-object" "memory" [ [ ] [ object ] ] ]
[ "end-scan" "memory" [ [ ] [ object ] ] ]
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: memory
-USING: kernel lists math namespaces prettyprint stdio words
-vectors unparser generic ;
+USING: errors generic kernel lists math namespaces prettyprint
+stdio unparser vectors words ;
: kb. 1024 /i unparse write " KB" write ;
#! Print heap allocation breakdown.
0 heap-stats [ dupd uncons heap-stat. 1 + ] each drop ;
+: (each-object) ( quot -- )
+ next-object dup [
+ swap dup slip (each-object)
+ ] [
+ 2drop
+ ] ifte ; inline
+
+: each-object ( quot -- )
+ #! Applies the quotation to each object in the image.
+ [
+ begin-scan (each-object)
+ ] [
+ end-scan rethrow
+ ] catch ; inline
+
: instances ( class -- list )
- #! Return a list of all instances of a built-in class.
- "builtin-type" word-property (instances) ;
+ #! Return a list of all instances of a built-in or tuple
+ #! class.
+ [
+ [
+ dup class pick = [ , ] [ drop ] ifte
+ ] each-object drop
+ ] make-list ;
dpush(list);
}
-
-void primitive_instances(void)
-{
- CELL list = F;
- CELL search_type = to_fixnum(dpop());
- CELL here;
-
- primitive_gc();
-
- here = active.here;
-
- begin_heap_scan();
-
- for(;;)
- {
- CELL size, type;
- CELL obj = heap_step(&size,&type);
-
- if(walk_donep())
- break;
-
- /* don't want an infinite loop if we ask for a list of all
- conses in the image! */
- if(heap_scan_ptr >= here)
- break;
-
- if(search_type == type)
- list = cons(obj,list);
- }
-
- dpush(list);
-}