From e677daf608dcb4c3b0e4bcb168a9ec7996de3732 Mon Sep 17 00:00:00 2001 From: yuyi Date: Mon, 15 Mar 2021 00:47:43 +0800 Subject: [PATCH] cgen: fix array_sort and format array_filter/map generated codes (#9303) --- vlib/v/gen/c/array.v | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/vlib/v/gen/c/array.v b/vlib/v/gen/c/array.v index 0d485bc32c..4179be3792 100644 --- a/vlib/v/gen/c/array.v +++ b/vlib/v/gen/c/array.v @@ -141,7 +141,8 @@ fn (mut g Gen) gen_array_map(node ast.CallExpr) { if inp_sym.kind != .array { verror('map() requires an array') } - g.write('\t${g.typ(node.left_type)} ${tmp}_orig = ') + g.empty_line = true + g.write('${g.typ(node.left_type)} ${tmp}_orig = ') g.expr(node.left) g.writeln(';') g.writeln('int ${tmp}_len = ${tmp}_orig.len;') @@ -296,13 +297,14 @@ fn (mut g Gen) gen_array_sort(node ast.CallExpr) { // deref := if node.left_type.is_ptr() || node.left_type.is_pointer() { '->' } else { '.' } // eprintln('> qsort: pointer $node.left_type | deref: `$deref`') + g.empty_line = true g.write('qsort(') g.expr(node.left) g.write('${deref}data, ') g.expr(node.left) g.write('${deref}len, ') g.expr(node.left) - g.writeln('${deref}element_size, (int (*)(const void *, const void *))&$compare_fn);') + g.write('${deref}element_size, (int (*)(const void *, const void *))&$compare_fn)') } // `nums.filter(it % 2 == 0)` @@ -317,7 +319,8 @@ fn (mut g Gen) gen_array_filter(node ast.CallExpr) { info := sym.info as table.Array styp := g.typ(node.return_type) elem_type_str := g.typ(info.elem_type) - g.write('\t${g.typ(node.left_type)} ${tmp}_orig = ') + g.empty_line = true + g.write('${g.typ(node.left_type)} ${tmp}_orig = ') g.expr(node.left) g.writeln(';') g.writeln('int ${tmp}_len = ${tmp}_orig.len;')