From 3a85955d22f6b12c17c2d94d99a8ce10ebe8b150 Mon Sep 17 00:00:00 2001 From: shove Date: Fri, 11 Nov 2022 16:06:01 +0800 Subject: [PATCH] all: rollback to old interpolation (step 4) (#16383) --- vlib/v/gen/c/auto_eq_methods.v | 2 +- vlib/v/gen/c/auto_str_methods.v | 52 ++++++++++++++++----------------- vlib/v/gen/c/cgen.v | 17 ++++++----- vlib/v/gen/c/cheaders.v | 10 +++---- vlib/v/gen/c/fn.v | 2 +- vlib/v/gen/c/for.v | 2 +- vlib/v/gen/c/sql.v | 2 +- vlib/v/gen/c/struct.v | 2 +- 8 files changed, 45 insertions(+), 44 deletions(-) diff --git a/vlib/v/gen/c/auto_eq_methods.v b/vlib/v/gen/c/auto_eq_methods.v index 971e21e425..76b998e238 100644 --- a/vlib/v/gen/c/auto_eq_methods.v +++ b/vlib/v/gen/c/auto_eq_methods.v @@ -353,7 +353,7 @@ fn (mut g Gen) gen_map_equality_fn(left_type ast.Type) string { } match kind { .string { - fn_builder.writeln('\t\tif (!fast_string_eq(*(string*)map_get(&b, k, &(string[]){ _SLIT("")}), v)) {') + fn_builder.writeln('\t\tif (!fast_string_eq(*(string*)map_get(&b, k, &(string[]){_SLIT("")}), v)) {') } .sum_type { eq_fn := g.gen_sumtype_equality_fn(value.typ) diff --git a/vlib/v/gen/c/auto_str_methods.v b/vlib/v/gen/c/auto_str_methods.v index cf9bd88418..774b0f2966 100644 --- a/vlib/v/gen/c/auto_str_methods.v +++ b/vlib/v/gen/c/auto_str_methods.v @@ -246,9 +246,9 @@ fn (mut g Gen) gen_str_for_alias(info ast.Alias, styp string, str_fn_name string g.auto_str_funcs.writeln('\tstring indents = string_repeat(_SLIT(" "), indent_count);') g.auto_str_funcs.writeln('\tstring tmp_ds = ${parent_str_fn_name}(it);') g.auto_str_funcs.writeln('\tstring res = str_intp(3, _MOV((StrIntpData[]){ - { _SLIT0, $c.si_s_code, {.d_s = indents }}, - { _SLIT("${clean_type_v_type_name}("), $c.si_s_code, {.d_s = tmp_ds }}, - { _SLIT(")"), 0, {.d_c = 0 }} + {_SLIT0, $c.si_s_code, {.d_s = indents }}, + {_SLIT("${clean_type_v_type_name}("), $c.si_s_code, {.d_s = tmp_ds }}, + {_SLIT(")"), 0, {.d_c = 0 }} }));') g.auto_str_funcs.writeln('\tstring_free(&indents);') g.auto_str_funcs.writeln('\tstring_free(&tmp_ds);') @@ -318,7 +318,7 @@ fn (mut g Gen) gen_str_for_enum(info ast.Enum, styp string, str_fn_name string) g.auto_str_funcs.writeln('\tu64 zit = (u64)it;') for i, val in info.vals { mask := u64(1) << i - g.auto_str_funcs.writeln('\tif (zit & 0x${mask:016x}U) { if (!first) { ret = string__plus(ret, _SLIT(" | "));} ret = string__plus(ret, _SLIT(".$val")); first = 0;}') + g.auto_str_funcs.writeln('\tif (zit & 0x${mask:016x}U) {if (!first) {ret = string__plus(ret, _SLIT(" | "));} ret = string__plus(ret, _SLIT(".$val")); first = 0;}') } g.auto_str_funcs.writeln('\tret = string__plus(ret, _SLIT("}"));') g.auto_str_funcs.writeln('\treturn ret;') @@ -377,8 +377,8 @@ fn (mut g Gen) gen_str_for_interface(info ast.Interface, styp string, str_fn_nam } val += ')' res := 'str_intp(2, _MOV((StrIntpData[]){ - { _SLIT("${clean_interface_v_type_name}(\'"), $c.si_s_code, {.d_s = $val}}, - { _SLIT("\')"), 0, {.d_c = 0 }} + {_SLIT("${clean_interface_v_type_name}(\'"), $c.si_s_code, {.d_s = $val}}, + {_SLIT("\')"), 0, {.d_c = 0 }} }))' fn_builder.write_string('\tif (x._typ == _${styp}_${sub_sym.cname}_index)') fn_builder.write_string(' return $res;') @@ -389,8 +389,8 @@ fn (mut g Gen) gen_str_for_interface(info ast.Interface, styp string, str_fn_nam } val += ')' res := 'str_intp(2, _MOV((StrIntpData[]){ - { _SLIT("${clean_interface_v_type_name}("), $c.si_s_code, {.d_s = $val}}, - { _SLIT(")"), 0, {.d_c = 0 }} + {_SLIT("${clean_interface_v_type_name}("), $c.si_s_code, {.d_s = $val}}, + {_SLIT(")"), 0, {.d_c = 0 }} }))' fn_builder.write_string('\tif (x._typ == _${styp}_${sub_sym.cname}_index)') fn_builder.write_string(' return $res;\n') @@ -446,8 +446,8 @@ fn (mut g Gen) gen_str_for_union_sum_type(info ast.SumType, styp string, str_fn_ } val += ')' res := 'str_intp(2, _MOV((StrIntpData[]){ - { _SLIT("${clean_sum_type_v_type_name}(\'"), $c.si_s_code, {.d_s = $val}}, - { _SLIT("\')"), 0, {.d_c = 0 }} + {_SLIT("${clean_sum_type_v_type_name}(\'"), $c.si_s_code, {.d_s = $val}}, + {_SLIT("\')"), 0, {.d_c = 0 }} }))' fn_builder.write_string('\t\tcase $typ.idx(): return $res;\n') } else { @@ -457,8 +457,8 @@ fn (mut g Gen) gen_str_for_union_sum_type(info ast.SumType, styp string, str_fn_ } val += ')' res := 'str_intp(2, _MOV((StrIntpData[]){ - { _SLIT("${clean_sum_type_v_type_name}("), $c.si_s_code, {.d_s = $val}}, - { _SLIT(")"), 0, {.d_c = 0 }} + {_SLIT("${clean_sum_type_v_type_name}("), $c.si_s_code, {.d_s = $val}}, + {_SLIT(")"), 0, {.d_c = 0 }} }))' fn_builder.write_string('\t\tcase $typ.idx(): return $res;\n') } @@ -584,12 +584,12 @@ fn (mut g Gen) gen_str_for_array(info ast.Array, styp string, str_fn_name string } } else if sym.kind == .rune { // Rune are managed at this level as strings - g.auto_str_funcs.writeln('\t\tstring x = str_intp(2, _MOV((StrIntpData[]){{ _SLIT("\`"), $c.si_s_code, {.d_s = ${elem_str_fn_name}(it) }}, { _SLIT("\`"), 0, {.d_c = 0 }}}));\n') + g.auto_str_funcs.writeln('\t\tstring x = str_intp(2, _MOV((StrIntpData[]){{_SLIT("\`"), $c.si_s_code, {.d_s = ${elem_str_fn_name}(it) }}, {_SLIT("\`"), 0, {.d_c = 0 }}}));\n') } else if sym.kind == .string { if is_elem_ptr { - g.auto_str_funcs.writeln('\t\tstring x = str_intp(2, _MOV((StrIntpData[]){{ _SLIT("&\'"), $c.si_s_code, {.d_s = *it }}, { _SLIT("\'"), 0, {.d_c = 0 }}}));\n') + g.auto_str_funcs.writeln('\t\tstring x = str_intp(2, _MOV((StrIntpData[]){{_SLIT("&\'"), $c.si_s_code, {.d_s = *it }}, {_SLIT("\'"), 0, {.d_c = 0 }}}));\n') } else { - g.auto_str_funcs.writeln('\t\tstring x = str_intp(2, _MOV((StrIntpData[]){{ _SLIT("\'"), $c.si_s_code, {.d_s = it }}, { _SLIT("\'"), 0, {.d_c = 0 }}}));\n') + g.auto_str_funcs.writeln('\t\tstring x = str_intp(2, _MOV((StrIntpData[]){{_SLIT("\'"), $c.si_s_code, {.d_s = it }}, {_SLIT("\'"), 0, {.d_c = 0 }}}));\n') } } else { // There is a custom .str() method, so use it. @@ -865,7 +865,7 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, styp string, str_fn_name stri } } fn_body.writeln('\tstring res = str_intp( ${(info.fields.len - field_skips.len) * 4 + 3}, _MOV((StrIntpData[]){') - fn_body.writeln('\t\t{ _SLIT("$clean_struct_v_type_name{\\n"), 0, {.d_c=0}},') + fn_body.writeln('\t\t{_SLIT("$clean_struct_v_type_name{\\n"), 0, {.d_c=0}},') mut is_first := true for i, field in info.fields { // Skip `str:skip` fields @@ -897,10 +897,10 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, styp string, str_fn_name stri if is_first { // first field doesn't need \n - fn_body.write_string('\t\t{ _SLIT0, $c.si_s_code, {.d_s=indents}}, { _SLIT(" $field.name: $ptr_amp$prefix"), 0, {.d_c=0}}, ') + fn_body.write_string('\t\t{_SLIT0, $c.si_s_code, {.d_s=indents}}, {_SLIT(" $field.name: $ptr_amp$prefix"), 0, {.d_c=0}}, ') is_first = false } else { - fn_body.write_string('\t\t{ _SLIT("\\n"), $c.si_s_code, {.d_s=indents}}, { _SLIT(" $field.name: $ptr_amp$prefix"), 0, {.d_c=0}}, ') + fn_body.write_string('\t\t{_SLIT("\\n"), $c.si_s_code, {.d_s=indents}}, {_SLIT(" $field.name: $ptr_amp$prefix"), 0, {.d_c=0}}, ') } // custom methods management @@ -919,10 +919,10 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, styp string, str_fn_name stri // with floats we use always the g representation: if sym.kind !in [.f32, .f64] { - fn_body.write_string('{ _SLIT("$quote_str"), ${int(base_fmt)}, {.${data_str(base_fmt)}=') + fn_body.write_string('{_SLIT("$quote_str"), ${int(base_fmt)}, {.${data_str(base_fmt)}=') } else { g_fmt := '0x' + (u32(base_fmt) | u32(0x7F) << 9).hex() - fn_body.write_string('{ _SLIT("$quote_str"), $g_fmt, {.${data_str(base_fmt)}=') + fn_body.write_string('{_SLIT("$quote_str"), $g_fmt, {.${data_str(base_fmt)}=') } mut funcprefix := '' @@ -965,9 +965,9 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, styp string, str_fn_name stri } } - fn_body.writeln('}}, { _SLIT("$quote_str"), 0, {.d_c=0}},') + fn_body.writeln('}}, {_SLIT("$quote_str"), 0, {.d_c=0}},') } - fn_body.writeln('\t\t{ _SLIT("\\n"), $c.si_s_code, {.d_s=indents}}, { _SLIT("}"), 0, {.d_c=0}},') + fn_body.writeln('\t\t{_SLIT("\\n"), $c.si_s_code, {.d_s=indents}}, {_SLIT("}"), 0, {.d_c=0}},') fn_body.writeln('\t}));') } @@ -1005,18 +1005,18 @@ fn struct_auto_str_func(sym &ast.TypeSymbol, _field_type ast.Type, fn_name strin // ptr int can be "nil", so this needs to be casted to a string if sym.kind == .f32 { return 'str_intp(1, _MOV((StrIntpData[]){ - { _SLIT0, $si_g32_code, {.d_f32 = *$method_str }} + {_SLIT0, $si_g32_code, {.d_f32 = *$method_str }} }))', true } else if sym.kind == .f64 { return 'str_intp(1, _MOV((StrIntpData[]){ - { _SLIT0, $si_g64_code, {.d_f64 = *$method_str }} + {_SLIT0, $si_g64_code, {.d_f64 = *$method_str }} }))', true } else if sym.kind == .u64 { fmt_type := StrIntpType.si_u64 - return 'str_intp(1, _MOV((StrIntpData[]){{ _SLIT0, ${u32(fmt_type) | 0xfe00}, {.d_u64 = *$method_str }}}))', true + return 'str_intp(1, _MOV((StrIntpData[]){{_SLIT0, ${u32(fmt_type) | 0xfe00}, {.d_u64 = *$method_str }}}))', true } fmt_type := StrIntpType.si_i32 - return 'str_intp(1, _MOV((StrIntpData[]){{ _SLIT0, ${u32(fmt_type) | 0xfe00}, {.d_i32 = *$method_str }}}))', true + return 'str_intp(1, _MOV((StrIntpData[]){{_SLIT0, ${u32(fmt_type) | 0xfe00}, {.d_i32 = *$method_str }}}))', true } return method_str, false } diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 2a8648a5e3..bec6af88c0 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -1252,7 +1252,7 @@ fn (mut g Gen) write_chan_pop_optional_fns() { static inline $opt_el_type __Option_${styp}_popval($styp ch) { $opt_el_type _tmp = {0}; if (sync__Channel_try_pop_priv(ch, _tmp.data, false)) { - return ($opt_el_type){ .state = 2, .err = _v_error(_SLIT("channel closed")), .data = { EMPTY_STRUCT_INITIALIZATION} }; + return ($opt_el_type){ .state = 2, .err = _v_error(_SLIT("channel closed")), .data = {EMPTY_STRUCT_INITIALIZATION} }; } return _tmp; }') @@ -1274,7 +1274,8 @@ fn (mut g Gen) write_chan_push_optional_fns() { g.channel_definitions.writeln(' static inline ${c.option_name}_void __Option_${styp}_pushval($styp ch, $el_type e) { if (sync__Channel_try_push_priv(ch, &e, false)) { - return (${c.option_name}_void){ .state = 2, .err = _v_error(_SLIT("channel closed")), .data = { EMPTY_STRUCT_INITIALIZATION} }; } + return (${c.option_name}_void){ .state = 2, .err = _v_error(_SLIT("channel closed")), .data = {EMPTY_STRUCT_INITIALIZATION} }; + } return (${c.option_name}_void){0}; }') } @@ -2294,7 +2295,7 @@ fn (mut g Gen) call_cfn_for_casting_expr(fname string, expr ast.Expr, exp_is_ptr } } if got_styp == 'none' && !g.cur_fn.return_type.has_flag(.optional) { - g.write('(none){ EMPTY_STRUCT_INITIALIZATION}') + g.write('(none){EMPTY_STRUCT_INITIALIZATION}') } else { g.expr(expr) } @@ -4297,7 +4298,7 @@ fn (mut g Gen) gen_result_error(target_type ast.Type, expr ast.Expr) { styp := g.typ(target_type) g.write('($styp){ .is_error=true, .err=') g.expr(expr) - g.write(', .data={ EMPTY_STRUCT_INITIALIZATION} }') + g.write(', .data={EMPTY_STRUCT_INITIALIZATION} }') } // NB: remove this when optional has no errors anymore @@ -4305,7 +4306,7 @@ fn (mut g Gen) gen_optional_error(target_type ast.Type, expr ast.Expr) { styp := g.typ(target_type) g.write('($styp){ .state=2, .err=') g.expr(expr) - g.write(', .data={ EMPTY_STRUCT_INITIALIZATION} }') + g.write(', .data={EMPTY_STRUCT_INITIALIZATION} }') } fn (mut g Gen) return_stmt(node ast.Return) { @@ -5163,13 +5164,13 @@ fn (mut g Gen) write_init_function() { // Note: os.args in this case will be []. g.writeln('__attribute__ ((constructor))') g.writeln('void _vinit_caller() {') - g.writeln('\tstatic bool once = false; if (once) { return;} once = true;') + g.writeln('\tstatic bool once = false; if (once) {return;} once = true;') g.writeln('\t_vinit(0,0);') g.writeln('}') g.writeln('__attribute__ ((destructor))') g.writeln('void _vcleanup_caller() {') - g.writeln('\tstatic bool once = false; if (once) { return;} once = true;') + g.writeln('\tstatic bool once = false; if (once) {return;} once = true;') g.writeln('\t_vcleanup();') g.writeln('}') } @@ -5725,7 +5726,7 @@ fn (mut g Gen) type_default(typ_ ast.Type) string { if field_sym.info is ast.Struct && field_sym.language == .v { if field_sym.info.fields.len == 0 && field_sym.info.embeds.len == 0 { - zero_str = '{ EMPTY_STRUCT_INITIALIZATION}' + zero_str = '{EMPTY_STRUCT_INITIALIZATION}' } } } diff --git a/vlib/v/gen/c/cheaders.v b/vlib/v/gen/c/cheaders.v index 0a6d4970c6..8f77ccc5c5 100644 --- a/vlib/v/gen/c/cheaders.v +++ b/vlib/v/gen/c/cheaders.v @@ -483,14 +483,14 @@ const c_helper_macros = '//============================== HELPER C MACROS ====== #define _SLEN(s, n) ((string){.str=(byteptr)("" s), .len=n, .is_lit=1}) // take the address of an rvalue -#define ADDR(type, expr) (&((type[]){ expr }[0])) +#define ADDR(type, expr) (&((type[]){expr}[0])) // copy something to the heap -#define HEAP(type, expr) ((type*)memdup((void*)&((type[]){ expr }[0]), sizeof(type))) -#define HEAP_noscan(type, expr) ((type*)memdup_noscan((void*)&((type[]){ expr }[0]), sizeof(type))) +#define HEAP(type, expr) ((type*)memdup((void*)&((type[]){expr}[0]), sizeof(type))) +#define HEAP_noscan(type, expr) ((type*)memdup_noscan((void*)&((type[]){expr}[0]), sizeof(type))) -#define _PUSH_MANY(arr, val, tmp, tmp_typ) { tmp_typ tmp = (val); array_push_many(arr, tmp.data, tmp.len);} -#define _PUSH_MANY_noscan(arr, val, tmp, tmp_typ) { tmp_typ tmp = (val); array_push_many_noscan(arr, tmp.data, tmp.len);} +#define _PUSH_MANY(arr, val, tmp, tmp_typ) {tmp_typ tmp = (val); array_push_many(arr, tmp.data, tmp.len);} +#define _PUSH_MANY_noscan(arr, val, tmp, tmp_typ) {tmp_typ tmp = (val); array_push_many_noscan(arr, tmp.data, tmp.len);} ' const c_headers = c_helper_macros + c_unsigned_comparison_functions + c_common_macros + diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index 689ad5f7b5..5f8ea52928 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -728,7 +728,7 @@ fn (mut g Gen) call_expr(node ast.CallExpr) { $if msvc { // MSVC has no support for the statement expressions used below } $else { - g.write(', ({ VUNREACHABLE(); })') + g.write(', ({VUNREACHABLE();})') } } } diff --git a/vlib/v/gen/c/for.v b/vlib/v/gen/c/for.v index 3e74d8f761..a74595aa4c 100644 --- a/vlib/v/gen/c/for.v +++ b/vlib/v/gen/c/for.v @@ -290,7 +290,7 @@ fn (mut g Gen) for_in_stmt(node_ ast.ForInStmt) { g.writeln('\t$idx = -1;') g.writeln('\tcontinue;') g.writeln('}') - g.writeln('if (!DenseArray_has_index(&$cond_var${arw_or_pt}key_values, $idx)) { continue;}') + g.writeln('if (!DenseArray_has_index(&$cond_var${arw_or_pt}key_values, $idx)) {continue;}') if node.key_var != '_' { key_styp := g.typ(node.key_type) key := c_name(node.key_var) diff --git a/vlib/v/gen/c/sql.v b/vlib/v/gen/c/sql.v index 91d280f1c9..97b4298250 100644 --- a/vlib/v/gen/c/sql.v +++ b/vlib/v/gen/c/sql.v @@ -183,7 +183,7 @@ fn (mut g Gen) sql_insert(node ast.SqlStmtLine, expr string, table_name string, for sub in subs { g.sql_stmt_line(sub, expr, or_expr) - g.writeln('array_push(&$last_ids_arr, _MOV((orm__Primitive[]){ orm__Connection_name_table[${expr}._typ]._method_last_id(${expr}._object)}));') + g.writeln('array_push(&$last_ids_arr, _MOV((orm__Primitive[]){orm__Connection_name_table[${expr}._typ]._method_last_id(${expr}._object)}));') } g.write('${result_name}_void $res = orm__Connection_name_table[${expr}._typ]._method_') diff --git a/vlib/v/gen/c/struct.v b/vlib/v/gen/c/struct.v index 1fcb61d28d..505183e061 100644 --- a/vlib/v/gen/c/struct.v +++ b/vlib/v/gen/c/struct.v @@ -182,7 +182,7 @@ fn (mut g Gen) struct_init(node ast.StructInit) { } field_name := c_name(field.name) if field.typ.has_flag(.optional) || field.typ.has_flag(.result) { - g.write('.$field_name = { EMPTY_STRUCT_INITIALIZATION },') + g.write('.$field_name = {EMPTY_STRUCT_INITIALIZATION},') initialized = true continue }