1.1 --- a/translator.py Fri Feb 17 18:49:57 2017 +0100
1.2 +++ b/translator.py Fri Feb 17 18:52:18 2017 +0100
1.3 @@ -739,8 +739,8 @@
1.4 }
1.5
1.6 temp_subs = {
1.7 - "<context>" : "__tmp_context",
1.8 - "<set_context>" : "__tmp_context",
1.9 + "<context>" : "__tmp_contexts",
1.10 + "<set_context>" : "__tmp_contexts",
1.11 "<accessor>" : "__tmp_value",
1.12 "<target_accessor>" : "__tmp_target_value",
1.13 "<set_accessor>" : "__tmp_value",
1.14 @@ -748,6 +748,7 @@
1.15 }
1.16
1.17 op_subs = {
1.18 + "<context>" : "__get_context",
1.19 "<set_context>" : "__set_context",
1.20 "<set_accessor>" : "__set_accessor",
1.21 "<set_target_accessor>" : "__set_target_accessor",
1.22 @@ -759,11 +760,16 @@
1.23 output = []
1.24 substituted = set()
1.25
1.26 + # The context set or retrieved will be that used by any enclosing
1.27 + # invocation.
1.28 +
1.29 + context_index = self.function_target - 1
1.30 +
1.31 # Obtain encoded versions of each instruction, accumulating temporary
1.32 # variables.
1.33
1.34 for instruction in self.optimiser.access_instructions[location]:
1.35 - encoded, _substituted = encode_access_instruction(instruction, subs)
1.36 + encoded, _substituted = encode_access_instruction(instruction, subs, context_index)
1.37 output.append(encoded)
1.38 substituted.update(_substituted)
1.39
1.40 @@ -1253,7 +1259,8 @@
1.41
1.42 if context_required:
1.43 if have_access_context:
1.44 - args = ["(__attr) {.value=__tmp_context}"]
1.45 + self.record_temp("__tmp_contexts")
1.46 + args = ["(__attr) {.value=__tmp_contexts[%d]}" % self.function_target]
1.47 else:
1.48 self.record_temp("__tmp_targets")
1.49 args = ["__CONTEXT_AS_VALUE(__tmp_targets[%d])" % self.function_target]
1.50 @@ -1367,12 +1374,13 @@
1.51 # Methods accessed via unidentified accessors are obtained.
1.52
1.53 elif function:
1.54 + self.record_temp("__tmp_contexts")
1.55 self.record_temp("__tmp_targets")
1.56
1.57 if context_required:
1.58 if have_access_context:
1.59 - stages.append("__get_function(__tmp_context, __tmp_targets[%d])" % (
1.60 - self.function_target))
1.61 + stages.append("__get_function(__tmp_contexts[%d], __tmp_targets[%d])" % (
1.62 + self.function_target, self.function_target))
1.63 else:
1.64 stages.append("__get_function(__CONTEXT_AS_VALUE(__tmp_targets[%d]).value, __tmp_targets[%d])" % (
1.65 self.function_target, self.function_target))
1.66 @@ -1925,14 +1933,15 @@
1.67
1.68 # Provide space for the given number of targets.
1.69
1.70 + targets = self.importer.function_targets.get(name)
1.71 +
1.72 if self.uses_temp(name, "__tmp_targets"):
1.73 - targets = self.importer.function_targets.get(name)
1.74 self.writeline("__attr __tmp_targets[%d];" % targets)
1.75 + if self.uses_temp(name, "__tmp_contexts"):
1.76 + self.writeline("__ref __tmp_contexts[%d];" % targets)
1.77
1.78 # Add temporary variable usage details.
1.79
1.80 - if self.uses_temp(name, "__tmp_context"):
1.81 - self.writeline("__ref __tmp_context;")
1.82 if self.uses_temp(name, "__tmp_value"):
1.83 self.writeline("__ref __tmp_value;")
1.84 if self.uses_temp(name, "__tmp_target_value"):