# HG changeset patch # User Paul Boddie # Date 1716233214 -7200 # Node ID fb368817a23bbae69b093ef81df99f4ae993ddad # Parent c8b0c2d6df5c831b24eea9b94bf3c8028cad4b77 Introduced an object size member to object structures, being set to a non-zero value in copiable type class structures to indicate that value replacement can occur with instances of such classes, with the given size being used to copy these instances. diff -r c8b0c2d6df5c -r fb368817a23b generator.py --- a/generator.py Mon May 20 01:06:05 2024 +0200 +++ b/generator.py Mon May 20 21:26:54 2024 +0200 @@ -3,7 +3,7 @@ """ Generate C code from object layouts and other deduced information. -Copyright (C) 2015-2019, 2021, 2023 Paul Boddie +Copyright (C) 2015-2019, 2021, 2023, 2024 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -70,6 +70,13 @@ dict_type, list_type, tuple_type ) + # Copiable types. + + copiable_types = [ + "__builtins__.core.wrapper", + float_type, + ] + # Data types with a trailing data member of the given native types. trailing_data_types = { @@ -859,6 +866,7 @@ typedef struct { const __table * table; __pos pos; + __int obj_size; __attr attrs[%s]; %s } %s; @@ -880,6 +888,10 @@ obj_type = ref.has_kind("") and encode_symbol("obj", origin) or "__obj" obj_name = encode_path(structure_name) + obj_size = ref.has_kind("") and structure_name in self.copiable_types and \ + "sizeof(%s)" % encode_symbol("obj", structure_name) or \ + "0" + if f_decls: print >>f_decls, "extern %s %s;\n" % (obj_type, obj_name) @@ -887,6 +899,7 @@ %s %s = { &%s, %s, + %s, { %s }, @@ -896,6 +909,7 @@ obj_type, obj_name, table_name, pos, + obj_size, ",\n ".join(structure), trailing and ",\n ".join(trailing) or "") diff -r c8b0c2d6df5c -r fb368817a23b templates/ops.c --- a/templates/ops.c Mon May 20 01:06:05 2024 +0200 +++ b/templates/ops.c Mon May 20 21:26:54 2024 +0200 @@ -1,6 +1,6 @@ /* Common operations. -Copyright (C) 2015, 2016, 2017, 2018, 2023 Paul Boddie +Copyright (C) 2015-2018, 2023, 2024 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -441,14 +441,12 @@ } /* Store an attribute in a target location. For targets that support value - replacement, a copied object is assigned when initialising the target. - - NOTE: Only floats and wrappers are currently supported for value replacement. - A special copy attribute could be employed to make this generic. */ + replacement, a copied object is assigned when initialising the target. */ __attr __set_attr(volatile __attr *target, __attr attr) { __ref obj; + int obj_size; /* Value already replaced in target by an operation. */ @@ -462,10 +460,10 @@ if ((obj != NULL) && __is_instance(obj)) { - if (__get_class(obj) == &__builtins___float_float) - attr = __ATTRVALUE(__COPY(obj, __INSTANCESIZE(__builtins___float_float))); - else if (__get_class(obj) == &__builtins___core_wrapper) - attr = __ATTRVALUE(__COPY(obj, __INSTANCESIZE(__builtins___core_wrapper))); + obj_size = __get_class(obj)->obj_size; + + if (obj_size) + attr = __ATTRVALUE(__COPY(obj, obj_size)); } /* Set and return the attribute. */ diff -r c8b0c2d6df5c -r fb368817a23b templates/types.h --- a/templates/types.h Mon May 20 01:06:05 2024 +0200 +++ b/templates/types.h Mon May 20 21:26:54 2024 +0200 @@ -1,6 +1,6 @@ /* Runtime types. -Copyright (C) 2015-2019, 2021, 2023 Paul Boddie +Copyright (C) 2015-2019, 2021, 2023, 2024 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -107,6 +107,8 @@ { const __table * table; /* attribute table */ __ppos pos; /* position of attribute indicating class */ + __int obj_size; /* object size for copiable objects defined + on class */ __attr attrs[]; /* attributes */ /* Specialisations of this type may add other members.