1.1 --- a/templates/ops.c Sat Sep 02 22:08:53 2023 +0200
1.2 +++ b/templates/ops.c Sun Sep 03 00:24:29 2023 +0200
1.3 @@ -47,14 +47,14 @@
1.4 return __ATTRVALUE(obj);
1.5 }
1.6
1.7 -__attr __load_static_replace(__attr context, __ref obj)
1.8 +__attr __load_static_replace(__attr __context, __attr context, __ref obj)
1.9 {
1.10 - return __update_context(context, __ATTRVALUE(obj));
1.11 + return __update_context(__context, context, __ATTRVALUE(obj));
1.12 }
1.13
1.14 -__attr __load_static_test(__attr context, __ref obj)
1.15 +__attr __load_static_test(__attr __context, __attr context, __ref obj)
1.16 {
1.17 - return __test_context(context, __ATTRVALUE(obj));
1.18 + return __test_context(__context, context, __ATTRVALUE(obj));
1.19 }
1.20
1.21 /* Direct retrieval operations, returning attribute locations. */
1.22 @@ -249,18 +249,34 @@
1.23 return 0;
1.24 }
1.25
1.26 -__attr __test_context(__attr context, __attr attr)
1.27 +__attr __test_context(__attr __context, __attr context, __attr attr)
1.28 {
1.29 /* Update the context or return the unchanged attribute. */
1.30
1.31 if (__test_context_update(context, attr, 0))
1.32 - return __update_context(context, attr);
1.33 + return __update_context(__context, context, attr);
1.34 else
1.35 return attr;
1.36 }
1.37
1.38 -__attr __update_context(__attr context, __attr attr)
1.39 +__attr __update_context(__attr __context, __attr context, __attr attr)
1.40 {
1.41 + /* Support context replacement in a similar fashion to value replacement in
1.42 + floats. */
1.43 +
1.44 + __ref obj = __VALUE(__context);
1.45 +
1.46 + /* With any existing wrapper object allocated, replace the attributes and
1.47 + return the same context. */
1.48 +
1.49 + if ((obj != NULL) && __is_instance(obj) &&
1.50 + (__get_class(obj) == &__builtins___core_wrapper))
1.51 + {
1.52 + __store_via_attr_ref(__get_object_attr_ref(obj, __context__), context);
1.53 + __store_via_attr_ref(__get_object_attr_ref(obj, __value__), attr);
1.54 + return __context;
1.55 + }
1.56 +
1.57 return __new_wrapper(context, attr);
1.58 }
1.59
1.60 @@ -426,7 +442,9 @@
1.61
1.62 /* Store an attribute in a target location. For targets that support value
1.63 replacement, a copied object is assigned when initialising the target.
1.64 - NOTE: Only floats are currently supported for value replacement. */
1.65 +
1.66 + NOTE: Only floats and wrappers are currently supported for value replacement.
1.67 + A special copy attribute could be employed to make this generic. */
1.68
1.69 __attr __set_attr(volatile __attr *target, __attr attr)
1.70 {
1.71 @@ -442,8 +460,13 @@
1.72 /* Value is replaceable and should be copied to avoid inadvertent
1.73 sharing. */
1.74
1.75 - if ((obj != NULL) && __is_instance(obj) && (__get_class(obj) == &__builtins___float_float))
1.76 - attr = __ATTRVALUE(__COPY(obj, sizeof(__obj___builtins___float_float)));
1.77 + if ((obj != NULL) && __is_instance(obj))
1.78 + {
1.79 + if (__get_class(obj) == &__builtins___float_float)
1.80 + attr = __ATTRVALUE(__COPY(obj, __INSTANCESIZE(__builtins___float_float)));
1.81 + else if (__get_class(obj) == &__builtins___core_wrapper)
1.82 + attr = __ATTRVALUE(__COPY(obj, __INSTANCESIZE(__builtins___core_wrapper)));
1.83 + }
1.84
1.85 /* Set and return the attribute. */
1.86