From 0ff74dae63127d912e4f6933b6296fd120147bb0 Mon Sep 17 00:00:00 2001 From: yuyi Date: Sun, 18 Sep 2022 23:07:16 +0800 Subject: [PATCH] vrepl: simplify and cleanup vrepl (#15807) --- cmd/tools/vrepl.v | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/cmd/tools/vrepl.v b/cmd/tools/vrepl.v index 02c7c8290b..524713e101 100644 --- a/cmd/tools/vrepl.v +++ b/cmd/tools/vrepl.v @@ -31,13 +31,12 @@ mut: eval_func_lines []string // same line of the `VSTARTUP` file, but used to test fn type } -const is_stdin_a_pipe = (os.is_atty(0) == 0) - -const vexe = os.getenv('VEXE') - -const vstartup = os.getenv('VSTARTUP') - -const repl_folder = os.join_path(os.temp_dir(), 'v', 'repl') +const ( + is_stdin_a_pipe = os.is_atty(0) == 0 + vexe = os.getenv('VEXE') + vstartup = os.getenv('VSTARTUP') + repl_folder = os.join_path(os.temp_dir(), 'v', 'repl') +) enum FnType { @none @@ -293,14 +292,13 @@ fn run_repl(workdir string, vrepl_prefix string) int { print('\n') print_output(result.output) } - file := os.join_path(workdir, '.${vrepl_prefix}vrepl.v') temp_file := os.join_path(workdir, '.${vrepl_prefix}vrepl_temp.v') mut prompt := '>>> ' defer { if !is_stdin_a_pipe { println('') } - cleanup_files([file, temp_file]) + cleanup_files(temp_file) } mut r := new_repl(workdir) for { @@ -517,11 +515,6 @@ fn convert_output(os_result string) string { return content } content += endline_if_missed(sline[idx + 1..]) - } else if line.contains('.vrepl.v:') { - // Ensure that .vrepl.v: is at the start, ignore the path - // This is needed to have stable .repl tests. - idx := line.index('.vrepl.v:') or { panic(err) } - content += endline_if_missed(line[idx..]) } else { content += endline_if_missed(line) } @@ -570,18 +563,16 @@ fn (mut r Repl) get_one_line(prompt string) ?string { return rline } -fn cleanup_files(files []string) { - for file in files { - os.rm(file) or {} - $if windows { - os.rm(file[..file.len - 2] + '.exe') or {} - $if msvc { - os.rm(file[..file.len - 2] + '.ilk') or {} - os.rm(file[..file.len - 2] + '.pdb') or {} - } - } $else { - os.rm(file[..file.len - 2]) or {} +fn cleanup_files(file string) { + os.rm(file) or {} + $if windows { + os.rm(file[..file.len - 2] + '.exe') or {} + $if msvc { + os.rm(file[..file.len - 2] + '.ilk') or {} + os.rm(file[..file.len - 2] + '.pdb') or {} } + } $else { + os.rm(file[..file.len - 2]) or {} } }