1.1 --- a/micropython/trans.py Tue Aug 10 23:18:42 2010 +0200
1.2 +++ b/micropython/trans.py Wed Aug 11 00:04:11 2010 +0200
1.3 @@ -511,36 +511,32 @@
1.4
1.5 elif self.optimiser.should_optimise_accesses_by_attribute_usage():
1.6
1.7 - if hasattr(node, "_attrusers"):
1.8 - target_names = set()
1.9 + target_names = self.possible_accessor_types(node)
1.10
1.11 - for user in node._attrusers:
1.12 - target_names.update(self.objtable.all_possible_objects(user._attrnames[node._username]))
1.13 + if target_names is not None and len(target_names) == 1:
1.14 + target_name = list(target_names)[0]
1.15
1.16 - if len(target_names) == 1:
1.17 - target_name = list(target_names)[0]
1.18 + # Access the object table to get the attribute.
1.19
1.20 - # Access the object table to get the attribute.
1.21 + try:
1.22 + attr = self.objtable.access(target_name, attrname)
1.23
1.24 - try:
1.25 - attr = self.objtable.access(target_name, attrname)
1.26 + # Disallow non-class/instance optimisations.
1.27
1.28 - # Disallow non-class/instance optimisations.
1.29 + except TableError, exc:
1.30 + print "Possible optimisation for", target_name, "not permissable."
1.31 +
1.32 + # Produce a suitable instruction.
1.33
1.34 - except TableError, exc:
1.35 - print "Possible optimisation for", target_name, "not permissable."
1.36 -
1.37 - # Produce a suitable instruction.
1.38 -
1.39 + else:
1.40 + if AddressContextCondInstruction is not None and attr.is_static_attribute():
1.41 + self.new_op(AddressContextCondInstruction(attr))
1.42 + elif AttrInstruction is not None and not attr.is_static_attribute():
1.43 + self.new_op(AttrInstruction(attr))
1.44 else:
1.45 - if AddressContextCondInstruction is not None and attr.is_static_attribute():
1.46 - self.new_op(AddressContextCondInstruction(attr))
1.47 - elif AttrInstruction is not None and not attr.is_static_attribute():
1.48 - self.new_op(AttrInstruction(attr))
1.49 - else:
1.50 - raise TranslateError("Storing of class or module attribute %r via an object is not permitted." % attrname)
1.51 + raise TranslateError("Storing of class or module attribute %r via an object is not permitted." % attrname)
1.52
1.53 - return
1.54 + return
1.55
1.56 # Otherwise, perform a normal operation.
1.57