1.1 --- a/translator.py Tue Mar 07 19:21:09 2017 +0100
1.2 +++ b/translator.py Tue Mar 07 22:21:58 2017 +0100
1.3 @@ -120,6 +120,10 @@
1.4 self.in_try_finally = False
1.5 self.in_try_except = False
1.6
1.7 + # Invocation adjustments.
1.8 +
1.9 + self.in_argument_list = False
1.10 +
1.11 # Attribute access and accessor counting.
1.12
1.13 self.attr_accesses = {}
1.14 @@ -313,6 +317,7 @@
1.15 else:
1.16 self.in_function = False
1.17 self.function_target = 0
1.18 + self.max_function_targets = 0
1.19 self.start_module()
1.20 self.process_structure(node)
1.21 self.end_module()
1.22 @@ -803,6 +808,7 @@
1.23 in_conditional = self.in_conditional
1.24 self.in_conditional = False
1.25 self.function_target = 0
1.26 + self.max_function_targets = 0
1.27
1.28 # Volatile locals for exception handling.
1.29
1.30 @@ -994,7 +1000,10 @@
1.31 # Any invocations in the expression will store target details in a
1.32 # different location.
1.33
1.34 - self.function_target += 1
1.35 + self.next_target()
1.36 +
1.37 + in_argument_list = self.in_argument_list
1.38 + self.in_argument_list = False
1.39
1.40 # Process the expression.
1.41
1.42 @@ -1002,6 +1011,7 @@
1.43
1.44 # Reference the current target again.
1.45
1.46 + self.in_argument_list = in_argument_list
1.47 self.function_target -= 1
1.48
1.49 # Obtain details of the invocation expression.
1.50 @@ -1126,7 +1136,13 @@
1.51 # Any invocations in the arguments will store target details in a
1.52 # different location.
1.53
1.54 - self.function_target += 1
1.55 + function_target = self.function_target
1.56 +
1.57 + if not target_identity:
1.58 + self.next_target()
1.59 +
1.60 + in_argument_list = self.in_argument_list
1.61 + self.in_argument_list = True
1.62
1.63 for i, arg in enumerate(n.args):
1.64 argexpr = self.process_structure_node(arg)
1.65 @@ -1166,7 +1182,10 @@
1.66
1.67 # Reference the current target again.
1.68
1.69 - self.function_target -= 1
1.70 + self.in_argument_list = in_argument_list
1.71 +
1.72 + if not self.in_argument_list:
1.73 + self.function_target = function_target
1.74
1.75 # Defaults are added to the frame where arguments are missing.
1.76
1.77 @@ -1256,6 +1275,13 @@
1.78 len(args), argstr))
1.79 return InvocationResult(stages)
1.80
1.81 + def next_target(self):
1.82 +
1.83 + "Allocate the next function target storage."
1.84 +
1.85 + self.function_target += 1
1.86 + self.max_function_targets = max(self.function_target, self.max_function_targets)
1.87 +
1.88 def always_callable(self, refs):
1.89
1.90 "Determine whether all 'refs' are callable."
1.91 @@ -1836,7 +1862,7 @@
1.92
1.93 # Provide space for the given number of targets.
1.94
1.95 - targets = self.importer.function_targets.get(name)
1.96 + targets = self.max_function_targets
1.97
1.98 if self.uses_temp(name, "__tmp_targets"):
1.99 self.writeline("__attr __tmp_targets[%d];" % targets)