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

105 lines
2.4 KiB
V
Raw Normal View History

2019-06-23 05:21:30 +03:00
// Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
2019-06-22 21:20:28 +03:00
module main
2019-08-29 01:52:32 +03:00
import (
compiler
benchmark
2019-10-18 20:49:34 +03:00
//time
2019-08-29 01:52:32 +03:00
)
2019-06-22 21:20:28 +03:00
fn main() {
2019-10-18 20:49:34 +03:00
//t := time.ticks()
//defer { println(time.ticks() - t) }
2019-07-03 14:20:43 +03:00
// There's no `flags` module yet, so args have to be parsed manually
args := compiler.env_vflags_and_os_args()
options := args.filter(it.starts_with('-'))
commands := args.filter(!it.starts_with('-'))
2019-06-22 21:20:28 +03:00
// Print the version and exit.
if '-v' in options || '--version' in options || 'version' in commands {
version_hash := compiler.vhash()
println('V $compiler.Version $version_hash')
2019-06-22 21:20:28 +03:00
return
}
else if '-h' in options || '--help' in options || 'help' in commands {
println(compiler.help_text)
2019-06-23 03:40:36 +03:00
return
2019-06-22 21:20:28 +03:00
}
else if 'translate' in commands {
2019-08-17 22:19:37 +03:00
println('Translating C to V will be available in V 0.3')
return
}
else if 'up' in commands {
compiler.update_v()
2019-08-17 22:19:37 +03:00
return
}
else if 'get' in commands {
println('use `v install` to install modules from vpm.vlang.io ')
2019-08-17 22:19:37 +03:00
return
}
else if 'symlink' in commands {
compiler.create_symlink()
2019-08-27 19:35:48 +03:00
return
}
else if 'install' in commands {
compiler.install_v(args)
return
2019-08-17 22:19:37 +03:00
}
// TODO quit if the v compiler is too old
// u := os.file_last_mod_unix('v')
2019-06-22 23:00:38 +03:00
// If there's no tmp path with current version yet, the user must be using a pre-built package
//
2019-06-22 21:20:28 +03:00
// Just fmt and exit
else if 'fmt' in commands {
compiler.vfmt(args)
2019-06-22 21:20:28 +03:00
return
}
else if 'test' in commands {
compiler.test_v()
return
}
// Generate the docs and exit
else if 'doc' in commands {
// v.gen_doc_html_for_module(args.last())
exit(0)
} else {
//println('unknown command/argument\n')
//println(compiler.help_text)
}
// Construct the V object from command line arguments
mut v := compiler.new_v(args)
if v.pref.is_verbose {
2019-06-22 21:20:28 +03:00
println(args)
}
2019-08-17 22:19:37 +03:00
if 'run' in args {
2019-08-09 23:37:31 +03:00
// always recompile for now, too error prone to skip recompilation otherwise
// for example for -repl usage, especially when piping lines to v
2019-08-17 22:19:37 +03:00
v.compile()
v.run_compiled_executable_and_exit()
}
2019-08-17 22:19:37 +03:00
// No args? REPL
if args.len < 2 || (args.len == 2 && args[1] == '-') || 'runrepl' in args {
compiler.run_repl()
return
}
mut tmark := benchmark.new_benchmark()
v.compile()
if v.pref.is_stats {
tmark.stop()
println( 'compilation took: ' + tmark.total_duration().str() + 'ms')
}
2019-08-17 22:19:37 +03:00
if v.pref.is_test {
v.run_compiled_executable_and_exit()
}
v.finalize_compilation()
}
2019-10-14 05:18:48 +03:00