1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-20 10:07:45 +03:00
mal/cpp/Validation.cpp
Stephen Thirlwall 179e8eafe4 c++11: step 2
Note that the optional tests for step 1 now fail because I no longer create a
hash directly in the reader, rather handle this as a reader macro:

    { LIST } -> ( hash-map LIST )

This way, once the constructor has built the hash-map, the hash is now evaluated,
and its evaluation procedure is a no-op.

I'd like to do the same with vectors, but this isn't so easy, as we use vectors
as parameter lists in fn* later on.

ie. we'd have this situation, which is incorrect (and I don't see an obvious workaround)

    (fn* [params] body) -> (fn* (vector params) body)
2015-03-27 20:44:42 +11:00

34 lines
853 B
C++

#include "Validation.h"
int checkArgsIs(const char* name, int expected, int got)
{
ASSERT(got == expected,
"\"%s\" expects %d arg%s, %d supplied",
name, expected, PLURAL(expected), got);
return got;
}
int checkArgsBetween(const char* name, int min, int max, int got)
{
ASSERT((got >= min) && (got <= max),
"\"%s\" expects between %d and %d arg%s, %d supplied",
name, min, max, PLURAL(max), got);
return got;
}
int checkArgsAtLeast(const char* name, int min, int got)
{
ASSERT(got >= min,
"\"%s\" expects at least %d arg%s, %d supplied",
name, min, PLURAL(min), got);
return got;
}
int checkArgsEven(const char* name, int got)
{
ASSERT(got % 2 == 0,
"\"%s\" expects an even number of args, %d supplied",
name, got);
return got;
}