# HG changeset patch # User Paul Boddie # Date 1240185000 -7200 # Node ID 657d0220c45f475e24e9f2b182ba4b1c8385ba03 # Parent b0e016b1312054a66ced35beab61a0f678ac46ea Reorganised the documentation some more, noting documents in the index.txt file. Moved non-common classes from the common module, making a new program module for program-related classes. diff -r b0e016b13120 -r 657d0220c45f README.txt --- a/README.txt Tue Apr 07 00:57:04 2009 +0200 +++ b/README.txt Mon Apr 20 01:50:00 2009 +0200 @@ -205,10 +205,3 @@ could be costly. Another less ambitious solution might only involve the optimisation of such internal method calls if an unambiguous target can be resolved. - -Optimising Function Invocations -------------------------------- - -Where an attribute value is itself regarded as constant and is a function, -knowledge about the parameters of the function can be employed to optimise the -preparation of the invocation frame. diff -r b0e016b13120 -r 657d0220c45f docs/concepts.txt --- a/docs/concepts.txt Tue Apr 07 00:57:04 2009 +0200 +++ b/docs/concepts.txt Mon Apr 20 01:50:00 2009 +0200 @@ -1,12 +1,33 @@ Concepts ======== +This document describes the underlying concepts employed in micropython. + + * Namespaces and attribute definition * Contexts and values * Tables, attributes and lookups * Objects and structures * Parameters and lookups * Instantiation +Namespaces and Attribute Definition +=================================== + +Namespaces are any objects which can retain attributes. + + * Module attributes are defined either at the module level or by global + statements. + * Class attributes are defined only within class statements. + * Instance attributes are defined only by assignments to attributes of self + within __init__ methods. + +These restrictions apply because such attributes are thus explicitly declared, +permitting the use of tables (described below). Module and class attributes +can also be finalised in this way in order to permit certain optimisations. + +See rejected.txt for complicating mechanisms which could be applied to +mitigate the effects of these restrictions on optimisations. + Contexts and Values =================== @@ -56,10 +77,9 @@ LoadConst Load class, function, Combine null context with module, constant loaded object - LoadAddress Load attribute from Preserve or override stored - LoadAddressContext class, module, context (as described in - LoadAttr instance assignment.txt) - LoadAttrIndex + LoadAddress* Load attribute from Preserve or override stored + LoadAttr* class, module, context (as described in + instance assignment.txt) In order to comply with traditional Python behaviour, contexts may or may not represent the object from which an attribute has been acquired. diff -r b0e016b13120 -r 657d0220c45f docs/evaluation.txt --- a/docs/evaluation.txt Tue Apr 07 00:57:04 2009 +0200 +++ b/docs/evaluation.txt Mon Apr 20 01:50:00 2009 +0200 @@ -46,6 +46,7 @@ ___ ___ ___ --> 3 ___ --> 1 1 | 1 ___ | ___ --> 2 | 2 + | | | 1 ----------- 2 ----------- 3 ----------- Conceptually, the frame can be considered as a collection of attributes, as diff -r b0e016b13120 -r 657d0220c45f docs/index.txt --- a/docs/index.txt Tue Apr 07 00:57:04 2009 +0200 +++ b/docs/index.txt Mon Apr 20 01:50:00 2009 +0200 @@ -1,4 +1,12 @@ Documentation Index =================== -concepts.txt +concepts.txt An overview of the concepts employed in micropython + +assignment.txt A quick tour of assignment semantics +evaluation.txt An overview of evaluation result storage and invocation frames +invocation.txt A quick tour of invocation semantics + +optimisations.txt A table of optimisations currently employed in micropython +rationale.txt A presentation of ideas and objectives +related.txt Related work diff -r b0e016b13120 -r 657d0220c45f docs/namespaces.txt --- a/docs/namespaces.txt Tue Apr 07 00:57:04 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -Namespace Definition -==================== - -Module attributes are defined either at the module level or by global -statements. - -Class attributes are defined only within class statements. - -Instance attributes are defined only by assignments to attributes of self -within __init__ methods. - -(These restrictions apply because such attributes are thus explicitly -declared. Module and class attributes can also be finalised in this way in -order to permit certain optimisations.) - -Potential Restrictions ----------------------- - -Names of classes and functions could be restricted to only refer to those -objects within the same namespace. If redefinition were to occur, or if -multiple possibilities were present, these restrictions could be moderated as -follows: - - * Classes assigned to the same name could provide the union of their - attributes. This would, however, cause a potential collision of attribute - definitions such as methods. - - * Functions, if they share compatible signatures, could share parameter list - definitions. - -It is easier, however, to regard multiply defined classes and functions as -non-constant and to either disallow optimisations or to actually prevent the -program describing them from compiling. diff -r b0e016b13120 -r 657d0220c45f docs/rejected.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/rejected.txt Mon Apr 20 01:50:00 2009 +0200 @@ -0,0 +1,19 @@ +Namespace Definitions +===================== + +Attributes can be redefined in modules and classes, but this eliminates much +of the potential for optimisation. However, names of classes and functions +could be restricted to only refer to the same kinds of objects within the same +namespace. If redefinition were to occur, or if multiple possibilities were +present, these restrictions could be moderated as follows: + + * Classes assigned to the same name could provide the union of their + attributes. This would, however, cause a potential collision of attribute + definitions such as methods. + + * Functions, if they share compatible signatures, could share parameter list + definitions. + +It is easier, however, to regard multiply defined classes and functions as +non-constant and to either disallow optimisations or to actually prevent the +program describing them from compiling. diff -r b0e016b13120 -r 657d0220c45f micropython/__init__.py --- a/micropython/__init__.py Tue Apr 07 00:57:04 2009 +0200 +++ b/micropython/__init__.py Mon Apr 20 01:50:00 2009 +0200 @@ -40,6 +40,7 @@ """ from micropython.common import * +from micropython.program import Block import micropython.ast import micropython.data import micropython.opt diff -r b0e016b13120 -r 657d0220c45f micropython/common.py --- a/micropython/common.py Tue Apr 07 00:57:04 2009 +0200 +++ b/micropython/common.py Mon Apr 20 01:50:00 2009 +0200 @@ -71,104 +71,6 @@ pass -# Program code representations. - -class Block: - - "A code block." - - def __init__(self): - self.code = [] - self.location = None - - def __repr__(self): - return "Block(%r, location=%r)" % (id(self), self.location) - - def as_raw(self, objtable, paramtable): - for i, item in enumerate(self.code): - if hasattr(item, "location"): - item.location = location + i - return self.code - -# Program data representations. - -class DataObject: - - "A representation of a raw program data object." - - def __init__(self, classcode, attrcode, codeaddr, codedetails, instance, name, funccode=None): - self.classcode = classcode - self.attrcode = attrcode - self.codeaddr = codeaddr - self.codedetails = codedetails - self.instance = instance - self.name = name - self.funccode = funccode - - def __repr__(self): - return "%r # %s" % ((self.classcode, self.attrcode, self.codeaddr, self.codedetails, self.instance, self.funccode), self.name) - -# Inspection representations. - -class AtLeast: - - "A special representation for numbers of a given value or greater." - - def __init__(self, count): - self.count = count - - def __eq__(self, other): - return 0 - - __lt__ = __le__ = __eq__ - - def __ne__(self, other): - return 1 - - def __gt__(self, other): - if isinstance(other, AtLeast): - return 0 - else: - return self.count > other - - def __ge__(self, other): - if isinstance(other, AtLeast): - return 0 - else: - return self.count >= other - - def __iadd__(self, other): - if isinstance(other, AtLeast): - self.count += other.count - else: - self.count += other - return self - - def __radd__(self, other): - if isinstance(other, AtLeast): - return AtLeast(self.count + other.count) - else: - return AtLeast(self.count + other) - - def __repr__(self): - return "AtLeast(%r)" % self.count - -class Naming: - - "A mix-in providing naming conveniences." - - def full_name(self): - if self.name is not None: - return self.parent.full_name() + "." + self.name - else: - return self.parent.full_name() - -class Undefined: - - "A special class of undefined values." - - pass - # Useful data. comparison_methods = { diff -r b0e016b13120 -r 657d0220c45f micropython/data.py --- a/micropython/data.py Tue Apr 07 00:57:04 2009 +0200 +++ b/micropython/data.py Mon Apr 20 01:50:00 2009 +0200 @@ -44,7 +44,7 @@ where each such object is defined. """ -from micropython.common import * +from micropython.program import DataObject def shortrepr(obj): if obj is None: @@ -52,8 +52,63 @@ else: return obj.__shortrepr__() +# Special representations. + +class AtLeast: + + "A special representation for numbers of a given value or greater." + + def __init__(self, count): + self.count = count + + def __eq__(self, other): + return 0 + + __lt__ = __le__ = __eq__ + + def __ne__(self, other): + return 1 + + def __gt__(self, other): + if isinstance(other, AtLeast): + return 0 + else: + return self.count > other + + def __ge__(self, other): + if isinstance(other, AtLeast): + return 0 + else: + return self.count >= other + + def __iadd__(self, other): + if isinstance(other, AtLeast): + self.count += other.count + else: + self.count += other + return self + + def __radd__(self, other): + if isinstance(other, AtLeast): + return AtLeast(self.count + other.count) + else: + return AtLeast(self.count + other) + + def __repr__(self): + return "AtLeast(%r)" % self.count + # Mix-ins and abstract classes. +class Naming: + + "A mix-in providing naming conveniences." + + def full_name(self): + if self.name is not None: + return self.parent.full_name() + "." + self.name + else: + return self.parent.full_name() + class NamespaceDict: "A mix-in providing dictionary methods." diff -r b0e016b13120 -r 657d0220c45f micropython/graph.py --- a/micropython/graph.py Tue Apr 07 00:57:04 2009 +0200 +++ b/micropython/graph.py Mon Apr 20 01:50:00 2009 +0200 @@ -95,7 +95,7 @@ print >>out, "}" def get_name(obj): - if isinstance(obj, micropython.common.Naming): + if isinstance(obj, micropython.data.Naming): return obj.full_name() elif isinstance(obj, micropython.data.Const): return obj.value_type_name() diff -r b0e016b13120 -r 657d0220c45f micropython/program.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/micropython/program.py Mon Apr 20 01:50:00 2009 +0200 @@ -0,0 +1,40 @@ +#!/usr/bin/env python + +""" +Program code and data representations. +""" + +class Block: + + "A code block." + + def __init__(self): + self.code = [] + self.location = None + + def __repr__(self): + return "Block(%r, location=%r)" % (id(self), self.location) + + def as_raw(self, objtable, paramtable): + for i, item in enumerate(self.code): + if hasattr(item, "location"): + item.location = location + i + return self.code + +class DataObject: + + "A representation of a raw program data object." + + def __init__(self, classcode, attrcode, codeaddr, codedetails, instance, name, funccode=None): + self.classcode = classcode + self.attrcode = attrcode + self.codeaddr = codeaddr + self.codedetails = codedetails + self.instance = instance + self.name = name + self.funccode = funccode + + def __repr__(self): + return "%r # %s" % ((self.classcode, self.attrcode, self.codeaddr, self.codedetails, self.instance, self.funccode), self.name) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r b0e016b13120 -r 657d0220c45f micropython/rsvp.py --- a/micropython/rsvp.py Tue Apr 07 00:57:04 2009 +0200 +++ b/micropython/rsvp.py Mon Apr 20 01:50:00 2009 +0200 @@ -20,7 +20,7 @@ """ from micropython.data import Attr, Const -from micropython.common import Block +from micropython.program import Block def name(attr): if isinstance(attr, Attr): diff -r b0e016b13120 -r 657d0220c45f rsvp.py --- a/rsvp.py Tue Apr 07 00:57:04 2009 +0200 +++ b/rsvp.py Mon Apr 20 01:50:00 2009 +0200 @@ -52,7 +52,7 @@ current callable """ -from micropython.common import DataObject # for creating "nice" new objects +from micropython.program import DataObject # for creating "nice" new objects class IllegalInstruction(Exception): pass