1.1 --- a/templates/ops.c Sat Sep 02 01:19:52 2023 +0200
1.2 +++ b/templates/ops.c Sat Sep 02 01:48:44 2023 +0200
1.3 @@ -57,11 +57,18 @@
1.4 return __test_context(context, __ATTRVALUE(obj));
1.5 }
1.6
1.7 +/* Direct retrieval operations, returning attribute locations. */
1.8 +
1.9 +__attr *__get_class_attr_ref__(__ref obj, int pos)
1.10 +{
1.11 + return __get_object_attr_ref__(__get_class(obj), pos);
1.12 +}
1.13 +
1.14 /* Direct retrieval operations, returning and setting attributes. */
1.15
1.16 __attr __load_via_object__(__ref obj, int pos)
1.17 {
1.18 - return obj->attrs[pos];
1.19 + return __load_via_attr_ref(__get_object_attr_ref__(obj, pos));
1.20 }
1.21
1.22 __attr __load_via_class__(__ref obj, int pos)
1.23 @@ -77,27 +84,6 @@
1.24 return __load_via_object__(obj, pos);
1.25 }
1.26
1.27 -/* Direct storage operations. */
1.28 -
1.29 -int __store_via_object__(__ref obj, int pos, __attr value)
1.30 -{
1.31 - obj->attrs[pos] = value;
1.32 - return 1;
1.33 -}
1.34 -
1.35 -int __store_via_class__(__ref obj, int pos, __attr value)
1.36 -{
1.37 - return __store_via_object__(__get_class(obj), pos, value);
1.38 -}
1.39 -
1.40 -int __get_class_and_store__(__ref obj, int pos, __attr value)
1.41 -{
1.42 - /* Forbid class-relative assignments. */
1.43 -
1.44 - __raise_type_error();
1.45 - return 0;
1.46 -}
1.47 -
1.48 /* Introspection. */
1.49
1.50 int __is_instance(__ref obj)
1.51 @@ -162,14 +148,36 @@
1.52 return __HASATTR(obj, pos, code) ? obj : 0;
1.53 }
1.54
1.55 +/* Attribute testing and location operations, returning the address of the
1.56 + attribute as opposed to its value. */
1.57 +
1.58 +__attr *__check_and_get_object_attr_ref_null(__ref obj, int pos, int code)
1.59 +{
1.60 + if (__HASATTR(obj, pos, code))
1.61 + return __get_object_attr_ref__(obj, pos);
1.62 + else
1.63 + return NULL;
1.64 +}
1.65 +
1.66 +__attr *__check_and_get_object_attr_ref__(__ref obj, int pos, int code)
1.67 +{
1.68 + if (__HASATTR(obj, pos, code))
1.69 + return __get_object_attr_ref__(obj, pos);
1.70 +
1.71 + __raise_type_error();
1.72 + return NULL;
1.73 +}
1.74 +
1.75 /* Attribute testing and retrieval operations. */
1.76
1.77 __attr __check_and_load_via_object_null(__ref obj, int pos, int code)
1.78 {
1.79 - if (__HASATTR(obj, pos, code))
1.80 - return __load_via_object__(obj, pos);
1.81 + __attr *attr = __check_and_get_object_attr_ref_null(obj, pos, code);
1.82 +
1.83 + if (attr == NULL)
1.84 + return __NULL;
1.85 else
1.86 - return __NULL;
1.87 + return __load_via_attr_ref(attr);
1.88 }
1.89
1.90 __attr __check_and_load_via_class__(__ref obj, int pos, int code)
1.91 @@ -179,54 +187,22 @@
1.92
1.93 __attr __check_and_load_via_object__(__ref obj, int pos, int code)
1.94 {
1.95 - if (__HASATTR(obj, pos, code))
1.96 - return __load_via_object__(obj, pos);
1.97 + __attr attr = __check_and_load_via_object_null(obj, pos, code);
1.98
1.99 - __raise_type_error();
1.100 - return __NULL;
1.101 + if (__ISNULL(attr))
1.102 + __raise_type_error();
1.103 +
1.104 + return attr;
1.105 }
1.106
1.107 __attr __check_and_load_via_any__(__ref obj, int pos, int code)
1.108 {
1.109 - __attr out = __check_and_load_via_object_null(obj, pos, code);
1.110 - if (__ISNULL(out))
1.111 - out = __check_and_load_via_class__(obj, pos, code);
1.112 - return out;
1.113 -}
1.114 -
1.115 -/* Attribute testing and storage operations. */
1.116 -
1.117 -int __check_and_store_via_class__(__ref obj, int pos, int code, __attr value)
1.118 -{
1.119 - /* Forbid class-relative assignments. */
1.120 -
1.121 - __raise_type_error();
1.122 - return 0;
1.123 -}
1.124 + __attr attr = __check_and_load_via_object_null(obj, pos, code);
1.125
1.126 -int __check_and_store_via_object__(__ref obj, int pos, int code, __attr value)
1.127 -{
1.128 - if (__HASATTR(obj, pos, code))
1.129 - {
1.130 - __store_via_object__(obj, pos, value);
1.131 - return 1;
1.132 - }
1.133 -
1.134 - /* No suitable attribute. */
1.135 + if (__ISNULL(attr))
1.136 + attr = __check_and_load_via_class__(obj, pos, code);
1.137
1.138 - __raise_type_error();
1.139 - return 0;
1.140 -}
1.141 -
1.142 -int __check_and_store_via_any__(__ref obj, int pos, int code, __attr value)
1.143 -{
1.144 - if (__check_and_store_via_object__(obj, pos, code, value))
1.145 - return 1;
1.146 -
1.147 - /* Forbid class-relative assignments. */
1.148 -
1.149 - __raise_type_error();
1.150 - return 0;
1.151 + return attr;
1.152 }
1.153
1.154 /* Context-related operations. */
1.155 @@ -448,11 +424,11 @@
1.156 return copy;
1.157 }
1.158
1.159 -/* Store a suitable attribute in a local. For locals that support value
1.160 - replacement, a copied object is assigned when initialising the local.
1.161 +/* Store an attribute in a target location. For targets that support value
1.162 + replacement, a copied object is assigned when initialising the target.
1.163 NOTE: Only floats are currently supported for value replacement. */
1.164
1.165 -__attr __set_local(volatile __attr *local, __attr attr)
1.166 +__attr __set_attr(volatile __attr *target, __attr attr)
1.167 {
1.168 __ref obj;
1.169
1.170 @@ -471,6 +447,6 @@
1.171
1.172 /* Set and return the attribute. */
1.173
1.174 - *local = attr;
1.175 + *target = attr;
1.176 return attr;
1.177 }