From 058a5cfcc227d379a852b4bca2db140fe1fb7ce3 Mon Sep 17 00:00:00 2001 From: Elijah Cohen Date: Sun, 17 Nov 2024 14:47:15 +0000 Subject: [PATCH] plugged a memory leak --- src/builtins.c | 5 +++++ src/test.c | 27 +++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/builtins.c b/src/builtins.c index e79fd1c..3a05b50 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -62,6 +62,7 @@ Sexpr* dispatch_others(Sexpr* b, Sexpr* rest, Sexpr* env) { // also need to return to this for the other types... if((b->value.q->type == CONS) || (b->value.q->type == SYM)) { + sexpr_free(rest); return clone(b); } // i might need to free something here? i'll come back later for it @@ -73,6 +74,10 @@ Sexpr* dispatch_others(Sexpr* b, Sexpr* rest, Sexpr* env) { Sexpr* ret = cons(idk, cons(clone(b), rest)); return ret; } + else if(b->type == CONS) { + sexpr_free(rest); + return b; + } return from_nil(); } diff --git a/src/test.c b/src/test.c index db89c82..8b6611d 100644 --- a/src/test.c +++ b/src/test.c @@ -302,8 +302,9 @@ void eval_tests() { run_eval_test("(cons 1 2)"); run_eval_test("(car (cons 1 2))"); run_eval_test("(cdr (cons 1 2))"); - run_eval_test("(if t (cons 1 2) (cons 2 1))"); - run_eval_test("(if nil (cons 1 2) (cons 2 1))"); + run_eval_test("(nil t 3 4)"); + //run_eval_test("(nil t (cons 1 2) (cons 2 1))"); + //run_eval_test("(if nil (cons 1 2) (cons 2 1))"); run_eval_test("(eq 1 1)"); run_eval_test("(eq 1 2)"); run_eval_test("(eq 1 (quote 1))"); @@ -332,6 +333,9 @@ void eval_tests() { run_eval_test("(nil 4 5)"); run_eval_test("(5 (+ 3) 4)"); + run_eval_test("(if t (cons 1 2) (cons 2 1))"); + + run_eval_test("(Z (B B S (C (eq 0) 1) (B B S * (C B (C - 1)))) 6)"); run_eval_test("(+ 5 (* 5))"); @@ -394,7 +398,26 @@ void test_string_parsing() { printf("string parsing done\n"); } +void isolating_problem() { + //run_eval_test("(if t (cons 1 2) (cons 2 1))"); + //run_eval_test("((cons 4 5) (cons 2 3))"); + run_eval_test("((quote asdf) 45)"); + //run_eval_test("((cons 4 5) 5)"); + //Sexpr* env = init_dict(); + //env = load_env(env); + //Sexpr* asdf = cons(from_uint(54), from_uint(32)); + //Sexpr* result = eval(asdf, env); + //sexpr_free(result); + //asdf = cons(asdf, cons(from_uint(98), from_nil())); + //PRINT("IDK HERE"); + //Sexpr* result = eval(asdf, env); + //sexpr_free(result); + //sexpr_free(env); + //run_eval_test("(cons 4 5 5)"); + //run_eval_test("((((((cons 4 5))))))"); +} void run_tests(){ + //isolating_problem(); //test_string_parsing(); eval_tests(); many_asserts(); -- 2.39.5