mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
make V compile itself using cached modules: ~0.3s speed-up
This commit is contained in:
parent
2ee252be5f
commit
4d941b5fdb
@ -106,25 +106,29 @@ fn (v mut V) cc() {
|
||||
a << f
|
||||
}
|
||||
|
||||
libs := ''// builtin.o os.o http.o etc
|
||||
mut libs := ''// builtin.o os.o http.o etc
|
||||
if v.pref.build_mode == .build_module {
|
||||
a << '-c'
|
||||
}
|
||||
else if v.pref.build_mode == .default_mode {
|
||||
else if v.pref.is_debug {
|
||||
libs = '$v_modules_path/vlib/builtin.o ' +
|
||||
'$v_modules_path/vlib/strings.o '+
|
||||
'$v_modules_path/vlib/math.o '
|
||||
/*
|
||||
// TODO
|
||||
libs = '$v_modules_path/vlib/builtin.o'
|
||||
if !os.file_exists(libs) {
|
||||
println('object file `$libs` not found')
|
||||
exit(1)
|
||||
}
|
||||
*/
|
||||
for imp in v.table.imports {
|
||||
if imp == 'webview' {
|
||||
continue
|
||||
}
|
||||
libs += ' "$v_modules_path/vlib/${imp}.o"'
|
||||
path := '"$v_modules_path/vlib/${imp}.o"'
|
||||
if os.file_exists(path) {
|
||||
libs += ' ' + path
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
if v.pref.sanitize {
|
||||
a << '-fsanitize=leak'
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
|
||||
/*
|
||||
.vh generation logic.
|
||||
.vh files contains only function signatures, consts, and types.
|
||||
.vh files contain only function signatures, consts, and types.
|
||||
They are used together with pre-compiled modules.
|
||||
*/
|
||||
|
||||
@ -95,7 +95,11 @@ fn v_type_str(typ_ string) string {
|
||||
return '[]' + typ.right(6)
|
||||
}
|
||||
if typ.contains('__') {
|
||||
return typ.all_after('__')
|
||||
opt := typ.starts_with('?')
|
||||
typ = typ.all_after('__')
|
||||
if opt {
|
||||
typ = '?' + typ
|
||||
}
|
||||
}
|
||||
return typ
|
||||
}
|
||||
@ -213,8 +217,8 @@ fn (v &V) generate_vh() {
|
||||
// Methods
|
||||
file.writeln('\n// Methods //////////////////')
|
||||
for _, typ in v.table.typesmap {
|
||||
if typ.mod != v.mod { //&& typ.mod != '' {
|
||||
//println('skipping method typ $typ.name mod=$typ.mod')
|
||||
if typ.mod != v.mod && !(v.mod == 'builtin' && typ.mod == '') {
|
||||
println('skipping method typ $typ.name mod=$typ.mod')
|
||||
continue
|
||||
}
|
||||
for method in typ.methods {
|
||||
|
@ -509,6 +509,8 @@ fn (p mut Parser) const_decl() {
|
||||
// .vh files don't have const values, just types: `const (a int)`
|
||||
typ = p.get_type()
|
||||
p.table.register_const(name, typ, p.mod)
|
||||
p.cgen.consts << ('extern ' +
|
||||
p.table.cgen_name_type_pair(name, typ)) + ';'
|
||||
continue // Don't generate C code when building a .vh file
|
||||
} else {
|
||||
p.check_space(.assign)
|
||||
@ -524,7 +526,9 @@ fn (p mut Parser) const_decl() {
|
||||
// TODO hack
|
||||
// cur_line has const's value right now. if it's just a number, then optimize generation:
|
||||
// output a #define so that we don't pollute the binary with unnecessary global vars
|
||||
if is_compile_time_const(p.cgen.cur_line) {
|
||||
// Do not do this when building a module, otherwise the consts
|
||||
// will not be accessible.
|
||||
if p.pref.build_mode != .build_module && is_compile_time_const(p.cgen.cur_line) {
|
||||
p.cgen.consts << '#define $name $p.cgen.cur_line'
|
||||
p.cgen.resetln('')
|
||||
p.fgenln('')
|
||||
|
Loading…
Reference in New Issue
Block a user