Rename main() files.

Tweak checkTypes() to expect a closing semicolon.
This commit is contained in:
Sage Vaillancourt 2023-03-03 10:57:04 -05:00
parent 6176e9eb4b
commit c37a12e244
14 changed files with 50 additions and 50 deletions

View File

@ -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)

View File

@ -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 = &params[0].table->table;
struct StrippedObject* fetched = getFromTable(table, params[1].string);

View File

@ -1,4 +0,0 @@
#ifndef PEBBLISP_MAIN_H
#define PEBBLISP_MAIN_H
#endif // PEBBLISP_MAIN_H

View File

@ -1,4 +1,4 @@
#define _GNU_SOURCE
#define _GNU_SOURCE // For segfault handling
#include "pebblisp.h"

4
src/pcmain.h Normal file
View File

@ -0,0 +1,4 @@
#ifndef PC_MAIN_H
#define PC_MAIN_H
#endif

View File

@ -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;
}

View File

@ -1,5 +1,5 @@
#ifndef CALC_H
#define CALC_H
#ifndef PEBBLE_MAIN_H
#define PEBBLE_MAIN_H
#include <pebble.h>
#include "pebblisp.h"

View File

@ -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];

View File

@ -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

View File

@ -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 = &params[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(&params[0]));
}

View File

@ -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);

View File

@ -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*),

View File

@ -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];

View File

@ -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);