diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-03-10 13:10:58 -0400 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-03-10 13:10:58 -0400 |
commit | eab6760e746527e88d05d507195c78a0197e8be5 (patch) | |
tree | efcf77fc87dcaac4163d1bce88ecf3bdbc090738 | |
parent | f7375a3534eeab4200ec8ed15b4d9acca5e1913f (diff) |
const varargs working
-rw-r--r-- | cgen.c | 8 | ||||
-rw-r--r-- | main.c | 3 | ||||
-rw-r--r-- | test.toc | 11 |
3 files changed, 14 insertions, 8 deletions
@@ -1022,7 +1022,7 @@ static void cgen_expr_pre(CGenerator *g, Expression *e) { if (!constness || !arg_is_const(arg, constness[i])) { cgen_arg_pre(g, arg); } - if (i < nparams-1) + if (i < nparams-1) /* necessary for varargs */ ++i; } if (e->type.kind == TYPE_TUPLE) { @@ -1444,7 +1444,8 @@ static void cgen_expr(CGenerator *g, Expression *e) { } cgen_write(g, "("); bool first_arg = true; - int i = 0; + size_t i = 0; + size_t nparams = arr_len(fn_type->types)-1; arr_foreach(e->call.arg_exprs, Expression, arg) { if (!fn_type->constness || !arg_is_const(arg, fn_type->constness[i])) { if (!first_arg) @@ -1452,7 +1453,8 @@ static void cgen_expr(CGenerator *g, Expression *e) { first_arg = false; cgen_arg(g, arg); } - ++i; + if (i < nparams-1) + ++i; } cgen_write(g, "))"); } @@ -13,11 +13,14 @@ const varargs varargs only exist in decls. not a type of its own don't allow default varargs don't allow semiconst varargs +don't allow struct varargs make sure you can't have a variadic function pointer make sure varargs works with inference #foreign variadic fns +EXPR_VALs don't always need temp variables where #returns_code (function/struct body is a block, to be evaluated at compile time, which returns the actual statements -- you can use this for implementation of printf) + - struct varargs break continue switch @@ -1,9 +1,10 @@ -// #include "std/io.toc"; +#include "std/io.toc"; -f ::= fn(x :: ..) int { - x[0] +f ::= fn(x :: ..) Type { + [#sizeof(x[0])]x[1] }; main ::= fn() { - f(1,2,3); -};
\ No newline at end of file + x: f(int,u8); +}; +main();
\ No newline at end of file |