summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cgen.c8
-rw-r--r--main.c3
-rw-r--r--test.toc11
3 files changed, 14 insertions, 8 deletions
diff --git a/cgen.c b/cgen.c
index dc61f5b..dd03cc9 100644
--- a/cgen.c
+++ b/cgen.c
@@ -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, "))");
}
diff --git a/main.c b/main.c
index 63efe85..8ebe7cb 100644
--- a/main.c
+++ b/main.c
@@ -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
diff --git a/test.toc b/test.toc
index 0004af0..d37489e 100644
--- a/test.toc
+++ b/test.toc
@@ -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