mumble

A Lisp written in C, following the *Build Your Own Lisp* book
Log | Files | Refs | README

commit 6316fe24263f219105959f2b4dc8caf64069784f
parent 59b92a64790e347e485ca1cb41088af820378efb
Author: NunoSempere <nuno.sempere@protonmail.com>
Date:   Tue,  2 May 2023 20:47:16 -0400

fix: fix some memory errors by doing the proper thing

on expr evaluation

Diffstat:
Mmumble | 0
Msrc/mumble.c | 19++++++++++++++-----
2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/mumble b/mumble Binary files differ. diff --git a/src/mumble.c b/src/mumble.c @@ -856,12 +856,21 @@ lispval* evaluate_lispval(lispval* l, lispenv* env) if (VERBOSE) 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* f = pop_lispval(temp, 0); // pop is destructive. lispval* operands = temp; - if (VERBOSE) - printfln("Allocated memory"); + */ // lispval* operation = clone_lispval(l->cell[0]); // lispval* operands = lispval_sexpr(); // for (int i = 1; i < l->count; i++) { @@ -871,17 +880,17 @@ lispval* evaluate_lispval(lispval* l, lispenv* env) printfln("Applying function to operands"); // lispval* answer = lispval_num(42); lispval* answer = f->func(operands, env); - if (VERBOSE) printfln("Applied function to operands"); - if (VERBOSE) + + if (VERBOSE) printfln("Cleaning up"); // builtin_functions(operation->sym, l, env); delete_lispval(f); delete_lispval(operands); // delete_lispval(temp); if (VERBOSE) - printfln("Returning"); + printfln("Cleaned up. Returning"); return answer; } return l;