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 (
|
2019-10-13 16:37:43 +03:00
|
|
|
compiler
|
2019-09-16 17:29:06 +03:00
|
|
|
benchmark
|
2019-08-29 01:52:32 +03:00
|
|
|
)
|
2019-06-22 21:20:28 +03:00
|
|
|
|
|
|
|
fn main() {
|
2019-07-03 14:20:43 +03:00
|
|
|
// There's no `flags` module yet, so args have to be parsed manually
|
2019-10-13 16:37:43 +03:00
|
|
|
args := compiler.env_vflags_and_os_args()
|
2019-06-22 21:20:28 +03:00
|
|
|
// Print the version and exit.
|
2019-07-01 22:51:51 +03:00
|
|
|
if '-v' in args || '--version' in args || 'version' in args {
|
2019-10-13 16:37:43 +03:00
|
|
|
version_hash := compiler.vhash()
|
|
|
|
println('V $compiler.Version $version_hash')
|
2019-06-22 21:20:28 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if '-h' in args || '--help' in args || 'help' in args {
|
2019-10-13 16:37:43 +03:00
|
|
|
println(compiler.HelpText)
|
2019-06-23 03:40:36 +03:00
|
|
|
return
|
2019-06-22 21:20:28 +03:00
|
|
|
}
|
2019-06-24 18:42:44 +03:00
|
|
|
if 'translate' in args {
|
2019-08-17 22:19:37 +03:00
|
|
|
println('Translating C to V will be available in V 0.3')
|
|
|
|
return
|
|
|
|
}
|
2019-07-31 05:40:38 +03:00
|
|
|
if 'up' in args {
|
2019-10-13 16:37:43 +03:00
|
|
|
compiler.update_v()
|
2019-08-17 22:19:37 +03:00
|
|
|
return
|
|
|
|
}
|
2019-08-01 02:34:28 +03:00
|
|
|
if 'get' in args {
|
2019-09-11 13:35:03 +03:00
|
|
|
println('use `v install` to install modules from vpm.vlang.io ')
|
2019-08-17 22:19:37 +03:00
|
|
|
return
|
|
|
|
}
|
2019-08-27 19:35:48 +03:00
|
|
|
if 'symlink' in args {
|
2019-10-13 16:37:43 +03:00
|
|
|
compiler.create_symlink()
|
2019-08-27 19:35:48 +03:00
|
|
|
return
|
|
|
|
}
|
2019-08-01 02:34:28 +03:00
|
|
|
if 'install' in args {
|
2019-10-13 16:37:43 +03:00
|
|
|
compiler.install_v(args)
|
2019-08-10 13:21:31 +03:00
|
|
|
return
|
2019-08-17 22:19:37 +03:00
|
|
|
}
|
2019-10-13 16:37:43 +03:00
|
|
|
// TODO quit if the v compiler is too old
|
2019-07-02 01:00:27 +03:00
|
|
|
// 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-09-29 04:54:12 +03:00
|
|
|
//
|
2019-06-22 21:20:28 +03:00
|
|
|
// Just fmt and exit
|
2019-08-17 22:19:37 +03:00
|
|
|
if 'fmt' in args {
|
2019-10-13 16:37:43 +03:00
|
|
|
compiler.vfmt(args)
|
2019-06-22 21:20:28 +03:00
|
|
|
return
|
|
|
|
}
|
2019-10-09 06:01:43 +03:00
|
|
|
if 'test' in args {
|
2019-10-13 16:37:43 +03:00
|
|
|
compiler.test_v()
|
2019-09-16 17:29:06 +03:00
|
|
|
return
|
|
|
|
}
|
2019-10-09 06:01:43 +03:00
|
|
|
// Construct the V object from command line arguments
|
2019-10-13 16:37:43 +03:00
|
|
|
mut v := compiler.new_v(args)
|
2019-06-30 23:44:15 +03:00
|
|
|
if v.pref.is_verbose {
|
2019-06-22 21:20:28 +03:00
|
|
|
println(args)
|
|
|
|
}
|
|
|
|
// Generate the docs and exit
|
2019-08-17 22:19:37 +03:00
|
|
|
if 'doc' in args {
|
2019-06-30 23:44:15 +03:00
|
|
|
// v.gen_doc_html_for_module(args.last())
|
2019-06-23 11:12:09 +03:00
|
|
|
exit(0)
|
2019-06-22 21:20:28 +03:00
|
|
|
}
|
2019-08-17 22:19:37 +03:00
|
|
|
|
2019-08-06 19:04:55 +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()
|
2019-08-06 19:04:55 +03:00
|
|
|
v.run_compiled_executable_and_exit()
|
|
|
|
}
|
2019-08-17 22:19:37 +03:00
|
|
|
|
2019-09-04 11:50:44 +03:00
|
|
|
// No args? REPL
|
|
|
|
if args.len < 2 || (args.len == 2 && args[1] == '-') || 'runrepl' in args {
|
2019-10-13 16:37:43 +03:00
|
|
|
compiler.run_repl()
|
2019-09-04 11:50:44 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-10-07 08:51:26 +03:00
|
|
|
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
|
|
|
|
2019-08-06 19:04:55 +03:00
|
|
|
if v.pref.is_test {
|
|
|
|
v.run_compiled_executable_and_exit()
|
|
|
|
}
|
2019-10-12 00:54:25 +03:00
|
|
|
|
2019-10-13 16:37:43 +03:00
|
|
|
v.finalize_compilation()
|
2019-10-12 00:54:25 +03:00
|
|
|
}
|
2019-10-14 05:18:48 +03:00
|
|
|
|