mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
pref: make minor performance related changes / simplify (#21379)
This commit is contained in:
parent
08da3cde2a
commit
e4bbd73da3
1 changed files with 37 additions and 41 deletions
|
@ -337,13 +337,12 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
|
||||||
// for i, arg in args {
|
// for i, arg in args {
|
||||||
for i := 0; i < args.len; i++ {
|
for i := 0; i < args.len; i++ {
|
||||||
arg := args[i]
|
arg := args[i]
|
||||||
current_args := args[i..].clone()
|
|
||||||
match arg {
|
match arg {
|
||||||
'-wasm-validate' {
|
'-wasm-validate' {
|
||||||
res.wasm_validate = true
|
res.wasm_validate = true
|
||||||
}
|
}
|
||||||
'-wasm-stack-top' {
|
'-wasm-stack-top' {
|
||||||
res.wasm_stack_top = cmdline.option(current_args, arg, res.wasm_stack_top.str()).int()
|
res.wasm_stack_top = cmdline.option(args[i..], arg, res.wasm_stack_top.str()).int()
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
'-apk' {
|
'-apk' {
|
||||||
|
@ -351,7 +350,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
|
||||||
res.build_options << arg
|
res.build_options << arg
|
||||||
}
|
}
|
||||||
'-arch' {
|
'-arch' {
|
||||||
target_arch := cmdline.option(current_args, '-arch', '')
|
target_arch := cmdline.option(args[i..], '-arch', '')
|
||||||
i++
|
i++
|
||||||
target_arch_kind := arch_from_string(target_arch) or {
|
target_arch_kind := arch_from_string(target_arch) or {
|
||||||
eprintln_exit('unknown architecture target `${target_arch}`')
|
eprintln_exit('unknown architecture target `${target_arch}`')
|
||||||
|
@ -360,7 +359,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
|
||||||
res.build_options << '${arg} ${target_arch}'
|
res.build_options << '${arg} ${target_arch}'
|
||||||
}
|
}
|
||||||
'-assert' {
|
'-assert' {
|
||||||
assert_mode := cmdline.option(current_args, '-assert', '')
|
assert_mode := cmdline.option(args[i..], '-assert', '')
|
||||||
match assert_mode {
|
match assert_mode {
|
||||||
'aborts' {
|
'aborts' {
|
||||||
res.assert_failure_mode = .aborts
|
res.assert_failure_mode = .aborts
|
||||||
|
@ -395,12 +394,11 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
|
||||||
res.is_help = true
|
res.is_help = true
|
||||||
}
|
}
|
||||||
'-q' {
|
'-q' {
|
||||||
if command_pos != -1 {
|
if command_pos == -1 {
|
||||||
// a -q flag after a command is for the command, not for v
|
// a -q flag after a command is for the command, not for v
|
||||||
continue
|
|
||||||
}
|
|
||||||
res.is_quiet = true
|
res.is_quiet = true
|
||||||
}
|
}
|
||||||
|
}
|
||||||
'-v', '-V', '--version', '-version' {
|
'-v', '-V', '--version', '-version' {
|
||||||
if command_pos == -1 {
|
if command_pos == -1 {
|
||||||
// Version flags after a command are intended for the command, not for V itself.
|
// Version flags after a command are intended for the command, not for V itself.
|
||||||
|
@ -415,7 +413,6 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
|
||||||
}
|
}
|
||||||
'-progress' {
|
'-progress' {
|
||||||
// processed by testing tools in cmd/tools/modules/testing/common.v
|
// processed by testing tools in cmd/tools/modules/testing/common.v
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
//'-i64' {
|
//'-i64' {
|
||||||
// res.use_64_int = true
|
// res.use_64_int = true
|
||||||
|
@ -444,11 +441,11 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
|
||||||
}
|
}
|
||||||
'-e' {
|
'-e' {
|
||||||
res.is_eval_argument = true
|
res.is_eval_argument = true
|
||||||
res.eval_argument = cmdline.option(current_args, '-e', '')
|
res.eval_argument = cmdline.option(args[i..], '-e', '')
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
'-gc' {
|
'-gc' {
|
||||||
gc_mode := cmdline.option(current_args, '-gc', '')
|
gc_mode := cmdline.option(args[i..], '-gc', '')
|
||||||
match gc_mode {
|
match gc_mode {
|
||||||
'none' {
|
'none' {
|
||||||
res.gc_mode = .no_gc
|
res.gc_mode = .no_gc
|
||||||
|
@ -556,7 +553,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
|
||||||
res.trace_calls = true
|
res.trace_calls = true
|
||||||
}
|
}
|
||||||
'-trace-fns' {
|
'-trace-fns' {
|
||||||
value := cmdline.option(current_args, arg, '')
|
value := cmdline.option(args[i..], arg, '')
|
||||||
res.build_options << arg
|
res.build_options << arg
|
||||||
res.build_options << value
|
res.build_options << value
|
||||||
trace_fns := value.split(',')
|
trace_fns := value.split(',')
|
||||||
|
@ -610,13 +607,13 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
|
||||||
res.build_options << arg
|
res.build_options << arg
|
||||||
}
|
}
|
||||||
'-prof', '-profile' {
|
'-prof', '-profile' {
|
||||||
res.profile_file = cmdline.option(current_args, arg, '-')
|
res.profile_file = cmdline.option(args[i..], arg, '-')
|
||||||
res.is_prof = true
|
res.is_prof = true
|
||||||
res.build_options << '${arg} ${res.profile_file}'
|
res.build_options << '${arg} ${res.profile_file}'
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
'-profile-fns' {
|
'-profile-fns' {
|
||||||
profile_fns := cmdline.option(current_args, arg, '').split(',')
|
profile_fns := cmdline.option(args[i..], arg, '').split(',')
|
||||||
if profile_fns.len > 0 {
|
if profile_fns.len > 0 {
|
||||||
res.profile_fns << profile_fns
|
res.profile_fns << profile_fns
|
||||||
}
|
}
|
||||||
|
@ -672,32 +669,32 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
|
||||||
res.show_depgraph = true
|
res.show_depgraph = true
|
||||||
}
|
}
|
||||||
'-run-only' {
|
'-run-only' {
|
||||||
res.run_only = cmdline.option(current_args, arg, os.getenv('VTEST_ONLY_FN')).split_any(',')
|
res.run_only = cmdline.option(args[i..], arg, os.getenv('VTEST_ONLY_FN')).split_any(',')
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
'-exclude' {
|
'-exclude' {
|
||||||
patterns := cmdline.option(current_args, arg, '').split_any(',')
|
patterns := cmdline.option(args[i..], arg, '').split_any(',')
|
||||||
res.exclude << patterns
|
res.exclude << patterns
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
'-test-runner' {
|
'-test-runner' {
|
||||||
res.test_runner = cmdline.option(current_args, arg, res.test_runner)
|
res.test_runner = cmdline.option(args[i..], arg, res.test_runner)
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
'-dump-c-flags' {
|
'-dump-c-flags' {
|
||||||
res.dump_c_flags = cmdline.option(current_args, arg, '-')
|
res.dump_c_flags = cmdline.option(args[i..], arg, '-')
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
'-dump-modules' {
|
'-dump-modules' {
|
||||||
res.dump_modules = cmdline.option(current_args, arg, '-')
|
res.dump_modules = cmdline.option(args[i..], arg, '-')
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
'-dump-files' {
|
'-dump-files' {
|
||||||
res.dump_files = cmdline.option(current_args, arg, '-')
|
res.dump_files = cmdline.option(args[i..], arg, '-')
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
'-dump-defines' {
|
'-dump-defines' {
|
||||||
res.dump_defines = cmdline.option(current_args, arg, '-')
|
res.dump_defines = cmdline.option(args[i..], arg, '-')
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
'-experimental' {
|
'-experimental' {
|
||||||
|
@ -710,9 +707,9 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
|
||||||
res.use_os_system_to_run = true
|
res.use_os_system_to_run = true
|
||||||
}
|
}
|
||||||
'-macosx-version-min' {
|
'-macosx-version-min' {
|
||||||
res.macosx_version_min = cmdline.option(current_args, arg, res.macosx_version_min)
|
res.macosx_version_min = cmdline.option(args[i..], arg, res.macosx_version_min)
|
||||||
i++
|
|
||||||
res.build_options << '${arg} ${res.macosx_version_min}'
|
res.build_options << '${arg} ${res.macosx_version_min}'
|
||||||
|
i++
|
||||||
}
|
}
|
||||||
'-nocache' {
|
'-nocache' {
|
||||||
res.use_cache = false
|
res.use_cache = false
|
||||||
|
@ -779,7 +776,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
|
||||||
res.build_options << '${arg}'
|
res.build_options << '${arg}'
|
||||||
}
|
}
|
||||||
'-os' {
|
'-os' {
|
||||||
target_os := cmdline.option(current_args, '-os', '')
|
target_os := cmdline.option(args[i..], '-os', '')
|
||||||
i++
|
i++
|
||||||
target_os_kind := os_from_string(target_os) or {
|
target_os_kind := os_from_string(target_os) or {
|
||||||
if target_os == 'cross' {
|
if target_os == 'cross' {
|
||||||
|
@ -801,50 +798,49 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
|
||||||
res.build_options << '${arg} ${target_os}'
|
res.build_options << '${arg} ${target_os}'
|
||||||
}
|
}
|
||||||
'-printfn' {
|
'-printfn' {
|
||||||
res.printfn_list << cmdline.option(current_args, '-printfn', '').split(',')
|
res.printfn_list << cmdline.option(args[i..], '-printfn', '').split(',')
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
'-cflags' {
|
'-cflags' {
|
||||||
res.cflags += ' ' + cmdline.option(current_args, '-cflags', '')
|
res.cflags += ' ' + cmdline.option(args[i..], '-cflags', '')
|
||||||
res.build_options << '${arg} "${res.cflags.trim_space()}"'
|
res.build_options << '${arg} "${res.cflags.trim_space()}"'
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
'-ldflags' {
|
'-ldflags' {
|
||||||
res.ldflags += ' ' + cmdline.option(current_args, '-ldflags', '')
|
res.ldflags += ' ' + cmdline.option(args[i..], '-ldflags', '')
|
||||||
res.build_options << '${arg} "${res.ldflags.trim_space()}"'
|
res.build_options << '${arg} "${res.ldflags.trim_space()}"'
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
'-d', '-define' {
|
'-d', '-define' {
|
||||||
if current_args.len > 1 {
|
if define := args[i..][1] {
|
||||||
define := current_args[1]
|
|
||||||
res.parse_define(define)
|
res.parse_define(define)
|
||||||
}
|
}
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
'-message-limit' {
|
'-message-limit' {
|
||||||
res.message_limit = cmdline.option(current_args, arg, '5').int()
|
res.message_limit = cmdline.option(args[i..], arg, '5').int()
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
'-thread-stack-size' {
|
'-thread-stack-size' {
|
||||||
res.thread_stack_size = cmdline.option(current_args, arg, res.thread_stack_size.str()).int()
|
res.thread_stack_size = cmdline.option(args[i..], arg, res.thread_stack_size.str()).int()
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
'-cc' {
|
'-cc' {
|
||||||
res.ccompiler = cmdline.option(current_args, '-cc', 'cc')
|
res.ccompiler = cmdline.option(args[i..], '-cc', 'cc')
|
||||||
res.build_options << '${arg} "${res.ccompiler}"'
|
res.build_options << '${arg} "${res.ccompiler}"'
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
'-c++' {
|
'-c++' {
|
||||||
res.cppcompiler = cmdline.option(current_args, '-c++', 'c++')
|
res.cppcompiler = cmdline.option(args[i..], '-c++', 'c++')
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
'-checker-match-exhaustive-cutoff-limit' {
|
'-checker-match-exhaustive-cutoff-limit' {
|
||||||
res.checker_match_exhaustive_cutoff_limit = cmdline.option(current_args,
|
res.checker_match_exhaustive_cutoff_limit = cmdline.option(args[i..],
|
||||||
arg, '10').int()
|
arg, '10').int()
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
'-o', '-output' {
|
'-o', '-output' {
|
||||||
res.out_name = cmdline.option(current_args, arg, '')
|
res.out_name = cmdline.option(args[i..], arg, '')
|
||||||
if res.out_name.ends_with('.js') {
|
if res.out_name.ends_with('.js') {
|
||||||
res.backend = .js_node
|
res.backend = .js_node
|
||||||
res.output_cross_c = true
|
res.output_cross_c = true
|
||||||
|
@ -860,7 +856,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
|
||||||
res.is_o = true
|
res.is_o = true
|
||||||
}
|
}
|
||||||
'-b', '-backend' {
|
'-b', '-backend' {
|
||||||
sbackend := cmdline.option(current_args, arg, 'c')
|
sbackend := cmdline.option(args[i..], arg, 'c')
|
||||||
res.build_options << '${arg} ${sbackend}'
|
res.build_options << '${arg} ${sbackend}'
|
||||||
b := backend_from_string(sbackend) or {
|
b := backend_from_string(sbackend) or {
|
||||||
eprintln_exit('Unknown V backend: ${sbackend}\nValid -backend choices are: c, go, interpret, js, js_node, js_browser, js_freestanding, native, wasm')
|
eprintln_exit('Unknown V backend: ${sbackend}\nValid -backend choices are: c, go, interpret, js, js_node, js_browser, js_freestanding, native, wasm')
|
||||||
|
@ -880,19 +876,19 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
|
||||||
res.output_es5 = true
|
res.output_es5 = true
|
||||||
}
|
}
|
||||||
'-path' {
|
'-path' {
|
||||||
path := cmdline.option(current_args, '-path', '')
|
path := cmdline.option(args[i..], '-path', '')
|
||||||
res.build_options << '${arg} "${path}"'
|
res.build_options << '${arg} "${path}"'
|
||||||
res.lookup_path = path.replace('|', os.path_delimiter).split(os.path_delimiter)
|
res.lookup_path = path.replace('|', os.path_delimiter).split(os.path_delimiter)
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
'-bare-builtin-dir' {
|
'-bare-builtin-dir' {
|
||||||
bare_builtin_dir := cmdline.option(current_args, arg, '')
|
bare_builtin_dir := cmdline.option(args[i..], arg, '')
|
||||||
res.build_options << '${arg} "${bare_builtin_dir}"'
|
res.build_options << '${arg} "${bare_builtin_dir}"'
|
||||||
res.bare_builtin_dir = bare_builtin_dir
|
res.bare_builtin_dir = bare_builtin_dir
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
'-custom-prelude' {
|
'-custom-prelude' {
|
||||||
path := cmdline.option(current_args, '-custom-prelude', '')
|
path := cmdline.option(args[i..], '-custom-prelude', '')
|
||||||
res.build_options << '${arg} ${path}'
|
res.build_options << '${arg} ${path}'
|
||||||
prelude := os.read_file(path) or {
|
prelude := os.read_file(path) or {
|
||||||
eprintln_exit('cannot open custom prelude file: ${err}')
|
eprintln_exit('cannot open custom prelude file: ${err}')
|
||||||
|
@ -901,15 +897,15 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
'-raw-vsh-tmp-prefix' {
|
'-raw-vsh-tmp-prefix' {
|
||||||
res.raw_vsh_tmp_prefix = cmdline.option(current_args, arg, '')
|
res.raw_vsh_tmp_prefix = cmdline.option(args[i..], arg, '')
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
'-cmain' {
|
'-cmain' {
|
||||||
res.cmain = cmdline.option(current_args, '-cmain', '')
|
res.cmain = cmdline.option(args[i..], '-cmain', '')
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
'-line-info' {
|
'-line-info' {
|
||||||
res.line_info = cmdline.option(current_args, arg, '')
|
res.line_info = cmdline.option(args[i..], arg, '')
|
||||||
res.parse_line_info(res.line_info)
|
res.parse_line_info(res.line_info)
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue