1.1 --- a/templates/types.h Fri Jan 25 23:39:19 2019 +0100
1.2 +++ b/templates/types.h Sat Jan 26 00:50:47 2019 +0100
1.3 @@ -1,6 +1,6 @@
1.4 /* Runtime types.
1.5
1.6 -Copyright (C) 2015, 2016, 2017, 2018 Paul Boddie <paul@boddie.org.uk>
1.7 +Copyright (C) 2015, 2016, 2017, 2018, 2019 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,7 +75,7 @@
1.12 /* General attribute members. */
1.13
1.14 __ref value; /* attribute value */
1.15 - int intvalue; /* integer value data ((integer << 1) | 1) */
1.16 + int intvalue; /* integer value data (shifted value, tagged) */
1.17
1.18 /* Special case attribute members. */
1.19
1.20 @@ -117,31 +117,33 @@
1.21
1.22 /* Attribute interpretation. */
1.23
1.24 -#define __INTEGER(ATTR) ((ATTR).intvalue % 2)
1.25 +#define __NUM_TAG_BITS 1
1.26 +#define __TAG_INT 0b1
1.27 +#define __INTEGER(ATTR) ((ATTR).intvalue & __TAG_INT)
1.28
1.29 /* Attribute value setting. */
1.30
1.31 -#define __ATTRVALUE(VALUE) ((__attr) {.value=(__ref) VALUE})
1.32 -#define __NULL __ATTRVALUE(0)
1.33 -#define __SETNULL(ATTR) ((ATTR).value = 0)
1.34 +#define __ATTRVALUE(VALUE) ((__attr) {.value=(__ref) VALUE})
1.35 +#define __NULL __ATTRVALUE(0)
1.36 +#define __SETNULL(ATTR) ((ATTR).value = 0)
1.37
1.38 /* Attribute as instance setting. */
1.39
1.40 -#define __INTVALUE(VALUE) ((__attr) {.intvalue=((VALUE) << 1) | 1})
1.41 -#define __TOINT(ATTR) ((ATTR).intvalue >> 1)
1.42 -#define __MAXINT ((1 << ((sizeof(__attr) * 8) - 2)) - 1)
1.43 -#define __MININT (-(1 << ((sizeof(__attr) * 8) - 2)))
1.44 +#define __INTVALUE(VALUE) ((__attr) {.intvalue=((VALUE) << __NUM_TAG_BITS) | __TAG_INT})
1.45 +#define __TOINT(ATTR) ((ATTR).intvalue >> __NUM_TAG_BITS)
1.46 +#define __MAXINT ((1 << ((sizeof(__attr) * 8) - 1 - __NUM_TAG_BITS)) - 1)
1.47 +#define __MININT (-(1 << ((sizeof(__attr) * 8) - 1 - __NUM_TAG_BITS)))
1.48
1.49 /* Argument lists. */
1.50
1.51 -#define __ARGS(...) ((__attr[]) {__VA_ARGS__})
1.52 -#define __KWARGS(...) ((__param[]) {__VA_ARGS__})
1.53 +#define __ARGS(...) ((__attr[]) {__VA_ARGS__})
1.54 +#define __KWARGS(...) ((__param[]) {__VA_ARGS__})
1.55
1.56 /* Attribute codes and positions for attribute names. */
1.57
1.58 -#define __ATTRCODE(ATTRNAME) __code_##ATTRNAME
1.59 -#define __ATTRPOS(ATTRNAME) __pos_##ATTRNAME
1.60 -#define __PARAMCODE(PARAMNAME) __pcode_##PARAMNAME
1.61 -#define __PARAMPOS(PARAMNAME) __ppos_##PARAMNAME
1.62 +#define __ATTRCODE(ATTRNAME) __code_##ATTRNAME
1.63 +#define __ATTRPOS(ATTRNAME) __pos_##ATTRNAME
1.64 +#define __PARAMCODE(PARAMNAME) __pcode_##PARAMNAME
1.65 +#define __PARAMPOS(PARAMNAME) __ppos_##PARAMNAME
1.66
1.67 #endif /* __TYPES_H__ */