1.1 --- a/templates/types.h Thu Nov 04 23:44:29 2021 +0100
1.2 +++ b/templates/types.h Tue Aug 29 01:46:23 2023 +0200
1.3 @@ -1,6 +1,6 @@
1.4 /* Runtime types.
1.5
1.6 -Copyright (C) 2015-2019, 2021 Paul Boddie <paul@boddie.org.uk>
1.7 +Copyright (C) 2015-2019, 2021, 2023 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 @@ -75,6 +75,10 @@
1.12
1.13 typedef ssize_t __int;
1.14
1.15 +/* Introduce a tagged pointer type. */
1.16 +
1.17 +typedef uintptr_t __ref_tagged;
1.18 +
1.19 /* Attribute value interpretations. */
1.20
1.21 typedef union __attr
1.22 @@ -83,6 +87,7 @@
1.23
1.24 __ref value; /* attribute value */
1.25 __int intvalue; /* integer value data (shifted value, tagged) */
1.26 + __ref_tagged refvalue; /* attribute value with tag */
1.27
1.28 /* Special case attribute members. */
1.29
1.30 @@ -127,8 +132,8 @@
1.31
1.32 #define __NUM_TAG_BITS 2
1.33 #define __TAG_INT 0b01
1.34 -#define __TAG_MASK 0b11
1.35 -#define __INTEGER(ATTR) (((ATTR).intvalue & __TAG_MASK) == __TAG_INT)
1.36 +#define __TAG_REPLACING 0b10
1.37 +#define __INTEGER(ATTR) ((ATTR).intvalue & __TAG_INT)
1.38
1.39 /* Attribute value setting. */
1.40
1.41 @@ -143,6 +148,12 @@
1.42 #define __MAXINT ((((__int) 1) << ((sizeof(__int) * 8) - 1 - __NUM_TAG_BITS)) - 1)
1.43 #define __MININT (-(((__int) 1) << ((sizeof(__int) * 8) - 1 - __NUM_TAG_BITS)))
1.44
1.45 +/* Attribute carrying replacement value. */
1.46 +
1.47 +#define __REPLACEMENT(ATTR) ((__attr) {.refvalue=(((__ref_tagged) (ATTR).value) | __TAG_REPLACING)})
1.48 +#define __REPLACED(ATTR) ((__attr) {.value=((__ref) ((ATTR).refvalue & ~__TAG_REPLACING))})
1.49 +#define __REPLACING(ATTR) ((ATTR).refvalue & __TAG_REPLACING)
1.50 +
1.51 /* Argument lists. */
1.52
1.53 #define __ARGS(...) ((__attr[]) {__VA_ARGS__})