Lichen

Change of templates/ops.c

1041:fb368817a23b
templates/ops.c value-replacement-generic
     1.1 --- a/templates/ops.c	Mon May 20 01:06:05 2024 +0200
     1.2 +++ b/templates/ops.c	Mon May 20 21:26:54 2024 +0200
     1.3 @@ -1,6 +1,6 @@
     1.4  /* Common operations.
     1.5  
     1.6 -Copyright (C) 2015, 2016, 2017, 2018, 2023 Paul Boddie <paul@boddie.org.uk>
     1.7 +Copyright (C) 2015-2018, 2023, 2024 Paul Boddie <paul@boddie.org.uk>
     1.8  
     1.9  This program is free software; you can redistribute it and/or modify it under
    1.10  the terms of the GNU General Public License as published by the Free Software
    1.11 @@ -441,14 +441,12 @@
    1.12  }
    1.13  
    1.14  /* Store an attribute in a target location. For targets that support value
    1.15 -   replacement, a copied object is assigned when initialising the target.
    1.16 -
    1.17 -   NOTE: Only floats and wrappers are currently supported for value replacement.
    1.18 -         A special copy attribute could be employed to make this generic. */
    1.19 +   replacement, a copied object is assigned when initialising the target. */
    1.20  
    1.21  __attr __set_attr(volatile __attr *target, __attr attr)
    1.22  {
    1.23      __ref obj;
    1.24 +    int obj_size;
    1.25  
    1.26      /* Value already replaced in target by an operation. */
    1.27  
    1.28 @@ -462,10 +460,10 @@
    1.29  
    1.30      if ((obj != NULL) && __is_instance(obj))
    1.31      {
    1.32 -        if (__get_class(obj) == &__builtins___float_float)
    1.33 -            attr = __ATTRVALUE(__COPY(obj, __INSTANCESIZE(__builtins___float_float)));
    1.34 -        else if (__get_class(obj) == &__builtins___core_wrapper)
    1.35 -            attr = __ATTRVALUE(__COPY(obj, __INSTANCESIZE(__builtins___core_wrapper)));
    1.36 +        obj_size = __get_class(obj)->obj_size;
    1.37 +
    1.38 +        if (obj_size)
    1.39 +            attr = __ATTRVALUE(__COPY(obj, obj_size));
    1.40      }
    1.41  
    1.42      /* Set and return the attribute. */