From e87a5b5f273923c216a88ed2166ae61a0000bd52 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Sat, 8 Feb 2020 14:58:58 -0500 Subject: recursion works but there are leaks --- err.c | 5 +++++ eval.c | 2 ++ test.toc | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/err.c b/err.c index a40499e..3c2d5d5 100644 --- a/err.c +++ b/err.c @@ -195,6 +195,7 @@ static void warn_print_( #define warn_print warn_print_ #endif + static void *err_malloc(size_t size) { if (size == 0) return NULL; void *ret = malloc(size); @@ -202,6 +203,10 @@ static void *err_malloc(size_t size) { fprintf(stderr, "Error: Out of memory.\n"); abort(); } + +#ifdef MALLOC_FILL + memset(ret, MALLOC_FILL, size); +#endif return ret; } diff --git a/eval.c b/eval.c index 8a0c944..9d73cb1 100644 --- a/eval.c +++ b/eval.c @@ -1518,6 +1518,7 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) { arr_foreach(params, Declaration, p) { int idx = 0; Value *pval = decl_add_val(p); + --arr_hdr(p->val_stack)->len; bool is_tuple = p->type.kind == TYPE_TUPLE; arr_foreach(p->idents, Identifier, i) { Value arg_val; @@ -1529,6 +1530,7 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) { ++arg; ++idx; } + ++arr_hdr(p->val_stack)->len; } arr_foreach(fn->ret_decls, Declaration, d) { diff --git a/test.toc b/test.toc index b676fbe..e2263b8 100644 --- a/test.toc +++ b/test.toc @@ -1,5 +1,6 @@ factorial ::= fn(x: int) int { -x*2 + if x < 2 { 1 } + else { x * factorial(x-1) } }; main ::= fn() { -- cgit v1.2.3