Lichen

Change of translator.py

1040:c8b0c2d6df5c
translator.py value-replacement-for-wrapper
     1.1 --- a/translator.py	Sun May 19 22:56:53 2024 +0200
     1.2 +++ b/translator.py	Mon May 20 01:06:05 2024 +0200
     1.3 @@ -613,7 +613,6 @@
     1.4  
     1.5              elif instruction[0] == "<set_attr_ref>":
     1.6                  attribute_ref_stored = True
     1.7 -                self.next_attribute_ref()
     1.8  
     1.9              # Collect the encoded instruction, noting any temporary variables
    1.10              # required by it.
    1.11 @@ -626,9 +625,14 @@
    1.12  
    1.13          # Record temporary name usage.
    1.14  
    1.15 +        temps = set()
    1.16 +
    1.17          for sub in substituted:
    1.18              if self.temp_subs.has_key(sub):
    1.19 -                self.record_temp(self.temp_subs[sub])
    1.20 +                temps.add(self.temp_subs[sub])
    1.21 +
    1.22 +        for temp in temps:
    1.23 +            self.next_temp(temp)
    1.24  
    1.25          # Get full final identity details.
    1.26  
    1.27 @@ -1322,8 +1326,11 @@
    1.28                  self.result_target_name = None
    1.29              else:
    1.30                  result_target = "__tmp_results[%d]" % self.result_target
    1.31 -                self.record_temp("__tmp_results")
    1.32 -                self.next_result()
    1.33 +
    1.34 +                # Reserve a temporary result target only if it will be used.
    1.35 +
    1.36 +                if not literal_instantiation:
    1.37 +                    self.next_temp("__tmp_results")
    1.38          else:
    1.39              result_target = None
    1.40  
    1.41 @@ -1568,6 +1575,28 @@
    1.42          self.max_accessor_index = 0
    1.43          self.max_attribute_ref_index = 0
    1.44  
    1.45 +    def next_temp(self, name):
    1.46 +
    1.47 +        "Allocate the next temporary storage element for 'name'."
    1.48 +
    1.49 +        if name == "__tmp_results":
    1.50 +            self.next_result()
    1.51 +        elif name == "__tmp_targets":
    1.52 +            self.next_target()
    1.53 +        elif name == "__tmp_contexts":
    1.54 +            self.next_context()
    1.55 +        elif name == "__tmp_values":
    1.56 +            self.next_accessor()
    1.57 +        elif name == "__tmp_attr_refs":
    1.58 +            self.next_attribute_ref()
    1.59 +        elif name in ("__tmp_private_context", "__tmp_target_value", "__tmp_result"):
    1.60 +            pass
    1.61 +        else:
    1.62 +            raise TranslateError("Temporary storage %s is not recognised." % name,
    1.63 +                                 self.get_namespace_path())
    1.64 +
    1.65 +        self.record_temp(name)
    1.66 +
    1.67      def next_result(self):
    1.68  
    1.69          "Allocate the next result target storage."
    1.70 @@ -1671,15 +1700,17 @@
    1.71  
    1.72          else:
    1.73              self.record_temp("__tmp_values")
    1.74 +            accessor_index = self.accessor_index
    1.75 +            self.next_accessor()
    1.76              return make_expression("""\
    1.77  (__set_accessor(%d, __ATTRVALUE(__COPY(&%s, sizeof(%s)))),
    1.78   %s,
    1.79   __get_accessor(%d))""" % (
    1.80 -                self.accessor_index,
    1.81 +                accessor_index,
    1.82                  encode_path(function_name),
    1.83                  encode_symbol("obj", function_name),
    1.84                  ", ".join(defaults),
    1.85 -                self.accessor_index))
    1.86 +                accessor_index))
    1.87  
    1.88      def process_logical_node(self, n):
    1.89