From 47908c22df6fec5f30fa6c49891b18e6c4791a90 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 1 Jan 2020 12:50:25 +0100 Subject: [PATCH] cgen_test: skip empty lines; os: make vc_gen compile --- vlib/os/os.v | 24 ------------------------ vlib/os/os_nix.v | 26 ++++++++++++++++++++++++++ vlib/os/os_windows.v | 13 +++++++++++++ vlib/v/gen/cgen_test.v | 9 ++++++--- vlib/v/gen/tests/2.c | 5 +++++ vlib/v/gen/tests/2.vv | 1 - 6 files changed, 50 insertions(+), 28 deletions(-) diff --git a/vlib/os/os.v b/vlib/os/os.v index 739983c06a..15d0847722 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -293,16 +293,6 @@ pub fn open_append(path string) ?File { return file } -// convert any value to []byte (LittleEndian) and write it -// for example if we have write(7, 4), "07 00 00 00" gets written -// write(0x1234, 2) => "34 12" -pub fn (f mut File) write_bytes(data voidptr, size int) { - $if linux { - C.syscall(sys_write, f.fd, data, 1) - } $else { - C.fwrite(data, 1, size, f.cfile) - } -} /* pub fn (f mut File) write_bytes_at(data voidptr, size, pos int) { @@ -324,20 +314,6 @@ pub fn (f mut File) flush() { C.fflush(f.cfile) } -pub fn (f mut File) close() { - if !f.opened { - return - } - f.opened = false - $if linux { - //$if linux_or_macos { - C.syscall(sys_close, f.fd) - return - } - C.fflush(f.cfile) - C.fclose(f.cfile) -} - // system starts the specified command, waits for it to complete, and returns its code. fn vpopen(path string) voidptr { // *C.FILE { diff --git a/vlib/os/os_nix.v b/vlib/os/os_nix.v index 6b4ae7aab3..dd03443bef 100644 --- a/vlib/os/os_nix.v +++ b/vlib/os/os_nix.v @@ -216,3 +216,29 @@ pub fn symlink(origin, target string) ?bool { if res == 0 { return true } return error(get_error_msg(C.errno)) } + +// convert any value to []byte (LittleEndian) and write it +// for example if we have write(7, 4), "07 00 00 00" gets written +// write(0x1234, 2) => "34 12" +pub fn (f mut File) write_bytes(data voidptr, size int) { + $if linux { + C.syscall(sys_write, f.fd, data, 1) + } $else { + C.fwrite(data, 1, size, f.cfile) + } +} + +pub fn (f mut File) close() { + if !f.opened { + return + } + f.opened = false + $if linux { + //$if linux_or_macos { + C.syscall(sys_close, f.fd) + return + } + C.fflush(f.cfile) + C.fclose(f.cfile) +} + diff --git a/vlib/os/os_windows.v b/vlib/os/os_windows.v index 125c851f31..afc4bb1fc6 100644 --- a/vlib/os/os_windows.v +++ b/vlib/os/os_windows.v @@ -340,3 +340,16 @@ pub fn symlink(origin, target string) ?bool { } return error(get_error_msg(int(C.GetLastError()))) } + +pub fn (f mut File) write_bytes(data voidptr, size int) { + C.fwrite(data, 1, size, f.cfile) +} + +pub fn (f mut File) close() { + if !f.opened { + return + } + f.opened = false + C.fflush(f.cfile) + C.fclose(f.cfile) +} diff --git a/vlib/v/gen/cgen_test.v b/vlib/v/gen/cgen_test.v index 9c7d0a72a1..4494d831dc 100644 --- a/vlib/v/gen/cgen_test.v +++ b/vlib/v/gen/cgen_test.v @@ -35,8 +35,10 @@ fn test_c_files() { } fn compare_texts(a, b string) bool { - lines_a := a.trim_space().split_into_lines() - lines_b := b.trim_space().split_into_lines() + lines_a_ := a.trim_space().split_into_lines() + lines_b_ := b.trim_space().split_into_lines() + lines_a := lines_a_.filter(it != '') + lines_b := lines_b_.filter(it != '') if lines_a.len != lines_b.len { println(term.red('different len')) // return false @@ -44,7 +46,8 @@ fn compare_texts(a, b string) bool { for i, line_a in lines_a { line_b := lines_b[i] if line_a.trim_space() != line_b.trim_space() { - println(term.red('!' + line_a)) + println(term.red('i=$i a="$line_a" b="$line_b"')) + // exit(1) return false } } diff --git a/vlib/v/gen/tests/2.c b/vlib/v/gen/tests/2.c index c22c351074..47835ab85c 100644 --- a/vlib/v/gen/tests/2.c +++ b/vlib/v/gen/tests/2.c @@ -54,6 +54,11 @@ void init_array() { }); } +void end() { + +} + + int main() { return 0; } diff --git a/vlib/v/gen/tests/2.vv b/vlib/v/gen/tests/2.vv index 1f6767deba..11e721def0 100644 --- a/vlib/v/gen/tests/2.vv +++ b/vlib/v/gen/tests/2.vv @@ -53,7 +53,6 @@ fn function2() { j := 0 } - fn init_array() { nums := [1,2,3]