From c37a12e2442ab6e39dcfcc1856137d53775c03b6 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Fri, 3 Mar 2023 10:57:04 -0500 Subject: [PATCH] Rename main() files. Tweak checkTypes() to expect a closing semicolon. --- src/Makefile | 2 +- src/hash.c | 4 ++-- src/main.h | 4 ---- src/{main.c => pcmain.c} | 2 +- src/pcmain.h | 4 ++++ src/{calc.c => pebblemain.c} | 22 +++++++++++----------- src/{calc.h => pebblemain.h} | 4 ++-- src/pebblisp.c | 2 +- src/pebblisp.h | 4 ++-- src/plfunc/general.c | 26 +++++++++++++------------- src/plfunc/pc.c | 10 +++++----- src/plfunc/pebbleobject.c | 2 +- src/plfunc/plstring.c | 12 ++++++------ src/plfunc/threads.c | 2 +- 14 files changed, 50 insertions(+), 50 deletions(-) delete mode 100644 src/main.h rename src/{main.c => pcmain.c} (99%) create mode 100644 src/pcmain.h rename src/{calc.c => pebblemain.c} (96%) rename src/{calc.h => pebblemain.h} (78%) diff --git a/src/Makefile b/src/Makefile index e4834c6..5d83165 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,6 +1,6 @@ exe = pl -base_files = main.c pebblisp.c tokens.c object.c env.c hash.c +base_files = pcmain.c pebblisp.c tokens.c object.c env.c hash.c func_files = plfunc/web.c plfunc/general.c plfunc/threads.c plfunc/plstring.c plfunc/pc.c files:= $(base_files) $(func_files) diff --git a/src/hash.c b/src/hash.c index 1dd5ba8..c54ae64 100644 --- a/src/hash.c +++ b/src/hash.c @@ -185,7 +185,7 @@ Object buildHashTable(Object* params, int length, struct Environment* env) Object addToHashTable(Object* params, int length, struct Environment* env) { - checkTypes(addToHashTable) + checkTypes(addToHashTable); Object name = params[1]; Object add = params[2]; @@ -197,7 +197,7 @@ Object addToHashTable(Object* params, int length, struct Environment* env) Object getFromHashTable(Object* params, int length, struct Environment* env) { - checkTypes(getFromHashTable) + checkTypes(getFromHashTable); struct ObjectTable* table = ¶ms[0].table->table; struct StrippedObject* fetched = getFromTable(table, params[1].string); diff --git a/src/main.h b/src/main.h deleted file mode 100644 index 6b296b9..0000000 --- a/src/main.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef PEBBLISP_MAIN_H -#define PEBBLISP_MAIN_H - -#endif // PEBBLISP_MAIN_H diff --git a/src/main.c b/src/pcmain.c similarity index 99% rename from src/main.c rename to src/pcmain.c index 30fbf36..cbd9312 100644 --- a/src/main.c +++ b/src/pcmain.c @@ -1,4 +1,4 @@ -#define _GNU_SOURCE +#define _GNU_SOURCE // For segfault handling #include "pebblisp.h" diff --git a/src/pcmain.h b/src/pcmain.h new file mode 100644 index 0000000..5ea9cab --- /dev/null +++ b/src/pcmain.h @@ -0,0 +1,4 @@ +#ifndef PC_MAIN_H +#define PC_MAIN_H + +#endif diff --git a/src/calc.c b/src/pebblemain.c similarity index 96% rename from src/calc.c rename to src/pebblemain.c index fb6a3db..c51cc26 100644 --- a/src/calc.c +++ b/src/pebblemain.c @@ -4,7 +4,7 @@ #define HASHLESS_ENV #include "object.h" #include "plfunc/pebbleobject.h" -#include "calc.h" +#include "pebblemain.h" #define RESULT_LENGTH 128 @@ -527,7 +527,7 @@ static void inbox_received_callback(DictionaryIterator* iter, void* context) } /** General **/ -void af(const char* name, Object (* func)(Object*, int, struct Environment*), struct Environment* env) +void addFunction(const char* name, Object (* func)(Object*, int, struct Environment*), struct Environment* env) { Object o = newObject(TYPE_FUNC); o.func = func; @@ -538,15 +538,15 @@ static struct Environment pebbleEnv() { struct Environment e = defaultEnv(); setGlobal(&e); - af("window", &add_window, &e); - af("sc", &run_script, &e); - af("cw", &createWindow, &e); - af("pw", &pushWindow, &e); - af("rw", &deleteWindow, &e); - af("atl", &addTextLayer, &e); - af("utl", &updateTextLayer, &e); - af("vibe", &doVibe, &e); - af("sub", &subscribe, &e); + addFunction("window", &add_window, &e); + addFunction("sc", &run_script, &e); + addFunction("cw", &createWindow, &e); + addFunction("pw", &pushWindow, &e); + addFunction("rw", &deleteWindow, &e); + addFunction("atl", &addTextLayer, &e); + addFunction("utl", &updateTextLayer, &e); + addFunction("vibe", &doVibe, &e); + addFunction("sub", &subscribe, &e); return e; } diff --git a/src/calc.h b/src/pebblemain.h similarity index 78% rename from src/calc.h rename to src/pebblemain.h index 3e39935..777a1a0 100644 --- a/src/calc.h +++ b/src/pebblemain.h @@ -1,5 +1,5 @@ -#ifndef CALC_H -#define CALC_H +#ifndef PEBBLE_MAIN_H +#define PEBBLE_MAIN_H #include #include "pebblisp.h" diff --git a/src/pebblisp.c b/src/pebblisp.c index 267900c..ff176e7 100644 --- a/src/pebblisp.c +++ b/src/pebblisp.c @@ -363,7 +363,7 @@ Object eval(const Object* obj, struct Environment* env) Object structAccess(Object* params, unused int length, unused struct Environment* env) { - checkTypes(structAccess) + checkTypes(structAccess); Object structo = params[0]; Object field = params[1]; diff --git a/src/pebblisp.h b/src/pebblisp.h index 8169afc..c831940 100644 --- a/src/pebblisp.h +++ b/src/pebblisp.h @@ -48,13 +48,13 @@ Object typeCheck(const char* funcName, Object* params, int length, #define checkTypes(FUNC) int FAILED; Object ERROR = typeCheck(FUNC ## Symbol, params, length, FUNC ## TypeChecks, array_length(FUNC ## TypeChecks), &FAILED); \ if (FAILED) { \ return ERROR; \ -} +} else do { } while (0) #define verifyTypes(FUNC, TYPE_CHECKS) int FAILED; Object ERROR = typeCheck(FUNC ## Symbol, params, length, TYPE_CHECKS, length, &FAILED); \ if (FAILED) { \ return ERROR; \ } #else -#define checkTypes(FUNC) ; +#define checkTypes(FUNC) do { } while (0) #endif #ifdef STANDALONE diff --git a/src/plfunc/general.c b/src/plfunc/general.c index 1c0c1b9..cf8b004 100644 --- a/src/plfunc/general.c +++ b/src/plfunc/general.c @@ -6,7 +6,7 @@ Object reduce(Object* params, unused int length, struct Environment* env) { - checkTypes(reduce) + checkTypes(reduce); Object list = params[0]; Object func = params[1]; Object total = params[2]; @@ -33,7 +33,7 @@ Object reduce(Object* params, unused int length, struct Environment* env) Object filter(Object* params, unused int length, struct Environment* env) { - checkTypes(filter) + checkTypes(filter); Object condition = params[0]; Object list = params[1]; @@ -54,7 +54,7 @@ Object filter(Object* params, unused int length, struct Environment* env) Object append(Object* params, unused int length, unused struct Environment* env) { - checkTypes(append) + checkTypes(append); Object list = params[0]; Object newElement = params[1]; @@ -65,7 +65,7 @@ Object append(Object* params, unused int length, unused struct Environment* env) Object prepend(Object* params, unused int length, unused struct Environment* env) { - checkTypes(prepend) + checkTypes(prepend); Object list = cloneObject(params[0]); Object newElement = cloneObject(params[1]); @@ -77,7 +77,7 @@ Object prepend(Object* params, unused int length, unused struct Environment* env Object at(Object* params, unused int length, unused struct Environment* env) { - checkTypes(at) + checkTypes(at); Object index = params[0]; Object list = params[1]; @@ -93,7 +93,7 @@ Object at(Object* params, unused int length, unused struct Environment* env) Object rest(Object* params, unused int length, unused struct Environment* env) { - checkTypes(rest) + checkTypes(rest); Object list = params[0]; Object BuildListNamed(ret); @@ -108,7 +108,7 @@ Object rest(Object* params, unused int length, unused struct Environment* env) Object reverse(Object* params, unused int length, unused struct Environment* ignore2) { - checkTypes(reverse) + checkTypes(reverse); const Object* list = ¶ms[0]; Object rev = listObject(); @@ -128,7 +128,7 @@ Object reverse(Object* params, unused int length, unused struct Environment* ign Object isNum(Object* params, unused int length, unused struct Environment* env) { - checkTypes(isNum) + checkTypes(isNum); Object test = params[0]; return boolObject(test.type == TYPE_NUMBER); @@ -136,7 +136,7 @@ Object isNum(Object* params, unused int length, unused struct Environment* env) Object isList(Object* params, unused int length, unused struct Environment* env) { - checkTypes(isList) + checkTypes(isList); Object test = params[0]; return boolObject(test.type == TYPE_LIST); @@ -144,7 +144,7 @@ Object isList(Object* params, unused int length, unused struct Environment* env) Object isString(Object* params, unused int length, unused struct Environment* env) { - checkTypes(isString) + checkTypes(isString); Object test = params[0]; return boolObject(test.type == TYPE_STRING); @@ -152,7 +152,7 @@ Object isString(Object* params, unused int length, unused struct Environment* en Object isErr(Object* params, unused int length, unused struct Environment* env) { - checkTypes(isErr) + checkTypes(isErr); Object test = params[0]; return boolObject(test.type == TYPE_ERROR); @@ -192,7 +192,7 @@ Object parseEvalO(Object* params, unused int length, struct Environment* env) Object catObjects(Object* params, int length, unused struct Environment* env) { - checkTypes(catObjects) + checkTypes(catObjects); if (length == 0) { return stringFromSlice("", 0); @@ -217,7 +217,7 @@ Object catObjects(Object* params, int length, unused struct Environment* env) Object len(Object* params, unused int length, unused struct Environment* env) { - checkTypes(len) + checkTypes(len); return numberObject(listLength(¶ms[0])); } diff --git a/src/plfunc/pc.c b/src/plfunc/pc.c index 3e3f70d..64d3181 100644 --- a/src/plfunc/pc.c +++ b/src/plfunc/pc.c @@ -14,7 +14,7 @@ Object print(Object* params, int length, unused struct Environment* env) Object numToChar(Object* params, unused int length, unused struct Environment* env) { - checkTypes(numToChar) + checkTypes(numToChar); Object c = params[0]; if (c.number > 255 || c.number < 0) { @@ -39,7 +39,7 @@ Object takeInput(Object* params, int length, unused struct Environment* env) Object cd(Object* params, unused int length, unused struct Environment* env) { - checkTypes(cd) + checkTypes(cd); return numberObject(chdir(params[0].string)); } @@ -52,7 +52,7 @@ Object cwd(unused Object* params, unused int length, unused struct Environment* Object systemCall(Object* params, unused int length, unused struct Environment* env) { - checkTypes(systemCall) + checkTypes(systemCall); Object process = params[0]; if (isStringy(process)) { @@ -63,7 +63,7 @@ Object systemCall(Object* params, unused int length, unused struct Environment* Object readFileToObject(Object* params, unused int length, unused struct Environment* env) { - checkTypes(readFileToObject) + checkTypes(readFileToObject); Object filename = params[0]; FILE* file = fopen(filename.string, "r"); @@ -79,7 +79,7 @@ Object readFileToObject(Object* params, unused int length, unused struct Environ Object getEnvVar(Object* params, unused int length, unused struct Environment* env) { - checkTypes(getEnvVar) + checkTypes(getEnvVar); const char* envVar = getenv(params[0].string); if (envVar) { return nullTerminated(envVar); diff --git a/src/plfunc/pebbleobject.c b/src/plfunc/pebbleobject.c index a8776b6..7309ca4 100644 --- a/src/plfunc/pebbleobject.c +++ b/src/plfunc/pebbleobject.c @@ -1,6 +1,6 @@ #include "pebbleobject.h" -#include "../calc.h" +#include "../pebblemain.h" #include "../object.h" Object pebbleOther(enum PebbleType type, void* data, void (* cleanup)(Object*), diff --git a/src/plfunc/plstring.c b/src/plfunc/plstring.c index 8fc688c..2328bc1 100644 --- a/src/plfunc/plstring.c +++ b/src/plfunc/plstring.c @@ -4,7 +4,7 @@ Object charVal(Object* params, unused int length, unused struct Environment* env) { - checkTypes(charVal) + checkTypes(charVal); Object test = params[0]; return numberObject(test.string[0]); @@ -12,7 +12,7 @@ Object charVal(Object* params, unused int length, unused struct Environment* env Object chars(Object* params, unused int length, unused struct Environment* env) { - checkTypes(chars) + checkTypes(chars); char c[2]; c[1] = '\0'; int i = 0; @@ -62,19 +62,19 @@ int stringComp(const char* string, const char* pattern) Object matches(Object* params, int length, unused struct Environment* env) { - checkTypes(matches) + checkTypes(matches); return boolObject(stringComp(params[0].string, params[1].string)); } Object slen(Object* params, int length, unused struct Environment* env) { - checkTypes(slen) + checkTypes(slen); return numberObject(strlen(params[0].string)); } Object substring(Object* params, int length, unused struct Environment* env) { - checkTypes(substring) + checkTypes(substring); Object start = params[0]; // First char to include Object end = params[1]; // First char to exclude Object string = params[2]; @@ -99,7 +99,7 @@ Object substring(Object* params, int length, unused struct Environment* env) Object charAt(Object* params, unused int length, unused struct Environment* env) { - checkTypes(charAt) + checkTypes(charAt); Object string = params[0]; Object at = params[1]; diff --git a/src/plfunc/threads.c b/src/plfunc/threads.c index 3c84f00..f3568e1 100644 --- a/src/plfunc/threads.c +++ b/src/plfunc/threads.c @@ -40,7 +40,7 @@ void cleanPromise(struct Promise* promise) Object await(Object* params, int length, struct Environment* env) { - checkTypes(await) + checkTypes(await); struct Promise* promise = params[0].promise; if (!promise->done) { // TODO: Does `done` need a mutex or other lock? pthread_join(promise->thread, NULL);