# HG changeset patch # User Paul Boddie # Date 1716159965 -7200 # Node ID c8b0c2d6df5c831b24eea9b94bf3c8028cad4b77 # Parent d62de545458a2d0b95ef44cec58745dd81391f18# Parent 16990afa27543e3536114fe5942ed9b3fa1e2756 Merged changes from the value-replacement branch. diff -r d62de545458a -r c8b0c2d6df5c translator.py --- a/translator.py Sun May 19 22:56:53 2024 +0200 +++ b/translator.py Mon May 20 01:06:05 2024 +0200 @@ -613,7 +613,6 @@ elif instruction[0] == "": attribute_ref_stored = True - self.next_attribute_ref() # Collect the encoded instruction, noting any temporary variables # required by it. @@ -626,9 +625,14 @@ # Record temporary name usage. + temps = set() + for sub in substituted: if self.temp_subs.has_key(sub): - self.record_temp(self.temp_subs[sub]) + temps.add(self.temp_subs[sub]) + + for temp in temps: + self.next_temp(temp) # Get full final identity details. @@ -1322,8 +1326,11 @@ self.result_target_name = None else: result_target = "__tmp_results[%d]" % self.result_target - self.record_temp("__tmp_results") - self.next_result() + + # Reserve a temporary result target only if it will be used. + + if not literal_instantiation: + self.next_temp("__tmp_results") else: result_target = None @@ -1568,6 +1575,28 @@ self.max_accessor_index = 0 self.max_attribute_ref_index = 0 + def next_temp(self, name): + + "Allocate the next temporary storage element for 'name'." + + if name == "__tmp_results": + self.next_result() + elif name == "__tmp_targets": + self.next_target() + elif name == "__tmp_contexts": + self.next_context() + elif name == "__tmp_values": + self.next_accessor() + elif name == "__tmp_attr_refs": + self.next_attribute_ref() + elif name in ("__tmp_private_context", "__tmp_target_value", "__tmp_result"): + pass + else: + raise TranslateError("Temporary storage %s is not recognised." % name, + self.get_namespace_path()) + + self.record_temp(name) + def next_result(self): "Allocate the next result target storage." @@ -1671,15 +1700,17 @@ else: self.record_temp("__tmp_values") + accessor_index = self.accessor_index + self.next_accessor() return make_expression("""\ (__set_accessor(%d, __ATTRVALUE(__COPY(&%s, sizeof(%s)))), %s, __get_accessor(%d))""" % ( - self.accessor_index, + accessor_index, encode_path(function_name), encode_symbol("obj", function_name), ", ".join(defaults), - self.accessor_index)) + accessor_index)) def process_logical_node(self, n):