live: fix reloader.v

pull/5114/head
Alexander Medvednikov 2020-05-29 04:36:08 +02:00
parent 81b44dc2c9
commit 96fb7901b3
2 changed files with 18 additions and 20 deletions

View File

@ -13,7 +13,7 @@ pub fn new_live_reload_info(original string, vexe string, vopts string, live_fn_
file_base := os.file_name(original).replace('.v', '')
so_dir := os.cache_dir()
so_extension := dl.dl_ext
/* $if msvc { so_extension = '.dll' } $else { so_extension = '.so' } */
// $if msvc { so_extension = '.dll' } $else { so_extension = '.so' }
return &live.LiveReloadInfo{
original: original
vexe: vexe
@ -36,11 +36,11 @@ pub fn start_reloader(r mut live.LiveReloadInfo) {
// If that fails, the program would crash anyway, just provide
// an error message to the user and exit:
r.reloads++
_ := compile_and_reload_shared_lib(r) or {
_ := compile_and_reload_shared_lib(mut r) or {
eprintln( err )
exit(1)
}
go reloader(r)
go reloader(mut r)
}
[if debuglive]
@ -50,25 +50,25 @@ fn elog(r mut live.LiveReloadInfo, s string){
fn compile_and_reload_shared_lib(r mut live.LiveReloadInfo) ?bool {
sw := time.new_stopwatch()
new_lib_path := compile_lib(r) or {
new_lib_path := compile_lib(mut r) or {
return error('errors while compiling $r.original')
}
elog(r,'> compile_and_reload_shared_lib compiled: ${new_lib_path}')
load_lib(r, new_lib_path )
elog(mut r,'> compile_and_reload_shared_lib compiled: ${new_lib_path}')
load_lib(mut r, new_lib_path )
r.reload_time_ms = int(sw.elapsed().milliseconds())
return true
}
fn compile_lib(r mut live.LiveReloadInfo) ?string {
new_lib_path, new_lib_path_with_extension := current_shared_library_path(r)
new_lib_path, new_lib_path_with_extension := current_shared_library_path(mut r)
cmd := '$r.vexe $r.vopts -o $new_lib_path $r.original'
elog(r,'> compilation cmd: $cmd')
elog(mut r,'> compilation cmd: $cmd')
cwatch := time.new_stopwatch()
recompilation_result := os.exec( cmd ) or {
eprintln('recompilation failed')
return none
}
elog(r,'compilation took: ${cwatch.elapsed().milliseconds()}ms')
elog(mut r,'compilation took: ${cwatch.elapsed().milliseconds()}ms')
if recompilation_result.exit_code != 0 {
eprintln('recompilation error:')
eprintln( recompilation_result.output )
@ -88,24 +88,24 @@ fn current_shared_library_path(r mut live.LiveReloadInfo) (string, string) {
}
fn load_lib(r mut live.LiveReloadInfo, new_lib_path string) {
elog(r,'live mutex locking...')
elog(mut r,'live mutex locking...')
C.pthread_mutex_lock(r.live_fn_mutex)
elog(r,'live mutex locked')
elog(mut r,'live mutex locked')
//
if r.cb_locked_before != voidptr(0) {
r.cb_locked_before( r )
}
//
protected_load_lib(r, new_lib_path)
protected_load_lib(mut r, new_lib_path)
//
r.reloads_ok++
if r.cb_locked_after != voidptr(0) {
r.cb_locked_after( r )
}
//
elog(r,'live mutex unlocking...')
elog(mut r,'live mutex unlocking...')
C.pthread_mutex_unlock(r.live_fn_mutex)
elog(r,'live mutex unlocked')
elog(mut r,'live mutex unlocked')
}
fn protected_load_lib(r mut live.LiveReloadInfo, new_lib_path string) {
@ -119,7 +119,7 @@ fn protected_load_lib(r mut live.LiveReloadInfo, new_lib_path string) {
exit(1)
}
r.live_linkfn( r.live_lib )
elog(r,'> load_lib OK, new live_lib: $r.live_lib')
elog(mut r,'> load_lib OK, new live_lib: $r.live_lib')
// removing the .so file from the filesystem after dlopen-ing
// it is safe, since it will still be mapped in memory
os.rm( new_lib_path )
@ -141,7 +141,7 @@ fn reloader(r mut live.LiveReloadInfo) {
if r.cb_before != voidptr(0) {
r.cb_before( r )
}
compile_and_reload_shared_lib(r) or {
compile_and_reload_shared_lib(mut r) or {
if r.cb_compile_failed != voidptr(0) {
r.cb_compile_failed( r )
}

View File

@ -31,11 +31,9 @@ pub fn (mut p Parser) call_expr(language table.Language, mod string) ast.CallExp
p.next() // `<`
p.expr_mod = ''
mut generic_type = p.parse_type()
if generic_type == table.t_type {
// Handle `foo<T>()`
// generic_type = p.cur_gen_type
}
p.check(.gt) // `>`
// In case of `foo<T>()`
// T is unwrapped and registered in the checker.
if generic_type != table.t_type {
p.table.register_fn_gen_type(fn_name, generic_type)
}