From 896cac9b89decb94a7d3f18f24276e4032d776ca Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Tue, 3 Dec 2019 22:32:19 -0500 Subject: fixed another problem, but Arr still aint workin --- test.toc | 39 ++++++++++++++++++--------------------- types.c | 14 ++++++++------ 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/test.toc b/test.toc index 67db6d5..61436ac 100644 --- a/test.toc +++ b/test.toc @@ -7,33 +7,30 @@ // "); // }; -// Arr @= fn (t @ Type) Type { -// struct { -// data : []t; -// len, cap : u64; -// } -// }; +Arr @= fn (t @ Type) Type { + struct { + data : []t; + len, cap : u64; + } +}; // todo: test that t @ type doesn't cause problems -// arr_add @= fn(t @ Type, a : &Arr(t), x : t) { -// if a.len >= a.cap { -// a.cap = a.cap * 2 + 2; -// new_data := new(t, a.cap); -// each i := 0..a.len { -// new_data[i] = a.data[i]; -// } -// a.data = new_data; -// } -// a.data[a.len] = x; -// a.len += 1; -// }; +arr_add @= fn(t @ Type, a : &Arr(t), x : t) { + if a.len >= a.cap { + a.cap = a.cap * 2 + 2; + new_data := new(t, a.cap); + each i := 0..a.len { + new_data[i] = a.data[i]; + } + a.data = new_data; + } + a.data[a.len] = x; + a.len += 1; +}; -t @= fn(t : Type) Type { t }; -// f @= fn(x : &t(float)){}; main @= fn() { - x : &t(float); // arr : Arr(int); // // arr_add(int, &arr, 5); // // arr_add(int, &arr, 10); diff --git a/types.c b/types.c index 6ba624d..c4d609c 100644 --- a/types.c +++ b/types.c @@ -1762,12 +1762,14 @@ static bool types_decl(Typer *tr, Declaration *d) { success = false; goto ret; } - Value *val = d->type.kind == TYPE_TUPLE ? &d->val.tuple[i] : &d->val; - if (!type_resolve(tr, val->type, d->where)) return false; - if (val->type->kind == TYPE_TUPLE) { - err_print(d->where, "You can't declare a new type to be a tuple."); - success = false; - goto ret; + if (d->flags & DECL_HAS_EXPR) { + Value *val = d->type.kind == TYPE_TUPLE ? &d->val.tuple[i] : &d->val; + if (!type_resolve(tr, val->type, d->where)) return false; + if (val->type->kind == TYPE_TUPLE) { + err_print(d->where, "You can't declare a new type to be a tuple."); + success = false; + goto ret; + } } } else if (!(d->flags & DECL_IS_CONST) && t->kind == TYPE_FN && t->fn.constness) { for (size_t p = 0; p < arr_len(t->fn.types)-1; p++) { -- cgit v1.2.3