Metalang99 1.13.3
Full-blown preprocessor metaprogramming
|
Utilitary stuff. More...
Go to the source code of this file.
Macros | |
#define | ML99_catEval(a, b) ML99_call(ML99_catEval, a, b) |
Concatenates a with b and evaluates the result. | |
#define | ML99_cat(a, b) ML99_call(ML99_cat, a, b) |
Concatenates a with b , leaving the result unevaluated. | |
#define | ML99_cat3(a, b, c) ML99_call(ML99_cat3, a, b, c) |
The same as ML99_cat but deals with 3 parameters. | |
#define | ML99_cat4(a, b, c, d) ML99_call(ML99_cat4, a, b, c, d) |
The same as ML99_cat but deals with 4 parameters. | |
#define | ML99_stringify(...) ML99_call(ML99_stringify, __VA_ARGS__) |
Stringifies provided arguments. | |
#define | ML99_empty(...) ML99_callUneval(ML99_empty, ) |
Evaluates to nothing. | |
#define | ML99_id(...) ML99_call(ML99_id, __VA_ARGS__) |
Evaluates to its arguments. | |
#define | ML99_const(x, a) ML99_call(ML99_const, x, a) |
Evaluates to x , skipping a . | |
#define | ML99_flip(f) ML99_call(ML99_flip, f) |
Reverses the order of arguments of the binary function f . | |
#define | ML99_uncomma(...) ML99_call(ML99_uncomma, __VA_ARGS__) |
Accepts terms and evaluates them with the space-separator. | |
#define | ML99_reify(f) ML99_call(ML99_reify, f) |
Turns f into a Metalang99-compliant metafunction with the arity of 1, which can be then called by ML99_appl. | |
#define | ML99_todo(f) ML99_call(ML99_todo, f) |
Indicates not yet implemented functionality of the macro f . | |
#define | ML99_todoWithMsg(f, message) ML99_call(ML99_todoWithMsg, f, message) |
The same as ML99_todo but emits a caller-supplied message. | |
#define | ML99_unimplemented(f) ML99_call(ML99_unimplemented, f) |
Indicates unimplemented functionality of the macro f . | |
#define | ML99_unimplementedWithMsg(f, message) ML99_call(ML99_unimplementedWithMsg, f, message) |
The same as ML99_unimplemented but emits a caller-supplied message. | |
#define | ML99_GEN_SYM(prefix, id) ML99_CAT4(prefix, id, _, __COUNTER__) |
Generates a unique identifier id in the namespace prefix . | |
#define | ML99_TRAILING_SEMICOLON(...) struct ml99_priv_trailing_semicolon |
Forces a caller to put a trailing semicolon. | |
#define | ML99_CAT_PRIMITIVE(a, b) a##b |
Concatenates a with b as-is, without expanding them. | |
#define | ML99_CAT3_PRIMITIVE(a, b, c) a##b##c |
The same as ML99_CAT_PRIMITIVE but deals with 3 parameters. | |
#define | ML99_CAT4_PRIMITIVE(a, b, c, d) a##b##c##d |
The same as ML99_CAT_PRIMITIVE but deals with 4 parameters. | |
#define | ML99_STRINGIFY_PRIMITIVE(...) #__VA_ARGS__ |
Stringifies x as-is, without expanding it. | |
#define | ML99_LPAREN(...) ( |
Expands to an opening parenthesis (( ). | |
#define | ML99_RPAREN(...) ) |
The same as ML99_LPAREN but emits a closing parenthesis. | |
#define | ML99_COMMA(...) , |
Expands to a single comma, consuming all arguments. | |
#define | ML99_GCC_PRAGMA(str) ML99_PRIV_GCC_PRAGMA(str) |
If you are compiling on GCC, this macro expands to _Pragma(str) , otherwise to emptiness. | |
#define | ML99_CLANG_PRAGMA(str) ML99_PRIV_CLANG_PRAGMA(str) |
The same as ML99_GCC_PRAGMA but for Clang. | |
#define | ML99_CAT(a, b) ML99_CAT_PRIMITIVE(a, b) |
#define | ML99_CAT3(a, b, c) ML99_CAT3_PRIMITIVE(a, b, c) |
#define | ML99_CAT4(a, b, c, d) ML99_CAT4_PRIMITIVE(a, b, c, d) |
#define | ML99_STRINGIFY(...) ML99_STRINGIFY_PRIMITIVE(__VA_ARGS__) |
#define | ML99_EMPTY(...) |
#define | ML99_ID(...) __VA_ARGS__ |
Utilitary stuff.
#define ML99_cat | ( | a, | |
b | |||
) | ML99_call(ML99_cat, a, b) |
Concatenates a
with b
, leaving the result unevaluated.
#define ML99_CAT_PRIMITIVE | ( | a, | |
b | |||
) | a##b |
Concatenates a
with b
as-is, without expanding them.
#define ML99_catEval | ( | a, | |
b | |||
) | ML99_call(ML99_catEval, a, b) |
Concatenates a
with b
and evaluates the result.
#define ML99_const | ( | x, | |
a | |||
) | ML99_call(ML99_const, x, a) |
#define ML99_flip | ( | f | ) | ML99_call(ML99_flip, f) |
Reverses the order of arguments of the binary function f
.
#define ML99_GEN_SYM | ( | prefix, | |
id | |||
) | ML99_CAT4(prefix, id, _, __COUNTER__) |
Generates a unique identifier id
in the namespace prefix
.
Let FOO
be the name of an enclosing macro. Then FOO_
must be specified for prefix
, and id
should be given any meaningful name (this makes debugging easier).
__COUNTER__
is defined, which must be a macro yielding integral literals starting from 0 incremented by 1 each time it is called. Currently, it is supported at least by Clang, GCC, TCC, and MSVC. #define ML99_id | ( | ... | ) | ML99_call(ML99_id, __VA_ARGS__) |
#define ML99_LPAREN | ( | ... | ) | ( |
Expands to an opening parenthesis ((
).
This is helpful when you want to delay macro arguments passing: just type BAR ML99_LPAREN() initial args...
at the end of some macro FOO
and complete the invocation of BAR
with the rest of args...)
in future.
This macro consumes all its arguments.
#define ML99_reify | ( | f | ) | ML99_call(ML99_reify, f) |
Turns f
into a Metalang99-compliant metafunction with the arity of 1, which can be then called by ML99_appl.
f
can be any C function or function-like macro.
Without ML99_reify, you would need to write some additional boilerplate:
#define ML99_RPAREN | ( | ... | ) | ) |
The same as ML99_LPAREN but emits a closing parenthesis.
#define ML99_stringify | ( | ... | ) | ML99_call(ML99_stringify, __VA_ARGS__) |
Stringifies provided arguments.
#define ML99_STRINGIFY_PRIMITIVE | ( | ... | ) | #__VA_ARGS__ |
Stringifies x
as-is, without expanding it.
#define ML99_todo | ( | f | ) | ML99_call(ML99_todo, f) |
Indicates not yet implemented functionality of the macro f
.
ML99_todo is the same as ML99_unimplemented except that the former conveys an intent that the functionality is to be implemented later but ML99_unimplemented makes no such claims.
#define ML99_todoWithMsg | ( | f, | |
message | |||
) | ML99_call(ML99_todoWithMsg, f, message) |
The same as ML99_todo but emits a caller-supplied message.
message
must be a string literal.
#define ML99_TRAILING_SEMICOLON | ( | ... | ) | struct ml99_priv_trailing_semicolon |
Forces a caller to put a trailing semicolon.
It is useful when defining macros, to make them formatted as complete statements.
do { ... } while (0)
idiom, this macro expands to a C declaration. #define ML99_uncomma | ( | ... | ) | ML99_call(ML99_uncomma, __VA_ARGS__) |
Accepts terms and evaluates them with the space-separator.
#define ML99_unimplemented | ( | f | ) | ML99_call(ML99_unimplemented, f) |
Indicates unimplemented functionality of the macro f
.
ML99_unimplemented is the same as ML99_todo except that the latter conveys an intent that the functionality is to be implemented later but ML99_unimplemented makes no such claims.
#define ML99_unimplementedWithMsg | ( | f, | |
message | |||
) | ML99_call(ML99_unimplementedWithMsg, f, message) |
The same as ML99_unimplemented but emits a caller-supplied message.
message
must be a string literal.