1.1 --- a/micropython/__init__.py Sat Jan 24 02:41:59 2009 +0100
1.2 +++ b/micropython/__init__.py Sun Jan 25 02:56:16 2009 +0100
1.3 @@ -101,10 +101,6 @@
1.4 last_module = self.importer.modules_ordered[-1]
1.5
1.6 for module in self.importer.modules_ordered:
1.7 -
1.8 - if not with_builtins and module.name == "__builtins__":
1.9 - continue
1.10 -
1.11 pos = len(self.code)
1.12
1.13 # Position the module in the image and make a translation.
1.14 @@ -164,17 +160,29 @@
1.15 self.code += obj.default_attrs
1.16 pos += len(obj.default_attrs)
1.17
1.18 + # Omit built-in function code where requested.
1.19 +
1.20 + if not with_builtins and module.name == "__builtins__":
1.21 + pass
1.22 +
1.23 # Append the function code to the image.
1.24
1.25 - code = trans.get_code(obj)
1.26 - self.code += code
1.27 - pos += len(code)
1.28 + else:
1.29 + code = trans.get_code(obj)
1.30 + self.code += code
1.31 + pos += len(code)
1.32 +
1.33 + # Omit built-in module code where requested.
1.34 +
1.35 + if not with_builtins and module.name == "__builtins__":
1.36 + pass
1.37
1.38 # Append the module top-level code to the image.
1.39
1.40 - code = trans.get_module_code(final=(module is last_module))
1.41 - self.code += code
1.42 - pos += len(code)
1.43 + else:
1.44 + code = trans.get_module_code(final=(module is last_module))
1.45 + self.code += code
1.46 + pos += len(code)
1.47
1.48 return self.code
1.49
1.50 @@ -191,17 +199,36 @@
1.51
1.52 pos = 0
1.53 for item in self.code:
1.54 +
1.55 + # Blocks are positioned leaving space for their expansion.
1.56 +
1.57 if isinstance(item, Block):
1.58 item.location = pos
1.59 pos += len(item.code)
1.60 +
1.61 + # Other multi-location objects.
1.62 +
1.63 elif isinstance(item, (micropython.data.Class, micropython.data.Const,
1.64 micropython.data.Function, micropython.data.Module)):
1.65 +
1.66 item.location = pos
1.67 pos += 1
1.68 +
1.69 + # Code and details are associated with certain objects.
1.70 +
1.71 if isinstance(item, micropython.data.Function):
1.72 - item.code_location = pos
1.73 +
1.74 + # Set the code location only where the code has been
1.75 + # generated.
1.76 +
1.77 + if not with_builtins and item.module.name == "__builtins__":
1.78 + item.code_location = item.full_name()
1.79 + else:
1.80 + item.code_location = pos
1.81 +
1.82 elif isinstance(item, micropython.data.Const):
1.83 pos += len(self.raw_data(item))
1.84 +
1.85 else:
1.86 pos += 1
1.87
1.88 @@ -270,7 +297,10 @@
1.89 0
1.90 ))
1.91
1.92 - assert item.code_location == len(self.raw_code)
1.93 + # Check the code location only where the code has been generated.
1.94 +
1.95 + assert (not with_builtins and item.module.name == "__builtins__") or \
1.96 + item.code_location == len(self.raw_code)
1.97
1.98 elif isinstance(item, micropython.data.Module):
1.99 assert item.location == len(self.raw_code)