v/v.v

96 lines
2.1 KiB
V
Raw Normal View History

2019-06-23 04:21:30 +02: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 20:20:28 +02:00
module main
2019-08-29 00:52:32 +02:00
import (
compiler
benchmark
2019-08-29 00:52:32 +02:00
)
2019-06-22 20:20:28 +02:00
fn main() {
2019-07-03 13:20:43 +02:00
// There's no `flags` module yet, so args have to be parsed manually
args := compiler.env_vflags_and_os_args()
2019-06-22 20:20:28 +02:00
// Print the version and exit.
if '-v' in args || '--version' in args || 'version' in args {
version_hash := compiler.vhash()
println('V $compiler.Version $version_hash')
2019-06-22 20:20:28 +02:00
return
}
if '-h' in args || '--help' in args || 'help' in args {
println(compiler.HelpText)
2019-06-23 02:40:36 +02:00
return
2019-06-22 20:20:28 +02:00
}
2019-06-24 17:42:44 +02:00
if 'translate' in args {
2019-08-17 21:19:37 +02:00
println('Translating C to V will be available in V 0.3')
return
}
2019-07-31 04:40:38 +02:00
if 'up' in args {
compiler.update_v()
2019-08-17 21:19:37 +02:00
return
}
2019-08-01 01:34:28 +02:00
if 'get' in args {
println('use `v install` to install modules from vpm.vlang.io ')
2019-08-17 21:19:37 +02:00
return
}
2019-08-27 18:35:48 +02:00
if 'symlink' in args {
compiler.create_symlink()
2019-08-27 18:35:48 +02:00
return
}
2019-08-01 01:34:28 +02:00
if 'install' in args {
compiler.install_v(args)
return
2019-08-17 21:19:37 +02:00
}
// TODO quit if the v compiler is too old
// u := os.file_last_mod_unix('v')
2019-06-22 22:00:38 +02:00
// If there's no tmp path with current version yet, the user must be using a pre-built package
//
2019-06-22 20:20:28 +02:00
// Just fmt and exit
2019-08-17 21:19:37 +02:00
if 'fmt' in args {
compiler.vfmt(args)
2019-06-22 20:20:28 +02:00
return
}
if 'test' in args {
compiler.test_v()
return
}
// Construct the V object from command line arguments
mut v := compiler.new_v(args)
if v.pref.is_verbose {
2019-06-22 20:20:28 +02:00
println(args)
}
// Generate the docs and exit
2019-08-17 21:19:37 +02:00
if 'doc' in args {
// v.gen_doc_html_for_module(args.last())
exit(0)
2019-06-22 20:20:28 +02:00
}
2019-08-17 21:19:37 +02:00
if 'run' in args {
2019-08-09 22:37:31 +02: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 21:19:37 +02:00
v.compile()
v.run_compiled_executable_and_exit()
}
2019-08-17 21:19:37 +02: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 21:19:37 +02:00
if v.pref.is_test {
v.run_compiled_executable_and_exit()
}
v.finalize_compilation()
}
2019-10-14 04:18:48 +02:00