From 57ee07f1261684171731b231f0b6ef100420d262 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Wed, 11 Mar 2020 18:00:39 -0400 Subject: cleanup and varargs bugfix --- main.c | 1 - parse.c | 12 ------------ test.toc | 2 +- types.c | 8 +++----- 4 files changed, 4 insertions(+), 19 deletions(-) diff --git a/main.c b/main.c index 9d93e33..256c5fb 100644 --- a/main.c +++ b/main.c @@ -8,7 +8,6 @@ /* TODO: -make sure varargs works with inference #foreign variadic fns EXPR_VALs don't always need temp variables where diff --git a/parse.c b/parse.c index 9413d6a..91d61e1 100644 --- a/parse.c +++ b/parse.c @@ -545,10 +545,6 @@ static Status parse_type(Parser *p, Type *type, Location *where) { err_print(slice_where, "You cannot have a slice of tuples."); return false; } - if (type_is_builtin(type->slice, BUILTIN_VARARGS)) { - err_print(slice_where, "You cannot have a slice of varargs."); - return false; - } break; } Token *end = expr_find_end(p, 0); @@ -562,10 +558,6 @@ static Status parse_type(Parser *p, Type *type, Location *where) { err_print(of_where, "You cannot have an array of tuples."); return false; } - if (type_is_builtin(type->arr.of, BUILTIN_VARARGS)) { - err_print(of_where, "You cannot have an array of varargs."); - return false; - } } break; case KW_LT: /* tuple! */ @@ -608,10 +600,6 @@ static Status parse_type(Parser *p, Type *type, Location *where) { err_print(ptr_where, "You cannot have a pointer to a tuple."); return false; } - if (type_is_builtin(type->ptr, BUILTIN_VARARGS)) { - err_print(ptr_where, "You cannot have a pointer to varargs."); - return false; - } } break; case KW_STRUCT: { /* struct */ diff --git a/test.toc b/test.toc index 21cd2c0..86d3b9f 100644 --- a/test.toc +++ b/test.toc @@ -1,6 +1,6 @@ #include "std/io.toc"; -g ::= fn(modulator: int, x : ..) int { +g ::= fn(modulator:: int, x : ..) int { total := 0; for e := x { total += modulator * (e as int); diff --git a/types.c b/types.c index 2e02b49..c1acac9 100644 --- a/types.c +++ b/types.c @@ -1217,7 +1217,7 @@ static Status call_arg_param_order(FnExpr *fn, Type *fn_type, Argument *args, Lo arr_foreach(fn->params, Declaration, decl) { arr_foreach(decl->idents, Identifier, ident) { if (order[param_idx] == -1) { - if (type_is_builtin(&decl->type, BUILTIN_VARARGS)) { + if ((decl->flags & DECL_ANNOTATES_TYPE) && type_is_builtin(&decl->type, BUILTIN_VARARGS)) { order[param_idx] = (I16)nargs; } else if (!(decl->flags & DECL_HAS_EXPR) && !(decl->flags & DECL_INFER)) { char *s = ident_to_str(*ident); @@ -2220,10 +2220,8 @@ static Status types_expr(Typer *tr, Expression *e) { if (param->flags & DECL_INFER) { *(Identifier *)arr_add(&inferred_idents) = *ident; } else if ((param->flags & DECL_ANNOTATES_TYPE) - && !(param->flags & DECL_HAS_EXPR)) { - if (param->type.kind == TYPE_TUPLE) - err_print(param->where, "Parameters cannot have tuple types."); - + && !type_is_builtin(¶m->type, BUILTIN_VARARGS)) { + /* add to stuff infer can use */ Type **p = arr_add(&decl_types); *p = ¶m->type; Type **q = arr_add(&arg_types); -- cgit v1.2.3