1.1 --- a/README.txt Sat Jul 14 17:42:42 2012 +0200
1.2 +++ b/README.txt Sat Jul 14 20:38:19 2012 +0200
1.3 @@ -20,17 +20,14 @@
1.4 directory of this software. See the following locations for the code for this
1.5 compiler package variant:
1.6
1.7 -http://hgweb.boddie.org.uk/python2.5-compiler-package/
1.8 -http://hgweb.boddie.org.uk/python2.6-compiler-package/
1.9 -http://hgweb.boddie.org.uk/python2.7-compiler-package/
1.10 +http://hgweb.boddie.org.uk/python2.6-compiler-package-micropython/
1.11
1.12 It should be sufficient to use the Python 2.6 package for systems running
1.13 Python 2.5 or 2.6 since the underlying standard library does not seem to have
1.14 changed significantly between these releases and the language syntax is
1.15 -sufficiently similar. For Python 2.7, the appropriate variant may be
1.16 -preferable or even required due to standard library and syntax changes in that
1.17 -release of the language implementation, but this has not yet been tested in
1.18 -any depth.
1.19 +sufficiently similar. For Python 2.7, an appropriate variant may be preferable
1.20 +or even required due to standard library and syntax changes in that release of
1.21 +the language implementation, but this has not yet been tested in any depth.
1.22
1.23 Quick Start
1.24 -----------
2.1 --- a/docs/annotations.txt Sat Jul 14 17:42:42 2012 +0200
2.2 +++ b/docs/annotations.txt Sat Jul 14 20:38:19 2012 +0200
2.3 @@ -12,11 +12,6 @@
2.4 Attribute Users
2.5 ---------------
2.6
2.7 -_attrcontributors defines nodes contributing to combined attribute usage known
2.8 - to a node
2.9 -_attrcombined defines a dictionary mapping local names to sets of
2.10 - attribute names found to be used with those names for the
2.11 - entire lifetime of a particular attribute user
2.12 _attrtypes defines types deduced either from combined attribute usage
2.13 details (for users)
2.14
2.15 @@ -26,6 +21,13 @@
2.16 _attrnames defines a dictionary mapping local names to sets of
2.17 attribute names found to be used with those names in a
2.18 branch
2.19 +_attrbranches indicates the immediate contributors to attribute usage
2.20 + known to a node
2.21 +_attrcontributors defines nodes contributing to combined attribute usage known
2.22 + to a node
2.23 +_attrcombined defines a dictionary mapping local names to sets of
2.24 + attribute names found to be used with those names for the
2.25 + entire lifetime of a particular attribute user
2.26 _attrmerged defines a dictionary mapping local names to sets of
2.27 attribute names merging combined observations with locally
2.28 applicable observations, indicating usage specific to a
3.1 --- a/micropython/ast.py Sat Jul 14 17:42:42 2012 +0200
3.2 +++ b/micropython/ast.py Sat Jul 14 20:38:19 2012 +0200
3.3 @@ -561,9 +561,11 @@
3.4
3.5 "Assign the assignment expression to the recipient 'node'."
3.6
3.7 - if hasattr(node, "flags") and node.flags == "OP_DELETE":
3.8 + if node.flags == "OP_DELETE":
3.9 raise TranslationNotImplementedError("AssName(OP_DELETE)")
3.10 + self._visitAssName(node)
3.11
3.12 + def _visitAssName(self, node):
3.13 self.start_target()
3.14 self._visitName(node, self.name_store_instructions)
3.15 self.assign_value()
3.16 @@ -587,7 +589,7 @@
3.17 self.record_value(1)
3.18
3.19 if isinstance(node.node, compiler.ast.Name):
3.20 - self.visitAssName(node.node)
3.21 + self._visitAssName(node.node)
3.22 elif isinstance(node.node, compiler.ast.Getattr):
3.23 self.visitAssAttr(node.node)
3.24 else:
4.1 --- a/micropython/common.py Sat Jul 14 17:42:42 2012 +0200
4.2 +++ b/micropython/common.py Sat Jul 14 20:38:19 2012 +0200
4.3 @@ -19,9 +19,9 @@
4.4 this program. If not, see <http://www.gnu.org/licenses/>.
4.5 """
4.6
4.7 -from micropython.data import Attr, Instance, UnresolvedName
4.8 +from compiler.ast import Class, Function, Module
4.9 +from micropython.data import Attr
4.10 from micropython.errors import *
4.11 -import sys
4.12
4.13 try:
4.14 set
4.15 @@ -55,7 +55,7 @@
4.16
4.17 # NOTE: Should perhaps specialise the subclasses appropriately.
4.18
4.19 - if hasattr(self, "unit"):
4.20 + if isinstance(self, (Class, Function, Module)):
4.21 exc.unit_name = self.unit.full_name()
4.22 else:
4.23 exc.unit_name = self.full_name()
4.24 @@ -79,13 +79,13 @@
4.25 # not that of a general instance or an unresolved name, attempt to
4.26 # identify it.
4.27
4.28 - if hasattr(node, "_attr") and isinstance(node._attr, Attr):
4.29 + if node._attr and isinstance(node._attr, Attr):
4.30 attr = node._attr
4.31 target_names.add((attr.parent.full_name(), attr.is_static_attribute()))
4.32
4.33 # Otherwise, attempt to employ the attribute usage observations.
4.34
4.35 - elif hasattr(node, "_attrusers"):
4.36 + elif node._attrusers:
4.37
4.38 # Visit each attribute user.
4.39
4.40 @@ -111,7 +111,7 @@
4.41 program unit within which it is found.
4.42 """
4.43
4.44 - return hasattr(node, "unit") and node.unit.parent.has_key(node.unit.name)
4.45 + return node.unit and node.unit.parent.has_key(node.unit.name)
4.46
4.47 # Useful data.
4.48
5.1 --- a/micropython/data.py Sat Jul 14 17:42:42 2012 +0200
5.2 +++ b/micropython/data.py Sat Jul 14 20:38:19 2012 +0200
5.3 @@ -52,6 +52,7 @@
5.4 where each such object is defined.
5.5 """
5.6
5.7 +from compiler.ast import AttributeUser
5.8 from micropython.program import ReplaceableContext, PlaceholderContext
5.9 from micropython.basicdata import *
5.10 from micropython.errors import *
5.11 @@ -424,7 +425,7 @@
5.12 program unit.
5.13 """
5.14
5.15 - if not hasattr(node, "_attrspecifictypes"):
5.16 + if node._attrspecifictypes is None:
5.17 merged = {}
5.18
5.19 # Get the combined usage information from the user definitions.
5.20 @@ -478,9 +479,11 @@
5.21
5.22 unfinished = {}
5.23
5.24 - if not hasattr(node, "_attrcombined"):
5.25 - node._attrcombined = None
5.26 - node._attrcontributors = None
5.27 + # Process any unprocessed contributors, indicating the unfinished state
5.28 + # of the associated data.
5.29 +
5.30 + if node._attrcombined is None:
5.31 + node._attrcombined = Unset
5.32
5.33 for contributor in node._attrbranches:
5.34
5.35 @@ -494,7 +497,7 @@
5.36 # occurred and this node will need to have its usage
5.37 # recalculated later for the unfinished contributor.
5.38
5.39 - if contributor._attrcombined is None:
5.40 + if contributor._attrcombined is Unset:
5.41 if not unfinished.has_key(contributor):
5.42 unfinished[contributor] = []
5.43 unfinished[contributor].append(node)
5.44 @@ -543,7 +546,7 @@
5.45
5.46 for contributor in node._attrbranches:
5.47 usage = contributor._attrcombined
5.48 - if usage is not None:
5.49 + if usage is not Unset:
5.50 all_contributions.append(usage)
5.51
5.52 all_contributors.add(contributor)
5.53 @@ -673,25 +676,25 @@
5.54
5.55 # Attribute usage for names.
5.56
5.57 - if not hasattr(node, "_attrnames"):
5.58 + if node._attrnames is None:
5.59 node._attrnames = {}
5.60 node._attrmerged = {}
5.61
5.62 # Branches contributing usage to this node.
5.63
5.64 - if not hasattr(node, "_attrbranches"):
5.65 + if node._attrbranches is None:
5.66 node._attrbranches = []
5.67
5.68 # Definitions receiving usage from this node.
5.69
5.70 - if not hasattr(node, "_attrdefs"):
5.71 + if node._attrdefs is None:
5.72 node._attrdefs = []
5.73
5.74 def _define_attribute_accessor(self, name, attrname, node, value):
5.75
5.76 # NOTE: Revisiting of nodes may occur for loops.
5.77
5.78 - if not hasattr(node, "_attrusers"):
5.79 + if node._attrusers is None:
5.80 node._attrusers = set()
5.81
5.82 node._attrusers.update(self.use_attribute(name, attrname, value))
5.83 @@ -1021,7 +1024,7 @@
5.84 def __init__(self, scopes):
5.85 self.scopes = scopes
5.86
5.87 -class NullBranch:
5.88 +class NullBranch(AttributeUser):
5.89
5.90 "A class representing an attribute user for a non-existent branch."
5.91
5.92 @@ -2209,4 +2212,13 @@
5.93 def __repr__(self):
5.94 return "AtLeast(%r)" % self.count
5.95
5.96 +class UnsetType:
5.97 +
5.98 + "A None-like value."
5.99 +
5.100 + def __nonzero__(self):
5.101 + return False
5.102 +
5.103 +Unset = UnsetType()
5.104 +
5.105 # vim: tabstop=4 expandtab shiftwidth=4
6.1 --- a/micropython/inspect.py Sat Jul 14 17:42:42 2012 +0200
6.2 +++ b/micropython/inspect.py Sat Jul 14 20:38:19 2012 +0200
6.3 @@ -661,6 +661,9 @@
6.4 # NOTE: Need to provide concrete values for things like base classes
6.5 # NOTE: while also handling module attribute modification.
6.6
6.7 + # Only specific class attributes are detected here since class
6.8 + # attribute finalisation has not yet occurred.
6.9 +
6.10 if isinstance(value, (Class, Module)):
6.11
6.12 # Check for class.__class__.
6.13 @@ -864,10 +867,12 @@
6.14 self._visitConst(i) # for __getitem__(i) at run-time
6.15
6.16 def visitAssName(self, node):
6.17 - if hasattr(node, "flags") and node.flags == "OP_DELETE":
6.18 + if node.flags == "OP_DELETE":
6.19 print >>sys.stderr, "Warning: deletion of attribute %r in %r is not supported." % (node.name, self.full_name())
6.20 #raise InspectError("Deletion of attribute %r is not supported." % node.name)
6.21 + self._visitAssName(node)
6.22
6.23 + def _visitAssName(self, node):
6.24 self.store(node.name, self.expr)
6.25 self.define_attribute_user(node)
6.26
6.27 @@ -902,7 +907,7 @@
6.28 # NOTE: not __setslice__.
6.29
6.30 if isinstance(node.node, compiler.ast.Name):
6.31 - self.visitAssName(node.node)
6.32 + self._visitAssName(node.node)
6.33 elif isinstance(node.node, compiler.ast.Getattr):
6.34 self.visitAssAttr(node.node)
6.35 else:
7.1 --- a/micropython/report.py Sat Jul 14 17:42:42 2012 +0200
7.2 +++ b/micropython/report.py Sat Jul 14 20:38:19 2012 +0200
7.3 @@ -344,7 +344,7 @@
7.4 self._names_list_end()
7.5
7.6 def _attrcombined(self, name, node):
7.7 - attrcombined = hasattr(node, "_attrcombined") and node._attrcombined.get(name) or []
7.8 + attrcombined = node._attrcombined and node._attrcombined.get(name) or []
7.9
7.10 for attrnames in attrcombined:
7.11 if attrnames:
7.12 @@ -1264,7 +1264,7 @@
7.13 self._visitBinary(node, "*")
7.14
7.15 def visitName(self, node):
7.16 - if hasattr(node, "_scope"):
7.17 + if node._scope:
7.18 scope = node._scope
7.19 self._name_start()
7.20 self.stream.write(node.name)
8.1 --- a/micropython/trans.py Sat Jul 14 17:42:42 2012 +0200
8.2 +++ b/micropython/trans.py Sat Jul 14 20:38:19 2012 +0200
8.3 @@ -33,7 +33,7 @@
8.4
8.5 def _generateGuards(self, node):
8.6
8.7 - if not (self.optimiser.should_optimise_accesses_by_attribute_usage() and hasattr(node, "_attrtypes")):
8.8 + if not (self.optimiser.should_optimise_accesses_by_attribute_usage() and node._attrtypes):
8.9 return
8.10
8.11 # For each name, attempt to restrict the type employed.