Combine fn macros.

Toying with storing fn types in the code.
This commit is contained in:
Sage Vaillancourt 2022-03-24 23:58:54 -04:00
parent 62e430af69
commit 581dfed359
2 changed files with 17 additions and 13 deletions

View File

@ -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 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 ## 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)
fn(_name, _docs, __VA_ARGS__)
struct Slice {
const char* text;

View File

@ -52,8 +52,8 @@ fn(prepend,
"(pre (2 3) 1)", "( 1 2 3 )",
);
/// LIST => NUMBER
fn(len,
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",