# HG changeset patch # User Paul Boddie # Date 1636214761 -3600 # Node ID c7bd72a6309b4e5a4f74f8b0f98110dc0aeef4e0 # Parent 150186eee8e780f64b5a3eb1f4c382b9752b57e7 Introduced a mutable value tag in place of type-specific tags. diff -r 150186eee8e7 -r c7bd72a6309b templates/native/common.c --- a/templates/native/common.c Sat Nov 06 01:05:42 2021 +0100 +++ b/templates/native/common.c Sat Nov 06 17:06:01 2021 +0100 @@ -31,7 +31,7 @@ /* Create a new int and set the trailing data. */ __attr attr = __NEWINSTANCEIM(__builtins___int_int); __set_trailing_data(attr, __builtins___int_int, n); - return attr; + return __TO_MUTABLE(attr); } __attr __new_str(char *s, __int size) @@ -57,7 +57,7 @@ /* Create a new float and set the trailing data. */ __attr attr = __NEWINSTANCEIM(__builtins___float_float); __set_trailing_data(attr, __builtins___float_float, n); - return attr; + return __TO_MUTABLE(attr); } __fragment *__fragment_append(__fragment *data, __attr value) diff -r 150186eee8e7 -r c7bd72a6309b templates/ops.c --- a/templates/ops.c Sat Nov 06 01:05:42 2021 +0100 +++ b/templates/ops.c Sat Nov 06 17:06:01 2021 +0100 @@ -1,6 +1,6 @@ /* Common operations. -Copyright (C) 2015, 2016, 2017, 2018, 2021 Paul Boddie +Copyright (C) 2015-2018, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -27,7 +27,7 @@ __ref __VALUE(__attr attr) { - return attr.value; + return (__ref) (attr.rawvalue & (~__TAG_MASK)); } /* Basic structure tests. */ diff -r 150186eee8e7 -r c7bd72a6309b templates/ops.h --- a/templates/ops.h Sat Nov 06 01:05:42 2021 +0100 +++ b/templates/ops.h Sat Nov 06 17:06:01 2021 +0100 @@ -1,6 +1,6 @@ /* Common operations. -Copyright (C) 2015, 2016, 2017, 2018 Paul Boddie +Copyright (C) 2015-2018, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -136,7 +136,7 @@ __ref __ISFUNC(__ref obj); -#define __ISNULL(__ATTR) (!__ATTR.value) +#define __ISNULL(__ATTR) (!(__ATTR.rawvalue & (~__TAG_MASK))) /* Attribute codes and positions for type objects. */ diff -r 150186eee8e7 -r c7bd72a6309b templates/progops.c --- a/templates/progops.c Sat Nov 06 01:05:42 2021 +0100 +++ b/templates/progops.c Sat Nov 06 17:06:01 2021 +0100 @@ -332,7 +332,7 @@ /* Test against True and False explicitly. If necessary, invoke the bool function with the object and test against True. */ - value = attr.value; + value = __VALUE(attr); return value == (__ref) &__predefined___builtins___boolean_True ? 1 : value == (__ref) &__predefined___builtins___boolean_False ? 0 : diff -r 150186eee8e7 -r c7bd72a6309b templates/progops.h --- a/templates/progops.h Sat Nov 06 01:05:42 2021 +0100 +++ b/templates/progops.h Sat Nov 06 17:06:01 2021 +0100 @@ -90,8 +90,8 @@ /* Operations for accessing trailing data. */ -#define __get_trailing_data(ATTR, TYPE) (((__OBJTYPE(TYPE) *) ((ATTR).value))->trailing) -#define __set_trailing_data(ATTR, TYPE, VALUE) ((__OBJTYPE(TYPE) *) ((ATTR).value))->trailing = VALUE; +#define __get_trailing_data(ATTR, TYPE) (((__OBJTYPE(TYPE) *) (__VALUE(ATTR)))->trailing) +#define __set_trailing_data(ATTR, TYPE, VALUE) ((__OBJTYPE(TYPE) *) (__VALUE(ATTR)))->trailing = VALUE; /* Specialised trailing data functions. */ diff -r 150186eee8e7 -r c7bd72a6309b templates/types.h --- a/templates/types.h Sat Nov 06 01:05:42 2021 +0100 +++ b/templates/types.h Sat Nov 06 17:06:01 2021 +0100 @@ -130,15 +130,12 @@ /* Attribute interpretation. */ -#define __NUM_TAG_BITS 2 -#define __TAG_INT 0b01 -#define __TAG_FLOAT 0b10 -#define __TAG_MASK 0b11 +#define __NUM_TAG_BITS 1 +#define __TAG_MUTABLE 0b1 +#define __TAG_MASK 0b1 -#if 0 -#define __INTEGER(ATTR) (((ATTR).rawvalue & __TAG_MASK) == __TAG_INT) -#define __FLOAT(ATTR) (((ATTR).rawvalue & __TAG_MASK) == __TAG_FLOAT) -#endif +#define __MUTABLE(ATTR) (((ATTR).rawvalue & __TAG_MASK) == __TAG_MUTABLE) +#define __TO_MUTABLE(ATTR) ((__attr) (((ATTR).rawvalue & (~__TAG_MASK)) | __TAG_MUTABLE)) /* Attribute value setting. */