1.1 --- a/micropython/__init__.py Wed Aug 27 00:45:14 2008 +0200
1.2 +++ b/micropython/__init__.py Mon Sep 01 01:32:32 2008 +0200
1.3 @@ -103,6 +103,20 @@
1.4 else:
1.5 del self.modules[name]
1.6
1.7 + def finalise(self):
1.8 +
1.9 + "Finalise the program."
1.10 +
1.11 + for module in self.get_modules():
1.12 +
1.13 + # Fix the attributes.
1.14 +
1.15 + module.finalise_attributes()
1.16 +
1.17 + for obj in module.all_objects:
1.18 + if isinstance(obj, (micropython.inspect.Class, micropython.inspect.Function)):
1.19 + obj.finalise_attributes()
1.20 +
1.21 def get_modules(self):
1.22
1.23 "Return all modules known to the importer."
1.24 @@ -113,8 +127,12 @@
1.25
1.26 "Return a dictionary mapping modules to structures."
1.27
1.28 + if self.code is not None:
1.29 + return self.code
1.30 +
1.31 objtable = self.get_object_table()
1.32 paramtable = self.get_parameter_table()
1.33 + self.finalise()
1.34
1.35 image = []
1.36
1.37 @@ -129,10 +147,6 @@
1.38 if not with_builtins and module.name == "__builtins__":
1.39 continue
1.40
1.41 - # Fix the attributes.
1.42 -
1.43 - module.finalise_attributes()
1.44 -
1.45 pos = len(image)
1.46
1.47 # Position the module in the image and make a translation.
1.48 @@ -156,10 +170,6 @@
1.49 for obj in module.all_objects:
1.50 if isinstance(obj, micropython.inspect.Class):
1.51
1.52 - # Fix the attributes.
1.53 -
1.54 - obj.finalise_attributes()
1.55 -
1.56 # Position the class in the image.
1.57
1.58 obj.location = pos
1.59 @@ -175,18 +185,21 @@
1.60 image += obj.attributes_as_list()
1.61 pos += len(attributes.keys())
1.62
1.63 - # Class-level code is generated separately.
1.64 - # The code location is set within the code generation
1.65 - # process for the module.
1.66 + # Generate the instantiator/initialiser.
1.67 + # Append the function code to the image.
1.68
1.69 - # NOTE: Generate module and function code here.
1.70 + instantiator = obj.get_instantiator()
1.71 + instantiator.code_location = pos
1.72 + code = trans.get_instantiator_code(obj)
1.73 + image += code
1.74 + pos += len(code)
1.75 +
1.76 + # Class-level code is generated separately at the module
1.77 + # level, and the code location is set within the code
1.78 + # generation process for the module.
1.79
1.80 elif isinstance(obj, micropython.inspect.Function):
1.81
1.82 - # Fix the attributes.
1.83 -
1.84 - obj.finalise_attributes()
1.85 -
1.86 # Position the function in the image.
1.87
1.88 obj.location = pos