diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d7fdb211ff..fdee2908b9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,6 +25,8 @@ jobs: run: | ./v vet vlib/sqlite ./v vet vlib/v + ./v vet cmd/v + ./v vet cmd/tools - name: v fmt -verify run: | ./v fmt -verify vlib/builtin/array.v diff --git a/cmd/tools/fast/fast.v b/cmd/tools/fast/fast.v index f9d914eac8..3c257059dc 100644 --- a/cmd/tools/fast/fast.v +++ b/cmd/tools/fast/fast.v @@ -1,7 +1,6 @@ // Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved. // Use of this source code is governed by an MIT license // that can be found in the LICENSE file. - import os import time @@ -23,18 +22,17 @@ fn main() { mut commit_hash := exec('git rev-parse HEAD') commit_hash = commit_hash[..8] if os.exists('last_commit.txt') { - last_commit := os.read_file('last_commit.txt')? + last_commit := os.read_file('last_commit.txt') ? if last_commit.trim_space() == commit_hash.trim_space() { println('No new commits to benchmark. Commit $commit_hash has already been processed.') return } commit_hash = last_commit.trim_space() } - if !os.exists('table.html') { - os.create('table.html')? + os.create('table.html') ? } - mut table := os.read_file('table.html')? + mut table := os.read_file('table.html') ? /* // Do nothing if it's already been processed. if table.contains(commit_hash) { @@ -67,14 +65,13 @@ fn main() { diff2 := measure('$vdir/vprod -cc clang -o v2 $vdir/cmd/v', 'v2') diff3 := measure('$vdir/vprod -x64 $vdir/cmd/tools/1mil.v', 'x64 1mil') diff4 := measure('$vdir/vprod -cc clang $vdir/examples/hello_world.v', 'hello.v') - //println('Building V took ${diff}ms') + // println('Building V took ${diff}ms') commit_date := exec('git log -n1 --pretty="format:%at" $commit') date := time.unix(commit_date.int()) - mut out := os.create('table.html')? + mut out := os.create('table.html') ? // Place the new row on top - table = - ' - ${date.format()} + table = ' + $date.format() $commit $message ${diff1}ms @@ -82,32 +79,34 @@ fn main() { ${diff3}ms ${diff4}ms \n' + - table.trim_space() + table.trim_space() out.writeln(table) out.close() // Regenerate index.html - header := os.read_file('header.html')? - footer := os.read_file('footer.html')? - mut res := os.create('index.html')? + header := os.read_file('header.html') ? + footer := os.read_file('footer.html') ? + mut res := os.create('index.html') ? res.writeln(header) res.writeln(table) res.writeln(footer) res.close() } exec('git checkout master') - os.write_file('last_commit.txt', commits[commits.len-1])? + os.write_file('last_commit.txt', commits[commits.len - 1]) ? } fn exec(s string) string { - e := os.exec(s) or { panic(err) } + e := os.exec(s) or { + panic(err) + } return e.output.trim_right('\r\n') } // returns milliseconds -fn measure(cmd, description string) int { +fn measure(cmd string, description string) int { println(' Measuring $description') println(' Warming up...') - for _ in 0..3 { + for _ in 0 .. 3 { exec(cmd) } println(' Building...') diff --git a/cmd/tools/oldv.v b/cmd/tools/oldv.v index b1fbe7f64c..afdbb8f121 100644 --- a/cmd/tools/oldv.v +++ b/cmd/tools/oldv.v @@ -6,25 +6,25 @@ import vgit const ( tool_version = '0.0.3' tool_description = ' Checkout an old V and compile it as it was on specific commit. - This tool is useful, when you want to discover when something broke. - It is also useful, when you just want to experiment with an older historic V. - - The VCOMMIT argument can be a git commitish like HEAD or master and so on. - When oldv is used with git bisect, you probably want to give HEAD. For example: - git bisect start - git bisect bad - git checkout known_good_commit - git bisect good - ## Now git will automatically checkout a middle commit between the bad and the good - cmd/tools/oldv HEAD --command="run commands in oldv folder, to verify if the commit is good or bad" - ## See what the result is, and either do: ... - git bisect good - ## ... or do: - git bisect bad - ## Now you just repeat the above steps, each time running oldv with the same command, then mark the result as good or bad, - ## until you find the commit, where the problem first occurred. - ## When you finish, do not forget to do: - git bisect reset' +| This tool is useful, when you want to discover when something broke. +| It is also useful, when you just want to experiment with an older historic V. +| +| The VCOMMIT argument can be a git commitish like HEAD or master and so on. +| When oldv is used with git bisect, you probably want to give HEAD. For example: +| git bisect start +| git bisect bad +| git checkout known_good_commit +| git bisect good +| ## Now git will automatically checkout a middle commit between the bad and the good +| cmd/tools/oldv HEAD --command="run commands in oldv folder, to verify if the commit is good or bad" +| ## See what the result is, and either do: ... +| git bisect good +| ## ... or do: +| git bisect bad +| ## Now you just repeat the above steps, each time running oldv with the same command, then mark the result as good or bad, +| ## until you find the commit, where the problem first occurred. +| ## When you finish, do not forget to do: +| git bisect reset'.strip_margin() ) struct Context { diff --git a/cmd/tools/performance_compare.v b/cmd/tools/performance_compare.v index 54c0cdf146..9656d9b95e 100644 --- a/cmd/tools/performance_compare.v +++ b/cmd/tools/performance_compare.v @@ -6,9 +6,9 @@ import vgit const ( tool_version = '0.0.5' tool_description = " Compares V executable size and performance, - between 2 commits from V\'s local git history. - When only one commit is given, it is compared to master. - " +| between 2 commits from V\'s local git history. +| When only one commit is given, it is compared to master. +| ".strip_margin() ) struct Context { diff --git a/cmd/tools/vrepl.v b/cmd/tools/vrepl.v index 81a621aa05..cf5780f58b 100644 --- a/cmd/tools/vrepl.v +++ b/cmd/tools/vrepl.v @@ -87,12 +87,12 @@ fn (r &Repl) current_source_code(should_add_temp_lines bool) string { fn repl_help() { println(util.full_v_version(false)) println(' - help Displays this information. - list Show the program so far. - reset Clears the accumulated program, so you can start a fresh. - Ctrl-C, Ctrl-D, exit Exits the REPL. - clear Clears the screen. -') + |help Displays this information. + |list Show the program so far. + |reset Clears the accumulated program, so you can start a fresh. + |Ctrl-C, Ctrl-D, exit Exits the REPL. + |clear Clears the screen. +'.strip_margin()) } fn run_repl(workdir string, vrepl_prefix string) { diff --git a/vlib/readline/readline_linux.c.v b/vlib/readline/readline_linux.c.v index d0a5acf2cf..eb5e70fcd2 100644 --- a/vlib/readline/readline_linux.c.v +++ b/vlib/readline/readline_linux.c.v @@ -11,7 +11,6 @@ import os #include #include - // Defines actions to execute enum Action { eof @@ -134,7 +133,7 @@ pub fn (mut r Readline) read_line_utf8(prompt string) ?ustring { // Returns the string from the utf8 ustring pub fn (mut r Readline) read_line(prompt string) ?string { - s := r.read_line_utf8(prompt)? + s := r.read_line_utf8(prompt) ? return s.s } @@ -142,7 +141,7 @@ pub fn (mut r Readline) read_line(prompt string) ?string { // Returns utf8 based ustring pub fn read_line_utf8(prompt string) ?ustring { mut r := Readline{} - s := r.read_line_utf8(prompt)? + s := r.read_line_utf8(prompt) ? return s } @@ -150,7 +149,7 @@ pub fn read_line_utf8(prompt string) ?ustring { // Return string from utf8 ustring pub fn read_line(prompt string) ?string { mut r := Readline{} - s := r.read_line(prompt)? + s := r.read_line(prompt) ? return s } @@ -181,8 +180,7 @@ fn (r Readline) analyse(c int) Action { Action.insert_character } else { Action.nothing - } - } + } } } } @@ -286,7 +284,7 @@ fn get_screen_columns() int { return cols } -fn shift_cursor(xpos, yoffset int) { +fn shift_cursor(xpos int, yoffset int) { if yoffset != 0 { if yoffset > 0 { term.cursor_down(yoffset) @@ -295,10 +293,10 @@ fn shift_cursor(xpos, yoffset int) { } } // Absolute X position - print('\x1b[${xpos+1}G') + print('\x1b[${xpos + 1}G') } -fn calculate_screen_position(x_in, y_in, screen_columns, char_count int, inp []int) []int { +fn calculate_screen_position(x_in int, y_in int, screen_columns int, char_count int, inp []int) []int { mut out := inp mut x := x_in mut y := y_in @@ -451,7 +449,10 @@ fn (mut r Readline) switch_overwrite() { } fn (mut r Readline) clear_screen() { - term.set_cursor_position(x:1, y:1) + term.set_cursor_position({ + x: 1 + y: 1 + }) term.erase_clear() r.refresh_line() } @@ -481,7 +482,6 @@ fn (mut r Readline) history_next() { fn (mut r Readline) suspend() { is_standalone := os.getenv('VCHILD') != 'true' - r.disable_raw_mode() if !is_standalone { // We have to SIGSTOP the parent v process