Skip to content

Commit

Permalink
More updates and small fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
tylov committed Nov 11, 2024
1 parent 6de976a commit 1820303
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 20 deletions.
18 changes: 5 additions & 13 deletions include/stc/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,11 @@ typedef const char* cstr_raw;
_it.ref != (C##_value*)_endref && (key = &_it.ref->first, val = &_it.ref->second); \
C##_next(&_it))

#ifndef __cplusplus
#define c_foritems(it, T, ...) \
for (struct {T* ref; int size, index;} \
it = {.ref=(T[])__VA_ARGS__, .size=(int)(sizeof((T[])__VA_ARGS__)/sizeof(T))} \
; it.index < it.size; ++it.ref, ++it.index)
#else
#include <initializer_list>
#define c_foritems(it, T, ...) \
for (struct {std::initializer_list<T> _il; std::initializer_list<T>::iterator ref; size_t size, index;} \
it = {._il=__VA_ARGS__, .ref=it._il.begin(), .size=it._il.size()} \
; it.index < it.size; ++it.ref, ++it.index)
#endif
#define c_forlist(...) c_foritems(_VA_ARGS__) // [deprecated]
#define c_foritems(it, T, ...) \
for (struct {T* ref; int size, index;} \
it = {.ref=c_make_array(T, __VA_ARGS__), .size=(int)(sizeof((T[])__VA_ARGS__)/sizeof(T))} \
; it.index < it.size; ++it.ref, ++it.index)
#define c_forlist(...) c_foritems(_VA_ARGS__) // [deprecated]
#define c_forpair(...) 'c_forpair not_supported. Use c_foreach_kv' // [removed]

// c_forrange, c_forrange32: python-like int range iteration
Expand Down
4 changes: 2 additions & 2 deletions include/stc/coroutine.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ typedef struct cco_runtime {
#define cco_yield_task(task, rt) cco_yield_task_v(task, rt, CCO_AWAIT)
#define cco_yield_task_v(task, rt, suspendval) \
do { \
cco_task* _t = cco_cast_task(task); \
{ cco_task* _t = cco_cast_task(task); \
_t->cco.await = (rt)->stack[(rt)->top]->cco.await; \
(rt)->stack[(rt)->top] = _t; \
(rt)->stack[(rt)->top] = _t; } \
cco_yield_v(suspendval); \
} while (0)

Expand Down
2 changes: 1 addition & 1 deletion include/stc/zsview.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ STC_INLINE bool zsview_equals(zsview zs, const char* str) {
}

STC_INLINE isize zsview_find(zsview zs, const char* search) {
char* res = strstr(zs.str, search);
const char* res = strstr(zs.str, search);
return res ? (res - zs.str) : c_NPOS;
}

Expand Down
5 changes: 3 additions & 2 deletions misc/examples/coroutines/cotasks2.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ int produce_items(struct produce_items* co, cco_runtime* rt) {

int consume_items(struct consume_items* co, cco_runtime* rt) {
cco_routine (co) {
int n, sz;
while (1) {
int n = rand() % 10;
int sz = (int)Inventory_size(&co->producer->inv);
n = rand() % 10;
sz = (int)Inventory_size(&co->producer->inv);
if (n > sz) n = sz;

c_forrange (n)
Expand Down
4 changes: 2 additions & 2 deletions misc/examples/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ common="-std=c99 -Werror -Wall"
#cc=clang; cflags="-s -O3 $common"
cc=gcc; cflags="-s -O3 $common"
#cc=gcc; cflags="-g $sanitize $common"
#cc=gcc; cflags="-x c++ -std=c++20 -O2 -s"
#cc=gcc; cflags="-x c++ -std=c++17 -O2 -s -DSTC_IMPLEMENT -Di_import"
#cc=tcc; cflags="-std=c99 -Wall"
#cc=cl; cflags="-nologo -O2 -MD -W3 -std:c11 -wd4003"
#cc=cl; cflags="-nologo -O2 -MD -W3 -wd4003"
#cc=cl; cflags="-nologo -TP -std:c++20 -wd4003"
#cc=cl; cflags="-nologo -TP -std:c++20 -wd4003 -DSTC_IMPLEMENT -Di_import"

if [ "$cc" = "cl" ]; then
oflag='/Fe:'
Expand Down

0 comments on commit 1820303

Please sign in to comment.