1.1 --- a/generator.py Mon May 20 01:06:05 2024 +0200
1.2 +++ b/generator.py Mon May 20 21:26:54 2024 +0200
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Generate C code from object layouts and other deduced information.
1.6
1.7 -Copyright (C) 2015-2019, 2021, 2023 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2015-2019, 2021, 2023, 2024 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -70,6 +70,13 @@
1.13 dict_type, list_type, tuple_type
1.14 )
1.15
1.16 + # Copiable types.
1.17 +
1.18 + copiable_types = [
1.19 + "__builtins__.core.wrapper",
1.20 + float_type,
1.21 + ]
1.22 +
1.23 # Data types with a trailing data member of the given native types.
1.24
1.25 trailing_data_types = {
1.26 @@ -859,6 +866,7 @@
1.27 typedef struct {
1.28 const __table * table;
1.29 __pos pos;
1.30 + __int obj_size;
1.31 __attr attrs[%s];
1.32 %s
1.33 } %s;
1.34 @@ -880,6 +888,10 @@
1.35 obj_type = ref.has_kind("<instance>") and encode_symbol("obj", origin) or "__obj"
1.36 obj_name = encode_path(structure_name)
1.37
1.38 + obj_size = ref.has_kind("<class>") and structure_name in self.copiable_types and \
1.39 + "sizeof(%s)" % encode_symbol("obj", structure_name) or \
1.40 + "0"
1.41 +
1.42 if f_decls:
1.43 print >>f_decls, "extern %s %s;\n" % (obj_type, obj_name)
1.44
1.45 @@ -887,6 +899,7 @@
1.46 %s %s = {
1.47 &%s,
1.48 %s,
1.49 + %s,
1.50 {
1.51 %s
1.52 },
1.53 @@ -896,6 +909,7 @@
1.54 obj_type, obj_name,
1.55 table_name,
1.56 pos,
1.57 + obj_size,
1.58 ",\n ".join(structure),
1.59 trailing and ",\n ".join(trailing) or "")
1.60
2.1 --- a/templates/ops.c Mon May 20 01:06:05 2024 +0200
2.2 +++ b/templates/ops.c Mon May 20 21:26:54 2024 +0200
2.3 @@ -1,6 +1,6 @@
2.4 /* Common operations.
2.5
2.6 -Copyright (C) 2015, 2016, 2017, 2018, 2023 Paul Boddie <paul@boddie.org.uk>
2.7 +Copyright (C) 2015-2018, 2023, 2024 Paul Boddie <paul@boddie.org.uk>
2.8
2.9 This program is free software; you can redistribute it and/or modify it under
2.10 the terms of the GNU General Public License as published by the Free Software
2.11 @@ -441,14 +441,12 @@
2.12 }
2.13
2.14 /* Store an attribute in a target location. For targets that support value
2.15 - replacement, a copied object is assigned when initialising the target.
2.16 -
2.17 - NOTE: Only floats and wrappers are currently supported for value replacement.
2.18 - A special copy attribute could be employed to make this generic. */
2.19 + replacement, a copied object is assigned when initialising the target. */
2.20
2.21 __attr __set_attr(volatile __attr *target, __attr attr)
2.22 {
2.23 __ref obj;
2.24 + int obj_size;
2.25
2.26 /* Value already replaced in target by an operation. */
2.27
2.28 @@ -462,10 +460,10 @@
2.29
2.30 if ((obj != NULL) && __is_instance(obj))
2.31 {
2.32 - if (__get_class(obj) == &__builtins___float_float)
2.33 - attr = __ATTRVALUE(__COPY(obj, __INSTANCESIZE(__builtins___float_float)));
2.34 - else if (__get_class(obj) == &__builtins___core_wrapper)
2.35 - attr = __ATTRVALUE(__COPY(obj, __INSTANCESIZE(__builtins___core_wrapper)));
2.36 + obj_size = __get_class(obj)->obj_size;
2.37 +
2.38 + if (obj_size)
2.39 + attr = __ATTRVALUE(__COPY(obj, obj_size));
2.40 }
2.41
2.42 /* Set and return the attribute. */
3.1 --- a/templates/types.h Mon May 20 01:06:05 2024 +0200
3.2 +++ b/templates/types.h Mon May 20 21:26:54 2024 +0200
3.3 @@ -1,6 +1,6 @@
3.4 /* Runtime types.
3.5
3.6 -Copyright (C) 2015-2019, 2021, 2023 Paul Boddie <paul@boddie.org.uk>
3.7 +Copyright (C) 2015-2019, 2021, 2023, 2024 Paul Boddie <paul@boddie.org.uk>
3.8
3.9 This program is free software; you can redistribute it and/or modify it under
3.10 the terms of the GNU General Public License as published by the Free Software
3.11 @@ -107,6 +107,8 @@
3.12 {
3.13 const __table * table; /* attribute table */
3.14 __ppos pos; /* position of attribute indicating class */
3.15 + __int obj_size; /* object size for copiable objects defined
3.16 + on class */
3.17 __attr attrs[]; /* attributes */
3.18
3.19 /* Specialisations of this type may add other members.