diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2019-12-04 23:16:47 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2019-12-04 23:16:47 -0500 |
commit | c898f92eecc4421c7e134daf37a6f87562b5f5d8 (patch) | |
tree | 0859d7325fb0284580d47d6229d34a52ff026224 | |
parent | ae8af6b1d8860b18ae159499af397d067f46c46a (diff) |
really figured out whats going on with Arr.
this isnt going to be easy to fix
-rw-r--r-- | test.toc | 78 | ||||
-rw-r--r-- | types.c | 5 |
2 files changed, 47 insertions, 36 deletions
@@ -1,45 +1,51 @@ -// puti @= fn(x: int) { -// #C("printf(\"%ld\\n\", (long)x); -// "); +// // puti @= fn(x: int) { +// // #C("printf(\"%ld\\n\", (long)x); +// // "); +// // }; +// // putf @= fn(x: float) { +// // #C("printf(\"%f\\n\", (double)x); +// // "); +// // }; + +// Arr @= fn (t @ Type) Type { +// struct { +// data : t; +// // len, cap : u64; +// } // }; -// putf @= fn(x: float) { -// #C("printf(\"%f\\n\", (double)x); -// "); + +// // todo: test that t @ type doesn't cause problems +// arr_add @= fn(t @ Type, a : &Arr(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 @= 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)) { - // 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; -}; +// main @= fn() { +// // arr : Arr(int); +// // // arr_add(int, &arr, 5); +// // // arr_add(int, &arr, 10); +// // // arr_add(int, &arr, 20); +// // // each i := 0..arr.len - 1 { +// // // puti(arr.data[i]); +// // // } +// }; + +// // t @= fn(x @ Type) Type { struct { t: x; } }; +// // // pass the wrong thing to t, and the error is in the wrong place +// // f @= fn(x: t(int)) {}; -main @= fn() { -// arr : Arr(int); -// // arr_add(int, &arr, 5); -// // arr_add(int, &arr, 10); -// // arr_add(int, &arr, 20); -// // each i := 0..arr.len - 1 { -// // puti(arr.data[i]); -// // } +f @= fn(t @ Type, x : t) { }; -// t @= fn(x @ Type) Type { struct { t: x; } }; -// // pass the wrong thing to t, and the error is in the wrong place -// f @= fn(x: t(int)) {};
\ No newline at end of file +main @= fn() { f(int, 3); };
\ No newline at end of file @@ -197,6 +197,7 @@ static bool type_of_fn(Typer *tr, FnExpr *f, Location where, Type *t, U16 flags) FnExpr *prev_fn = tr->fn; FnExpr fn_copy; + if (!(flags & TYPE_OF_FN_NO_COPY_EVEN_IF_CONST) && fn_has_any_const_params(f)) { Copier cop = copier_create(tr->allocr, tr->block); copy_fn_expr(&cop, &fn_copy, f, false); @@ -287,6 +288,7 @@ static bool type_of_fn(Typer *tr, FnExpr *f, Location where, Type *t, U16 flags) } else { f->ret_type.kind = TYPE_TUPLE; f->ret_type.flags = TYPE_IS_RESOLVED; + f->ret_type.was_expr = NULL; f->ret_type.tuple = NULL; arr_foreach(f->ret_decls, Declaration, d) { arr_foreach(d->idents, Identifier, i) { @@ -1176,6 +1178,9 @@ static bool types_expr(Typer *tr, Expression *e) { bool should_be_evald = arg_is_const(&new_args[i], fn_type->constness[i]); if (should_be_evald) { Value *arg_val = typer_arr_add(tr, &table_index.tuple); + printf("Evaluating expression: "); + print_location(new_args[i].where); + if (!eval_expr(tr->evalr, &new_args[i], arg_val)) { if (tr->evalr->enabled) { info_print(new_args[i].where, "(error occured while trying to evaluate compile-time argument, argument #%lu)", 1+(unsigned long)i); |