v2: compile vrepl, 'fn main(){println(2+2)}' runs now
It works if you give it complete V programs like fn main(){println(2+2)} but not for single expressions like 2+2 or statements like a:='abc'pull/4205/head
parent
fd12e4e826
commit
abf15e863c
|
@ -916,6 +916,10 @@ pub fn (s mut []string) sort_by_len() {
|
||||||
s.sort_with_compare(compare_strings_by_len)
|
s.sort_with_compare(compare_strings_by_len)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn (s ustring) str() string {
|
||||||
|
return s.s
|
||||||
|
}
|
||||||
|
|
||||||
pub fn (s string) ustring() ustring {
|
pub fn (s string) ustring() ustring {
|
||||||
mut res := ustring{
|
mut res := ustring{
|
||||||
s: s
|
s: s
|
||||||
|
@ -985,7 +989,7 @@ fn (u ustring) ge(a ustring) bool {
|
||||||
return !u.lt(a)
|
return !u.lt(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (u ustring) add(a ustring) ustring {
|
pub fn (u ustring) add(a ustring) ustring {
|
||||||
mut res := ustring{
|
mut res := ustring{
|
||||||
s: u.s + a.s
|
s: u.s + a.s
|
||||||
runes: new_array(0, u.s.len + a.s.len, sizeof(int))
|
runes: new_array(0, u.s.len + a.s.len, sizeof(int))
|
||||||
|
|
|
@ -313,7 +313,8 @@ fn shift_cursor(xpos int, yoffset int) {
|
||||||
print('\x1b[${xpos + 1}G')
|
print('\x1b[${xpos + 1}G')
|
||||||
}
|
}
|
||||||
|
|
||||||
fn calculate_screen_position(x_in int, y_in int, screen_columns int, char_count int, out mut []int) {
|
fn calculate_screen_position(x_in int, y_in int, screen_columns int, char_count int, inp []int) []int {
|
||||||
|
mut out := inp
|
||||||
mut x := x_in
|
mut x := x_in
|
||||||
mut y := y_in
|
mut y := y_in
|
||||||
out[0] = x
|
out[0] = x
|
||||||
|
@ -330,15 +331,16 @@ fn calculate_screen_position(x_in int, y_in int, screen_columns int, char_count
|
||||||
out[0] = 0
|
out[0] = 0
|
||||||
out[1]++
|
out[1]++
|
||||||
}
|
}
|
||||||
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
// Will redraw the line
|
// Will redraw the line
|
||||||
fn (r mut Readline) refresh_line() {
|
fn (r mut Readline) refresh_line() {
|
||||||
mut end_of_input := [0, 0]
|
mut end_of_input := [0, 0]
|
||||||
calculate_screen_position(r.prompt.len, 0, get_screen_columns(), r.current.len, mut end_of_input)
|
end_of_input = calculate_screen_position(r.prompt.len, 0, get_screen_columns(), r.current.len, end_of_input)
|
||||||
end_of_input[1] += r.current.count('\n'.ustring())
|
end_of_input[1] += r.current.count('\n'.ustring())
|
||||||
mut cursor_pos := [0, 0]
|
mut cursor_pos := [0, 0]
|
||||||
calculate_screen_position(r.prompt.len, 0, get_screen_columns(), r.cursor, mut cursor_pos)
|
cursor_pos = calculate_screen_position(r.prompt.len, 0, get_screen_columns(), r.cursor, cursor_pos)
|
||||||
|
|
||||||
shift_cursor(0, -r.cursor_row_offset)
|
shift_cursor(0, -r.cursor_row_offset)
|
||||||
term.erase_toend()
|
term.erase_toend()
|
||||||
|
@ -363,9 +365,9 @@ fn (r mut Readline) eof() bool {
|
||||||
|
|
||||||
fn (r mut Readline) insert_character(c int) {
|
fn (r mut Readline) insert_character(c int) {
|
||||||
if !r.overwrite || r.cursor == r.current.len {
|
if !r.overwrite || r.cursor == r.current.len {
|
||||||
r.current = r.current.left(r.cursor).ustring() + utf32_to_str(u32(c)).ustring() + r.current.right(r.cursor).ustring()
|
r.current = r.current.left(r.cursor).ustring().add( utf32_to_str(u32(c)).ustring() ).add( r.current.right(r.cursor).ustring() )
|
||||||
} else {
|
} else {
|
||||||
r.current = r.current.left(r.cursor).ustring() + utf32_to_str(u32(c)).ustring() + r.current.right(r.cursor + 1).ustring()
|
r.current = r.current.left(r.cursor).ustring().add( utf32_to_str(u32(c)).ustring() ).add( r.current.right(r.cursor + 1).ustring() )
|
||||||
}
|
}
|
||||||
r.cursor++
|
r.cursor++
|
||||||
// Refresh the line to add the new character
|
// Refresh the line to add the new character
|
||||||
|
@ -380,7 +382,7 @@ fn (r mut Readline) delete_character() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
r.cursor--
|
r.cursor--
|
||||||
r.current = r.current.left(r.cursor).ustring() + r.current.right(r.cursor + 1).ustring()
|
r.current = r.current.left(r.cursor).ustring().add( r.current.right(r.cursor + 1).ustring() )
|
||||||
r.refresh_line()
|
r.refresh_line()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,7 +391,7 @@ fn (r mut Readline) suppr_character() {
|
||||||
if r.cursor > r.current.len {
|
if r.cursor > r.current.len {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
r.current = r.current.left(r.cursor).ustring() + r.current.right(r.cursor + 1).ustring()
|
r.current = r.current.left(r.cursor).ustring().add( r.current.right(r.cursor + 1).ustring() )
|
||||||
r.refresh_line()
|
r.refresh_line()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,7 +399,7 @@ fn (r mut Readline) suppr_character() {
|
||||||
fn (r mut Readline) commit_line() bool {
|
fn (r mut Readline) commit_line() bool {
|
||||||
r.previous_lines.insert(1, r.current)
|
r.previous_lines.insert(1, r.current)
|
||||||
a := '\n'.ustring()
|
a := '\n'.ustring()
|
||||||
r.current = r.current + a
|
r.current = r.current.add( a )
|
||||||
r.cursor = r.current.len
|
r.cursor = r.current.len
|
||||||
if r.is_tty {
|
if r.is_tty {
|
||||||
r.refresh_line()
|
r.refresh_line()
|
||||||
|
|
Loading…
Reference in New Issue