1.1 --- a/micropython/trans.py Sun Oct 25 18:35:53 2009 +0100
1.2 +++ b/micropython/trans.py Mon Oct 26 00:23:36 2009 +0100
1.3 @@ -336,24 +336,17 @@
1.4
1.5 if target_name is not None:
1.6
1.7 - # Access the object table to get the attribute position.
1.8 + # Access the object table to get the attribute.
1.9
1.10 try:
1.11 - table_entry = self.objtable.table[target_name]
1.12 - except KeyError:
1.13 - raise TranslateError(self.module.full_name(), node,
1.14 - "No object entry exists for target %r." % target_name)
1.15 -
1.16 - try:
1.17 - pos = table_entry[attrname]
1.18 - except KeyError:
1.19 - raise TranslateError(self.module.full_name(), node,
1.20 - "No attribute entry exists for name %r in target %r." % (attrname, target_name))
1.21 + attr = self.objtable.access(target_name, attrname)
1.22 + except TableError, exc:
1.23 + raise TranslateError(self.module.full_name(), node, exc.args[0])
1.24
1.25 # Produce a suitable instruction.
1.26
1.27 if AddressInstruction is not None:
1.28 - self.replace_active_value(AddressInstruction(pos))
1.29 + self.replace_active_value(AddressInstruction(attr))
1.30 else:
1.31 raise TranslateError(self.module.full_name(), node,
1.32 "Storing of class or module attribute %r via an object is not permitted." % attrname)
1.33 @@ -431,6 +424,34 @@
1.34 except KeyError:
1.35 pass
1.36
1.37 + elif self.optimiser.should_optimise_accesses_by_attribute_usage():
1.38 +
1.39 + if hasattr(node, "_attrnames"):
1.40 + target_names = self.objtable.all_possible_objects(node._attrnames)
1.41 + print self.expr_temp, node._attrnames, "->", target_names
1.42 +
1.43 + if len(target_names) == 1:
1.44 + target_name = target_names[0]
1.45 +
1.46 + # Access the object table to get the attribute.
1.47 +
1.48 + try:
1.49 + attr = self.objtable.access(target_name, attrname)
1.50 + except TableError, exc:
1.51 + raise TranslateError(self.module.full_name(), node, exc.args[0])
1.52 +
1.53 + # Produce a suitable instruction.
1.54 +
1.55 + if AddressContextCondInstruction is not None and attr.is_static_attribute():
1.56 + self.new_op(AddressContextCondInstruction(attr))
1.57 + elif AttrInstruction is not None and not attr.is_static_attribute():
1.58 + self.new_op(AttrInstruction(attr))
1.59 + else:
1.60 + raise TranslateError(self.module.full_name(), node,
1.61 + "Storing of class or module attribute %r via an object is not permitted." % attrname)
1.62 +
1.63 + return
1.64 +
1.65 # Otherwise, perform a normal operation.
1.66
1.67 try: