# HG changeset patch # User Paul Boddie # Date 1693330171 -7200 # Node ID 1fde2e291f5f411cfc2fc5d5ccccfb7150a1cb97 # Parent 1e7ccc84119f6b71d82aaf2d697627364b8b711f Treat integers and sizes identically for convenience. diff -r 1e7ccc84119f -r 1fde2e291f5f generator.py --- a/generator.py Thu Nov 04 23:44:29 2021 +0100 +++ b/generator.py Tue Aug 29 19:29:31 2023 +0200 @@ -1066,7 +1066,7 @@ # Special internal size member. elif attrname == "__size__": - structure.append("{.sizevalue=%d}" % attr) + structure.append("{.intvalue=__FROMINT(%d)}" % attr) continue # Special internal key member. diff -r 1e7ccc84119f -r 1fde2e291f5f templates/native/buffer.c --- a/templates/native/buffer.c Thu Nov 04 23:44:29 2021 +0100 +++ b/templates/native/buffer.c Tue Aug 29 19:29:31 2023 +0200 @@ -36,7 +36,7 @@ /* Calculate the size of the string. */ for (i = 0; i < data->size; i++) - size += __load_via_object(__VALUE(data->attrs[i]), __size__).sizevalue; + size += __TOINT(__load_via_object(__VALUE(data->attrs[i]), __size__)); /* Reserve space for a new string. */ s = (char *) __ALLOCATE(size + 1, sizeof(char)); @@ -45,7 +45,7 @@ for (i = 0, j = 0; i < data->size; i++) { o = __load_via_object(__VALUE(data->attrs[i]), __data__); - n = __load_via_object(__VALUE(data->attrs[i]), __size__).sizevalue; + n = __TOINT(__load_via_object(__VALUE(data->attrs[i]), __size__)); memcpy(s + j, o.strvalue, n); /* does not null terminate but final byte should be zero */ j += n; } diff -r 1e7ccc84119f -r 1fde2e291f5f templates/native/common.c --- a/templates/native/common.c Thu Nov 04 23:44:29 2021 +0100 +++ b/templates/native/common.c Tue Aug 29 19:29:31 2023 +0200 @@ -31,7 +31,7 @@ /* Create a new string and mutate the __data__, __size__ and __key__ attributes. */ __attr attr = __NEWINSTANCE(__builtins___str_str); __store_via_object(__VALUE(attr), __data__, (__attr) {.strvalue=s}); - __store_via_object(__VALUE(attr), __size__, (__attr) {.sizevalue=size}); + __store_via_object(__VALUE(attr), __size__, __INTVALUE(size)); __store_via_object(__VALUE(attr), __key__, __NULL); return attr; } diff -r 1e7ccc84119f -r 1fde2e291f5f templates/native/io.c --- a/templates/native/io.c Thu Nov 04 23:44:29 2021 +0100 +++ b/templates/native/io.c Tue Aug 29 19:29:31 2023 +0200 @@ -150,7 +150,7 @@ /* str.__data__ interpreted as string */ char *s = __load_via_object(__VALUE(str), __data__).strvalue; /* str.__size__ interpreted as int */ - size_t to_write = __load_via_object(__VALUE(str), __size__).sizevalue; + size_t to_write = __TOINT(__load_via_object(__VALUE(str), __size__)); size_t have_written = fwrite(s, sizeof(char), to_write, f); int error; @@ -207,7 +207,7 @@ /* str.__data__ interpreted as string */ char *s = __load_via_object(__VALUE(str), __data__).strvalue; /* str.__size__ interpreted as int */ - size_t size = __load_via_object(__VALUE(str), __size__).sizevalue; + size_t size = __TOINT(__load_via_object(__VALUE(str), __size__)); ssize_t have_written; errno = 0; diff -r 1e7ccc84119f -r 1fde2e291f5f templates/native/str.c --- a/templates/native/str.c Thu Nov 04 23:44:29 2021 +0100 +++ b/templates/native/str.c Tue Aug 29 19:29:31 2023 +0200 @@ -34,7 +34,7 @@ char *s = _data.strvalue; char *o = other.strvalue; /* _size, othersize interpreted as size */ - __int ss = _size.sizevalue, os = othersize.sizevalue; + __int ss = __TOINT(_size), os = __TOINT(othersize); __int n = ss + os; char *r = (char *) __ALLOCATE(n + 1, sizeof(char)); @@ -95,7 +95,7 @@ __attr __fn_native_str_str_size(__attr __self, __attr _size) { - return __new_int(_size.sizevalue); + return __new_int(__TOINT(_size)); } __attr __fn_native_str_str_substr(__attr __self, __attr _data, __attr start, __attr end, __attr step) diff -r 1e7ccc84119f -r 1fde2e291f5f templates/native/unicode.c --- a/templates/native/unicode.c Thu Nov 04 23:44:29 2021 +0100 +++ b/templates/native/unicode.c Tue Aug 29 19:29:31 2023 +0200 @@ -74,7 +74,7 @@ /* _data interpreted as string.__data__ */ char *s = _data.strvalue; /* _size interpreted as size */ - __int size = _size.sizevalue; + __int size = __TOINT(_size); __int i, c = 0; for (i = 0; i < size; i++) @@ -90,7 +90,7 @@ /* _data interpreted as string.__data__ */ char *s = _data.strvalue; /* _size interpreted as size */ - __int size = _size.sizevalue; + __int size = __TOINT(_size); __int i, c = 0, v; for (i = 0; i < size; i++) @@ -124,7 +124,7 @@ /* _data interpreted as string.__data__ */ char *s = _data.strvalue, *sub; /* _size interpreted as size */ - __int ss = _size.sizevalue; + __int ss = __TOINT(_size); /* start interpreted as int */ __int istart = __TOINT(start); /* end interpreted as int */ diff -r 1e7ccc84119f -r 1fde2e291f5f templates/types.h --- a/templates/types.h Thu Nov 04 23:44:29 2021 +0100 +++ b/templates/types.h Tue Aug 29 19:29:31 2023 +0200 @@ -82,7 +82,8 @@ /* General attribute members. */ __ref value; /* attribute value */ - __int intvalue; /* integer value data (shifted value, tagged) */ + __int intvalue; /* integer value data or object-specific size + (shifted value, tagged) */ /* Special case attribute members. */ @@ -95,7 +96,6 @@ char * strvalue; /* string value */ __fragment * seqvalue; /* sequence data */ void * datavalue; /* object-specific data */ - __int sizevalue; /* object-specific size */ } __attr; typedef struct __obj @@ -136,9 +136,10 @@ #define __NULL __ATTRVALUE(0) #define __SETNULL(ATTR) ((ATTR).value = 0) -/* Attribute as instance setting. */ +/* Attribute as instance value. */ -#define __INTVALUE(VALUE) ((__attr) {.intvalue=(((__int) VALUE) << __NUM_TAG_BITS) | __TAG_INT}) +#define __FROMINT(VALUE) ((((__int) VALUE) << __NUM_TAG_BITS) | __TAG_INT) +#define __INTVALUE(VALUE) ((__attr) {.intvalue=__FROMINT(VALUE)}) #define __TOINT(ATTR) ((ATTR).intvalue >> __NUM_TAG_BITS) #define __MAXINT ((((__int) 1) << ((sizeof(__int) * 8) - 1 - __NUM_TAG_BITS)) - 1) #define __MININT (-(((__int) 1) << ((sizeof(__int) * 8) - 1 - __NUM_TAG_BITS)))