From fe41bda6f96bc72dc346001fbbdc6542806a317a Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sat, 7 Oct 2023 13:47:50 +0300 Subject: [PATCH] pref: temporary 64 bit int option --- vlib/builtin/option.v | 2 +- vlib/v/ast/ast.v | 7 +++++++ vlib/v/gen/c/cgen.v | 8 ++++++-- vlib/v/pref/pref.v | 5 +++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/vlib/builtin/option.v b/vlib/builtin/option.v index 9e40d6f937cefe..cb21ccc576fbd8 100644 --- a/vlib/builtin/option.v +++ b/vlib/builtin/option.v @@ -5,7 +5,7 @@ module builtin // Option is the base of V's internal option return system. struct Option { - state u8 + state u8 // 0 - ok; 2 - none; 1 - ? err IError = none__ // Data is trailing after err // and is not included in here but in the diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 2b995089e874be..7b313e3dae384d 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -9,6 +9,13 @@ import v.pref pub type TypeDecl = AliasTypeDecl | FnTypeDecl | SumTypeDecl +pub const int_type_name = $if amd64 || arm64 { + 'i32' + //'i64' +} $else { + 'i32' +} + pub type Expr = AnonFn | ArrayDecompose | ArrayInit diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 665543b9b164fa..6eeb18c8adce12 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -1006,8 +1006,8 @@ fn (mut g Gen) base_type(_t ast.Type) string { } // On 64 bit systems int is an i64 $if amd64 || arm64 { - if t == ast.int_type { - // return 'i64' + if g.pref.use_64_int && t == ast.int_type { + return 'i64' } } share := t.share() @@ -1115,6 +1115,8 @@ fn (g Gen) option_type_text(styp string, base string) string { // replace void with something else size := if base == 'void' { 'u8' + } else if base == 'int' { + ast.int_type_name } else if base.starts_with('anon_fn') { 'void*' } else if base.starts_with('_option_') { @@ -1134,6 +1136,8 @@ fn (g Gen) result_type_text(styp string, base string) string { // replace void with something else size := if base == 'void' { 'u8' + } else if base == 'int' { + ast.int_type_name } else if base.starts_with('anon_fn') { 'void*' } else if base.starts_with('_option_') { diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index f0682b0da2cbab..733c6284c471f9 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -241,6 +241,8 @@ pub mut: // wasm settings: 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 } pub struct LineInfo { @@ -407,6 +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 + } '-Wimpure-v' { res.warn_impure_v = true }