1.1 --- a/README.txt Tue Apr 07 00:57:04 2009 +0200
1.2 +++ b/README.txt Mon Apr 20 01:50:00 2009 +0200
1.3 @@ -205,10 +205,3 @@
1.4 could be costly. Another less ambitious solution might only involve the
1.5 optimisation of such internal method calls if an unambiguous target can be
1.6 resolved.
1.7 -
1.8 -Optimising Function Invocations
1.9 --------------------------------
1.10 -
1.11 -Where an attribute value is itself regarded as constant and is a function,
1.12 -knowledge about the parameters of the function can be employed to optimise the
1.13 -preparation of the invocation frame.
2.1 --- a/docs/concepts.txt Tue Apr 07 00:57:04 2009 +0200
2.2 +++ b/docs/concepts.txt Mon Apr 20 01:50:00 2009 +0200
2.3 @@ -1,12 +1,33 @@
2.4 Concepts
2.5 ========
2.6
2.7 +This document describes the underlying concepts employed in micropython.
2.8 +
2.9 + * Namespaces and attribute definition
2.10 * Contexts and values
2.11 * Tables, attributes and lookups
2.12 * Objects and structures
2.13 * Parameters and lookups
2.14 * Instantiation
2.15
2.16 +Namespaces and Attribute Definition
2.17 +===================================
2.18 +
2.19 +Namespaces are any objects which can retain attributes.
2.20 +
2.21 + * Module attributes are defined either at the module level or by global
2.22 + statements.
2.23 + * Class attributes are defined only within class statements.
2.24 + * Instance attributes are defined only by assignments to attributes of self
2.25 + within __init__ methods.
2.26 +
2.27 +These restrictions apply because such attributes are thus explicitly declared,
2.28 +permitting the use of tables (described below). Module and class attributes
2.29 +can also be finalised in this way in order to permit certain optimisations.
2.30 +
2.31 +See rejected.txt for complicating mechanisms which could be applied to
2.32 +mitigate the effects of these restrictions on optimisations.
2.33 +
2.34 Contexts and Values
2.35 ===================
2.36
2.37 @@ -56,10 +77,9 @@
2.38 LoadConst Load class, function, Combine null context with
2.39 module, constant loaded object
2.40
2.41 - LoadAddress Load attribute from Preserve or override stored
2.42 - LoadAddressContext class, module, context (as described in
2.43 - LoadAttr instance assignment.txt)
2.44 - LoadAttrIndex
2.45 + LoadAddress* Load attribute from Preserve or override stored
2.46 + LoadAttr* class, module, context (as described in
2.47 + instance assignment.txt)
2.48
2.49 In order to comply with traditional Python behaviour, contexts may or may not
2.50 represent the object from which an attribute has been acquired.
3.1 --- a/docs/evaluation.txt Tue Apr 07 00:57:04 2009 +0200
3.2 +++ b/docs/evaluation.txt Mon Apr 20 01:50:00 2009 +0200
3.3 @@ -46,6 +46,7 @@
3.4 ___ ___ ___ --> 3
3.5 ___ --> 1 1 | 1
3.6 ___ | ___ --> 2 | 2
3.7 + | | |
3.8 1 ----------- 2 ----------- 3 -----------
3.9
3.10 Conceptually, the frame can be considered as a collection of attributes, as
4.1 --- a/docs/index.txt Tue Apr 07 00:57:04 2009 +0200
4.2 +++ b/docs/index.txt Mon Apr 20 01:50:00 2009 +0200
4.3 @@ -1,4 +1,12 @@
4.4 Documentation Index
4.5 ===================
4.6
4.7 -concepts.txt
4.8 +concepts.txt An overview of the concepts employed in micropython
4.9 +
4.10 +assignment.txt A quick tour of assignment semantics
4.11 +evaluation.txt An overview of evaluation result storage and invocation frames
4.12 +invocation.txt A quick tour of invocation semantics
4.13 +
4.14 +optimisations.txt A table of optimisations currently employed in micropython
4.15 +rationale.txt A presentation of ideas and objectives
4.16 +related.txt Related work
5.1 --- a/docs/namespaces.txt Tue Apr 07 00:57:04 2009 +0200
5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
5.3 @@ -1,33 +0,0 @@
5.4 -Namespace Definition
5.5 -====================
5.6 -
5.7 -Module attributes are defined either at the module level or by global
5.8 -statements.
5.9 -
5.10 -Class attributes are defined only within class statements.
5.11 -
5.12 -Instance attributes are defined only by assignments to attributes of self
5.13 -within __init__ methods.
5.14 -
5.15 -(These restrictions apply because such attributes are thus explicitly
5.16 -declared. Module and class attributes can also be finalised in this way in
5.17 -order to permit certain optimisations.)
5.18 -
5.19 -Potential Restrictions
5.20 -----------------------
5.21 -
5.22 -Names of classes and functions could be restricted to only refer to those
5.23 -objects within the same namespace. If redefinition were to occur, or if
5.24 -multiple possibilities were present, these restrictions could be moderated as
5.25 -follows:
5.26 -
5.27 - * Classes assigned to the same name could provide the union of their
5.28 - attributes. This would, however, cause a potential collision of attribute
5.29 - definitions such as methods.
5.30 -
5.31 - * Functions, if they share compatible signatures, could share parameter list
5.32 - definitions.
5.33 -
5.34 -It is easier, however, to regard multiply defined classes and functions as
5.35 -non-constant and to either disallow optimisations or to actually prevent the
5.36 -program describing them from compiling.
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/docs/rejected.txt Mon Apr 20 01:50:00 2009 +0200
6.3 @@ -0,0 +1,19 @@
6.4 +Namespace Definitions
6.5 +=====================
6.6 +
6.7 +Attributes can be redefined in modules and classes, but this eliminates much
6.8 +of the potential for optimisation. However, names of classes and functions
6.9 +could be restricted to only refer to the same kinds of objects within the same
6.10 +namespace. If redefinition were to occur, or if multiple possibilities were
6.11 +present, these restrictions could be moderated as follows:
6.12 +
6.13 + * Classes assigned to the same name could provide the union of their
6.14 + attributes. This would, however, cause a potential collision of attribute
6.15 + definitions such as methods.
6.16 +
6.17 + * Functions, if they share compatible signatures, could share parameter list
6.18 + definitions.
6.19 +
6.20 +It is easier, however, to regard multiply defined classes and functions as
6.21 +non-constant and to either disallow optimisations or to actually prevent the
6.22 +program describing them from compiling.
7.1 --- a/micropython/__init__.py Tue Apr 07 00:57:04 2009 +0200
7.2 +++ b/micropython/__init__.py Mon Apr 20 01:50:00 2009 +0200
7.3 @@ -40,6 +40,7 @@
7.4 """
7.5
7.6 from micropython.common import *
7.7 +from micropython.program import Block
7.8 import micropython.ast
7.9 import micropython.data
7.10 import micropython.opt
8.1 --- a/micropython/common.py Tue Apr 07 00:57:04 2009 +0200
8.2 +++ b/micropython/common.py Mon Apr 20 01:50:00 2009 +0200
8.3 @@ -71,104 +71,6 @@
8.4
8.5 pass
8.6
8.7 -# Program code representations.
8.8 -
8.9 -class Block:
8.10 -
8.11 - "A code block."
8.12 -
8.13 - def __init__(self):
8.14 - self.code = []
8.15 - self.location = None
8.16 -
8.17 - def __repr__(self):
8.18 - return "Block(%r, location=%r)" % (id(self), self.location)
8.19 -
8.20 - def as_raw(self, objtable, paramtable):
8.21 - for i, item in enumerate(self.code):
8.22 - if hasattr(item, "location"):
8.23 - item.location = location + i
8.24 - return self.code
8.25 -
8.26 -# Program data representations.
8.27 -
8.28 -class DataObject:
8.29 -
8.30 - "A representation of a raw program data object."
8.31 -
8.32 - def __init__(self, classcode, attrcode, codeaddr, codedetails, instance, name, funccode=None):
8.33 - self.classcode = classcode
8.34 - self.attrcode = attrcode
8.35 - self.codeaddr = codeaddr
8.36 - self.codedetails = codedetails
8.37 - self.instance = instance
8.38 - self.name = name
8.39 - self.funccode = funccode
8.40 -
8.41 - def __repr__(self):
8.42 - return "%r # %s" % ((self.classcode, self.attrcode, self.codeaddr, self.codedetails, self.instance, self.funccode), self.name)
8.43 -
8.44 -# Inspection representations.
8.45 -
8.46 -class AtLeast:
8.47 -
8.48 - "A special representation for numbers of a given value or greater."
8.49 -
8.50 - def __init__(self, count):
8.51 - self.count = count
8.52 -
8.53 - def __eq__(self, other):
8.54 - return 0
8.55 -
8.56 - __lt__ = __le__ = __eq__
8.57 -
8.58 - def __ne__(self, other):
8.59 - return 1
8.60 -
8.61 - def __gt__(self, other):
8.62 - if isinstance(other, AtLeast):
8.63 - return 0
8.64 - else:
8.65 - return self.count > other
8.66 -
8.67 - def __ge__(self, other):
8.68 - if isinstance(other, AtLeast):
8.69 - return 0
8.70 - else:
8.71 - return self.count >= other
8.72 -
8.73 - def __iadd__(self, other):
8.74 - if isinstance(other, AtLeast):
8.75 - self.count += other.count
8.76 - else:
8.77 - self.count += other
8.78 - return self
8.79 -
8.80 - def __radd__(self, other):
8.81 - if isinstance(other, AtLeast):
8.82 - return AtLeast(self.count + other.count)
8.83 - else:
8.84 - return AtLeast(self.count + other)
8.85 -
8.86 - def __repr__(self):
8.87 - return "AtLeast(%r)" % self.count
8.88 -
8.89 -class Naming:
8.90 -
8.91 - "A mix-in providing naming conveniences."
8.92 -
8.93 - def full_name(self):
8.94 - if self.name is not None:
8.95 - return self.parent.full_name() + "." + self.name
8.96 - else:
8.97 - return self.parent.full_name()
8.98 -
8.99 -class Undefined:
8.100 -
8.101 - "A special class of undefined values."
8.102 -
8.103 - pass
8.104 -
8.105 # Useful data.
8.106
8.107 comparison_methods = {
9.1 --- a/micropython/data.py Tue Apr 07 00:57:04 2009 +0200
9.2 +++ b/micropython/data.py Mon Apr 20 01:50:00 2009 +0200
9.3 @@ -44,7 +44,7 @@
9.4 where each such object is defined.
9.5 """
9.6
9.7 -from micropython.common import *
9.8 +from micropython.program import DataObject
9.9
9.10 def shortrepr(obj):
9.11 if obj is None:
9.12 @@ -52,8 +52,63 @@
9.13 else:
9.14 return obj.__shortrepr__()
9.15
9.16 +# Special representations.
9.17 +
9.18 +class AtLeast:
9.19 +
9.20 + "A special representation for numbers of a given value or greater."
9.21 +
9.22 + def __init__(self, count):
9.23 + self.count = count
9.24 +
9.25 + def __eq__(self, other):
9.26 + return 0
9.27 +
9.28 + __lt__ = __le__ = __eq__
9.29 +
9.30 + def __ne__(self, other):
9.31 + return 1
9.32 +
9.33 + def __gt__(self, other):
9.34 + if isinstance(other, AtLeast):
9.35 + return 0
9.36 + else:
9.37 + return self.count > other
9.38 +
9.39 + def __ge__(self, other):
9.40 + if isinstance(other, AtLeast):
9.41 + return 0
9.42 + else:
9.43 + return self.count >= other
9.44 +
9.45 + def __iadd__(self, other):
9.46 + if isinstance(other, AtLeast):
9.47 + self.count += other.count
9.48 + else:
9.49 + self.count += other
9.50 + return self
9.51 +
9.52 + def __radd__(self, other):
9.53 + if isinstance(other, AtLeast):
9.54 + return AtLeast(self.count + other.count)
9.55 + else:
9.56 + return AtLeast(self.count + other)
9.57 +
9.58 + def __repr__(self):
9.59 + return "AtLeast(%r)" % self.count
9.60 +
9.61 # Mix-ins and abstract classes.
9.62
9.63 +class Naming:
9.64 +
9.65 + "A mix-in providing naming conveniences."
9.66 +
9.67 + def full_name(self):
9.68 + if self.name is not None:
9.69 + return self.parent.full_name() + "." + self.name
9.70 + else:
9.71 + return self.parent.full_name()
9.72 +
9.73 class NamespaceDict:
9.74
9.75 "A mix-in providing dictionary methods."
10.1 --- a/micropython/graph.py Tue Apr 07 00:57:04 2009 +0200
10.2 +++ b/micropython/graph.py Mon Apr 20 01:50:00 2009 +0200
10.3 @@ -95,7 +95,7 @@
10.4 print >>out, "}"
10.5
10.6 def get_name(obj):
10.7 - if isinstance(obj, micropython.common.Naming):
10.8 + if isinstance(obj, micropython.data.Naming):
10.9 return obj.full_name()
10.10 elif isinstance(obj, micropython.data.Const):
10.11 return obj.value_type_name()
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/micropython/program.py Mon Apr 20 01:50:00 2009 +0200
11.3 @@ -0,0 +1,40 @@
11.4 +#!/usr/bin/env python
11.5 +
11.6 +"""
11.7 +Program code and data representations.
11.8 +"""
11.9 +
11.10 +class Block:
11.11 +
11.12 + "A code block."
11.13 +
11.14 + def __init__(self):
11.15 + self.code = []
11.16 + self.location = None
11.17 +
11.18 + def __repr__(self):
11.19 + return "Block(%r, location=%r)" % (id(self), self.location)
11.20 +
11.21 + def as_raw(self, objtable, paramtable):
11.22 + for i, item in enumerate(self.code):
11.23 + if hasattr(item, "location"):
11.24 + item.location = location + i
11.25 + return self.code
11.26 +
11.27 +class DataObject:
11.28 +
11.29 + "A representation of a raw program data object."
11.30 +
11.31 + def __init__(self, classcode, attrcode, codeaddr, codedetails, instance, name, funccode=None):
11.32 + self.classcode = classcode
11.33 + self.attrcode = attrcode
11.34 + self.codeaddr = codeaddr
11.35 + self.codedetails = codedetails
11.36 + self.instance = instance
11.37 + self.name = name
11.38 + self.funccode = funccode
11.39 +
11.40 + def __repr__(self):
11.41 + return "%r # %s" % ((self.classcode, self.attrcode, self.codeaddr, self.codedetails, self.instance, self.funccode), self.name)
11.42 +
11.43 +# vim: tabstop=4 expandtab shiftwidth=4
12.1 --- a/micropython/rsvp.py Tue Apr 07 00:57:04 2009 +0200
12.2 +++ b/micropython/rsvp.py Mon Apr 20 01:50:00 2009 +0200
12.3 @@ -20,7 +20,7 @@
12.4 """
12.5
12.6 from micropython.data import Attr, Const
12.7 -from micropython.common import Block
12.8 +from micropython.program import Block
12.9
12.10 def name(attr):
12.11 if isinstance(attr, Attr):
13.1 --- a/rsvp.py Tue Apr 07 00:57:04 2009 +0200
13.2 +++ b/rsvp.py Mon Apr 20 01:50:00 2009 +0200
13.3 @@ -52,7 +52,7 @@
13.4 current callable
13.5 """
13.6
13.7 -from micropython.common import DataObject # for creating "nice" new objects
13.8 +from micropython.program import DataObject # for creating "nice" new objects
13.9
13.10 class IllegalInstruction(Exception):
13.11 pass