Combine fn macros.
Toying with storing fn types in the code.
This commit is contained in:
parent
62e430af69
commit
581dfed359
|
@ -10,17 +10,21 @@
|
|||
|
||||
#define array_length(_array) (sizeof(_array) / sizeof((_array)[0]))
|
||||
|
||||
#define fn(_name, _docs, ...) static const char * const _name ## Doc = _docs; \
|
||||
#define UNPACK(...) __VA_ARGS__
|
||||
|
||||
#define fn(_name, _docs, ...) \
|
||||
static const char * const _name ## Doc = _docs; \
|
||||
static const char * const _name ## Tests[] = {__VA_ARGS__}; \
|
||||
static_assert(array_length(_name ## Tests) % 2 == 0, "Array of test strings must have exactly one expected result for each test."); \
|
||||
Object _name(Object* params, int length, struct Environment* env)
|
||||
|
||||
#define fnn(_name, _symbol, _docs, ...)\
|
||||
static const char * const _name ## Doc = _docs;\
|
||||
static const char * const _name ## Symbol = _symbol;\
|
||||
static const char * const _name ## Tests[] = {__VA_ARGS__}; \
|
||||
static_assert(array_length(_name ## Tests) % 2 == 0, "Array of test strings must have exactly one expected result for each test."); \
|
||||
Object _name(Object* params, int length, struct Environment* env)
|
||||
#define tfn(_name, _type, _docs, ...) \
|
||||
static const Type _name ## Type[] = UNPACK _type; \
|
||||
fn(_name, _docs, __VA_ARGS__)
|
||||
|
||||
#define fnn(_name, _symbol, _docs, ...) \
|
||||
static const char * const _name ## Symbol = _symbol; \
|
||||
fn(_name, _docs, __VA_ARGS__)
|
||||
|
||||
struct Slice {
|
||||
const char* text;
|
||||
|
|
12
src/plfunc.h
12
src/plfunc.h
|
@ -52,12 +52,12 @@ fn(prepend,
|
|||
"(pre (2 3) 1)", "( 1 2 3 )",
|
||||
);
|
||||
|
||||
/// LIST => NUMBER
|
||||
fn(len,
|
||||
"Returns the length of the given list, or a NOT_A_LIST error if the expression is not a list.",
|
||||
"(len (2 3))", "2",
|
||||
"(len ())", "0",
|
||||
"(len \"string\")", "NOT_A_LIST",
|
||||
tfn(len,
|
||||
({ TYPE_LIST, TYPE_NUMBER }),
|
||||
"Returns the length of the given list, or a NOT_A_LIST error if the expression is not a list.",
|
||||
"(len (2 3))", "2",
|
||||
"(len ())", "0",
|
||||
"(len \"string\")", "NOT_A_LIST",
|
||||
);
|
||||
|
||||
/// LIST, FUNCY, ANY => ANY
|
||||
|
|
Loading…
Reference in New Issue