1.1 --- a/micropython/ast.py Sun Oct 26 02:14:29 2008 +0200
1.2 +++ b/micropython/ast.py Mon Oct 27 01:19:06 2008 +0100
1.3 @@ -106,22 +106,7 @@
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 @@ -146,9 +131,6 @@
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 @@ -165,9 +147,6 @@
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 @@ -430,7 +409,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_blocks for similar code.
1.51 + extend.attr = ntemp + node.unit.local_usage # NOTE: See get_code for similar code.
1.52
1.53 # Code writing methods.
1.54
1.55 @@ -1698,7 +1677,7 @@
1.56
1.57 self._generateFunctionDefaults(node.unit)
1.58
1.59 - # Visiting of the code occurs when get_blocks is invoked on this node.
1.60 + # Visiting of the code occurs when get_code is invoked on this node.
1.61
1.62 else:
1.63 extend = ExtendFrame()
1.64 @@ -1750,7 +1729,7 @@
1.65 self.new_op(temp)
1.66 #self.discard_temp(temp)
1.67
1.68 - # Visiting of the code occurs when get_blocks is invoked on this node.
1.69 + # Visiting of the code occurs when get_code is invoked on this node.
1.70
1.71 else:
1.72 self.dispatch(node.code)
2.1 --- a/micropython/common.py Sun Oct 26 02:14:29 2008 +0200
2.2 +++ b/micropython/common.py Mon Oct 27 01:19:06 2008 +0100
2.3 @@ -84,17 +84,6 @@
2.4 def __repr__(self):
2.5 return "Block(%r, location=%r)" % (id(self), self.location)
2.6
2.7 -class Label:
2.8 -
2.9 - "A reference to a location."
2.10 -
2.11 - def __init__(self, number, location=None):
2.12 - self.number = number
2.13 - self.location = location
2.14 -
2.15 - def __repr__(self):
2.16 - return "Label(%r, location=%r)" % (self.number, self.location)
2.17 -
2.18 # Inspection representations.
2.19
2.20 class AtLeast:
3.1 --- a/micropython/rsvp.py Sun Oct 26 02:14:29 2008 +0200
3.2 +++ b/micropython/rsvp.py Mon Oct 27 01:19:06 2008 +0100
3.3 @@ -19,7 +19,7 @@
3.4 this program. If not, see <http://www.gnu.org/licenses/>.
3.5 """
3.6
3.7 -from micropython.common import Label
3.8 +from micropython.common import Block
3.9 from micropython.data import Attr, Class, Const, Function, Module
3.10
3.11 def raw(code, objtable, paramtable):
3.12 @@ -30,6 +30,7 @@
3.13 """
3.14
3.15 new_code = []
3.16 +
3.17 for item in code:
3.18
3.19 if isinstance(item, Attr):
3.20 @@ -38,6 +39,9 @@
3.21 item.value and item.value.location # no useful context is provided
3.22 ))
3.23
3.24 + elif isinstance(item, Block):
3.25 + new_code += raw_block(item, len(new_code))
3.26 +
3.27 # Using classcode, attrcode, codeaddr, codedetails, instance.
3.28
3.29 elif isinstance(item, Class):
3.30 @@ -90,6 +94,18 @@
3.31
3.32 return new_code
3.33
3.34 +def raw_block(block, location):
3.35 +
3.36 + """
3.37 + Return the code for the given 'block', appearing at the given location.
3.38 + """
3.39 +
3.40 + block.location = location
3.41 + for i, item in enumerate(block.code):
3.42 + if hasattr(item, "location"):
3.43 + item.location = location + i
3.44 + return block.code
3.45 +
3.46 def name(attr):
3.47 if isinstance(attr, Attr):
3.48 return attr.name or "<unnamed>"
3.49 @@ -186,8 +202,6 @@
3.50 position = self.attr.name
3.51 result = None
3.52 return location, position, result
3.53 - elif isinstance(self.attr, Label):
3.54 - return None, None, self.attr.location
3.55 else:
3.56 return None, None, self.attr.location
3.57