fix: fix some memory errors by doing the proper thing

on expr evaluation
This commit is contained in:
NunoSempere 2023-05-02 20:47:16 -04:00
parent 59b92a6479
commit 6316fe2426
2 changed files with 14 additions and 5 deletions

BIN
mumble

Binary file not shown.

View File

@ -856,12 +856,21 @@ lispval* evaluate_lispval(lispval* l, lispenv* env)
if (VERBOSE) if (VERBOSE)
print_lispval_tree(l, 4); print_lispval_tree(l, 4);
// Ok, do this properly now.
if (VERBOSE)
printfln("Constructing function and operands");
lispval* f = clone_lispval(l->cell[0]);
lispval* operands = lispval_sexpr();
for(int i=1; i<l->count; i++){
lispval_append_child(operands, l->cell[i]);
}
/*
lispval* temp = clone_lispval(l); lispval* temp = clone_lispval(l);
lispval* f = pop_lispval(temp, 0); lispval* f = pop_lispval(temp, 0);
// pop is destructive. // pop is destructive.
lispval* operands = temp; lispval* operands = temp;
if (VERBOSE) */
printfln("Allocated memory");
// lispval* operation = clone_lispval(l->cell[0]); // lispval* operation = clone_lispval(l->cell[0]);
// lispval* operands = lispval_sexpr(); // lispval* operands = lispval_sexpr();
// for (int i = 1; i < l->count; i++) { // for (int i = 1; i < l->count; i++) {
@ -871,17 +880,17 @@ lispval* evaluate_lispval(lispval* l, lispenv* env)
printfln("Applying function to operands"); printfln("Applying function to operands");
// lispval* answer = lispval_num(42); // lispval* answer = lispval_num(42);
lispval* answer = f->func(operands, env); lispval* answer = f->func(operands, env);
if (VERBOSE) if (VERBOSE)
printfln("Applied function to operands"); printfln("Applied function to operands");
if (VERBOSE)
if (VERBOSE)
printfln("Cleaning up"); printfln("Cleaning up");
// builtin_functions(operation->sym, l, env); // builtin_functions(operation->sym, l, env);
delete_lispval(f); delete_lispval(f);
delete_lispval(operands); delete_lispval(operands);
// delete_lispval(temp); // delete_lispval(temp);
if (VERBOSE) if (VERBOSE)
printfln("Returning"); printfln("Cleaned up. Returning");
return answer; return answer;
} }
return l; return l;