diff --git a/Makefile b/Makefile deleted file mode 100644 index 917b050..0000000 --- a/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -all: - pebble build && sudo cp build/*.pbw /media/sf_New_Folder diff --git a/src/object.c b/src/object.c index ef1c076..5a7c226 100644 --- a/src/object.c +++ b/src/object.c @@ -3,6 +3,12 @@ #include #include +#ifdef DEBUG +#define printd(...) printf(__VA_ARGS__) +#else +#define printd(...) stringObj(NULL, NULL) +#endif + #ifndef STANDALONE #define printf(...) stringObj(NULL, NULL) #endif @@ -177,61 +183,75 @@ void debugObj(const Object *obj) return; } -// Prints the given object -void printObj(const Object *obj) +void _printList(const Object *list, int newline); +void _printObj(const Object *obj, int newline) { for(int i = 0; i < depth; i++) - printf(" "); + printd(" "); depth++; if(obj->type == TYPE_NUMBER) { - printf("TYPE_NUMBER"); + printd("TYPE_NUMBER"); } else if(obj->type == TYPE_BOOL) { - printf("TYPE_BOOL"); + printd("TYPE_BOOL"); } else if(obj->type == TYPE_LIST) { - printf("TYPE_LIST\n"); - printList(obj); + printd("TYPE_LIST\n"); + _printList(obj, newline); depth--; return; } else if(obj->type == TYPE_FUNC) { - printf("TYPE_FUNC"); + printd("TYPE_FUNC"); } else if(obj->type == TYPE_SYMBOL) { - printf("TYPE_SYMBOL"); + printd("TYPE_SYMBOL"); } else if(obj->type == TYPE_LAMBDA) { - printf("TYPE_LAMBDA Params:\n"); + printd("TYPE_LAMBDA Params:\n"); depth++; printObj(&obj->lambda->params); for(int i = 1; i < depth; i++) printf(" "); - printf("Lambda Body: \n"); + printd("Lambda Body: \n"); printObj(&obj->lambda->body); } else if(obj->type == TYPE_ERROR) { - printf("TYPE_ERROR: "); + printd("TYPE_ERROR: "); } else { - printf("TYPE_OTHER (as int)"); + printd("TYPE_OTHER (as int)"); } depth--; char temp[20] = ""; stringObj(temp, obj); - printf(": %s\n", temp); + if(newline) + printf("%s\n", temp); + else + printf("%s", temp); printErr(obj); } +// Prints the given object +void printObj(const Object *obj) +{ + _printObj(obj, 1); +} + +void _printList(const Object *list, int newline) +{ + printf("("); + const Object *tail = list->list; + while(tail != NULL) { + printf(" "); + depth++; + _printObj(tail, 0); + depth--; + tail = tail->forward; + } + printf(" )"); + + if(newline) + printf("\n"); +} + void printList(const Object *list) { - const Object *tail = list->list; - if(tail == NULL) { - for(int i = 0; i < depth; i++) - printf(" "); - printf("EMPTY LIST\n"); - return; - } - while(tail != NULL) { - depth++; - printObj(tail); - depth--; - tail = tail->forward; - } + _printList(list, 1); } void cleanObject(Object *target) diff --git a/src/pebblisp.c b/src/pebblisp.c index ed619c7..051f64c 100644 --- a/src/pebblisp.c +++ b/src/pebblisp.c @@ -126,6 +126,11 @@ Object evalLambdaArgs(const Object *arg_forms) return constructLambda(arg_forms, arg_forms->forward); } +Object evalMapArgs(const Object *arg_forms) +{ + return listObject(); +} + struct Environment envForLambda(const Object *params, const Object *arg_forms, struct Environment *outer) { @@ -169,6 +174,8 @@ Object evalBuiltIns(const Object *first, const Object *rest, return evalIfArgs(rest, env); } else if(strcmp(first->name, "fn") == 0) { return evalLambdaArgs(rest); + } else if(strcmp(first->name, "mp") == 0) { + return evalMapArgs(rest); } return errorObject(BUILT_IN_NOT_FOUND); @@ -232,7 +239,7 @@ Object eval(const Object *obj, struct Environment *env) return eval(&first_eval.lambda->body, &newEnv); } else { - return errorObject(TYPE_LIST_NOT_CAUGHT); + return *obj; } } case TYPE_LAMBDA: