1.1 --- a/translator.py Tue Feb 28 00:00:09 2017 +0100
1.2 +++ b/translator.py Tue Feb 28 17:00:26 2017 +0100
1.3 @@ -1627,6 +1627,18 @@
1.4
1.5 # Special variable usage.
1.6
1.7 + def get_temp_path(self):
1.8 +
1.9 + """
1.10 + Return the appropriate namespace path for temporary names in the current
1.11 + namespace.
1.12 + """
1.13 +
1.14 + if self.in_function:
1.15 + return self.get_namespace_path()
1.16 + else:
1.17 + return self.name
1.18 +
1.19 def record_temp(self, name):
1.20
1.21 """
1.22 @@ -1636,13 +1648,23 @@
1.23 program.
1.24 """
1.25
1.26 - if self.in_function:
1.27 - path = self.get_namespace_path()
1.28 - else:
1.29 - path = self.name
1.30 -
1.31 - init_item(self.temp_usage, path, set)
1.32 - self.temp_usage[path].add(name)
1.33 + path = self.get_temp_path()
1.34 +
1.35 + init_item(self.temp_usage, path, list)
1.36 + self.temp_usage[path].append(name)
1.37 +
1.38 + def remove_temps(self, names):
1.39 +
1.40 + """
1.41 + Remove 'names' from temporary storage allocations, each instance
1.42 + removing each request for storage.
1.43 + """
1.44 +
1.45 + path = self.get_temp_path()
1.46 +
1.47 + for name in names:
1.48 + if self.uses_temp(path, name):
1.49 + self.temp_usage[path].remove(name)
1.50
1.51 def uses_temp(self, path, name):
1.52
1.53 @@ -1816,6 +1838,9 @@
1.54
1.55 if isinstance(test_ref, LogicalResult):
1.56 self.writeline("%s %s" % (statement, test_ref.apply_test()))
1.57 + temps = test_ref.discards_temporary()
1.58 + if temps:
1.59 + self.remove_temps(temps)
1.60 else:
1.61 self.writeline("%s (__BOOL(%s))" % (statement, test_ref))
1.62