# HG changeset patch # User Paul Boddie # Date 1372719064 -7200 # Node ID 0bd17ac3005e72e7caf323367ea408359ed52dd9 # Parent 0f4bbb3b9c2fab7d2a975d7183fbd97c680f5724 Removed location/image-related information. Ordered the attributes generated in syspython. Added a method for getting a list of positioned instance attributes. diff -r 0f4bbb3b9c2f -r 0bd17ac3005e docs/concepts.txt --- a/docs/concepts.txt Mon Jul 01 12:57:30 2013 +0200 +++ b/docs/concepts.txt Tue Jul 02 00:51:04 2013 +0200 @@ -308,11 +308,11 @@ This could be given instead as follows: - attrcode, is-class-or-module, location + attrcode, is-class-or-module-attribute, location -Since uses-absolute-address corresponds to is-class-or-module, and since there -is a need to test for classes and modules to prevent assignment to attributes -of such objects, this particular information is always required. +Since uses-absolute-address corresponds to is-class-or-module-attribute, and +since there is a need to test for classes and modules to prevent assignment to +attributes of such objects, this particular information is always required. The __class__ Attribute ----------------------- diff -r 0f4bbb3b9c2f -r 0bd17ac3005e micropython/basicdata.py --- a/micropython/basicdata.py Mon Jul 01 12:57:30 2013 +0200 +++ b/micropython/basicdata.py Tue Jul 02 00:51:04 2013 +0200 @@ -3,7 +3,7 @@ """ Fundamental program data structure abstractions. -Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 Paul Boddie +Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -70,10 +70,6 @@ def __init__(self): self.parent = None - # Image generation details. - - self.location = None - def __repr__(self): return "" @@ -109,10 +105,7 @@ return self.value def __repr__(self): - if self.location is not None: - return "Const(%r, location=%r)" % (self.value, self.location) - else: - return "Const(%r)" % self.value + return "Const(%r)" % self.value __shortrepr__ = __repr__ diff -r 0f4bbb3b9c2f -r 0bd17ac3005e micropython/data.py --- a/micropython/data.py Mon Jul 01 12:57:30 2013 +0200 +++ b/micropython/data.py Tue Jul 02 00:51:04 2013 +0200 @@ -582,17 +582,9 @@ self.reset_caches() - # Image generation details. - - self.location = None - self.code_location = None - self.code_body_location = None # corresponds to the instantiator + # Program-related details. self.instantiator = None - self.instance_template_location = None # for creating instances at run-time - - # Program-related details. - self.blocks = None self.temp_usage = 0 self.local_usage = 0 @@ -622,10 +614,7 @@ self.allattr_names = None # from allattr def __repr__(self): - if self.location is not None: - return "" % (shortrepr(self), self.location) - else: - return "" % shortrepr(self) + return "" % shortrepr(self) def __shortrepr__(self): return "%s.%s" % (shortrepr(self.parent), self.name) @@ -823,6 +812,14 @@ self.finalise_instance_attributes() return self.all_instattr + def instance_attributes_as_list(self): + + "Return instance-only attributes in a list ordered by position." + + attrs = self.instance_attributes().values() + attrs.sort(cmp=lambda x, y: cmp(x.position, y.position)) + return attrs + def finalise_instance_attributes(self): "Make sure that the instance attributes are fully defined." @@ -1042,9 +1039,6 @@ # Image generation details. self.dynamic = None - self.location = None - self.code_location = None - self.code_body_location = None # Program-related details. @@ -1076,12 +1070,7 @@ return l def __repr__(self): - if self.location is not None: - return "" % ( - shortrepr(self), self.location, self.code_location - ) - else: - return "" % shortrepr(self) + return "" % shortrepr(self) def __shortrepr__(self): return "%s.%s(%s)" % (shortrepr(self.parent), self.name, ", ".join(self.argnames)) @@ -1349,11 +1338,6 @@ self.keyword_names = set() - # Image generation details. - - self.location = None - self.code_location = None - # Program-related details. self.blocks = None @@ -1365,10 +1349,7 @@ return self.name def __repr__(self): - if self.location is not None: - return "" % (self.name, self.location) - else: - return "" % shortrepr(self) + return "" % shortrepr(self) def __shortrepr__(self): return self.name diff -r 0f4bbb3b9c2f -r 0bd17ac3005e micropython/report.py --- a/micropython/report.py Mon Jul 01 12:57:30 2013 +0200 +++ b/micropython/report.py Tue Jul 02 00:51:04 2013 +0200 @@ -568,8 +568,7 @@ # ...and instance attribute names in order... - attrs = obj.instance_attributes().values() - attrs.sort(cmp=lambda x, y: cmp(x.position, y.position)) + attrs = obj.instance_attributes_as_list() if attrs: for attr in attrs: @@ -582,8 +581,7 @@ # ...and class attribute names in order. - attrs = obj.class_attributes().values() - attrs.sort(cmp=lambda x, y: cmp(x.position, y.position)) + attrs = obj.attributes_as_list() if attrs: for attr in attrs: diff -r 0f4bbb3b9c2f -r 0bd17ac3005e micropython/syspython.py --- a/micropython/syspython.py Mon Jul 01 12:57:30 2013 +0200 +++ b/micropython/syspython.py Tue Jul 02 00:51:04 2013 +0200 @@ -96,7 +96,7 @@ globalnames = module.module_attribute_names() and [ compiler.ast.CallFunc( special_name("__globalnames__"), - [special_name(name) for name in module.module_attribute_names()] + [special_name(attr.name) for attr in module.attributes_as_list()] ) ] or [] @@ -163,14 +163,14 @@ instattrs = cls.instance_attribute_names() and [ compiler.ast.CallFunc( special_name("__instattrs__"), - [special_name(name) for name in cls.instance_attribute_names()] + [special_name(attr.name) for attr in cls.instance_attributes_as_list()] ) ] or [] clsattrs = cls.class_attribute_names() and [ compiler.ast.CallFunc( special_name("__clsattrs__"), - [special_name(name) for name in cls.class_attribute_names()] + [special_name(attr.name) for attr in cls.attributes_as_list()] ) ] or [] diff -r 0f4bbb3b9c2f -r 0bd17ac3005e micropython/table.py --- a/micropython/table.py Mon Jul 01 12:57:30 2013 +0200 +++ b/micropython/table.py Tue Jul 02 00:51:04 2013 +0200 @@ -175,21 +175,9 @@ if isinstance(attr, (Class, Module)): return (attr_index, None, None) - # Get the absolute location for classes and modules. - - if attr.parent is not None and attr.is_static_attribute(): - location = attr.parent.location or 0 - else: - location = 0 + # Attribute index/code, attribute type, position in structure. - if attr.position is not None: - position = attr.position + location + 1 # skip structure header - else: - position = None # NOTE: Should fix unpositioned attributes. - - # Attribute index/code, attribute type, location/position. - - return (attr_index, attr.is_static_attribute(), position) + return (attr_index, attr.is_static_attribute(), attr.position) class ParameterList(List):