mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
![Delyan Angelov](/assets/img/avatar_default.png)
* Move compiler/ under vlib/compiler/ . * Add a minimal compiler/main.v driver program. * Cleanup compiler/main.v . * Make most compiler tests pass again. * Apply the fix by @joe-conigliaro , so that the rest of the compiler tests are fixed too. * Thanks to @avitkauskas, now the vlib/vcompiler/tests/str_gen_test.v test does not need to be special cased anymore. * Reapply @joe-conigliaro fix for vgen.
96 lines
2.1 KiB
V
Executable File
96 lines
2.1 KiB
V
Executable File
// 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.
|
|
|
|
module main
|
|
|
|
import (
|
|
compiler
|
|
benchmark
|
|
)
|
|
|
|
fn main() {
|
|
// There's no `flags` module yet, so args have to be parsed manually
|
|
args := compiler.env_vflags_and_os_args()
|
|
// 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')
|
|
return
|
|
}
|
|
if '-h' in args || '--help' in args || 'help' in args {
|
|
println(compiler.HelpText)
|
|
return
|
|
}
|
|
if 'translate' in args {
|
|
println('Translating C to V will be available in V 0.3')
|
|
return
|
|
}
|
|
if 'up' in args {
|
|
compiler.update_v()
|
|
return
|
|
}
|
|
if 'get' in args {
|
|
println('use `v install` to install modules from vpm.vlang.io ')
|
|
return
|
|
}
|
|
if 'symlink' in args {
|
|
compiler.create_symlink()
|
|
return
|
|
}
|
|
if 'install' in args {
|
|
compiler.install_v(args)
|
|
return
|
|
}
|
|
// TODO quit if the v compiler is too old
|
|
// u := os.file_last_mod_unix('v')
|
|
// If there's no tmp path with current version yet, the user must be using a pre-built package
|
|
//
|
|
// Just fmt and exit
|
|
if 'fmt' in args {
|
|
compiler.vfmt(args)
|
|
return
|
|
}
|
|
if 'test' in args {
|
|
compiler.test_v()
|
|
return
|
|
}
|
|
// Construct the V object from command line arguments
|
|
mut v := compiler.new_v(args)
|
|
v.pref.building_v = true
|
|
if v.pref.is_verbose {
|
|
println(args)
|
|
}
|
|
// Generate the docs and exit
|
|
if 'doc' in args {
|
|
// v.gen_doc_html_for_module(args.last())
|
|
exit(0)
|
|
}
|
|
|
|
if 'run' in args {
|
|
// always recompile for now, too error prone to skip recompilation otherwise
|
|
// for example for -repl usage, especially when piping lines to v
|
|
v.compile()
|
|
v.run_compiled_executable_and_exit()
|
|
}
|
|
|
|
// 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')
|
|
}
|
|
|
|
if v.pref.is_test {
|
|
v.run_compiled_executable_and_exit()
|
|
}
|
|
|
|
v.finalize_compilation()
|
|
}
|