summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/stc/coroutine.h21
-rw-r--r--include/stc/priv/template.h24
2 files changed, 20 insertions, 25 deletions
diff --git a/include/stc/coroutine.h b/include/stc/coroutine.h
index cecd4002..5f06e7b8 100644
--- a/include/stc/coroutine.h
+++ b/include/stc/coroutine.h
@@ -131,16 +131,19 @@ typedef enum {
(void)((co)->cco_state = 0)
/*
- * Generators
+ * Iterator (for generators)
+ * User define: Gen must be an existing typedef struct:
+ * Gen_iter Gen_begin(Gen* g); // function
+ * int Gen_next(Gen_iter* it); // coroutine
*/
-#define cco_iter_struct(Name, ...) \
- typedef Name Name##_value; \
- typedef struct { \
- Name##_value* ref; \
+#define cco_iter_struct(Gen, ...) \
+ typedef Gen Gen##_value; \
+ typedef struct Gen##_iter { \
+ Gen##_value* ref; \
int cco_state; \
__VA_ARGS__ \
- } Name##_iter
+ } Gen##_iter
/*
* Tasks
@@ -148,9 +151,9 @@ typedef enum {
struct cco_runtime;
-#define cco_task_struct(Name, ...) \
- struct Name { \
- int (*cco_func)(struct Name*, struct cco_runtime*); \
+#define cco_task_struct(Task, ...) \
+ struct Task { \
+ int (*cco_func)(struct Task*, struct cco_runtime*); \
int cco_state, cco_expect; \
__VA_ARGS__ \
}
diff --git a/include/stc/priv/template.h b/include/stc/priv/template.h
index 3b8a5b39..65dee203 100644
--- a/include/stc/priv/template.h
+++ b/include/stc/priv/template.h
@@ -140,14 +140,14 @@
#ifndef i_keyclone
#define i_keyclone c_PASTE(i_key, _clone)
#endif
- #if !defined i_keyto && defined i_keyraw
- #define i_keyto c_PASTE(i_key, _toraw)
+ #ifndef i_keydrop
+ #define i_keydrop c_PASTE(i_key, _drop)
#endif
#if !defined i_keyfrom && defined i_keyraw
#define i_keyfrom c_PASTE(i_key, _from)
#endif
- #ifndef i_keydrop
- #define i_keydrop c_PASTE(i_key, _drop)
+ #if !defined i_keyto && defined i_keyraw
+ #define i_keyto c_PASTE(i_key, _toraw)
#endif
#if !defined i_keyraw && (defined i_cmp || defined i_less || defined i_eq || defined i_hash)
#define i_use_cmp
@@ -245,22 +245,14 @@
#ifndef i_valclone
#define i_valclone c_PASTE(i_val, _clone)
#endif
- #if !defined i_valto && defined i_valraw
- #define i_valto c_PASTE(i_val, _toraw)
+ #ifndef i_valdrop
+ #define i_valdrop c_PASTE(i_val, _drop)
#endif
#if !defined i_valfrom && defined i_valraw
#define i_valfrom c_PASTE(i_val, _from)
#endif
- #ifndef i_valdrop
- #define i_valdrop c_PASTE(i_val, _drop)
- #endif
-#endif
-
-#if !defined i_valraw && !defined i_no_clone
- #if !defined i_valfrom && defined i_valclone
- #define i_valfrom i_valclone
- #elif !defined i_valclone && defined i_valfrom
- #define i_valclone i_valfrom
+ #if !defined i_valto && defined i_valraw
+ #define i_valto c_PASTE(i_val, _toraw)
#endif
#endif