Skip to content

Commit

Permalink
pref: temporary 64 bit int option
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Oct 7, 2023
1 parent 49b8c2f commit fe41bda
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion vlib/builtin/option.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions vlib/v/ast/ast.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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_') {
Expand All @@ -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_') {
Expand Down
5 changes: 5 additions & 0 deletions vlib/v/pref/pref.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit fe41bda

Please sign in to comment.