Add missing BAD_SYMBOL error

This commit is contained in:
Sage Vaillancourt 2022-10-25 13:23:35 -04:00
parent a145b436c9
commit 9b6b80f204
3 changed files with 17 additions and 7 deletions

View File

@ -122,6 +122,7 @@ static const char* errorText[] = {
"NULL_MAP_ARGS",
"LAMBDA_ARGS_NOT_LIST",
"DID_NOT_FIND_SYMBOL",
"BAD_SYMBOL",
"BAD_TYPE",
"BAD_PARAMS",
"BAD_NUMBER",

View File

@ -22,7 +22,13 @@
#ifdef RELEASE
#define assert(...) do { } while (0)
#else
#define assert(...) do {if (!(__VA_ARGS__)) {eprintf("\nassertion '" # __VA_ARGS__ "' at %s:%d failed!\nBailing!\n", __FILE__, __LINE__); int* X = NULL; unused int Y = *X;}} while (0)
#define assert(...) do { \
if (!(__VA_ARGS__)) { \
eprintf("\nassertion '" # __VA_ARGS__ "' at %s:%d failed!\nBailing!\n", __FILE__, __LINE__); \
int* X = NULL; \
unused int Y = *X; \
}\
} while (0)
#endif
#define MAX_TOK_CNT 2048
@ -94,6 +100,7 @@ enum errorCode {
NULL_MAP_ARGS,
LAMBDA_ARGS_NOT_LIST,
DID_NOT_FIND_SYMBOL,
BAD_SYMBOL,
BAD_TYPE,
BAD_PARAMS,
BAD_NUMBER,

View File

@ -54,15 +54,17 @@ Object listDef(Object* nameList, Object* valueList, struct Environment* env)
* @param env The environment to add the new definition to
* @return The symbol(s) defined
*/
Object def(Object* params, unused int length, struct Environment* env)
Object def(Object* params, int length, struct Environment* env)
{
if (length == 2) {
if (isStringy(params[0])) {
return singleDef(params[0].string, &params[1], env);
}
if (length == 2 && isListy(params[0]) && isListy(params[1])) {
if (isListy(params[0]) && isListy(params[1])) {
return listDef(&params[0], &params[1], env);
}
}
throw(BAD_TYPE, "Poorly constructed (def)");
}