1.1 --- a/micropython/common.py Thu Sep 08 00:33:33 2011 +0200
1.2 +++ b/micropython/common.py Sat Sep 10 20:29:30 2011 +0200
1.3 @@ -264,7 +264,8 @@
1.4 """
1.5 Return for the given attribute 'usage', using the 'objtable', the object
1.6 types which satisfy such usage, reporting any problems for the given 'name'
1.7 - and 'unit_name'.
1.8 + and 'unit_name'. Each object type is given as a tuple of the form (type,
1.9 + is_static).
1.10 """
1.11
1.12 all_objtypes = set()
2.1 --- a/micropython/data.py Thu Sep 08 00:33:33 2011 +0200
2.2 +++ b/micropython/data.py Sat Sep 10 20:29:30 2011 +0200
2.3 @@ -977,7 +977,7 @@
2.4 """
2.5
2.6 value = self.get_value()
2.7 - return not (value is None or isinstance(value, Instance))
2.8 + return not (value is None or (isinstance(value, Instance) and not isinstance(value, Constant)))
2.9
2.10 def is_static_attribute(self):
2.11
3.1 --- a/micropython/inspect.py Thu Sep 08 00:33:33 2011 +0200
3.2 +++ b/micropython/inspect.py Sat Sep 10 20:29:30 2011 +0200
3.3 @@ -194,6 +194,24 @@
3.4
3.5 "Vacuum the given object 'obj'."
3.6
3.7 + # Get all constant objects in apparent use.
3.8 +
3.9 + if delete_all:
3.10 + obj_objects = set()
3.11 + else:
3.12 + obj_objects = []
3.13 + for name, attr in obj.items_for_vacuum():
3.14 +
3.15 + # Get constant objects for attributes in use.
3.16 +
3.17 + if self.importer.uses_attribute(obj.full_name(), name) and \
3.18 + attr is not None and attr.is_constant():
3.19 +
3.20 + value = attr.get_value()
3.21 + obj_objects.append(value)
3.22 +
3.23 + # Now vacuum unused attributes and objects not in use.
3.24 +
3.25 for name, attr in obj.items_for_vacuum():
3.26
3.27 # Only consider deleting entire unused objects or things accessible
3.28 @@ -206,12 +224,15 @@
3.29 # have been defined within the object and therefore are not
3.30 # redefined by other code regions.
3.31
3.32 - if attr is not None and attr.assignments == 1:
3.33 + if attr is not None and attr.is_constant():
3.34 value = attr.get_value()
3.35
3.36 # The value must have this object as a parent.
3.37 + # However, it must not be shared by several names.
3.38
3.39 - if value is not obj and value.parent is obj and value in self.all_objects:
3.40 + if value is not obj and value.parent is obj and \
3.41 + value in self.all_objects and value not in obj_objects:
3.42 +
3.43 self.all_objects.remove(value)
3.44
3.45 # Delete class contents and lambdas from functions.
3.46 @@ -462,6 +483,11 @@
3.47
3.48 def _visitAttr(self, expr, attrname, node):
3.49
3.50 + """
3.51 + Process the attribute provided by the given 'expr' with the given
3.52 + 'attrname' and involving the given 'node'.
3.53 + """
3.54 +
3.55 # Attempt to identify the nature of the attribute.
3.56
3.57 if isinstance(expr, Attr):
4.1 --- a/micropython/opt.py Thu Sep 08 00:33:33 2011 +0200
4.2 +++ b/micropython/opt.py Sat Sep 10 20:29:30 2011 +0200
4.3 @@ -137,8 +137,8 @@
4.4 """
4.5
4.6 if self.active in self.active_values:
4.7 - removed = self.active
4.8 - self.translation.remove_op()
4.9 + removed = self.translation.remove_op()
4.10 + self.active_values.remove(removed)
4.11 return removed
4.12 else:
4.13 return None
4.14 @@ -239,7 +239,8 @@
4.15 # NOTE: locals/frames.
4.16
4.17 return isinstance(instruction, (StoreAddress, StoreAddressContext)) and \
4.18 - instruction.attr.assignments == 1
4.19 + instruction.attr.is_constant() and \
4.20 + instruction.attr.is_strict_constant()
4.21
4.22 def is_simple_input(self, instruction):
4.23
4.24 @@ -263,8 +264,11 @@
4.25 last_op = last_op or self.translation.last_op()
4.26 return last_op and last_op.attr == instruction.attr and (
4.27 isinstance(instruction, StoreTemp) and isinstance(last_op, LoadTemp) or
4.28 - isinstance(instruction, StoreAddress) and isinstance(last_op, LoadAddress)
4.29 - )
4.30 + isinstance(instruction, StoreAddress) and isinstance(last_op, LoadAddress) or
4.31 + last_op.source == instruction.target and (
4.32 + isinstance(instruction, LoadTemp) and isinstance(last_op, StoreTemp) or
4.33 + isinstance(instruction, LoadAddress) and isinstance(last_op, StoreAddress)
4.34 + ))
4.35
4.36 # Convenience tests on outputs.
4.37
4.38 @@ -335,7 +339,7 @@
4.39
4.40 # Optimisation methods. See the supported_optimisations class attribute.
4.41
4.42 - def optimise_constant_storage(self, expr=None):
4.43 + def optimise_constant_storage(self, expr):
4.44
4.45 """
4.46 Where the last operation stores a constant into a target which is also
5.1 --- a/micropython/rsvp.py Thu Sep 08 00:33:33 2011 +0200
5.2 +++ b/micropython/rsvp.py Sat Sep 10 20:29:30 2011 +0200
5.3 @@ -334,7 +334,7 @@
5.4
5.5 def format_operand(self):
5.6 operand = self.get_operand()
5.7 - return repr(operand)
5.8 + return operand is not None and repr(operand) or ""
5.9
5.10 def format_working(self):
5.11 return self.working != self.default_working and (", working=%r" % self.working) or ""