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

v: make js hello world work

This commit is contained in:
Abdullah Atta
2020-05-21 18:17:16 +05:00
committed by GitHub
parent a9999ee10d
commit 9888bacad5
13 changed files with 70 additions and 836 deletions

View File

@@ -59,7 +59,12 @@ fn (mut b Builder) run_compiled_executable_and_exit() {
if b.pref.is_verbose {
println('============ running $b.pref.out_name ============')
}
mut cmd := '"${b.pref.out_name}"'
if b.pref.backend == .js {
cmd = 'node "${b.pref.out_name}.js"'
}
for arg in b.pref.run_args {
// Determine if there are spaces in the parameters
if arg.index_byte(` `) > 0 {
@@ -139,7 +144,7 @@ pub fn (v Builder) get_builtin_files() []string {
if v.pref.is_bare {
return v.v_files_from_dir(os.join_path(location, 'builtin', 'bare'))
}
$if js {
if v.pref.backend == .js {
return v.v_files_from_dir(os.join_path(location, 'builtin', 'js'))
}
return v.v_files_from_dir(os.join_path(location, 'builtin'))

View File

@@ -38,13 +38,22 @@ pub fn (mut b Builder) build_js(v_files []string, out_file string) {
}
pub fn (mut b Builder) compile_js() {
// TODO files << b.get_builtin_files()
files := b.get_user_files()
mut files := b.get_user_files()
files << b.get_builtin_files()
b.set_module_lookup_paths()
if b.pref.is_verbose {
println('all .v files:')
println(files)
}
b.build_js(files, b.pref.out_name + '.js')
// TODO run the file
}
fn (mut b Builder) run_js() {
cmd := 'node ' + b.pref.out_name + '.js'
res := os.exec(cmd) or {
println('JS compilation failed.')
verror(err)
return
}
println(res.output)
}