From 8171a38b7130849e3049a4ea15a4fd06c154d9b0 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 29 Feb 2024 13:28:39 -0500 Subject: Add type namespaces --- builtins/array.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'builtins/array.h') 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], \ -- cgit v1.2.3