diff options
-rw-r--r-- | err.c | 5 | ||||
-rw-r--r-- | eval.c | 2 | ||||
-rw-r--r-- | test.toc | 3 |
3 files changed, 9 insertions, 1 deletions
@@ -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; } @@ -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) { @@ -1,5 +1,6 @@ factorial ::= fn(x: int) int { -x*2 + if x < 2 { 1 } + else { x * factorial(x-1) } }; main ::= fn() { |