main: vrepl interactive shell update

pull/1023/head
Shivanjan Chakravorty 2019-07-06 15:37:44 +05:30 committed by Alexander Medvednikov
parent 0f8682d2f0
commit f630d3f342
1 changed files with 45 additions and 5 deletions

View File

@ -963,6 +963,7 @@ fn run_repl() []string {
println('Use Ctrl-C or `exit` to exit')
println('For now you have to use println() to print values, this will be fixed soon\n')
file := TmpPath + '/vrepl.v'
temp_file := TmpPath + '/vrepl_temp.v'
mut lines := []string
for {
print('>>> ')
@ -982,13 +983,52 @@ fn run_repl() []string {
lines << void_line
source_code := lines.join('\n') + '\n' + line
os.write_file(file, source_code)
mut v := new_v( ['v', '-repl', file])
v.compile()
s := os.exec(TmpPath + '/vrepl')
println(s)
s := os.exec('v run '+TmpPath+'/vrepl.v')
mut vals := s.split('\n')
if s.contains('panic: ') {
if !s.contains('declared and not used') {
for i:=1; i<vals.len; i++ {
println(vals[i])
}
}
else {
println(s)
}
}
else {
for i:=0; i<vals.len-1; i++ {
println(vals[i])
}
}
}
else {
lines << line
mut temp_line := line
mut temp_flag := false
if !(line.contains(' ') || line.contains(':') || line.contains('=') || line.contains(',') ){
temp_line = 'println('+line+')'
temp_flag = true
}
temp_source_code := lines.join('\n') + '\n' + temp_line
os.write_file(temp_file, temp_source_code)
s := os.exec('v run '+TmpPath+'/vrepl_temp.v')
if s.contains('panic: ') {
if !s.contains('declared and not used') {
mut vals := s.split('\n')
for i:=1; i<vals.len; i++ {
println(vals[i])
}
}
else {
lines << line
}
}
else {
lines << line
mut vals := s.split('\n')
for i:=0; i<vals.len-1; i++ {
println(vals[i])
}
}
}
}
return lines