diff options
| author | Tyge Løvset <[email protected]> | 2023-01-19 21:20:16 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-01-19 21:20:16 +0100 |
| commit | f8accdbcee0b397ad6ba2f2c2c64575a003e71e5 (patch) | |
| tree | 1ec8e47eb15fd69d53e394e143c36d7f3500643e /include | |
| parent | 5aa48d538569463ffeda976d21f79edc5f276be4 (diff) | |
| download | STC-modified-f8accdbcee0b397ad6ba2f2c2c64575a003e71e5.tar.gz STC-modified-f8accdbcee0b397ad6ba2f2c2c64575a003e71e5.zip | |
Finish last commit. Most safe function macros are now preferred lowercase, whereas flow control macros (c_FOREACH, ..) are preferred uppercase.
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/algo/crange.h | 2 | ||||
| -rw-r--r-- | include/stc/algo/csort.h | 6 | ||||
| -rw-r--r-- | include/stc/algo/filter.h | 12 | ||||
| -rw-r--r-- | include/stc/carc.h | 4 | ||||
| -rw-r--r-- | include/stc/cbits.h | 4 | ||||
| -rw-r--r-- | include/stc/cbox.h | 6 | ||||
| -rw-r--r-- | include/stc/ccommon.h | 33 | ||||
| -rw-r--r-- | include/stc/cdeq.h | 8 | ||||
| -rw-r--r-- | include/stc/clist.h | 8 | ||||
| -rw-r--r-- | include/stc/cmap.h | 10 | ||||
| -rw-r--r-- | include/stc/cpque.h | 2 | ||||
| -rw-r--r-- | include/stc/crandom.h | 4 | ||||
| -rw-r--r-- | include/stc/csmap.h | 4 | ||||
| -rw-r--r-- | include/stc/cspan.h | 13 | ||||
| -rw-r--r-- | include/stc/cstack.h | 4 | ||||
| -rw-r--r-- | include/stc/cstr.h | 16 | ||||
| -rw-r--r-- | include/stc/csview.h | 10 | ||||
| -rw-r--r-- | include/stc/cvec.h | 10 | ||||
| -rw-r--r-- | include/stc/priv/lowcase.h | 26 |
19 files changed, 91 insertions, 91 deletions
diff --git a/include/stc/algo/crange.h b/include/stc/algo/crange.h index 63242a54..5e1610d9 100644 --- a/include/stc/algo/crange.h +++ b/include/stc/algo/crange.h @@ -36,7 +36,7 @@ int main() int a = 100, b = INT32_MAX; c_FORFILTER (i, crange, crange_literal(a, b, 8) , i.index > 10 - , c_FLT_TAKE(i, 3)) + , c_flt_take(i, 3)) printf(" %lld", *i.ref); puts(""); } diff --git a/include/stc/algo/csort.h b/include/stc/algo/csort.h index 2cd7b548..9c9bcd5b 100644 --- a/include/stc/algo/csort.h +++ b/include/stc/algo/csort.h @@ -84,13 +84,13 @@ static inline void c_PASTE(cqsort_, i_tag)(i_val arr[], intptr_t lo, intptr_t hi while (i_less((&arr[i]), (&pivot))) ++i; while (i_less((&pivot), (&arr[j]))) --j; if (i <= j) { - c_SWAP(i_val, arr+i, arr+j); + c_swap(i_val, arr+i, arr+j); ++i; --j; } } if (j - lo > hi - i) { - c_SWAP(intptr_t, &lo, &i); - c_SWAP(intptr_t, &hi, &j); + c_swap(intptr_t, &lo, &i); + c_swap(intptr_t, &hi, &j); } if (j - lo > 64) c_PASTE(cqsort_, i_tag)(arr, lo, j); diff --git a/include/stc/algo/filter.h b/include/stc/algo/filter.h index e941be2e..0f850f41 100644 --- a/include/stc/algo/filter.h +++ b/include/stc/algo/filter.h @@ -37,9 +37,9 @@ int main() puts(""); c_FORFILTER (i, cstack_int, stk - , c_FLT_SKIPWHILE(i, *i.ref < 3) + , c_flt_skipwhile(i, *i.ref < 3) && (*i.ref & 1) == 0 // even only - , c_FLT_TAKE(i, 2)) // break after 2 + , c_flt_take(i, 2)) // break after 2 printf(" %d", *i.ref); puts(""); } @@ -54,10 +54,10 @@ int main() #define c_NFILTERS 14 /* 22, 30, .. */ #endif -#define c_FLT_TAKE(i, n) (++(i).s1[(i).s1top++] <= (n)) -#define c_FLT_SKIP(i, n) (++(i).s1[(i).s1top++] > (n)) -#define c_FLT_SKIPWHILE(i, pred) ((i).s2[(i).s2top++] |= !(pred)) -#define c_FLT_TAKEWHILE(i, pred) !c_FLT_SKIPWHILE(i, pred) +#define c_flt_take(i, n) (++(i).s1[(i).s1top++] <= (n)) +#define c_flt_skip(i, n) (++(i).s1[(i).s1top++] > (n)) +#define c_flt_skipwhile(i, pred) ((i).s2[(i).s2top++] |= !(pred)) +#define c_flt_takewhile(i, pred) !c_flt_skipwhile(i, pred) #define c_FORFILTER(...) c_MACRO_OVERLOAD(c_FORFILTER, __VA_ARGS__) diff --git a/include/stc/carc.h b/include/stc/carc.h index 614af18e..fa2ee3b4 100644 --- a/include/stc/carc.h +++ b/include/stc/carc.h @@ -45,7 +45,7 @@ int main() { ArcPers q = ArcPers_clone(p); // share the pointer printf("%s %s. uses: %ld\n", cstr_str(&q.get->name), cstr_str(&q.get->last), *q.use_count); - c_DROP(ArcPers, &p, &q); + c_drop(ArcPers, &p, &q); } */ #include "ccommon.h" @@ -93,7 +93,7 @@ _cx_deftypes(_c_carc_types, _cx_self, i_key); struct _cx_memb(_rep_) { catomic_long counter; i_key value; }; STC_INLINE _cx_self _cx_memb(_init)(void) - { return c_INIT(_cx_self){NULL, NULL}; } + { return c_COMPOUND(_cx_self){NULL, NULL}; } STC_INLINE long _cx_memb(_use_count)(const _cx_self* self) { return self->use_count ? *self->use_count : 0; } diff --git a/include/stc/cbits.h b/include/stc/cbits.h index 6a71487f..b0cb7a9c 100644 --- a/include/stc/cbits.h +++ b/include/stc/cbits.h @@ -123,7 +123,7 @@ STC_INLINE bool _cbits_disjoint(const uint64_t* set, const uint64_t* other, cons struct { uint64_t *data64; size_t _size; } typedef i_type; -STC_INLINE cbits cbits_init(void) { return c_INIT(cbits){NULL}; } +STC_INLINE cbits cbits_init(void) { return c_COMPOUND(cbits){NULL}; } STC_INLINE void cbits_create(cbits* self) { self->data64 = NULL; self->_size = 0; } STC_INLINE void cbits_drop(cbits* self) { c_FREE(self->data64); } STC_INLINE size_t cbits_size(const cbits* self) { return self->_size; } @@ -195,7 +195,7 @@ STC_INLINE cbits cbits_with_pattern(const size_t size, const uint64_t pattern) { struct { uint64_t data64[(i_capacity - 1)/64 + 1]; } typedef i_type; -STC_INLINE i_type _i_memb(_init)(void) { return c_INIT(i_type){0}; } +STC_INLINE i_type _i_memb(_init)(void) { return c_COMPOUND(i_type){0}; } STC_INLINE void _i_memb(_create)(i_type* self) {} STC_INLINE void _i_memb(_drop)(i_type* self) {} STC_INLINE size_t _i_memb(_size)(const i_type* self) { return i_capacity; } diff --git a/include/stc/cbox.h b/include/stc/cbox.h index 95dfdf8f..6dc41ed1 100644 --- a/include/stc/cbox.h +++ b/include/stc/cbox.h @@ -37,7 +37,7 @@ Person Person_clone(Person p) { } void Person_drop(Person* p) { printf("drop: %s %s\n", cstr_str(&p->name), cstr_str(&p->email)); - c_DROP(cstr, &p->name, &p->email); + c_drop(cstr, &p->name, &p->email); } #define i_keyclass Person // bind Person clone+drop fn's @@ -79,13 +79,13 @@ _cx_deftypes(_c_cbox_types, _cx_self, i_key); // constructors (take ownership) STC_INLINE _cx_self _cx_memb(_init)(void) - { return c_INIT(_cx_self){NULL}; } + { return c_COMPOUND(_cx_self){NULL}; } STC_INLINE long _cx_memb(_use_count)(const _cx_self* self) { return (long)(self->get != NULL); } STC_INLINE _cx_self _cx_memb(_from_ptr)(_cx_value* p) - { return c_INIT(_cx_self){p}; } + { return c_COMPOUND(_cx_self){p}; } // c++: std::make_unique<i_key>(val) STC_INLINE _cx_self _cx_memb(_make)(_cx_value val) { diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index d7b68d1f..09befa56 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -71,12 +71,12 @@ #define c_ALLOC(T) static_cast<T*>(c_MALLOC(sizeof(T))) #define c_ALLOC_N(T, n) static_cast<T*>(c_MALLOC(sizeof(T)*(n))) #define c_NEW(T, ...) new (c_ALLOC(T)) T(__VA_ARGS__) - #define c_INIT(T) T + #define c_COMPOUND(T) T #else #define c_ALLOC(T) ((T*)c_MALLOC(sizeof(T))) #define c_ALLOC_N(T, n) ((T*)c_MALLOC(sizeof(T)*(n))) #define c_NEW(T, ...) ((T*)memcpy(c_ALLOC(T), (T[]){__VA_ARGS__}, sizeof(T))) - #define c_INIT(T) (T) + #define c_COMPOUND(T) (T) #endif #ifndef c_MALLOC #define c_MALLOC(sz) malloc(sz) @@ -85,12 +85,11 @@ #define c_FREE(p) free(p) #endif -#define c_STATIC_ASSERT(b) ((int)(0*sizeof(int[(b) ? 1 : -1]))) -#define c_CONTAINER_OF(p, T, m) ((T*)((char*)(p) + 0*sizeof((p) == &((T*)0)->m) - offsetof(T, m))) -#define c_DELETE(T, ptr) do { T *_tp = ptr; T##_drop(_tp); c_FREE(_tp); } while (0) -#define c_SWAP(T, xp, yp) do { T *_xp = xp, *_yp = yp, \ +#define c_static_assert(b) ((int)(0*sizeof(int[(b) ? 1 : -1]))) +#define c_container_of(p, T, m) ((T*)((char*)(p) + 0*sizeof((p) == &((T*)0)->m) - offsetof(T, m))) +#define c_delete(T, ptr) do { T *_tp = ptr; T##_drop(_tp); c_FREE(_tp); } while (0) +#define c_swap(T, xp, yp) do { T *_xp = xp, *_yp = yp, \ _tv = *_xp; *_xp = *_yp; *_yp = _tv; } while (0) -#define c_ARRAYLEN(a) (sizeof(a)/sizeof 0[a]) // x and y are i_keyraw* type, defaults to i_key*: #define c_default_cmp(x, y) (c_default_less(y, x) - c_default_less(x, y)) @@ -115,18 +114,18 @@ #define c_initialize(C, ...) \ C##_from_n((C##_raw[])__VA_ARGS__, sizeof((C##_raw[])__VA_ARGS__)/sizeof(C##_raw)) -#define c_literal(C, ...) (*(C[]){c_initialize(C, __VA_ARGS__)}) -/* Generic algorithms */ +/* Function macros and various others */ typedef const char* crawstr; #define crawstr_cmp(xp, yp) strcmp(*(xp), *(yp)) #define crawstr_hash(p) cstrhash(*(p)) #define crawstr_len(literal) (sizeof("" literal) - 1U) +#define c_ARRAYLEN(a) (sizeof(a)/sizeof 0[a]) #define c_SV(...) c_MACRO_OVERLOAD(c_SV, __VA_ARGS__) #define c_SV1(lit) c_SV2(lit, crawstr_len(lit)) -#define c_SV2(str, n) (c_INIT(csview){str, n}) +#define c_SV2(str, n) (c_COMPOUND(csview){str, n}) #define c_ARGSV(sv) (int)(sv).size, (sv).str /* use with "%.*s" */ #define c_PAIR(ref) (ref)->first, (ref)->second @@ -166,6 +165,8 @@ STC_INLINE char* cstrnstrn(const char *str, const char *needle, return NULL; } +/* Control block macros */ + #define c_FOREACH(...) c_MACRO_OVERLOAD(c_FOREACH, __VA_ARGS__) #define c_FOREACH3(it, C, cnt) \ for (C##_iter it = C##_begin(&cnt); it.ref; C##_next(&it)) @@ -208,7 +209,6 @@ STC_INLINE char* cstrnstrn(const char *str, const char *needle, #define c_WITH3(declvar, pred, drop) for (declvar, **_c_i = NULL; !_c_i && (pred); ++_c_i, drop) #define c_SCOPE(init, drop) for (int _c_i = (init, 1); _c_i; --_c_i, drop) #define c_DEFER(...) for (int _c_i = 1; _c_i; --_c_i, __VA_ARGS__) -#define c_DROP(C, ...) do { c_FORLIST (_i, C*, {__VA_ARGS__}) C##_drop(*_i.ref); } while(0) #define c_AUTO(...) c_MACRO_OVERLOAD(c_AUTO, __VA_ARGS__) #define c_AUTO2(C, a) \ @@ -223,13 +223,16 @@ STC_INLINE char* cstrnstrn(const char *str, const char *needle, c_WITH2(c_EXPAND(C a = C##_init(), b = C##_init(), c = C##_init(), d = C##_init()), \ (C##_drop(&d), C##_drop(&c), C##_drop(&b), C##_drop(&a))) -#define c_FIND_IF(...) c_MACRO_OVERLOAD(c_FIND_IF, __VA_ARGS__) -#define c_FIND_IF4(it, C, cnt, pred) do { \ +/* Generic functions */ + +#define c_drop(C, ...) do { c_FORLIST (_i, C*, {__VA_ARGS__}) C##_drop(*_i.ref); } while(0) +#define c_find_if(...) c_MACRO_OVERLOAD(c_find_if, __VA_ARGS__) +#define c_find_if4(it, C, cnt, pred) do { \ size_t index = 0; \ for (it = C##_begin(&cnt); it.ref && !(pred); C##_next(&it)) \ ++index; \ } while (0) -#define c_FIND_IF5(it, C, start, end, pred) do { \ +#define c_find_if5(it, C, start, end, pred) do { \ size_t index = 0; \ const C##_value* _endref = (end).ref; \ for (it = start; it.ref != _endref && !(pred); C##_next(&it)) \ @@ -237,7 +240,7 @@ STC_INLINE char* cstrnstrn(const char *str, const char *needle, if (it.ref == _endref) it.ref = NULL; \ } while (0) -#define c_ERASE_IF(it, C, cnt, pred) do { \ +#define c_erase_if(it, C, cnt, pred) do { \ C##_iter it = C##_begin(&cnt); \ for (size_t index = 0; it.ref; ++index) { \ if (pred) it = C##_erase_at(&cnt, it); \ diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h index b555da63..befb4146 100644 --- a/include/stc/cdeq.h +++ b/include/stc/cdeq.h @@ -101,11 +101,11 @@ STC_INLINE void _cx_memb(_pop_front)(_cx_self* self) // == _pop() when _ STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { size_t n = self->_len; - return c_INIT(_cx_iter){n ? self->data : NULL, self->data + n}; + return c_COMPOUND(_cx_iter){n ? self->data : NULL, self->data + n}; } STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) - { return c_INIT(_cx_iter){NULL, self->data + self->_len}; } + { return c_COMPOUND(_cx_iter){NULL, self->data + self->_len}; } STC_INLINE void _cx_memb(_next)(_cx_iter* it) { if (++it->ref == it->end) it->ref = NULL; } @@ -345,7 +345,7 @@ _cx_memb(_insert_uninit)(_cx_self* self, _cx_value* pos, const size_t n) { self->_len += n; pos = self->data + idx; } - return c_INIT(_cx_iter){pos, self->data + self->_len}; + return c_COMPOUND(_cx_iter){pos, self->data + self->_len}; } STC_DEF _cx_value* @@ -377,7 +377,7 @@ _cx_memb(_erase_range_p)(_cx_self* self, _cx_value* p1, _cx_value* p2) { { i_keydrop(p); } memmove(p1, p2, (size_t)(end - p2)*sizeof *p1); self->_len -= (size_t)len; - return c_INIT(_cx_iter){p2 == end ? NULL : p1, end - len}; + return c_COMPOUND(_cx_iter){p2 == end ? NULL : p1, end - len}; } #if !defined i_no_clone diff --git a/include/stc/clist.h b/include/stc/clist.h index ac687fc9..de32b931 100644 --- a/include/stc/clist.h +++ b/include/stc/clist.h @@ -64,7 +64,7 @@ SELF##_value value; \ } -#define _clist_tonode(vp) c_CONTAINER_OF(vp, _cx_node, value) +#define _clist_tonode(vp) c_container_of(vp, _cx_node, value) _c_clist_types(clist_VOID, int); _c_clist_complete_types(clist_VOID, dummy); @@ -133,7 +133,7 @@ STC_INLINE _cx_value* _cx_memb(_emplace)(_cx_self* self, _cx_raw raw) { return _cx_memb(_push_back)(self, i_keyfrom(raw)); } #endif // !i_no_emplace -STC_INLINE _cx_self _cx_memb(_init)(void) { return c_INIT(_cx_self){NULL}; } +STC_INLINE _cx_self _cx_memb(_init)(void) { return c_COMPOUND(_cx_self){NULL}; } STC_INLINE void _cx_memb(_put_n)(_cx_self* self, const _cx_raw* raw, size_t n) { while (n--) _cx_memb(_push_back)(self, i_keyfrom(*raw++)); } STC_INLINE _cx_self _cx_memb(_from_n)(const _cx_raw* raw, size_t n) @@ -161,12 +161,12 @@ _cx_memb(_count)(const _cx_self* self) { STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { _cx_value* head = self->last ? &self->last->next->value : NULL; - return c_INIT(_cx_iter){head, &self->last, self->last}; + return c_COMPOUND(_cx_iter){head, &self->last, self->last}; } STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) - { return c_INIT(_cx_iter){NULL}; } + { return c_COMPOUND(_cx_iter){NULL}; } STC_INLINE void _cx_memb(_next)(_cx_iter* it) { diff --git a/include/stc/cmap.h b/include/stc/cmap.h index e63adb77..c2f8cf3e 100644 --- a/include/stc/cmap.h +++ b/include/stc/cmap.h @@ -107,7 +107,7 @@ STC_API chash_bucket_t _cx_memb(_bucket_)(const _cx_self* self, const _cx_rawke STC_API _cx_result _cx_memb(_insert_entry_)(_cx_self* self, _cx_rawkey rkey); STC_API void _cx_memb(_erase_entry)(_cx_self* self, _cx_value* val); -STC_INLINE _cx_self _cx_memb(_init)(void) { return c_INIT(_cx_self){0}; } +STC_INLINE _cx_self _cx_memb(_init)(void) { return c_COMPOUND(_cx_self){0}; } STC_INLINE void _cx_memb(_shrink_to_fit)(_cx_self* self) { _cx_memb(_reserve)(self, self->size); } STC_INLINE float _cx_memb(_max_load_factor)(const _cx_self* self) { return (float)(i_max_load_factor); } STC_INLINE bool _cx_memb(_empty)(const _cx_self* map) { return !map->size; } @@ -166,7 +166,7 @@ _cx_memb(_emplace)(_cx_self* self, _cx_rawkey rkey _i_MAP_ONLY(, i_valraw rmappe STC_INLINE _cx_raw _cx_memb(_value_toraw)(const _cx_value* val) { return _i_SET_ONLY( i_keyto(val) ) - _i_MAP_ONLY( c_INIT(_cx_raw){i_keyto((&val->first)), i_valto((&val->second))} ); + _i_MAP_ONLY( c_COMPOUND(_cx_raw){i_keyto((&val->first)), i_valto((&val->second))} ); } STC_INLINE void @@ -222,7 +222,7 @@ STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) - { return c_INIT(_cx_iter){NULL}; } + { return c_COMPOUND(_cx_iter){NULL}; } STC_INLINE void _cx_memb(_next)(_cx_iter* it) { @@ -240,7 +240,7 @@ STC_INLINE _cx_iter _cx_memb(_find)(const _cx_self* self, _cx_rawkey rkey) { size_t idx; if (self->size && self->_hashx[idx = _cx_memb(_bucket_)(self, &rkey).idx]) - return c_INIT(_cx_iter){self->table + idx, + return c_COMPOUND(_cx_iter){self->table + idx, self->table + self->bucket_count, self->_hashx + idx}; return _cx_memb(_end)(self); @@ -430,7 +430,7 @@ _cx_memb(_reserve)(_cx_self* self, const size_t _newcap) { m.table[b.idx] = *e; m._hashx[b.idx] = (uint8_t)b.hx; } - c_SWAP(_cx_self, self, &m); + c_swap(_cx_self, self, &m); } c_FREE(m._hashx); c_FREE(m.table); diff --git a/include/stc/cpque.h b/include/stc/cpque.h index f1f03f8e..83fcb684 100644 --- a/include/stc/cpque.h +++ b/include/stc/cpque.h @@ -45,7 +45,7 @@ STC_API void _cx_memb(_erase_at)(_cx_self* self, size_t idx); STC_API void _cx_memb(_push)(_cx_self* self, _cx_value value); STC_INLINE _cx_self _cx_memb(_init)(void) - { return c_INIT(_cx_self){NULL}; } + { return c_COMPOUND(_cx_self){NULL}; } STC_INLINE void _cx_memb(_put_n)(_cx_self* self, const _cx_raw* raw, size_t n) { while (n--) _cx_memb(_push)(self, i_keyfrom(*raw++)); } diff --git a/include/stc/crandom.h b/include/stc/crandom.h index 733c3ec5..9cb23e93 100644 --- a/include/stc/crandom.h +++ b/include/stc/crandom.h @@ -100,12 +100,12 @@ STC_INLINE double stc64_uniformf(stc64_t* rng, stc64_uniformf_t* dist) { /* Init uniform distributed float64 RNG, range [low, high). */ STC_INLINE stc64_uniformf_t stc64_uniformf_new(double low, double high) { - return c_INIT(stc64_uniformf_t){low, high - low}; + return c_COMPOUND(stc64_uniformf_t){low, high - low}; } /* Marsaglia polar method for gaussian/normal distribution, float64. */ STC_INLINE stc64_normalf_t stc64_normalf_new(double mean, double stddev) { - return c_INIT(stc64_normalf_t){mean, stddev, 0.0, 0}; + return c_COMPOUND(stc64_normalf_t){mean, stddev, 0.0, 0}; } /* -------------------------- IMPLEMENTATION ------------------------- */ diff --git a/include/stc/csmap.h b/include/stc/csmap.h index 75f10308..67b2265e 100644 --- a/include/stc/csmap.h +++ b/include/stc/csmap.h @@ -143,7 +143,7 @@ _cx_memb(_clear)(_cx_self* self) STC_INLINE _cx_raw _cx_memb(_value_toraw)(const _cx_value* val) { return _i_SET_ONLY( i_keyto(val) ) - _i_MAP_ONLY( c_INIT(_cx_raw){i_keyto((&val->first)), + _i_MAP_ONLY( c_COMPOUND(_cx_raw){i_keyto((&val->first)), i_valto((&val->second))} ); } @@ -231,7 +231,7 @@ _cx_memb(_reserve)(_cx_self* self, const size_t cap) { _cx_node* nodes = (_cx_node*)c_REALLOC(self->nodes, (cap + 1)*sizeof(_cx_node)); if (!nodes) return false; - nodes[0] = c_INIT(_cx_node){{0, 0}, 0}; + nodes[0] = c_COMPOUND(_cx_node){{0, 0}, 0}; self->nodes = nodes; self->cap = (i_size)cap; return true; diff --git a/include/stc/cspan.h b/include/stc/cspan.h index 9969a670..88e10b07 100644 --- a/include/stc/cspan.h +++ b/include/stc/cspan.h @@ -40,18 +40,17 @@ int demo1() { } int demo2() { - int array[] = {1, 2, 3, 4, 5}; + int array[] = {10, 20, 30, 23, 22, 21}; Intspan span = cspan_from_array(array); c_FOREACH (i, Intspan, span) printf(" %d", *i.ref); puts(""); - // use a temporary Intspan object. - c_FORFILTER (i, Intspan, c_literal(Intspan, {10, 20, 30, 23, 22, 21}) - , c_FLT_SKIPWHILE(i, *i.ref < 25) + c_FORFILTER (i, Intspan, span, + , c_flt_skipwhile(i, *i.ref < 25) && (*i.ref & 1) == 0 // even only - , c_FLT_TAKE(i, 2)) // break after 2 + , c_flt_take(i, 2)) // break after 2 printf(" %d", *i.ref); puts(""); } @@ -86,7 +85,7 @@ int demo2() { #define using_cspan3(Self, T) using_cspan2(Self, T); using_cspan(Self##3, T, 3) #define using_cspan4(Self, T) using_cspan3(Self, T); using_cspan(Self##4, T, 4) -#define cspan_rank_ok(self, rank) c_STATIC_ASSERT(cspan_rank(self) == rank) +#define cspan_rank_ok(self, rank) c_static_assert(cspan_rank(self) == rank) #define cspan_make(array, ...) \ {.data=array, .dim={__VA_ARGS__}} @@ -96,7 +95,7 @@ int demo2() { {.data=(container)->data, .dim={(uint32_t)(container)->_len}} #define cspan_from_array(array) \ - {.data=(array) + c_STATIC_ASSERT(sizeof(array) != sizeof(void*)), .dim={c_ARRAYLEN(array)}} + {.data=(array) + c_static_assert(sizeof(array) != sizeof(void*)), .dim={c_ARRAYLEN(array)}} #define cspan_size(self) _cspan_size((self)->dim, cspan_rank(self)) #define cspan_rank(self) c_ARRAYLEN((self)->dim) diff --git a/include/stc/cstack.h b/include/stc/cstack.h index c1332769..a40b74de 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -175,12 +175,12 @@ STC_INLINE i_keyraw _cx_memb(_value_toraw)(const _cx_value* val) #endif // !i_no_clone STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { - return c_INIT(_cx_iter){self->_len ? (_cx_value*)self->data : NULL, + return c_COMPOUND(_cx_iter){self->_len ? (_cx_value*)self->data : NULL, (_cx_value*)self->data + self->_len}; } STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) - { return c_INIT(_cx_iter){NULL, (_cx_value*)self->data + self->_len}; } + { return c_COMPOUND(_cx_iter){NULL, (_cx_value*)self->data + self->_len}; } STC_INLINE void _cx_memb(_next)(_cx_iter* it) { if (++it->ref == it->end) it->ref = NULL; } diff --git a/include/stc/cstr.h b/include/stc/cstr.h index 46ad2fcd..b500065e 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -71,7 +71,7 @@ STC_API char* _cstr_internal_move(cstr* self, size_t pos1, size_t pos2); /**************************** PUBLIC API **********************************/ #define cstr_lit(literal) cstr_from_n(literal, crawstr_len(literal)) -#define cstr_NULL (c_INIT(cstr){{{0}, 0}}) +#define cstr_NULL (c_COMPOUND(cstr){{{0}, 0}}) #define cstr_toraw(self) cstr_str(self) STC_API char* cstr_reserve(cstr* self, size_t cap); @@ -90,12 +90,12 @@ STC_API cstr cstr_replace_sv(csview sv, csview search, csview repl, unsigned STC_INLINE cstr_buf cstr_buffer(cstr* s) { return cstr_is_long(s) - ? c_INIT(cstr_buf){s->lon.data, cstr_l_size(s), cstr_l_cap(s)} - : c_INIT(cstr_buf){s->sml.data, cstr_s_size(s), cstr_s_cap}; + ? c_COMPOUND(cstr_buf){s->lon.data, cstr_l_size(s), cstr_l_cap(s)} + : c_COMPOUND(cstr_buf){s->sml.data, cstr_s_size(s), cstr_s_cap}; } STC_INLINE csview cstr_sv(const cstr* s) { - return cstr_is_long(s) ? c_INIT(csview){s->lon.data, cstr_l_size(s)} - : c_INIT(csview){s->sml.data, cstr_s_size(s)}; + return cstr_is_long(s) ? c_COMPOUND(csview){s->lon.data, cstr_l_size(s)} + : c_COMPOUND(csview){s->sml.data, cstr_s_size(s)}; } STC_INLINE cstr cstr_init(void) @@ -222,11 +222,11 @@ STC_INLINE csview cstr_u8_chr(const cstr* self, size_t u8idx) { STC_INLINE cstr_iter cstr_begin(const cstr* self) { csview sv = cstr_sv(self); - if (!sv.size) return c_INIT(cstr_iter){NULL}; - return c_INIT(cstr_iter){.u8 = {{sv.str, utf8_chr_size(sv.str)}}}; + if (!sv.size) return c_COMPOUND(cstr_iter){NULL}; + return c_COMPOUND(cstr_iter){.u8 = {{sv.str, utf8_chr_size(sv.str)}}}; } STC_INLINE cstr_iter cstr_end(const cstr* self) { - (void)self; return c_INIT(cstr_iter){NULL}; + (void)self; return c_COMPOUND(cstr_iter){NULL}; } STC_INLINE void cstr_next(cstr_iter* it) { it->ref += it->u8.chr.size; diff --git a/include/stc/csview.h b/include/stc/csview.h index 1ab34d9a..fb860a66 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -37,7 +37,7 @@ STC_API size_t csview_find_sv(csview sv, csview search); STC_INLINE csview csview_from(const char* str) - { return c_INIT(csview){str, strlen(str)}; } + { return c_COMPOUND(csview){str, strlen(str)}; } STC_INLINE void csview_clear(csview* self) { *self = csview_NULL; } STC_INLINE size_t csview_size(csview sv) { return sv.size; } @@ -76,12 +76,12 @@ STC_INLINE csview csview_slice(csview sv, size_t p1, size_t p2) { /* utf8 iterator */ STC_INLINE csview_iter csview_begin(const csview* self) { - if (!self->size) return c_INIT(csview_iter){NULL}; - return c_INIT(csview_iter){.u8 = {{self->str, utf8_chr_size(self->str)}, - self->str + self->size}}; + if (!self->size) return c_COMPOUND(csview_iter){NULL}; + return c_COMPOUND(csview_iter){.u8 = {{self->str, utf8_chr_size(self->str)}, + self->str + self->size}}; } STC_INLINE csview_iter csview_end(const csview* self) { - return c_INIT(csview_iter){.u8 = {{NULL}, self->str + self->size}}; + return c_COMPOUND(csview_iter){.u8 = {{NULL}, self->str + self->size}}; } STC_INLINE void csview_next(csview_iter* it) { it->ref += it->u8.chr.size; diff --git a/include/stc/cvec.h b/include/stc/cvec.h index 7f8365d7..8010aea3 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -199,11 +199,11 @@ _cx_memb(_at_mut)(_cx_self* self, const size_t idx) { STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { size_t n = self->_len; - return c_INIT(_cx_iter){n ? self->data : NULL, self->data + n}; + return c_COMPOUND(_cx_iter){n ? self->data : NULL, self->data + n}; } STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) - { return c_INIT(_cx_iter){NULL, self->data + self->_len}; } + { return c_COMPOUND(_cx_iter){NULL, self->data + self->_len}; } STC_INLINE void _cx_memb(_next)(_cx_iter* it) { if (++it->ref == it->end) it->ref = NULL; } @@ -259,7 +259,7 @@ _cx_memb(_sort)(_cx_self* self) { STC_DEF _cx_self _cx_memb(_init)(void) { - return c_INIT(_cx_self){NULL}; + return c_COMPOUND(_cx_self){NULL}; } STC_DEF void @@ -328,7 +328,7 @@ _cx_memb(_insert_uninit)(_cx_self* self, _cx_value* pos, const size_t n) { memmove(pos + n, pos, (self->_len - idx)*sizeof *pos); self->_len += n; } - return c_INIT(_cx_iter){pos, self->data + self->_len}; + return c_COMPOUND(_cx_iter){pos, self->data + self->_len}; } STC_DEF _cx_iter @@ -348,7 +348,7 @@ _cx_memb(_erase_range_p)(_cx_self* self, _cx_value* p1, _cx_value* p2) { { i_keydrop(p); } memmove(p1, p2, (size_t)(end - p2)*sizeof *p1); self->_len -= len; - return c_INIT(_cx_iter){p2 == end ? NULL : p1, end - len}; + return c_COMPOUND(_cx_iter){p2 == end ? NULL : p1, end - len}; } #if !defined i_no_clone diff --git a/include/stc/priv/lowcase.h b/include/stc/priv/lowcase.h index 8fdadd75..cb6ed991 100644 --- a/include/stc/priv/lowcase.h +++ b/include/stc/priv/lowcase.h @@ -27,10 +27,6 @@ #define c_calloc c_CALLOC #define c_realloc c_REALLOC #define c_free c_FREE -#define c_delete c_DELETE -#define c_swap c_SWAP -#define c_container_of c_CONTAINER_OF -#define c_static_assert c_STATIC_ASSERT #define c_arraylen c_ARRAYLEN #define c_forlist c_FORLIST #define c_forrange c_FORRANGE @@ -45,14 +41,16 @@ #define c_with c_WITH #define c_scope c_SCOPE #define c_defer c_DEFER -#define c_drop c_DROP #define c_sv c_SV -#define c_ARGsv c_ARGSV -#define c_find_if c_FIND_IF -#define c_erase_if c_ERASE_IF -#define c_flt_take c_FLT_TAKE -#define c_flt_skip c_FLT_SKIP -#define c_flt_skipwhile c_FLT_SKIPWHILE -#define c_flt_takewhile c_FLT_TAKEWHILE -#define cstr_new(lit) cstr_lit(lit) -#define cstr_null cstr_NULL + +#define c_DROP c_drop +#define c_FIND_IF c_find_if +#define c_ERASE_IF c_erase_if +#define c_FLT_TAKE c_flt_take +#define c_FLT_SKIP c_flt_skip +#define c_FLT_SKIPWHILE c_flt_skipwhile +#define c_FLT_TAKEWHILE c_flt_takewhile +#define c_DELETE c_delete +#define c_SWAP c_swap +#define c_CONTAINER_OF c_container_of +#define c_STATIC_ASSERT c_static_assert |
