Set up 'atomic' for arrays

This commit is contained in:
Bruce Hill 2024-02-23 13:40:24 -05:00
parent 4df2f8e4cb
commit c04b373cb4

View File

@ -17,10 +17,12 @@
#define $Array_get_unchecked(type, x, i) ({ const array_t *$arr = x; int64_t $index = (int64_t)(i); \
int64_t $off = $index + ($index < 0) * ($arr->length + 1) - 1; \
*(type*)($arr->data + $arr->stride * $off);})
#define $is_atomic(x) _Generic(x, bool: true, int8_t: true, int16_t: true, int32_t: true, int64_t: true, float: true, double: true, default: false)
#define $Array(x, ...) ({ __typeof(x) $items[] = {x, __VA_ARGS__}; \
(array_t){.length=sizeof($items)/sizeof($items[0]), \
.stride=(int64_t)&$items[1] - (int64_t)&$items[0], \
.data=memcpy(GC_MALLOC(sizeof($items)), $items, sizeof($items)), \
.data=memcpy($is_atomic(x) ? GC_MALLOC_ATOMIC(sizeof($items)) : GC_MALLOC(sizeof($items)), $items, sizeof($items)), \
.atomic=$is_atomic(x), \
.copy_on_write=1}; })
void Array__insert(array_t *arr, const void *item, int64_t index, const TypeInfo *type);