All known memory leaks handled!
Watch the commented `if` -127,7 +137,10 @ Object eval for weird behavior
This commit is contained in:
parent
f488e29c54
commit
efb151d0ef
|
@ -3,7 +3,7 @@
|
|||
|
||||
#define MAX_TOK_LEN 10 // 11
|
||||
#define MAX_TOK_CNT 128 // 128
|
||||
#define MAX_ENV_ELM 15 // 50
|
||||
#define MAX_ENV_ELM 25 // 50
|
||||
|
||||
#define FOR_POINTER_IN_LIST(_list) \
|
||||
for(Object *_element = _list->list; \
|
||||
|
|
|
@ -50,12 +50,21 @@ Object evalMapArgs(const Object *arg_forms, struct Environment *env)
|
|||
FOR_POINTER_IN_LIST(inputList) {
|
||||
// Create a new list for each element,
|
||||
// since lambda evaluation looks for a list
|
||||
const Object tempList = startList(*POINTER);
|
||||
Object tempList;
|
||||
if(POINTER->type == TYPE_LIST) {
|
||||
Object tl = listObject();
|
||||
copyList(&tl, POINTER);
|
||||
tempList = startList(tl);
|
||||
} else {
|
||||
tempList = startList(*POINTER);
|
||||
}
|
||||
|
||||
struct Environment newEnv =
|
||||
envForLambda(&lambda.lambda->params, &tempList, env);
|
||||
// Add the lambda evaluation to the list
|
||||
nf_addToList(&list, eval(&lambda.lambda->body, &newEnv));
|
||||
deleteEnv(&newEnv);
|
||||
cleanObject(&tempList);
|
||||
}
|
||||
|
||||
return list;
|
||||
|
@ -93,8 +102,9 @@ Object eval(const Object *obj, struct Environment *env)
|
|||
case TYPE_NUMBER:
|
||||
case TYPE_BOOL:
|
||||
return *obj; // Return as is
|
||||
|
||||
case TYPE_STRING:
|
||||
return copyString(*obj); // Return as is
|
||||
return copyString(*obj);
|
||||
|
||||
case TYPE_SYMBOL:
|
||||
return fetchFromEnvironment(obj->name, env);
|
||||
|
@ -127,7 +137,10 @@ Object eval(const Object *obj, struct Environment *env)
|
|||
|
||||
Object func_eval = rest[0];
|
||||
for(int i = 1; i < length; i++) {
|
||||
Object toClean = func_eval;
|
||||
func_eval = first_eval.func(func_eval, rest[i], env);
|
||||
//if(i != length - 1)
|
||||
cleanObject(&toClean);
|
||||
cleanObject(&rest[i]);
|
||||
}
|
||||
|
||||
|
@ -364,7 +377,7 @@ Object parseEval(const char *input, struct Environment *env)
|
|||
|
||||
int i = 0;
|
||||
int parens = 0;
|
||||
Object obj;
|
||||
Object obj = numberObject(0);
|
||||
struct Slice *tok = tokens;
|
||||
if(tok[i].text[0] != '(') {
|
||||
Object parsed = parse(tok).obj;
|
||||
|
@ -377,6 +390,7 @@ Object parseEval(const char *input, struct Environment *env)
|
|||
} else if(tok[i].text[0] == ')') {
|
||||
parens--;
|
||||
if(parens == 0) {
|
||||
cleanObject(&obj);
|
||||
Object parsed = parse(tok).obj;
|
||||
tok = &tok[i + 1];
|
||||
i = -1;
|
||||
|
@ -418,6 +432,6 @@ int main(int argc, const char* argv[])
|
|||
} else {
|
||||
repl(&env);
|
||||
}
|
||||
// deleteEnv(&env);
|
||||
deleteEnv(&env);
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue