Metalang99 1.13.5
Full-blown preprocessor metaprogramming
Loading...
Searching...
No Matches
gen.h File Reference

Support for C language constructions. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ML99_semicoloned(...)
 Puts a semicolon after provided arguments.
#define ML99_braced(...)
 Puts provided arguments into braces.
#define ML99_assign(lhs, ...)
 Generates an assignment of provided variadic arguments to lhs.
#define ML99_assignInitializerList(lhs, ...)
 A shortcut for ML99_assign(lhs, ML99_braced(...)).
#define ML99_assignStmt(lhs, ...)
 A shortcut for ML99_semicoloned(ML99_assign(lhs, ...)).
#define ML99_assignInitializerListStmt(lhs, ...)
 A shortcut for ML99_assignStmt(lhs, ML99_braced(...)).
#define ML99_invoke(f, ...)
 Generates a function/macro invocation.
#define ML99_invokeStmt(f, ...)
 A shortcut for ML99_semicoloned(ML99_invoke(f, ...)).
#define ML99_prefixedBlock(prefix, ...)
 Generates prefix { code }.
#define ML99_typedef(ident, ...)
 Generates a type definition.
#define ML99_struct(ident, ...)
 Generates a C structure.
#define ML99_anonStruct(...)
 Generates an anonymous C structure.
#define ML99_union(ident, ...)
 The same as ML99_struct but generates a union.
#define ML99_anonUnion(...)
 The same as ML99_anonStruct but generates a union.
#define ML99_enum(ident, ...)
 The same as ML99_struct but generates an enumeration.
#define ML99_anonEnum(...)
 The same as ML99_anonStruct but generates an enumeration.
#define ML99_fnPtr(ret_ty, name, ...)
 Generates a function pointer.
#define ML99_fnPtrStmt(ret_ty, name, ...)
 A shortcut for ML99_semicoloned(ML99_fnPtr(ret_ty, name, ...)).
#define ML99_times(n, ...)
 Pastes provided arguments n times.
#define ML99_repeat(n, f)
 Invokes f n times, providing an iteration index each time.
#define ML99_indexedParams(type_list)
 Generates \((T_0 \ \_0, ..., T_n \ \_n)\).
#define ML99_indexedFields(type_list)
 Generates \(T_0 \ \_0; ...; T_n \ \_n\).
#define ML99_indexedInitializerList(n)
 Generates \(\{ \_0, ..., \_{n - 1} \}\).
#define ML99_indexedArgs(n)
 Generates \(\_0, ..., \_{n - 1}\).

Detailed Description

Support for C language constructions.

Some decent usage examples can be found in datatype99/examples/derive.

Macro Definition Documentation

◆ ML99_anonEnum

#define ML99_anonEnum ( ...)
Value:
ML99_call(ML99_anonEnum, __VA_ARGS__)
#define ML99_anonEnum(...)
The same as ML99_anonStruct but generates an enumeration.
Definition gen.h:177
#define ML99_call(op,...)
Invokes a metafunction with arguments.
Definition lang.h:33

The same as ML99_anonStruct but generates an enumeration.

◆ ML99_anonStruct

#define ML99_anonStruct ( ...)
Value:
#define ML99_anonStruct(...)
Generates an anonymous C structure.
Definition gen.h:157

Generates an anonymous C structure.

Examples

#include <metalang99/gen.h>
// struct { int x, y; }
ML99_struct(v(int x, y;))
Support for C language constructions.
#define ML99_struct(ident,...)
Generates a C structure.
Definition gen.h:143
#define v(...)
A value that is pasted as-is; no evaluation occurs on provided arguments.
Definition lang.h:145

◆ ML99_anonUnion

#define ML99_anonUnion ( ...)
Value:
#define ML99_anonUnion(...)
The same as ML99_anonStruct but generates a union.
Definition gen.h:167

The same as ML99_anonStruct but generates a union.

◆ ML99_assign

#define ML99_assign ( lhs,
... )
Value:
ML99_call(ML99_assign, lhs, __VA_ARGS__)
#define ML99_assign(lhs,...)
Generates an assignment of provided variadic arguments to lhs.
Definition gen.h:64

Generates an assignment of provided variadic arguments to lhs.

Examples

#include <metalang99/gen.h>
// x = 5, 6, 7
ML99_assign(v(x), v(5, 6, 7))

◆ ML99_assignInitializerList

#define ML99_assignInitializerList ( lhs,
... )
Value:
#define ML99_assignInitializerList(lhs,...)
A shortcut for ML99_assign(lhs, ML99_braced(...)).
Definition gen.h:69

A shortcut for ML99_assign(lhs, ML99_braced(...)).

◆ ML99_assignInitializerListStmt

#define ML99_assignInitializerListStmt ( lhs,
... )
Value:
#define ML99_assignInitializerListStmt(lhs,...)
A shortcut for ML99_assignStmt(lhs, ML99_braced(...)).
Definition gen.h:79

A shortcut for ML99_assignStmt(lhs, ML99_braced(...)).

◆ ML99_assignStmt

#define ML99_assignStmt ( lhs,
... )
Value:
ML99_call(ML99_assignStmt, lhs, __VA_ARGS__)
#define ML99_assignStmt(lhs,...)
A shortcut for ML99_semicoloned(ML99_assign(lhs, ...)).
Definition gen.h:74

A shortcut for ML99_semicoloned(ML99_assign(lhs, ...)).

◆ ML99_braced

#define ML99_braced ( ...)
Value:
ML99_call(ML99_braced, __VA_ARGS__)
#define ML99_braced(...)
Puts provided arguments into braces.
Definition gen.h:50

Puts provided arguments into braces.

Examples

#include <metalang99/gen.h>
// { int a, b, c; }
ML99_braced(v(int a, b, c;))

◆ ML99_enum

#define ML99_enum ( ident,
... )
Value:
ML99_call(ML99_enum, ident, __VA_ARGS__)
#define ML99_enum(ident,...)
The same as ML99_struct but generates an enumeration.
Definition gen.h:172

The same as ML99_struct but generates an enumeration.

◆ ML99_fnPtr

#define ML99_fnPtr ( ret_ty,
name,
... )
Value:
ML99_call(ML99_fnPtr, ret_ty, name, __VA_ARGS__)
#define ML99_fnPtr(ret_ty, name,...)
Generates a function pointer.
Definition gen.h:194

Generates a function pointer.

Examples

#include <metalang99/gen.h>
// int (*add)(int x, int y)
ML99_fnPtr(v(int), v(add), v(int x), v(int y))
// const char *(*title)(void)
ML99_fnPtr(v(const char *), v(title), v(void))

◆ ML99_fnPtrStmt

#define ML99_fnPtrStmt ( ret_ty,
name,
... )
Value:
ML99_call(ML99_fnPtrStmt, ret_ty, name, __VA_ARGS__)
#define ML99_fnPtrStmt(ret_ty, name,...)
A shortcut for ML99_semicoloned(ML99_fnPtr(ret_ty, name, ...)).
Definition gen.h:199

A shortcut for ML99_semicoloned(ML99_fnPtr(ret_ty, name, ...)).

◆ ML99_indexedArgs

#define ML99_indexedArgs ( n)
Value:
#define ML99_indexedArgs(n)
Generates .
Definition gen.h:304

Generates \(\_0, ..., \_{n - 1}\).

If n is 0, this macro results in emptiness.

Examples

#include <metalang99/gen.h>
// _0, _1, _2
// ML99_empty()

◆ ML99_indexedFields

#define ML99_indexedFields ( type_list)
Value:
#define ML99_indexedFields(type_list)
Generates .
Definition gen.h:266

Generates \(T_0 \ \_0; ...; T_n \ \_n\).

If type_list is empty, this macro results in emptiness.

Examples

#include <metalang99/gen.h>
// int _0; long long _1; const char * _2;
ML99_indexedFields(ML99_list(v(int, long long, const char *)))
// ML99_empty()
#define ML99_list(...)
Constructs a list from its arguments.
Definition list.h:147
#define ML99_nil(...)
The empty list.
Definition list.h:35

◆ ML99_indexedInitializerList

#define ML99_indexedInitializerList ( n)
Value:
#define ML99_indexedInitializerList(n)
Generates .
Definition gen.h:285

Generates \(\{ \_0, ..., \_{n - 1} \}\).

If n is 0, this macro results in { 0 }.

Examples

#include <metalang99/gen.h>
// { _0, _1, _2 }
// { 0 }

◆ ML99_indexedParams

#define ML99_indexedParams ( type_list)
Value:
#define ML99_indexedParams(type_list)
Generates .
Definition gen.h:247

Generates \((T_0 \ \_0, ..., T_n \ \_n)\).

If type_list is empty, this macro results in (void).

Examples

#include <metalang99/gen.h>
// (int _0, long long _1, const char * _2)
ML99_indexedParams(ML99_list(v(int, long long, const char *)))
// (void)

◆ ML99_invoke

#define ML99_invoke ( f,
... )
Value:
ML99_call(ML99_invoke, f, __VA_ARGS__)
#define ML99_invoke(f,...)
Generates a function/macro invocation.
Definition gen.h:94

Generates a function/macro invocation.

Examples

#include <metalang99/gen.h>
// If you are on C11.
ML99_invoke(v(_Static_assert), v(1 == 1, "Must be true"))

◆ ML99_invokeStmt

#define ML99_invokeStmt ( f,
... )
Value:
ML99_call(ML99_invokeStmt, f, __VA_ARGS__)
#define ML99_invokeStmt(f,...)
A shortcut for ML99_semicoloned(ML99_invoke(f, ...)).
Definition gen.h:99

A shortcut for ML99_semicoloned(ML99_invoke(f, ...)).

◆ ML99_prefixedBlock

#define ML99_prefixedBlock ( prefix,
... )
Value:
ML99_call(ML99_prefixedBlock, prefix, __VA_ARGS__)
#define ML99_prefixedBlock(prefix,...)
Generates prefix { code }.
Definition gen.h:115

Generates prefix { code }.

Examples

#include <metalang99/gen.h>
// if (1 == 1) {
// printf("x = %d\n", x);
// }
ML99_prefixedBlock(v(if (1 == 1)), v(printf("x = %d\n", x);))

◆ ML99_repeat

#define ML99_repeat ( n,
f )
Value:
#define ML99_repeat(n, f)
Invokes f n times, providing an iteration index each time.
Definition gen.h:228

Invokes f n times, providing an iteration index each time.

Examples

#include <metalang99/gen.h>
// _0 _1 _2
#define ML99_appl(f,...)
Applies arguments to f.
Definition lang.h:93
Utilitary stuff.
#define ML99_cat(a, b)
Concatenates a with b, leaving the result unevaluated.
Definition util.h:53

◆ ML99_semicoloned

#define ML99_semicoloned ( ...)
Value:
#define ML99_semicoloned(...)
Puts a semicolon after provided arguments.
Definition gen.h:36

Puts a semicolon after provided arguments.

Examples

#include <metalang99/gen.h>
// int x = 5;
ML99_semicoloned(v(int x = 5))

◆ ML99_struct

#define ML99_struct ( ident,
... )
Value:
ML99_call(ML99_struct, ident, __VA_ARGS__)

Generates a C structure.

Examples

#include <metalang99/gen.h>
// struct Point { int x, y; }
ML99_struct(v(Point), v(int x, y;))

◆ ML99_times

#define ML99_times ( n,
... )
Value:
ML99_call(ML99_times, n, __VA_ARGS__)
#define ML99_times(n,...)
Pastes provided arguments n times.
Definition gen.h:213

Pastes provided arguments n times.

Examples

#include <metalang99/gen.h>
// ~ ~ ~ ~ ~
ML99_times(v(5), v(~))

◆ ML99_typedef

#define ML99_typedef ( ident,
... )
Value:
ML99_call(ML99_typedef, ident, __VA_ARGS__)
#define ML99_typedef(ident,...)
Generates a type definition.
Definition gen.h:129

Generates a type definition.

Examples

#include <metalang99/gen.h>
// typedef struct { int x, y; } Point;
ML99_typedef(v(Point), v(struct { int x, y; }))

◆ ML99_union

#define ML99_union ( ident,
... )
Value:
ML99_call(ML99_union, ident, __VA_ARGS__)
#define ML99_union(ident,...)
The same as ML99_struct but generates a union.
Definition gen.h:162

The same as ML99_struct but generates a union.