1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
Alexander Medvednikov
2019-12-20 00:29:37 +03:00
parent b6fe2ebc0b
commit 6210984c97
54 changed files with 1757 additions and 1993 deletions

View File

@ -7,10 +7,10 @@ fn (v &V) generate_hotcode_reloading_compiler_flags() []string {
mut a := []string
if v.pref.is_live || v.pref.is_so {
// See 'man dlopen', and test running a GUI program compiled with -live
if (v.os == .linux || os.user_os() == 'linux'){
if (v.os == .linux || os.user_os() == 'linux') {
a << '-rdynamic'
}
if (v.os == .mac || os.user_os() == 'mac'){
if (v.os == .mac || os.user_os() == 'mac') {
a << '-flat_namespace'
}
}
@ -26,7 +26,8 @@ fn (v &V) generate_hotcode_reloading_declarations() {
if v.pref.is_live {
cgen.genln('pthread_mutex_t live_fn_mutex = PTHREAD_MUTEX_INITIALIZER;')
}
} else {
}
else {
if v.pref.is_so {
cgen.genln('HANDLE live_fn_mutex;')
cgen.genln('
@ -45,7 +46,9 @@ void pthread_mutex_unlock(HANDLE *m) {
}
fn (v &V) generate_hotcode_reloading_main_caller() {
if !v.pref.is_live { return }
if !v.pref.is_live {
return
}
// We are in live code reload mode, so start the .so loader in the background
mut cgen := v.cgen
cgen.genln('')
@ -57,9 +60,10 @@ fn (v &V) generate_hotcode_reloading_main_caller() {
cgen.genln(' load_so(live_library_name);')
cgen.genln(' pthread_t _thread_so;')
cgen.genln(' pthread_create(&_thread_so , NULL, (void *)&reload_so, live_library_name);')
} else {
}
else {
// windows:
so_name := file_base + if v.pref.ccompiler == 'msvc' {'.dll'} else {'.so'}
so_name := file_base + if v.pref.ccompiler == 'msvc' { '.dll' } else { '.so' }
cgen.genln(' char *live_library_name = "$so_name";')
cgen.genln(' live_fn_mutex = CreateMutexA(0, 0, 0);')
cgen.genln(' load_so(live_library_name);')
@ -70,7 +74,6 @@ fn (v &V) generate_hotcode_reloading_main_caller() {
fn (v &V) generate_hot_reload_code() {
mut cgen := v.cgen
// Hot code reloading
if v.pref.is_live {
mut file := os.realpath(v.dir)
@ -79,17 +82,14 @@ fn (v &V) generate_hot_reload_code() {
// Need to build .so file before building the live application
// The live app needs to load this .so file on initialization.
mut vexe := os.args[0]
if os.user_os() == 'windows' {
vexe = cescaped_path(vexe)
file = cescaped_path(file)
}
mut msvc := ''
if v.pref.ccompiler == 'msvc' {
msvc = '-cc msvc'
}
so_debug_flag := if v.pref.is_debug { '-g' } else { '' }
cmd_compile_shared_library := '$vexe $msvc $so_debug_flag -o $file_base -solive -shared $file'
if v.pref.show_c_cmd {
@ -100,7 +100,6 @@ fn (v &V) generate_hot_reload_code() {
diff := time.ticks() - ticks
println('compiling shared library took $diff ms')
println('=========\n')
cgen.genln('
void lfnmutex_print(char *s){
@ -111,7 +110,6 @@ void lfnmutex_print(char *s){
}
}
')
if v.os != .windows {
cgen.genln('
void* live_lib=0;
@ -153,12 +151,10 @@ int load_so(byteptr path) {
return 0;
}
')
for so_fn in cgen.so_fns {
cgen.genln('$so_fn = (void *)GetProcAddress(live_lib, "$so_fn"); ')
}
}
cgen.genln('return 1;
}
@ -218,10 +214,10 @@ void reload_so() {
time__sleep_ms(100);
}
}
' )
')
}
if v.pref.is_so {
cgen.genln(' int load_so(byteptr path) { return 0; }')
}
}