fix V.js methods after the recent generics fix

pull/2356/head
Alexander Medvednikov 2019-10-25 21:57:32 +03:00
parent 280c7d396c
commit 9c5a359de3
4 changed files with 17 additions and 8 deletions

View File

@ -19,13 +19,17 @@ fn (v mut V) cc() {
// Just create a C/JavaScript file and exit // Just create a C/JavaScript file and exit
// for example: `v -o v.c compiler` // for example: `v -o v.c compiler`
if v.out_name.ends_with('.c') || v.out_name.ends_with('.js') { 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 !js {
if v.out_name.ends_with('.js') { if v.out_name.ends_with('.js') {
vjs_path := vexe + 'js' vjs_path := vexe + 'js'
dir := os.dir(vexe) dir := os.dir(vexe)
if !os.file_exists(vjs_path) { if !os.file_exists(vjs_path) {
println('V.js compiler not found, building...') 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') ret := os.system('$vexe -o $vjs_path -os js $dir/v.v')
if ret == 0 { if ret == 0 {
println('Done.') println('Done.')

View File

@ -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 { if !p.expr_var.is_changed {
p.mark_var_changed(p.expr_var) p.mark_var_changed(p.expr_var)
} }
met_call := p.gen_method_call(receiver, receiver_type, cgen_name, f.typ) p.gen_method_call(receiver, receiver_type, cgen_name, f.typ, method_ph)
p.cgen.set_placeholder(method_ph, met_call)
} else { } else {
// Normal function call // Normal function call
p.gen('$cgen_name (') p.gen('$cgen_name (')
} }
// foo<Bar>() // `foo<Bar>()`
// if f is generic, the name is changed to a suitable instance in dispatch_generic_fn_instance() // 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 // we then replace `cgen_name` with the instance's name
generic := f.is_generic generic := f.is_generic

View File

@ -247,7 +247,9 @@ fn (table mut Table) fn_gen_name(f &Fn) string {
return name 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 cgen_name := p.table.fn_gen_name(f)
mut method_call := cgen_name + ' (' mut method_call := cgen_name + ' ('
// if receiver is key_mut or a ref (&), generate & for the first arg // 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) ' 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) { fn (p mut Parser) gen_array_at(typ_ string, is_arr0 bool, fn_ph int) {

View File

@ -91,9 +91,13 @@ fn (table &Table) fn_gen_name(f &Fn) string {
return name return name
} }
fn (p mut Parser) gen_method_call(receiver_type, ftyp string, //fn (p mut Parser) gen_method_call(receiver &Var, receiver_type string,
cgen_name string, receiver Var,method_ph int) //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 cgen_name := p.table.fn_gen_name(f)
//mut method_call := cgen_name + '(' //mut method_call := cgen_name + '('
p.gen('.' + cgen_name.all_after('_') + '(') p.gen('.' + cgen_name.all_after('_') + '(')