From 9c5a359de382e98b272e8c6a75e685d9710304f7 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 25 Oct 2019 21:57:32 +0300 Subject: [PATCH] fix V.js methods after the recent generics fix --- vlib/compiler/cc.v | 6 +++++- vlib/compiler/fn.v | 5 ++--- vlib/compiler/gen_c.v | 6 ++++-- vlib/compiler/gen_js.v | 8 ++++++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/vlib/compiler/cc.v b/vlib/compiler/cc.v index bc5aa40a45..0fa19bc0aa 100644 --- a/vlib/compiler/cc.v +++ b/vlib/compiler/cc.v @@ -19,13 +19,17 @@ fn (v mut V) cc() { // Just create a C/JavaScript file and exit // for example: `v -o v.c compiler` if v.out_name.ends_with('.c') || v.out_name.ends_with('.js') { - // Translating V code to JS by launching vjs + // Translating V code to JS by launching vjs. + // Using a separate process for V.js is for performance mostly, + // to avoid constant is_js checks. $if !js { if v.out_name.ends_with('.js') { vjs_path := vexe + 'js' dir := os.dir(vexe) if !os.file_exists(vjs_path) { println('V.js compiler not found, building...') + // Build V.js. Specifying `-os js` makes V include + // only _js.v files and ignore _c.v files. ret := os.system('$vexe -o $vjs_path -os js $dir/v.v') if ret == 0 { println('Done.') diff --git a/vlib/compiler/fn.v b/vlib/compiler/fn.v index a4eb69a412..3f546689ce 100644 --- a/vlib/compiler/fn.v +++ b/vlib/compiler/fn.v @@ -721,14 +721,13 @@ fn (p mut Parser) fn_call(f mut Fn, method_ph int, receiver_var, receiver_type s if !p.expr_var.is_changed { p.mark_var_changed(p.expr_var) } - met_call := p.gen_method_call(receiver, receiver_type, cgen_name, f.typ) - p.cgen.set_placeholder(method_ph, met_call) + p.gen_method_call(receiver, receiver_type, cgen_name, f.typ, method_ph) } else { // Normal function call p.gen('$cgen_name (') } - // foo() + // `foo()` // if f is generic, the name is changed to a suitable instance in dispatch_generic_fn_instance() // we then replace `cgen_name` with the instance's name generic := f.is_generic diff --git a/vlib/compiler/gen_c.v b/vlib/compiler/gen_c.v index 5aea8e1054..708ef60516 100644 --- a/vlib/compiler/gen_c.v +++ b/vlib/compiler/gen_c.v @@ -247,7 +247,9 @@ fn (table mut Table) fn_gen_name(f &Fn) string { return name } -fn (p mut Parser) gen_method_call(receiver &Var, receiver_type string, cgen_name string, ftyp string) string { +fn (p mut Parser) gen_method_call(receiver &Var, receiver_type string, + cgen_name string, ftyp string, method_ph int) +{ //mut cgen_name := p.table.fn_gen_name(f) mut method_call := cgen_name + ' (' // if receiver is key_mut or a ref (&), generate & for the first arg @@ -270,7 +272,7 @@ fn (p mut Parser) gen_method_call(receiver &Var, receiver_type string, cgen_name cast = '(voidptr) ' } } - return '$cast $method_call' + p.cgen.set_placeholder(method_ph, '$cast $method_call') } fn (p mut Parser) gen_array_at(typ_ string, is_arr0 bool, fn_ph int) { diff --git a/vlib/compiler/gen_js.v b/vlib/compiler/gen_js.v index 9323afd000..23c7e48545 100644 --- a/vlib/compiler/gen_js.v +++ b/vlib/compiler/gen_js.v @@ -91,9 +91,13 @@ fn (table &Table) fn_gen_name(f &Fn) string { return name } -fn (p mut Parser) gen_method_call(receiver_type, ftyp string, - cgen_name string, receiver Var,method_ph int) +//fn (p mut Parser) gen_method_call(receiver &Var, receiver_type string, + //ftyp string, cgen_name string, receiver Var,method_ph int) +fn (p mut Parser) gen_method_call(receiver &Var, receiver_type string, + cgen_name string, ftyp string, method_ph int) { + // TODO js methods have been broken from the start + //mut cgen_name := p.table.fn_gen_name(f) //mut method_call := cgen_name + '(' p.gen('.' + cgen_name.all_after('_') + '(')