Metalang99 1.13.3
Full-blown preprocessor metaprogramming
gen.h
Go to the documentation of this file.
1
9#ifndef ML99_GEN_H
10#define ML99_GEN_H
11
12#include <metalang99/priv/bool.h>
13
14#include <metalang99/choice.h>
15#include <metalang99/lang.h>
16#include <metalang99/list.h>
17#include <metalang99/nat.h>
18#include <metalang99/tuple.h>
20
21#include <metalang99/stmt.h> // For backwards compatibility.
22#include <metalang99/util.h> // For backwards compatibility: ML99_GEN_SYM, ML99_TRAILING_SEMICOLON.
23
36#define ML99_semicoloned(...) ML99_call(ML99_semicoloned, __VA_ARGS__)
37
50#define ML99_braced(...) ML99_call(ML99_braced, __VA_ARGS__)
51
64#define ML99_assign(lhs, ...) ML99_call(ML99_assign, lhs, __VA_ARGS__)
65
69#define ML99_assignInitializerList(lhs, ...) ML99_call(ML99_assignInitializerList, lhs, __VA_ARGS__)
70
74#define ML99_assignStmt(lhs, ...) ML99_call(ML99_assignStmt, lhs, __VA_ARGS__)
75
79#define ML99_assignInitializerListStmt(lhs, ...) \
80 ML99_call(ML99_assignInitializerListStmt, lhs, __VA_ARGS__)
81
94#define ML99_invoke(f, ...) ML99_call(ML99_invoke, f, __VA_ARGS__)
95
99#define ML99_invokeStmt(f, ...) ML99_call(ML99_invokeStmt, f, __VA_ARGS__)
100
115#define ML99_prefixedBlock(prefix, ...) ML99_call(ML99_prefixedBlock, prefix, __VA_ARGS__)
116
129#define ML99_typedef(ident, ...) ML99_call(ML99_typedef, ident, __VA_ARGS__)
130
143#define ML99_struct(ident, ...) ML99_call(ML99_struct, ident, __VA_ARGS__)
144
157#define ML99_anonStruct(...) ML99_call(ML99_anonStruct, __VA_ARGS__)
158
162#define ML99_union(ident, ...) ML99_call(ML99_union, ident, __VA_ARGS__)
163
167#define ML99_anonUnion(...) ML99_call(ML99_anonUnion, __VA_ARGS__)
168
172#define ML99_enum(ident, ...) ML99_call(ML99_enum, ident, __VA_ARGS__)
173
177#define ML99_anonEnum(...) ML99_call(ML99_anonEnum, __VA_ARGS__)
178
194#define ML99_fnPtr(ret_ty, name, ...) ML99_call(ML99_fnPtr, ret_ty, name, __VA_ARGS__)
195
199#define ML99_fnPtrStmt(ret_ty, name, ...) ML99_call(ML99_fnPtrStmt, ret_ty, name, __VA_ARGS__)
200
213#define ML99_times(n, ...) ML99_call(ML99_times, n, __VA_ARGS__)
214
228#define ML99_repeat(n, f) ML99_call(ML99_repeat, n, f)
229
247#define ML99_indexedParams(type_list) ML99_call(ML99_indexedParams, type_list)
248
266#define ML99_indexedFields(type_list) ML99_call(ML99_indexedFields, type_list)
267
285#define ML99_indexedInitializerList(n) ML99_call(ML99_indexedInitializerList, n)
286
304#define ML99_indexedArgs(n) ML99_call(ML99_indexedArgs, n)
305
306#ifndef DOXYGEN_IGNORE
307
308#define ML99_semicoloned_IMPL(...) v(__VA_ARGS__;)
309#define ML99_braced_IMPL(...) v({__VA_ARGS__})
310#define ML99_assign_IMPL(lhs, ...) v(lhs = __VA_ARGS__)
311#define ML99_assignStmt_IMPL(lhs, ...) v(lhs = __VA_ARGS__;)
312#define ML99_assignInitializerList_IMPL(lhs, ...) v(lhs = {__VA_ARGS__})
313#define ML99_assignInitializerListStmt_IMPL(lhs, ...) v(lhs = {__VA_ARGS__};)
314#define ML99_invoke_IMPL(f, ...) v(f(__VA_ARGS__))
315#define ML99_invokeStmt_IMPL(f, ...) v(f(__VA_ARGS__);)
316#define ML99_typedef_IMPL(ident, ...) v(typedef __VA_ARGS__ ident;)
317#define ML99_fnPtr_IMPL(ret_ty, name, ...) v(ret_ty (*name)(__VA_ARGS__))
318#define ML99_fnPtrStmt_IMPL(ret_ty, name, ...) v(ret_ty (*name)(__VA_ARGS__);)
319
320// clang-format off
321#define ML99_prefixedBlock_IMPL(prefix, ...) v(prefix {__VA_ARGS__})
322#define ML99_struct_IMPL(ident, ...) v(struct ident {__VA_ARGS__})
323#define ML99_anonStruct_IMPL(...) v(struct {__VA_ARGS__})
324#define ML99_union_IMPL(ident, ...) v(union ident {__VA_ARGS__})
325#define ML99_anonUnion_IMPL(...) v(union {__VA_ARGS__})
326#define ML99_enum_IMPL(ident, ...) v(enum ident {__VA_ARGS__})
327#define ML99_anonEnum_IMPL(...) v(enum {__VA_ARGS__})
328// clang-format on
329
330#define ML99_times_IMPL(n, ...) ML99_natMatchWithArgs_IMPL(n, ML99_PRIV_times_, __VA_ARGS__)
331#define ML99_PRIV_times_Z_IMPL ML99_empty_IMPL
332#define ML99_PRIV_times_S_IMPL(i, ...) ML99_TERMS(v(__VA_ARGS__), ML99_times_IMPL(i, __VA_ARGS__))
333
334#define ML99_repeat_IMPL(n, f) ML99_natMatchWithArgs_IMPL(n, ML99_PRIV_repeat_, f)
335#define ML99_PRIV_repeat_Z_IMPL ML99_empty_IMPL
336#define ML99_PRIV_repeat_S_IMPL(i, f) ML99_TERMS(ML99_repeat_IMPL(i, f), ML99_appl_IMPL(f, i))
337
338// ML99_indexedParams_IMPL {
339
340#define ML99_indexedParams_IMPL(type_list) \
341 ML99_tuple(ML99_PRIV_IF( \
342 ML99_IS_NIL(type_list), \
343 v(void), \
344 ML99_variadicsTail(ML99_PRIV_indexedParamsAux_IMPL(type_list, 0))))
345
346#define ML99_PRIV_indexedParamsAux_IMPL(type_list, i) \
347 ML99_matchWithArgs_IMPL(type_list, ML99_PRIV_indexedParams_, i)
348#define ML99_PRIV_indexedParams_nil_IMPL ML99_empty_IMPL
349#define ML99_PRIV_indexedParams_cons_IMPL(x, xs, i) \
350 ML99_TERMS(v(, x _##i), ML99_PRIV_indexedParamsAux_IMPL(xs, ML99_INC(i)))
351// } (ML99_indexedParams_IMPL)
352
353// ML99_indexedFields_IMPL {
354
355#define ML99_indexedFields_IMPL(type_list) ML99_PRIV_indexedFieldsAux_IMPL(type_list, 0)
356
357#define ML99_PRIV_indexedFieldsAux_IMPL(type_list, i) \
358 ML99_matchWithArgs_IMPL(type_list, ML99_PRIV_indexedFields_, i)
359#define ML99_PRIV_indexedFields_nil_IMPL ML99_empty_IMPL
360#define ML99_PRIV_indexedFields_cons_IMPL(x, xs, i) \
361 ML99_TERMS(v(x _##i;), ML99_PRIV_indexedFieldsAux_IMPL(xs, ML99_INC(i)))
362// } (ML99_indexedFields_IMPL)
363
364#define ML99_indexedInitializerList_IMPL(n) ML99_braced(ML99_PRIV_INDEXED_ITEMS(n, v(0)))
365#define ML99_indexedArgs_IMPL(n) ML99_PRIV_INDEXED_ITEMS(n, v(ML99_EMPTY()))
366
367#define ML99_PRIV_INDEXED_ITEMS(n, empty_case) \
368 ML99_PRIV_IF( \
369 ML99_NAT_EQ(n, 0), \
370 empty_case, \
371 ML99_variadicsTail(ML99_repeat_IMPL(n, ML99_PRIV_indexedItem)))
372
373#define ML99_PRIV_indexedItem_IMPL(i) v(, _##i)
374
375// Arity specifiers {
376
377#define ML99_semicoloned_ARITY 1
378#define ML99_braced_ARITY 1
379#define ML99_assign_ARITY 2
380#define ML99_assignStmt_ARITY 2
381#define ML99_assignInitializerList_ARITY 2
382#define ML99_assignInitializerListStmt_ARITY 2
383#define ML99_invoke_ARITY 2
384#define ML99_invokeStmt_ARITY 2
385#define ML99_prefixedBlock_ARITY 2
386#define ML99_typedef_ARITY 2
387#define ML99_struct_ARITY 2
388#define ML99_anonStruct_ARITY 1
389#define ML99_union_ARITY 2
390#define ML99_anonUnion_ARITY 1
391#define ML99_enum_ARITY 2
392#define ML99_anonEnum_ARITY 1
393#define ML99_fnPtr_ARITY 3
394#define ML99_fnPtrStmt_ARITY 3
395#define ML99_repeat_ARITY 2
396#define ML99_times_ARITY 2
397#define ML99_indexedParams_ARITY 1
398#define ML99_indexedFields_ARITY 1
399#define ML99_indexedInitializerList_ARITY 1
400#define ML99_indexedArgs_ARITY 1
401
402#define ML99_PRIV_indexedItem_ARITY 1
403// } (Arity specifiers)
404
405#endif // DOXYGEN_IGNORE
406
407#endif // ML99_GEN_H
Choice types: (tag, ...).
The core metalanguage.
Cons-lists.
Natural numbers: [0; 255].
Statement chaining.
Tuples: (x, y, z).
Utilitary stuff.
Variadic arguments: x, y, z.