Fix support for pop generic macro function

This commit is contained in:
Patrick Pelissier committed 2023-12-30 16:23:02 +01:00
1 parent 5344423ad9
commit 044a085fb6
3 files changed
+17 -4

No files matched your search

+4
View File
@@ -1458,6 +1458,7 @@ M_BEGIN_PROTECTED_CODE
#define M_PATTERN_type_type ,
#define M_PATTERN_TYPE_TYPE ,
#define M_PATTERN_SUBTYPE_SUBTYPE ,
#define M_PATTERN_SUBTYPE_PTR_SUBTYPE_PTR ,
#define M_PATTERN_IT_TYPE_IT_TYPE ,
#define M_PATTERN_KEY_TYPE_KEY_TYPE ,
#define M_PATTERN_VALUE_TYPE_VALUE_TYPE ,
@@ -3369,6 +3370,7 @@ M_INLINE size_t m_core_cstr_hash(const char str[])
#define M_TYPE_TYPE(a) ,a,
#define M_SUBTYPE_SUBTYPE(a) ,a,
#define M_GENTYPE_GENTYPE(a) ,a,
#define M_SUBTYPE_PTR_SUBTYPE_PTR(a) ,a,
#define M_NAME_NAME(a) ,a,
#define M_OPLIST_OPLIST(a) ,a,
#define M_SORT_SORT(a) ,a,
@@ -3458,6 +3460,7 @@ M_INLINE size_t m_core_cstr_hash(const char str[])
#define M_GET_CMP(...) M_GET_METHOD(CMP, M_CMP_DEFAULT, __VA_ARGS__)
#define M_GET_TYPE(...) M_GET_METHOD(TYPE, M_NO_DEF_TYPE, __VA_ARGS__)
#define M_GET_SUBTYPE(...) M_GET_METHOD(SUBTYPE, M_NO_DEF_TYPE, __VA_ARGS__)
#define M_GET_SUBTYPE_PTR(...) M_GET_METHOD(SUBTYPE_PTR, M_NO_DEF_TYPE, __VA_ARGS__)
#define M_GET_GENTYPE(...) M_GET_METHOD(GENTYPE, M_NO_DEF_TYPE, __VA_ARGS__)
#define M_GET_NAME(...) M_GET_METHOD(NAME, M_NO_DEF_TYPE, __VA_ARGS__)
#define M_GET_OPLIST(...) M_GET_METHOD(OPLIST, (), __VA_ARGS__)
@@ -3539,6 +3542,7 @@ M_INLINE size_t m_core_cstr_hash(const char str[])
#define M_CALL_CMP(oplist, ...) M_APPLY_API(M_GET_CMP oplist, oplist, __VA_ARGS__)
//#define M_CALL_TYPE(oplist, ...) M_APPLY_API(M_GET_TYPE oplist, oplist, __VA_ARGS__)
//#define M_CALL_SUBTYPE(oplist, ...) M_APPLY_API(M_GET_SUBTYPE oplist, oplist, __VA_ARGS__)
//#define M_CALL_SUBTYPE_PTR(oplist, ...) M_APPLY_API(M_GET_SUBTYPE_PTR oplist, oplist, __VA_ARGS__)
//#define M_CALL_GENTYPE(oplist, ...) M_APPLY_API(M_GET_GENTYPE oplist, oplist, __VA_ARGS__)
//#define M_CALL_NAME(oplist, ...) M_APPLY_API(M_GET_NAME oplist, oplist, __VA_ARGS__)
//#define M_CALL_OPLIST(oplist, ...) M_APPLY_API(M_GET_OPLIST oplist, oplist, __VA_ARGS__)
+6 -4
View File
@@ -71,9 +71,9 @@
#define erase(x, y) M_G3N_CALL_2(ERASE, x, TYPE, x, KEY_TYPE, y)
#define get_size(x) M_G3N_CALL_1(GET_SIZE, x)
#define push(x, y) M_G3N_CALL_2(PUSH, x, TYPE, x, SUBTYPE, y)
#define pop(x, y) M_G3N_CALL_2(PUSH, x, TYPE, x, SUBTYPE, y)
#define push_move(x, y) M_G3N_CALL_2(PUSH_MOVE, x, TYPE, x, SUBTYPE *, y)
#define pop_move(x, y) M_G3N_CALL_2(PUSH, x, TYPE, x, SUBTYPE*, y)
#define pop(x, y) M_G3N_CALL_2(POP, y, SUBTYPE_PTR, x, TYPE, y)
#define push_move(x, y) M_G3N_CALL_2(PUSH_MOVE, x, TYPE, x, SUBTYPE_PTR, y)
#define pop_move(x, y) M_G3N_CALL_2(POP_MOVE, y, SUBTYPE_PTR, x, TYPE, y)
#define reverse(x) M_G3N_CALL_1(REVERSE, x)
#define get_str(s, c, b) M_G3N_CALL_3(GET_STR, c, string_t, s, TYPE, c, bool, b)
#define parse_str(c, s, e) M_G3N_CALL_3(PARSE_STR, c, TYPE, c, m_g3n_cstring, s, m_g3n_cstring_end, e)
@@ -173,7 +173,9 @@ typedef const char **m_g3n_cstring_end;
// Translate type' into the container type if type == TYPE, IT_TYPE into its iterator
// KEY_TYPE, VALUE_TYPE, SUBTYPE into the associated type in the oplist,
// or keep 'type' otherwise
#define M_G3N_TYPE(type, oplist) M_GET_METHOD(type, type, M_OPFLAT oplist ())
// Handle also specially SUBTYPE_PTR
#define M_G3N_TYPE(type, oplist) M_G3N_TYPE_B(type, oplist())
#define M_G3N_TYPE_B(type, oplist) M_GET_METHOD(type, type, SUBTYPE_PTR(M_GET_SUBTYPE oplist *), M_OPFLAT oplist)
// Call the OPERATOR call of the oplist registered to the variable 'x'
// which takes one argument.
+7
View File
@@ -100,12 +100,19 @@ static void test_string(string_t p)
static void test_array(void)
{
M_LET(a, array_int_t) {
bool b = empty_p(a);
assert(b);
push(a, 14);
b = empty_p(a);
assert(!b);
push(a, 15);
out_str(stdout, a);
for each(it, a) {
printf("=%d, ", *it);
}
int z;
pop(&z, a);
assert(z == 15);
}
// Just change the type, same code!
M_LET(a, list_int_t) {