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 1a11fd1 commit 39fcc1f
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions m-generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down

0 comments on commit 39fcc1f

Please sign in to comment.