Skip to content

Commit

Permalink
all: use arguments() instead of os.args in some files
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Feb 20, 2025
1 parent 0dd7698 commit a045bb0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
15 changes: 8 additions & 7 deletions cmd/tools/fast/fast.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import time
import arrays
import log

const args = arguments()
const warmup_samples = 2

const max_samples = 20
Expand Down Expand Up @@ -54,7 +55,7 @@ fn main() {
if vdir.contains('/tmp/cirrus-ci-build') {
ccompiler_path = 'clang'
}
if os.args.contains('-clang') {
if args.contains('-clang') {
ccompiler_path = 'clang'
}
elog('fast_dir: ${fast_dir} | vdir: ${vdir} | compiler: ${ccompiler_path}')
Expand All @@ -68,7 +69,7 @@ fn main() {
os.create('table.html')!
}

if !os.args.contains('-noupdate') {
if !args.contains('-noupdate') {
elog('Fetching updates...')
ret := lsystem('${vdir}/v up')
if ret != 0 {
Expand All @@ -83,7 +84,7 @@ fn main() {
uploaded_index := os.read_file('fast.vlang.io/index.html')!
if uploaded_index.contains('>${commit}<') {
elog('NOTE: commit ${commit} had been benchmarked already.')
if !os.args.contains('-force') {
if !args.contains('-force') {
elog('nothing more to do')
return
}
Expand All @@ -98,21 +99,21 @@ fn main() {
elog('Benchmarking commit ${commit} , with commit message: "${message}", commit_date: ${commit_date}, date: ${date}')

// build an optimized V
if os.args.contains('-do-not-rebuild-vprod') {
if args.contains('-do-not-rebuild-vprod') {
if !os.exists('vprod') {
elog('Exiting, since if you use `-do-not-rebuild-vprod`, you should already have a `${vdir}/vprod` executable, but it is missing!')
return
}
} else {
elog(' Building vprod...')
if os.args.contains('-noprod') {
if args.contains('-noprod') {
lexec('./v -o vprod cmd/v') // for faster debugging
} else {
lexec('./v -o vprod -prod -prealloc cmd/v')
}
}

if !os.args.contains('-do-not-rebuild-caches') {
if !args.contains('-do-not-rebuild-caches') {
elog('clearing caches...')
// cache vlib modules
lexec('${vdir}/v wipe-cache')
Expand Down Expand Up @@ -163,7 +164,7 @@ fn main() {
res.close()

// upload the result to github pages
if os.args.contains('-upload') {
if args.contains('-upload') {
$if freebsd {
// Note: tcc currently can not compile vpm on FreeBSD, due to its dependence on net.ssl and net.mbedtls, so force using clang instead:
elog('FreeBSD: compiling the VPM tool with clang...')
Expand Down
5 changes: 3 additions & 2 deletions cmd/tools/vself.v
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import os
import os.cmdline
import v.util.recompilation

const is_debug = os.args.contains('-debug')
const args_ = arguments()
const is_debug = args_.contains('-debug')

// support a renamed `v` executable too:
const vexe = os.getenv_opt('VEXE') or { @VEXE }
Expand All @@ -24,7 +25,7 @@ fn main() {
recompilation.must_be_enabled(vroot, 'Please install V from source, to use `${vexe_name} self` .')
os.chdir(vroot)!
os.setenv('VCOLORS', 'always', true)
mut args := os.args[1..].filter(it != 'self')
mut args := args_[1..].filter(it != 'self')
if args.len == 0 || ('-cc' !in args && '-prod' !in args && '-parallel-cc' !in args) {
// compiling by default, i.e. `v self`:
uos := os.user_os()
Expand Down
10 changes: 6 additions & 4 deletions cmd/tools/vup.v
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ struct App {
skip_current bool // skip the current hash check, enabling easier testing on the same commit, without using docker etc
}

const args = arguments()

fn new_app() App {
return App{
is_verbose: '-v' in os.args
is_prod: '-prod' in os.args
is_verbose: '-v' in args
is_prod: '-prod' in args
vexe: vexe
vroot: vroot
skip_v_self: '-skip_v_self' in os.args
skip_current: '-skip_current' in os.args
skip_v_self: '-skip_v_self' in args
skip_current: '-skip_current' in args
}
}

Expand Down
11 changes: 3 additions & 8 deletions examples/fibonacci.v
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
// This program displays the fibonacci sequence
import os
const args = arguments()

fn main() {
// Check for user input
if os.args.len != 2 {
if args.len != 2 {
println('usage: fibonacci [rank]')

return
}

// Parse first argument and cast it to int

stop := os.args[1].int()
stop := args[1].int()
// Can only calculate correctly until rank 92
if stop > 92 {
println('rank must be 92 or less')
return
}

// Three consecutive terms of the sequence
mut a := i64(0)
mut b := i64(0)
Expand All @@ -29,7 +25,6 @@ fn main() {
b = c
// Compute the new term
c = a + b

// Print the new term
println(c)
}
Expand Down

0 comments on commit a045bb0

Please sign in to comment.