From 39fcc1fbef341ab1cd3ee1935716f4c890facdb1 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sun, 5 Nov 2023 19:31:38 +0100 Subject: [PATCH] WIP --- m-generic.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/m-generic.h b/m-generic.h index 3d2b7bed..d8b4346e 100644 --- a/m-generic.h +++ b/m-generic.h @@ -94,17 +94,65 @@ struct m_g3neric_dummys; gentype: M_C(M_CALL_, op)(oplist(), M_AS_TYPE(gentype, x), M_AS_LINKED_TYPE(gentype, x, basictype, y)), \ const gentype: M_C(M_CALL_, op)(oplist(), M_AS_LINKED_TYPE(const gentype, x, gentype, x), M_AS_LINKED_TYPE(const gentype, x, basictype, y)), +// Call the OPERATOR call of the oplist registered to the variable 'x' +// which takes two argument (type, subtype) +#define M_G3N_CALL_t2(op, x, y) \ + _Generic( ((void)0, (y)), \ + M_MAP2(M_G3N_CALL_t2_func, (op, x, y) M_G3N_REGISTERED_ITEMS() ) \ + struct m_g3neric_dummys *: /* cannot happen */ (void) 0) +#define M_G3N_CALL_t2_func(x, oplist) \ + M_G3N_CALL_t2_func_test(M_GET_GENTYPE oplist(), \ + M_IF_METHOD(GENTYPE, M_GET_OPLIST oplist())(M_GET_GENTYPE M_GET_OPLIST oplist(), M_GET_SUBTYPE oplist()), \ + M_TRIPLE_1 x, M_TRIPLE_2 x, M_TRIPLE_3 x, oplist) +#define M_G3N_CALL_t2_func_test(gentype, basictype, op, x, y, oplist) \ + M_IF_METHOD(op, oplist())(M_G3N_CALL_t2_func_expand, M_EAT)(gentype, op, x, y, oplist) +#define M_G3N_CALL_t2_func_expand(gentype, basictype, op, x, y, oplist) \ + gentype: M_C(M_CALL_, op)(oplist(), M_AS_LINKED_TYPE(gentype, y, basictype *, x), M_AS_LINKED_TYPE(gentype, y, gentype, y)), \ + const gentype: M_C(M_CALL_, op)(oplist(), M_AS_LINKED_TYPE(gentype, y, basictype *, x), M_AS_LINKED_TYPE(const gentype, y, gentype, y)), + #define M_AS_LINKED_TYPE(typex, x, typey, y) _Generic(((void)0,(x)), typex: (y), default: (typey) {0}) // Define generic functions // TODO: m_ prefix? #define init(x) M_G3N_CALL_1(INIT, x) #define init_set(x, y) M_G3N_CALL_2(INIT_SET, x, y) +#define init_move(x, y) M_G3N_CALL_2(INIT_MOVE, x, y) +#define move(x, y) M_G3N_CALL_2(MOVE, x, y) #define set(x, y) M_G3N_CALL_2(SET, x, y) #define clear(x) M_G3N_CALL_1(CLEAR, x) -#define init_move(x, y) M_G3N_CALL_2(INIT_MOVE, x, y) -#define push(x, y) M_G3N_CALL_2tPUSH, x, y) +#define swap(x, y) M_G3N_CALL_2(SWAP, x, y) +#define hash(x) M_G3N_CALL_1(HASH, x) +#define equal(x, y) M_G3N_CALL_2(EQUAL, x, y) +#define cmp(x, y) M_G3N_CALL_2(CMP, x, y) +#define sort(x) M_G3N_CALL_1(SORT, x) +// splice_back +// splice_at +// it* #define empty_p(x) M_G3N_CALL_1(EMPTY_P, x) +#define add(x, y) M_G3N_CALL_2(ADD, x, y) +#define sub(x, y) M_G3N_CALL_2(SUB, x, y) +#define mul(x, y) M_G3N_CALL_2(MUL, x, y) +#define div(x, y) M_G3N_CALL_2(DIV, x, y) +#define reset(x) M_G3N_CALL_1(RESET, x) +// get +// set_at +// safe_get +// erase +// size +#define push(x, y) M_G3N_CALL_2t(PUSH, x, y) +#define pop(x, y) M_G3N_CALL_t2(PUSH, x, y) +#define push_move(x, y) M_G3N_CALL_2t(PUSH_MOVE, x, y) +#define pop_move(x, y) M_G3N_CALL_t2(PUSH, x, y) +#define reverse(x) M_G3N_CALL_1(REVERSE, x) +//#define get_str() +// out_str +// in_str +// out_str +// in_serial +// out_serial + +// init_with ? How to handle the different type of parameters ? +// emplace ? /* User code has to register oplists :