Lichen

Changeset

941:d697508a12c0
2021-10-31 Paul Boddie raw files shortlog changelog graph 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.
templates/native/buffer.c (file) templates/native/common.c (file) templates/native/common.h (file) templates/native/iconv.c (file) templates/native/int.c (file) templates/native/io.c (file) templates/native/list.c (file) templates/native/str.c (file) templates/native/system.c (file) templates/native/tuple.c (file) templates/native/unicode.c (file) templates/progops.c (file) templates/progops.h (file) templates/types.h (file)
     1.1 --- a/templates/native/buffer.c	Sat Oct 30 23:09:57 2021 +0200
     1.2 +++ b/templates/native/buffer.c	Sun Oct 31 01:01:10 2021 +0200
     1.3 @@ -1,6 +1,6 @@
     1.4  /* Native functions for buffer operations.
     1.5  
     1.6 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
     1.7 +Copyright (C) 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
     1.8  
     1.9  This program is free software; you can redistribute it and/or modify it under
    1.10  the terms of the GNU General Public License as published by the Free Software
    1.11 @@ -30,7 +30,7 @@
    1.12  {
    1.13      /* _data interpreted as buffer.__data__ */
    1.14      __fragment *data = _data.seqvalue;
    1.15 -    unsigned int size = 0, i, j, n;
    1.16 +    __int size = 0, i, j, n;
    1.17      char *s;
    1.18      __attr o;
    1.19  
     2.1 --- a/templates/native/common.c	Sat Oct 30 23:09:57 2021 +0200
     2.2 +++ b/templates/native/common.c	Sun Oct 31 01:01:10 2021 +0200
     2.3 @@ -26,7 +26,7 @@
     2.4  
     2.5  /* Utility functions. */
     2.6  
     2.7 -__attr __new_str(char *s, int size)
     2.8 +__attr __new_str(char *s, __int size)
     2.9  {
    2.10      /* Create a new string and mutate the __data__, __size__ and __key__ attributes. */
    2.11      __attr attr = __NEWINSTANCE(__builtins___str_str);
    2.12 @@ -47,8 +47,8 @@
    2.13  __fragment *__fragment_append(__fragment *data, __attr value)
    2.14  {
    2.15      __fragment *newdata = data;
    2.16 -    unsigned int size = data->size, capacity = data->capacity;
    2.17 -    unsigned int n;
    2.18 +    __int size = data->size, capacity = data->capacity;
    2.19 +    __int n;
    2.20  
    2.21      /* Re-allocate the fragment if the capacity has been reached. */
    2.22      if (size >= capacity)
     3.1 --- a/templates/native/common.h	Sat Oct 30 23:09:57 2021 +0200
     3.2 +++ b/templates/native/common.h	Sun Oct 31 01:01:10 2021 +0200
     3.3 @@ -24,7 +24,7 @@
     3.4  /* Utility functions. */
     3.5  
     3.6  #define __new_int(VALUE) __INTVALUE(VALUE)
     3.7 -__attr __new_str(char *s, int size);
     3.8 +__attr __new_str(char *s, __int size);
     3.9  __attr __new_list(__fragment *f);
    3.10  __fragment *__fragment_append(__fragment *data, __attr value);
    3.11  
     4.1 --- a/templates/native/iconv.c	Sat Oct 30 23:09:57 2021 +0200
     4.2 +++ b/templates/native/iconv.c	Sun Oct 31 01:01:10 2021 +0200
     4.3 @@ -1,6 +1,6 @@
     4.4  /* Native functions for character set conversion.
     4.5  
     4.6 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
     4.7 +Copyright (C) 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
     4.8  
     4.9  This program is free software; you can redistribute it and/or modify it under
    4.10  the terms of the GNU General Public License as published by the Free Software
    4.11 @@ -56,8 +56,8 @@
    4.12      /* Obtain the string, start position, and remaining bytes from the state. */
    4.13  
    4.14      char *inbuf = __load_via_object(__VALUE(f->attrs[0]), __data__).strvalue;
    4.15 -    int start = __TOINT(f->attrs[1]);
    4.16 -    int remaining = __TOINT(f->attrs[2]);
    4.17 +    __int start = __TOINT(f->attrs[1]);
    4.18 +    __int remaining = __TOINT(f->attrs[2]);
    4.19  
    4.20      /* Allocate a string for the output buffer using the remaining input size
    4.21         as a guide. */
     5.1 --- a/templates/native/int.c	Sat Oct 30 23:09:57 2021 +0200
     5.2 +++ b/templates/native/int.c	Sun Oct 31 01:01:10 2021 +0200
     5.3 @@ -1,6 +1,6 @@
     5.4  /* Native functions for integer operations.
     5.5  
     5.6 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
     5.7 +Copyright (C) 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
     5.8  
     5.9  This program is free software; you can redistribute it and/or modify it under
    5.10  the terms of the GNU General Public License as published by the Free Software
    5.11 @@ -39,8 +39,8 @@
    5.12  __attr __fn_native_int_int_add(__attr __self, __attr self, __attr other)
    5.13  {
    5.14      /* self and other interpreted as int */
    5.15 -    int i = __TOINT(self);
    5.16 -    int j = __TOINT(other);
    5.17 +    __int i = __TOINT(self);
    5.18 +    __int j = __TOINT(other);
    5.19  
    5.20      /* Test for overflow. */
    5.21      if (((i > 0) && (j > 0) && (i > __MAXINT - j)) ||
    5.22 @@ -55,8 +55,8 @@
    5.23  __attr __fn_native_int_int_sub(__attr __self, __attr self, __attr other)
    5.24  {
    5.25      /* self and other interpreted as int */
    5.26 -    int i = __TOINT(self);
    5.27 -    int j = __TOINT(other);
    5.28 +    __int i = __TOINT(self);
    5.29 +    __int j = __TOINT(other);
    5.30  
    5.31      /* Test for overflow. */
    5.32      if (((i < 0) && (j > 0) && (i < __MININT + j)) ||
    5.33 @@ -71,8 +71,8 @@
    5.34  __attr __fn_native_int_int_mul(__attr __self, __attr self, __attr other)
    5.35  {
    5.36      /* self and other interpreted as int */
    5.37 -    int i = __TOINT(self);
    5.38 -    int j = __TOINT(other);
    5.39 +    __int i = __TOINT(self);
    5.40 +    __int j = __TOINT(other);
    5.41  
    5.42      /* Test for overflow. */
    5.43      if (((i > 0) && (j > 0) && (i > __MAXINT / j)) ||
    5.44 @@ -89,8 +89,8 @@
    5.45  __attr __fn_native_int_int_div(__attr __self, __attr self, __attr other)
    5.46  {
    5.47      /* self and other interpreted as int */
    5.48 -    int i = __TOINT(self);
    5.49 -    int j = __TOINT(other);
    5.50 +    __int i = __TOINT(self);
    5.51 +    __int j = __TOINT(other);
    5.52  
    5.53      /* Test for division by zero or overflow. */
    5.54      if (j == 0)
    5.55 @@ -105,8 +105,8 @@
    5.56  __attr __fn_native_int_int_mod(__attr __self, __attr self, __attr other)
    5.57  {
    5.58      /* self and other interpreted as int */
    5.59 -    int i = __TOINT(self);
    5.60 -    int j = __TOINT(other);
    5.61 +    __int i = __TOINT(self);
    5.62 +    __int j = __TOINT(other);
    5.63  
    5.64      /* Test for division by zero or overflow. */
    5.65      if (j == 0)
    5.66 @@ -121,7 +121,7 @@
    5.67  __attr __fn_native_int_int_neg(__attr __self, __attr self)
    5.68  {
    5.69      /* self interpreted as int */
    5.70 -    int i = __TOINT(self);
    5.71 +    __int i = __TOINT(self);
    5.72  
    5.73      /* Test for overflow. */
    5.74      if (i == __MININT)
    5.75 @@ -134,8 +134,8 @@
    5.76  __attr __fn_native_int_int_pow(__attr __self, __attr self, __attr other)
    5.77  {
    5.78      /* self and other interpreted as int */
    5.79 -    int i = __TOINT(self);
    5.80 -    int j = __TOINT(other);
    5.81 +    __int i = __TOINT(self);
    5.82 +    __int j = __TOINT(other);
    5.83      int k;
    5.84  
    5.85      errno = 0;
    5.86 @@ -157,8 +157,8 @@
    5.87  __attr __fn_native_int_int_and(__attr __self, __attr self, __attr other)
    5.88  {
    5.89      /* self and other interpreted as int */
    5.90 -    int i = __TOINT(self);
    5.91 -    int j = __TOINT(other);
    5.92 +    __int i = __TOINT(self);
    5.93 +    __int j = __TOINT(other);
    5.94  
    5.95      /* Return the new integer. */
    5.96      /* NOTE: No overflow test applied. */
    5.97 @@ -168,7 +168,7 @@
    5.98  __attr __fn_native_int_int_not(__attr __self, __attr self)
    5.99  {
   5.100      /* self interpreted as int */
   5.101 -    int i = __TOINT(self);
   5.102 +    __int i = __TOINT(self);
   5.103  
   5.104      /* Return the new integer. */
   5.105      return __new_int(~i);
   5.106 @@ -177,8 +177,8 @@
   5.107  __attr __fn_native_int_int_or(__attr __self, __attr self, __attr other)
   5.108  {
   5.109      /* self and other interpreted as int */
   5.110 -    int i = __TOINT(self);
   5.111 -    int j = __TOINT(other);
   5.112 +    __int i = __TOINT(self);
   5.113 +    __int j = __TOINT(other);
   5.114  
   5.115      /* Return the new integer. */
   5.116      /* NOTE: No overflow test applied. */
   5.117 @@ -188,8 +188,8 @@
   5.118  __attr __fn_native_int_int_xor(__attr __self, __attr self, __attr other)
   5.119  {
   5.120      /* self and other interpreted as int */
   5.121 -    int i = __TOINT(self);
   5.122 -    int j = __TOINT(other);
   5.123 +    __int i = __TOINT(self);
   5.124 +    __int j = __TOINT(other);
   5.125  
   5.126      /* Return the new integer. */
   5.127      /* NOTE: No overflow test applied. */
   5.128 @@ -199,8 +199,8 @@
   5.129  __attr __fn_native_int_int_lshift(__attr __self, __attr self, __attr other)
   5.130  {
   5.131      /* self and other interpreted as int */
   5.132 -    int i = __TOINT(self);
   5.133 -    int j = __TOINT(other);
   5.134 +    __int i = __TOINT(self);
   5.135 +    __int j = __TOINT(other);
   5.136  
   5.137      /* Return the new integer. */
   5.138      /* NOTE: No overflow test applied. */
   5.139 @@ -210,8 +210,8 @@
   5.140  __attr __fn_native_int_int_rshift(__attr __self, __attr self, __attr other)
   5.141  {
   5.142      /* self and other interpreted as int */
   5.143 -    int i = __TOINT(self);
   5.144 -    int j = __TOINT(other);
   5.145 +    __int i = __TOINT(self);
   5.146 +    __int j = __TOINT(other);
   5.147  
   5.148      /* Return the new integer. */
   5.149      /* NOTE: No overflow test applied. */
   5.150 @@ -221,8 +221,8 @@
   5.151  __attr __fn_native_int_int_le(__attr __self, __attr self, __attr other)
   5.152  {
   5.153      /* self and other interpreted as int */
   5.154 -    int i = __TOINT(self);
   5.155 -    int j = __TOINT(other);
   5.156 +    __int i = __TOINT(self);
   5.157 +    __int j = __TOINT(other);
   5.158  
   5.159      /* Return a boolean result. */
   5.160      return i <= j ? __builtins___boolean_True : __builtins___boolean_False;
   5.161 @@ -231,8 +231,8 @@
   5.162  __attr __fn_native_int_int_lt(__attr __self, __attr self, __attr other)
   5.163  {
   5.164      /* self and other interpreted as int */
   5.165 -    int i = __TOINT(self);
   5.166 -    int j = __TOINT(other);
   5.167 +    __int i = __TOINT(self);
   5.168 +    __int j = __TOINT(other);
   5.169  
   5.170      /* Return a boolean result. */
   5.171      return i < j ? __builtins___boolean_True : __builtins___boolean_False;
   5.172 @@ -241,8 +241,8 @@
   5.173  __attr __fn_native_int_int_ge(__attr __self, __attr self, __attr other)
   5.174  {
   5.175      /* self and other interpreted as int */
   5.176 -    int i = __TOINT(self);
   5.177 -    int j = __TOINT(other);
   5.178 +    __int i = __TOINT(self);
   5.179 +    __int j = __TOINT(other);
   5.180  
   5.181      /* Return a boolean result. */
   5.182      return i >= j ? __builtins___boolean_True : __builtins___boolean_False;
   5.183 @@ -251,8 +251,8 @@
   5.184  __attr __fn_native_int_int_gt(__attr __self, __attr self, __attr other)
   5.185  {
   5.186      /* self and other interpreted as int */
   5.187 -    int i = __TOINT(self);
   5.188 -    int j = __TOINT(other);
   5.189 +    __int i = __TOINT(self);
   5.190 +    __int j = __TOINT(other);
   5.191  
   5.192      /* Return a boolean result. */
   5.193      return i > j ? __builtins___boolean_True : __builtins___boolean_False;
   5.194 @@ -261,8 +261,8 @@
   5.195  __attr __fn_native_int_int_eq(__attr __self, __attr self, __attr other)
   5.196  {
   5.197      /* self and other interpreted as int */
   5.198 -    int i = __TOINT(self);
   5.199 -    int j = __TOINT(other);
   5.200 +    __int i = __TOINT(self);
   5.201 +    __int j = __TOINT(other);
   5.202  
   5.203      /* Return a boolean result. */
   5.204      return i == j ? __builtins___boolean_True : __builtins___boolean_False;
   5.205 @@ -271,8 +271,8 @@
   5.206  __attr __fn_native_int_int_ne(__attr __self, __attr self, __attr other)
   5.207  {
   5.208      /* self and other interpreted as int */
   5.209 -    int i = __TOINT(self);
   5.210 -    int j = __TOINT(other);
   5.211 +    __int i = __TOINT(self);
   5.212 +    __int j = __TOINT(other);
   5.213  
   5.214      /* Return a boolean result. */
   5.215      return i != j ? __builtins___boolean_True : __builtins___boolean_False;
   5.216 @@ -281,14 +281,14 @@
   5.217  __attr __fn_native_int_int_str(__attr __self, __attr self)
   5.218  {
   5.219      /* self interpreted as int */
   5.220 -    int i = __TOINT(self);
   5.221 +    __int i = __TOINT(self);
   5.222  
   5.223      /* Employ a buffer big enough to fit the largest integer plus an extra
   5.224         character, a minus sign, and the null terminator. */
   5.225      unsigned int n = (int) log10(__MAXINT) + 3;
   5.226      char *s = (char *) __ALLOCATE(n, sizeof(char));
   5.227  
   5.228 -    snprintf(s, n, "%d", i);
   5.229 +    snprintf(s, n, "%ld", i);
   5.230  
   5.231      /* Return a new string. */
   5.232      return __new_str(s, strlen(s));
     6.1 --- a/templates/native/io.c	Sat Oct 30 23:09:57 2021 +0200
     6.2 +++ b/templates/native/io.c	Sun Oct 31 01:01:10 2021 +0200
     6.3 @@ -1,6 +1,6 @@
     6.4  /* Native functions for input/output.
     6.5  
     6.6 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
     6.7 +Copyright (C) 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
     6.8  
     6.9  This program is free software; you can redistribute it and/or modify it under
    6.10  the terms of the GNU General Public License as published by the Free Software
    6.11 @@ -120,7 +120,7 @@
    6.12      /* fp interpreted as FILE reference */
    6.13      FILE *f = (FILE *) fp.datavalue;
    6.14      /* size interpreted as int */
    6.15 -    int to_read = __TOINT(size);
    6.16 +    size_t to_read = __TOINT(size);
    6.17      char buf[to_read];
    6.18      size_t have_read;
    6.19      int error;
    6.20 @@ -150,7 +150,7 @@
    6.21      /* str.__data__ interpreted as string */
    6.22      char *s = __load_via_object(__VALUE(str), __data__).strvalue;
    6.23      /* str.__size__ interpreted as int */
    6.24 -    int to_write = __TOINT(__load_via_object(__VALUE(str), __size__));
    6.25 +    size_t to_write = __TOINT(__load_via_object(__VALUE(str), __size__));
    6.26      size_t have_written = fwrite(s, sizeof(char), to_write, f);
    6.27      int error;
    6.28  
    6.29 @@ -182,7 +182,7 @@
    6.30      /* fd interpreted as int */
    6.31      int i = __TOINT(fd);
    6.32      /* n interpreted as int */
    6.33 -    int to_read = __TOINT(n);
    6.34 +    size_t to_read = __TOINT(n);
    6.35      char buf[to_read];
    6.36      ssize_t have_read;
    6.37      char *s;
    6.38 @@ -207,7 +207,7 @@
    6.39      /* str.__data__ interpreted as string */
    6.40      char *s = __load_via_object(__VALUE(str), __data__).strvalue;
    6.41      /* str.__size__ interpreted as int */
    6.42 -    int size = __TOINT(__load_via_object(__VALUE(str), __size__));
    6.43 +    size_t size = __TOINT(__load_via_object(__VALUE(str), __size__));
    6.44      ssize_t have_written;
    6.45  
    6.46      errno = 0;
     7.1 --- a/templates/native/list.c	Sat Oct 30 23:09:57 2021 +0200
     7.2 +++ b/templates/native/list.c	Sun Oct 31 01:01:10 2021 +0200
     7.3 @@ -1,6 +1,6 @@
     7.4  /* Native functions for list operations.
     7.5  
     7.6 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
     7.7 +Copyright (C) 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
     7.8  
     7.9  This program is free software; you can redistribute it and/or modify it under
    7.10  the terms of the GNU General Public License as published by the Free Software
    7.11 @@ -30,7 +30,7 @@
    7.12  __attr __fn_native_list_list_init(__attr __self, __attr size)
    7.13  {
    7.14      /* size interpreted as int */
    7.15 -    unsigned int n = __TOINT(size);
    7.16 +    __int n = __TOINT(size);
    7.17      __attr attr = {.seqvalue=__new_fragment(n)};
    7.18  
    7.19      /* Return the __data__ attribute. */
    7.20 @@ -42,7 +42,7 @@
    7.21      /* _data interpreted as list.__data__ */
    7.22      __fragment *data = _data.seqvalue;
    7.23      /* size interpreted as int */
    7.24 -    unsigned int n = __TOINT(size);
    7.25 +    __int n = __TOINT(size);
    7.26  
    7.27      data->size = n;
    7.28      return __builtins___none_None;
    7.29 @@ -66,9 +66,9 @@
    7.30      __fragment *data = __load_via_object(__VALUE(self), __data__).seqvalue;
    7.31      __fragment *other_data = other.seqvalue;
    7.32      __fragment *newdata = data;
    7.33 -    unsigned int size = data->size, capacity = data->capacity;
    7.34 -    unsigned int other_size = other_data->size;
    7.35 -    unsigned int i, j, n = size + other_size;
    7.36 +    __int size = data->size, capacity = data->capacity;
    7.37 +    __int other_size = other_data->size;
    7.38 +    __int i, j, n = size + other_size;
    7.39  
    7.40      /* Re-allocate the fragment if the capacity has been reached. */
    7.41      if (n >= capacity)
    7.42 @@ -91,7 +91,7 @@
    7.43  __attr __fn_native_list_list_len(__attr self, __attr _data)
    7.44  {
    7.45      /* _data interpreted as list.__data__ */
    7.46 -    unsigned int size = _data.seqvalue->size;
    7.47 +    __int size = _data.seqvalue->size;
    7.48  
    7.49      /* Return the new integer. */
    7.50      return __new_int(size);
    7.51 @@ -107,7 +107,7 @@
    7.52      /* _data interpreted as list.__data__ */
    7.53      __attr *elements = _data.seqvalue->attrs;
    7.54      /* index interpreted as int */
    7.55 -    int i = __TOINT(index);
    7.56 +    __int i = __TOINT(index);
    7.57  
    7.58      return elements[i];
    7.59  }
    7.60 @@ -117,7 +117,7 @@
    7.61      /* _data interpreted as list.__data__ */
    7.62      __attr *elements = _data.seqvalue->attrs;
    7.63      /* index interpreted as int */
    7.64 -    int i = __TOINT(index);
    7.65 +    __int i = __TOINT(index);
    7.66  
    7.67      /* Set the element. */
    7.68      elements[i] = value;
     8.1 --- a/templates/native/str.c	Sat Oct 30 23:09:57 2021 +0200
     8.2 +++ b/templates/native/str.c	Sun Oct 31 01:01:10 2021 +0200
     8.3 @@ -1,6 +1,6 @@
     8.4  /* Native functions for string operations.
     8.5  
     8.6 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
     8.7 +Copyright (C) 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
     8.8  
     8.9  This program is free software; you can redistribute it and/or modify it under
    8.10  the terms of the GNU General Public License as published by the Free Software
    8.11 @@ -34,8 +34,8 @@
    8.12      char *s = _data.strvalue;
    8.13      char *o = other.strvalue;
    8.14      /* _size, othersize interpreted as int */
    8.15 -    int ss = __TOINT(_size), os = __TOINT(othersize);
    8.16 -    int n = ss + os;
    8.17 +    __int ss = __TOINT(_size), os = __TOINT(othersize);
    8.18 +    __int n = ss + os;
    8.19      char *r = (char *) __ALLOCATE(n + 1, sizeof(char));
    8.20  
    8.21      memcpy(r, s, ss);
    8.22 @@ -90,7 +90,7 @@
    8.23      /* _data interpreted as string.__data__ */
    8.24      char *s = _data.strvalue;
    8.25  
    8.26 -    return __new_int((unsigned int) s[0]);
    8.27 +    return __new_int((__int) s[0]);
    8.28  }
    8.29  
    8.30  __attr __fn_native_str_str_substr(__attr __self, __attr _data, __attr start, __attr end, __attr step)
    8.31 @@ -98,15 +98,15 @@
    8.32      /* _data interpreted as string.__data__ */
    8.33      char *s = _data.strvalue, *sub;
    8.34      /* start interpreted as int */
    8.35 -    int istart = __TOINT(start);
    8.36 +    __int istart = __TOINT(start);
    8.37      /* end interpreted as int */
    8.38 -    int iend = __TOINT(end);
    8.39 +    __int iend = __TOINT(end);
    8.40      /* step interpreted as int */
    8.41 -    int istep = __TOINT(step);
    8.42 +    __int istep = __TOINT(step);
    8.43  
    8.44      /* Calculate the size of the substring. */
    8.45      size_t resultsize = ((iend - istart - (istep > 0 ? 1 : -1)) / istep) + 1;
    8.46 -    int to, from;
    8.47 +    size_t to, from;
    8.48  
    8.49      /* Reserve space for a new string. */
    8.50      sub = (char *) __ALLOCATE(resultsize + 1, sizeof(char));
     9.1 --- a/templates/native/system.c	Sat Oct 30 23:09:57 2021 +0200
     9.2 +++ b/templates/native/system.c	Sun Oct 31 01:01:10 2021 +0200
     9.3 @@ -1,6 +1,6 @@
     9.4  /* Native functions for system operations.
     9.5  
     9.6 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
     9.7 +Copyright (C) 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
     9.8  
     9.9  This program is free software; you can redistribute it and/or modify it under
    9.10  the terms of the GNU General Public License as published by the Free Software
    10.1 --- a/templates/native/tuple.c	Sat Oct 30 23:09:57 2021 +0200
    10.2 +++ b/templates/native/tuple.c	Sun Oct 31 01:01:10 2021 +0200
    10.3 @@ -1,6 +1,6 @@
    10.4  /* Native functions for tuple operations.
    10.5  
    10.6 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
    10.7 +Copyright (C) 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
    10.8  
    10.9  This program is free software; you can redistribute it and/or modify it under
   10.10  the terms of the GNU General Public License as published by the Free Software
   10.11 @@ -32,7 +32,7 @@
   10.12  __attr __fn_native_tuple_tuple_init(__attr __self, __attr size)
   10.13  {
   10.14      /* size interpreted as int */
   10.15 -    int n = __TOINT(size);
   10.16 +    __int n = __TOINT(size);
   10.17  
   10.18      /* Return the __data__ attribute. */
   10.19      if (n) return (__attr) {.seqvalue=__new_fragment(n)};
    11.1 --- a/templates/native/unicode.c	Sat Oct 30 23:09:57 2021 +0200
    11.2 +++ b/templates/native/unicode.c	Sun Oct 31 01:01:10 2021 +0200
    11.3 @@ -1,6 +1,6 @@
    11.4  /* Native functions for Unicode operations.
    11.5  
    11.6 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
    11.7 +Copyright (C) 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
    11.8  
    11.9  This program is free software; you can redistribute it and/or modify it under
   11.10  the terms of the GNU General Public License as published by the Free Software
   11.11 @@ -39,9 +39,9 @@
   11.12      else return 0;
   11.13  }
   11.14  
   11.15 -static unsigned int nextpos(char *s, unsigned int size, unsigned int bytestart)
   11.16 +static __int nextpos(char *s, __int size, __int bytestart)
   11.17  {
   11.18 -    unsigned int i = bytestart;
   11.19 +    __int i = bytestart;
   11.20  
   11.21      while (i < size)
   11.22      {
   11.23 @@ -53,9 +53,9 @@
   11.24      return i;
   11.25  }
   11.26  
   11.27 -static unsigned int prevpos(char *s, unsigned int bytestart)
   11.28 +static __int prevpos(char *s, __int bytestart)
   11.29  {
   11.30 -    unsigned int i = bytestart;
   11.31 +    __int i = bytestart;
   11.32  
   11.33      while (i > 0)
   11.34      {
   11.35 @@ -74,8 +74,8 @@
   11.36      /* _data interpreted as string.__data__ */
   11.37      char *s = _data.strvalue;
   11.38      /* _size interpreted as int */
   11.39 -    int size = __TOINT(_size);
   11.40 -    unsigned int i, c = 0;
   11.41 +    __int size = __TOINT(_size);
   11.42 +    __int i, c = 0;
   11.43  
   11.44      for (i = 0; i < size; i++)
   11.45          if (boundary(s[i]))
   11.46 @@ -90,8 +90,8 @@
   11.47      /* _data interpreted as string.__data__ */
   11.48      char *s = _data.strvalue;
   11.49      /* _size interpreted as int */
   11.50 -    int size = __TOINT(_size);
   11.51 -    unsigned int i, c = 0, v;
   11.52 +    __int size = __TOINT(_size);
   11.53 +    __int i, c = 0, v;
   11.54  
   11.55      for (i = 0; i < size; i++)
   11.56      {
   11.57 @@ -124,20 +124,20 @@
   11.58      /* _data interpreted as string.__data__ */
   11.59      char *s = _data.strvalue, *sub;
   11.60      /* _size interpreted as int */
   11.61 -    int ss = __TOINT(_size);
   11.62 +    __int ss = __TOINT(_size);
   11.63      /* start interpreted as int */
   11.64 -    int istart = __TOINT(start);
   11.65 +    __int istart = __TOINT(start);
   11.66      /* end interpreted as int */
   11.67 -    int iend = __TOINT(end);
   11.68 +    __int iend = __TOINT(end);
   11.69      /* step interpreted as int */
   11.70 -    int istep = __TOINT(step);
   11.71 +    __int istep = __TOINT(step);
   11.72  
   11.73      /* Calculate the number of characters. */
   11.74 -    size_t nchar = ((iend - istart - (istep > 0 ? 1 : -1)) / istep) + 1;
   11.75 -    unsigned int indexes[nchar];
   11.76 +    __int nchar = ((iend - istart - (istep > 0 ? 1 : -1)) / istep) + 1;
   11.77 +    __int indexes[nchar];
   11.78  
   11.79 -    unsigned int c, d, i, to, from, lastbyte = 0;
   11.80 -    int resultsize = 0;
   11.81 +    __int c, d, i, to, from, lastbyte = 0;
   11.82 +    __int resultsize = 0;
   11.83  
   11.84      /* Find the indexes of the characters. */
   11.85      if (istep > 0)
   11.86 @@ -197,7 +197,7 @@
   11.87  {
   11.88      /* value interpreted as int */
   11.89      int i = __TOINT(value);
   11.90 -    unsigned int resultsize;
   11.91 +    __int resultsize;
   11.92      char *s;
   11.93  
   11.94      if (i < 128) resultsize = 1;
    12.1 --- a/templates/progops.c	Sat Oct 30 23:09:57 2021 +0200
    12.2 +++ b/templates/progops.c	Sun Oct 31 01:01:10 2021 +0200
    12.3 @@ -49,7 +49,7 @@
    12.4  
    12.5  /* Generic internal data allocation. */
    12.6  
    12.7 -__fragment *__new_fragment(unsigned int n) 
    12.8 +__fragment *__new_fragment(__int n) 
    12.9  {
   12.10      /* Allocate space for the list. */
   12.11  
   12.12 @@ -62,9 +62,9 @@
   12.13      return data;
   12.14  }
   12.15  
   12.16 -void __newdata_sequence(unsigned int number, __fragment *data, __attr args[])
   12.17 +void __newdata_sequence(__int number, __fragment *data, __attr args[])
   12.18  {
   12.19 -    unsigned int i;
   12.20 +    __int i;
   12.21  
   12.22      /* Copy the given number of values. */
   12.23  
   12.24 @@ -74,7 +74,7 @@
   12.25      data->size = number;
   12.26  }
   12.27  
   12.28 -__attr __newdata_list(unsigned int number, __attr args[])
   12.29 +__attr __newdata_list(__int number, __attr args[])
   12.30  {
   12.31      __attr self = __NEWINSTANCE(__builtins___list_list);
   12.32      __fragment *data = __new_fragment(number);
   12.33 @@ -86,7 +86,7 @@
   12.34      return self;
   12.35  }
   12.36  
   12.37 -__attr __newdata_tuple(unsigned int number, __attr args[])
   12.38 +__attr __newdata_tuple(__int number, __attr args[])
   12.39  {
   12.40      /* Allocate the tuple and fragment together. */
   12.41  
   12.42 @@ -103,7 +103,7 @@
   12.43  }
   12.44  
   12.45  #ifdef __HAVE___builtins___dict_dict
   12.46 -__attr __newdata_dict(unsigned int number, __attr args[])
   12.47 +__attr __newdata_dict(__int number, __attr args[])
   12.48  {
   12.49      __attr self = __NEWINSTANCE(__builtins___dict_dict);
   12.50  
   12.51 @@ -313,10 +313,11 @@
   12.52  {
   12.53      __ref value;
   12.54  
   12.55 -    /* Integers can be used directly as truth values. */
   12.56 +    /* Non-zero integers yield a non-zero result. Since the integer type can be
   12.57 +       larger than int, a conversion is performed. */
   12.58  
   12.59      if (__INTEGER(attr))
   12.60 -        return __TOINT(attr);
   12.61 +        return __TOINT(attr) ? 1 : 0;
   12.62  
   12.63      /* Test against True and False explicitly. If necessary, invoke the bool
   12.64         function with the object and test against True. */
    13.1 --- a/templates/progops.h	Sat Oct 30 23:09:57 2021 +0200
    13.2 +++ b/templates/progops.h	Sun Oct 31 01:01:10 2021 +0200
    13.3 @@ -30,16 +30,16 @@
    13.4  
    13.5  /* Generic internal data allocation. */
    13.6  
    13.7 -__fragment *__new_fragment(unsigned int n);
    13.8 +__fragment *__new_fragment(__int n);
    13.9  
   13.10 -__attr __newdata_list(unsigned int number, __attr args[]);
   13.11 -__attr __newdata_tuple(unsigned int number, __attr args[]);
   13.12 +__attr __newdata_list(__int number, __attr args[]);
   13.13 +__attr __newdata_tuple(__int number, __attr args[]);
   13.14  
   13.15  #define __newliteral___builtins___list_list(NUM, ...) __newdata_list(NUM, __ARGS(__VA_ARGS__))
   13.16  #define __newliteral___builtins___tuple_tuple(NUM, ...) __newdata_tuple(NUM, __ARGS(__VA_ARGS__))
   13.17  
   13.18  #ifdef __HAVE___builtins___dict_dict
   13.19 -__attr __newdata_dict(unsigned int number, __attr args[]);
   13.20 +__attr __newdata_dict(__int number, __attr args[]);
   13.21  #define __newliteral___builtins___dict_dict(NUM, ...) __newdata_dict(NUM, __ARGS(__VA_ARGS__))
   13.22  #endif /* __HAVE___builtins___dict_dict */
   13.23  
    14.1 --- a/templates/types.h	Sat Oct 30 23:09:57 2021 +0200
    14.2 +++ b/templates/types.h	Sun Oct 31 01:01:10 2021 +0200
    14.3 @@ -1,6 +1,7 @@
    14.4  /* Runtime types.
    14.5  
    14.6 -Copyright (C) 2015, 2016, 2017, 2018, 2019 Paul Boddie <paul@boddie.org.uk>
    14.7 +Copyright (C) 2015, 2016, 2017, 2018, 2019,
    14.8 +              2021 Paul Boddie <paul@boddie.org.uk>
    14.9  
   14.10  This program is free software; you can redistribute it and/or modify it under
   14.11  the terms of the GNU General Public License as published by the Free Software
   14.12 @@ -23,6 +24,7 @@
   14.13     program specifically. */
   14.14  
   14.15  #include <stdint.h>
   14.16 +#include <stdlib.h>
   14.17  
   14.18  /* Include the special instance position value. The pos member of __obj refers
   14.19     to the special type attribute for classes, indicating which position holds
   14.20 @@ -70,12 +72,19 @@
   14.21  typedef union __attr __attr;
   14.22  typedef __obj * __ref;
   14.23  
   14.24 +/* Introduce an integer type that should not exceed the size of the pointer
   14.25 +   type. */
   14.26 +
   14.27 +typedef ssize_t __int;
   14.28 +
   14.29 +/* Attribute value interpretations. */
   14.30 +
   14.31  typedef union __attr
   14.32  {
   14.33      /* General attribute members. */
   14.34  
   14.35      __ref value;                /* attribute value */
   14.36 -    int intvalue;               /* integer value data (shifted value, tagged) */
   14.37 +    __int intvalue;             /* integer value data (shifted value, tagged) */
   14.38  
   14.39      /* Special case attribute members. */
   14.40  
   14.41 @@ -105,11 +114,11 @@
   14.42  
   14.43  typedef struct __fragment
   14.44  {
   14.45 -    unsigned int size, capacity;
   14.46 +    __int size, capacity;
   14.47      __attr attrs[];
   14.48  } __fragment;
   14.49  
   14.50 -#define __FRAGMENT_SIZE(NUMBER) ((NUMBER) * sizeof(__attr) + 2 * sizeof(unsigned int))
   14.51 +#define __FRAGMENT_SIZE(NUMBER) ((NUMBER) * sizeof(__attr) + 2 * sizeof(__int))
   14.52  
   14.53  /* Attribute interpretation. */
   14.54  
   14.55 @@ -125,10 +134,10 @@
   14.56  
   14.57  /* Attribute as instance setting. */
   14.58  
   14.59 -#define __INTVALUE(VALUE)   ((__attr) {.intvalue=((VALUE) << __NUM_TAG_BITS) | __TAG_INT})
   14.60 +#define __INTVALUE(VALUE)   ((__attr) {.intvalue=(((__int) VALUE) << __NUM_TAG_BITS) | __TAG_INT})
   14.61  #define __TOINT(ATTR)       ((ATTR).intvalue >> __NUM_TAG_BITS)
   14.62 -#define __MAXINT            ((1 << ((sizeof(int) * 8) - 1 - __NUM_TAG_BITS)) - 1)
   14.63 -#define __MININT            (-(1 << ((sizeof(int) * 8) - 1 - __NUM_TAG_BITS)))
   14.64 +#define __MAXINT            ((((__int) 1) << ((sizeof(__int) * 8) - 1 - __NUM_TAG_BITS)) - 1)
   14.65 +#define __MININT            (-(((__int) 1) << ((sizeof(__int) * 8) - 1 - __NUM_TAG_BITS)))
   14.66  
   14.67  /* Argument lists. */
   14.68