From 4f85b49bb554ea72a6824074633bf15240217481 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sun, 8 Oct 2023 14:12:38 +0300 Subject: [PATCH] all: new int fixes --- examples/tetris/tetris.v | 7 ++----- vlib/v/ast/comptime_const_values.v | 16 ++++++++++++++-- vlib/v/checker/tests/compare_unsigned_signed.out | 7 +++++++ vlib/v/gen/c/cgen.v | 4 ++++ 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/examples/tetris/tetris.v b/examples/tetris/tetris.v index bf210225ba..71712f4f31 100644 --- a/examples/tetris/tetris.v +++ b/examples/tetris/tetris.v @@ -115,7 +115,7 @@ mut: // gg context for drawing gg &gg.Context = unsafe { nil } font_loaded bool - show_ghost bool = true + show_ghost bool // frame/time counters: frame int frame_old int @@ -159,9 +159,7 @@ fn frame(mut game Game) { } fn main() { - mut game := &Game{ - gg: 0 - } + mut game := &Game{} mut fpath := os.resource_abs_path(os.join_path('..', 'assets', 'fonts', 'RobotoMono-Regular.ttf')) $if android { fpath = 'fonts/RobotoMono-Regular.ttf' @@ -322,7 +320,6 @@ fn (mut g Game) get_tetro() { g.tetro = g.tetros_cache[idx..idx + tetro_size].clone() } -// TODO mut fn (mut g Game) drop_tetro() { for i in 0 .. tetro_size { tetro := g.tetro[i] diff --git a/vlib/v/ast/comptime_const_values.v b/vlib/v/ast/comptime_const_values.v index 30e0e3574c..1e0c679e86 100644 --- a/vlib/v/ast/comptime_const_values.v +++ b/vlib/v/ast/comptime_const_values.v @@ -7,6 +7,7 @@ pub type ComptTimeConstValue = EmptyExpr | i32 | i64 | i8 + | int | rune | string | u16 @@ -55,7 +56,7 @@ pub fn (val ComptTimeConstValue) i32() ?i32 { pub fn (val ComptTimeConstValue) voidptr() ?voidptr { match val { - i8, i16, i32, i64 { return voidptr(i64(val)) } + i8, i16, i32, i64, int { return voidptr(i64(val)) } u8, u16, u32, u64 { return voidptr(u64(val)) } rune { return voidptr(u64(val)) } voidptr { return val } @@ -75,7 +76,7 @@ pub fn (val ComptTimeConstValue) i64() ?i64 { i32 { return i64(val) } - i64 { + i64, int { return i64(val) } u8 { @@ -164,6 +165,11 @@ pub fn (val ComptTimeConstValue) u64() ?u64 { return u64(val) } } + int { + if val >= 0 { + return u64(val) + } + } u8 { return u64(val) } @@ -217,6 +223,9 @@ pub fn (val ComptTimeConstValue) f64() ?f64 { i64 { return f64(val) } + int { + return f64(val) + } u8 { return f64(val) } @@ -259,6 +268,9 @@ pub fn (val ComptTimeConstValue) string() ?string { i64 { return val.str() } + int { + return val.str() + } u8 { return val.str() } diff --git a/vlib/v/checker/tests/compare_unsigned_signed.out b/vlib/v/checker/tests/compare_unsigned_signed.out index 29e68d85a1..ca8bb7a6e5 100644 --- a/vlib/v/checker/tests/compare_unsigned_signed.out +++ b/vlib/v/checker/tests/compare_unsigned_signed.out @@ -46,6 +46,13 @@ vlib/v/checker/tests/compare_unsigned_signed.vv:20:13: error: `int` cannot be co | ~~ 21 | _ = i32(0) == u64(0) // FIXME 22 | // swap order +vlib/v/checker/tests/compare_unsigned_signed.vv:21:13: error: `i32` cannot be compared with `u64` + 19 | _ = i16(0) != u32(0) + 20 | _ = int(0) == u64(0) + 21 | _ = i32(0) == u64(0) // FIXME + | ~~ + 22 | // swap order + 23 | _ = u16(0) == i8(0) vlib/v/checker/tests/compare_unsigned_signed.vv:23:13: error: `u16` cannot be compared with `i8` 21 | _ = i32(0) == u64(0) // FIXME 22 | // swap order diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 2791c0b4ad..bd5ec55038 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -5390,6 +5390,10 @@ fn (mut g Gen) const_decl_precomputed(mod string, name string, field_name string i32 { g.const_decl_write_precomputed(mod, styp, cname, field_name, ct_value.str()) } + int { + // XTODO int64 + g.const_decl_write_precomputed(mod, styp, cname, field_name, ct_value.str()) + } i64 { if typ == ast.i64_type { return false