Skip to content

Commit

Permalink
all: i64 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Oct 7, 2023
1 parent 3c68e78 commit 8c5ac3a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
8 changes: 8 additions & 0 deletions vlib/builtin/int.v
Expand Up @@ -125,6 +125,14 @@ pub fn (n int) str() string {
return n.str_l(12)
}

// str returns the value of the `int` as a `string`.
// Example: assert int(-2020).str() == '-2020'
/*
pub fn int_str(n int) string {
return i64(n).str()
}
*/

// str returns the value of the `u32` as a `string`.
// Example: assert u32(20000).str() == '20000'
[direct_array_access; inline]
Expand Down
3 changes: 2 additions & 1 deletion vlib/builtin/wasm/wasi/int.v
@@ -1,7 +1,8 @@
module builtin

type byte = u8
type i32 = int

// type i32 = int

const (
// digit pairs in reverse order
Expand Down
20 changes: 17 additions & 3 deletions vlib/v/ast/types.v
Expand Up @@ -981,8 +981,8 @@ pub fn (t &TypeSymbol) is_pointer() bool {

[inline]
pub fn (t &TypeSymbol) is_int() bool {
res := t.kind in [.i8, .i16, .int, .i64, .isize, .u8, .u16, .u32, .u64, .usize, .int_literal,
.rune]
res := t.kind in [.i8, .i16, .int, .i64, .i32, .isize, .u8, .u16, .u32, .u64, .usize,
.int_literal, .rune]
if !res && t.kind == .alias {
return (t.info as Alias).parent_type.is_number()
}
Expand Down Expand Up @@ -1047,10 +1047,24 @@ pub fn (t &Table) type_size(typ Type) (int, int) {
size = 2
align = 2
}
.int, .i32, .u32, .rune, .f32, .enum_ {
.i32, .u32, .rune, .f32, .enum_ {
size = 4
align = 4
}
.int {
$if new_int ? {
$if arm64 || amd64 {
size = 8
align = 8
} $else {
size = 4
align = 4
}
} $else {
size = 4
align = 4
}
}
.i64, .u64, .int_literal, .f64, .float_literal {
size = 8
align = 8
Expand Down
2 changes: 2 additions & 0 deletions vlib/v/gen/c/cgen.v
Expand Up @@ -1002,12 +1002,14 @@ fn (mut g Gen) base_type(_t ast.Type) string {
return 'u64'
}
}
/*
// On 64 bit systems int is an i64
$if amd64 || arm64 {
if g.pref.use_64_int && t == ast.int_type {
return 'i64'
}
}
*/
share := t.share()
mut styp := if share == .atomic_t { t.atomic_typename() } else { g.cc_type(t, true) }
if t.has_flag(.shared_f) {
Expand Down
8 changes: 4 additions & 4 deletions vlib/v/pref/pref.v
Expand Up @@ -242,7 +242,7 @@ pub mut:
wasm_stack_top int = 1024 + (16 * 1024) // stack size for webassembly backend
wasm_validate bool // validate webassembly code, by calling `wasm-validate`
// temp
use_64_int bool
// use_64_int bool
}

pub struct LineInfo {
Expand Down Expand Up @@ -409,9 +409,9 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
// processed by testing tools in cmd/tools/modules/testing/common.v
continue
}
'-i64' {
res.use_64_int = true
}
//'-i64' {
// res.use_64_int = true
//}
'-Wimpure-v' {
res.warn_impure_v = true
}
Expand Down

0 comments on commit 8c5ac3a

Please sign in to comment.