mirror of
https://github.com/vlang/v.git
synced 2025-09-14 15:02:33 +03:00
This commit is contained in:
parent
fd19458ca7
commit
175ede54b6
6 changed files with 21 additions and 37 deletions
|
@ -477,23 +477,13 @@ fn run_repl(workdir string, vrepl_prefix string) int {
|
||||||
} else if temp_line.starts_with('#include ') {
|
} else if temp_line.starts_with('#include ') {
|
||||||
temp_source_code = '${temp_line}\n' + r.current_source_code(false, false)
|
temp_source_code = '${temp_line}\n' + r.current_source_code(false, false)
|
||||||
} else {
|
} else {
|
||||||
for i, l in r.lines {
|
|
||||||
if (l.starts_with('for ') || l.starts_with('if ')) && l.contains('println') {
|
|
||||||
r.lines.delete(i)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
temp_source_code = r.current_source_code(true, false) + '\n${temp_line}\n'
|
temp_source_code = r.current_source_code(true, false) + '\n${temp_line}\n'
|
||||||
}
|
}
|
||||||
os.write_file(temp_file, temp_source_code) or { panic(err) }
|
os.write_file(temp_file, temp_source_code) or { panic(err) }
|
||||||
s := repl_run_vfile(temp_file) or { return 1 }
|
s := repl_run_vfile(temp_file) or { return 1 }
|
||||||
if s.exit_code == 0 {
|
if s.exit_code == 0 {
|
||||||
for r.temp_lines.len > 0 {
|
r.lines << r.temp_lines
|
||||||
if !r.temp_lines[0].starts_with('print') {
|
r.temp_lines.clear()
|
||||||
r.lines << r.temp_lines[0]
|
|
||||||
}
|
|
||||||
r.temp_lines.delete(0)
|
|
||||||
}
|
|
||||||
if r.line.starts_with('import ') {
|
if r.line.starts_with('import ') {
|
||||||
r.parse_import(r.line)
|
r.parse_import(r.line)
|
||||||
} else if r.line.starts_with('#include ') {
|
} else if r.line.starts_with('#include ') {
|
||||||
|
@ -600,7 +590,7 @@ fn repl_run_vfile(file string) !os.Result {
|
||||||
$if trace_repl_temp_files ? {
|
$if trace_repl_temp_files ? {
|
||||||
eprintln('>> repl_run_vfile file: ${file}')
|
eprintln('>> repl_run_vfile file: ${file}')
|
||||||
}
|
}
|
||||||
s := os.execute('${os.quoted_path(vexe)} -repl run ${os.quoted_path(file)}')
|
s := os.execute('${os.quoted_path(vexe)} -message-limit 1 -repl run ${os.quoted_path(file)}')
|
||||||
if s.exit_code < 0 {
|
if s.exit_code < 0 {
|
||||||
rerror(s.output)
|
rerror(s.output)
|
||||||
return error(s.output)
|
return error(s.output)
|
||||||
|
|
|
@ -5,8 +5,3 @@ error: undefined ident: `a`
|
||||||
6 |
|
6 |
|
||||||
7 | println(a)
|
7 | println(a)
|
||||||
| ^
|
| ^
|
||||||
error: `println` can not print void expressions
|
|
||||||
5 | import math
|
|
||||||
6 |
|
|
||||||
7 | println(a)
|
|
||||||
| ~~~~~~~~~~
|
|
||||||
|
|
|
@ -7,19 +7,9 @@ error: undefined ident: `a` (use `:=` to declare a variable)
|
||||||
6 |
|
6 |
|
||||||
7 | a = 3
|
7 | a = 3
|
||||||
| ^
|
| ^
|
||||||
error: cannot assign to `a`: expected `void`, not `int literal`
|
|
||||||
5 | import math
|
|
||||||
6 |
|
|
||||||
7 | a = 3
|
|
||||||
| ^
|
|
||||||
error: undefined ident: `b`
|
error: undefined ident: `b`
|
||||||
5 | import math
|
5 | import math
|
||||||
6 |
|
6 |
|
||||||
7 | println(b)
|
7 | println(b)
|
||||||
| ^
|
| ^
|
||||||
error: `println` can not print void expressions
|
|
||||||
5 | import math
|
|
||||||
6 |
|
|
||||||
7 | println(b)
|
|
||||||
| ~~~~~~~~~~
|
|
||||||
[4]
|
[4]
|
||||||
|
|
|
@ -5,8 +5,3 @@ error: undefined ident: `exitasdfasdf`
|
||||||
6 |
|
6 |
|
||||||
7 | println(exitasdfasdf)
|
7 | println(exitasdfasdf)
|
||||||
| ~~~~~~~~~~~~
|
| ~~~~~~~~~~~~
|
||||||
error: `println` can not print void expressions
|
|
||||||
5 | import math
|
|
||||||
6 |
|
|
||||||
7 | println(exitasdfasdf)
|
|
||||||
| ~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
fn test() { println('foo') } test() fn test2(a int) { println(a) } test2(42)
|
|
||||||
===output===
|
|
||||||
foo
|
|
||||||
42
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
mut numbers := [1,2,3,4,5]
|
||||||
|
if 1 in numbers {
|
||||||
|
println('yes')
|
||||||
|
}
|
||||||
|
println('hi')
|
||||||
|
for number in numbers {
|
||||||
|
println(number)
|
||||||
|
}
|
||||||
|
println(numbers)
|
||||||
|
===output===
|
||||||
|
yes
|
||||||
|
hi
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
5
|
||||||
|
[1, 2, 3, 4, 5]
|
Loading…
Add table
Add a link
Reference in a new issue