1.1 --- a/docs/concepts.txt Mon Jun 08 00:49:37 2009 +0200
1.2 +++ b/docs/concepts.txt Fri Jun 12 22:03:56 2009 +0200
1.3 @@ -212,7 +212,10 @@
1.4 The locations stored in table/list elements are for instance attributes
1.5 relative to the location of the instance, whereas those for class attributes
1.6 and modules are absolute addresses (although these could also be changed to
1.7 -object-relative locations).
1.8 +object-relative locations). Thus, each occupied table cell has the following
1.9 +structure:
1.10 +
1.11 + attrcode, uses-absolute-address, address (or location)
1.12
1.13 Objects and Structures
1.14 ======================
1.15 @@ -247,10 +250,12 @@
1.16
1.17 Used to test instances for membership of classes (or descendants of classes).
1.18
1.19 -Since, in traditional Python, classes are only ever instances of the "type"
1.20 -built-in class, support for testing such a relationship directly has been
1.21 +Since, in traditional Python, classes are only ever instances of some generic
1.22 +built-in type, support for testing such a relationship directly has been
1.23 removed and the attrcode is not specified for classes: the presence of an
1.24 -attrcode indicates that a given object is an instance.
1.25 +attrcode indicates that a given object is an instance. In addition, support
1.26 +has also been removed for testing modules in the same way, meaning that the
1.27 +attrcode is also not specified for modules.
1.28
1.29 See the "Testing Instance Compatibility with Classes (Attrcode)" section below
1.30 for details of attrcodes.
2.1 --- a/micropython/__init__.py Mon Jun 08 00:49:37 2009 +0200
2.2 +++ b/micropython/__init__.py Fri Jun 12 22:03:56 2009 +0200
2.3 @@ -193,7 +193,7 @@
2.4 # Append the module top-level code to the image.
2.5
2.6 else:
2.7 - code = trans.get_module_code(final=(module is last_module))
2.8 + code = trans.get_module_code()
2.9 self.code += code
2.10 pos += len(code)
2.11
3.1 --- a/micropython/ast.py Mon Jun 08 00:49:37 2009 +0200
3.2 +++ b/micropython/ast.py Fri Jun 12 22:03:56 2009 +0200
3.3 @@ -115,11 +115,10 @@
3.4
3.5 self.optimiser.reset()
3.6
3.7 - def get_module_code(self, final=0):
3.8 + def get_module_code(self):
3.9
3.10 """
3.11 - Return the top-level module code including finalising code if 'final' is
3.12 - set to a true value.
3.13 + Return the top-level module code.
3.14 """
3.15
3.16 self.unit = self.module
3.17 @@ -133,7 +132,7 @@
3.18
3.19 # Finish off the translated program if appropriate.
3.20
3.21 - if final:
3.22 + if self.module.name == "__main__":
3.23 self.new_op(Return())
3.24
3.25 self.unit.temp_usage = self.max_temp_position + 1
4.1 --- a/micropython/data.py Mon Jun 08 00:49:37 2009 +0200
4.2 +++ b/micropython/data.py Fri Jun 12 22:03:56 2009 +0200
4.3 @@ -352,8 +352,14 @@
4.4
4.5 self.context_values.update(context_values)
4.6
4.7 - def is_class_attribute(self):
4.8 - return isinstance(self.parent, Class)
4.9 + def is_static_attribute(self):
4.10 +
4.11 + """
4.12 + Return whether this attribute is defined on a fixed/static object such
4.13 + as a class or a module.
4.14 + """
4.15 +
4.16 + return isinstance(self.parent, (Class, Module))
4.17
4.18 def defined_within_hierarchy(self):
4.19
4.20 @@ -1222,7 +1228,7 @@
4.21 return [
4.22 DataObject(
4.23 objtable.as_list().get_code(self.full_name()),
4.24 - None, # NOTE: module name not used as an attribute, but should be instance
4.25 + None, # modules treated like classes
4.26 None,
4.27 self.full_name(),
4.28 len(self.module_attributes()) + 1 # size
5.1 --- a/micropython/table.py Mon Jun 08 00:49:37 2009 +0200
5.2 +++ b/micropython/table.py Fri Jun 12 22:03:56 2009 +0200
5.3 @@ -186,7 +186,7 @@
5.4
5.5 # Attribute index/code, attribute type, location/position.
5.6
5.7 - return (attr_index, attr.is_class_attribute(), position)
5.8 + return (attr_index, attr.is_static_attribute(), position)
5.9
5.10 class ParameterList(List):
5.11
6.1 --- a/rsvp.py Mon Jun 08 00:49:37 2009 +0200
6.2 +++ b/rsvp.py Fri Jun 12 22:03:56 2009 +0200
6.3 @@ -461,10 +461,10 @@
6.4 element = self.objlist[data.classcode + self.operand]
6.5
6.6 if element is not None:
6.7 - attr_index, class_attr, offset = element
6.8 + attr_index, static_attr, offset = element
6.9 if attr_index == self.operand:
6.10 - if class_attr:
6.11 - self.value = self.load(offset) # offset is address of class attribute
6.12 + if static_attr:
6.13 + self.value = self.load(offset) # offset is address of class/module attribute
6.14 else:
6.15 self.value = self.load(ref + offset)
6.16 return
6.17 @@ -480,11 +480,11 @@
6.18 element = self.objlist[data.classcode + self.operand]
6.19
6.20 if element is not None:
6.21 - attr_index, class_attr, offset = element
6.22 + attr_index, static_attr, offset = element
6.23 if attr_index == self.operand:
6.24 - if class_attr:
6.25 - loaded_context, loaded_ref = self.load(offset) # offset is address of class attribute
6.26 - if data.attrcode is None: # absent attrcode == class
6.27 + if static_attr:
6.28 + loaded_context, loaded_ref = self.load(offset) # offset is address of class/module attribute
6.29 + if data.attrcode is None: # absent attrcode == class/module
6.30 self.value = loaded_context, loaded_ref
6.31 else:
6.32 self.value = self._LoadAddressContextCond(loaded_context, loaded_ref, inst_ref)
6.33 @@ -501,9 +501,9 @@
6.34 element = self.objlist[data.classcode + self.operand]
6.35
6.36 if element is not None:
6.37 - attr_index, class_attr, offset = element
6.38 + attr_index, static_attr, offset = element
6.39 if attr_index == self.operand:
6.40 - if class_attr:
6.41 + if static_attr:
6.42 self.exception = self._MakeObject(2, self.type_error_instance)
6.43 return self.RaiseException()
6.44 else:
6.45 @@ -715,7 +715,7 @@
6.46
6.47 # Insist on instance vs. class.
6.48
6.49 - if data.attrcode is None: # absent attrcode == class
6.50 + if data.attrcode is None: # absent attrcode == class/module
6.51 return 0
6.52
6.53 if target_data.attrcode is not None: # present attrcode == instance
6.54 @@ -726,7 +726,7 @@
6.55 element = self.objlist[target_data.classcode + data.attrcode]
6.56
6.57 if element is not None:
6.58 - attr_index, class_attr, offset = element
6.59 + attr_index, static_attr, offset = element
6.60 return attr_index == data.attrcode
6.61 else:
6.62 return 0
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/tests/failure/importer_module_attribute_assignment.py Fri Jun 12 22:03:56 2009 +0200
7.3 @@ -0,0 +1,15 @@
7.4 +#!/usr/bin/env python
7.5 +
7.6 +import imported
7.7 +
7.8 +class C: # hack: make an attribute called y known to the system
7.9 + y = None # hack: this prevents compilation errors with the statements
7.10 + # hack: below
7.11 +
7.12 +n = None
7.13 +n = imported
7.14 +n.a = 1 # not detected due to reassignment of n
7.15 +n.y = 2 # not detected due to reassignment of n
7.16 +n.y = 3 # not detected due to reassignment of n
7.17 +
7.18 +# vim: tabstop=4 expandtab shiftwidth=4
8.1 --- a/tests/importer.py Mon Jun 08 00:49:37 2009 +0200
8.2 +++ b/tests/importer.py Fri Jun 12 22:03:56 2009 +0200
8.3 @@ -2,20 +2,10 @@
8.4
8.5 import imported
8.6
8.7 -imported.attr # cannot assign to this
8.8 +result_123 = imported.attr # cannot assign to this
8.9
8.10 m = imported
8.11 -imported.a # cannot assign to this
8.12 -m.a # cannot assign to this (m is known)
8.13 -
8.14 -class C: # hack: make an attribute called y known to the system
8.15 - y = None # hack: this prevents compilation errors with the statements
8.16 - # hack: below
8.17 -
8.18 -n = None
8.19 -n = imported
8.20 -n.a = 1 # not detected due to reassignment of n
8.21 -n.y = 2 # not detected due to reassignment of n
8.22 -n.y = 3 # not detected due to reassignment of n
8.23 +result1_10 = imported.a # can only read from the attribute, not replace it
8.24 +result2_10 = m.a # can only read from the attribute (m is known)
8.25
8.26 # vim: tabstop=4 expandtab shiftwidth=4
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/tests/importer_uncertain.py Fri Jun 12 22:03:56 2009 +0200
9.3 @@ -0,0 +1,11 @@
9.4 +#!/usr/bin/env python
9.5 +
9.6 +import imported
9.7 +
9.8 +m = None
9.9 +m = imported
9.10 +
9.11 +result_123 = m.attr
9.12 +result_10 = m.a
9.13 +
9.14 +# vim: tabstop=4 expandtab shiftwidth=4