remove unnecessary casts everywhere

pull/3006/head
Alexander Medvednikov 2019-12-07 15:51:00 +03:00
parent d7ccbba2c9
commit f51784ee01
8 changed files with 38 additions and 33 deletions

View File

@ -41,8 +41,8 @@ jobs:
run: | run: |
brew services start postgresql brew services start postgresql
sleep 3 sleep 3
psql -c -d postgres 'select rolname from pg_roles' psql -c -d postgres -c 'select rolname from pg_roles'
psql -U postgres -c 'create database customerdb;' psql -U postgres -d postgres -c 'create database customerdb;'
psql -d customerdb -f examples/database/pg/mydb.sql psql -d customerdb -f examples/database/pg/mydb.sql
- name: Test v->c - name: Test v->c
run: ./v test-compiler run: ./v test-compiler

View File

@ -39,6 +39,7 @@ struct Clipboard {
retry_delay int retry_delay int
mut: mut:
hwnd HWND hwnd HWND
foo int // TODO remove
} }
fn (cb &Clipboard) get_clipboard_lock() bool { fn (cb &Clipboard) get_clipboard_lock() bool {
@ -92,14 +93,16 @@ fn (cb &Clipboard) has_ownership() bool {
return GetClipboardOwner() == cb.hwnd return GetClipboardOwner() == cb.hwnd
} }
fn (cb &Clipboard) clear() { fn (cb mut Clipboard) clear() {
if !cb.get_clipboard_lock() {return} if !cb.get_clipboard_lock() {return}
EmptyClipboard() EmptyClipboard()
CloseClipboard() CloseClipboard()
cb.foo = 0
} }
fn (cb &Clipboard) free(){ fn (cb mut Clipboard) free(){
DestroyWindow(cb.hwnd) DestroyWindow(cb.hwnd)
cb.foo = 0
} }
// the string.to_wide doesn't work with SetClipboardData, don't know why // the string.to_wide doesn't work with SetClipboardData, don't know why
@ -115,7 +118,8 @@ fn to_wide(text string) &HGLOBAL {
return buf return buf
} }
fn (cb &Clipboard) set_text(text string) bool { fn (cb mut Clipboard) set_text(text string) bool {
cb.foo = 0
buf := to_wide(text) buf := to_wide(text)
if !cb.get_clipboard_lock() { if !cb.get_clipboard_lock() {
GlobalFree(buf) GlobalFree(buf)
@ -135,7 +139,8 @@ fn (cb &Clipboard) set_text(text string) bool {
return true return true
} }
fn (cb &Clipboard) get_text() string { fn (cb mut Clipboard) get_text() string {
cb.foo = 0
if !cb.get_clipboard_lock() { if !cb.get_clipboard_lock() {
return "" return ""
} }

View File

@ -129,7 +129,7 @@ fn build_keys() map[string]int {
mut res := map[string]int mut res := map[string]int
for t := int(TokenKind.keyword_beg) + 1; t < int(TokenKind.keyword_end); t++ { for t := int(TokenKind.keyword_beg) + 1; t < int(TokenKind.keyword_end); t++ {
key := TokenStr[t] key := TokenStr[t]
res[key] = int(t) res[key] = t
} }
return res return res
} }

View File

@ -410,7 +410,7 @@ fn vpclose(f voidptr) int {
return int( C._pclose(f) ) return int( C._pclose(f) )
} }
$else { $else {
ret , _ := posix_wait4_to_exit_status( int( C.pclose(f) ) ) ret , _ := posix_wait4_to_exit_status(C.pclose(f))
return ret return ret
} }
} }
@ -428,7 +428,7 @@ pub fn system(cmd string) int {
// TODO remove panic // TODO remove panic
//panic(';, &&, || and \\n are not allowed in shell commands') //panic(';, &&, || and \\n are not allowed in shell commands')
//} //}
mut ret := int(0) mut ret := 0
$if windows { $if windows {
// overcome bug in system & _wsystem (cmd) when first char is quote `"` // overcome bug in system & _wsystem (cmd) when first char is quote `"`
wcmd := if cmd.len > 1 && cmd[0] == `"` && cmd[1] != `"` { '"$cmd"' } else { cmd } wcmd := if cmd.len > 1 && cmd[0] == `"` && cmd[1] != `"` { '"$cmd"' } else { cmd }

View File

@ -65,7 +65,7 @@ pub fn is_dir(path string) bool {
pub fn mkdir(path string) ?bool { pub fn mkdir(path string) ?bool {
if path == '.' { return true } if path == '.' { return true }
apath := os.realpath( path ) apath := os.realpath( path )
r := int(C.mkdir(apath.str, 511)) r := C.mkdir(apath.str, 511)
if r == -1 { if r == -1 {
return error(get_error_msg(C.errno)) return error(get_error_msg(C.errno))
} }

View File

@ -10,14 +10,14 @@ mut:
} }
/** /**
* new_pcg32 - a Pcg32 PRNG generator * new_pcg32 - a Pcg32 PRNG generator
* @param initstate - the initial state of the PRNG. * @param initstate - the initial state of the PRNG.
* @param initseq - the stream/step of the PRNG. * @param initseq - the stream/step of the PRNG.
* @return a new Pcg32 PRNG instance * @return a new Pcg32 PRNG instance
*/ */
pub fn new_pcg32(initstate u64, initseq u64) Pcg32 { pub fn new_pcg32(initstate u64, initseq u64) Pcg32 {
mut rng := Pcg32{} mut rng := Pcg32{}
rng.state = u64(0) rng.state = u64(0)
rng.inc = u64( u64(initseq << u64(1)) | u64(1) ) rng.inc = (initseq << u64(1)) | u64(1)
rng.next() rng.next()
rng.state += initstate rng.state += initstate
rng.next() rng.next()
@ -27,12 +27,12 @@ pub fn new_pcg32(initstate u64, initseq u64) Pcg32 {
* Pcg32.next - update the PRNG state and get back the next random number * Pcg32.next - update the PRNG state and get back the next random number
* @return the generated pseudo random number * @return the generated pseudo random number
*/ */
[inline] pub fn (rng mut Pcg32) next() u32 { [inline] pub fn (rng mut Pcg32) next() u32 {
oldstate := rng.state oldstate := rng.state
rng.state = oldstate * u64(6364136223846793005) + rng.inc rng.state = oldstate * (6364136223846793005) + rng.inc
xorshifted := u32( u64( u64(oldstate >> u64(18)) ^ oldstate) >> u64(27) ) xorshifted := u32( ( (oldstate >> u64(18)) ^ oldstate) >> u64(27) )
rot := u32( oldstate >> u64(59) ) rot := u32( oldstate >> u64(59) )
return u32( (xorshifted >> rot) | (xorshifted << ((-rot) & u32(31))) ) return ( (xorshifted >> rot) | (xorshifted << ((-rot) & u32(31))) )
} }
/** /**
* Pcg32.bounded_next - update the PRNG state. Get the next number < bound * Pcg32.bounded_next - update the PRNG state. Get the next number < bound
@ -42,7 +42,7 @@ pub fn new_pcg32(initstate u64, initseq u64) Pcg32 {
[inline] pub fn (rng mut Pcg32) bounded_next(bound u32) u32 { [inline] pub fn (rng mut Pcg32) bounded_next(bound u32) u32 {
// To avoid bias, we need to make the range of the RNG a multiple of // To avoid bias, we need to make the range of the RNG a multiple of
// bound, which we do by dropping output less than a threshold. // bound, which we do by dropping output less than a threshold.
threshold := u32( -bound % bound ) threshold := ( -bound % bound )
// Uniformity guarantees that loop below will terminate. In practice, it // Uniformity guarantees that loop below will terminate. In practice, it
// should usually terminate quickly; on average (assuming all bounds are // should usually terminate quickly; on average (assuming all bounds are
// equally likely), 82.25% of the time, we can expect it to require just // equally likely), 82.25% of the time, we can expect it to require just
@ -51,8 +51,8 @@ pub fn new_pcg32(initstate u64, initseq u64) Pcg32 {
for { for {
r := rng.next() r := rng.next()
if r >= threshold { if r >= threshold {
return u32( r % bound ) return ( r % bound )
} }
} }
return u32(0) return u32(0)
} }

View File

@ -8,7 +8,7 @@ mut:
} }
/** /**
* new_splitmix64 - a Splitmix64 PRNG generator * new_splitmix64 - a Splitmix64 PRNG generator
* @param seed the initial seed of the PRNG. * @param seed the initial seed of the PRNG.
* @return a new Splitmix64 PRNG instance * @return a new Splitmix64 PRNG instance
*/ */
pub fn new_splitmix64(seed u64) Splitmix64 { pub fn new_splitmix64(seed u64) Splitmix64 {
@ -19,11 +19,11 @@ pub fn new_splitmix64(seed u64) Splitmix64 {
* @return the generated pseudo random number * @return the generated pseudo random number
*/ */
[inline] pub fn (rng mut Splitmix64) next() u64 { [inline] pub fn (rng mut Splitmix64) next() u64 {
rng.state += u64(0x9e3779b97f4a7c15) rng.state += (0x9e3779b97f4a7c15)
mut z := rng.state mut z := rng.state
z = (z ^ u64((z >> u64(30)))) * u64(0xbf58476d1ce4e5b9) z = (z ^ ((z >> u64(30)))) * (0xbf58476d1ce4e5b9)
z = (z ^ u64((z >> u64(27)))) * u64(0x94d049bb133111eb) z = (z ^ ((z >> u64(27)))) * (0x94d049bb133111eb)
return z ^ u64(z >> u64(31)) return z ^ (z >> (31))
} }
/** /**
* Splitmix64.bounded_next - Get the next random number < bound * Splitmix64.bounded_next - Get the next random number < bound
@ -31,12 +31,12 @@ pub fn new_splitmix64(seed u64) Splitmix64 {
* @return the generated pseudo random number * @return the generated pseudo random number
*/ */
[inline] pub fn (rng mut Splitmix64) bounded_next(bound u64) u64 { [inline] pub fn (rng mut Splitmix64) bounded_next(bound u64) u64 {
threshold := u64( -bound % bound ) threshold := -bound % bound
for { for {
r := rng.next() r := rng.next()
if r >= threshold { if r >= threshold {
return u64( r % bound ) return r % bound
} }
} }
return u64(0) return u64(0)
} }

View File

@ -150,13 +150,13 @@ pub fn unix(abs int) Time {
y += n y += n
d -= 365 * n d -= 365 * n
yday := int(d) yday := d
mut day := yday mut day := yday
year := abs / int(3.154e+7) + 1970 //int(i64(y) + absolute_zero_year) year := abs / int(3.154e+7) + 1970 //int(i64(y) + absolute_zero_year)
hour := int(abs%seconds_per_day) / seconds_per_hour hour := (abs%seconds_per_day) / seconds_per_hour
minute := int(abs % seconds_per_hour) / seconds_per_minute minute := (abs % seconds_per_hour) / seconds_per_minute
second := int(abs % seconds_per_minute) second := (abs % seconds_per_minute)
if is_leap_year(year) { if is_leap_year(year) {
// Leap year // Leap year
@ -174,12 +174,12 @@ pub fn unix(abs int) Time {
// The estimate may be too low by at most one month, so adjust. // The estimate may be too low by at most one month, so adjust.
mut month := day / 31 mut month := day / 31
mut begin := 0 mut begin := 0
end := int(days_before[month+1]) end := (days_before[month+1])
if day >= end { if day >= end {
month++ month++
begin = end begin = end
} else { } else {
begin = int(days_before[month]) begin = (days_before[month])
} }
month++ // because January is 1 month++ // because January is 1