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 8, 2023
1 parent e78963a commit 4c73221
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions m-generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@

#include "m-core.h"

#ifdef _MSC_VER
#define m_typeof(x) decltype(x)
#else
// Definition valid for C23, GCC, CLANG, TCC, ...
#define m_typeof(x) typeof(x)
#endif

/* 3 levels of indirection are neeeded:
* One level is the organisation.
* One level is the component of the organisation.
Expand Down Expand Up @@ -64,6 +71,19 @@ struct m_g3neric_dummys;
gentype: M_C(M_CALL_, op)(oplist(), M_AS_TYPE(gentype, x)), \
const gentype: M_C(M_CALL_, op)(oplist(), M_AS_LINKED_TYPE(const gentype, x, gentype, x)),

// Get a variable of the OPERATOR type of the oplist registered to the variable 'x'
#define M_G3N_TYPE_1(op, x) \
_Generic( ((void)0, (x)), \
M_MAP2(M_G3N_TYPE_1_func, (op, x) M_G3N_REGISTERED_ITEMS() ) \
struct m_g3neric_dummys *: /* cannot happen */ (void)0)
#define M_G3N_TYPE_1_func(x, oplist) \
M_G3N_TYPE_1_func_test(M_GET_GENTYPE oplist(), M_PAIR_1 x, M_PAIR_2 x, oplist)
#define M_G3N_TYPE_1_func_test(gentype, op, x, oplist) \
M_IF_METHOD(op, oplist())(M_G3N_TYPE_1_func_expand, M_EAT)(gentype, op, x, oplist)
#define M_G3N_TYPE_1_func_expand(gentype, op, x, oplist) \
gentype: ( M_C(M_GET_, op)(oplist() )) { 0 }, \
const gentype: ( M_C(M_GET_, op)(oplist() ) ) { 0 },

// Call the OPERATOR call of the oplist registered to the variable 'x'
// which takes two argument (type, type)
#define M_G3N_CALL_2(op, x, y) \
Expand Down Expand Up @@ -188,9 +208,16 @@ struct m_g3neric_dummys;
#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*
// splice_back(cont, cont, it)
// splice_at(cont, it, cont, it)
#define it_type(x) m_typeof(M_G3N_TYPE_1(IT_TYPE, x))
#define sub_type(x) m_typeof(M_G3N_TYPE_1(SUBTYPE, x))
// it_first(it_type, cont) + it_last + it_end
// it_set(it_type, it_type)
// it_end_p(it) + it_last_p(it) + it_next(it) + it_previous(it) + it_ref(it) + it_cref(it)
// it_equal_p(it, it)
// it_insert(cont, it, obj)
// it_remove(cont, 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)
Expand All @@ -207,8 +234,8 @@ struct m_g3neric_dummys;
#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()
//#define parse_str()
//#define get_str(string_t, cont, bool)
//#define parse_str(cont, const char *, const char **)
#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)
Expand Down

0 comments on commit 4c73221

Please sign in to comment.