mirror of
https://github.com/vlang/v.git
synced 2025-09-09 23:39:39 -04:00
parent
067c5b6486
commit
b5f022d804
@ -68,6 +68,7 @@ mut:
|
||||
cleanup strings.Builder
|
||||
cleanups map[string]strings.Builder // contents of `void _vcleanup(){}`
|
||||
gowrappers strings.Builder // all go callsite wrappers
|
||||
waiter_fn_definitions strings.Builder // waiter fns definitions
|
||||
auto_str_funcs strings.Builder // function bodies of all auto generated _str funcs
|
||||
dump_funcs strings.Builder // function bodies of all auto generated _str funcs
|
||||
pcs_declarations strings.Builder // -prof profile counter declarations for each function
|
||||
@ -390,6 +391,7 @@ pub fn gen(files []&ast.File, mut table ast.Table, pref_ &pref.Preferences) (str
|
||||
global_g.alias_definitions.write(g.alias_definitions) or { panic(err) }
|
||||
global_g.definitions.write(g.definitions) or { panic(err) }
|
||||
global_g.gowrappers.write(g.gowrappers) or { panic(err) }
|
||||
global_g.waiter_fn_definitions.write(g.waiter_fn_definitions) or { panic(err) }
|
||||
global_g.auto_str_funcs.write(g.auto_str_funcs) or { panic(err) }
|
||||
global_g.dump_funcs.write(g.auto_str_funcs) or { panic(err) }
|
||||
global_g.comptime_definitions.write(g.comptime_definitions) or { panic(err) }
|
||||
@ -593,6 +595,9 @@ pub fn gen(files []&ast.File, mut table ast.Table, pref_ &pref.Preferences) (str
|
||||
if interface_table.len > 0 {
|
||||
b.write_string2('\n// V interface table:\n', interface_table)
|
||||
}
|
||||
if g.waiter_fn_definitions.len > 0 {
|
||||
b.write_string2('\n// V gowrappers waiter fns:\n', g.waiter_fn_definitions.str())
|
||||
}
|
||||
if g.gowrappers.len > 0 {
|
||||
b.write_string2('\n// V gowrappers:\n', g.gowrappers.str())
|
||||
}
|
||||
@ -668,6 +673,7 @@ fn cgen_process_one_file_cb(mut p pool.PoolProcessor, idx int, wid int) &Gen {
|
||||
alias_definitions: strings.new_builder(100)
|
||||
definitions: strings.new_builder(100)
|
||||
gowrappers: strings.new_builder(100)
|
||||
waiter_fn_definitions: strings.new_builder(100)
|
||||
auto_str_funcs: strings.new_builder(100)
|
||||
comptime_definitions: strings.new_builder(100)
|
||||
pcs_declarations: strings.new_builder(100)
|
||||
@ -738,6 +744,7 @@ pub fn (mut g Gen) free_builders() {
|
||||
g.definitions.free()
|
||||
g.cleanup.free()
|
||||
g.gowrappers.free()
|
||||
g.waiter_fn_definitions.free()
|
||||
g.auto_str_funcs.free()
|
||||
g.dump_funcs.free()
|
||||
g.comptime_definitions.free()
|
||||
@ -1316,6 +1323,7 @@ fn (mut g Gen) register_thread_void_wait_call() {
|
||||
return
|
||||
}
|
||||
g.waiter_fns << '__v_thread_wait'
|
||||
g.waiter_fn_definitions.writeln('void __v_thread_wait(__v_thread thread);')
|
||||
}
|
||||
g.gowrappers.writeln('void __v_thread_wait(__v_thread thread) {')
|
||||
if g.pref.os == .windows {
|
||||
@ -1346,6 +1354,7 @@ fn (mut g Gen) register_thread_array_wait_call(eltyp string) string {
|
||||
if should_register {
|
||||
if is_void {
|
||||
g.register_thread_void_wait_call()
|
||||
g.waiter_fn_definitions.writeln('void ${fn_name}(${thread_arr_typ} a);')
|
||||
g.gowrappers.writeln('
|
||||
void ${fn_name}(${thread_arr_typ} a) {
|
||||
for (int i = 0; i < a.len; ++i) {
|
||||
@ -1355,6 +1364,7 @@ void ${fn_name}(${thread_arr_typ} a) {
|
||||
}
|
||||
}')
|
||||
} else {
|
||||
g.waiter_fn_definitions.writeln('${ret_typ} ${fn_name}(${thread_arr_typ} a);')
|
||||
g.gowrappers.writeln('
|
||||
${ret_typ} ${fn_name}(${thread_arr_typ} a) {
|
||||
${ret_typ} res = __new_array_with_default(a.len, a.len, sizeof(${eltyp}), 0);
|
||||
@ -1392,6 +1402,7 @@ fn (mut g Gen) register_thread_fixed_array_wait_call(node ast.CallExpr, eltyp st
|
||||
if should_register {
|
||||
if is_void {
|
||||
g.register_thread_void_wait_call()
|
||||
g.waiter_fn_definitions.writeln('void ${fn_name}(${thread_arr_typ} a);')
|
||||
g.gowrappers.writeln('
|
||||
void ${fn_name}(${thread_arr_typ} a) {
|
||||
for (int i = 0; i < ${len}; ++i) {
|
||||
@ -1401,6 +1412,7 @@ void ${fn_name}(${thread_arr_typ} a) {
|
||||
}
|
||||
}')
|
||||
} else {
|
||||
g.waiter_fn_definitions.writeln('${ret_typ} ${fn_name}(${thread_arr_typ} a);')
|
||||
g.gowrappers.writeln('
|
||||
${ret_typ} ${fn_name}(${thread_arr_typ} a) {
|
||||
${ret_typ} res = __new_array_with_default(${len}, ${len}, sizeof(${eltyp}), 0);
|
||||
|
@ -183,6 +183,7 @@ fn (mut g Gen) spawn_and_go_expr(node ast.SpawnExpr, mode SpawnGoMode) {
|
||||
}
|
||||
}
|
||||
if should_register {
|
||||
g.waiter_fn_definitions.writeln('${s_ret_typ} ${waiter_fn_name}(${gohandle_name} thread);')
|
||||
g.gowrappers.writeln('\n${s_ret_typ} ${waiter_fn_name}(${gohandle_name} thread) {')
|
||||
mut c_ret_ptr_ptr := 'NULL'
|
||||
if node.call_expr.return_type != ast.void_type {
|
||||
|
7
vlib/v/gen/c/testdata/waiter_fns_gen_nix.c.must_have
vendored
Normal file
7
vlib/v/gen/c/testdata/waiter_fns_gen_nix.c.must_have
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
// V gowrappers waiter fns:
|
||||
IError __v_thread_IError_wait(__v_thread_IError thread);
|
||||
Array_IError Array___v_thread_IError_wait(Array___v_thread_IError a);
|
||||
// V gowrappers:
|
||||
IError __v_thread_IError_wait(__v_thread_IError thread) {
|
||||
void* main__rsync_thread_wrapper(thread_arg_main__rsync *arg) {
|
||||
Array_IError Array___v_thread_IError_wait(Array___v_thread_IError a) {
|
34
vlib/v/gen/c/testdata/waiter_fns_gen_nix.vv
vendored
Normal file
34
vlib/v/gen/c/testdata/waiter_fns_gen_nix.vv
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
module main
|
||||
|
||||
fn rsync(a string, b string) IError {
|
||||
return none
|
||||
}
|
||||
|
||||
fn main() {
|
||||
options := {
|
||||
'a': 'b'
|
||||
'b': 'b'
|
||||
'c': 'b'
|
||||
'd': 'b'
|
||||
}
|
||||
|
||||
mut eflag := false
|
||||
mut threads := []thread IError{}
|
||||
|
||||
for srv, port in options {
|
||||
threads << go rsync(srv, port)
|
||||
}
|
||||
|
||||
awt := threads.wait()
|
||||
|
||||
for e in awt {
|
||||
if e.str() != 'none' {
|
||||
eflag = true
|
||||
eprintln(e.str())
|
||||
}
|
||||
}
|
||||
|
||||
if eflag {
|
||||
exit(1)
|
||||
}
|
||||
}
|
7
vlib/v/gen/c/testdata/waiter_fns_gen_windows.c.must_have
vendored
Normal file
7
vlib/v/gen/c/testdata/waiter_fns_gen_windows.c.must_have
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
// V gowrappers waiter fns:
|
||||
IError __v_thread_IError_wait(__v_thread_IError thread);
|
||||
Array_IError Array___v_thread_IError_wait(Array___v_thread_IError a);
|
||||
// V gowrappers:
|
||||
IError __v_thread_IError_wait(__v_thread_IError thread) {
|
||||
u32 main__rsync_thread_wrapper(thread_arg_main__rsync *arg) {
|
||||
Array_IError Array___v_thread_IError_wait(Array___v_thread_IError a) {
|
34
vlib/v/gen/c/testdata/waiter_fns_gen_windows.vv
vendored
Normal file
34
vlib/v/gen/c/testdata/waiter_fns_gen_windows.vv
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
module main
|
||||
|
||||
fn rsync(a string, b string) IError {
|
||||
return none
|
||||
}
|
||||
|
||||
fn main() {
|
||||
options := {
|
||||
'a': 'b'
|
||||
'b': 'b'
|
||||
'c': 'b'
|
||||
'd': 'b'
|
||||
}
|
||||
|
||||
mut eflag := false
|
||||
mut threads := []thread IError{}
|
||||
|
||||
for srv, port in options {
|
||||
threads << go rsync(srv, port)
|
||||
}
|
||||
|
||||
awt := threads.wait()
|
||||
|
||||
for e in awt {
|
||||
if e.str() != 'none' {
|
||||
eflag = true
|
||||
eprintln(e.str())
|
||||
}
|
||||
}
|
||||
|
||||
if eflag {
|
||||
exit(1)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user