diff --git a/examples/tetris/tetris.v b/examples/tetris/tetris.v index edbdd5b056..9439d433f5 100644 --- a/examples/tetris/tetris.v +++ b/examples/tetris/tetris.v @@ -402,6 +402,7 @@ fn key_down(wnd voidptr, key, code, action, mods int) { game.state = .running } } + else {} } if game.state != .running { @@ -434,5 +435,6 @@ fn key_down(wnd voidptr, key, code, action, mods int) { glfw.KeyDown { game.move_tetro() // drop faster when the player presses } + else { } } } diff --git a/vlib/bitfield/bitfield_test.v b/vlib/bitfield/bitfield_test.v index 529fdbcd03..8d86e6b64e 100644 --- a/vlib/bitfield/bitfield_test.v +++ b/vlib/bitfield/bitfield_test.v @@ -117,6 +117,9 @@ fn test_hamming() { input1.setbit(i) input2.setbit(i) } + else { + + } } } assert count == bitfield.hamming(input1, input2) diff --git a/vlib/builtin/utf8.v b/vlib/builtin/utf8.v index 166ce91eb3..8350384850 100644 --- a/vlib/builtin/utf8.v +++ b/vlib/builtin/utf8.v @@ -120,7 +120,7 @@ pub fn string_from_wide(_wstr &u16) string { pub fn string_from_wide2(_wstr &u16, len int) string { $if windows { - num_chars := C.WideCharToMultiByte(CP_UTF8, 0, _wstr, len, 0, 0, 0, 0)) + num_chars := C.WideCharToMultiByte(CP_UTF8, 0, _wstr, len, 0, 0, 0, 0) mut str_to := malloc(num_chars + 1) if !isnil(str_to) { C.WideCharToMultiByte(CP_UTF8, 0, _wstr, len, str_to, num_chars, 0, 0) diff --git a/vlib/compiler/if_match.v b/vlib/compiler/if_match.v index 284e7fbbfa..3bf7b46bab 100644 --- a/vlib/compiler/if_match.v +++ b/vlib/compiler/if_match.v @@ -203,14 +203,8 @@ fn (p mut Parser) match_statement(is_expr bool) string { i++ p.fgen_nl() } - - //if is_expr { - // we get here if no else found, ternary requires "else" branch - p.warn('match expression requires `else`') - //} - - p.returns = false // only get here when no default, so return is not guaranteed - + p.error('match expression requires `else`') + //p.returns = false // only get here when no default, so return is not guaranteed return '' } diff --git a/vlib/compiler/tests/match_test.v b/vlib/compiler/tests/match_test.v index c5ce1cf102..c0fb8108d7 100644 --- a/vlib/compiler/tests/match_test.v +++ b/vlib/compiler/tests/match_test.v @@ -21,7 +21,7 @@ fn test_match_integers() { 2 { 3 } else { 5 } } == 3 - + assert match 0 { 1 { 2 } 2 { 3 } @@ -31,7 +31,7 @@ fn test_match_integers() { assert match 1 { else { 5 } } == 5 - + a = 0 match 2 { 0 { a = 1 } @@ -42,7 +42,7 @@ fn test_match_integers() { } } assert a == 3 - + a = 0 match 1 { 0 { a = 1 } @@ -51,6 +51,7 @@ fn test_match_integers() { a = a + 2 a = a + 2 } + else {} } assert a == 6 @@ -61,7 +62,7 @@ fn test_match_integers() { } } assert a == -2 -} +} fn test_match_enums(){ mut b := Color.red diff --git a/vlib/encoding/base64/base64.v b/vlib/encoding/base64/base64.v index 64e6a756f6..f708f267d9 100644 --- a/vlib/encoding/base64/base64.v +++ b/vlib/encoding/base64/base64.v @@ -5,7 +5,7 @@ module base64 const ( - Index = [int(0), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + Index = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 63, 62, 62, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, diff --git a/vlib/encoding/csv/writer.v b/vlib/encoding/csv/writer.v index 4bd6c73063..0ed39705e6 100644 --- a/vlib/encoding/csv/writer.v +++ b/vlib/encoding/csv/writer.v @@ -39,7 +39,7 @@ pub fn (w mut Writer) write(record []string) ?bool { } w.sb.write('"') - + for field.len > 0 { mut i := field.index_any('"\r\n') if i < 0 { @@ -52,12 +52,13 @@ pub fn (w mut Writer) write(record []string) ?bool { if field.len > 0 { z := field[0] match z { - `"` { - w.sb.write('""') - } - `\r`, `\n` { - w.sb.write(le) - } + `"` { + w.sb.write('""') + } + `\r`, `\n` { + w.sb.write(le) + } + else {} } field = field[1..] } diff --git a/vlib/encoding/utf8/utf8_util.v b/vlib/encoding/utf8/utf8_util.v index ffe5ba8d0f..26927b5024 100644 --- a/vlib/encoding/utf8/utf8_util.v +++ b/vlib/encoding/utf8/utf8_util.v @@ -47,7 +47,7 @@ pub fn u_to_upper(s ustring) ustring { // to_lower return an lowercase string from a string pub fn to_lower(s string) string { - return up_low(s, false) + return up_low(s, false) } // u_to_lower return an lowercase string from a ustring @@ -69,10 +69,10 @@ fn utf8util_char_len(b byte) int { } -// -// if upper_flag == true then make low ==> upper conversion +// +// if upper_flag == true then make low ==> upper conversion // if upper_flag == false then make upper ==> low conversion -// +// // up_low make the dirt job fn up_low(s string, upper_flag bool) string { mut _index := 0 @@ -90,14 +90,14 @@ fn up_low(s string, upper_flag bool) string { } } else if ch_len > 1 && ch_len < 5{ - mut lword := int(0) + mut lword := 0 for i:=0; i < ch_len ; i++ { - lword = (lword << 8 ) | int( s.str[_index + i] ) + lword = (lword << 8 ) | int( s.str[_index + i] ) } //C.printf(" #%d (%x) ", _index, lword) - + mut res := int(0) // 2 byte utf-8 @@ -110,14 +110,14 @@ fn up_low(s string, upper_flag bool) string { // byte format: 1110xxxx 10xxxxxx 10xxxxxx // else if ch_len == 3 { - res = ( lword & 0x0f0000 ) >> 4 | ( lword & 0x3f00 ) >> 2 | ( lword & 0x3f ) + res = ( lword & 0x0f0000 ) >> 4 | ( lword & 0x3f00 ) >> 2 | ( lword & 0x3f ) } // 4 byte utf-8 // byte format: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx // else if ch_len == 4 { - res = (( lword & 0x07000000 ) >> 6) | (( lword & 0x003f0000 ) >> 4) | - (( lword & 0x00003F00 ) >> 2 ) | ( lword & 0x0000003f ) + res = (( lword & 0x07000000 ) >> 6) | (( lword & 0x003f0000 ) >> 4) | + (( lword & 0x00003F00 ) >> 2 ) | ( lword & 0x0000003f ) } //C.printf("len: %d code: %04x ",ch_len,res) @@ -125,15 +125,15 @@ fn up_low(s string, upper_flag bool) string { //C.printf(" utf8 index: %d ",ch_index) // char not in table, no need of conversion - if ch_index == 0 { + if ch_index == 0 { for i in 0..ch_len { - str_res[_index + i] = s.str[_index + i] + str_res[_index + i] = s.str[_index + i] } //C.printf("\n") }else{ tab_char := u16(unicode_con_table_up_to_low[ch_index]) //C.printf("tab_char: %04x ",tab_char) - + if ch_len == 2 { ch0 := byte( (tab_char >> 6) & 0x1f ) | 0xc0 /*110x xxxx*/ ch1 := byte( (tab_char >> 0) & 0x3f ) | 0x80 /*10xx xxxx*/ @@ -141,12 +141,12 @@ fn up_low(s string, upper_flag bool) string { str_res[ _index + 0 ] = ch0 str_res[ _index + 1 ] = ch1 - + //**************************************************************** // BUG: doesn't compile, workaround use shitf to right of 0 bit //**************************************************************** //str_res[_index + 1 ] = byte( tab_char & 0xbf ) /*1011 1111*/ - + } else if ch_len == 3 { ch0 := byte( (tab_char >> 12) & 0x0f ) | 0xe0 /*1110 xxxx*/ @@ -160,24 +160,24 @@ fn up_low(s string, upper_flag bool) string { } // TODO: write if needed else if ch_len == 4 { - // place holder!! + // place holder!! // at the present time simply copy the utf8 char for i in 0..ch_len { - str_res[_index + i] = s.str[_index + i] + str_res[_index + i] = s.str[_index + i] } } } - } + } // other cases, just copy the string else{ for i in 0..ch_len { - str_res[_index + i] = s.str[_index + i] + str_res[_index + i] = s.str[_index + i] } } old_index = _index - _index += ch_len + _index += ch_len // we are done, exit the loop if _index >= s.len { @@ -201,7 +201,7 @@ fn find_char_in_table( in_code u16, upper_flag bool) int { mut first_index := int(0) // first index of our utf8 char range mut last_index := int(unicode_con_table_up_to_low.len >> 1) // last+1 index of our utf8 char range - mut index := int(0) + mut index := int(0) mut x := u16(0) mut offset:=int(0) // up to low @@ -215,7 +215,7 @@ fn find_char_in_table( in_code u16, upper_flag bool) int { for { index = (first_index+last_index) >> 1 x = unicode_con_table_up_to_low[ (index<<1)+offset ] - + //C.printf("(%d..%d) index:%d base[%04x]==>[%04x]\n",first_index,last_index,index,in_code,x) if x == in_code { @@ -223,7 +223,7 @@ fn find_char_in_table( in_code u16, upper_flag bool) int { return int( (index<<1) + i_step) } else if x>in_code { - last_index=index + last_index=index }else { first_index=index @@ -246,7 +246,7 @@ fn find_char_in_table( in_code u16, upper_flag bool) int { * source: https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_73/nls/rbagslowtoupmaptable.htm?view=embed * term of use: https://www.ibm.com/legal?lnk=flg-tous-usen * license: not stated, general fair use license applied -* +* * regex expresion => replace from html table to V : * src: ([A-F\d]+)\s+([A-F\d]+)\s+(.*) * dst: 0x$1, 0x$2, // $3 diff --git a/vlib/gg/gg.v b/vlib/gg/gg.v index 85f489d1d4..21fbfdb833 100644 --- a/vlib/gg/gg.v +++ b/vlib/gg/gg.v @@ -382,7 +382,7 @@ pub fn (ctx &GG) draw_line_c(x, y, x2, y2 f32, color gx.Color) { C.glDeleteBuffers(1, &ctx.vbo) ctx.shader.use() ctx.shader.set_color('color', color) - vertices := [f32(x), f32(y), f32(x2), f32(y2)] ! + vertices := [x, y, x2, y2] ! gl.bind_vao(ctx.vao) gl.set_vbo(ctx.vbo, vertices, C.GL_STATIC_DRAW) gl.vertex_attrib_pointer(0, 2, C.GL_FLOAT, false, 2, 0) @@ -433,7 +433,7 @@ pub fn (ctx &GG) draw_image(x, y, w, h f32, tex_id u32) { gl.enable_vertex_attrib_array(1) gl.vertex_attrib_pointer(2, 2, C.GL_FLOAT, false, 8, 6) gl.enable_vertex_attrib_array(2) - gl.bind_2d_texture(u32(tex_id)) + gl.bind_2d_texture(tex_id) gl.bind_vao(ctx.vao) gl.draw_elements(C.GL_TRIANGLES, 6, C.GL_UNSIGNED_INT, 0) } diff --git a/vlib/glm/glm.v b/vlib/glm/glm.v index 1207a72fa3..cefca3436d 100644 --- a/vlib/glm/glm.v +++ b/vlib/glm/glm.v @@ -6,7 +6,7 @@ module glm import math -/* +/* #flag -lmyglm # f32* myglm_ortho(f32, f32, f32, f32); # f32* myglm_translate(f32, f32, f32); @@ -117,11 +117,11 @@ fn (a Vec3) print() { x := a.x y := a.y z := a.z - C.printf('vec3{%f,%f,%f}\n',x,y,z) + C.printf('vec3{%f,%f,%f}\n',x,y,z) // println('vec3{$x,$y,$z}') } -/* +/* fn rotate(m Mat4, angle f32, vec Vec3) Mat4 { // # t_mat4 m; // println('rotate done') @@ -154,7 +154,7 @@ pub fn translate(m Mat4, v Vec3) Mat4 { return mat4(out) } -/* +/* fn normalize(vec Vec3) Vec3 { # return myglm_normalize(vec); return Vec3{} @@ -165,13 +165,13 @@ pub fn ortho(left, right, bottom, top f32) Mat4 { //println('glm ortho($left, $right, $bottom, $top)') // mat<4, 4, T, defaultp> Result(static_cast(1)); n := 16 - mut res := f32_calloc(n) - res[0] = 2.0 / f32(right - left) - res[5] = 2.0 / f32(top - bottom) - res[10] = 1.0 - res[12] = - (right + left) / (right - left) - res[13] = - (top + bottom) / (top - bottom) - res[15] = 1.0 + mut res := f32_calloc(n) + res[0] = 2.0 / (right - left) + res[5] = 2.0 / (top - bottom) + res[10] = 1.0 + res[12] = - (right + left) / (right - left) + res[13] = - (top + bottom) / (top - bottom) + res[15] = 1.0 return mat4(res) } @@ -277,24 +277,24 @@ fn ortho_js(left, right, bottom, top f32) &f32 { lr := 1.0 / (left - right) bt := 1.0 / (bottom - top) nf := 1.0 / 1.0// (mynear -myfar) - mut out := (*f32)( malloc (sizeof(f32) * 16)) - out[0] = -2.0 * lr - out[1] = 0 - out[2] = 0 - out[3] = 0 - out[4] = 0 - out[5] = -2.0 * bt - out[6] = 0 - out[7] = 0 - out[8] = 0 - out[9] = 0 - out[10] = 2.0 * nf - out[11] = 0 - out[12] = (left + right) * lr - out[13] = (top + bottom) * bt + mut out := (*f32)( malloc (sizeof(f32) * 16)) + out[0] = -2.0 * lr + out[1] = 0 + out[2] = 0 + out[3] = 0 + out[4] = 0 + out[5] = -2.0 * bt + out[6] = 0 + out[7] = 0 + out[8] = 0 + out[9] = 0 + out[10] = 2.0 * nf + out[11] = 0 + out[12] = (left + right) * lr + out[13] = (top + bottom) * bt out[14] = 1.0 * nf//(far + near) * nf; - out[15] = 1 - return out + out[15] = 1 + return out //f := 0.0 //return &f } @@ -307,7 +307,7 @@ fn cross(a, b Vec3) Vec3 { return Vec3{} } -/* +/* fn perspective(degrees f32, ratio f32, a, b f32) Mat4 { // println('lang per degrees=$degrees ratio=$ratio a=$a b=$b') // # printf("lang pers degrees=%f ratio=%f a=%f b=%f\n", degrees, ratio, a,b); diff --git a/vlib/json/json_primitives.v b/vlib/json/json_primitives.v index 81f4a1e4ee..8b1897f48f 100644 --- a/vlib/json/json_primitives.v +++ b/vlib/json/json_primitives.v @@ -74,7 +74,7 @@ fn jsdecode_f32(root &C.cJSON) f32 { if isnil(root) { return f32(0) } - return f32(root.valuedouble) + return root.valuedouble } fn jsdecode_f64(root &C.cJSON) f64 { diff --git a/vlib/math/bits.v b/vlib/math/bits.v index b1a0241e4a..a320973b87 100644 --- a/vlib/math/bits.v +++ b/vlib/math/bits.v @@ -12,8 +12,8 @@ const ( mask = 0x7FF shift = 64 - 11 - 1 bias = 1023 - sign_mask = u64(u64(1) << 63) - frac_mask = u64(u64(u64(1)<= 0, negative infinity if sign < 0. diff --git a/vlib/math/math.v b/vlib/math/math.v index 19a18a2f20..286402b0b1 100644 --- a/vlib/math/math.v +++ b/vlib/math/math.v @@ -140,9 +140,9 @@ pub fn factorial(n f64) f64 { return max_f64 } - /* Otherwise return n!. */ + // Otherwise return n!. if n == f64(i64(n)) && n >= 0.0 { - return f64(factorials[i64(n)]) + return factorials[i64(n)] } return gamma(n + 1.0) diff --git a/vlib/net/socket.v b/vlib/net/socket.v index d906228a2d..dc5fd205ab 100644 --- a/vlib/net/socket.v +++ b/vlib/net/socket.v @@ -277,7 +277,7 @@ pub fn (s Socket) read_line() string { mut res := '' // The final result, including the ending \n. for { mut line := '' // The current line. Can be a partial without \n in it. - n := int(C.recv(s.sockfd, buf, MAX_READ-1, MSG_PEEK)) + n := C.recv(s.sockfd, buf, MAX_READ-1, MSG_PEEK) if n == -1 { return res } if n == 0 { return res } buf[n] = `\0` diff --git a/vlib/net/urllib/urllib.v b/vlib/net/urllib/urllib.v index 15feb72f5b..199f75f48b 100644 --- a/vlib/net/urllib/urllib.v +++ b/vlib/net/urllib/urllib.v @@ -103,8 +103,9 @@ fn should_escape(c byte, mode EncodingMode) bool { // everything, so escape nothing. return false } + else {} } - } + } else {} } if mode == .encode_fragment { @@ -118,6 +119,7 @@ fn should_escape(c byte, mode EncodingMode) bool { `!`, `(`, `)`, `*`{ return false } + else {} } } @@ -184,7 +186,7 @@ fn unescape(s_ string, mode EncodingMode) ?string { // That is, you can use escaping in the zone identifier but not // to introduce bytes you couldn't just write directly. // But Windows puts spaces here! Yay. - v := byte(unhex(s[i+1])<