compiler: stage 1 of printing shortened commit on v --version

pull/1920/head
Delyan Angelov 2019-09-10 23:08:48 +03:00 committed by Alexander Medvednikov
parent 03b3278369
commit 08262b5c43
3 changed files with 26 additions and 5 deletions

View File

@ -100,13 +100,13 @@ mut:
building_v bool
}
fn main() {
// There's no `flags` module yet, so args have to be parsed manually
args := env_vflags_and_os_args()
// Print the version and exit.
if '-v' in args || '--version' in args || 'version' in args {
println('V $Version')
versionhash := vhash()
println('V $Version $versionhash')
return
}
if '-h' in args || '--help' in args || 'help' in args {
@ -231,6 +231,12 @@ fn (v mut V) compile() {
cgen.genln('#define VDEBUG (1) ')
}
if v.pref.building_v {
cgen.genln('#ifndef V_COMMIT_HASH')
cgen.genln('#define V_COMMIT_HASH "' + vhash() + '"')
cgen.genln('#endif')
}
cgen.genln(CommonCHeaders)
v.generate_hotcode_reloading_declarations()
@ -1008,3 +1014,14 @@ pub fn cerror(s string) {
os.flush_stdout()
exit(1)
}
// TODO: this must be uncommented on stage 2, after V_COMMIT_HASH is always present and preserved
fn vhash() string {
/*
mut buf := [50]byte
buf[0] = 0
C.snprintf(buf, 50, '%s', C.V_COMMIT_HASH )
return tos_clone(buf)
*/
return '0000000'
}

View File

@ -51,8 +51,9 @@ fn (r mut Repl) function_call(line string) bool {
}
fn repl_help() {
versionhash := vhash()
println('
V $Version
V $Version $versionhash
help Displays this information.
Ctrl-C, Ctrl-D, exit Exits the REPL.
clear Clears the screen.
@ -60,7 +61,8 @@ V $Version
}
fn run_repl() []string {
println('V $Version')
versionhash := vhash()
println('V $Version $versionhash')
println('Use Ctrl-C or `exit` to exit')
file := '.vrepl.v'
temp_file := '.vrepl_temp.v'

View File

@ -401,6 +401,7 @@ fn (s mut Scanner) scan() ScanRes {
// @FILE => will be substituted with the path of the V source file
// @LINE => will be substituted with the V line number where it appears (as a string).
// @COLUMN => will be substituted with the column where it appears (as a string).
// @VHASH => will be substituted with the shortened commit hash of the V compiler (as a string).
// This allows things like this:
// println( 'file: ' + @FILE + ' | line: ' + @LINE + ' | fn: ' + @FN)
// ... which is useful while debugging/tracing
@ -408,6 +409,7 @@ fn (s mut Scanner) scan() ScanRes {
if name == 'FILE' { return scan_res(.str, os.realpath(s.file_path)) }
if name == 'LINE' { return scan_res(.str, (s.line_nr+1).str()) }
if name == 'COLUMN' { return scan_res(.str, (s.current_column()).str()) }
if name == 'VHASH' { return scan_res(.str, vhash()) }
if !is_key(name) {
s.error('@ must be used before keywords (e.g. `@type string`)')
}