# HG changeset patch # User Paul Boddie # Date 1225066746 -3600 # Node ID b46b27a60bcd8f498db967fe2528d2d562addc03 # Parent 63855c5d72afa61c746337b8ebf808eefeb782e4 Moved block expansion into the micropython.rsvp module's raw processing functions. Reverted the get*_code methods on the Translation class to return blocks. Removed the Label class. diff -r 63855c5d72af -r b46b27a60bcd micropython/ast.py --- a/micropython/ast.py Sun Oct 26 02:14:29 2008 +0200 +++ b/micropython/ast.py Mon Oct 27 01:19:06 2008 +0100 @@ -106,22 +106,7 @@ self.optimiser.reset() - def get_code_for_blocks(self, blocks, location): - - """ - Return the code for the given 'blocks', appearing at the given location. - """ - - code = [] - for block in blocks: - block.location = len(code) + location - code += block.code - return code - def get_module_code(self, final=0): - return self.get_code_for_blocks(self.get_module_blocks(final), self.module.code_location) - - def get_module_blocks(self, final=0): """ Return the top-level module code including finalising code if 'final' is @@ -146,9 +131,6 @@ return self.blocks def get_code(self, unit): - return self.get_code_for_blocks(self.get_blocks(unit), unit.code_location) - - def get_blocks(self, unit): "Return the code for the given 'unit'." @@ -165,9 +147,6 @@ return self.blocks def get_instantiator_code(self, cls): - return self.get_code_for_blocks(self.get_instantiator_blocks(cls), cls.get_instantiator().code_location) - - def get_instantiator_blocks(self, cls): "Return the code for the given class 'cls'." @@ -430,7 +409,7 @@ """ ntemp = self.max_temp_position + 1 - extend.attr = ntemp + node.unit.local_usage # NOTE: See get_blocks for similar code. + extend.attr = ntemp + node.unit.local_usage # NOTE: See get_code for similar code. # Code writing methods. @@ -1698,7 +1677,7 @@ self._generateFunctionDefaults(node.unit) - # Visiting of the code occurs when get_blocks is invoked on this node. + # Visiting of the code occurs when get_code is invoked on this node. else: extend = ExtendFrame() @@ -1750,7 +1729,7 @@ self.new_op(temp) #self.discard_temp(temp) - # Visiting of the code occurs when get_blocks is invoked on this node. + # Visiting of the code occurs when get_code is invoked on this node. else: self.dispatch(node.code) diff -r 63855c5d72af -r b46b27a60bcd micropython/common.py --- a/micropython/common.py Sun Oct 26 02:14:29 2008 +0200 +++ b/micropython/common.py Mon Oct 27 01:19:06 2008 +0100 @@ -84,17 +84,6 @@ def __repr__(self): return "Block(%r, location=%r)" % (id(self), self.location) -class Label: - - "A reference to a location." - - def __init__(self, number, location=None): - self.number = number - self.location = location - - def __repr__(self): - return "Label(%r, location=%r)" % (self.number, self.location) - # Inspection representations. class AtLeast: diff -r 63855c5d72af -r b46b27a60bcd micropython/rsvp.py --- a/micropython/rsvp.py Sun Oct 26 02:14:29 2008 +0200 +++ b/micropython/rsvp.py Mon Oct 27 01:19:06 2008 +0100 @@ -19,7 +19,7 @@ this program. If not, see . """ -from micropython.common import Label +from micropython.common import Block from micropython.data import Attr, Class, Const, Function, Module def raw(code, objtable, paramtable): @@ -30,6 +30,7 @@ """ new_code = [] + for item in code: if isinstance(item, Attr): @@ -38,6 +39,9 @@ item.value and item.value.location # no useful context is provided )) + elif isinstance(item, Block): + new_code += raw_block(item, len(new_code)) + # Using classcode, attrcode, codeaddr, codedetails, instance. elif isinstance(item, Class): @@ -90,6 +94,18 @@ return new_code +def raw_block(block, location): + + """ + Return the code for the given 'block', appearing at the given location. + """ + + block.location = location + for i, item in enumerate(block.code): + if hasattr(item, "location"): + item.location = location + i + return block.code + def name(attr): if isinstance(attr, Attr): return attr.name or "" @@ -186,8 +202,6 @@ position = self.attr.name result = None return location, position, result - elif isinstance(self.attr, Label): - return None, None, self.attr.location else: return None, None, self.attr.location