1.1 --- a/micropython/__init__.py Mon May 05 00:46:38 2008 +0200
1.2 +++ b/micropython/__init__.py Sat May 10 02:32:20 2008 +0200
1.3 @@ -72,6 +72,20 @@
1.4 self.objtable = None
1.5 self.paramtable = None
1.6
1.7 + # Constant records.
1.8 +
1.9 + self.constant_values = {}
1.10 + self.constant_list = None # cache for constants
1.11 +
1.12 + def constants(self):
1.13 +
1.14 + "Return a list of constants."
1.15 +
1.16 + if self.constant_list is None:
1.17 + self.constant_list = list(self.constant_values.values())
1.18 +
1.19 + return self.constant_list
1.20 +
1.21 def vacuum(self):
1.22
1.23 "Tidy up the modules."
1.24 @@ -97,6 +111,12 @@
1.25
1.26 image = []
1.27
1.28 + # Append constants to the image.
1.29 +
1.30 + for pos, const in enumerate(self.constants()):
1.31 + const.location = pos
1.32 + image.append(const)
1.33 +
1.34 for module_name, module in self.modules.items():
1.35 if not with_builtins and module_name == "__builtins__":
1.36 continue
1.37 @@ -107,13 +127,6 @@
1.38
1.39 pos = len(image)
1.40
1.41 - # Append constants to the image.
1.42 -
1.43 - for const in module.constants():
1.44 - const.location = pos
1.45 - image.append(const)
1.46 - pos += 1
1.47 -
1.48 # Position the module in the image and make a translation.
1.49
1.50 module.location = pos