1.1 --- a/encoders.py Sat Sep 02 01:19:52 2023 +0200
1.2 +++ b/encoders.py Sat Sep 02 01:48:44 2023 +0200
1.3 @@ -233,18 +233,12 @@
1.4
1.5 attribute_loading_ops = (
1.6 "__load_via_class", "__load_via_object", "__get_class_and_load",
1.7 - )
1.8 -
1.9 -attribute_ops = attribute_loading_ops + (
1.10 - "__store_via_class", "__store_via_object",
1.11 - )
1.12 -
1.13 -checked_loading_ops = (
1.14 "__check_and_load_via_class", "__check_and_load_via_object", "__check_and_load_via_any",
1.15 )
1.16
1.17 -checked_ops = checked_loading_ops + (
1.18 - "__check_and_store_via_class", "__check_and_store_via_object", "__check_and_store_via_any",
1.19 +attribute_ref_lookup_ops = (
1.20 + "__get_object_attr_ref", "__get_class_attr_ref",
1.21 + "__check_and_get_object_attr_ref",
1.22 )
1.23
1.24 typename_ops = (
1.25 @@ -267,6 +261,14 @@
1.26 "<accessor>", "<set_accessor>",
1.27 )
1.28
1.29 +attribute_ref_values = (
1.30 + "<attr_ref>",
1.31 + )
1.32 +
1.33 +attribute_ref_ops = (
1.34 + "<attr_ref>", "<set_attr_ref>",
1.35 + )
1.36 +
1.37 context_values = (
1.38 "<context>",
1.39 )
1.40 @@ -279,14 +281,15 @@
1.41 "<test_context_revert>", "<test_context_static>",
1.42 )
1.43
1.44 -reference_acting_ops = attribute_ops + checked_ops + type_ops + typename_ops
1.45 -attribute_producing_ops = attribute_loading_ops + checked_loading_ops
1.46 +reference_acting_ops = attribute_ref_lookup_ops + attribute_loading_ops + type_ops + typename_ops
1.47 +attribute_producing_ops = attribute_loading_ops
1.48
1.49 attribute_producing_variables = (
1.50 "<accessor>", "<context>", "<name>", "<private_context>", "<target_accessor>"
1.51 )
1.52
1.53 -def encode_access_instruction(instruction, subs, accessor_index, context_index):
1.54 +def encode_access_instruction(instruction, subs, accessor_index, context_index,
1.55 + attribute_ref_index):
1.56
1.57 """
1.58 Encode the 'instruction' - a sequence starting with an operation and
1.59 @@ -302,6 +305,9 @@
1.60 The 'context_index' parameter defines the position in local context storage
1.61 for the referenced context or affected by a context operation.
1.62
1.63 + The 'attribute_ref_index' parameter defines the position in local attribute
1.64 + reference storage for a referenced attribute.
1.65 +
1.66 Return both the encoded instruction and a collection of substituted names.
1.67 """
1.68
1.69 @@ -315,7 +321,8 @@
1.70 if args:
1.71 converting_op = op
1.72 for arg in args:
1.73 - s, _substituted = encode_access_instruction_arg(arg, subs, converting_op, accessor_index, context_index)
1.74 + s, _substituted = encode_access_instruction_arg(arg, subs,
1.75 + converting_op, accessor_index, context_index, attribute_ref_index)
1.76 substituted.update(_substituted)
1.77 a.append(s)
1.78 converting_op = None
1.79 @@ -342,6 +349,11 @@
1.80 if op in accessor_ops:
1.81 a.insert(0, accessor_index)
1.82
1.83 + # Add attribute reference storage information to certain operations.
1.84 +
1.85 + if op in attribute_ref_ops:
1.86 + a.insert(0, attribute_ref_index)
1.87 +
1.88 # Add context storage information to certain operations.
1.89
1.90 if op in context_ops:
1.91 @@ -381,7 +393,7 @@
1.92
1.93 return "%s%s" % (op, argstr), substituted
1.94
1.95 -def encode_access_instruction_arg(arg, subs, op, accessor_index, context_index):
1.96 +def encode_access_instruction_arg(arg, subs, op, accessor_index, context_index, attribute_ref_index):
1.97
1.98 """
1.99 Encode 'arg' using 'subs' to define substitutions, 'op' to indicate the
1.100 @@ -393,7 +405,8 @@
1.101 """
1.102
1.103 if isinstance(arg, tuple):
1.104 - encoded, substituted = encode_access_instruction(arg, subs, accessor_index, context_index)
1.105 + encoded, substituted = encode_access_instruction(arg, subs,
1.106 + accessor_index, context_index, attribute_ref_index)
1.107 return attribute_to_reference(op, arg[0], encoded, substituted)
1.108
1.109 # Special values only need replacing, not encoding.
1.110 @@ -404,6 +417,8 @@
1.111
1.112 if arg in accessor_values or arg in context_values:
1.113 encoded = "%s(%s)" % (subs.get(arg), context_index)
1.114 + elif arg in attribute_ref_values:
1.115 + encoded = "%s(%s)" % (subs.get(arg), attribute_ref_index)
1.116 else:
1.117 encoded = subs.get(arg)
1.118