<s> from __future__ import absolute_import <EOL> from rpython . rlib import rgc , jit <EOL> from topaz . module import ModuleDef <EOL> from topaz . objects . objectobject import W_BaseObject <EOL> def try_cast_gcref_to_w_baseobject ( gcref ) : <EOL> return rgc . try_cast_gcref_to_instance ( W_BaseObject , gcref ) <EOL> def clear_gcflag_extra ( pending ) : <EOL> while pending : <EOL> gcref = pending . pop ( ) <EOL> if rgc . get_gcflag_extra ( gcref ) : <EOL> rgc . toggle_gcflag_extra ( gcref ) <EOL> pending . extend ( rgc . get_rpy_referents ( gcref ) ) <EOL> class ObjectSpace ( object ) : <EOL> moduledef = ModuleDef ( "<STR_LIT>" ) <EOL> @ moduledef . function ( "<STR_LIT>" ) <EOL> def method_each_object ( self , space , w_mod , block ) : <EOL> if block is None : <EOL> return space . send ( self , "<STR_LIT>" , [ space . newsymbol ( "<STR_LIT>" ) , w_mod ] , block ) <EOL> match_w = [ ] <EOL> roots = [ gcref for gcref in rgc . get_rpy_roots ( ) if gcref ] <EOL> pending = roots [ : ] <EOL> while pending : <EOL> gcref = pending . pop ( ) <EOL> if not rgc . get_gcflag_extra ( gcref ) : <EOL> rgc . toggle_gcflag_extra ( gcref ) <EOL> w_obj = try_cast_gcref_to_w_baseobject ( gcref ) <EOL> if w_obj is not None and space . is_kind_of ( w_obj , w_mod ) : <EOL> match_w . append ( w_obj ) <EOL> pending . extend ( rgc . get_rpy_referents ( gcref ) ) <EOL> clear_gcflag_extra ( roots ) <EOL> for w_obj in match_w : <EOL> space . invoke_block ( block , [ w_obj ] ) <EOL> return space . newint ( len ( match_w ) ) <EOL> @ moduledef . function ( "<STR_LIT>" ) <EOL> @ jit . dont_look_inside <EOL> def method_garbage_collect ( self ) : <EOL> rgc . collect ( ) </s>
