1.1 --- a/micropython/trans.py Sat Sep 10 20:29:30 2011 +0200
1.2 +++ b/micropython/trans.py Sat Sep 10 20:33:52 2011 +0200
1.3 @@ -190,11 +190,8 @@
1.4 target_plus_name = self.optimiser.optimise_constant_accessor()
1.5
1.6 # Only try and discover the position if the target can be resolved.
1.7 - # Since instances cannot be constants, this involves classes and
1.8 - # modules.
1.9 - # It is acceptable to replace the instruction providing the constant
1.10 - # input because doing so does not lose any input information required by
1.11 - # the replacement instructions.
1.12 + # Since instances cannot be constants in general, this involves classes
1.13 + # and modules, but constants known at compile-time must also be handled.
1.14
1.15 if target_plus_name is not None:
1.16 target, target_name = target_plus_name
1.17 @@ -219,7 +216,20 @@
1.18 # Produce a suitable instruction.
1.19
1.20 if AddressInstruction is not None:
1.21 - self.replace_active_value(AddressInstruction(attr))
1.22 +
1.23 + # Where the target is a constant instance, the constant input
1.24 + # needs to be retained as the context of the resulting
1.25 + # attribute.
1.26 +
1.27 + if isinstance(target, Instance):
1.28 + self.new_op(AddressContextInstruction(attr))
1.29 +
1.30 + # It is acceptable to replace the instruction providing the
1.31 + # constant input because doing so does not lose any input
1.32 + # information required by the replacement instructions.
1.33 +
1.34 + else:
1.35 + self.replace_active_value(AddressInstruction(attr))
1.36 else:
1.37 raise TranslateError("Storing of class or module attribute %r via an object is not permitted." % attrname)
1.38
1.39 @@ -631,6 +641,7 @@
1.40
1.41 self.dispatch(arg.expr)
1.42 self.record_value()
1.43 + self.start_target()
1.44
1.45 # Store the source value using the callable's parameter
1.46 # table information.
1.47 @@ -979,6 +990,7 @@
1.48
1.49 else:
1.50 self.record_value()
1.51 + self.start_target()
1.52 self.new_op(StoreName(fn[parameter]))
1.53 self.assign_value()
1.54 self.discard_value()
1.55 @@ -1011,6 +1023,7 @@
1.56 self.dispatch(default)
1.57
1.58 self.record_value()
1.59 + self.start_target()
1.60 if dynamic:
1.61 self.new_op(temp)
1.62 self.new_op(StoreAttr(attr))
1.63 @@ -1239,6 +1252,8 @@
1.64
1.65 self.make_instance(self.get_builtin_class("list"), 1)
1.66 list_temp = self.get_temp()
1.67 +
1.68 + self.start_target()
1.69 self.new_op(list_temp)
1.70 self.new_op(StoreAttr(Attr(0, None, None))) # _elements is at position 0
1.71 self.assign_value()
1.72 @@ -1267,6 +1282,7 @@
1.73 position 'i' with the given starting 'offset'.
1.74 """
1.75
1.76 + self.start_target()
1.77 self.new_op(temp)
1.78 self.new_op(StoreAttr(Attr(i + offset, None, None)))
1.79 self.assign_value()