summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-06-13 18:21:04 +0200
committerTyge Løvset <[email protected]>2023-06-13 18:21:04 +0200
commit06f3ae1d904d776aea8a78113c16fc30309817ed (patch)
tree9dd2332386a4cd4a76000d719bf999d41a05998c /include
parentb564ef6bdfcd2437f1b4997f42054c45ccdedbb1 (diff)
downloadSTC-modified-06f3ae1d904d776aea8a78113c16fc30309817ed.tar.gz
STC-modified-06f3ae1d904d776aea8a78113c16fc30309817ed.zip
Added cco_closue(Ret, Closure) to define coroutine closure.
Added back cco_await_on(child) calls.
Diffstat (limited to 'include')
-rw-r--r--include/stc/algo/coroutine.h16
-rw-r--r--include/stc/cstr.h7
-rw-r--r--include/stc/csview.h7
-rw-r--r--include/stc/utf8.h6
4 files changed, 22 insertions, 14 deletions
diff --git a/include/stc/algo/coroutine.h b/include/stc/algo/coroutine.h
index 5cd6d68f..61581f64 100644
--- a/include/stc/algo/coroutine.h
+++ b/include/stc/algo/coroutine.h
@@ -84,7 +84,21 @@ enum {
case __LINE__: if (!(promise)) {return ret; goto _resume;} \
} while (0)
-#define cco_run(co, call) while (call, !cco_done(co))
+#define cco_closure(Ret, Closure, ...) \
+ struct Closure { \
+ Ret (*coroutine)(struct Closure*); \
+ __VA_ARGS__ \
+ int cco_state; \
+ }
+
+#define cco_resume(closure) (closure)->coroutine(closure)
+#define cco_await_on(...) c_MACRO_OVERLOAD(cco_await_on, __VA_ARGS__)
+#define cco_await_on_1(closure) cco_await_on_2(closure, cco_resume(closure))
+#define cco_await_on_2(co, func) cco_await_1((func(co), !cco_done(co)))
+
+#define cco_block_on(...) c_MACRO_OVERLOAD(cco_block_on, __VA_ARGS__)
+#define cco_block_on_1(closure) while (cco_resume(closure), !cco_done(closure))
+#define cco_block_on_2(co, func) while (func(co), !cco_done(co))
#define cco_final \
*_state = cco_state_final; case cco_state_final
diff --git a/include/stc/cstr.h b/include/stc/cstr.h
index bdfee39b..b9b066ad 100644
--- a/include/stc/cstr.h
+++ b/include/stc/cstr.h
@@ -24,7 +24,7 @@
/* A string type with short string optimization in C99 with good small-string
* optimization (22 characters with 24 bytes string).
*/
-#define _i_nested
+#define _i_inc_utf8
#include "utf8.h"
#ifndef CSTR_H_INCLUDED
@@ -440,7 +440,7 @@ cstr cstr_tocase(csview sv, int k) {
#endif // i_import
/* -------------------------- IMPLEMENTATION ------------------------- */
-#if defined i_import || (defined i_implement && !defined _i_nested)
+#if defined i_import || defined i_implement
#ifndef CSTR_C_INCLUDED
#define CSTR_C_INCLUDED
@@ -655,11 +655,8 @@ intptr_t cstr_printf(cstr* self, const char* fmt, ...) {
#if defined __GNUC__ && !defined __clang__
# pragma GCC diagnostic pop
#endif
-#ifndef _i_nested
#undef i_opt
#undef i_header
#undef i_static
#undef i_implement
#undef i_import
-#endif
-#undef _i_nested
diff --git a/include/stc/csview.h b/include/stc/csview.h
index c16f58bc..07ab4059 100644
--- a/include/stc/csview.h
+++ b/include/stc/csview.h
@@ -20,7 +20,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-#define _i_nested
+#define _i_inc_utf8
#include "utf8.h"
#ifndef CSVIEW_H_INCLUDED
@@ -150,7 +150,7 @@ STC_INLINE csview cstr_u8_substr(const cstr* self , intptr_t bytepos, intptr_t u
#endif
/* -------------------------- IMPLEMENTATION ------------------------- */
-#if defined i_import || (defined i_implement && !defined _i_nested)
+#if defined i_import || defined i_implement
#ifndef CSVIEW_C_INCLUDED
#define CSVIEW_C_INCLUDED
@@ -203,11 +203,8 @@ csview csview_token(csview sv, const char* sep, intptr_t* start) {
}
#endif // CSVIEW_C_INCLUDED
#endif // i_implement
-#ifndef _i_nested
#undef i_static
#undef i_header
#undef i_implement
#undef i_import
#undef i_opt
-#endif
-#undef _i_nested
diff --git a/include/stc/utf8.h b/include/stc/utf8.h
index 190cc7f3..6d12856f 100644
--- a/include/stc/utf8.h
+++ b/include/stc/utf8.h
@@ -138,14 +138,14 @@ STC_INLINE intptr_t utf8_pos(const char* s, intptr_t index)
{ return (intptr_t)(utf8_at(s, index) - s); }
#endif // UTF8_H_INCLUDED
-#if defined i_import || (defined i_implement && !defined _i_nested)
+#if defined i_import || (defined i_implement && !defined _i_inc_utf8)
# include "../../src/utf8code.c"
#endif
-#ifndef _i_nested
+#ifndef _i_inc_utf8
#undef i_static
#undef i_header
#undef i_implement
#undef i_import
#undef i_opt
#endif
-#undef _i_nested
+#undef _i_inc_utf8