| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#pragma once |
| 23 |
|
| 24 |
#if !defined (DEX_INSIDE) && !defined (DEX_COMPILATION) |
| 25 |
# error "Only <libdex.h> can be included directly." |
| 26 |
#endif |
| 27 |
|
| 28 |
#include <glib-object.h> |
| 29 |
|
| 30 |
#include "dex-future.h" |
| 31 |
#include "dex-version-macros.h" |
| 32 |
|
| 33 |
G_BEGIN_DECLS |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
#define DEX_DEFINE_CLOSURE_VALUE(type, name) \ |
| 43 |
(_DEX_CLOSURE_FIELD_VALUE_DECLARE, _DEX_CLOSURE_FIELD_VALUE_CLEAR, type, name, NULL) |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
#define DEX_DEFINE_CLOSURE_VALUE_WITH_CLEAR(type, name, clear) \ |
| 55 |
(_DEX_CLOSURE_FIELD_VALUE_DECLARE, _DEX_CLOSURE_FIELD_VALUE_WITH_CLEAR_CLEAR, \ |
| 56 |
type, name, clear) |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
#define DEX_DEFINE_CLOSURE_POINTER(type, name, clear) \ |
| 69 |
(_DEX_CLOSURE_FIELD_POINTER_DECLARE, _DEX_CLOSURE_FIELD_POINTER_CLEAR, type, name, clear) |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
#define DEX_DEFINE_CLOSURE_OBJECT(type, name) \ |
| 79 |
(_DEX_CLOSURE_FIELD_OBJECT_DECLARE, _DEX_CLOSURE_FIELD_OBJECT_CLEAR, type, name, NULL) |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
#define DEX_DEFINE_CLOSURE_TYPE(type_name, type_prefix, ...) \ |
| 104 |
typedef struct _##type_name \ |
| 105 |
{ \ |
| 106 |
guint pc; \ |
| 107 |
DexFuture *pending; \ |
| 108 |
_DEX_CLOSURE_FOR_EACH (_DEX_CLOSURE_FIELD_DECLARE, __VA_ARGS__) \ |
| 109 |
} type_name; \ |
| 110 |
static inline type_name *type_prefix##_new (void) \ |
| 111 |
{ \ |
| 112 |
return g_new0 (type_name, 1); \ |
| 113 |
} \ |
| 114 |
static inline void type_prefix##_free (type_name *state) \ |
| 115 |
{ \ |
| 116 |
if (state == NULL) \ |
| 117 |
return; \ |
| 118 |
dex_clear ((gpointer) &state->pending); \ |
| 119 |
_DEX_CLOSURE_FOR_EACH (_DEX_CLOSURE_FIELD_CLEAR, __VA_ARGS__) \ |
| 120 |
g_free (state); \ |
| 121 |
} |
| 122 |
|
| 123 |
#define _DEX_CLOSURE_FIELD_DECLARE(field) \ |
| 124 |
_DEX_CLOSURE_FIELD_DECLARE_1 field |
| 125 |
#define _DEX_CLOSURE_FIELD_DECLARE_1(declare, clear_func, type, name, clear) \ |
| 126 |
declare (type, name, clear) |
| 127 |
|
| 128 |
#define _DEX_CLOSURE_FIELD_VALUE_DECLARE(type, name, clear) type name; |
| 129 |
#define _DEX_CLOSURE_FIELD_POINTER_DECLARE(type, name, clear) type name; |
| 130 |
#define _DEX_CLOSURE_FIELD_OBJECT_DECLARE(type, name, clear) type *name; |
| 131 |
|
| 132 |
#define _DEX_CLOSURE_FIELD_CLEAR(field) \ |
| 133 |
_DEX_CLOSURE_FIELD_CLEAR_1 field |
| 134 |
#define _DEX_CLOSURE_FIELD_CLEAR_1(declare, clear_func, type, name, clear) \ |
| 135 |
clear_func (state, type, name, clear); |
| 136 |
|
| 137 |
#define _DEX_CLOSURE_FIELD_VALUE_CLEAR(state, type, name, clear) \ |
| 138 |
G_STMT_START { } G_STMT_END |
| 139 |
|
| 140 |
#define _DEX_CLOSURE_FIELD_VALUE_WITH_CLEAR_CLEAR(state, type, name, clear) \ |
| 141 |
G_STMT_START { \ |
| 142 |
(clear) (&(state)->name); \ |
| 143 |
} G_STMT_END |
| 144 |
|
| 145 |
#define _DEX_CLOSURE_FIELD_POINTER_CLEAR(state, type, name, clear) \ |
| 146 |
G_STMT_START { \ |
| 147 |
g_clear_pointer (&(state)->name, clear); \ |
| 148 |
} G_STMT_END |
| 149 |
|
| 150 |
#define _DEX_CLOSURE_FIELD_OBJECT_CLEAR(state, type, name, clear) \ |
| 151 |
G_STMT_START { \ |
| 152 |
g_clear_object ((GObject **) &((state)->name)); \ |
| 153 |
} G_STMT_END |
| 154 |
|
| 155 |
#define _DEX_CLOSURE_FOR_EACH(macro, ...) \ |
| 156 |
_DEX_CLOSURE_CONCAT (_DEX_CLOSURE_FOR_EACH_, _DEX_CLOSURE_NARGS (__VA_ARGS__)) \ |
| 157 |
(macro, __VA_ARGS__) |
| 158 |
|
| 159 |
#define _DEX_CLOSURE_CONCAT(a, b) \ |
| 160 |
_DEX_CLOSURE_CONCAT_EXPAND (a, b) |
| 161 |
#define _DEX_CLOSURE_CONCAT_EXPAND(a, b) a##b |
| 162 |
|
| 163 |
#define _DEX_CLOSURE_NARGS(...) \ |
| 164 |
_DEX_CLOSURE_NARGS_ (__VA_ARGS__, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) |
| 165 |
#define _DEX_CLOSURE_NARGS_(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, ...) a17 |
| 166 |
|
| 167 |
#define _DEX_CLOSURE_FOR_EACH_0(macro) |
| 168 |
#define _DEX_CLOSURE_FOR_EACH_1(macro, a1) \ |
| 169 |
macro(a1) |
| 170 |
#define _DEX_CLOSURE_FOR_EACH_2(macro, a1, a2) \ |
| 171 |
macro(a1) macro(a2) |
| 172 |
#define _DEX_CLOSURE_FOR_EACH_3(macro, a1, a2, a3) \ |
| 173 |
macro(a1) macro(a2) macro(a3) |
| 174 |
#define _DEX_CLOSURE_FOR_EACH_4(macro, a1, a2, a3, a4) \ |
| 175 |
macro(a1) macro(a2) macro(a3) macro(a4) |
| 176 |
#define _DEX_CLOSURE_FOR_EACH_5(macro, a1, a2, a3, a4, a5) \ |
| 177 |
macro(a1) macro(a2) macro(a3) macro(a4) macro(a5) |
| 178 |
#define _DEX_CLOSURE_FOR_EACH_6(macro, a1, a2, a3, a4, a5, a6) \ |
| 179 |
macro(a1) macro(a2) macro(a3) macro(a4) macro(a5) macro(a6) |
| 180 |
#define _DEX_CLOSURE_FOR_EACH_7(macro, a1, a2, a3, a4, a5, a6, a7) \ |
| 181 |
macro(a1) macro(a2) macro(a3) macro(a4) macro(a5) macro(a6) macro(a7) |
| 182 |
#define _DEX_CLOSURE_FOR_EACH_8(macro, a1, a2, a3, a4, a5, a6, a7, a8) \ |
| 183 |
macro(a1) macro(a2) macro(a3) macro(a4) macro(a5) macro(a6) macro(a7) macro(a8) |
| 184 |
#define _DEX_CLOSURE_FOR_EACH_9(macro, a1, a2, a3, a4, a5, a6, a7, a8, a9) \ |
| 185 |
macro(a1) macro(a2) macro(a3) macro(a4) macro(a5) macro(a6) macro(a7) macro(a8) \ |
| 186 |
macro(a9) |
| 187 |
#define _DEX_CLOSURE_FOR_EACH_10(macro, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) \ |
| 188 |
macro(a1) macro(a2) macro(a3) macro(a4) macro(a5) macro(a6) macro(a7) macro(a8) \ |
| 189 |
macro(a9) macro(a10) |
| 190 |
#define _DEX_CLOSURE_FOR_EACH_11(macro, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) \ |
| 191 |
macro(a1) macro(a2) macro(a3) macro(a4) macro(a5) macro(a6) macro(a7) macro(a8) \ |
| 192 |
macro(a9) macro(a10) macro(a11) |
| 193 |
#define _DEX_CLOSURE_FOR_EACH_12(macro, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) \ |
| 194 |
macro(a1) macro(a2) macro(a3) macro(a4) macro(a5) macro(a6) macro(a7) macro(a8) \ |
| 195 |
macro(a9) macro(a10) macro(a11) macro(a12) |
| 196 |
#define _DEX_CLOSURE_FOR_EACH_13(macro, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) \ |
| 197 |
macro(a1) macro(a2) macro(a3) macro(a4) macro(a5) macro(a6) macro(a7) macro(a8) \ |
| 198 |
macro(a9) macro(a10) macro(a11) macro(a12) macro(a13) |
| 199 |
#define _DEX_CLOSURE_FOR_EACH_14(macro, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) \ |
| 200 |
macro(a1) macro(a2) macro(a3) macro(a4) macro(a5) macro(a6) macro(a7) macro(a8) \ |
| 201 |
macro(a9) macro(a10) macro(a11) macro(a12) macro(a13) macro(a14) |
| 202 |
#define _DEX_CLOSURE_FOR_EACH_15(macro, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) \ |
| 203 |
macro(a1) macro(a2) macro(a3) macro(a4) macro(a5) macro(a6) macro(a7) macro(a8) \ |
| 204 |
macro(a9) macro(a10) macro(a11) macro(a12) macro(a13) macro(a14) macro(a15) |
| 205 |
#define _DEX_CLOSURE_FOR_EACH_16(macro, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16) \ |
| 206 |
macro(a1) macro(a2) macro(a3) macro(a4) macro(a5) macro(a6) macro(a7) macro(a8) \ |
| 207 |
macro(a9) macro(a10) macro(a11) macro(a12) macro(a13) macro(a14) macro(a15) macro(a16) |
| 208 |
|
| 209 |
G_END_DECLS |