1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

compiler: module init function & init consts for cached modules

This commit is contained in:
joe-conigliaro
2019-10-12 09:17:37 +11:00
committed by Alexander Medvednikov
parent c7e47e6884
commit 51388fea75
11 changed files with 164 additions and 59 deletions

View File

@@ -106,17 +106,27 @@ fn v_type_str(typ_ string) string {
fn (v &V) generate_vh() {
println('\n\n\n\nGenerating a V header file for module `$v.mod`')
dir := '$v_modules_path${os.PathSeparator}$v.mod'
mod_path := v.mod.replace('.', os.PathSeparator)
dir := '$v_modules_path${os.PathSeparator}$mod_path'
path := dir + '.vh'
if !os.dir_exists(dir) {
os.mkdir(dir)
// create recursive
mut mkpath := v_modules_path
for subdir in mod_path.split(os.PathSeparator) {
mkpath += os.PathSeparator + subdir
if !os.dir_exists(mkpath) {
os.mkdir(mkpath)
}
}
// os.mkdir(os.realpath(dir))
}
println(path)
file := os.create(path) or { panic(err) }
// Consts
mod_def := if v.mod.contains('.') { v.mod.all_after('.') } else { v.mod }
file.writeln('// $v.mod module header \n')
file.writeln('module $v.mod')
file.writeln('module $mod_def')
file.writeln('// Consts')
if v.table.consts.len > 0 {
file.writeln('const (')