diff options
-rw-r--r-- | eval.c | 12 | ||||
-rw-r--r-- | main.c | 1 | ||||
-rw-r--r-- | test.toc | 2 | ||||
-rw-r--r-- | tests/arr/arr.toc | 16 |
4 files changed, 19 insertions, 12 deletions
@@ -22,8 +22,10 @@ static void evalr_create(Evaluator *ev, Typer *tr, Allocator *allocr) { static void evalr_free(Evaluator *ev) { typedef void *VoidPtr; - arr_foreach(ev->to_free, VoidPtr, f) + arr_foreach(ev->to_free, VoidPtr, f) { + printf("Freeing %p\n",*f); free(*f); + } arr_clear(&ev->to_free); } @@ -363,10 +365,9 @@ static void *val_ptr_to_free(Value *v, Type *t) { case TYPE_PTR: case TYPE_SLICE: case TYPE_VOID: + case TYPE_TYPE: case TYPE_UNKNOWN: return NULL; - case TYPE_TYPE: - return v->type->was_expr; case TYPE_ARR: return v->arr; case TYPE_TUPLE: @@ -1337,11 +1338,6 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) { int index = ident_index_in_decl(e->ident, d); assert(index != -1); *v = *decl_val_at_index(d, index); - if (e->type.kind == TYPE_TYPE) { - /* make sure was_expr is set */ - /* NOTE: this will be freed (see val_ptr_to_free) */ - v->type->was_expr = err_malloc(sizeof *v->type->was_expr); - } } else { char *s = ident_to_str(e->ident); @@ -6,7 +6,6 @@ /* TODO: -make sure you can't have a tuple parameter (check const tuple params) check arr.toc's Arr works @ compile time new version of copy_val for copying types?? @@ -16,7 +16,7 @@ main ::= fn() { puti(f(7)); puti(f(4)); - f ::= fn(x ::= 3, y::=x) z := x + 1 { }; + f ::= fn(a,b::=3) z := a+b { }; r ::= f(); puti(r); diff --git a/tests/arr/arr.toc b/tests/arr/arr.toc index a999512..4cabd9e 100644 --- a/tests/arr/arr.toc +++ b/tests/arr/arr.toc @@ -28,6 +28,18 @@ arr_add ::= fn(t :: Type, a : &Arr(t), x : t) { a.len += 1; }; +square ::= fn(t :: Type, x : t) t { + a : Arr(t); + each i := 1,2..2*x-1 { + arr_add(t, &a, i); + }; + sum := 0 as t; + each i := 0..a.len-1 { + sum += a.data[i]; + }; + sum +}; + ArrInt ::= Arr(int); @@ -39,8 +51,8 @@ main ::= fn() { arr : ArrInt; farr : Arr(float); each i := 1..100 { - arr_add(int, &arr, inc(int, i*i)); - arr_add(float, &farr, inc(float, (i*i) as float)); + arr_add(int, &arr, inc(int, square(int, i))); + arr_add(float, &farr, inc(float, square(float, i as float))); } each i := 0..arr.len - 1 { puti(arr.data[i]); |