2020-04-15 23:16:49 +02:00
|
|
|
module builder
|
|
|
|
|
|
|
|
import (
|
|
|
|
time
|
|
|
|
os
|
|
|
|
v.parser
|
|
|
|
v.pref
|
|
|
|
v.gen
|
|
|
|
v.gen.js
|
|
|
|
)
|
|
|
|
|
|
|
|
pub fn (b mut Builder) gen_js(v_files []string) string {
|
|
|
|
t0 := time.ticks()
|
|
|
|
b.parsed_files = parser.parse_files(v_files, b.table, b.pref, b.global_scope)
|
|
|
|
b.parse_imports()
|
|
|
|
t1 := time.ticks()
|
|
|
|
parse_time := t1 - t0
|
|
|
|
b.info('PARSE: ${parse_time}ms')
|
|
|
|
b.checker.check_files(b.parsed_files)
|
|
|
|
t2 := time.ticks()
|
|
|
|
check_time := t2 - t1
|
|
|
|
b.info('CHECK: ${check_time}ms')
|
|
|
|
if b.checker.nr_errors > 0 {
|
|
|
|
exit(1)
|
|
|
|
}
|
|
|
|
res := js.gen(b.parsed_files, b.table, b.pref)
|
|
|
|
t3 := time.ticks()
|
|
|
|
gen_time := t3 - t2
|
|
|
|
b.info('JS GEN: ${gen_time}ms')
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn (b mut Builder) build_js(v_files []string, out_file string) {
|
|
|
|
b.out_name_js = out_file
|
|
|
|
b.info('build_js($out_file)')
|
|
|
|
mut f := os.create(out_file) or {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
f.writeln(b.gen_js(v_files))
|
|
|
|
f.close()
|
|
|
|
}
|
|
|
|
|
2020-04-17 21:17:19 +02:00
|
|
|
pub fn (b mut Builder) compile_js() {
|
2020-04-15 23:16:49 +02:00
|
|
|
//TODO files << b.get_builtin_files()
|
2020-04-17 21:17:19 +02:00
|
|
|
files := b.get_user_files()
|
2020-04-15 23:16:49 +02:00
|
|
|
b.set_module_lookup_paths()
|
2020-04-17 21:17:19 +02:00
|
|
|
if b.pref.is_verbose {
|
2020-04-15 23:16:49 +02:00
|
|
|
println('all .v files:')
|
|
|
|
println(files)
|
|
|
|
}
|
2020-04-17 21:17:19 +02:00
|
|
|
b.build_js(files, b.pref.out_name + '.js')
|
2020-04-15 23:16:49 +02:00
|
|
|
//TODO run the file
|
|
|
|
}
|