1.1 --- a/templates/types.h Sat Oct 30 23:09:57 2021 +0200
1.2 +++ b/templates/types.h Sun Oct 31 01:01:10 2021 +0200
1.3 @@ -1,6 +1,7 @@
1.4 /* Runtime types.
1.5
1.6 -Copyright (C) 2015, 2016, 2017, 2018, 2019 Paul Boddie <paul@boddie.org.uk>
1.7 +Copyright (C) 2015, 2016, 2017, 2018, 2019,
1.8 + 2021 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -23,6 +24,7 @@
1.13 program specifically. */
1.14
1.15 #include <stdint.h>
1.16 +#include <stdlib.h>
1.17
1.18 /* Include the special instance position value. The pos member of __obj refers
1.19 to the special type attribute for classes, indicating which position holds
1.20 @@ -70,12 +72,19 @@
1.21 typedef union __attr __attr;
1.22 typedef __obj * __ref;
1.23
1.24 +/* Introduce an integer type that should not exceed the size of the pointer
1.25 + type. */
1.26 +
1.27 +typedef ssize_t __int;
1.28 +
1.29 +/* Attribute value interpretations. */
1.30 +
1.31 typedef union __attr
1.32 {
1.33 /* General attribute members. */
1.34
1.35 __ref value; /* attribute value */
1.36 - int intvalue; /* integer value data (shifted value, tagged) */
1.37 + __int intvalue; /* integer value data (shifted value, tagged) */
1.38
1.39 /* Special case attribute members. */
1.40
1.41 @@ -105,11 +114,11 @@
1.42
1.43 typedef struct __fragment
1.44 {
1.45 - unsigned int size, capacity;
1.46 + __int size, capacity;
1.47 __attr attrs[];
1.48 } __fragment;
1.49
1.50 -#define __FRAGMENT_SIZE(NUMBER) ((NUMBER) * sizeof(__attr) + 2 * sizeof(unsigned int))
1.51 +#define __FRAGMENT_SIZE(NUMBER) ((NUMBER) * sizeof(__attr) + 2 * sizeof(__int))
1.52
1.53 /* Attribute interpretation. */
1.54
1.55 @@ -125,10 +134,10 @@
1.56
1.57 /* Attribute as instance setting. */
1.58
1.59 -#define __INTVALUE(VALUE) ((__attr) {.intvalue=((VALUE) << __NUM_TAG_BITS) | __TAG_INT})
1.60 +#define __INTVALUE(VALUE) ((__attr) {.intvalue=(((__int) VALUE) << __NUM_TAG_BITS) | __TAG_INT})
1.61 #define __TOINT(ATTR) ((ATTR).intvalue >> __NUM_TAG_BITS)
1.62 -#define __MAXINT ((1 << ((sizeof(int) * 8) - 1 - __NUM_TAG_BITS)) - 1)
1.63 -#define __MININT (-(1 << ((sizeof(int) * 8) - 1 - __NUM_TAG_BITS)))
1.64 +#define __MAXINT ((((__int) 1) << ((sizeof(__int) * 8) - 1 - __NUM_TAG_BITS)) - 1)
1.65 +#define __MININT (-(((__int) 1) << ((sizeof(__int) * 8) - 1 - __NUM_TAG_BITS)))
1.66
1.67 /* Argument lists. */
1.68