summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-05-24 12:43:39 +0200
committerTyge Løvset <[email protected]>2021-05-24 12:43:39 +0200
commit64f50b93b08a8015783b2887e1ab5afd5fedb40c (patch)
treeca70f0b4c87b0d59a9689b12d26bfa2bab160916 /include
parent771a8dff31b0c0a905c57ec6f590cd03975f8817 (diff)
downloadSTC-modified-64f50b93b08a8015783b2887e1ab5afd5fedb40c.tar.gz
STC-modified-64f50b93b08a8015783b2887e1ab5afd5fedb40c.zip
Renamed c_with => c_fordefer, and removed c_withvar. Macros were too deceiving and hid the fact that it was for-loops. Now it is more explicit.
Diffstat (limited to 'include')
-rw-r--r--include/stc/carray.h2
-rw-r--r--include/stc/cbits.h2
-rw-r--r--include/stc/ccommon.h19
-rw-r--r--include/stc/clist.h2
-rw-r--r--include/stc/cmap.h2
-rw-r--r--include/stc/cpque.h2
-rw-r--r--include/stc/cqueue.h2
-rw-r--r--include/stc/csmap.h2
-rw-r--r--include/stc/cstack.h2
-rw-r--r--include/stc/cstr.h2
10 files changed, 16 insertions, 21 deletions
diff --git a/include/stc/carray.h b/include/stc/carray.h
index e3859b8a..fa794238 100644
--- a/include/stc/carray.h
+++ b/include/stc/carray.h
@@ -33,7 +33,7 @@ using_carray2(i, int);
int main() {
int w = 7, h = 5;
- c_with (carray2i image = carray2i_init(w, h), carray2i_del(&image))
+ c_fordefer (carray2i image = carray2i_init(w, h), carray2i_del(&image))
{
int *dat = carray2i_data(&image);
for (int i = 0; i < carray2i_size(image); ++i)
diff --git a/include/stc/cbits.h b/include/stc/cbits.h
index fc2d525b..803fe2d5 100644
--- a/include/stc/cbits.h
+++ b/include/stc/cbits.h
@@ -30,7 +30,7 @@ Similar to boost::dynamic_bitset / std::bitset
#include "cbits.h"
int main() {
- c_with (cbits bset = cbits_with_size(23, true), cbits_del(&bset))
+ c_fordefer (cbits bset = cbits_with_size(23, true), cbits_del(&bset))
{
cbits_reset(&bset, 9);
cbits_resize(&bset, 43, false);
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index bf9d6aed..62b8a172 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -53,12 +53,13 @@
/* Macro overloading feature support: https://rextester.com/ONP80107 */
#define _c_CAT( A, B ) A ## B
+#define _c_SELECT(NAME, NUM) _c_CAT( NAME ## _, NUM)
#define _c_EXPAND(...) __VA_ARGS__
#define _c_ARG_N(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, N,...) N
#define _c_RSEQ_N 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
#define _c_APPLY_ARG_N(ARGS) _c_EXPAND(_c_ARG_N ARGS)
#define _c_ARG_COUNT(...) _c_EXPAND(_c_APPLY_ARG_N((__VA_ARGS__, _c_RSEQ_N)))
-#define _c_SELECT(NAME, NUM) _c_CAT( NAME ## _, NUM)
+#define _c_LABEL(id) _c_SELECT(_c_label_##id, __LINE__)
#define c_MACRO_OVERLOAD(NAME, ...) _c_SELECT(NAME, _c_ARG_COUNT(__VA_ARGS__))(__VA_ARGS__)
#define c_static_assert(cond, ...) typedef char _static_assert_[(cond) ? 1 : -1]
@@ -122,21 +123,15 @@
for (type i=start, _c_inc=step, _c_end=(stop) - (0 < _c_inc) \
; (i <= _c_end) == (0 < _c_inc); i += _c_inc)
-#define c_with(start, end) for (start, *_c_ii = NULL; !_c_ii; ++_c_ii, end)
-#define c_withvar(...) c_MACRO_OVERLOAD(c_withvar, __VA_ARGS__)
-#define c_withvar_2(CX, var) c_with (CX var = CX##_init(), CX##_del(&var))
-#define c_withvar_3(CX, v1, v2) c_with (_c_EXPAND(CX v1 = CX##_init(), v2 = v1), (CX##_del(&v2), CX##_del(&v1)))
-#define c_withvar_4(CX, v1, v2, v3) c_with (_c_EXPAND(CX v1 = CX##_init(), v2 = v1, v3 = v1), \
- (CX##_del(&v3), CX##_del(&v2), CX##_del(&v1)))
-#define c_defer(...) for (int _c_ii = 0; !_c_ii; ++_c_ii, __VA_ARGS__)
+#define c_fordefer(...) c_MACRO_OVERLOAD(c_fordefer, __VA_ARGS__)
+#define c_fordefer_1(release) for (int _c_ii = 0; !_c_ii; ++_c_ii, release)
+#define c_fordefer_2(acquire, release) for (acquire, *_c_ii = NULL; !_c_ii; ++_c_ii, release)
-#define c_withbuf(b, type, n) c_withbuf_N(b, type, n, 256)
-#define c_withbuf_N(b, type, n, BYTES) \
+#define c_forbuffer(b, type, n) c_forbuffer_N(b, type, n, 256)
+#define c_forbuffer_N(b, type, n, BYTES) \
for (type _c_b[((BYTES) - 1) / sizeof(type) + 1], \
*b = (n)*sizeof *b > (BYTES) ? c_new_n(type, n) : _c_b \
; b; b != _c_b ? c_free(b) : (void)0, b = NULL)
-#define c_exitwith continue
-#define c_exitdefer continue
#define c_var(CX, c, ...) \
CX c = CX##_init(); c_emplace(CX, c, __VA_ARGS__)
diff --git a/include/stc/clist.h b/include/stc/clist.h
index 55ab5bf0..538c25b4 100644
--- a/include/stc/clist.h
+++ b/include/stc/clist.h
@@ -35,7 +35,7 @@
using_clist(ix, int64_t);
int main() {
- c_with (clist_ix list = clist_ix_init(), clist_ix_del(&list))
+ c_fordefer (clist_ix list = clist_ix_init(), clist_ix_del(&list))
{
stc64_t rng = stc64_init(12345);
int n;
diff --git a/include/stc/cmap.h b/include/stc/cmap.h
index efa1ddb9..9377aadd 100644
--- a/include/stc/cmap.h
+++ b/include/stc/cmap.h
@@ -31,7 +31,7 @@
using_cmap(mx, int, char); // Map of int -> char
int main(void) {
- c_with (cmap_mx m = cmap_mx_init(), cmap_mx_del(&m))
+ c_fordefer (cmap_mx m = cmap_mx_init(), cmap_mx_del(&m))
{
cmap_mx_emplace(&m, 5, 'a');
cmap_mx_emplace(&m, 8, 'b');
diff --git a/include/stc/cpque.h b/include/stc/cpque.h
index 20acf6f6..afdd41ac 100644
--- a/include/stc/cpque.h
+++ b/include/stc/cpque.h
@@ -32,7 +32,7 @@
stc64_t rng = stc64_init(1234);
stc64_uniformf_t dist = stc64_uniformf_init(10.0f, 100.0f);
- c_with (cpque_f queue = cpque_f_init(), cpque_f_del(&queue))
+ c_fordefer (cpque_f queue = cpque_f_init(), cpque_f_del(&queue))
{
// Push ten million random numbers onto the queue.
for (int i=0; i<10000000; ++i)
diff --git a/include/stc/cqueue.h b/include/stc/cqueue.h
index 37d18fba..99afc296 100644
--- a/include/stc/cqueue.h
+++ b/include/stc/cqueue.h
@@ -35,7 +35,7 @@
stc64_t rng = stc64_init(1234);
stc64_uniform_t dist = stc64_uniform_init(rng, 0, n);
- c_with (cqueue_i queue = cqueue_i_init(), cqueue_i_del(&queue))
+ c_fordefer (cqueue_i queue = cqueue_i_init(), cqueue_i_del(&queue))
{
// Push ten million random numbers onto the queue.
for (int i=0; i<n; ++i)
diff --git a/include/stc/csmap.h b/include/stc/csmap.h
index 91cf3d11..2909e0a1 100644
--- a/include/stc/csmap.h
+++ b/include/stc/csmap.h
@@ -30,7 +30,7 @@
using_csmap(mx, int, char); // Sorted map<int, char>
int main(void) {
- c_with (csmap_mx m = csmap_mx_init(), csmap_mx_del(&m))
+ c_fordefer (csmap_mx m = csmap_mx_init(), csmap_mx_del(&m))
{
csmap_mx_insert(&m, 5, 'a');
csmap_mx_insert(&m, 8, 'b');
diff --git a/include/stc/cstack.h b/include/stc/cstack.h
index 2184c89e..575e9012 100644
--- a/include/stc/cstack.h
+++ b/include/stc/cstack.h
@@ -32,7 +32,7 @@
using_cstack(i, cvec_i);
int main() {
- c_with (cstack_i stack = cstack_i_init(), cstack_i_del(&stack))
+ c_fordefer (cstack_i stack = cstack_i_init(), cstack_i_del(&stack))
{
for (int i=0; i<100; ++i)
cstack_i_push(&stack, i*i);
diff --git a/include/stc/cstr.h b/include/stc/cstr.h
index a188b1cf..54ec993b 100644
--- a/include/stc/cstr.h
+++ b/include/stc/cstr.h
@@ -307,7 +307,7 @@ STC_DEF void
cstr_replace_n(cstr* self, size_t pos, size_t len, const char* str, size_t n) {
size_t sz = cstr_size(*self);
if (len > sz - pos) len = sz - pos;
- c_withbuf (xstr, char, n) {
+ c_forbuffer (xstr, char, n) {
memcpy(xstr, str, n);
_cstr_internal_move(self, pos + len, pos + n);
memcpy(&self->str[pos], xstr, n);