1.1 --- a/README.txt Sun Aug 17 20:46:49 2008 +0200
1.2 +++ b/README.txt Mon Aug 18 01:40:18 2008 +0200
1.3 @@ -9,6 +9,10 @@
1.4 Instance attributes are defined only by assignments to attributes of self
1.5 within __init__ methods.
1.6
1.7 +(These restrictions apply because such attributes are thus explicitly
1.8 +declared. Module and class attributes can also be finalised in this way in
1.9 +order to permit certain optimisations.)
1.10 +
1.11 Potential Restrictions
1.12 ----------------------
1.13
2.1 --- a/docs/invocation.txt Sun Aug 17 20:46:49 2008 +0200
2.2 +++ b/docs/invocation.txt Mon Aug 18 01:40:18 2008 +0200
2.3 @@ -143,3 +143,13 @@
2.4 f(obj, 1, 2) # no restrictions on obj
2.5 obj.m(1, 2) # f(obj, 1, 2)
2.6 C.m(obj, 1, 2) # f(obj "assert isinstance(obj, C)", 1, 2)
2.7 +
2.8 +Context propagation:
2.9 +
2.10 + fn = C.m # has context C
2.11 + fn(obj, 1, 2) # non-instance context -> explicit context required
2.12 + # must perform isinstance(obj, C)
2.13 + fn = c.m # table entry for m on C -> replace context
2.14 + # gives context c
2.15 + fn(1, 2) # instance context -> no explicit context required
2.16 + # context c inserted in call
3.1 --- a/docs/structures.txt Sun Aug 17 20:46:49 2008 +0200
3.2 +++ b/docs/structures.txt Mon Aug 18 01:40:18 2008 +0200
3.3 @@ -13,8 +13,8 @@
3.4 object context
3.5 reference reference
3.6
3.7 -Acquiring Values
3.8 -----------------
3.9 +Values and Contexts
3.10 +-------------------
3.11
3.12 Values are acquired through name lookups and attribute access, yielding
3.13 the appropriate object reference together with a context reference as
3.14 @@ -61,7 +61,10 @@
3.15 constant's class hierarchy)
3.16
3.17 LoadAddressContext Override loaded context with a
3.18 - predetermined object
3.19 + predetermined object (provided
3.20 + that the object and context are
3.21 + compatible, which can be tested at
3.22 + compile-time)
3.23
3.24 LoadAttr Load attribute from Attributes with null contexts or
3.25 instance contexts compatible with the
3.26 @@ -85,14 +88,20 @@
3.27 * Since only class-originating attributes may cause context overriding, and
3.28 since class attributes may only be defined within class definitions, the
3.29 attributes whose context may be modified should be known at compile-time.
3.30 + (These will be those attributes whose context agrees with their parent
3.31 + class.)
3.32
3.33 * By recording a special context value for attributes whose context can be
3.34 overridden, this value can be tested efficiently at run-time where the
3.35 - appropriate conditions are satisfied.
3.36 + appropriate conditions are satisfied. (This special context value or
3.37 + indicator will be present in the object table record for the attribute.)
3.38
3.39 * It should be possible to move the instance compatibility condition testing
3.40 to compile-time by testing the compatibility of the origin of an attribute
3.41 - with the class on which it is stored.
3.42 + with the class on which it is stored. However, some compatibility testing
3.43 + will still be required if invoking methods via classes, since the instance
3.44 + will be specified in the argument list instead of being presented in an
3.45 + attribute lookup instruction.
3.46
3.47 Storing Values
3.48 --------------
4.1 --- a/micropython/__init__.py Sun Aug 17 20:46:49 2008 +0200
4.2 +++ b/micropython/__init__.py Mon Aug 18 01:40:18 2008 +0200
4.3 @@ -71,6 +71,7 @@
4.4
4.5 self.objtable = None
4.6 self.paramtable = None
4.7 + self.clstable = None
4.8
4.9 # Constant records.
4.10
4.11 @@ -113,6 +114,7 @@
4.12
4.13 objtable = self.get_object_table()
4.14 paramtable = self.get_parameter_table()
4.15 + clstable = self.get_class_table()
4.16
4.17 image = []
4.18
4.19 @@ -235,6 +237,21 @@
4.20
4.21 return self.objtable
4.22
4.23 + def get_class_table(self):
4.24 +
4.25 + "Return a table with details of class compatibility."
4.26 +
4.27 + if self.clstable is None:
4.28 + t = self.clstable = micropython.table.Table()
4.29 + for module in self.get_modules():
4.30 + for obj in module.all_objects:
4.31 + if isinstance(obj, micropython.inspect.Class):
4.32 + compatible = [obj] + obj.descendants
4.33 + compatible_dict = dict([(cls.full_name(), cls) for cls in compatible])
4.34 + t.add(obj.full_name(), compatible_dict)
4.35 +
4.36 + return self.clstable
4.37 +
4.38 def get_parameter_table(self):
4.39
4.40 "Return a table with details of parameters for functions and methods."
5.1 --- a/micropython/ast.py Sun Aug 17 20:46:49 2008 +0200
5.2 +++ b/micropython/ast.py Mon Aug 18 01:40:18 2008 +0200
5.3 @@ -67,6 +67,7 @@
5.4 self.importer = importer
5.5 self.objtable = self.importer.get_object_table()
5.6 self.paramtable = self.importer.get_parameter_table()
5.7 + self.clstable = self.importer.get_class_table()
5.8 self.builtins = self.importer.modules.get("__builtins__")
5.9
5.10 # Desired optimisations.
5.11 @@ -280,6 +281,13 @@
5.12 op = self.code.pop()
5.13 self.active = None
5.14
5.15 + def remove_active_value(self):
5.16 +
5.17 + "Remove the value-providing active instruction if appropriate."
5.18 +
5.19 + if self.active_value is self.active:
5.20 + self.remove_op()
5.21 +
5.22 def replace_op(self, op):
5.23
5.24 "Replace the last added instruction with 'op'."
5.25 @@ -349,7 +357,9 @@
5.26 StoreTemp, StoreFrame, StoreResult, StoreException, # as the value being stored
5.27 LoadAddressContext, LoadAttr, LoadAttrIndex, # as the object being referenced
5.28 StoreAttr, StoreAttrIndex, StoreCallable, # as the object being referenced
5.29 - TestIdentity, CheckSelf # as one of the operands
5.30 + TestIdentity, CheckSelf, # as one of the operands
5.31 + LoadContext, # as the object providing the result
5.32 + JumpWithFrame # as the target
5.33 ))
5.34
5.35 def _is_resultant_no_operation(self, instruction):
5.36 @@ -554,9 +564,8 @@
5.37 if self._should_optimise_temp_storage() and \
5.38 self._have_temp_compatible_access():
5.39
5.40 - last = self.last_op()
5.41 - self.remove_op()
5.42 - return last
5.43 + self.remove_active_value()
5.44 + return self.active
5.45 else:
5.46 return self.get_temp()
5.47
5.48 @@ -570,9 +579,7 @@
5.49 self._have_simple_input() and \
5.50 self._is_simple_input_user(instruction):
5.51
5.52 - if self.active_value is self.active:
5.53 - self.remove_op()
5.54 -
5.55 + self.remove_active_value()
5.56 instruction.input = self.active_value
5.57
5.58 def _optimise_away_no_operations(self, instruction):
5.59 @@ -593,8 +600,8 @@
5.60
5.61 "Discard results which will not be used."
5.62
5.63 - if self._have_input():
5.64 - self.remove_op()
5.65 + if self._have_simple_input():
5.66 + self.remove_active_value()
5.67
5.68 # Visitor methods.
5.69
6.1 --- a/micropython/rsvp.py Sun Aug 17 20:46:49 2008 +0200
6.2 +++ b/micropython/rsvp.py Mon Aug 18 01:40:18 2008 +0200
6.3 @@ -26,7 +26,7 @@
6.4 new_code = []
6.5 for item in code:
6.6 if isinstance(item, Attr):
6.7 - new_code.append((None, item.value and item.value.location)) # no useful context is provided
6.8 + new_code.append((item.context and item.context.location, item.value and item.value.location)) # no useful context is provided
6.9 else:
6.10 new_code.append(item)
6.11 return new_code
7.1 --- a/test.py Sun Aug 17 20:46:49 2008 +0200
7.2 +++ b/test.py Mon Aug 18 01:40:18 2008 +0200
7.3 @@ -68,5 +68,6 @@
7.4 i.vacuum()
7.5 ot = i.get_object_table()
7.6 pt = i.get_parameter_table()
7.7 + ct = i.get_class_table()
7.8
7.9 # vim: tabstop=4 expandtab shiftwidth=4
9.1 --- a/tests/subclass.py Sun Aug 17 20:46:49 2008 +0200
9.2 +++ b/tests/subclass.py Mon Aug 18 01:40:18 2008 +0200
9.3 @@ -16,7 +16,7 @@
9.4 A.a(self)
9.5
9.6 def b(self):
9.7 - pass
9.8 + self.a()
9.9
9.10 def __init__(self, x, y):
9.11 self.x = x