v repl: remove dependency on v compiler module, thus making its compilation faster

pull/2652/head
Delyan Angelov 2019-11-05 14:10:15 +02:00 committed by Alexander Medvednikov
parent 53981c8747
commit d279cedd28
1 changed files with 19 additions and 8 deletions

View File

@ -5,7 +5,6 @@
module main module main
import ( import (
compiler
os os
term term
readline readline
@ -63,9 +62,9 @@ fn (r &Repl) function_call(line string) bool {
} }
pub fn repl_help() { pub fn repl_help() {
version_hash := compiler.vhash() version := v_version()
println(' println(version)
V ${compiler.Version} $version_hash println('
help Displays this information. help Displays this information.
Ctrl-C, Ctrl-D, exit Exits the REPL. Ctrl-C, Ctrl-D, exit Exits the REPL.
clear Clears the screen. clear Clears the screen.
@ -73,8 +72,8 @@ V ${compiler.Version} $version_hash
} }
pub fn run_repl() []string { pub fn run_repl() []string {
version_hash := compiler.vhash() version := v_version()
println('V ${compiler.Version} $version_hash') println(version)
println('Use Ctrl-C or `exit` to exit') println('Use Ctrl-C or `exit` to exit')
file := '.vrepl.v' file := '.vrepl.v'
temp_file := '.vrepl_temp.v' temp_file := '.vrepl_temp.v'
@ -143,7 +142,7 @@ pub fn run_repl() []string {
source_code := r.functions.join('\n') + r.lines.join('\n') + '\n' + r.line source_code := r.functions.join('\n') + r.lines.join('\n') + '\n' + r.line
os.write_file(file, source_code) os.write_file(file, source_code)
s := os.exec('"$vexe" run $file -repl') or { s := os.exec('"$vexe" run $file -repl') or {
compiler.verror(err) rerror(err)
return []string return []string
} }
vals := s.output.split('\n') vals := s.output.split('\n')
@ -162,7 +161,7 @@ pub fn run_repl() []string {
temp_source_code := r.functions.join('\n') + r.lines.join('\n') + '\n' + r.temp_lines.join('\n') + '\n' + temp_line temp_source_code := r.functions.join('\n') + r.lines.join('\n') + '\n' + r.temp_lines.join('\n') + '\n' + temp_line
os.write_file(temp_file, temp_source_code) os.write_file(temp_file, temp_source_code)
s := os.exec('"$vexe" run $temp_file -repl') or { s := os.exec('"$vexe" run $temp_file -repl') or {
compiler.verror(err) rerror(err)
return []string return []string
} }
if !func_call && s.exit_code == 0 && !temp_flag { if !func_call && s.exit_code == 0 && !temp_flag {
@ -197,3 +196,15 @@ fn main() {
} }
run_repl() run_repl()
} }
pub fn rerror(s string) {
println('V repl error: $s')
os.flush_stdout()
exit(1)
}
fn v_version() string {
vexe := os.args[1]
vversion_res := os.exec('$vexe --version') or { panic('"$vexe --version" is not working') }
return vversion_res.output
}