Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
P-p-H-d committed Nov 5, 2023
1 parent 39fcc1f commit ace4c55
Showing 1 changed file with 45 additions and 13 deletions.
58 changes: 45 additions & 13 deletions m-generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ struct m_g3neric_dummys;
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_2t_func_test(gentype, basictype, op, x, y, oplist) \
M_IF_METHOD(op, oplist())(M_G3N_CALL_2t_func_expand, M_EAT)(gentype, op, x, y, oplist)
M_IF_METHOD(op, oplist())(M_G3N_CALL_2t_func_expand, M_EAT)(gentype, basictype, op, x, y, oplist)
#define M_G3N_CALL_2t_func_expand(gentype, basictype, op, x, y, oplist) \
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)
// which takes two argument (subtype *, type)
#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() ) \
Expand All @@ -105,11 +105,41 @@ struct m_g3neric_dummys;
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)
M_IF_METHOD(op, oplist())(M_G3N_CALL_t2_func_expand, M_EAT)(gentype, basictype, 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)),

// Call the OPERATOR call of the oplist registered to the variable 'x'
// which takes two argument (type, a) typeof(a) is always the same for all types
#define M_G3N_CALL_21(op, x, y) \
_Generic( ((void)0, (x)), \
M_MAP2(M_G3N_CALL_21_func, (op, x, y) M_G3N_REGISTERED_ITEMS() ) \
struct m_g3neric_dummys *: /* cannot happen */ (void) 0)
#define M_G3N_CALL_21_func(x, oplist) \
M_G3N_CALL_21_func_test(M_GET_GENTYPE oplist(), \
M_TRIPLE_1 x, M_TRIPLE_2 x, M_TRIPLE_3 x, oplist)
#define M_G3N_CALL_21_func_test(gentype, op, x, y, oplist) \
M_IF_METHOD(op, oplist())(M_G3N_CALL_21_func_expand, M_EAT)(gentype, op, x, y, oplist)
#define M_G3N_CALL_21_func_expand(gentype, op, x, y, oplist) \
gentype: M_C(M_CALL_, op)(oplist(), M_AS_TYPE(gentype, x), y), \
const gentype: M_C(M_CALL_, op)(oplist(), M_AS_TYPE(const gentype, x), y),

// Call the OPERATOR call of the oplist registered to the variable 'x'
// which takes two argument (a, type) typeof(a) is always the same for all types
#define M_G3N_CALL_22(op, x, y) \
_Generic( ((void)0, (y)), \
M_MAP2(M_G3N_CALL_22_func, (op, x, y) M_G3N_REGISTERED_ITEMS() ) \
struct m_g3neric_dummys *: /* cannot happen */ (void) 0)
#define M_G3N_CALL_22_func(x, oplist) \
M_G3N_CALL_22_func_test(M_GET_GENTYPE oplist(), \
M_TRIPLE_1 x, M_TRIPLE_2 x, M_TRIPLE_3 x, oplist)
#define M_G3N_CALL_22_func_test(gentype, op, x, y, oplist) \
M_IF_METHOD(op, oplist())(M_G3N_CALL_22_func_expand, M_EAT)(gentype, op, x, y, oplist)
#define M_G3N_CALL_22_func_expand(gentype, op, x, y, oplist) \
gentype: M_C(M_CALL_, op)(oplist(), x, M_AS_TYPE(gentype, y)), \
const gentype: M_C(M_CALL_, op)(oplist(), x, M_AS_TYPE(const gentype, y)),

#define M_AS_LINKED_TYPE(typex, x, typey, y) _Generic(((void)0,(x)), typex: (y), default: (typey) {0})

// Define generic functions
Expand Down Expand Up @@ -138,21 +168,23 @@ struct m_g3neric_dummys;
// set_at
// safe_get
// erase
// size
#define get_size(x) M_G3N_CALL_1(GET_SIZE, x)
#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 ?
//#define get_str()
//#define parse_str()
#define out_str(x, y) M_G3N_CALL_22(OUT_STR, x, y)
#define in_str(x, y) M_G3N_CALL_21(IN_STR, x, y)
#define out_serial(x, y) M_G3N_CALL_22(OUT_SERIAL, x, y)
#define in_serial(x, y) M_G3N_CALL_21(IN_SERIAL, x, y)

// TODO: init_with ? How to handle the different type of parameters ?
// TODO: emplace ?
// TODO: for each(x, cont) { }
// TODO: Integrate in M_PRINT ?

/* User code has to register oplists :
Expand Down

0 comments on commit ace4c55

Please sign in to comment.