# HG changeset patch # User Paul Boddie # Date 1342291099 -7200 # Node ID 8dc737ce59edc986af21a4c701146fd7a3820f16 # Parent d13e02292ffaacb51152e264114b21f672a96801 Initialised the annotation attributes on the underlying AST nodes, requiring a modified compiler library, removing the associated attribute presence tests in this software. diff -r d13e02292ffa -r 8dc737ce59ed README.txt --- a/README.txt Sat Jul 14 17:42:42 2012 +0200 +++ b/README.txt Sat Jul 14 20:38:19 2012 +0200 @@ -20,17 +20,14 @@ directory of this software. See the following locations for the code for this compiler package variant: -http://hgweb.boddie.org.uk/python2.5-compiler-package/ -http://hgweb.boddie.org.uk/python2.6-compiler-package/ -http://hgweb.boddie.org.uk/python2.7-compiler-package/ +http://hgweb.boddie.org.uk/python2.6-compiler-package-micropython/ It should be sufficient to use the Python 2.6 package for systems running Python 2.5 or 2.6 since the underlying standard library does not seem to have changed significantly between these releases and the language syntax is -sufficiently similar. For Python 2.7, the appropriate variant may be -preferable or even required due to standard library and syntax changes in that -release of the language implementation, but this has not yet been tested in -any depth. +sufficiently similar. For Python 2.7, an appropriate variant may be preferable +or even required due to standard library and syntax changes in that release of +the language implementation, but this has not yet been tested in any depth. Quick Start ----------- diff -r d13e02292ffa -r 8dc737ce59ed docs/annotations.txt --- a/docs/annotations.txt Sat Jul 14 17:42:42 2012 +0200 +++ b/docs/annotations.txt Sat Jul 14 20:38:19 2012 +0200 @@ -12,11 +12,6 @@ Attribute Users --------------- -_attrcontributors defines nodes contributing to combined attribute usage known - to a node -_attrcombined defines a dictionary mapping local names to sets of - attribute names found to be used with those names for the - entire lifetime of a particular attribute user _attrtypes defines types deduced either from combined attribute usage details (for users) @@ -26,6 +21,13 @@ _attrnames defines a dictionary mapping local names to sets of attribute names found to be used with those names in a branch +_attrbranches indicates the immediate contributors to attribute usage + known to a node +_attrcontributors defines nodes contributing to combined attribute usage known + to a node +_attrcombined defines a dictionary mapping local names to sets of + attribute names found to be used with those names for the + entire lifetime of a particular attribute user _attrmerged defines a dictionary mapping local names to sets of attribute names merging combined observations with locally applicable observations, indicating usage specific to a diff -r d13e02292ffa -r 8dc737ce59ed micropython/ast.py --- a/micropython/ast.py Sat Jul 14 17:42:42 2012 +0200 +++ b/micropython/ast.py Sat Jul 14 20:38:19 2012 +0200 @@ -561,9 +561,11 @@ "Assign the assignment expression to the recipient 'node'." - if hasattr(node, "flags") and node.flags == "OP_DELETE": + if node.flags == "OP_DELETE": raise TranslationNotImplementedError("AssName(OP_DELETE)") + self._visitAssName(node) + def _visitAssName(self, node): self.start_target() self._visitName(node, self.name_store_instructions) self.assign_value() @@ -587,7 +589,7 @@ self.record_value(1) if isinstance(node.node, compiler.ast.Name): - self.visitAssName(node.node) + self._visitAssName(node.node) elif isinstance(node.node, compiler.ast.Getattr): self.visitAssAttr(node.node) else: diff -r d13e02292ffa -r 8dc737ce59ed micropython/common.py --- a/micropython/common.py Sat Jul 14 17:42:42 2012 +0200 +++ b/micropython/common.py Sat Jul 14 20:38:19 2012 +0200 @@ -19,9 +19,9 @@ this program. If not, see . """ -from micropython.data import Attr, Instance, UnresolvedName +from compiler.ast import Class, Function, Module +from micropython.data import Attr from micropython.errors import * -import sys try: set @@ -55,7 +55,7 @@ # NOTE: Should perhaps specialise the subclasses appropriately. - if hasattr(self, "unit"): + if isinstance(self, (Class, Function, Module)): exc.unit_name = self.unit.full_name() else: exc.unit_name = self.full_name() @@ -79,13 +79,13 @@ # not that of a general instance or an unresolved name, attempt to # identify it. - if hasattr(node, "_attr") and isinstance(node._attr, Attr): + if node._attr and isinstance(node._attr, Attr): attr = node._attr target_names.add((attr.parent.full_name(), attr.is_static_attribute())) # Otherwise, attempt to employ the attribute usage observations. - elif hasattr(node, "_attrusers"): + elif node._attrusers: # Visit each attribute user. @@ -111,7 +111,7 @@ program unit within which it is found. """ - return hasattr(node, "unit") and node.unit.parent.has_key(node.unit.name) + return node.unit and node.unit.parent.has_key(node.unit.name) # Useful data. diff -r d13e02292ffa -r 8dc737ce59ed micropython/data.py --- a/micropython/data.py Sat Jul 14 17:42:42 2012 +0200 +++ b/micropython/data.py Sat Jul 14 20:38:19 2012 +0200 @@ -52,6 +52,7 @@ where each such object is defined. """ +from compiler.ast import AttributeUser from micropython.program import ReplaceableContext, PlaceholderContext from micropython.basicdata import * from micropython.errors import * @@ -424,7 +425,7 @@ program unit. """ - if not hasattr(node, "_attrspecifictypes"): + if node._attrspecifictypes is None: merged = {} # Get the combined usage information from the user definitions. @@ -478,9 +479,11 @@ unfinished = {} - if not hasattr(node, "_attrcombined"): - node._attrcombined = None - node._attrcontributors = None + # Process any unprocessed contributors, indicating the unfinished state + # of the associated data. + + if node._attrcombined is None: + node._attrcombined = Unset for contributor in node._attrbranches: @@ -494,7 +497,7 @@ # occurred and this node will need to have its usage # recalculated later for the unfinished contributor. - if contributor._attrcombined is None: + if contributor._attrcombined is Unset: if not unfinished.has_key(contributor): unfinished[contributor] = [] unfinished[contributor].append(node) @@ -543,7 +546,7 @@ for contributor in node._attrbranches: usage = contributor._attrcombined - if usage is not None: + if usage is not Unset: all_contributions.append(usage) all_contributors.add(contributor) @@ -673,25 +676,25 @@ # Attribute usage for names. - if not hasattr(node, "_attrnames"): + if node._attrnames is None: node._attrnames = {} node._attrmerged = {} # Branches contributing usage to this node. - if not hasattr(node, "_attrbranches"): + if node._attrbranches is None: node._attrbranches = [] # Definitions receiving usage from this node. - if not hasattr(node, "_attrdefs"): + if node._attrdefs is None: node._attrdefs = [] def _define_attribute_accessor(self, name, attrname, node, value): # NOTE: Revisiting of nodes may occur for loops. - if not hasattr(node, "_attrusers"): + if node._attrusers is None: node._attrusers = set() node._attrusers.update(self.use_attribute(name, attrname, value)) @@ -1021,7 +1024,7 @@ def __init__(self, scopes): self.scopes = scopes -class NullBranch: +class NullBranch(AttributeUser): "A class representing an attribute user for a non-existent branch." @@ -2209,4 +2212,13 @@ def __repr__(self): return "AtLeast(%r)" % self.count +class UnsetType: + + "A None-like value." + + def __nonzero__(self): + return False + +Unset = UnsetType() + # vim: tabstop=4 expandtab shiftwidth=4 diff -r d13e02292ffa -r 8dc737ce59ed micropython/inspect.py --- a/micropython/inspect.py Sat Jul 14 17:42:42 2012 +0200 +++ b/micropython/inspect.py Sat Jul 14 20:38:19 2012 +0200 @@ -661,6 +661,9 @@ # NOTE: Need to provide concrete values for things like base classes # NOTE: while also handling module attribute modification. + # Only specific class attributes are detected here since class + # attribute finalisation has not yet occurred. + if isinstance(value, (Class, Module)): # Check for class.__class__. @@ -864,10 +867,12 @@ self._visitConst(i) # for __getitem__(i) at run-time def visitAssName(self, node): - if hasattr(node, "flags") and node.flags == "OP_DELETE": + if node.flags == "OP_DELETE": print >>sys.stderr, "Warning: deletion of attribute %r in %r is not supported." % (node.name, self.full_name()) #raise InspectError("Deletion of attribute %r is not supported." % node.name) + self._visitAssName(node) + def _visitAssName(self, node): self.store(node.name, self.expr) self.define_attribute_user(node) @@ -902,7 +907,7 @@ # NOTE: not __setslice__. if isinstance(node.node, compiler.ast.Name): - self.visitAssName(node.node) + self._visitAssName(node.node) elif isinstance(node.node, compiler.ast.Getattr): self.visitAssAttr(node.node) else: diff -r d13e02292ffa -r 8dc737ce59ed micropython/report.py --- a/micropython/report.py Sat Jul 14 17:42:42 2012 +0200 +++ b/micropython/report.py Sat Jul 14 20:38:19 2012 +0200 @@ -344,7 +344,7 @@ self._names_list_end() def _attrcombined(self, name, node): - attrcombined = hasattr(node, "_attrcombined") and node._attrcombined.get(name) or [] + attrcombined = node._attrcombined and node._attrcombined.get(name) or [] for attrnames in attrcombined: if attrnames: @@ -1264,7 +1264,7 @@ self._visitBinary(node, "*") def visitName(self, node): - if hasattr(node, "_scope"): + if node._scope: scope = node._scope self._name_start() self.stream.write(node.name) diff -r d13e02292ffa -r 8dc737ce59ed micropython/trans.py --- a/micropython/trans.py Sat Jul 14 17:42:42 2012 +0200 +++ b/micropython/trans.py Sat Jul 14 20:38:19 2012 +0200 @@ -33,7 +33,7 @@ def _generateGuards(self, node): - if not (self.optimiser.should_optimise_accesses_by_attribute_usage() and hasattr(node, "_attrtypes")): + if not (self.optimiser.should_optimise_accesses_by_attribute_usage() and node._attrtypes): return # For each name, attempt to restrict the type employed.