plugged a memory leak
authorElijah Cohen <cohen@eli173.com>
Sun, 17 Nov 2024 14:47:15 +0000 (14:47 +0000)
committerElijah Cohen <cohen@eli173.com>
Sun, 17 Nov 2024 14:47:15 +0000 (14:47 +0000)
src/builtins.c
src/test.c

index e79fd1c519f9132430b0d07136b80eb6242e919b..3a05b50ea3f5b158c9eefb520f61966906bc22b2 100644 (file)
@@ -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();      
 }
 
index db89c8287f93230b3590ac999c823a81c8c539f9..8b6611db253ba31148526c2fc4cdbdd60ca93618 100644 (file)
@@ -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();