Loading...
Searching...
No Matches
gen.h
Go to the documentation of this file.
#ifndef ML99_GEN_H
#define ML99_GEN_H
#include <metalang99/priv/bool.h>
#include <metalang99/choice.h>
#include <metalang99/lang.h>
#include <metalang99/list.h>
#include <metalang99/nat.h>
#include <metalang99/tuple.h>
#include <metalang99/variadics.h>
#include <metalang99/stmt.h> // For backwards compatibility.
#include <metalang99/util.h> // For backwards compatibility: ML99_GEN_SYM, ML99_TRAILING_SEMICOLON.
#define ML99_semicoloned(...) ML99_call(ML99_semicoloned, __VA_ARGS__)
#define ML99_braced(...) ML99_call(ML99_braced, __VA_ARGS__)
#define ML99_assign(lhs, ...) ML99_call(ML99_assign, lhs, __VA_ARGS__)
#define ML99_assignInitializerList(lhs, ...) ML99_call(ML99_assignInitializerList, lhs, __VA_ARGS__)
#define ML99_assignStmt(lhs, ...) ML99_call(ML99_assignStmt, lhs, __VA_ARGS__)
#define ML99_assignInitializerListStmt(lhs, ...) \
ML99_call(ML99_assignInitializerListStmt, lhs, __VA_ARGS__)
#define ML99_invoke(f, ...) ML99_call(ML99_invoke, f, __VA_ARGS__)
#define ML99_invokeStmt(f, ...) ML99_call(ML99_invokeStmt, f, __VA_ARGS__)
#define ML99_prefixedBlock(prefix, ...) ML99_call(ML99_prefixedBlock, prefix, __VA_ARGS__)
#define ML99_typedef(ident, ...) ML99_call(ML99_typedef, ident, __VA_ARGS__)
#define ML99_struct(ident, ...) ML99_call(ML99_struct, ident, __VA_ARGS__)
#define ML99_anonStruct(...) ML99_call(ML99_anonStruct, __VA_ARGS__)
#define ML99_union(ident, ...) ML99_call(ML99_union, ident, __VA_ARGS__)
#define ML99_anonUnion(...) ML99_call(ML99_anonUnion, __VA_ARGS__)
#define ML99_enum(ident, ...) ML99_call(ML99_enum, ident, __VA_ARGS__)
#define ML99_anonEnum(...) ML99_call(ML99_anonEnum, __VA_ARGS__)
#define ML99_fnPtr(ret_ty, name, ...) ML99_call(ML99_fnPtr, ret_ty, name, __VA_ARGS__)
#define ML99_fnPtrStmt(ret_ty, name, ...) ML99_call(ML99_fnPtrStmt, ret_ty, name, __VA_ARGS__)
#define ML99_times(n, ...) ML99_call(ML99_times, n, __VA_ARGS__)
#define ML99_repeat(n, f) ML99_call(ML99_repeat, n, f)
#define ML99_indexedParams(type_list) ML99_call(ML99_indexedParams, type_list)
#define ML99_indexedFields(type_list) ML99_call(ML99_indexedFields, type_list)
#define ML99_indexedInitializerList(n) ML99_call(ML99_indexedInitializerList, n)
#define ML99_indexedArgs(n) ML99_call(ML99_indexedArgs, n)
#ifndef DOXYGEN_IGNORE
#define ML99_semicoloned_IMPL(...) v(__VA_ARGS__;)
#define ML99_braced_IMPL(...) v({__VA_ARGS__})
#define ML99_assign_IMPL(lhs, ...) v(lhs = __VA_ARGS__)
#define ML99_assignStmt_IMPL(lhs, ...) v(lhs = __VA_ARGS__;)
#define ML99_assignInitializerList_IMPL(lhs, ...) v(lhs = {__VA_ARGS__})
#define ML99_assignInitializerListStmt_IMPL(lhs, ...) v(lhs = {__VA_ARGS__};)
#define ML99_invoke_IMPL(f, ...) v(f(__VA_ARGS__))
#define ML99_invokeStmt_IMPL(f, ...) v(f(__VA_ARGS__);)
#define ML99_typedef_IMPL(ident, ...) v(typedef __VA_ARGS__ ident;)
#define ML99_fnPtr_IMPL(ret_ty, name, ...) v(ret_ty (*name)(__VA_ARGS__))
#define ML99_fnPtrStmt_IMPL(ret_ty, name, ...) v(ret_ty (*name)(__VA_ARGS__);)
// clang-format off
#define ML99_prefixedBlock_IMPL(prefix, ...) v(prefix {__VA_ARGS__})
#define ML99_struct_IMPL(ident, ...) v(struct ident {__VA_ARGS__})
#define ML99_anonStruct_IMPL(...) v(struct {__VA_ARGS__})
#define ML99_union_IMPL(ident, ...) v(union ident {__VA_ARGS__})
#define ML99_anonUnion_IMPL(...) v(union {__VA_ARGS__})
#define ML99_enum_IMPL(ident, ...) v(enum ident {__VA_ARGS__})
#define ML99_anonEnum_IMPL(...) v(enum {__VA_ARGS__})
// clang-format on
#define ML99_times_IMPL(n, ...) ML99_natMatchWithArgs_IMPL(n, ML99_PRIV_times_, __VA_ARGS__)
#define ML99_PRIV_times_Z_IMPL ML99_empty_IMPL
#define ML99_PRIV_times_S_IMPL(i, ...) ML99_TERMS(v(__VA_ARGS__), ML99_times_IMPL(i, __VA_ARGS__))
#define ML99_repeat_IMPL(n, f) ML99_natMatchWithArgs_IMPL(n, ML99_PRIV_repeat_, f)
#define ML99_PRIV_repeat_Z_IMPL ML99_empty_IMPL
#define ML99_PRIV_repeat_S_IMPL(i, f) ML99_TERMS(ML99_repeat_IMPL(i, f), ML99_appl_IMPL(f, i))
// ML99_indexedParams_IMPL {
#define ML99_indexedParams_IMPL(type_list) \
ML99_tuple(ML99_PRIV_IF( \
ML99_IS_NIL(type_list), \
v(void), \
ML99_variadicsTail(ML99_PRIV_indexedParamsAux_IMPL(type_list, 0))))
#define ML99_PRIV_indexedParamsAux_IMPL(type_list, i) \
ML99_matchWithArgs_IMPL(type_list, ML99_PRIV_indexedParams_, i)
#define ML99_PRIV_indexedParams_nil_IMPL ML99_empty_IMPL
#define ML99_PRIV_indexedParams_cons_IMPL(x, xs, i) \
ML99_TERMS(v(, x _##i), ML99_PRIV_indexedParamsAux_IMPL(xs, ML99_INC(i)))
// } (ML99_indexedParams_IMPL)
// ML99_indexedFields_IMPL {
#define ML99_indexedFields_IMPL(type_list) ML99_PRIV_indexedFieldsAux_IMPL(type_list, 0)
#define ML99_PRIV_indexedFieldsAux_IMPL(type_list, i) \
ML99_matchWithArgs_IMPL(type_list, ML99_PRIV_indexedFields_, i)
#define ML99_PRIV_indexedFields_nil_IMPL ML99_empty_IMPL
#define ML99_PRIV_indexedFields_cons_IMPL(x, xs, i) \
ML99_TERMS(v(x _##i;), ML99_PRIV_indexedFieldsAux_IMPL(xs, ML99_INC(i)))
// } (ML99_indexedFields_IMPL)
#define ML99_indexedInitializerList_IMPL(n) ML99_braced(ML99_PRIV_INDEXED_ITEMS(n, v(0)))
#define ML99_indexedArgs_IMPL(n) ML99_PRIV_INDEXED_ITEMS(n, v(ML99_EMPTY()))
#define ML99_PRIV_INDEXED_ITEMS(n, empty_case) \
ML99_PRIV_IF( \
ML99_NAT_EQ(n, 0), \
empty_case, \
ML99_variadicsTail(ML99_repeat_IMPL(n, ML99_PRIV_indexedItem)))
#define ML99_PRIV_indexedItem_IMPL(i) v(, _##i)
// Arity specifiers {
#define ML99_semicoloned_ARITY 1
#define ML99_braced_ARITY 1
#define ML99_assign_ARITY 2
#define ML99_assignStmt_ARITY 2
#define ML99_assignInitializerList_ARITY 2
#define ML99_assignInitializerListStmt_ARITY 2
#define ML99_invoke_ARITY 2
#define ML99_invokeStmt_ARITY 2
#define ML99_prefixedBlock_ARITY 2
#define ML99_typedef_ARITY 2
#define ML99_struct_ARITY 2
#define ML99_anonStruct_ARITY 1
#define ML99_union_ARITY 2
#define ML99_anonUnion_ARITY 1
#define ML99_enum_ARITY 2
#define ML99_anonEnum_ARITY 1
#define ML99_fnPtr_ARITY 3
#define ML99_fnPtrStmt_ARITY 3
#define ML99_repeat_ARITY 2
#define ML99_times_ARITY 2
#define ML99_indexedParams_ARITY 1
#define ML99_indexedFields_ARITY 1
#define ML99_indexedInitializerList_ARITY 1
#define ML99_indexedArgs_ARITY 1
#define ML99_PRIV_indexedItem_ARITY 1
// } (Arity specifiers)
#endif // DOXYGEN_IGNORE
#endif // ML99_GEN_H
choice.h
Choice types: (tag, ...).
lang.h
The core metalanguage.
list.h
Cons-lists.
nat.h
Natural numbers: [0; 255].
stmt.h
Statement chaining.
tuple.h
Tuples: (x, y, z).
util.h
Utilitary stuff.
variadics.h
Variadic arguments: x, y, z.