1.1 --- a/micropython/inspect.py Thu Sep 08 00:33:33 2011 +0200
1.2 +++ b/micropython/inspect.py Sat Sep 10 20:29:30 2011 +0200
1.3 @@ -194,6 +194,24 @@
1.4
1.5 "Vacuum the given object 'obj'."
1.6
1.7 + # Get all constant objects in apparent use.
1.8 +
1.9 + if delete_all:
1.10 + obj_objects = set()
1.11 + else:
1.12 + obj_objects = []
1.13 + for name, attr in obj.items_for_vacuum():
1.14 +
1.15 + # Get constant objects for attributes in use.
1.16 +
1.17 + if self.importer.uses_attribute(obj.full_name(), name) and \
1.18 + attr is not None and attr.is_constant():
1.19 +
1.20 + value = attr.get_value()
1.21 + obj_objects.append(value)
1.22 +
1.23 + # Now vacuum unused attributes and objects not in use.
1.24 +
1.25 for name, attr in obj.items_for_vacuum():
1.26
1.27 # Only consider deleting entire unused objects or things accessible
1.28 @@ -206,12 +224,15 @@
1.29 # have been defined within the object and therefore are not
1.30 # redefined by other code regions.
1.31
1.32 - if attr is not None and attr.assignments == 1:
1.33 + if attr is not None and attr.is_constant():
1.34 value = attr.get_value()
1.35
1.36 # The value must have this object as a parent.
1.37 + # However, it must not be shared by several names.
1.38
1.39 - if value is not obj and value.parent is obj and value in self.all_objects:
1.40 + if value is not obj and value.parent is obj and \
1.41 + value in self.all_objects and value not in obj_objects:
1.42 +
1.43 self.all_objects.remove(value)
1.44
1.45 # Delete class contents and lambdas from functions.
1.46 @@ -462,6 +483,11 @@
1.47
1.48 def _visitAttr(self, expr, attrname, node):
1.49
1.50 + """
1.51 + Process the attribute provided by the given 'expr' with the given
1.52 + 'attrname' and involving the given 'node'.
1.53 + """
1.54 +
1.55 # Attempt to identify the nature of the attribute.
1.56
1.57 if isinstance(expr, Attr):