1.1 --- a/micropython/__init__.py Sat Nov 08 23:11:45 2008 +0100
1.2 +++ b/micropython/__init__.py Mon Nov 10 21:38:58 2008 +0100
1.3 @@ -95,14 +95,20 @@
1.4 self.init_predefined_constants()
1.5
1.6 # Name records (used to track actual use of names).
1.7 + # Include names which may not be explicitly used in programs.
1.8
1.9 - self.names_used = set()
1.10 + self.names_used = set(["__init__"])
1.11
1.12 # Main program information.
1.13
1.14 self.code = None
1.15 self.code_location = None
1.16
1.17 + # Status information.
1.18 +
1.19 + self.vacuumed = 0
1.20 + self.finalised = 0
1.21 +
1.22 # Name accounting.
1.23
1.24 def use_name(self, name):
1.25 @@ -156,25 +162,30 @@
1.26
1.27 "Tidy up the modules."
1.28
1.29 + if self.vacuumed:
1.30 + return
1.31 +
1.32 for name, module in self.modules.items():
1.33 if module.loaded:
1.34 module.vacuum()
1.35 else:
1.36 del self.modules[name]
1.37
1.38 + self.vacuumed = 1
1.39 +
1.40 def finalise(self):
1.41
1.42 "Finalise the program."
1.43
1.44 - for module in self.get_modules():
1.45 + if self.finalised:
1.46 + return
1.47
1.48 - # Fix the attributes.
1.49 + self.vacuum()
1.50
1.51 - module.finalise_attributes()
1.52 + for module in self.get_modules():
1.53 + module.finalise()
1.54
1.55 - for obj in module.all_objects:
1.56 - if isinstance(obj, (micropython.inspect.Class, micropython.inspect.Function)):
1.57 - obj.finalise_attributes()
1.58 + self.finalised = 1
1.59
1.60 # Access to finalised program information.
1.61
1.62 @@ -307,6 +318,8 @@
1.63 "Return a table with details of attributes for classes and modules."
1.64
1.65 if self.objtable is None:
1.66 + self.vacuum()
1.67 +
1.68 t = self.objtable = micropython.table.ObjectTable()
1.69 for module in self.get_modules():
1.70 t.add(module.full_name(), module.module_attributes())