diff --git a/src/env.c b/src/env.c index abbe817..f818e40 100644 --- a/src/env.c +++ b/src/env.c @@ -64,8 +64,9 @@ struct Environment envForLambda(const Object *params, const Object *arg_forms, for(int i = 0; i < paramCount; i++) { const char *newObjName = itemAt(params, i)->string; // Eval the `march` list - const Object newEnvObj = eval(march, outer); + Object newEnvObj = eval(march, outer); addToEnv(&env, newObjName, newEnvObj); // Could use eval_forms? + cleanObject(&newEnvObj); march = march->forward; } diff --git a/src/pebblisp.c b/src/pebblisp.c index 55cd717..5a55dcd 100644 --- a/src/pebblisp.c +++ b/src/pebblisp.c @@ -45,9 +45,12 @@ Object evalDefArgs(const Object *symbol, const Object *value, struct Environment Object evalIfArgs(const Object *argForms, struct Environment *env) { - return eval(argForms, env).number ? + Object condition = eval(argForms, env); + Object result = condition.number ? eval(argForms->forward, env) : eval(argForms->forward->forward, env); + cleanObject(&condition); + return result; } Object evalLambdaArgs(const Object *argForms) @@ -242,7 +245,7 @@ Object evalList(const Object *obj, struct Environment *env) if(listLength(obj->list) == 0) { return cloneObject(*obj); } - return startList(cloneObject(eval(obj->list, env))); + return startList(eval(obj->list, env)); } Object *first_form = obj->list; @@ -735,7 +738,8 @@ Object parseEval(const char *input, struct Environment *env) cleanObject(&obj); Object parsed = parse(tok).obj; if(parsed.type == TYPE_ERROR) { - return parsed; + obj = parsed; + break; } if(tok[i].text[0] == ')') { tok = &tok[i + 1];