# HG changeset patch # User Paul Boddie # Date 1216592640 -7200 # Node ID ff6235ff830d7dcf8634212679854d5963ea0fac # Parent d4dd63e66f6cd71bc5de5d5d3aa5647e1c8278bb Made module and class attribute storage forbidden via attribute access on objects, since this is not generally detectable at compile-time. (There would be a run-time test on other store instructions in order to protect guarantees about class and module attributes.) Added name-related instruction attributes to the Translation class. diff -r d4dd63e66f6c -r ff6235ff830d micropython/ast.py --- a/micropython/ast.py Sun Jul 20 23:16:26 2008 +0200 +++ b/micropython/ast.py Mon Jul 21 00:24:00 2008 +0200 @@ -34,7 +34,9 @@ supported_optimisations = ["constant_storage", "known_target", "self_access", "temp_storage", "load_operations", "unused_results"] attribute_load_instructions = (LoadAddress, LoadAddressContext, LoadAttr, LoadAttrIndex) - attribute_store_instructions = (StoreAddress, None, StoreAttr, StoreAttrIndex) + attribute_store_instructions = (None, None, StoreAttr, StoreAttrIndex) + name_load_instructions = (LoadName, LoadAddress) + name_store_instructions = (StoreName, StoreAddress) def __init__(self, module, importer, optimisations=None): @@ -568,7 +570,12 @@ # Produce a suitable instruction. - self.replace_op(AddressInstruction(pos)) + if AddressInstruction is not None: + self.replace_op(AddressInstruction(pos)) + else: + raise TranslateError(self.module.full_name(), node, + "Storing of class or module attribute %r via an object is not permitted." % attrname) + return # Where the last operation involves the special 'self' name, check to @@ -1118,7 +1125,7 @@ def visitAssList(self, node): raise TranslationNotImplementedError(self.module.full_name(), node, "AssList") def visitAssName(self, node): - self._visitName(node, (StoreName, StoreAddress)) + self._visitName(node, self.name_store_instructions) self.set_source() visitAssTuple = visitAssList @@ -1161,7 +1168,7 @@ self.new_op(LoadConst(node.unit)) self.record_value() - self._visitName(node, (StoreName, StoreAddress)) + self._visitName(node, self.name_store_instructions) self.set_source() self.discard_value() @@ -1290,7 +1297,7 @@ self.new_op(LoadConst(node.unit)) self.record_value() - self._visitName(node, (StoreName, StoreAddress)) + self._visitName(node, self.name_store_instructions) self.set_source() self.discard_value() @@ -1380,7 +1387,7 @@ const = self.module.constant_values[None] self.new_op(LoadConst(const)) else: - self._visitName(node, (LoadName, LoadAddress)) + self._visitName(node, self.name_load_instructions) def visitNot(self, node): next_label = self.new_label() diff -r d4dd63e66f6c -r ff6235ff830d tests/attributes.py --- a/tests/attributes.py Sun Jul 20 23:16:26 2008 +0200 +++ b/tests/attributes.py Mon Jul 21 00:24:00 2008 +0200 @@ -9,7 +9,7 @@ def update(self, value): self.attr = value - C.clsattr = value + C.clsattr C C.clsattr