summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--err.c5
-rw-r--r--eval.c2
-rw-r--r--test.toc3
3 files changed, 9 insertions, 1 deletions
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() {