1.1 --- a/micropython/ast.py Tue Mar 04 00:41:53 2008 +0100
1.2 +++ b/micropython/ast.py Sun Mar 09 02:10:12 2008 +0100
1.3 @@ -170,6 +170,9 @@
1.4 # NOTE: Only simple cases are used for optimisations.
1.5
1.6 last = self.last_op()
1.7 +
1.8 + # Where the last operation yields a constant...
1.9 +
1.10 if isinstance(last, (LoadName, LoadAttr)) and last.attr.assignments == 1:
1.11
1.12 # Get the details of the access.
1.13 @@ -178,7 +181,16 @@
1.14 target_name = target.full_name()
1.15 table_entry = self.objtable.table[target_name]
1.16 pos = table_entry[attrname]
1.17 - self.replace_op(AttrInstruction(pos))
1.18 + self.replace_op(AttrInstruction(pos + target.location))
1.19 +
1.20 + # Where the last operation involves the special 'self' name, check to
1.21 + # see if the attribute is acceptably positioned.
1.22 +
1.23 + elif isinstance(last, LoadName) and last.attr.name == "self" and not self.unit.is_relocated(attrname):
1.24 + attr = self.unit.parent.all_attributes()[attrname]
1.25 + self.new_op(AttrInstruction(attr))
1.26 +
1.27 + # Otherwise, perform a normal operation.
1.28
1.29 else:
1.30 index = self.objtable.get_index(attrname)
1.31 @@ -491,7 +503,7 @@
1.32 # Only store the name when visiting this node from outside.
1.33
1.34 if self.unit is not node.unit:
1.35 - self.new_op(LoadConst(node.unit))
1.36 + self.new_op(LoadConst(Const(node.unit)))
1.37 self._visitName(node, (StoreName, StoreAttr))
1.38
1.39 # Visiting of the code occurs when get_code is invoked on this node.