# HG changeset patch # User Paul Boddie # Date 1635634870 -7200 # Node ID d697508a12c0afbfaed617ba10a209bd7cef4e76 # Parent 6ddce984649bb8991108ed9e948e8a2379e1125b Introduced a dedicated integer type based on ssize_t. This allows integers to be used for sizes and lengths in native and low-level operations whilst also supporting their storage in the same amount of space as a pointer, thus avoiding the inflation of attributes that might occur if a larger type were chosen. diff -r 6ddce984649b -r d697508a12c0 templates/native/buffer.c --- a/templates/native/buffer.c Sat Oct 30 23:09:57 2021 +0200 +++ b/templates/native/buffer.c Sun Oct 31 01:01:10 2021 +0200 @@ -1,6 +1,6 @@ /* Native functions for buffer operations. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 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 @@ -30,7 +30,7 @@ { /* _data interpreted as buffer.__data__ */ __fragment *data = _data.seqvalue; - unsigned int size = 0, i, j, n; + __int size = 0, i, j, n; char *s; __attr o; diff -r 6ddce984649b -r d697508a12c0 templates/native/common.c --- a/templates/native/common.c Sat Oct 30 23:09:57 2021 +0200 +++ b/templates/native/common.c Sun Oct 31 01:01:10 2021 +0200 @@ -26,7 +26,7 @@ /* Utility functions. */ -__attr __new_str(char *s, int size) +__attr __new_str(char *s, __int size) { /* Create a new string and mutate the __data__, __size__ and __key__ attributes. */ __attr attr = __NEWINSTANCE(__builtins___str_str); @@ -47,8 +47,8 @@ __fragment *__fragment_append(__fragment *data, __attr value) { __fragment *newdata = data; - unsigned int size = data->size, capacity = data->capacity; - unsigned int n; + __int size = data->size, capacity = data->capacity; + __int n; /* Re-allocate the fragment if the capacity has been reached. */ if (size >= capacity) diff -r 6ddce984649b -r d697508a12c0 templates/native/common.h --- a/templates/native/common.h Sat Oct 30 23:09:57 2021 +0200 +++ b/templates/native/common.h Sun Oct 31 01:01:10 2021 +0200 @@ -24,7 +24,7 @@ /* Utility functions. */ #define __new_int(VALUE) __INTVALUE(VALUE) -__attr __new_str(char *s, int size); +__attr __new_str(char *s, __int size); __attr __new_list(__fragment *f); __fragment *__fragment_append(__fragment *data, __attr value); diff -r 6ddce984649b -r d697508a12c0 templates/native/iconv.c --- a/templates/native/iconv.c Sat Oct 30 23:09:57 2021 +0200 +++ b/templates/native/iconv.c Sun Oct 31 01:01:10 2021 +0200 @@ -1,6 +1,6 @@ /* Native functions for character set conversion. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 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 @@ -56,8 +56,8 @@ /* Obtain the string, start position, and remaining bytes from the state. */ char *inbuf = __load_via_object(__VALUE(f->attrs[0]), __data__).strvalue; - int start = __TOINT(f->attrs[1]); - int remaining = __TOINT(f->attrs[2]); + __int start = __TOINT(f->attrs[1]); + __int remaining = __TOINT(f->attrs[2]); /* Allocate a string for the output buffer using the remaining input size as a guide. */ diff -r 6ddce984649b -r d697508a12c0 templates/native/int.c --- a/templates/native/int.c Sat Oct 30 23:09:57 2021 +0200 +++ b/templates/native/int.c Sun Oct 31 01:01:10 2021 +0200 @@ -1,6 +1,6 @@ /* Native functions for integer operations. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 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 @@ -39,8 +39,8 @@ __attr __fn_native_int_int_add(__attr __self, __attr self, __attr other) { /* self and other interpreted as int */ - int i = __TOINT(self); - int j = __TOINT(other); + __int i = __TOINT(self); + __int j = __TOINT(other); /* Test for overflow. */ if (((i > 0) && (j > 0) && (i > __MAXINT - j)) || @@ -55,8 +55,8 @@ __attr __fn_native_int_int_sub(__attr __self, __attr self, __attr other) { /* self and other interpreted as int */ - int i = __TOINT(self); - int j = __TOINT(other); + __int i = __TOINT(self); + __int j = __TOINT(other); /* Test for overflow. */ if (((i < 0) && (j > 0) && (i < __MININT + j)) || @@ -71,8 +71,8 @@ __attr __fn_native_int_int_mul(__attr __self, __attr self, __attr other) { /* self and other interpreted as int */ - int i = __TOINT(self); - int j = __TOINT(other); + __int i = __TOINT(self); + __int j = __TOINT(other); /* Test for overflow. */ if (((i > 0) && (j > 0) && (i > __MAXINT / j)) || @@ -89,8 +89,8 @@ __attr __fn_native_int_int_div(__attr __self, __attr self, __attr other) { /* self and other interpreted as int */ - int i = __TOINT(self); - int j = __TOINT(other); + __int i = __TOINT(self); + __int j = __TOINT(other); /* Test for division by zero or overflow. */ if (j == 0) @@ -105,8 +105,8 @@ __attr __fn_native_int_int_mod(__attr __self, __attr self, __attr other) { /* self and other interpreted as int */ - int i = __TOINT(self); - int j = __TOINT(other); + __int i = __TOINT(self); + __int j = __TOINT(other); /* Test for division by zero or overflow. */ if (j == 0) @@ -121,7 +121,7 @@ __attr __fn_native_int_int_neg(__attr __self, __attr self) { /* self interpreted as int */ - int i = __TOINT(self); + __int i = __TOINT(self); /* Test for overflow. */ if (i == __MININT) @@ -134,8 +134,8 @@ __attr __fn_native_int_int_pow(__attr __self, __attr self, __attr other) { /* self and other interpreted as int */ - int i = __TOINT(self); - int j = __TOINT(other); + __int i = __TOINT(self); + __int j = __TOINT(other); int k; errno = 0; @@ -157,8 +157,8 @@ __attr __fn_native_int_int_and(__attr __self, __attr self, __attr other) { /* self and other interpreted as int */ - int i = __TOINT(self); - int j = __TOINT(other); + __int i = __TOINT(self); + __int j = __TOINT(other); /* Return the new integer. */ /* NOTE: No overflow test applied. */ @@ -168,7 +168,7 @@ __attr __fn_native_int_int_not(__attr __self, __attr self) { /* self interpreted as int */ - int i = __TOINT(self); + __int i = __TOINT(self); /* Return the new integer. */ return __new_int(~i); @@ -177,8 +177,8 @@ __attr __fn_native_int_int_or(__attr __self, __attr self, __attr other) { /* self and other interpreted as int */ - int i = __TOINT(self); - int j = __TOINT(other); + __int i = __TOINT(self); + __int j = __TOINT(other); /* Return the new integer. */ /* NOTE: No overflow test applied. */ @@ -188,8 +188,8 @@ __attr __fn_native_int_int_xor(__attr __self, __attr self, __attr other) { /* self and other interpreted as int */ - int i = __TOINT(self); - int j = __TOINT(other); + __int i = __TOINT(self); + __int j = __TOINT(other); /* Return the new integer. */ /* NOTE: No overflow test applied. */ @@ -199,8 +199,8 @@ __attr __fn_native_int_int_lshift(__attr __self, __attr self, __attr other) { /* self and other interpreted as int */ - int i = __TOINT(self); - int j = __TOINT(other); + __int i = __TOINT(self); + __int j = __TOINT(other); /* Return the new integer. */ /* NOTE: No overflow test applied. */ @@ -210,8 +210,8 @@ __attr __fn_native_int_int_rshift(__attr __self, __attr self, __attr other) { /* self and other interpreted as int */ - int i = __TOINT(self); - int j = __TOINT(other); + __int i = __TOINT(self); + __int j = __TOINT(other); /* Return the new integer. */ /* NOTE: No overflow test applied. */ @@ -221,8 +221,8 @@ __attr __fn_native_int_int_le(__attr __self, __attr self, __attr other) { /* self and other interpreted as int */ - int i = __TOINT(self); - int j = __TOINT(other); + __int i = __TOINT(self); + __int j = __TOINT(other); /* Return a boolean result. */ return i <= j ? __builtins___boolean_True : __builtins___boolean_False; @@ -231,8 +231,8 @@ __attr __fn_native_int_int_lt(__attr __self, __attr self, __attr other) { /* self and other interpreted as int */ - int i = __TOINT(self); - int j = __TOINT(other); + __int i = __TOINT(self); + __int j = __TOINT(other); /* Return a boolean result. */ return i < j ? __builtins___boolean_True : __builtins___boolean_False; @@ -241,8 +241,8 @@ __attr __fn_native_int_int_ge(__attr __self, __attr self, __attr other) { /* self and other interpreted as int */ - int i = __TOINT(self); - int j = __TOINT(other); + __int i = __TOINT(self); + __int j = __TOINT(other); /* Return a boolean result. */ return i >= j ? __builtins___boolean_True : __builtins___boolean_False; @@ -251,8 +251,8 @@ __attr __fn_native_int_int_gt(__attr __self, __attr self, __attr other) { /* self and other interpreted as int */ - int i = __TOINT(self); - int j = __TOINT(other); + __int i = __TOINT(self); + __int j = __TOINT(other); /* Return a boolean result. */ return i > j ? __builtins___boolean_True : __builtins___boolean_False; @@ -261,8 +261,8 @@ __attr __fn_native_int_int_eq(__attr __self, __attr self, __attr other) { /* self and other interpreted as int */ - int i = __TOINT(self); - int j = __TOINT(other); + __int i = __TOINT(self); + __int j = __TOINT(other); /* Return a boolean result. */ return i == j ? __builtins___boolean_True : __builtins___boolean_False; @@ -271,8 +271,8 @@ __attr __fn_native_int_int_ne(__attr __self, __attr self, __attr other) { /* self and other interpreted as int */ - int i = __TOINT(self); - int j = __TOINT(other); + __int i = __TOINT(self); + __int j = __TOINT(other); /* Return a boolean result. */ return i != j ? __builtins___boolean_True : __builtins___boolean_False; @@ -281,14 +281,14 @@ __attr __fn_native_int_int_str(__attr __self, __attr self) { /* self interpreted as int */ - int i = __TOINT(self); + __int i = __TOINT(self); /* Employ a buffer big enough to fit the largest integer plus an extra character, a minus sign, and the null terminator. */ unsigned int n = (int) log10(__MAXINT) + 3; char *s = (char *) __ALLOCATE(n, sizeof(char)); - snprintf(s, n, "%d", i); + snprintf(s, n, "%ld", i); /* Return a new string. */ return __new_str(s, strlen(s)); diff -r 6ddce984649b -r d697508a12c0 templates/native/io.c --- a/templates/native/io.c Sat Oct 30 23:09:57 2021 +0200 +++ b/templates/native/io.c Sun Oct 31 01:01:10 2021 +0200 @@ -1,6 +1,6 @@ /* Native functions for input/output. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 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 @@ -120,7 +120,7 @@ /* fp interpreted as FILE reference */ FILE *f = (FILE *) fp.datavalue; /* size interpreted as int */ - int to_read = __TOINT(size); + size_t to_read = __TOINT(size); char buf[to_read]; size_t have_read; int error; @@ -150,7 +150,7 @@ /* str.__data__ interpreted as string */ char *s = __load_via_object(__VALUE(str), __data__).strvalue; /* str.__size__ interpreted as int */ - int to_write = __TOINT(__load_via_object(__VALUE(str), __size__)); + size_t to_write = __TOINT(__load_via_object(__VALUE(str), __size__)); size_t have_written = fwrite(s, sizeof(char), to_write, f); int error; @@ -182,7 +182,7 @@ /* fd interpreted as int */ int i = __TOINT(fd); /* n interpreted as int */ - int to_read = __TOINT(n); + size_t to_read = __TOINT(n); char buf[to_read]; ssize_t have_read; char *s; @@ -207,7 +207,7 @@ /* str.__data__ interpreted as string */ char *s = __load_via_object(__VALUE(str), __data__).strvalue; /* str.__size__ interpreted as int */ - int size = __TOINT(__load_via_object(__VALUE(str), __size__)); + size_t size = __TOINT(__load_via_object(__VALUE(str), __size__)); ssize_t have_written; errno = 0; diff -r 6ddce984649b -r d697508a12c0 templates/native/list.c --- a/templates/native/list.c Sat Oct 30 23:09:57 2021 +0200 +++ b/templates/native/list.c Sun Oct 31 01:01:10 2021 +0200 @@ -1,6 +1,6 @@ /* Native functions for list operations. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 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 @@ -30,7 +30,7 @@ __attr __fn_native_list_list_init(__attr __self, __attr size) { /* size interpreted as int */ - unsigned int n = __TOINT(size); + __int n = __TOINT(size); __attr attr = {.seqvalue=__new_fragment(n)}; /* Return the __data__ attribute. */ @@ -42,7 +42,7 @@ /* _data interpreted as list.__data__ */ __fragment *data = _data.seqvalue; /* size interpreted as int */ - unsigned int n = __TOINT(size); + __int n = __TOINT(size); data->size = n; return __builtins___none_None; @@ -66,9 +66,9 @@ __fragment *data = __load_via_object(__VALUE(self), __data__).seqvalue; __fragment *other_data = other.seqvalue; __fragment *newdata = data; - unsigned int size = data->size, capacity = data->capacity; - unsigned int other_size = other_data->size; - unsigned int i, j, n = size + other_size; + __int size = data->size, capacity = data->capacity; + __int other_size = other_data->size; + __int i, j, n = size + other_size; /* Re-allocate the fragment if the capacity has been reached. */ if (n >= capacity) @@ -91,7 +91,7 @@ __attr __fn_native_list_list_len(__attr self, __attr _data) { /* _data interpreted as list.__data__ */ - unsigned int size = _data.seqvalue->size; + __int size = _data.seqvalue->size; /* Return the new integer. */ return __new_int(size); @@ -107,7 +107,7 @@ /* _data interpreted as list.__data__ */ __attr *elements = _data.seqvalue->attrs; /* index interpreted as int */ - int i = __TOINT(index); + __int i = __TOINT(index); return elements[i]; } @@ -117,7 +117,7 @@ /* _data interpreted as list.__data__ */ __attr *elements = _data.seqvalue->attrs; /* index interpreted as int */ - int i = __TOINT(index); + __int i = __TOINT(index); /* Set the element. */ elements[i] = value; diff -r 6ddce984649b -r d697508a12c0 templates/native/str.c --- a/templates/native/str.c Sat Oct 30 23:09:57 2021 +0200 +++ b/templates/native/str.c Sun Oct 31 01:01:10 2021 +0200 @@ -1,6 +1,6 @@ /* Native functions for string operations. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 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 @@ -34,8 +34,8 @@ char *s = _data.strvalue; char *o = other.strvalue; /* _size, othersize interpreted as int */ - int ss = __TOINT(_size), os = __TOINT(othersize); - int n = ss + os; + __int ss = __TOINT(_size), os = __TOINT(othersize); + __int n = ss + os; char *r = (char *) __ALLOCATE(n + 1, sizeof(char)); memcpy(r, s, ss); @@ -90,7 +90,7 @@ /* _data interpreted as string.__data__ */ char *s = _data.strvalue; - return __new_int((unsigned int) s[0]); + return __new_int((__int) s[0]); } __attr __fn_native_str_str_substr(__attr __self, __attr _data, __attr start, __attr end, __attr step) @@ -98,15 +98,15 @@ /* _data interpreted as string.__data__ */ char *s = _data.strvalue, *sub; /* start interpreted as int */ - int istart = __TOINT(start); + __int istart = __TOINT(start); /* end interpreted as int */ - int iend = __TOINT(end); + __int iend = __TOINT(end); /* step interpreted as int */ - int istep = __TOINT(step); + __int istep = __TOINT(step); /* Calculate the size of the substring. */ size_t resultsize = ((iend - istart - (istep > 0 ? 1 : -1)) / istep) + 1; - int to, from; + size_t to, from; /* Reserve space for a new string. */ sub = (char *) __ALLOCATE(resultsize + 1, sizeof(char)); diff -r 6ddce984649b -r d697508a12c0 templates/native/system.c --- a/templates/native/system.c Sat Oct 30 23:09:57 2021 +0200 +++ b/templates/native/system.c Sun Oct 31 01:01:10 2021 +0200 @@ -1,6 +1,6 @@ /* Native functions for system operations. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 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 diff -r 6ddce984649b -r d697508a12c0 templates/native/tuple.c --- a/templates/native/tuple.c Sat Oct 30 23:09:57 2021 +0200 +++ b/templates/native/tuple.c Sun Oct 31 01:01:10 2021 +0200 @@ -1,6 +1,6 @@ /* Native functions for tuple operations. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 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 @@ -32,7 +32,7 @@ __attr __fn_native_tuple_tuple_init(__attr __self, __attr size) { /* size interpreted as int */ - int n = __TOINT(size); + __int n = __TOINT(size); /* Return the __data__ attribute. */ if (n) return (__attr) {.seqvalue=__new_fragment(n)}; diff -r 6ddce984649b -r d697508a12c0 templates/native/unicode.c --- a/templates/native/unicode.c Sat Oct 30 23:09:57 2021 +0200 +++ b/templates/native/unicode.c Sun Oct 31 01:01:10 2021 +0200 @@ -1,6 +1,6 @@ /* Native functions for Unicode operations. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 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 @@ -39,9 +39,9 @@ else return 0; } -static unsigned int nextpos(char *s, unsigned int size, unsigned int bytestart) +static __int nextpos(char *s, __int size, __int bytestart) { - unsigned int i = bytestart; + __int i = bytestart; while (i < size) { @@ -53,9 +53,9 @@ return i; } -static unsigned int prevpos(char *s, unsigned int bytestart) +static __int prevpos(char *s, __int bytestart) { - unsigned int i = bytestart; + __int i = bytestart; while (i > 0) { @@ -74,8 +74,8 @@ /* _data interpreted as string.__data__ */ char *s = _data.strvalue; /* _size interpreted as int */ - int size = __TOINT(_size); - unsigned int i, c = 0; + __int size = __TOINT(_size); + __int i, c = 0; for (i = 0; i < size; i++) if (boundary(s[i])) @@ -90,8 +90,8 @@ /* _data interpreted as string.__data__ */ char *s = _data.strvalue; /* _size interpreted as int */ - int size = __TOINT(_size); - unsigned int i, c = 0, v; + __int size = __TOINT(_size); + __int i, c = 0, v; for (i = 0; i < size; i++) { @@ -124,20 +124,20 @@ /* _data interpreted as string.__data__ */ char *s = _data.strvalue, *sub; /* _size interpreted as int */ - int ss = __TOINT(_size); + __int ss = __TOINT(_size); /* start interpreted as int */ - int istart = __TOINT(start); + __int istart = __TOINT(start); /* end interpreted as int */ - int iend = __TOINT(end); + __int iend = __TOINT(end); /* step interpreted as int */ - int istep = __TOINT(step); + __int istep = __TOINT(step); /* Calculate the number of characters. */ - size_t nchar = ((iend - istart - (istep > 0 ? 1 : -1)) / istep) + 1; - unsigned int indexes[nchar]; + __int nchar = ((iend - istart - (istep > 0 ? 1 : -1)) / istep) + 1; + __int indexes[nchar]; - unsigned int c, d, i, to, from, lastbyte = 0; - int resultsize = 0; + __int c, d, i, to, from, lastbyte = 0; + __int resultsize = 0; /* Find the indexes of the characters. */ if (istep > 0) @@ -197,7 +197,7 @@ { /* value interpreted as int */ int i = __TOINT(value); - unsigned int resultsize; + __int resultsize; char *s; if (i < 128) resultsize = 1; diff -r 6ddce984649b -r d697508a12c0 templates/progops.c --- a/templates/progops.c Sat Oct 30 23:09:57 2021 +0200 +++ b/templates/progops.c Sun Oct 31 01:01:10 2021 +0200 @@ -49,7 +49,7 @@ /* Generic internal data allocation. */ -__fragment *__new_fragment(unsigned int n) +__fragment *__new_fragment(__int n) { /* Allocate space for the list. */ @@ -62,9 +62,9 @@ return data; } -void __newdata_sequence(unsigned int number, __fragment *data, __attr args[]) +void __newdata_sequence(__int number, __fragment *data, __attr args[]) { - unsigned int i; + __int i; /* Copy the given number of values. */ @@ -74,7 +74,7 @@ data->size = number; } -__attr __newdata_list(unsigned int number, __attr args[]) +__attr __newdata_list(__int number, __attr args[]) { __attr self = __NEWINSTANCE(__builtins___list_list); __fragment *data = __new_fragment(number); @@ -86,7 +86,7 @@ return self; } -__attr __newdata_tuple(unsigned int number, __attr args[]) +__attr __newdata_tuple(__int number, __attr args[]) { /* Allocate the tuple and fragment together. */ @@ -103,7 +103,7 @@ } #ifdef __HAVE___builtins___dict_dict -__attr __newdata_dict(unsigned int number, __attr args[]) +__attr __newdata_dict(__int number, __attr args[]) { __attr self = __NEWINSTANCE(__builtins___dict_dict); @@ -313,10 +313,11 @@ { __ref value; - /* Integers can be used directly as truth values. */ + /* Non-zero integers yield a non-zero result. Since the integer type can be + larger than int, a conversion is performed. */ if (__INTEGER(attr)) - return __TOINT(attr); + return __TOINT(attr) ? 1 : 0; /* Test against True and False explicitly. If necessary, invoke the bool function with the object and test against True. */ diff -r 6ddce984649b -r d697508a12c0 templates/progops.h --- a/templates/progops.h Sat Oct 30 23:09:57 2021 +0200 +++ b/templates/progops.h Sun Oct 31 01:01:10 2021 +0200 @@ -30,16 +30,16 @@ /* Generic internal data allocation. */ -__fragment *__new_fragment(unsigned int n); +__fragment *__new_fragment(__int n); -__attr __newdata_list(unsigned int number, __attr args[]); -__attr __newdata_tuple(unsigned int number, __attr args[]); +__attr __newdata_list(__int number, __attr args[]); +__attr __newdata_tuple(__int number, __attr args[]); #define __newliteral___builtins___list_list(NUM, ...) __newdata_list(NUM, __ARGS(__VA_ARGS__)) #define __newliteral___builtins___tuple_tuple(NUM, ...) __newdata_tuple(NUM, __ARGS(__VA_ARGS__)) #ifdef __HAVE___builtins___dict_dict -__attr __newdata_dict(unsigned int number, __attr args[]); +__attr __newdata_dict(__int number, __attr args[]); #define __newliteral___builtins___dict_dict(NUM, ...) __newdata_dict(NUM, __ARGS(__VA_ARGS__)) #endif /* __HAVE___builtins___dict_dict */ diff -r 6ddce984649b -r d697508a12c0 templates/types.h --- a/templates/types.h Sat Oct 30 23:09:57 2021 +0200 +++ b/templates/types.h Sun Oct 31 01:01:10 2021 +0200 @@ -1,6 +1,7 @@ /* Runtime types. -Copyright (C) 2015, 2016, 2017, 2018, 2019 Paul Boddie +Copyright (C) 2015, 2016, 2017, 2018, 2019, + 2021 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 @@ -23,6 +24,7 @@ program specifically. */ #include +#include /* Include the special instance position value. The pos member of __obj refers to the special type attribute for classes, indicating which position holds @@ -70,12 +72,19 @@ typedef union __attr __attr; typedef __obj * __ref; +/* Introduce an integer type that should not exceed the size of the pointer + type. */ + +typedef ssize_t __int; + +/* Attribute value interpretations. */ + typedef union __attr { /* General attribute members. */ __ref value; /* attribute value */ - int intvalue; /* integer value data (shifted value, tagged) */ + __int intvalue; /* integer value data (shifted value, tagged) */ /* Special case attribute members. */ @@ -105,11 +114,11 @@ typedef struct __fragment { - unsigned int size, capacity; + __int size, capacity; __attr attrs[]; } __fragment; -#define __FRAGMENT_SIZE(NUMBER) ((NUMBER) * sizeof(__attr) + 2 * sizeof(unsigned int)) +#define __FRAGMENT_SIZE(NUMBER) ((NUMBER) * sizeof(__attr) + 2 * sizeof(__int)) /* Attribute interpretation. */ @@ -125,10 +134,10 @@ /* Attribute as instance setting. */ -#define __INTVALUE(VALUE) ((__attr) {.intvalue=((VALUE) << __NUM_TAG_BITS) | __TAG_INT}) +#define __INTVALUE(VALUE) ((__attr) {.intvalue=(((__int) VALUE) << __NUM_TAG_BITS) | __TAG_INT}) #define __TOINT(ATTR) ((ATTR).intvalue >> __NUM_TAG_BITS) -#define __MAXINT ((1 << ((sizeof(int) * 8) - 1 - __NUM_TAG_BITS)) - 1) -#define __MININT (-(1 << ((sizeof(int) * 8) - 1 - __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))) /* Argument lists. */