From 18525922fd2c318e4ed2701211ddc4363dce3c2a Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sat, 29 Jun 2019 17:58:20 +0200 Subject: [PATCH] Windows fixes --- compiler/main.v | 9 ++++++--- compiler/scanner.v | 7 +++++-- vlib/os/os.v | 8 +++++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/compiler/main.v b/compiler/main.v index ce3188b672..790adba3e3 100644 --- a/compiler/main.v +++ b/compiler/main.v @@ -486,12 +486,15 @@ mut args := '' // Find clang executable fast_clang := '/usr/local/Cellar/llvm/8.0.0/bin/clang' args := a.join(' ') - cmd := if os.file_exists(fast_clang) { - '$fast_clang -I. $args' + mut cmd := if os.file_exists(fast_clang) { + '$fast_clang $args' } else { - 'cc -I. $args' + 'cc $args' } + $if windows { + cmd = 'gcc $args' + } // Print the C command if c.show_c_cmd || c.is_verbose { println('\n==========\n$cmd\n=========\n') diff --git a/compiler/scanner.v b/compiler/scanner.v index eb4ba104a1..923bd7287c 100644 --- a/compiler/scanner.v +++ b/compiler/scanner.v @@ -179,13 +179,11 @@ fn (s mut Scanner) scan() ScanRes { return scan_res(STRING, s.ident_string()) } s.skip_whitespace() - // println('ws skipped') // end of file if s.pos >= s.text.len { // println('scan(): returning EOF (pos >= len)') return scan_res(EOF, '') } - // println('!!!!! HANDLE CHAR pos=$s.pos') // handle each char c := s.text[s.pos] mut nextc := `\0` @@ -481,6 +479,11 @@ fn (s mut Scanner) scan() ScanRes { } return scan_res(DIV, '') } + $if windows { + if c == `\0` { + return scan_res(EOF, '') + } + } println('(char code=$c) pos=$s.pos len=$s.text.len') s.error('invalid character `${c.str()}`') return scan_res(EOF, '') diff --git a/vlib/os/os.v b/vlib/os/os.v index a55be9cc13..be911a36db 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -77,8 +77,14 @@ fn parse_windows_cmd_line(cmd byteptr) []string { // read_file reads the file in `path` and returns the contents. pub fn read_file(path string) ?string { mut res := '' + mut mode := 'r' + 777 // TODO + // Need 'rb' on windows to avoid the \r\n mess. + $if windows { + mode = 'rb' + } cpath := path.cstr() - fp := C.fopen(cpath, 'r') + fp := C.fopen(cpath, mode.cstr()) if isnil(fp) { return error('failed to open file "$path"') }