From 7dc98120c0399e433ecdf2bf26d15c69fcbbee95 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sat, 2 May 2020 00:45:39 +0200 Subject: [PATCH] cgen: vfmt -live fix; add new to c_reserved --- vlib/v/gen/cgen.v | 6 +++--- vlib/v/gen/fn.v | 20 +++++++++----------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 17dc2c7133..27c0e24375 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -36,7 +36,8 @@ const ( 'unsigned', 'void', 'volatile', - 'while' + 'while', + 'new' ] ) @@ -92,7 +93,6 @@ mut: attr string is_builtin_mod bool hotcode_fn_names []string - // fn_main &ast.FnDecl // the FnDecl of the main function. Needed in order to generate the main function code *last* } @@ -263,7 +263,7 @@ pub fn (mut g Gen) finish() { if g.fn_main != 0 { g.out.writeln('') g.fn_decl = g.fn_main - g.gen_fn_decl( g.fn_main ) + g.gen_fn_decl(g.fn_main) } } diff --git a/vlib/v/gen/fn.v b/vlib/v/gen/fn.v index 7f84acba4d..935377062f 100644 --- a/vlib/v/gen/fn.v +++ b/vlib/v/gen/fn.v @@ -23,11 +23,11 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl) { g.write('inline ') } // - is_livefn := g.attr == 'live' - is_livemain := g.pref.is_livemain && is_livefn + is_livefn := g.attr == 'live' + is_livemain := g.pref.is_livemain && is_livefn is_liveshared := g.pref.is_liveshared && is_livefn - is_livemode := g.pref.is_livemain || g.pref.is_liveshared - is_live_wrap := is_livefn && is_livemode + is_livemode := g.pref.is_livemain || g.pref.is_liveshared + is_live_wrap := is_livefn && is_livemode if is_livefn && !is_livemode { eprintln('INFO: compile with `v -live $g.pref.path `, if you want to use the [live] function ${it.name} .') } @@ -66,7 +66,6 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl) { // println(name) // } // type_name := g.table.Type_to_str(it.return_type) - // Live functions are protected by a mutex, because otherwise they // can be changed by the live reload thread, *while* they are // running, with unpredictable results (usually just crashing). @@ -89,7 +88,7 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl) { g.definitions.write('$type_name ${impl_fn_name}(') g.write('$type_name ${impl_fn_name}(') } - }else{ + } else { g.definitions.write('$type_name ${name}(') g.write('$type_name ${name}(') } @@ -102,7 +101,6 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl) { } g.definitions.writeln(');') g.writeln(') {') - if is_livemain { // The live function just calls its implementation dual, while ensuring // that the call is wrapped by the mutex lock & unlock calls. @@ -119,8 +117,9 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl) { live_fncall = '${type_name} res = ${live_fncall}' live_fnreturn = 'return res;' } - g.definitions.writeln('$type_name ${name}('+fn_args_list.join(', ')+');') - g.hotcode_definitions.writeln('$type_name ${name}('+fn_args_list.join(', ')+'){') + g.definitions.writeln('$type_name ${name}(' + fn_args_list.join(', ') + ');') + g.hotcode_definitions.writeln('$type_name ${name}(' + fn_args_list.join(', ') + + '){') g.hotcode_definitions.writeln(' pthread_mutex_lock(&live_fn_mutex);') g.hotcode_definitions.writeln(' $live_fncall') g.hotcode_definitions.writeln(' pthread_mutex_unlock(&live_fn_mutex);') @@ -148,7 +147,6 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl) { } } } - if g.pref.is_livemain && is_main { g.generate_hotcode_reloading_main_caller() } @@ -513,7 +511,7 @@ fn (mut g Gen) call_args(args []ast.CallArg, expected_types []table.Type) { exp_styp := g.typ(expected_types[arg_no]) // g.table.get_type_symbol(expected_types[arg_no]) styp := g.typ(arg.typ) // g.table.get_type_symbol(arg.typ) if exp_sym.kind == .interface_ { - g.write('/*i*/I_${styp}_to_${exp_styp}(') + g.write('I_${styp}_to_${exp_styp}(') is_interface = true } }