1.1 --- a/micropython/ast.py Sat Oct 25 21:51:23 2008 +0200
1.2 +++ b/micropython/ast.py Sun Oct 26 02:14:29 2008 +0200
1.3 @@ -106,7 +106,22 @@
1.4
1.5 self.optimiser.reset()
1.6
1.7 + def get_code_for_blocks(self, blocks, location):
1.8 +
1.9 + """
1.10 + Return the code for the given 'blocks', appearing at the given location.
1.11 + """
1.12 +
1.13 + code = []
1.14 + for block in blocks:
1.15 + block.location = len(code) + location
1.16 + code += block.code
1.17 + return code
1.18 +
1.19 def get_module_code(self, final=0):
1.20 + return self.get_code_for_blocks(self.get_module_blocks(final), self.module.code_location)
1.21 +
1.22 + def get_module_blocks(self, final=0):
1.23
1.24 """
1.25 Return the top-level module code including finalising code if 'final' is
1.26 @@ -131,6 +146,9 @@
1.27 return self.blocks
1.28
1.29 def get_code(self, unit):
1.30 + return self.get_code_for_blocks(self.get_blocks(unit), unit.code_location)
1.31 +
1.32 + def get_blocks(self, unit):
1.33
1.34 "Return the code for the given 'unit'."
1.35
1.36 @@ -147,6 +165,9 @@
1.37 return self.blocks
1.38
1.39 def get_instantiator_code(self, cls):
1.40 + return self.get_code_for_blocks(self.get_instantiator_blocks(cls), cls.get_instantiator().code_location)
1.41 +
1.42 + def get_instantiator_blocks(self, cls):
1.43
1.44 "Return the code for the given class 'cls'."
1.45
1.46 @@ -409,7 +430,7 @@
1.47 """
1.48
1.49 ntemp = self.max_temp_position + 1
1.50 - extend.attr = ntemp + node.unit.local_usage # NOTE: See get_code for similar code.
1.51 + extend.attr = ntemp + node.unit.local_usage # NOTE: See get_blocks for similar code.
1.52
1.53 # Code writing methods.
1.54
1.55 @@ -1677,7 +1698,7 @@
1.56
1.57 self._generateFunctionDefaults(node.unit)
1.58
1.59 - # Visiting of the code occurs when get_code is invoked on this node.
1.60 + # Visiting of the code occurs when get_blocks is invoked on this node.
1.61
1.62 else:
1.63 extend = ExtendFrame()
1.64 @@ -1729,7 +1750,7 @@
1.65 self.new_op(temp)
1.66 #self.discard_temp(temp)
1.67
1.68 - # Visiting of the code occurs when get_code is invoked on this node.
1.69 + # Visiting of the code occurs when get_blocks is invoked on this node.
1.70
1.71 else:
1.72 self.dispatch(node.code)