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", "NULL_MAP_ARGS",
"LAMBDA_ARGS_NOT_LIST", "LAMBDA_ARGS_NOT_LIST",
"DID_NOT_FIND_SYMBOL", "DID_NOT_FIND_SYMBOL",
"BAD_SYMBOL",
"BAD_TYPE", "BAD_TYPE",
"BAD_PARAMS", "BAD_PARAMS",
"BAD_NUMBER", "BAD_NUMBER",

View File

@ -22,7 +22,13 @@
#ifdef RELEASE #ifdef RELEASE
#define assert(...) do { } while (0) #define assert(...) do { } while (0)
#else #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 #endif
#define MAX_TOK_CNT 2048 #define MAX_TOK_CNT 2048
@ -94,6 +100,7 @@ enum errorCode {
NULL_MAP_ARGS, NULL_MAP_ARGS,
LAMBDA_ARGS_NOT_LIST, LAMBDA_ARGS_NOT_LIST,
DID_NOT_FIND_SYMBOL, DID_NOT_FIND_SYMBOL,
BAD_SYMBOL,
BAD_TYPE, BAD_TYPE,
BAD_PARAMS, BAD_PARAMS,
BAD_NUMBER, 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 * @param env The environment to add the new definition to
* @return The symbol(s) defined * @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])) { if (isStringy(params[0])) {
return singleDef(params[0].string, &params[1], env); 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); return listDef(&params[0], &params[1], env);
} }
}
throw(BAD_TYPE, "Poorly constructed (def)"); throw(BAD_TYPE, "Poorly constructed (def)");
} }