1.1 --- a/generator.py Tue Aug 29 18:37:11 2023 +0200
1.2 +++ b/generator.py Tue Aug 29 19:30:28 2023 +0200
1.3 @@ -1071,7 +1071,7 @@
1.4 # Special internal size member.
1.5
1.6 elif attrname == "__size__":
1.7 - structure.append("{.sizevalue=%d}" % attr)
1.8 + structure.append("{.intvalue=__FROMINT(%d)}" % attr)
1.9 continue
1.10
1.11 # Special internal key member.
2.1 --- a/templates/native/buffer.c Tue Aug 29 18:37:11 2023 +0200
2.2 +++ b/templates/native/buffer.c Tue Aug 29 19:30:28 2023 +0200
2.3 @@ -36,7 +36,7 @@
2.4
2.5 /* Calculate the size of the string. */
2.6 for (i = 0; i < data->size; i++)
2.7 - size += __load_via_object(__VALUE(data->attrs[i]), __size__).sizevalue;
2.8 + size += __TOINT(__load_via_object(__VALUE(data->attrs[i]), __size__));
2.9
2.10 /* Reserve space for a new string. */
2.11 s = (char *) __ALLOCATE(size + 1, sizeof(char));
2.12 @@ -45,7 +45,7 @@
2.13 for (i = 0, j = 0; i < data->size; i++)
2.14 {
2.15 o = __load_via_object(__VALUE(data->attrs[i]), __data__);
2.16 - n = __load_via_object(__VALUE(data->attrs[i]), __size__).sizevalue;
2.17 + n = __TOINT(__load_via_object(__VALUE(data->attrs[i]), __size__));
2.18 memcpy(s + j, o.strvalue, n); /* does not null terminate but final byte should be zero */
2.19 j += n;
2.20 }
3.1 --- a/templates/native/common.c Tue Aug 29 18:37:11 2023 +0200
3.2 +++ b/templates/native/common.c Tue Aug 29 19:30:28 2023 +0200
3.3 @@ -31,7 +31,7 @@
3.4 /* Create a new string and mutate the __data__, __size__ and __key__ attributes. */
3.5 __attr attr = __NEWINSTANCE(__builtins___str_str);
3.6 __store_via_object(__VALUE(attr), __data__, (__attr) {.strvalue=s});
3.7 - __store_via_object(__VALUE(attr), __size__, (__attr) {.sizevalue=size});
3.8 + __store_via_object(__VALUE(attr), __size__, __INTVALUE(size));
3.9 __store_via_object(__VALUE(attr), __key__, __NULL);
3.10 return attr;
3.11 }
4.1 --- a/templates/native/io.c Tue Aug 29 18:37:11 2023 +0200
4.2 +++ b/templates/native/io.c Tue Aug 29 19:30:28 2023 +0200
4.3 @@ -150,7 +150,7 @@
4.4 /* str.__data__ interpreted as string */
4.5 char *s = __load_via_object(__VALUE(str), __data__).strvalue;
4.6 /* str.__size__ interpreted as int */
4.7 - size_t to_write = __load_via_object(__VALUE(str), __size__).sizevalue;
4.8 + size_t to_write = __TOINT(__load_via_object(__VALUE(str), __size__));
4.9 size_t have_written = fwrite(s, sizeof(char), to_write, f);
4.10 int error;
4.11
4.12 @@ -207,7 +207,7 @@
4.13 /* str.__data__ interpreted as string */
4.14 char *s = __load_via_object(__VALUE(str), __data__).strvalue;
4.15 /* str.__size__ interpreted as int */
4.16 - size_t size = __load_via_object(__VALUE(str), __size__).sizevalue;
4.17 + size_t size = __TOINT(__load_via_object(__VALUE(str), __size__));
4.18 ssize_t have_written;
4.19
4.20 errno = 0;
5.1 --- a/templates/native/str.c Tue Aug 29 18:37:11 2023 +0200
5.2 +++ b/templates/native/str.c Tue Aug 29 19:30:28 2023 +0200
5.3 @@ -34,7 +34,7 @@
5.4 char *s = _data.strvalue;
5.5 char *o = other.strvalue;
5.6 /* _size, othersize interpreted as size */
5.7 - __int ss = _size.sizevalue, os = othersize.sizevalue;
5.8 + __int ss = __TOINT(_size), os = __TOINT(othersize);
5.9 __int n = ss + os;
5.10 char *r = (char *) __ALLOCATE(n + 1, sizeof(char));
5.11
5.12 @@ -95,7 +95,7 @@
5.13
5.14 __attr __fn_native_str_str_size(__attr __result, __attr __self, __attr _size)
5.15 {
5.16 - return __new_int(_size.sizevalue);
5.17 + return __new_int(__TOINT(_size));
5.18 }
5.19
5.20 __attr __fn_native_str_str_substr(__attr __result, __attr __self, __attr _data, __attr start, __attr end, __attr step)
6.1 --- a/templates/native/unicode.c Tue Aug 29 18:37:11 2023 +0200
6.2 +++ b/templates/native/unicode.c Tue Aug 29 19:30:28 2023 +0200
6.3 @@ -74,7 +74,7 @@
6.4 /* _data interpreted as string.__data__ */
6.5 char *s = _data.strvalue;
6.6 /* _size interpreted as size */
6.7 - __int size = _size.sizevalue;
6.8 + __int size = __TOINT(_size);
6.9 __int i, c = 0;
6.10
6.11 for (i = 0; i < size; i++)
6.12 @@ -90,7 +90,7 @@
6.13 /* _data interpreted as string.__data__ */
6.14 char *s = _data.strvalue;
6.15 /* _size interpreted as size */
6.16 - __int size = _size.sizevalue;
6.17 + __int size = __TOINT(_size);
6.18 __int i, c = 0, v;
6.19
6.20 for (i = 0; i < size; i++)
6.21 @@ -124,7 +124,7 @@
6.22 /* _data interpreted as string.__data__ */
6.23 char *s = _data.strvalue, *sub;
6.24 /* _size interpreted as size */
6.25 - __int ss = _size.sizevalue;
6.26 + __int ss = __TOINT(_size);
6.27 /* start interpreted as int */
6.28 __int istart = __TOINT(start);
6.29 /* end interpreted as int */
7.1 --- a/templates/types.h Tue Aug 29 18:37:11 2023 +0200
7.2 +++ b/templates/types.h Tue Aug 29 19:30:28 2023 +0200
7.3 @@ -86,7 +86,8 @@
7.4 /* General attribute members. */
7.5
7.6 __ref value; /* attribute value */
7.7 - __int intvalue; /* integer value data (shifted value, tagged) */
7.8 + __int intvalue; /* integer value data or object-specific size
7.9 + (shifted value, tagged) */
7.10 __ref_tagged refvalue; /* attribute value with tag */
7.11
7.12 /* Special case attribute members. */
7.13 @@ -100,7 +101,6 @@
7.14 char * strvalue; /* string value */
7.15 __fragment * seqvalue; /* sequence data */
7.16 void * datavalue; /* object-specific data */
7.17 - __int sizevalue; /* object-specific size */
7.18 } __attr;
7.19
7.20 typedef struct __obj
7.21 @@ -141,9 +141,10 @@
7.22 #define __NULL __ATTRVALUE(0)
7.23 #define __SETNULL(ATTR) ((ATTR).value = 0)
7.24
7.25 -/* Attribute as instance setting. */
7.26 +/* Attribute as instance value. */
7.27
7.28 -#define __INTVALUE(VALUE) ((__attr) {.intvalue=(((__int) VALUE) << __NUM_TAG_BITS) | __TAG_INT})
7.29 +#define __FROMINT(VALUE) ((((__int) VALUE) << __NUM_TAG_BITS) | __TAG_INT)
7.30 +#define __INTVALUE(VALUE) ((__attr) {.intvalue=__FROMINT(VALUE)})
7.31 #define __TOINT(ATTR) ((ATTR).intvalue >> __NUM_TAG_BITS)
7.32 #define __MAXINT ((((__int) 1) << ((sizeof(__int) * 8) - 1 - __NUM_TAG_BITS)) - 1)
7.33 #define __MININT (-(((__int) 1) << ((sizeof(__int) * 8) - 1 - __NUM_TAG_BITS)))