1.1 --- a/templates/native/int.c Sat Oct 30 23:09:57 2021 +0200
1.2 +++ b/templates/native/int.c Sun Oct 31 01:01:10 2021 +0200
1.3 @@ -1,6 +1,6 @@
1.4 /* Native functions for integer 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 @@ -39,8 +39,8 @@
1.12 __attr __fn_native_int_int_add(__attr __self, __attr self, __attr other)
1.13 {
1.14 /* self and other interpreted as int */
1.15 - int i = __TOINT(self);
1.16 - int j = __TOINT(other);
1.17 + __int i = __TOINT(self);
1.18 + __int j = __TOINT(other);
1.19
1.20 /* Test for overflow. */
1.21 if (((i > 0) && (j > 0) && (i > __MAXINT - j)) ||
1.22 @@ -55,8 +55,8 @@
1.23 __attr __fn_native_int_int_sub(__attr __self, __attr self, __attr other)
1.24 {
1.25 /* self and other interpreted as int */
1.26 - int i = __TOINT(self);
1.27 - int j = __TOINT(other);
1.28 + __int i = __TOINT(self);
1.29 + __int j = __TOINT(other);
1.30
1.31 /* Test for overflow. */
1.32 if (((i < 0) && (j > 0) && (i < __MININT + j)) ||
1.33 @@ -71,8 +71,8 @@
1.34 __attr __fn_native_int_int_mul(__attr __self, __attr self, __attr other)
1.35 {
1.36 /* self and other interpreted as int */
1.37 - int i = __TOINT(self);
1.38 - int j = __TOINT(other);
1.39 + __int i = __TOINT(self);
1.40 + __int j = __TOINT(other);
1.41
1.42 /* Test for overflow. */
1.43 if (((i > 0) && (j > 0) && (i > __MAXINT / j)) ||
1.44 @@ -89,8 +89,8 @@
1.45 __attr __fn_native_int_int_div(__attr __self, __attr self, __attr other)
1.46 {
1.47 /* self and other interpreted as int */
1.48 - int i = __TOINT(self);
1.49 - int j = __TOINT(other);
1.50 + __int i = __TOINT(self);
1.51 + __int j = __TOINT(other);
1.52
1.53 /* Test for division by zero or overflow. */
1.54 if (j == 0)
1.55 @@ -105,8 +105,8 @@
1.56 __attr __fn_native_int_int_mod(__attr __self, __attr self, __attr other)
1.57 {
1.58 /* self and other interpreted as int */
1.59 - int i = __TOINT(self);
1.60 - int j = __TOINT(other);
1.61 + __int i = __TOINT(self);
1.62 + __int j = __TOINT(other);
1.63
1.64 /* Test for division by zero or overflow. */
1.65 if (j == 0)
1.66 @@ -121,7 +121,7 @@
1.67 __attr __fn_native_int_int_neg(__attr __self, __attr self)
1.68 {
1.69 /* self interpreted as int */
1.70 - int i = __TOINT(self);
1.71 + __int i = __TOINT(self);
1.72
1.73 /* Test for overflow. */
1.74 if (i == __MININT)
1.75 @@ -134,8 +134,8 @@
1.76 __attr __fn_native_int_int_pow(__attr __self, __attr self, __attr other)
1.77 {
1.78 /* self and other interpreted as int */
1.79 - int i = __TOINT(self);
1.80 - int j = __TOINT(other);
1.81 + __int i = __TOINT(self);
1.82 + __int j = __TOINT(other);
1.83 int k;
1.84
1.85 errno = 0;
1.86 @@ -157,8 +157,8 @@
1.87 __attr __fn_native_int_int_and(__attr __self, __attr self, __attr other)
1.88 {
1.89 /* self and other interpreted as int */
1.90 - int i = __TOINT(self);
1.91 - int j = __TOINT(other);
1.92 + __int i = __TOINT(self);
1.93 + __int j = __TOINT(other);
1.94
1.95 /* Return the new integer. */
1.96 /* NOTE: No overflow test applied. */
1.97 @@ -168,7 +168,7 @@
1.98 __attr __fn_native_int_int_not(__attr __self, __attr self)
1.99 {
1.100 /* self interpreted as int */
1.101 - int i = __TOINT(self);
1.102 + __int i = __TOINT(self);
1.103
1.104 /* Return the new integer. */
1.105 return __new_int(~i);
1.106 @@ -177,8 +177,8 @@
1.107 __attr __fn_native_int_int_or(__attr __self, __attr self, __attr other)
1.108 {
1.109 /* self and other interpreted as int */
1.110 - int i = __TOINT(self);
1.111 - int j = __TOINT(other);
1.112 + __int i = __TOINT(self);
1.113 + __int j = __TOINT(other);
1.114
1.115 /* Return the new integer. */
1.116 /* NOTE: No overflow test applied. */
1.117 @@ -188,8 +188,8 @@
1.118 __attr __fn_native_int_int_xor(__attr __self, __attr self, __attr other)
1.119 {
1.120 /* self and other interpreted as int */
1.121 - int i = __TOINT(self);
1.122 - int j = __TOINT(other);
1.123 + __int i = __TOINT(self);
1.124 + __int j = __TOINT(other);
1.125
1.126 /* Return the new integer. */
1.127 /* NOTE: No overflow test applied. */
1.128 @@ -199,8 +199,8 @@
1.129 __attr __fn_native_int_int_lshift(__attr __self, __attr self, __attr other)
1.130 {
1.131 /* self and other interpreted as int */
1.132 - int i = __TOINT(self);
1.133 - int j = __TOINT(other);
1.134 + __int i = __TOINT(self);
1.135 + __int j = __TOINT(other);
1.136
1.137 /* Return the new integer. */
1.138 /* NOTE: No overflow test applied. */
1.139 @@ -210,8 +210,8 @@
1.140 __attr __fn_native_int_int_rshift(__attr __self, __attr self, __attr other)
1.141 {
1.142 /* self and other interpreted as int */
1.143 - int i = __TOINT(self);
1.144 - int j = __TOINT(other);
1.145 + __int i = __TOINT(self);
1.146 + __int j = __TOINT(other);
1.147
1.148 /* Return the new integer. */
1.149 /* NOTE: No overflow test applied. */
1.150 @@ -221,8 +221,8 @@
1.151 __attr __fn_native_int_int_le(__attr __self, __attr self, __attr other)
1.152 {
1.153 /* self and other interpreted as int */
1.154 - int i = __TOINT(self);
1.155 - int j = __TOINT(other);
1.156 + __int i = __TOINT(self);
1.157 + __int j = __TOINT(other);
1.158
1.159 /* Return a boolean result. */
1.160 return i <= j ? __builtins___boolean_True : __builtins___boolean_False;
1.161 @@ -231,8 +231,8 @@
1.162 __attr __fn_native_int_int_lt(__attr __self, __attr self, __attr other)
1.163 {
1.164 /* self and other interpreted as int */
1.165 - int i = __TOINT(self);
1.166 - int j = __TOINT(other);
1.167 + __int i = __TOINT(self);
1.168 + __int j = __TOINT(other);
1.169
1.170 /* Return a boolean result. */
1.171 return i < j ? __builtins___boolean_True : __builtins___boolean_False;
1.172 @@ -241,8 +241,8 @@
1.173 __attr __fn_native_int_int_ge(__attr __self, __attr self, __attr other)
1.174 {
1.175 /* self and other interpreted as int */
1.176 - int i = __TOINT(self);
1.177 - int j = __TOINT(other);
1.178 + __int i = __TOINT(self);
1.179 + __int j = __TOINT(other);
1.180
1.181 /* Return a boolean result. */
1.182 return i >= j ? __builtins___boolean_True : __builtins___boolean_False;
1.183 @@ -251,8 +251,8 @@
1.184 __attr __fn_native_int_int_gt(__attr __self, __attr self, __attr other)
1.185 {
1.186 /* self and other interpreted as int */
1.187 - int i = __TOINT(self);
1.188 - int j = __TOINT(other);
1.189 + __int i = __TOINT(self);
1.190 + __int j = __TOINT(other);
1.191
1.192 /* Return a boolean result. */
1.193 return i > j ? __builtins___boolean_True : __builtins___boolean_False;
1.194 @@ -261,8 +261,8 @@
1.195 __attr __fn_native_int_int_eq(__attr __self, __attr self, __attr other)
1.196 {
1.197 /* self and other interpreted as int */
1.198 - int i = __TOINT(self);
1.199 - int j = __TOINT(other);
1.200 + __int i = __TOINT(self);
1.201 + __int j = __TOINT(other);
1.202
1.203 /* Return a boolean result. */
1.204 return i == j ? __builtins___boolean_True : __builtins___boolean_False;
1.205 @@ -271,8 +271,8 @@
1.206 __attr __fn_native_int_int_ne(__attr __self, __attr self, __attr other)
1.207 {
1.208 /* self and other interpreted as int */
1.209 - int i = __TOINT(self);
1.210 - int j = __TOINT(other);
1.211 + __int i = __TOINT(self);
1.212 + __int j = __TOINT(other);
1.213
1.214 /* Return a boolean result. */
1.215 return i != j ? __builtins___boolean_True : __builtins___boolean_False;
1.216 @@ -281,14 +281,14 @@
1.217 __attr __fn_native_int_int_str(__attr __self, __attr self)
1.218 {
1.219 /* self interpreted as int */
1.220 - int i = __TOINT(self);
1.221 + __int i = __TOINT(self);
1.222
1.223 /* Employ a buffer big enough to fit the largest integer plus an extra
1.224 character, a minus sign, and the null terminator. */
1.225 unsigned int n = (int) log10(__MAXINT) + 3;
1.226 char *s = (char *) __ALLOCATE(n, sizeof(char));
1.227
1.228 - snprintf(s, n, "%d", i);
1.229 + snprintf(s, n, "%ld", i);
1.230
1.231 /* Return a new string. */
1.232 return __new_str(s, strlen(s));