From d9c860805f581871baddb65e2c814d27c1549bf7 Mon Sep 17 00:00:00 2001 From: = <=> Date: Sun, 10 May 2020 03:32:26 +0100 Subject: [PATCH] Turns out recursion worked the whole time. Fixed issue with too-small REPL input buffer... --- src/pebblisp.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/pebblisp.c b/src/pebblisp.c index c87852a..e875d25 100644 --- a/src/pebblisp.c +++ b/src/pebblisp.c @@ -128,15 +128,6 @@ Object evalDefArgs(const Object *arg_forms, struct Environment *env) Object evalIfArgs(const Object *arg_forms, struct Environment *env) { - printd("eval(arg_forms):\n "); - Object o = eval(arg_forms, env); - debugObj(&o); - printd("eval(arg_forms->forward):\n "); - o = eval(arg_forms->forward, env); - debugObj(&o); - printd("eval(arg_forms->forward->forward):\n "); - o = eval(arg_forms->forward->forward, env); - debugObj(&o); return eval(arg_forms, env).number? eval(arg_forms->forward, env) : eval(arg_forms->forward->forward, env); @@ -429,12 +420,8 @@ struct Environment defaultEnv() { struct Environment e; e.outer = NULL; e.strings = calloc(sizeof(char*), MAX_ENV_ELM); - e.size = MAX_ENV_ELM; - // for(int i = 0; i < MAX_ENV_ELM; i++) { - // e.strings[i] = NULL; - // } - e.objects = malloc(sizeof(Object) * MAX_ENV_ELM); + e.size = MAX_ENV_ELM; addFunc("+", &add, &e); addFunc("-", &sub, &e); @@ -446,6 +433,7 @@ struct Environment defaultEnv() { addFunc("len", &len, &e); parseEval("(def max (fn (a b) (if (> a b) a b)))", &e); parseEval("(def min (fn (a b) (if (< a b) a b)))", &e); + parseEval("(def ad (fn (a) (if (> a 10) a (ad (* 10 a) ))))", &e); return e; } @@ -476,14 +464,14 @@ Object parseEval(const char *input, struct Environment *env) #ifdef STANDALONE int repl(struct Environment *env) { - char input[100] = ""; + char input[200] = ""; while(input[0] != 'q') { printf("pebblisp>> "); fgets(input, 100, stdin); Object obj = parseEval(input, env); // printAndClean(&obj); printObj(&obj); - //printEnv(env); + // printEnv(env); } }