diff --git a/cmd/v/v.v b/cmd/v/v.v index b20c1167fb..60ab87b248 100644 --- a/cmd/v/v.v +++ b/cmd/v/v.v @@ -34,7 +34,7 @@ const ( 'shader', 'symlink', 'test', - 'test-all', /* runs most of the tests and other checking tools, that will be run by the CI */ + 'test-all', // runs most of the tests and other checking tools, that will be run by the CI 'test-cleancode', 'test-fmt', 'test-parser', diff --git a/vlib/v/gen/c/assign.v b/vlib/v/gen/c/assign.v index e04738a6d3..6f401871a8 100644 --- a/vlib/v/gen/c/assign.v +++ b/vlib/v/gen/c/assign.v @@ -154,7 +154,7 @@ fn (mut g Gen) gen_assign_stmt(node ast.AssignStmt) { ret_styp := g.typ(val.decl.return_type) g.write('$ret_styp (*$ident.name) (') def_pos := g.definitions.len - g.fn_args(val.decl.params, voidptr(0)) + g.fn_decl_params(val.decl.params, voidptr(0), false) g.definitions.go_back(g.definitions.len - def_pos) g.write(') = ') } else { @@ -312,7 +312,7 @@ fn (mut g Gen) gen_assign_stmt(node ast.AssignStmt) { ret_styp := g.typ(func.func.return_type) g.write('$ret_styp (*${g.get_ternary_name(ident.name)}) (') def_pos := g.definitions.len - g.fn_args(func.func.params, voidptr(0)) + g.fn_decl_params(func.func.params, voidptr(0), false) g.definitions.go_back(g.definitions.len - def_pos) g.write(')') } else { diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 2181c09d37..b974da241f 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -6849,7 +6849,7 @@ static inline __shared__$interface_name ${shared_fn_name}(__shared__$cctype* x) ...params[0] typ: st.set_nr_muls(1) } - fargs, _, _ := g.fn_args(params, voidptr(0)) + fargs, _, _ := g.fn_decl_params(params, voidptr(0), false) mut parameter_name := g.out.cut_last(g.out.len - params_start_pos) if st.is_ptr() { diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index c6c49889a9..0fe424b46e 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -274,7 +274,7 @@ fn (mut g Gen) gen_fn_decl(node &ast.FnDecl, skip bool) { g.write(fn_header) } arg_start_pos := g.out.len - fargs, fargtypes, heap_promoted := g.fn_args(node.params, node.scope) + fargs, fargtypes, heap_promoted := g.fn_decl_params(node.params, node.scope, node.is_variadic) if is_closure { mut s := '$cur_closure_ctx *$c.closure_ctx' if node.params.len > 0 { @@ -537,16 +537,15 @@ fn (mut g Gen) write_defer_stmts_when_needed() { } } -// fn decl args -fn (mut g Gen) fn_args(args []ast.Param, scope &ast.Scope) ([]string, []string, []bool) { +fn (mut g Gen) fn_decl_params(params []ast.Param, scope &ast.Scope, is_variadic bool) ([]string, []string, []bool) { mut fargs := []string{} mut fargtypes := []string{} mut heap_promoted := []bool{} - if args.len == 0 { + if params.len == 0 { // in C, `()` is untyped, unlike `(void)` g.write('void') } - for i, arg in args { + for i, arg in params { mut caname := if arg.name == '_' { g.new_tmp_declaration_name() } else { c_name(arg.name) } typ := g.unwrap_generic(arg.typ) arg_type_sym := g.table.sym(typ) @@ -556,7 +555,7 @@ fn (mut g Gen) fn_args(args []ast.Param, scope &ast.Scope) ([]string, []string, func := info.func g.write('${g.typ(func.return_type)} (*$caname)(') g.definitions.write_string('${g.typ(func.return_type)} (*$caname)(') - g.fn_args(func.params, voidptr(0)) + g.fn_decl_params(func.params, voidptr(0), func.is_variadic) g.write(')') g.definitions.write_string(')') fargs << caname @@ -586,11 +585,15 @@ fn (mut g Gen) fn_args(args []ast.Param, scope &ast.Scope) ([]string, []string, fargtypes << arg_type_name heap_promoted << heap_prom } - if i < args.len - 1 { + if i < params.len - 1 { g.write(', ') g.definitions.write_string(', ') } } + if g.pref.translated && is_variadic { + g.write(', ...') + g.definitions.write_string(', ...') + } return fargs, fargtypes, heap_promoted }