diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-02-29 13:28:39 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-02-29 13:28:39 -0500 |
| commit | 8171a38b7130849e3049a4ea15a4fd06c154d9b0 (patch) | |
| tree | 7ec4b204e6600ac3dc553d9caadfc722d04d0c8c /builtins/array.h | |
| parent | 764d9fe73b0c9da918d2ecf2c4031219a1fac5be (diff) | |
Add type namespaces
Diffstat (limited to 'builtins/array.h')
| -rw-r--r-- | builtins/array.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/builtins/array.h b/builtins/array.h index 86e57169..76ab29fd 100644 --- a/builtins/array.h +++ b/builtins/array.h @@ -18,6 +18,12 @@ 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 $TypedArray(t, ...) ({ t $items[] = {__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)), \ + .atomic=0, \ + .data_refcount=1}; }) #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], \ |
