Add macro VARIANT_DEF2_AS

This commit is contained in:
Patrick Pelissier committed 2020-10-03 14:07:14 +02:00
1 parent b3fa63c971
commit ad4dcae1db
2 files changed
+20

No files matched your search

+10
View File
@@ -39,6 +39,16 @@
M_END_PROTECTED_CODE
/* Define the variant type and functions
as the given name_t
USAGE:
VARIANT_DEF2_AS(name, name_t, [(field1, type1, oplist1), (field2, type2, oplist2), ...] ) */
#define VARIANT_DEF2_AS(name, name_t, ...) \
M_BEGIN_PROTECTED_CODE \
VARIANTI_DEF2_P1( (name, name_t VARIANTI_INJECT_GLOBAL(__VA_ARGS__)) ) \
M_END_PROTECTED_CODE
/* Define the oplist of a variant.
USAGE: VARIANT_OPLIST(name[, oplist of the first type, ...]) */
#define VARIANT_OPLIST(...) \
+10
View File
@@ -58,6 +58,8 @@ VARIANT_DEF2(rvariant2, (name, string_t), (value, int))
VARIANT_DEF2(rvariant3, (name, string_t), (ivariant2, rvariant2_t), (ivariant, rvariant_t) )
VARIANT_DEF2_AS(vector, Vector, (x, double), (y, double) )
#define M_OPL_Vector() VARIANT_OPLIST(vector, M_DEFAULT_OPLIST)
static void test_pair(void)
{
@@ -273,11 +275,19 @@ test_io(void)
}
}
static void test_double (void)
{
M_LET(v, Vector) {
assert (vector_empty_p(v) );
}
}
int main(void)
{
test_pair();
test_triple();
test_io();
test_double();
exit(0);
}