1.1 --- a/micropython/data.py Fri Feb 12 01:34:28 2010 +0100
1.2 +++ b/micropython/data.py Sun Feb 14 16:28:12 2010 +0100
1.3 @@ -1,7 +1,11 @@
1.4 #!/usr/bin/env python
1.5
1.6 """
1.7 -Data classes.
1.8 +Program data structures. There are two separate kinds of structures: those with
1.9 +context, which are the values manipulated by programs, and those without
1.10 +context, which are typically constant things which are stored alongside the
1.11 +program but which are wrapped in context-dependent structures in the running
1.12 +program.
1.13
1.14 Copyright (C) 2007, 2008, 2009, 2010 Paul Boddie <paul@boddie.org.uk>
1.15
1.16 @@ -20,6 +24,10 @@
1.17
1.18 --------
1.19
1.20 +The principal value structure class in this module is the Attr class which
1.21 +represents attributes of objects and retains the context of each reference to an
1.22 +attribute. This class models program behaviour at run-time.
1.23 +
1.24 The central data structure classes in this module are the following:
1.25
1.26 * Class
1.27 @@ -123,12 +131,24 @@
1.28 # Specific namespaces should define known names during initialisation.
1.29 # For example, functions can define names belonging to parameters.
1.30
1.31 + # Attribute usage, defining a consensus for each name.
1.32 +
1.33 self.attributes_used = [{}] # stack of usage
1.34 self.attribute_shelves = [] # stack of unmerged definitions
1.35 +
1.36 + # Attribute usage abandonment, where the usage will not contribute to
1.37 + # the consensus.
1.38 +
1.39 self.abandon_attributes = 0 # used when a block will never contribute
1.40 self.abandoned_shelves = []
1.41 +
1.42 + # Attribute users, defining names which use attributes.
1.43 +
1.44 self.attribute_users = [{}] # stack of assignments
1.45 self.user_shelves = []
1.46 +
1.47 + # Define attribute usage to identify active program sections.
1.48 +
1.49 self.all_attributes_used = []
1.50
1.51 # Attribute/name definition and access.
1.52 @@ -369,17 +389,30 @@
1.53 self.all_attributes_used.append(defs[name])
1.54
1.55 def _new_branchpoint(self):
1.56 +
1.57 + """
1.58 + Establish a new branchpoint where several control-flow branches diverge
1.59 + and subsequently converge.
1.60 + """
1.61 +
1.62 self.attribute_shelves.append([])
1.63 self.abandoned_shelves.append([])
1.64 self.user_shelves.append([])
1.65
1.66 def _new_branch(self):
1.67 +
1.68 + """
1.69 + Establish a new control-flow branch, transferring attribute usage to
1.70 + the new branch so that it may be augmented for each name locally.
1.71 + """
1.72 +
1.73 d = {}
1.74 for name, attrnames in self.attributes_used[-1].items():
1.75 d[name] = set(attrnames)
1.76 self.attributes_used.append(d)
1.77
1.78 - # The users apply also to the new branch.
1.79 + # In the new branch, usage does not necessarily feed back to the users
1.80 + # immediately.
1.81
1.82 self.attribute_users.append({})
1.83
1.84 @@ -478,11 +511,7 @@
1.85 if not active.has_key(name) or attrnames.issuperset(active[name]):
1.86 self.all_attributes_used.append(attrnames)
1.87
1.88 -# Program data structures. There are two separate kinds of structures: those
1.89 -# with context, which are the values manipulated by programs, and those without
1.90 -# context, which are typically constant things which are stored alongside the
1.91 -# program but which are wrapped in context-dependent structures in the running
1.92 -# program.
1.93 +# Program data structures.
1.94
1.95 class Attr:
1.96