From e1dd4c19b5f442d0baff51067bb368084e2b36cf Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 10 Oct 2019 22:27:22 +0300 Subject: [PATCH] compiler: cache modules if they are not built yet --- compiler/cc.v | 15 +++++---------- compiler/fn.v | 4 ++-- compiler/parser.v | 3 ++- vlib/builtin/map.v | 1 + vlib/os/os.v | 1 + 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/compiler/cc.v b/compiler/cc.v index 87ff86fc7f..f4cdf9936d 100644 --- a/compiler/cc.v +++ b/compiler/cc.v @@ -111,20 +111,14 @@ fn (v mut V) cc() { a << '-c' } else if v.pref.is_debug { + vexe := os.executable() builtin_o_path := '$v_modules_path/vlib/builtin.o' if os.file_exists(builtin_o_path) { libs = builtin_o_path } else { - println('$builtin_o_path not found... build module builtin') + println('$builtin_o_path not found... building module builtin') + os.system('$vexe build module vlib/builtin') } - // '$v_modules_path/vlib/strings.o '+ - // '$v_modules_path/vlib/math.o ' - /* - if !os.file_exists(libs) { - println('object file `$libs` not found') - exit(1) - } - */ for imp in v.table.imports { if imp == 'webview' { continue @@ -134,7 +128,8 @@ fn (v mut V) cc() { if os.file_exists(path) { libs += ' ' + path } else { - println('$path not found... build module $imp') + println('$path not found... building module $imp') + os.system('$vexe build module vlib/$imp') } } } diff --git a/compiler/fn.v b/compiler/fn.v index aae73ffa48..2f93d6e4e5 100644 --- a/compiler/fn.v +++ b/compiler/fn.v @@ -419,8 +419,8 @@ fn (p mut Parser) fn_decl() { p.genln('pthread_mutex_lock(&live_fn_mutex);') } - if f.name == 'main__main' || f.name == 'main' || f.name == 'WinMain' { - if p.pref.is_test && !p.scanner.file_path.contains('/volt') { + if f.name in ['main__main', 'main', 'WinMain'] { + if p.pref.is_test { p.error_with_token_index('tests cannot have function `main`', f.fn_name_token_idx) } } diff --git a/compiler/parser.v b/compiler/parser.v index 7ba70d6145..1fbc4bceee 100644 --- a/compiler/parser.v +++ b/compiler/parser.v @@ -1686,6 +1686,7 @@ fn (p mut Parser) bterm() string { // also called on *, &, @, . (enum) fn (p mut Parser) name_expr() string { + //println('n') p.has_immutable_field = false p.is_const_literal = false ph := p.cgen.add_placeholder() @@ -2958,7 +2959,7 @@ fn (p mut Parser) map_init() string { mut i := 0 for { key := p.lit - keys_gen += 'tos2((byte*)"$key"), ' + keys_gen += 'tos3("$key"), ' p.check(.str) p.check(.colon) p.cgen.start_tmp() diff --git a/vlib/builtin/map.v b/vlib/builtin/map.v index 55e75bf969..c467b8cab2 100644 --- a/vlib/builtin/map.v +++ b/vlib/builtin/map.v @@ -177,6 +177,7 @@ pub fn (m &map) keys() []string { } fn (m map) get(key string, out voidptr) bool { + //println('g') if m.root == 0 { return false } diff --git a/vlib/os/os.v b/vlib/os/os.v index 92d7b5c069..fc1ee57e4f 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -333,6 +333,7 @@ pub fn exec(cmd string) ?Result { } } +// `system` works like `exec()`, but only returns a return code. pub fn system(cmd string) int { mut ret := int(0) $if windows {