1.1 --- a/templates/types.h Sun Nov 14 00:50:17 2021 +0100
1.2 +++ b/templates/types.h Sun Nov 28 02:03:21 2021 +0100
1.3 @@ -42,6 +42,7 @@
1.4 typedef struct __table
1.5 {
1.6 const __pos size;
1.7 + const size_t obj_size; /* size for value instance copying */
1.8 const __code attrs[];
1.9 } __table;
1.10
1.11 @@ -80,6 +81,11 @@
1.12
1.13 typedef _Float64 __float;
1.14
1.15 +/* Introduce value stack section and descriptor. */
1.16 +
1.17 +typedef struct __section __section;
1.18 +typedef struct __stackdesc __stackdesc;
1.19 +
1.20 /* Attribute value interpretations. */
1.21
1.22 typedef union __attr
1.23 @@ -101,6 +107,11 @@
1.24 __fragment * seqvalue; /* sequence data */
1.25 void * datavalue; /* object-specific data */
1.26 __int sizevalue; /* object-specific size */
1.27 +
1.28 + /* Value stack parameter member. */
1.29 +
1.30 + __stackdesc *stackdesc; /* reference to value stack descriptor */
1.31 +
1.32 } __attr;
1.33
1.34 typedef struct __obj
1.35 @@ -115,7 +126,7 @@
1.36
1.37 } __obj;
1.38
1.39 -#define __INSTANCE_SIZE(NUMBER) ((NUMBER) * sizeof(__attr) + sizeof(__table *) + sizeof(__ppos))
1.40 +#define __INSTANCE_SIZE(REF) ((REF)->table->obj_size)
1.41
1.42 /* Fragments are simple collections of attributes employed by sequence types.
1.43 They provide the basis of lists and tuples. */
1.44 @@ -128,17 +139,33 @@
1.45
1.46 #define __FRAGMENT_SIZE(NUMBER) ((NUMBER) * sizeof(__attr) + 2 * sizeof(__int))
1.47
1.48 +/* Sections are used to provide the value stack. */
1.49 +
1.50 +typedef struct __section
1.51 +{
1.52 + char *base, *level, *limit;
1.53 + __section *previous;
1.54 +} __section;
1.55 +
1.56 +/* The value stack descriptor references the current value stack section. */
1.57 +
1.58 +typedef struct __stackdesc
1.59 +{
1.60 + __section *current;
1.61 +} __stackdesc;
1.62 +
1.63 /* Attribute interpretation. */
1.64
1.65 #define __NUM_TAG_BITS 2
1.66 -#define __TAG_COPYABLE 0b01UL
1.67 #define __TAG_MUTABLE 0b10UL
1.68 #define __TAG_MASK 0b11UL
1.69
1.70 -#define __COPYABLE(ATTR) ((ATTR).rawvalue & __TAG_COPYABLE)
1.71 +#define __COPYABLE(ATTR) (__VALUE(ATTR)->table->obj_size != 0)
1.72 #define __MUTABLE(ATTR) ((ATTR).rawvalue & __TAG_MUTABLE)
1.73 #define __TO_IMMUTABLE(ATTR) ((__attr) {.rawvalue=(ATTR).rawvalue & (~__TAG_MUTABLE)})
1.74 -#define __TO_MUTABLE(ATTR) ((__attr) {.rawvalue=(ATTR).rawvalue | __TAG_MASK})
1.75 +#define __TO_MUTABLE(ATTR) ((__attr) {.rawvalue=(ATTR).rawvalue | __TAG_MUTABLE})
1.76 +#define __MUTABLEVALUE(REF) ((__attr) {.rawvalue=(uintptr_t) REF | __TAG_MUTABLE})
1.77 +#define __RAWVALUE(VALUE) ((__attr) {.rawvalue=VALUE})
1.78
1.79 /* Attribute value setting. */
1.80