Turns out recursion worked the whole time.
Fixed issue with too-small REPL input buffer...
This commit is contained in:
parent
cb945a1e41
commit
d9c860805f
|
@ -128,15 +128,6 @@ Object evalDefArgs(const Object *arg_forms, struct Environment *env)
|
||||||
|
|
||||||
Object evalIfArgs(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?
|
return eval(arg_forms, env).number?
|
||||||
eval(arg_forms->forward, env) :
|
eval(arg_forms->forward, env) :
|
||||||
eval(arg_forms->forward->forward, env);
|
eval(arg_forms->forward->forward, env);
|
||||||
|
@ -429,12 +420,8 @@ struct Environment defaultEnv() {
|
||||||
struct Environment e;
|
struct Environment e;
|
||||||
e.outer = NULL;
|
e.outer = NULL;
|
||||||
e.strings = calloc(sizeof(char*), MAX_ENV_ELM);
|
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.objects = malloc(sizeof(Object) * MAX_ENV_ELM);
|
||||||
|
e.size = MAX_ENV_ELM;
|
||||||
|
|
||||||
addFunc("+", &add, &e);
|
addFunc("+", &add, &e);
|
||||||
addFunc("-", &sub, &e);
|
addFunc("-", &sub, &e);
|
||||||
|
@ -446,6 +433,7 @@ struct Environment defaultEnv() {
|
||||||
addFunc("len", &len, &e);
|
addFunc("len", &len, &e);
|
||||||
parseEval("(def max (fn (a b) (if (> a b) a b)))", &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 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;
|
return e;
|
||||||
}
|
}
|
||||||
|
@ -476,7 +464,7 @@ Object parseEval(const char *input, struct Environment *env)
|
||||||
#ifdef STANDALONE
|
#ifdef STANDALONE
|
||||||
int repl(struct Environment *env)
|
int repl(struct Environment *env)
|
||||||
{
|
{
|
||||||
char input[100] = "";
|
char input[200] = "";
|
||||||
while(input[0] != 'q') {
|
while(input[0] != 'q') {
|
||||||
printf("pebblisp>> ");
|
printf("pebblisp>> ");
|
||||||
fgets(input, 100, stdin);
|
fgets(input, 100, stdin);
|
||||||
|
|
Loading…
Reference in New Issue