diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-03-11 17:54:38 -0400 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-03-11 17:54:38 -0400 |
commit | 91b74e90fb1e3b59058a7dc7045795c32e53c5a5 (patch) | |
tree | 0c835420c65d16278facedac224b35b8c42de4b2 | |
parent | fcc2801b3ffc5cbf0e93f88df1dc849b209fb664 (diff) |
passing varargs seemingly fully working
-rw-r--r-- | eval.c | 2 | ||||
-rw-r--r-- | test.toc | 15 | ||||
-rw-r--r-- | types.c | 4 |
3 files changed, 12 insertions, 9 deletions
@@ -1450,7 +1450,7 @@ static Status eval_expr(Evaluator *ev, Expression *e, Value *v) { bool multiple_idents = arr_len(p->idents) > 1; bool is_tuple = p->type.kind == TYPE_TUPLE; if (type_is_builtin(&p->type, BUILTIN_VARARGS)) { - Expression *args_end = arg + nargs; + Expression *args_end = e->call.arg_exprs + nargs; /* set varargs */ pval->varargs = NULL; for (; arg != args_end; ++arg) { @@ -2,8 +2,8 @@ g ::= fn(modulator: int, x : ..) int { total := 0; - for e, i := x { - total += modulator * i * (e as int); + for e := x { + total += modulator * (e as int); } total }; @@ -13,14 +13,15 @@ f ::= fn(x : ..) int { }; main ::= fn() { - puti(f(5)); + puti(f(5)); - puti(f(5,6)); + puti(f(5,6)); - puti(f(1,2,3)); - - puti(f(1,1,1,1)); + puti(f(1,2,3)); + puti(f(1,1,1,1)); + + puti(f()); }; main();
\ No newline at end of file @@ -1217,7 +1217,9 @@ 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 (!(decl->flags & DECL_HAS_EXPR) && !(decl->flags & DECL_INFER)) { + if (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); err_print(where, "Parameter #%lu (%s) was not set in function call.", param_idx+1, s); free(s); |