mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
cgen,builtin: support for 64bit int 1 (#25236)
Some checks are pending
json encoder benchmark CI / json-encode-benchmark (push) Waiting to run
Graphics CI / gg-regressions (push) Waiting to run
vlib modules CI / build-module-docs (push) Waiting to run
native backend CI / native-backend-ubuntu (push) Waiting to run
native backend CI / native-backend-windows (push) Waiting to run
Shy and PV CI / v-compiles-puzzle-vibes (push) Waiting to run
Sanitized CI / sanitize-undefined-clang (push) Waiting to run
Sanitized CI / sanitize-undefined-gcc (push) Waiting to run
Sanitized CI / tests-sanitize-address-clang (push) Waiting to run
Sanitized CI / sanitize-address-msvc (push) Waiting to run
Sanitized CI / sanitize-address-gcc (push) Waiting to run
Sanitized CI / sanitize-memory-clang (push) Waiting to run
sdl CI / v-compiles-sdl-examples (push) Waiting to run
Time CI / time-linux (push) Waiting to run
Time CI / time-macos (push) Waiting to run
Time CI / time-windows (push) Waiting to run
toml CI / toml-module-pass-external-test-suites (push) Waiting to run
Tools CI / tools-linux (clang) (push) Waiting to run
Tools CI / tools-linux (gcc) (push) Waiting to run
Tools CI / tools-linux (tcc) (push) Waiting to run
Tools CI / tools-macos (clang) (push) Waiting to run
Tools CI / tools-windows (gcc) (push) Waiting to run
Tools CI / tools-windows (msvc) (push) Waiting to run
Tools CI / tools-windows (tcc) (push) Waiting to run
Tools CI / tools-docker-ubuntu-musl (push) Waiting to run
vab CI / vab-compiles-v-examples (push) Waiting to run
vab CI / v-compiles-os-android (push) Waiting to run
wasm backend CI / wasm-backend (ubuntu-22.04) (push) Waiting to run
wasm backend CI / wasm-backend (windows-2022) (push) Waiting to run
Some checks are pending
json encoder benchmark CI / json-encode-benchmark (push) Waiting to run
Graphics CI / gg-regressions (push) Waiting to run
vlib modules CI / build-module-docs (push) Waiting to run
native backend CI / native-backend-ubuntu (push) Waiting to run
native backend CI / native-backend-windows (push) Waiting to run
Shy and PV CI / v-compiles-puzzle-vibes (push) Waiting to run
Sanitized CI / sanitize-undefined-clang (push) Waiting to run
Sanitized CI / sanitize-undefined-gcc (push) Waiting to run
Sanitized CI / tests-sanitize-address-clang (push) Waiting to run
Sanitized CI / sanitize-address-msvc (push) Waiting to run
Sanitized CI / sanitize-address-gcc (push) Waiting to run
Sanitized CI / sanitize-memory-clang (push) Waiting to run
sdl CI / v-compiles-sdl-examples (push) Waiting to run
Time CI / time-linux (push) Waiting to run
Time CI / time-macos (push) Waiting to run
Time CI / time-windows (push) Waiting to run
toml CI / toml-module-pass-external-test-suites (push) Waiting to run
Tools CI / tools-linux (clang) (push) Waiting to run
Tools CI / tools-linux (gcc) (push) Waiting to run
Tools CI / tools-linux (tcc) (push) Waiting to run
Tools CI / tools-macos (clang) (push) Waiting to run
Tools CI / tools-windows (gcc) (push) Waiting to run
Tools CI / tools-windows (msvc) (push) Waiting to run
Tools CI / tools-windows (tcc) (push) Waiting to run
Tools CI / tools-docker-ubuntu-musl (push) Waiting to run
vab CI / vab-compiles-v-examples (push) Waiting to run
vab CI / v-compiles-os-android (push) Waiting to run
wasm backend CI / wasm-backend (ubuntu-22.04) (push) Waiting to run
wasm backend CI / wasm-backend (windows-2022) (push) Waiting to run
This commit is contained in:
parent
64343168c6
commit
c221b3226b
48 changed files with 610 additions and 370 deletions
|
@ -607,7 +607,8 @@ pub fn (mut a array) delete_last() {
|
||||||
// Alternative: Slices can also be made with [start..end] notation
|
// Alternative: Slices can also be made with [start..end] notation
|
||||||
// Alternative: `.slice_ni()` will always return an array.
|
// Alternative: `.slice_ni()` will always return an array.
|
||||||
fn (a array) slice(start int, _end int) array {
|
fn (a array) slice(start int, _end int) array {
|
||||||
end := if _end == max_int { a.len } else { _end } // max_int
|
// WARNNING: The is a temp solution for bootstrap!
|
||||||
|
end := if _end == max_i64 || _end == max_i32 { a.len } else { _end } // max_int
|
||||||
$if !no_bounds_checking {
|
$if !no_bounds_checking {
|
||||||
if start > end {
|
if start > end {
|
||||||
panic('array.slice: invalid slice index (start>end):' + impl_i64_to_string(i64(start)) +
|
panic('array.slice: invalid slice index (start>end):' + impl_i64_to_string(i64(start)) +
|
||||||
|
@ -644,7 +645,8 @@ fn (a array) slice(start int, _end int) array {
|
||||||
// This function always return a valid array.
|
// This function always return a valid array.
|
||||||
fn (a array) slice_ni(_start int, _end int) array {
|
fn (a array) slice_ni(_start int, _end int) array {
|
||||||
// a.flags.clear(.noslices)
|
// a.flags.clear(.noslices)
|
||||||
mut end := if _end == max_int { a.len } else { _end } // max_int
|
// WARNNING: The is a temp solution for bootstrap!
|
||||||
|
mut end := if _end == max_i64 || _end == max_i32 { a.len } else { _end } // max_int
|
||||||
mut start := _start
|
mut start := _start
|
||||||
|
|
||||||
if start < 0 {
|
if start < 0 {
|
||||||
|
|
|
@ -42,15 +42,23 @@ pub const max_i16 = i16(32767)
|
||||||
pub const min_i32 = i32(-2147483648)
|
pub const min_i32 = i32(-2147483648)
|
||||||
pub const max_i32 = i32(2147483647)
|
pub const max_i32 = i32(2147483647)
|
||||||
|
|
||||||
pub const min_int = int(-2147483648)
|
|
||||||
pub const max_int = int(2147483647)
|
|
||||||
|
|
||||||
// -9223372036854775808 is wrong, because C compilers parse literal values
|
// -9223372036854775808 is wrong, because C compilers parse literal values
|
||||||
// without sign first, and 9223372036854775808 overflows i64, hence the
|
// without sign first, and 9223372036854775808 overflows i64, hence the
|
||||||
// consecutive subtraction by 1
|
// consecutive subtraction by 1
|
||||||
pub const min_i64 = i64(-9223372036854775807 - 1)
|
pub const min_i64 = i64(-9223372036854775807 - 1)
|
||||||
pub const max_i64 = i64(9223372036854775807)
|
pub const max_i64 = i64(9223372036854775807)
|
||||||
|
|
||||||
|
pub const min_int = $if new_int ? && (arm64 || amd64 || rv64 || s390x || ppc64le || loongarch64) {
|
||||||
|
int(min_i64)
|
||||||
|
} $else {
|
||||||
|
int(min_i32)
|
||||||
|
}
|
||||||
|
pub const max_int = $if new_int ? && (arm64 || amd64 || rv64 || s390x || ppc64le || loongarch64) {
|
||||||
|
int(max_i64)
|
||||||
|
} $else {
|
||||||
|
int(max_i32)
|
||||||
|
}
|
||||||
|
|
||||||
pub const min_u8 = u8(0)
|
pub const min_u8 = u8(0)
|
||||||
pub const max_u8 = u8(255)
|
pub const max_u8 = u8(255)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
module builtin
|
|
||||||
|
|
||||||
// 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()
|
|
||||||
}
|
|
|
@ -11,15 +11,15 @@ pub const max_i16 = i16(32767)
|
||||||
pub const min_i32 = i32(-2147483648)
|
pub const min_i32 = i32(-2147483648)
|
||||||
pub const max_i32 = i32(2147483647)
|
pub const max_i32 = i32(2147483647)
|
||||||
|
|
||||||
pub const min_int = min_i32
|
|
||||||
pub const max_int = max_i32
|
|
||||||
|
|
||||||
// -9223372036854775808 is wrong, because C compilers parse literal values
|
// -9223372036854775808 is wrong, because C compilers parse literal values
|
||||||
// without sign first, and 9223372036854775808 overflows i64, hence the
|
// without sign first, and 9223372036854775808 overflows i64, hence the
|
||||||
// consecutive subtraction by 1
|
// consecutive subtraction by 1
|
||||||
pub const min_i64 = i64(-9223372036854775807 - 1)
|
pub const min_i64 = i64(-9223372036854775807 - 1)
|
||||||
pub const max_i64 = i64(9223372036854775807)
|
pub const max_i64 = i64(9223372036854775807)
|
||||||
|
|
||||||
|
pub const min_int = int(min_i32)
|
||||||
|
pub const max_int = int(max_i32)
|
||||||
|
|
||||||
pub const min_u8 = u8(0)
|
pub const min_u8 = u8(0)
|
||||||
pub const max_u8 = u8(255)
|
pub const max_u8 = u8(255)
|
||||||
|
|
||||||
|
|
|
@ -1165,7 +1165,8 @@ pub fn (s string) split_by_space() []string {
|
||||||
// Example: assert 'ABCD'.substr(1,3) == 'BC'
|
// Example: assert 'ABCD'.substr(1,3) == 'BC'
|
||||||
@[direct_array_access]
|
@[direct_array_access]
|
||||||
pub fn (s string) substr(start int, _end int) string {
|
pub fn (s string) substr(start int, _end int) string {
|
||||||
end := if _end == max_int { s.len } else { _end } // max_int
|
// WARNNING: The is a temp solution for bootstrap!
|
||||||
|
end := if _end == max_i64 || _end == max_i32 { s.len } else { _end } // max_int
|
||||||
$if !no_bounds_checking {
|
$if !no_bounds_checking {
|
||||||
if start > end || start > s.len || end > s.len || start < 0 || end < 0 {
|
if start > end || start > s.len || end > s.len || start < 0 || end < 0 {
|
||||||
panic('substr(' + impl_i64_to_string(start) + ', ' + impl_i64_to_string(end) +
|
panic('substr(' + impl_i64_to_string(start) + ', ' + impl_i64_to_string(end) +
|
||||||
|
@ -1205,7 +1206,8 @@ pub fn (s string) substr_unsafe(start int, _end int) string {
|
||||||
// return an error when the index is out of range
|
// return an error when the index is out of range
|
||||||
@[direct_array_access]
|
@[direct_array_access]
|
||||||
pub fn (s string) substr_with_check(start int, _end int) !string {
|
pub fn (s string) substr_with_check(start int, _end int) !string {
|
||||||
end := if _end == max_int { s.len } else { _end } // max_int
|
// WARNNING: The is a temp solution for bootstrap!
|
||||||
|
end := if _end == max_i64 || _end == max_i32 { s.len } else { _end } // max_int
|
||||||
if start > end || start > s.len || end > s.len || start < 0 || end < 0 {
|
if start > end || start > s.len || end > s.len || start < 0 || end < 0 {
|
||||||
return error('substr(' + impl_i64_to_string(start) + ', ' + impl_i64_to_string(end) +
|
return error('substr(' + impl_i64_to_string(start) + ', ' + impl_i64_to_string(end) +
|
||||||
') out of bounds (len=' + impl_i64_to_string(s.len) + ')')
|
') out of bounds (len=' + impl_i64_to_string(s.len) + ')')
|
||||||
|
@ -1230,7 +1232,8 @@ pub fn (s string) substr_with_check(start int, _end int) !string {
|
||||||
@[direct_array_access]
|
@[direct_array_access]
|
||||||
pub fn (s string) substr_ni(_start int, _end int) string {
|
pub fn (s string) substr_ni(_start int, _end int) string {
|
||||||
mut start := _start
|
mut start := _start
|
||||||
mut end := if _end == max_int { s.len } else { _end } // max_int
|
// WARNNING: The is a temp solution for bootstrap!
|
||||||
|
mut end := if _end == max_i64 || _end == max_i32 { s.len } else { _end }
|
||||||
|
|
||||||
// borders math
|
// borders math
|
||||||
if start < 0 {
|
if start < 0 {
|
||||||
|
|
|
@ -71,7 +71,7 @@ pub mut:
|
||||||
d_u16 u16
|
d_u16 u16
|
||||||
d_i16 i16
|
d_i16 i16
|
||||||
d_u32 u32
|
d_u32 u32
|
||||||
d_i32 int
|
d_i32 i32
|
||||||
d_u64 u64
|
d_u64 u64
|
||||||
d_i64 i64
|
d_i64 i64
|
||||||
d_f32 f32
|
d_f32 f32
|
||||||
|
|
|
@ -16,15 +16,15 @@ pub const max_i16 = i16(32767)
|
||||||
pub const min_i32 = i32(-2147483648)
|
pub const min_i32 = i32(-2147483648)
|
||||||
pub const max_i32 = i32(2147483647)
|
pub const max_i32 = i32(2147483647)
|
||||||
|
|
||||||
pub const min_int = min_i32
|
|
||||||
pub const max_int = max_i32
|
|
||||||
|
|
||||||
// -9223372036854775808 is wrong, because C compilers parse literal values
|
// -9223372036854775808 is wrong, because C compilers parse literal values
|
||||||
// without sign first, and 9223372036854775808 overflows i64, hence the
|
// without sign first, and 9223372036854775808 overflows i64, hence the
|
||||||
// consecutive subtraction by 1
|
// consecutive subtraction by 1
|
||||||
pub const min_i64 = i64(-9223372036854775807 - 1)
|
pub const min_i64 = i64(-9223372036854775807 - 1)
|
||||||
pub const max_i64 = i64(9223372036854775807)
|
pub const max_i64 = i64(9223372036854775807)
|
||||||
|
|
||||||
|
pub const min_int = int(min_i32)
|
||||||
|
pub const max_int = int(max_i32)
|
||||||
|
|
||||||
pub const min_u8 = u8(0)
|
pub const min_u8 = u8(0)
|
||||||
pub const max_u8 = u8(255)
|
pub const max_u8 = u8(255)
|
||||||
|
|
||||||
|
|
|
@ -105,3 +105,23 @@ fn test_sum_types() {
|
||||||
j := json.encode(animals[0])
|
j := json.encode(animals[0])
|
||||||
assert j == '{"cat_name":"Whiskers","_type":"Cat"}'
|
assert j == '{"cat_name":"Whiskers","_type":"Cat"}'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Value = string | i32
|
||||||
|
|
||||||
|
struct Node {
|
||||||
|
value Value
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_sum_types_with_i32() {
|
||||||
|
data1 := json.encode([Node{i32(128)}, Node{'mystring'}])
|
||||||
|
assert data1 == '[{"value":128},{"value":"mystring"}]'
|
||||||
|
|
||||||
|
node := json.decode([]Node, data1) or {
|
||||||
|
println(err)
|
||||||
|
assert false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
assert node.len == 2
|
||||||
|
assert node[0].value == Value(i32(128))
|
||||||
|
assert node[1].value == Value('mystring')
|
||||||
|
}
|
||||||
|
|
|
@ -31,10 +31,7 @@ pub fn maxof[T]() T {
|
||||||
} $else $if T is f64 {
|
} $else $if T is f64 {
|
||||||
return max_f64
|
return max_f64
|
||||||
} $else $if T is int {
|
} $else $if T is int {
|
||||||
$if new_int ? {
|
return max_int
|
||||||
return int(max_i64)
|
|
||||||
}
|
|
||||||
return int(max_i32)
|
|
||||||
} $else {
|
} $else {
|
||||||
panic('A maximum value of the type `' + typeof[T]().name + '` is not defined.')
|
panic('A maximum value of the type `' + typeof[T]().name + '` is not defined.')
|
||||||
}
|
}
|
||||||
|
@ -68,10 +65,7 @@ pub fn minof[T]() T {
|
||||||
} $else $if T is f64 {
|
} $else $if T is f64 {
|
||||||
return -max_f64
|
return -max_f64
|
||||||
} $else $if T is int {
|
} $else $if T is int {
|
||||||
$if new_int ? {
|
return min_int
|
||||||
return int(min_i64)
|
|
||||||
}
|
|
||||||
return int(min_i32)
|
|
||||||
} $else {
|
} $else {
|
||||||
panic('A minimum value of the type `' + typeof[T]().name + '` is not defined.')
|
panic('A minimum value of the type `' + typeof[T]().name + '` is not defined.')
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,3 +20,8 @@ fn test_abs() {
|
||||||
assert math.abs(1.2345) == 1.2345
|
assert math.abs(1.2345) == 1.2345
|
||||||
assert math.abs(-5.5) == 5.5
|
assert math.abs(-5.5) == 5.5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_max_min_int_has_type_of_int() {
|
||||||
|
assert math.max(int(100), min_int) == 100
|
||||||
|
assert math.min(int(100), max_int) == 100
|
||||||
|
}
|
||||||
|
|
|
@ -11,9 +11,9 @@ import v.pref
|
||||||
import sync.stdatomic
|
import sync.stdatomic
|
||||||
|
|
||||||
// V type names that cannot be used as global var name
|
// V type names that cannot be used as global var name
|
||||||
pub const global_reserved_type_names = ['byte', 'bool', 'char', 'i8', 'i16', 'int', 'i64', 'u8',
|
pub const global_reserved_type_names = ['byte', 'bool', 'char', 'i8', 'i16', 'i32', 'int', 'i64',
|
||||||
'u16', 'u32', 'u64', 'f32', 'f64', 'map', 'string', 'rune', 'usize', 'isize', 'voidptr', 'thread',
|
'u8', 'u16', 'u32', 'u64', 'f32', 'f64', 'map', 'string', 'rune', 'usize', 'isize', 'voidptr',
|
||||||
'array']
|
'thread', 'array']
|
||||||
|
|
||||||
pub const result_name = '_result'
|
pub const result_name = '_result'
|
||||||
pub const option_name = '_option'
|
pub const option_name = '_option'
|
||||||
|
@ -24,10 +24,9 @@ pub const builtins = ['string', 'array', 'DenseArray', 'map', 'Error', 'IError',
|
||||||
|
|
||||||
pub type TypeDecl = AliasTypeDecl | FnTypeDecl | SumTypeDecl
|
pub type TypeDecl = AliasTypeDecl | FnTypeDecl | SumTypeDecl
|
||||||
|
|
||||||
// pub const int_type_name = $if amd64 || arm64 {
|
pub const int_type_name = $if new_int ?
|
||||||
pub const int_type_name = $if new_int ? {
|
&& (arm64 || amd64 || rv64 || s390x || ppc64le || loongarch64) {
|
||||||
//'int'
|
'vint_t'
|
||||||
'i64'
|
|
||||||
} $else {
|
} $else {
|
||||||
'int'
|
'int'
|
||||||
}
|
}
|
||||||
|
@ -2816,7 +2815,7 @@ pub fn (expr Expr) is_literal() bool {
|
||||||
}
|
}
|
||||||
CastExpr {
|
CastExpr {
|
||||||
!expr.has_arg && expr.expr.is_literal() && (expr.typ.is_any_kind_of_pointer()
|
!expr.has_arg && expr.expr.is_literal() && (expr.typ.is_any_kind_of_pointer()
|
||||||
|| expr.typ in [i8_type, i16_type, int_type, i64_type, u8_type, u16_type, u32_type, u64_type, f32_type, f64_type, char_type, bool_type, rune_type])
|
|| expr.typ in [i8_type, i16_type, i32_type, int_type, i64_type, u8_type, u16_type, u32_type, u64_type, f32_type, f64_type, char_type, bool_type, rune_type])
|
||||||
}
|
}
|
||||||
SizeOf, IsRefType {
|
SizeOf, IsRefType {
|
||||||
expr.is_type || expr.expr.is_literal()
|
expr.is_type || expr.expr.is_literal()
|
||||||
|
|
|
@ -1340,7 +1340,7 @@ pub fn (mut t Table) find_or_register_fn_type(f Fn, is_anon bool, has_decl bool)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut t Table) add_placeholder_type(name string, language Language) int {
|
pub fn (mut t Table) add_placeholder_type(name string, cname string, language Language) int {
|
||||||
mut modname := ''
|
mut modname := ''
|
||||||
if name.contains('.') {
|
if name.contains('.') {
|
||||||
modname = name.all_before_last('.')
|
modname = name.all_before_last('.')
|
||||||
|
@ -1348,7 +1348,7 @@ pub fn (mut t Table) add_placeholder_type(name string, language Language) int {
|
||||||
ph_type := TypeSymbol{
|
ph_type := TypeSymbol{
|
||||||
kind: .placeholder
|
kind: .placeholder
|
||||||
name: name
|
name: name
|
||||||
cname: util.no_dots(name).replace_each(['&', ''])
|
cname: util.no_dots(cname).replace_each(['&', ''])
|
||||||
language: language
|
language: language
|
||||||
mod: modname
|
mod: modname
|
||||||
is_pub: true
|
is_pub: true
|
||||||
|
@ -1591,7 +1591,7 @@ pub fn (mut t Table) bitsize_to_type(bit_size int) Type {
|
||||||
return i16_type
|
return i16_type
|
||||||
}
|
}
|
||||||
32 {
|
32 {
|
||||||
return int_type
|
return i32_type
|
||||||
}
|
}
|
||||||
64 {
|
64 {
|
||||||
return i64_type
|
return i64_type
|
||||||
|
@ -1854,6 +1854,7 @@ pub fn (mut t Table) convert_generic_type(generic_type Type, generic_names []str
|
||||||
if sym.info.is_generic {
|
if sym.info.is_generic {
|
||||||
mut nrt := '${sym.name}['
|
mut nrt := '${sym.name}['
|
||||||
mut rnrt := '${sym.rname}['
|
mut rnrt := '${sym.rname}['
|
||||||
|
mut cnrt := '${sym.cname}['
|
||||||
mut t_generic_names := generic_names.clone()
|
mut t_generic_names := generic_names.clone()
|
||||||
mut t_to_types := to_types.clone()
|
mut t_to_types := to_types.clone()
|
||||||
if sym.generic_types.len > 0 && sym.generic_types.len == sym.info.generic_types.len
|
if sym.generic_types.len > 0 && sym.generic_types.len == sym.info.generic_types.len
|
||||||
|
@ -1886,9 +1887,11 @@ pub fn (mut t Table) convert_generic_type(generic_type Type, generic_names []str
|
||||||
}
|
}
|
||||||
nrt += gts.name
|
nrt += gts.name
|
||||||
rnrt += gts.name
|
rnrt += gts.name
|
||||||
|
cnrt += gts.cname
|
||||||
if i != sym.info.generic_types.len - 1 {
|
if i != sym.info.generic_types.len - 1 {
|
||||||
nrt += ', '
|
nrt += ', '
|
||||||
rnrt += ', '
|
rnrt += ', '
|
||||||
|
cnrt += ', '
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return none
|
return none
|
||||||
|
@ -1896,11 +1899,12 @@ pub fn (mut t Table) convert_generic_type(generic_type Type, generic_names []str
|
||||||
}
|
}
|
||||||
nrt += ']'
|
nrt += ']'
|
||||||
rnrt += ']'
|
rnrt += ']'
|
||||||
|
cnrt += ']'
|
||||||
mut idx := t.type_idxs[nrt]
|
mut idx := t.type_idxs[nrt]
|
||||||
if idx == 0 {
|
if idx == 0 {
|
||||||
idx = t.type_idxs[rnrt]
|
idx = t.type_idxs[rnrt]
|
||||||
if idx == 0 {
|
if idx == 0 {
|
||||||
idx = t.add_placeholder_type(nrt, .v)
|
idx = t.add_placeholder_type(nrt, cnrt, .v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new_type(idx).derive_add_muls(generic_type).clear_flag(.generic)
|
return new_type(idx).derive_add_muls(generic_type).clear_flag(.generic)
|
||||||
|
|
|
@ -625,18 +625,46 @@ pub fn (typ Type) is_unsigned() bool {
|
||||||
|
|
||||||
pub fn (typ Type) flip_signedness() Type {
|
pub fn (typ Type) flip_signedness() Type {
|
||||||
return match typ {
|
return match typ {
|
||||||
i8_type { u8_type }
|
i8_type {
|
||||||
i16_type { u16_type }
|
u8_type
|
||||||
int_type { u32_type }
|
}
|
||||||
i32_type { u32_type }
|
i16_type {
|
||||||
isize_type { usize_type }
|
u16_type
|
||||||
i64_type { u64_type }
|
}
|
||||||
u8_type { i8_type }
|
i32_type {
|
||||||
u16_type { i16_type }
|
u32_type
|
||||||
u32_type { int_type }
|
}
|
||||||
usize_type { isize_type }
|
i64_type {
|
||||||
u64_type { i64_type }
|
u64_type
|
||||||
else { typ }
|
}
|
||||||
|
int_type {
|
||||||
|
$if new_int ? && (arm64 || amd64 || rv64 || s390x || ppc64le || loongarch64) {
|
||||||
|
u64_type
|
||||||
|
} $else {
|
||||||
|
u32_type
|
||||||
|
}
|
||||||
|
}
|
||||||
|
isize_type {
|
||||||
|
usize_type
|
||||||
|
}
|
||||||
|
u8_type {
|
||||||
|
i8_type
|
||||||
|
}
|
||||||
|
u16_type {
|
||||||
|
i16_type
|
||||||
|
}
|
||||||
|
u32_type {
|
||||||
|
i32_type
|
||||||
|
}
|
||||||
|
u64_type {
|
||||||
|
i64_type
|
||||||
|
}
|
||||||
|
usize_type {
|
||||||
|
isize_type
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
void_type
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -699,18 +727,18 @@ pub const error_type_idx = 30
|
||||||
pub const nil_type_idx = 31
|
pub const nil_type_idx = 31
|
||||||
|
|
||||||
// Note: builtin_type_names must be in the same order as the idx consts above
|
// Note: builtin_type_names must be in the same order as the idx consts above
|
||||||
pub const builtin_type_names = ['void', 'voidptr', 'byteptr', 'charptr', 'i8', 'i16', 'int', 'i64',
|
pub const builtin_type_names = ['void', 'voidptr', 'byteptr', 'charptr', 'i8', 'i16', 'i32', 'int',
|
||||||
'isize', 'u8', 'u16', 'u32', 'u64', 'usize', 'f32', 'f64', 'char', 'bool', 'none', 'string',
|
'i64', 'isize', 'u8', 'u16', 'u32', 'u64', 'usize', 'f32', 'f64', 'char', 'bool', 'none',
|
||||||
'rune', 'array', 'map', 'chan', 'any', 'float_literal', 'int_literal', 'thread', 'Error', 'nil',
|
'string', 'rune', 'array', 'map', 'chan', 'any', 'float_literal', 'int_literal', 'thread',
|
||||||
'i32']
|
'Error', 'nil']
|
||||||
|
|
||||||
pub const builtin_type_names_matcher = token.new_keywords_matcher_from_array_trie(builtin_type_names)
|
pub const builtin_type_names_matcher = token.new_keywords_matcher_from_array_trie(builtin_type_names)
|
||||||
|
|
||||||
pub const integer_type_idxs = [i8_type_idx, i16_type_idx, int_type_idx, i64_type_idx, u8_type_idx,
|
pub const integer_type_idxs = [i8_type_idx, i16_type_idx, i32_type_idx, int_type_idx, i64_type_idx,
|
||||||
u16_type_idx, u32_type_idx, u64_type_idx, isize_type_idx, usize_type_idx, int_literal_type_idx,
|
u8_type_idx, u16_type_idx, u32_type_idx, u64_type_idx, isize_type_idx, usize_type_idx,
|
||||||
rune_type_idx, i32_type_idx]
|
int_literal_type_idx, rune_type_idx]
|
||||||
pub const signed_integer_type_idxs = [char_type_idx, i8_type_idx, i16_type_idx, int_type_idx,
|
pub const signed_integer_type_idxs = [char_type_idx, i8_type_idx, i16_type_idx, i32_type_idx,
|
||||||
i64_type_idx, i32_type_idx, isize_type_idx]
|
int_type_idx, i64_type_idx, isize_type_idx]
|
||||||
pub const unsigned_integer_type_idxs = [u8_type_idx, u16_type_idx, u32_type_idx, u64_type_idx,
|
pub const unsigned_integer_type_idxs = [u8_type_idx, u16_type_idx, u32_type_idx, u64_type_idx,
|
||||||
usize_type_idx]
|
usize_type_idx]
|
||||||
// C will promote any type smaller than int to int in an expression
|
// C will promote any type smaller than int to int in an expression
|
||||||
|
@ -1161,7 +1189,7 @@ pub fn (t &TypeSymbol) is_pointer() bool {
|
||||||
|
|
||||||
@[inline]
|
@[inline]
|
||||||
pub fn (t &TypeSymbol) is_int() bool {
|
pub fn (t &TypeSymbol) is_int() bool {
|
||||||
res := t.kind in [.i8, .i16, .int, .i64, .i32, .isize, .u8, .u16, .u32, .u64, .usize,
|
res := t.kind in [.i8, .i16, .i32, .int, .i64, .isize, .u8, .u16, .u32, .u64, .usize,
|
||||||
.int_literal, .rune]
|
.int_literal, .rune]
|
||||||
if !res && t.kind == .alias {
|
if !res && t.kind == .alias {
|
||||||
return (t.info as Alias).parent_type.is_int()
|
return (t.info as Alias).parent_type.is_int()
|
||||||
|
@ -1232,18 +1260,13 @@ pub fn (t &Table) type_size(typ Type) (int, int) {
|
||||||
align = 4
|
align = 4
|
||||||
}
|
}
|
||||||
.int {
|
.int {
|
||||||
$if new_int ? {
|
$if new_int ? && (arm64 || amd64 || rv64 || s390x || ppc64le || loongarch64) {
|
||||||
$if arm64 || amd64 {
|
|
||||||
size = 8
|
size = 8
|
||||||
align = 8
|
align = 8
|
||||||
} $else {
|
} $else {
|
||||||
size = 4
|
size = 4
|
||||||
align = 4
|
align = 4
|
||||||
}
|
}
|
||||||
} $else {
|
|
||||||
size = 4
|
|
||||||
align = 4
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.i64, .u64, .int_literal, .f64, .float_literal {
|
.i64, .u64, .int_literal, .f64, .float_literal {
|
||||||
size = 8
|
size = 8
|
||||||
|
|
|
@ -746,14 +746,14 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
|
||||||
} else if left_type.is_unsigned() {
|
} else if left_type.is_unsigned() {
|
||||||
left_type
|
left_type
|
||||||
} else {
|
} else {
|
||||||
// signed types' idx adds with 5 will get correct relative unsigned type
|
// signed types => unsigned types
|
||||||
// i8 => byte
|
unsigned_type := left_type.flip_signedness()
|
||||||
// i16 => u16
|
if unsigned_type == ast.void_type {
|
||||||
// int => u32
|
c.error('invalid operation: shift on type `${c.table.sym(left_type).name}`',
|
||||||
// i64 => u64
|
node.pos)
|
||||||
// isize => usize
|
ast.void_type
|
||||||
// i128 => u128 NOT IMPLEMENTED YET
|
}
|
||||||
ast.idx_to_type(left_type.idx() + ast.u32_type_idx - ast.int_type_idx)
|
unsigned_type
|
||||||
}
|
}
|
||||||
|
|
||||||
node = ast.AssignStmt{
|
node = ast.AssignStmt{
|
||||||
|
|
|
@ -625,18 +625,46 @@ fn (mut c Checker) check_shift(mut node ast.InfixExpr, left_type_ ast.Type, righ
|
||||||
return left_type
|
return left_type
|
||||||
}
|
}
|
||||||
moffset := match left_type_final {
|
moffset := match left_type_final {
|
||||||
ast.char_type { 7 }
|
ast.char_type {
|
||||||
ast.i8_type { 7 }
|
7
|
||||||
ast.i16_type { 15 }
|
}
|
||||||
ast.int_type { 31 }
|
ast.i8_type {
|
||||||
ast.i64_type { 63 }
|
7
|
||||||
|
}
|
||||||
|
ast.i16_type {
|
||||||
|
15
|
||||||
|
}
|
||||||
|
ast.i32_type {
|
||||||
|
31
|
||||||
|
}
|
||||||
|
ast.int_type {
|
||||||
|
$if new_int ?
|
||||||
|
&& (arm64 || amd64 || rv64 || s390x || ppc64le || loongarch64) {
|
||||||
|
63
|
||||||
|
} $else {
|
||||||
|
31
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ast.i64_type {
|
||||||
|
63
|
||||||
|
}
|
||||||
//
|
//
|
||||||
ast.u8_type { 7 }
|
ast.u8_type {
|
||||||
|
7
|
||||||
|
}
|
||||||
// ast.u8_type { 7 }
|
// ast.u8_type { 7 }
|
||||||
ast.u16_type { 15 }
|
ast.u16_type {
|
||||||
ast.u32_type { 31 }
|
15
|
||||||
ast.u64_type { 63 }
|
}
|
||||||
else { 64 }
|
ast.u32_type {
|
||||||
|
31
|
||||||
|
}
|
||||||
|
ast.u64_type {
|
||||||
|
63
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
64
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ival > moffset && !c.pref.translated && !c.file.is_translated {
|
if ival > moffset && !c.pref.translated && !c.file.is_translated {
|
||||||
c.error('shift count for type `${left_sym_final.name}` too large (maximum: ${moffset} bits)',
|
c.error('shift count for type `${left_sym_final.name}` too large (maximum: ${moffset} bits)',
|
||||||
|
|
|
@ -36,8 +36,8 @@ pub const fixed_array_builtin_methods = ['contains', 'index', 'any', 'all', 'wai
|
||||||
'sorted', 'sort_with_compare', 'sorted_with_compare', 'reverse', 'reverse_in_place', 'count']
|
'sorted', 'sort_with_compare', 'sorted_with_compare', 'reverse', 'reverse_in_place', 'count']
|
||||||
pub const fixed_array_builtin_methods_chk = token.new_keywords_matcher_from_array_trie(fixed_array_builtin_methods)
|
pub const fixed_array_builtin_methods_chk = token.new_keywords_matcher_from_array_trie(fixed_array_builtin_methods)
|
||||||
// TODO: remove `byte` from this list when it is no longer supported
|
// TODO: remove `byte` from this list when it is no longer supported
|
||||||
pub const reserved_type_names = ['bool', 'char', 'i8', 'i16', 'int', 'i64', 'u8', 'u16', 'u32',
|
pub const reserved_type_names = ['bool', 'char', 'i8', 'i16', 'i32', 'int', 'i64', 'u8', 'u16',
|
||||||
'u64', 'f32', 'f64', 'map', 'string', 'rune', 'usize', 'isize', 'voidptr', 'thread']
|
'u32', 'u64', 'f32', 'f64', 'map', 'string', 'rune', 'usize', 'isize', 'voidptr', 'thread']
|
||||||
pub const reserved_type_names_chk = token.new_keywords_matcher_from_array_trie(reserved_type_names)
|
pub const reserved_type_names_chk = token.new_keywords_matcher_from_array_trie(reserved_type_names)
|
||||||
pub const vroot_is_deprecated_message = '@VROOT is deprecated, use @VMODROOT or @VEXEROOT instead'
|
pub const vroot_is_deprecated_message = '@VROOT is deprecated, use @VMODROOT or @VEXEROOT instead'
|
||||||
|
|
||||||
|
@ -686,7 +686,7 @@ fn (mut c Checker) alias_type_decl(mut node ast.AliasTypeDecl) {
|
||||||
.voidptr, .byteptr, .charptr {}
|
.voidptr, .byteptr, .charptr {}
|
||||||
.char, .rune, .bool {}
|
.char, .rune, .bool {}
|
||||||
.string, .enum, .none, .any {}
|
.string, .enum, .none, .any {}
|
||||||
.i8, .i16, .int, .i64, .isize {}
|
.i8, .i16, .i32, .int, .i64, .isize {}
|
||||||
.u8, .u16, .u32, .u64, .usize {}
|
.u8, .u16, .u32, .u64, .usize {}
|
||||||
.f32, .f64 {}
|
.f32, .f64 {}
|
||||||
.interface {}
|
.interface {}
|
||||||
|
@ -2048,9 +2048,16 @@ fn (mut c Checker) enum_decl(mut node ast.EnumDecl) {
|
||||||
ast.i16_type {
|
ast.i16_type {
|
||||||
signed, enum_imin, enum_imax = true, min_i16, max_i16
|
signed, enum_imin, enum_imax = true, min_i16, max_i16
|
||||||
}
|
}
|
||||||
ast.int_type {
|
ast.i32_type {
|
||||||
signed, enum_imin, enum_imax = true, min_i32, max_i32
|
signed, enum_imin, enum_imax = true, min_i32, max_i32
|
||||||
}
|
}
|
||||||
|
ast.int_type {
|
||||||
|
$if new_int ? && (arm64 || amd64 || rv64 || s390x || ppc64le || loongarch64) {
|
||||||
|
signed, enum_imin, enum_imax = true, min_i32, max_i32
|
||||||
|
} $else {
|
||||||
|
signed, enum_imin, enum_imax = true, min_i64, max_i64
|
||||||
|
}
|
||||||
|
}
|
||||||
ast.i64_type {
|
ast.i64_type {
|
||||||
signed, enum_imin, enum_imax = true, min_i64, max_i64
|
signed, enum_imin, enum_imax = true, min_i64, max_i64
|
||||||
}
|
}
|
||||||
|
@ -3795,9 +3802,16 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
|
||||||
ast.i16_type_idx {
|
ast.i16_type_idx {
|
||||||
u64(0xffff)
|
u64(0xffff)
|
||||||
}
|
}
|
||||||
ast.int_type_idx, ast.i32_type_idx {
|
ast.i32_type_idx {
|
||||||
u64(0xffffffff)
|
u64(0xffffffff)
|
||||||
}
|
}
|
||||||
|
ast.int_type_idx {
|
||||||
|
$if new_int ? && (arm64 || amd64 || rv64 || s390x || ppc64le || loongarch64) {
|
||||||
|
u64(0xffffffffffffffff)
|
||||||
|
} $else {
|
||||||
|
u64(0xffffffff)
|
||||||
|
}
|
||||||
|
}
|
||||||
ast.i64_type_idx {
|
ast.i64_type_idx {
|
||||||
u64(0xffffffffffffffff)
|
u64(0xffffffffffffffff)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3427,7 +3427,7 @@ fn (mut c Checker) array_builtin_method_call(mut node ast.CallExpr, left_type as
|
||||||
'\ne.g. `users.${method_name}(a.id < b.id)`', node.pos)
|
'\ne.g. `users.${method_name}(a.id < b.id)`', node.pos)
|
||||||
}
|
}
|
||||||
} else if !(c.table.sym(elem_typ).has_method('<')
|
} else if !(c.table.sym(elem_typ).has_method('<')
|
||||||
|| c.table.unalias_num_type(elem_typ) in [ast.int_type, ast.int_type.ref(), ast.string_type, ast.string_type.ref(), ast.i8_type, ast.i16_type, ast.i64_type, ast.u8_type, ast.rune_type, ast.u16_type, ast.u32_type, ast.u64_type, ast.f32_type, ast.f64_type, ast.char_type, ast.bool_type, ast.float_literal_type, ast.int_literal_type]) {
|
|| c.table.unalias_num_type(elem_typ) in [ast.int_type, ast.int_type.ref(), ast.string_type, ast.string_type.ref(), ast.i8_type, ast.i16_type, ast.i32_type, ast.i64_type, ast.u8_type, ast.rune_type, ast.u16_type, ast.u32_type, ast.u64_type, ast.f32_type, ast.f64_type, ast.char_type, ast.bool_type, ast.float_literal_type, ast.int_literal_type]) {
|
||||||
c.error('custom sorting condition must be supplied for type `${c.table.type_to_str(elem_typ)}`',
|
c.error('custom sorting condition must be supplied for type `${c.table.type_to_str(elem_typ)}`',
|
||||||
node.pos)
|
node.pos)
|
||||||
}
|
}
|
||||||
|
@ -3778,7 +3778,7 @@ fn (mut c Checker) fixed_array_builtin_method_call(mut node ast.CallExpr, left_t
|
||||||
'\ne.g. `users.${method_name}(a.id < b.id)`', node.pos)
|
'\ne.g. `users.${method_name}(a.id < b.id)`', node.pos)
|
||||||
}
|
}
|
||||||
} else if !(c.table.sym(elem_typ).has_method('<')
|
} else if !(c.table.sym(elem_typ).has_method('<')
|
||||||
|| c.table.unalias_num_type(elem_typ) in [ast.int_type, ast.int_type.ref(), ast.string_type, ast.string_type.ref(), ast.i8_type, ast.i16_type, ast.i64_type, ast.u8_type, ast.rune_type, ast.u16_type, ast.u32_type, ast.u64_type, ast.f32_type, ast.f64_type, ast.char_type, ast.bool_type, ast.float_literal_type, ast.int_literal_type]) {
|
|| c.table.unalias_num_type(elem_typ) in [ast.int_type, ast.int_type.ref(), ast.string_type, ast.string_type.ref(), ast.i8_type, ast.i16_type, ast.i32_type, ast.i64_type, ast.u8_type, ast.rune_type, ast.u16_type, ast.u32_type, ast.u64_type, ast.f32_type, ast.f64_type, ast.char_type, ast.bool_type, ast.float_literal_type, ast.int_literal_type]) {
|
||||||
c.error('custom sorting condition must be supplied for type `${c.table.type_to_str(elem_typ)}`',
|
c.error('custom sorting condition must be supplied for type `${c.table.type_to_str(elem_typ)}`',
|
||||||
node.pos)
|
node.pos)
|
||||||
}
|
}
|
||||||
|
|
|
@ -651,22 +651,12 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
|
||||||
} else if left_type.is_unsigned() {
|
} else if left_type.is_unsigned() {
|
||||||
left_type
|
left_type
|
||||||
} else {
|
} else {
|
||||||
// signed types' idx adds with 5 will get correct relative unsigned type
|
unsigned_type := left_type.flip_signedness()
|
||||||
// i8 => byte
|
if unsigned_type == ast.void_type {
|
||||||
// i16 => u16
|
// signed type can't convert to an unsigned type
|
||||||
// int => u32
|
0
|
||||||
// i64 => u64
|
}
|
||||||
// isize => usize
|
unsigned_type
|
||||||
// i128 => u128 NOT IMPLEMENTED YET
|
|
||||||
ast.idx_to_type(match left_type.idx() {
|
|
||||||
ast.i8_type_idx { ast.u8_type_idx }
|
|
||||||
ast.i16_type_idx { ast.u16_type_idx }
|
|
||||||
ast.i32_type_idx { ast.u32_type_idx }
|
|
||||||
ast.int_type_idx { ast.u32_type_idx }
|
|
||||||
ast.i64_type_idx { ast.u64_type_idx }
|
|
||||||
ast.isize_type_idx { ast.usize_type_idx }
|
|
||||||
else { 0 }
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if modified_left_type == 0 {
|
if modified_left_type == 0 {
|
||||||
|
|
|
@ -390,11 +390,23 @@ fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type {
|
||||||
needs_explicit_cast = true
|
needs_explicit_cast = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.i32, .int {
|
.i32 {
|
||||||
if !(num >= min_i32 && num <= max_i32) {
|
if !(num >= min_i32 && num <= max_i32) {
|
||||||
needs_explicit_cast = true
|
needs_explicit_cast = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.int {
|
||||||
|
$if new_int ? && (arm64 || amd64 || rv64
|
||||||
|
|| s390x || ppc64le || loongarch64) {
|
||||||
|
if !(num >= min_i64 && num <= max_i64) {
|
||||||
|
needs_explicit_cast = true
|
||||||
|
}
|
||||||
|
} $else {
|
||||||
|
if !(num >= min_i32 && num <= max_i32) {
|
||||||
|
needs_explicit_cast = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
.i64 {
|
.i64 {
|
||||||
if !(num >= min_i64 && num <= max_i64) {
|
if !(num >= min_i64 && num <= max_i64) {
|
||||||
needs_explicit_cast = true
|
needs_explicit_cast = true
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
vlib/v/checker/tests/enum_field_overflow.vv:3:10: error: enum value `2147483647` overflows the enum type `int`, values of which have to be in [-2147483648, 2147483647]
|
vlib/v/checker/tests/enum_field_overflow.vv:3:10: error: enum value `2147483647` overflows the enum type `i32`, values of which have to be in [-2147483648, 2147483647]
|
||||||
1 | enum Color {
|
1 | enum Color as i32 {
|
||||||
2 | red
|
2 | red
|
||||||
3 | green = 2147483647
|
3 | green = 2147483647
|
||||||
| ~~~~~~~~~~
|
| ~~~~~~~~~~
|
||||||
4 | blue
|
4 | blue
|
||||||
5 | }
|
5 | }
|
||||||
vlib/v/checker/tests/enum_field_overflow.vv:4:2: error: enum value overflows type `int`, which has a maximum value of 2147483647
|
vlib/v/checker/tests/enum_field_overflow.vv:4:2: error: enum value overflows type `i32`, which has a maximum value of 2147483647
|
||||||
2 | red
|
2 | red
|
||||||
3 | green = 2147483647
|
3 | green = 2147483647
|
||||||
4 | blue
|
4 | blue
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
enum Color {
|
enum Color as i32 {
|
||||||
red
|
red
|
||||||
green = 2147483647
|
green = 2147483647
|
||||||
blue
|
blue
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
vlib/v/checker/tests/enum_field_value_overflow.vv:3:10: error: enum value `2147483648` overflows the enum type `int`, values of which have to be in [-2147483648, 2147483647]
|
vlib/v/checker/tests/enum_field_value_overflow.vv:3:10: error: enum value `2147483648` overflows the enum type `i32`, values of which have to be in [-2147483648, 2147483647]
|
||||||
1 | enum Color {
|
1 | enum Color as i32 {
|
||||||
2 | red
|
2 | red
|
||||||
3 | green = 2147483648
|
3 | green = 2147483648
|
||||||
| ~~~~~~~~~~
|
| ~~~~~~~~~~
|
||||||
|
@ -40,8 +40,8 @@ vlib/v/checker/tests/enum_field_value_overflow.vv:21:10: error: enum value `3276
|
||||||
| ~~~~~
|
| ~~~~~
|
||||||
22 | blue
|
22 | blue
|
||||||
23 | }
|
23 | }
|
||||||
vlib/v/checker/tests/enum_field_value_overflow.vv:27:10: error: enum value `2147483648` overflows the enum type `int`, values of which have to be in [-2147483648, 2147483647]
|
vlib/v/checker/tests/enum_field_value_overflow.vv:27:10: error: enum value `2147483648` overflows the enum type `i32`, values of which have to be in [-2147483648, 2147483647]
|
||||||
25 | enum ColorI32 {
|
25 | enum ColorI32 as i32 {
|
||||||
26 | red
|
26 | red
|
||||||
27 | green = 2147483648
|
27 | green = 2147483648
|
||||||
| ~~~~~~~~~~
|
| ~~~~~~~~~~
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
enum Color {
|
enum Color as i32 {
|
||||||
red
|
red
|
||||||
green = 2147483648
|
green = 2147483648
|
||||||
blue
|
blue
|
||||||
|
@ -22,7 +22,7 @@ enum ColorI16 as i16 {
|
||||||
blue
|
blue
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ColorI32 {
|
enum ColorI32 as i32 {
|
||||||
red
|
red
|
||||||
green = 2147483648
|
green = 2147483648
|
||||||
blue
|
blue
|
||||||
|
|
|
@ -117,11 +117,11 @@ fn (mut g Gen) fixed_array_init(node ast.ArrayInit, array_type Type, var_name st
|
||||||
g.writeln2(';', '{')
|
g.writeln2(';', '{')
|
||||||
g.indent++
|
g.indent++
|
||||||
g.writeln('${elem_typ_str}* pelem = (${elem_typ_str}*)${past.tmp_var};')
|
g.writeln('${elem_typ_str}* pelem = (${elem_typ_str}*)${past.tmp_var};')
|
||||||
g.writeln('int _len = (int)sizeof(${past.tmp_var}) / sizeof(${elem_typ_str});')
|
g.writeln('${ast.int_type_name} _len = (${ast.int_type_name})sizeof(${past.tmp_var}) / sizeof(${elem_typ_str});')
|
||||||
g.writeln('for (int index=0; index<_len; index++, pelem++) {')
|
g.writeln('for (${ast.int_type_name} index=0; index<_len; index++, pelem++) {')
|
||||||
g.set_current_pos_as_last_stmt_pos()
|
g.set_current_pos_as_last_stmt_pos()
|
||||||
g.indent++
|
g.indent++
|
||||||
g.writeln('int it = index;') // FIXME: Remove this line when it is fully forbidden
|
g.writeln('${ast.int_type_name} it = index;') // FIXME: Remove this line when it is fully forbidden
|
||||||
g.write('*pelem = ')
|
g.write('*pelem = ')
|
||||||
g.expr_with_init(node)
|
g.expr_with_init(node)
|
||||||
g.writeln(';')
|
g.writeln(';')
|
||||||
|
@ -354,10 +354,10 @@ fn (mut g Gen) array_init_with_fields(node ast.ArrayInit, elem_type Type, is_amp
|
||||||
g.writeln2(';', '{')
|
g.writeln2(';', '{')
|
||||||
g.indent++
|
g.indent++
|
||||||
g.writeln('${elem_typ}* pelem = (${elem_typ}*)${past.tmp_var}.data;')
|
g.writeln('${elem_typ}* pelem = (${elem_typ}*)${past.tmp_var}.data;')
|
||||||
g.writeln('for (int index=0; index<${past.tmp_var}.len; index++, pelem++) {')
|
g.writeln('for (${ast.int_type_name} index=0; index<${past.tmp_var}.len; index++, pelem++) {')
|
||||||
g.set_current_pos_as_last_stmt_pos()
|
g.set_current_pos_as_last_stmt_pos()
|
||||||
g.indent++
|
g.indent++
|
||||||
g.writeln('int it = index;') // FIXME: Remove this line when it is fully forbidden
|
g.writeln('${ast.int_type_name} it = index;') // FIXME: Remove this line when it is fully forbidden
|
||||||
if elem_type.unaliased_sym.kind != .array_fixed {
|
if elem_type.unaliased_sym.kind != .array_fixed {
|
||||||
g.write('*pelem = ')
|
g.write('*pelem = ')
|
||||||
g.expr_with_init(node)
|
g.expr_with_init(node)
|
||||||
|
@ -423,7 +423,7 @@ fn (mut g Gen) array_init_with_fields(node ast.ArrayInit, elem_type Type, is_amp
|
||||||
g.expr(node.len_expr)
|
g.expr(node.len_expr)
|
||||||
g.writeln(') * sizeof(${elem_styp}));')
|
g.writeln(') * sizeof(${elem_styp}));')
|
||||||
ind := g.new_tmp_var()
|
ind := g.new_tmp_var()
|
||||||
g.write('for (int ${ind}=0; ${ind}<')
|
g.write('for (${ast.int_type_name} ${ind}=0; ${ind}<')
|
||||||
g.expr(node.len_expr)
|
g.expr(node.len_expr)
|
||||||
g.writeln('; ${ind}++) {')
|
g.writeln('; ${ind}++) {')
|
||||||
g.write('\t${tmp}[${ind}] = ')
|
g.write('\t${tmp}[${ind}] = ')
|
||||||
|
@ -565,7 +565,7 @@ fn (mut g Gen) gen_array_map(node ast.CallExpr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
i := g.new_tmp_var()
|
i := g.new_tmp_var()
|
||||||
g.writeln('for (int ${i} = 0; ${i} < ${past.tmp_var}_len; ++${i}) {')
|
g.writeln('for (${ast.int_type_name} ${i} = 0; ${i} < ${past.tmp_var}_len; ++${i}) {')
|
||||||
g.indent++
|
g.indent++
|
||||||
var_name := g.get_array_expr_param_name(mut expr)
|
var_name := g.get_array_expr_param_name(mut expr)
|
||||||
is_auto_heap := expr is ast.CastExpr && (expr.expr is ast.Ident && expr.expr.is_auto_heap())
|
is_auto_heap := expr is ast.CastExpr && (expr.expr is ast.Ident && expr.expr.is_auto_heap())
|
||||||
|
@ -958,7 +958,7 @@ fn (mut g Gen) gen_fixed_array_reverse_in_place(node ast.CallExpr) {
|
||||||
i := g.new_tmp_var()
|
i := g.new_tmp_var()
|
||||||
left_var := g.expr_string(node.left)
|
left_var := g.expr_string(node.left)
|
||||||
g.empty_line = true
|
g.empty_line = true
|
||||||
g.writeln('for (int ${i} = 0; ${i} < ${info.size}/2; ++${i}) {')
|
g.writeln('for (${ast.int_type_name} ${i} = 0; ${i} < ${info.size}/2; ++${i}) {')
|
||||||
g.writeln('\tmemcpy(&${tmp_var}, &${left_var}[${i}], sizeof(${elem_styp}));')
|
g.writeln('\tmemcpy(&${tmp_var}, &${left_var}[${i}], sizeof(${elem_styp}));')
|
||||||
g.writeln('\tmemcpy(&${left_var}[${i}], &${left_var}[${info.size}-${i}-1], sizeof(${elem_styp}));')
|
g.writeln('\tmemcpy(&${left_var}[${i}], &${left_var}[${info.size}-${i}-1], sizeof(${elem_styp}));')
|
||||||
g.writeln('\tmemcpy(&${left_var}[${info.size}-${i}-1], &${tmp_var}, sizeof(${elem_styp}));')
|
g.writeln('\tmemcpy(&${left_var}[${info.size}-${i}-1], &${tmp_var}, sizeof(${elem_styp}));')
|
||||||
|
@ -995,7 +995,7 @@ fn (mut g Gen) gen_array_filter(node ast.CallExpr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
i := g.new_tmp_var()
|
i := g.new_tmp_var()
|
||||||
g.writeln('for (int ${i} = 0; ${i} < ${past.tmp_var}_len; ++${i}) {')
|
g.writeln('for (${ast.int_type_name} ${i} = 0; ${i} < ${past.tmp_var}_len; ++${i}) {')
|
||||||
g.indent++
|
g.indent++
|
||||||
g.write_prepared_var(var_name, info.elem_type, elem_type_str, past.tmp_var, i, true,
|
g.write_prepared_var(var_name, info.elem_type, elem_type_str, past.tmp_var, i, true,
|
||||||
false)
|
false)
|
||||||
|
@ -1133,10 +1133,6 @@ fn (mut g Gen) get_array_contains_method(typ ast.Type) string {
|
||||||
|
|
||||||
fn (mut g Gen) gen_array_contains_methods() {
|
fn (mut g Gen) gen_array_contains_methods() {
|
||||||
mut done := []ast.Type{}
|
mut done := []ast.Type{}
|
||||||
mut got_int_str := false
|
|
||||||
$if new_int ? {
|
|
||||||
println(g.array_contains_types)
|
|
||||||
}
|
|
||||||
for t in g.array_contains_types {
|
for t in g.array_contains_types {
|
||||||
left_final_sym := g.table.final_sym(t)
|
left_final_sym := g.table.final_sym(t)
|
||||||
if left_final_sym.idx in done || g.table.sym(t).has_method('contains') {
|
if left_final_sym.idx in done || g.table.sym(t).has_method('contains') {
|
||||||
|
@ -1147,20 +1143,6 @@ fn (mut g Gen) gen_array_contains_methods() {
|
||||||
mut left_type_str := g.styp(t)
|
mut left_type_str := g.styp(t)
|
||||||
fn_name := '${left_type_str}_contains'
|
fn_name := '${left_type_str}_contains'
|
||||||
|
|
||||||
$if new_int ? {
|
|
||||||
if fn_name == 'Array_i64_contains' {
|
|
||||||
if got_int_str {
|
|
||||||
continue
|
|
||||||
} else {
|
|
||||||
got_int_str = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if t == ast.int_type_idx || t == ast.i64_type_idx {
|
|
||||||
// continue
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
if left_final_sym.kind == .array {
|
if left_final_sym.kind == .array {
|
||||||
elem_type := (left_final_sym.info as ast.Array).elem_type
|
elem_type := (left_final_sym.info as ast.Array).elem_type
|
||||||
mut elem_type_str := g.styp(elem_type)
|
mut elem_type_str := g.styp(elem_type)
|
||||||
|
@ -1172,7 +1154,7 @@ fn (mut g Gen) gen_array_contains_methods() {
|
||||||
}
|
}
|
||||||
g.type_definitions.writeln('${g.static_non_parallel}bool ${fn_name}(${left_type_str} a, ${elem_type_str} v);')
|
g.type_definitions.writeln('${g.static_non_parallel}bool ${fn_name}(${left_type_str} a, ${elem_type_str} v);')
|
||||||
fn_builder.writeln('${g.static_non_parallel}bool ${fn_name}(${left_type_str} a, ${elem_type_str} v) {')
|
fn_builder.writeln('${g.static_non_parallel}bool ${fn_name}(${left_type_str} a, ${elem_type_str} v) {')
|
||||||
fn_builder.writeln('\tfor (int i = 0; i < a.len; ++i) {')
|
fn_builder.writeln('\tfor (${ast.int_type_name} i = 0; i < a.len; ++i) {')
|
||||||
if elem_kind == .string {
|
if elem_kind == .string {
|
||||||
fn_builder.writeln('\t\tif (builtin__fast_string_eq(((string*)a.data)[i], v)) {')
|
fn_builder.writeln('\t\tif (builtin__fast_string_eq(((string*)a.data)[i], v)) {')
|
||||||
} else if elem_kind in [.array, .array_fixed] && elem_is_not_ptr {
|
} else if elem_kind in [.array, .array_fixed] && elem_is_not_ptr {
|
||||||
|
@ -1214,7 +1196,7 @@ fn (mut g Gen) gen_array_contains_methods() {
|
||||||
}
|
}
|
||||||
g.type_definitions.writeln('${g.static_non_parallel}bool ${fn_name}(${left_type_str} a, ${elem_type_str} v);')
|
g.type_definitions.writeln('${g.static_non_parallel}bool ${fn_name}(${left_type_str} a, ${elem_type_str} v);')
|
||||||
fn_builder.writeln('${g.static_non_parallel}bool ${fn_name}(${left_type_str} a, ${elem_type_str} v) {')
|
fn_builder.writeln('${g.static_non_parallel}bool ${fn_name}(${left_type_str} a, ${elem_type_str} v) {')
|
||||||
fn_builder.writeln('\tfor (int i = 0; i < ${size}; ++i) {')
|
fn_builder.writeln('\tfor (${ast.int_type_name} i = 0; i < ${size}; ++i) {')
|
||||||
if elem_kind == .string {
|
if elem_kind == .string {
|
||||||
fn_builder.writeln('\t\tif (builtin__fast_string_eq(a[i], v)) {')
|
fn_builder.writeln('\t\tif (builtin__fast_string_eq(a[i], v)) {')
|
||||||
} else if elem_kind in [.array, .array_fixed] && elem_is_not_ptr {
|
} else if elem_kind in [.array, .array_fixed] && elem_is_not_ptr {
|
||||||
|
@ -1318,10 +1300,10 @@ fn (mut g Gen) gen_array_index_methods() {
|
||||||
left_type_str = 'Array_voidptr'
|
left_type_str = 'Array_voidptr'
|
||||||
elem_type_str = 'voidptr'
|
elem_type_str = 'voidptr'
|
||||||
}
|
}
|
||||||
g.type_definitions.writeln('${g.static_non_parallel}int ${fn_name}(${left_type_str} a, ${elem_type_str} v);')
|
g.type_definitions.writeln('${g.static_non_parallel}${ast.int_type_name} ${fn_name}(${left_type_str} a, ${elem_type_str} v);')
|
||||||
fn_builder.writeln('${g.static_non_parallel}int ${fn_name}(${left_type_str} a, ${elem_type_str} v) {')
|
fn_builder.writeln('${g.static_non_parallel}${ast.int_type_name} ${fn_name}(${left_type_str} a, ${elem_type_str} v) {')
|
||||||
fn_builder.writeln('\t${elem_type_str}* pelem = a.data;')
|
fn_builder.writeln('\t${elem_type_str}* pelem = a.data;')
|
||||||
fn_builder.writeln('\tfor (int i = 0; i < a.len; ++i, ++pelem) {')
|
fn_builder.writeln('\tfor (${ast.int_type_name} i = 0; i < a.len; ++i, ++pelem) {')
|
||||||
if elem_sym.kind == .string {
|
if elem_sym.kind == .string {
|
||||||
fn_builder.writeln('\t\tif (builtin__fast_string_eq(*pelem, v)) {')
|
fn_builder.writeln('\t\tif (builtin__fast_string_eq(*pelem, v)) {')
|
||||||
} else if elem_sym.kind in [.array, .array_fixed] && !info.elem_type.is_ptr() {
|
} else if elem_sym.kind in [.array, .array_fixed] && !info.elem_type.is_ptr() {
|
||||||
|
@ -1362,9 +1344,9 @@ fn (mut g Gen) gen_array_index_methods() {
|
||||||
if elem_sym.kind == .function {
|
if elem_sym.kind == .function {
|
||||||
elem_type_str = 'voidptr'
|
elem_type_str = 'voidptr'
|
||||||
}
|
}
|
||||||
g.type_definitions.writeln('${g.static_non_parallel}int ${fn_name}(${left_type_str} a, ${elem_type_str} v);')
|
g.type_definitions.writeln('${g.static_non_parallel}${ast.int_type_name} ${fn_name}(${left_type_str} a, ${elem_type_str} v);')
|
||||||
fn_builder.writeln('${g.static_non_parallel}int ${fn_name}(${left_type_str} a, ${elem_type_str} v) {')
|
fn_builder.writeln('${g.static_non_parallel}${ast.int_type_name} ${fn_name}(${left_type_str} a, ${elem_type_str} v) {')
|
||||||
fn_builder.writeln('\tfor (int i = 0; i < ${info.size}; ++i) {')
|
fn_builder.writeln('\tfor (${ast.int_type_name} i = 0; i < ${info.size}; ++i) {')
|
||||||
if elem_sym.kind == .string {
|
if elem_sym.kind == .string {
|
||||||
fn_builder.writeln('\t\tif (builtin__fast_string_eq(a[i], v)) {')
|
fn_builder.writeln('\t\tif (builtin__fast_string_eq(a[i], v)) {')
|
||||||
} else if elem_sym.kind in [.array, .array_fixed] && !info.elem_type.is_ptr() {
|
} else if elem_sym.kind in [.array, .array_fixed] && !info.elem_type.is_ptr() {
|
||||||
|
@ -1499,7 +1481,7 @@ fn (mut g Gen) gen_array_any(node ast.CallExpr) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i := g.new_tmp_var()
|
i := g.new_tmp_var()
|
||||||
g.writeln('for (int ${i} = 0; ${i} < ${past.tmp_var}_len; ++${i}) {')
|
g.writeln('for (${ast.int_type_name} ${i} = 0; ${i} < ${past.tmp_var}_len; ++${i}) {')
|
||||||
g.indent++
|
g.indent++
|
||||||
|
|
||||||
g.write_prepared_var(var_name, elem_type, elem_type_str, past.tmp_var, i, left_is_array,
|
g.write_prepared_var(var_name, elem_type, elem_type_str, past.tmp_var, i, left_is_array,
|
||||||
|
@ -1577,7 +1559,8 @@ fn (mut g Gen) gen_array_count(node ast.CallExpr) {
|
||||||
(sym.info as ast.ArrayFixed).elem_type
|
(sym.info as ast.ArrayFixed).elem_type
|
||||||
}
|
}
|
||||||
elem_type_str := g.styp(elem_type)
|
elem_type_str := g.styp(elem_type)
|
||||||
has_infix_left_var_name := g.write_prepared_tmp_value(past.tmp_var, node, 'int', '0')
|
has_infix_left_var_name := g.write_prepared_tmp_value(past.tmp_var, node, ast.int_type_name,
|
||||||
|
'0')
|
||||||
|
|
||||||
mut expr := node.args[0].expr
|
mut expr := node.args[0].expr
|
||||||
var_name := g.get_array_expr_param_name(mut expr)
|
var_name := g.get_array_expr_param_name(mut expr)
|
||||||
|
@ -1590,7 +1573,7 @@ fn (mut g Gen) gen_array_count(node ast.CallExpr) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i := g.new_tmp_var()
|
i := g.new_tmp_var()
|
||||||
g.writeln('for (int ${i} = 0; ${i} < ${past.tmp_var}_len; ++${i}) {')
|
g.writeln('for (${ast.int_type_name} ${i} = 0; ${i} < ${past.tmp_var}_len; ++${i}) {')
|
||||||
g.indent++
|
g.indent++
|
||||||
|
|
||||||
g.write_prepared_var(var_name, elem_type, elem_type_str, past.tmp_var, i, left_is_array,
|
g.write_prepared_var(var_name, elem_type, elem_type_str, past.tmp_var, i, left_is_array,
|
||||||
|
@ -1684,7 +1667,7 @@ fn (mut g Gen) gen_array_all(node ast.CallExpr) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g.writeln('for (int ${i} = 0; ${i} < ${past.tmp_var}_len; ++${i}) {')
|
g.writeln('for (${ast.int_type_name} ${i} = 0; ${i} < ${past.tmp_var}_len; ++${i}) {')
|
||||||
g.indent++
|
g.indent++
|
||||||
g.write_prepared_var(var_name, elem_type, elem_type_str, past.tmp_var, i, left_is_array,
|
g.write_prepared_var(var_name, elem_type, elem_type_str, past.tmp_var, i, left_is_array,
|
||||||
false)
|
false)
|
||||||
|
@ -1774,7 +1757,7 @@ fn (mut g Gen) write_prepared_tmp_value(tmp string, node &ast.CallExpr, tmp_styp
|
||||||
g.write('->val')
|
g.write('->val')
|
||||||
}
|
}
|
||||||
g.writeln(';')
|
g.writeln(';')
|
||||||
g.writeln('int ${tmp}_len = ${tmp}_orig.len;')
|
g.writeln('${ast.int_type_name} ${tmp}_len = ${tmp}_orig.len;')
|
||||||
} else if left_sym.kind == .array_fixed {
|
} else if left_sym.kind == .array_fixed {
|
||||||
left_info := left_sym.info as ast.ArrayFixed
|
left_info := left_sym.info as ast.ArrayFixed
|
||||||
left_styp := g.styp(left_type)
|
left_styp := g.styp(left_type)
|
||||||
|
@ -1792,7 +1775,7 @@ fn (mut g Gen) write_prepared_tmp_value(tmp string, node &ast.CallExpr, tmp_styp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g.writeln(', sizeof(${left_styp}));')
|
g.writeln(', sizeof(${left_styp}));')
|
||||||
g.writeln('int ${tmp}_len = ${left_info.size};')
|
g.writeln('${ast.int_type_name} ${tmp}_len = ${left_info.size};')
|
||||||
}
|
}
|
||||||
return has_infix_left_var_name
|
return has_infix_left_var_name
|
||||||
}
|
}
|
||||||
|
|
|
@ -1386,7 +1386,7 @@ fn (mut g Gen) gen_cross_tmp_variable(left []ast.Expr, val ast.Expr) {
|
||||||
if resolved_sym.is_builtin() && !fn_name.starts_with('builtin__') {
|
if resolved_sym.is_builtin() && !fn_name.starts_with('builtin__') {
|
||||||
fn_name = 'builtin__${fn_name}'
|
fn_name = 'builtin__${fn_name}'
|
||||||
}
|
}
|
||||||
} else if rec_typ_name in ['int_literal', 'float_literal'] {
|
} else if rec_typ_name in ['int_literal', 'float_literal', 'vint_t'] {
|
||||||
fn_name = 'builtin__${fn_name}'
|
fn_name = 'builtin__${fn_name}'
|
||||||
}
|
}
|
||||||
g.write('${fn_name}(&')
|
g.write('${fn_name}(&')
|
||||||
|
|
|
@ -384,7 +384,7 @@ fn (mut g Gen) gen_array_equality_fn(left_type ast.Type) string {
|
||||||
fn_builder.writeln('\tif (${left_len} != ${right_len}) {')
|
fn_builder.writeln('\tif (${left_len} != ${right_len}) {')
|
||||||
fn_builder.writeln('\t\treturn false;')
|
fn_builder.writeln('\t\treturn false;')
|
||||||
fn_builder.writeln('\t}')
|
fn_builder.writeln('\t}')
|
||||||
fn_builder.writeln('\tfor (int i = 0; i < ${left_len}; ++i) {')
|
fn_builder.writeln('\tfor (${ast.int_type_name} i = 0; i < ${left_len}; ++i) {')
|
||||||
// compare every pair of elements of the two arrays
|
// compare every pair of elements of the two arrays
|
||||||
if elem.sym.kind == .string {
|
if elem.sym.kind == .string {
|
||||||
fn_builder.writeln('\t\tif (!builtin__string__eq(*((${ptr_elem_styp}*)((byte*)${left_data}+(i*${left_elem}))), *((${ptr_elem_styp}*)((byte*)${right_data}+(i*${right_elem}))))) {')
|
fn_builder.writeln('\t\tif (!builtin__string__eq(*((${ptr_elem_styp}*)((byte*)${left_data}+(i*${left_elem}))), *((${ptr_elem_styp}*)((byte*)${right_data}+(i*${right_elem}))))) {')
|
||||||
|
@ -473,7 +473,7 @@ fn (mut g Gen) gen_fixed_array_equality_fn(left_type ast.Type) string {
|
||||||
fn_builder.writeln('\t\treturn true;')
|
fn_builder.writeln('\t\treturn true;')
|
||||||
fn_builder.writeln('\t}')
|
fn_builder.writeln('\t}')
|
||||||
}
|
}
|
||||||
fn_builder.writeln('\tfor (int i = 0; i < ${size}; ++i) {')
|
fn_builder.writeln('\tfor (${ast.int_type_name} i = 0; i < ${size}; ++i) {')
|
||||||
// compare every pair of elements of the two fixed arrays
|
// compare every pair of elements of the two fixed arrays
|
||||||
if elem.sym.kind == .string {
|
if elem.sym.kind == .string {
|
||||||
fn_builder.writeln('\t\tif (!builtin__string__eq(((string*)${left})[i], ((string*)${right})[i])) {')
|
fn_builder.writeln('\t\tif (!builtin__string__eq(((string*)${left})[i], ((string*)${right})[i])) {')
|
||||||
|
@ -538,7 +538,7 @@ fn (mut g Gen) gen_map_equality_fn(left_type ast.Type) string {
|
||||||
fn_builder.writeln('\tif (${left_len} != ${right_len}) {')
|
fn_builder.writeln('\tif (${left_len} != ${right_len}) {')
|
||||||
fn_builder.writeln('\t\treturn false;')
|
fn_builder.writeln('\t\treturn false;')
|
||||||
fn_builder.writeln('\t}')
|
fn_builder.writeln('\t}')
|
||||||
fn_builder.writeln('\tfor (int i = 0; i < ${key_values}.len; ++i) {')
|
fn_builder.writeln('\tfor (${ast.int_type_name} i = 0; i < ${key_values}.len; ++i) {')
|
||||||
fn_builder.writeln('\t\tif (!builtin__DenseArray_has_index(&${key_values}, i)) continue;')
|
fn_builder.writeln('\t\tif (!builtin__DenseArray_has_index(&${key_values}, i)) continue;')
|
||||||
fn_builder.writeln('\t\tvoidptr k = builtin__DenseArray_key(&${key_values}, i);')
|
fn_builder.writeln('\t\tvoidptr k = builtin__DenseArray_key(&${key_values}, i);')
|
||||||
fn_builder.writeln('\t\tif (!builtin__map_exists(${b}, k)) return false;')
|
fn_builder.writeln('\t\tif (!builtin__map_exists(${b}, k)) return false;')
|
||||||
|
@ -628,7 +628,7 @@ fn (mut g Gen) gen_interface_equality_fn(left_type ast.Type) string {
|
||||||
|
|
||||||
fn_builder.writeln('${g.static_non_parallel}inline bool ${fn_name}_interface_eq(${ptr_styp} a, ${ptr_styp} b) {')
|
fn_builder.writeln('${g.static_non_parallel}inline bool ${fn_name}_interface_eq(${ptr_styp} a, ${ptr_styp} b) {')
|
||||||
fn_builder.writeln('\tif (${left_arg} == ${right_arg}) {')
|
fn_builder.writeln('\tif (${left_arg} == ${right_arg}) {')
|
||||||
fn_builder.writeln('\t\tint idx = v_typeof_interface_idx_${idx_fn}(${left_arg});')
|
fn_builder.writeln('\t\tu32 idx = v_typeof_interface_idx_${idx_fn}(${left_arg});')
|
||||||
if info is ast.Interface {
|
if info is ast.Interface {
|
||||||
for typ in info.types {
|
for typ in info.types {
|
||||||
sym := g.table.sym(typ.set_nr_muls(0))
|
sym := g.table.sym(typ.set_nr_muls(0))
|
||||||
|
|
|
@ -188,7 +188,7 @@ fn (mut g Gen) gen_free_for_array(info ast.Array, styp string, fn_name string) {
|
||||||
|
|
||||||
sym := g.table.sym(g.unwrap_generic(info.elem_type))
|
sym := g.table.sym(g.unwrap_generic(info.elem_type))
|
||||||
if sym.kind in [.string, .array, .map, .struct] {
|
if sym.kind in [.string, .array, .map, .struct] {
|
||||||
fn_builder.writeln('\tfor (int i = 0; i < it->len; i++) {')
|
fn_builder.writeln('\tfor (${ast.int_type_name} i = 0; i < it->len; i++) {')
|
||||||
|
|
||||||
mut elem_styp := g.styp(info.elem_type).replace('*', '')
|
mut elem_styp := g.styp(info.elem_type).replace('*', '')
|
||||||
mut elem_styp_fn_name := if sym.has_method('free') {
|
mut elem_styp_fn_name := if sym.has_method('free') {
|
||||||
|
|
|
@ -16,23 +16,9 @@ fn (mut g Gen) gen_str_default(sym ast.TypeSymbol, styp string, str_fn_name stri
|
||||||
}
|
}
|
||||||
mut convertor := ''
|
mut convertor := ''
|
||||||
mut typename_ := ''
|
mut typename_ := ''
|
||||||
mut got_int_str := false
|
|
||||||
if sym.parent_idx in ast.integer_type_idxs {
|
if sym.parent_idx in ast.integer_type_idxs {
|
||||||
convertor = 'int'
|
convertor = 'int'
|
||||||
typename_ = 'int'
|
typename_ = 'int'
|
||||||
$if new_int ? {
|
|
||||||
if str_fn_name == 'i64_str' {
|
|
||||||
if got_int_str {
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
got_int_str = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if sym.parent_idx == ast.int_type_idx {
|
|
||||||
// return
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
} else if sym.parent_idx == ast.f32_type_idx {
|
} else if sym.parent_idx == ast.f32_type_idx {
|
||||||
convertor = 'float'
|
convertor = 'float'
|
||||||
typename_ = 'f32'
|
typename_ = 'f32'
|
||||||
|
@ -202,8 +188,8 @@ fn (mut g Gen) gen_str_for_option(typ ast.Type, styp string, str_fn_name string)
|
||||||
|
|
||||||
g.definitions.writeln('string ${str_fn_name}(${styp} it);')
|
g.definitions.writeln('string ${str_fn_name}(${styp} it);')
|
||||||
g.auto_str_funcs.writeln('string ${str_fn_name}(${styp} it) { return indent_${str_fn_name}(it, 0); }')
|
g.auto_str_funcs.writeln('string ${str_fn_name}(${styp} it) { return indent_${str_fn_name}(it, 0); }')
|
||||||
g.definitions.writeln('string indent_${str_fn_name}(${styp} it, int indent_count);')
|
g.definitions.writeln('string indent_${str_fn_name}(${styp} it, ${ast.int_type_name} indent_count);')
|
||||||
g.auto_str_funcs.writeln('string indent_${str_fn_name}(${styp} it, int indent_count) {')
|
g.auto_str_funcs.writeln('string indent_${str_fn_name}(${styp} it, ${ast.int_type_name} indent_count) {')
|
||||||
g.auto_str_funcs.writeln('\tstring res;')
|
g.auto_str_funcs.writeln('\tstring res;')
|
||||||
g.auto_str_funcs.writeln('\tif (it.state == 0) {')
|
g.auto_str_funcs.writeln('\tif (it.state == 0) {')
|
||||||
deref := if typ.is_ptr() && !typ.has_flag(.option_mut_param_t) {
|
deref := if typ.is_ptr() && !typ.has_flag(.option_mut_param_t) {
|
||||||
|
@ -255,8 +241,8 @@ fn (mut g Gen) gen_str_for_result(typ ast.Type, styp string, str_fn_name string)
|
||||||
|
|
||||||
g.definitions.writeln('string ${str_fn_name}(${styp} it);')
|
g.definitions.writeln('string ${str_fn_name}(${styp} it);')
|
||||||
g.auto_str_funcs.writeln('string ${str_fn_name}(${styp} it) { return indent_${str_fn_name}(it, 0); }')
|
g.auto_str_funcs.writeln('string ${str_fn_name}(${styp} it) { return indent_${str_fn_name}(it, 0); }')
|
||||||
g.definitions.writeln('string indent_${str_fn_name}(${styp} it, int indent_count);')
|
g.definitions.writeln('string indent_${str_fn_name}(${styp} it, ${ast.int_type_name} indent_count);')
|
||||||
g.auto_str_funcs.writeln('string indent_${str_fn_name}(${styp} it, int indent_count) {')
|
g.auto_str_funcs.writeln('string indent_${str_fn_name}(${styp} it, ${ast.int_type_name} indent_count) {')
|
||||||
g.auto_str_funcs.writeln('\tstring res;')
|
g.auto_str_funcs.writeln('\tstring res;')
|
||||||
g.auto_str_funcs.writeln('\tif (!it.is_error) {')
|
g.auto_str_funcs.writeln('\tif (!it.is_error) {')
|
||||||
if sym.kind == .string {
|
if sym.kind == .string {
|
||||||
|
@ -292,8 +278,8 @@ fn (mut g Gen) gen_str_for_alias(info ast.Alias, styp string, str_fn_name string
|
||||||
|
|
||||||
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${arg_def});')
|
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${arg_def});')
|
||||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${arg_def}) { return indent_${str_fn_name}(it, 0); }')
|
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${arg_def}) { return indent_${str_fn_name}(it, 0); }')
|
||||||
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${arg_def}, int indent_count);')
|
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${arg_def}, ${ast.int_type_name} indent_count);')
|
||||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${arg_def}, int indent_count) {')
|
g.auto_str_funcs.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${arg_def}, ${ast.int_type_name} indent_count) {')
|
||||||
old := g.reset_tmp_count()
|
old := g.reset_tmp_count()
|
||||||
defer { g.tmp_count = old }
|
defer { g.tmp_count = old }
|
||||||
g.auto_str_funcs.writeln('\tstring indents = builtin__string_repeat(_S(" "), indent_count);')
|
g.auto_str_funcs.writeln('\tstring indents = builtin__string_repeat(_S(" "), indent_count);')
|
||||||
|
@ -373,7 +359,7 @@ fn (mut g Gen) gen_str_for_enum(info ast.Enum, styp string, str_fn_name string)
|
||||||
if info.is_flag {
|
if info.is_flag {
|
||||||
clean_name := util.strip_main_name(styp.replace('__', '.'))
|
clean_name := util.strip_main_name(styp.replace('__', '.'))
|
||||||
g.auto_str_funcs.writeln('\tstring ret = _S("${clean_name}{");')
|
g.auto_str_funcs.writeln('\tstring ret = _S("${clean_name}{");')
|
||||||
g.auto_str_funcs.writeln('\tint first = 1;')
|
g.auto_str_funcs.writeln('\t${ast.int_type_name} first = 1;')
|
||||||
g.auto_str_funcs.writeln('\tu64 zit = (u64)it;')
|
g.auto_str_funcs.writeln('\tu64 zit = (u64)it;')
|
||||||
for i, val in info.vals {
|
for i, val in info.vals {
|
||||||
mask := u64(1) << i
|
mask := u64(1) << i
|
||||||
|
@ -413,10 +399,10 @@ fn (mut g Gen) gen_str_for_interface(info ast.Interface, styp string, typ_str st
|
||||||
// _str() functions should have a single argument, the indenting ones take 2:
|
// _str() functions should have a single argument, the indenting ones take 2:
|
||||||
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} x);')
|
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} x);')
|
||||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} x) { return indent_${str_fn_name}(x, 0); }')
|
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} x) { return indent_${str_fn_name}(x, 0); }')
|
||||||
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} x, int indent_count);')
|
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} x, ${ast.int_type_name} indent_count);')
|
||||||
mut fn_builder := strings.new_builder(512)
|
mut fn_builder := strings.new_builder(512)
|
||||||
clean_interface_v_type_name := util.strip_main_name(typ_str)
|
clean_interface_v_type_name := util.strip_main_name(typ_str)
|
||||||
fn_builder.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} x, int indent_count) { /* gen_str_for_interface */')
|
fn_builder.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} x, ${ast.int_type_name} indent_count) { /* gen_str_for_interface */')
|
||||||
for typ in info.types {
|
for typ in info.types {
|
||||||
sub_sym := g.table.sym(ast.mktyp(typ))
|
sub_sym := g.table.sym(ast.mktyp(typ))
|
||||||
if g.pref.skip_unused && sub_sym.idx !in g.table.used_features.used_syms {
|
if g.pref.skip_unused && sub_sym.idx !in g.table.used_features.used_syms {
|
||||||
|
@ -473,9 +459,9 @@ fn (mut g Gen) gen_str_for_union_sum_type(info ast.SumType, styp string, typ_str
|
||||||
// _str() functions should have a single argument, the indenting ones take 2:
|
// _str() functions should have a single argument, the indenting ones take 2:
|
||||||
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} x);')
|
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} x);')
|
||||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} x) { return indent_${str_fn_name}(x, 0); }')
|
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} x) { return indent_${str_fn_name}(x, 0); }')
|
||||||
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} x, int indent_count);')
|
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} x, ${ast.int_type_name} indent_count);')
|
||||||
mut fn_builder := strings.new_builder(512)
|
mut fn_builder := strings.new_builder(512)
|
||||||
fn_builder.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} x, int indent_count) {')
|
fn_builder.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} x, ${ast.int_type_name} indent_count) {')
|
||||||
mut clean_sum_type_v_type_name := ''
|
mut clean_sum_type_v_type_name := ''
|
||||||
if info.is_anon {
|
if info.is_anon {
|
||||||
variant_names := info.variants.map(util.strip_main_name(g.table.sym(it).name))
|
variant_names := info.variants.map(util.strip_main_name(g.table.sym(it).name))
|
||||||
|
@ -632,11 +618,11 @@ fn (mut g Gen) gen_str_for_array(info ast.Array, styp string, str_fn_name string
|
||||||
|
|
||||||
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} a);')
|
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} a);')
|
||||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} a) { return indent_${str_fn_name}(a, 0);}')
|
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} a) { return indent_${str_fn_name}(a, 0);}')
|
||||||
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} a, int indent_count);')
|
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} a, ${ast.int_type_name} indent_count);')
|
||||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} a, int indent_count) {')
|
g.auto_str_funcs.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} a, ${ast.int_type_name} indent_count) {')
|
||||||
g.auto_str_funcs.writeln('\tstrings__Builder sb = strings__new_builder(2 + a.len * 10);')
|
g.auto_str_funcs.writeln('\tstrings__Builder sb = strings__new_builder(2 + a.len * 10);')
|
||||||
g.auto_str_funcs.writeln('\tstrings__Builder_write_string(&sb, _S("["));')
|
g.auto_str_funcs.writeln('\tstrings__Builder_write_string(&sb, _S("["));')
|
||||||
g.auto_str_funcs.writeln('\tfor (int i = 0; i < a.len; ++i) {')
|
g.auto_str_funcs.writeln('\tfor (${ast.int_type_name} i = 0; i < a.len; ++i) {')
|
||||||
if sym.kind == .function {
|
if sym.kind == .function {
|
||||||
g.auto_str_funcs.writeln('\t\tstring x = ${elem_str_fn_name}();')
|
g.auto_str_funcs.writeln('\t\tstring x = ${elem_str_fn_name}();')
|
||||||
} else {
|
} else {
|
||||||
|
@ -739,11 +725,11 @@ fn (mut g Gen) gen_str_for_array_fixed(info ast.ArrayFixed, styp string, str_fn_
|
||||||
|
|
||||||
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${def_arg});')
|
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${def_arg});')
|
||||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${def_arg}) { return indent_${str_fn_name}(a, 0);}')
|
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${def_arg}) { return indent_${str_fn_name}(a, 0);}')
|
||||||
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${def_arg}, int indent_count);')
|
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${def_arg}, ${ast.int_type_name} indent_count);')
|
||||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${def_arg}, int indent_count) {')
|
g.auto_str_funcs.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${def_arg}, ${ast.int_type_name} indent_count) {')
|
||||||
g.auto_str_funcs.writeln('\tstrings__Builder sb = strings__new_builder(2 + ${info.size} * 10);')
|
g.auto_str_funcs.writeln('\tstrings__Builder sb = strings__new_builder(2 + ${info.size} * 10);')
|
||||||
g.auto_str_funcs.writeln('\tstrings__Builder_write_string(&sb, _S("["));')
|
g.auto_str_funcs.writeln('\tstrings__Builder_write_string(&sb, _S("["));')
|
||||||
g.auto_str_funcs.writeln('\tfor (int i = 0; i < ${info.size}; ++i) {')
|
g.auto_str_funcs.writeln('\tfor (${ast.int_type_name} i = 0; i < ${info.size}; ++i) {')
|
||||||
if sym.kind == .function {
|
if sym.kind == .function {
|
||||||
g.auto_str_funcs.writeln('\t\tstring x = ${elem_str_fn_name}();')
|
g.auto_str_funcs.writeln('\t\tstring x = ${elem_str_fn_name}();')
|
||||||
g.auto_str_funcs.writeln('\t\tstrings__Builder_write_string(&sb, x);')
|
g.auto_str_funcs.writeln('\t\tstrings__Builder_write_string(&sb, x);')
|
||||||
|
@ -826,12 +812,12 @@ fn (mut g Gen) gen_str_for_map(info ast.Map, styp string, str_fn_name string) {
|
||||||
|
|
||||||
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} m);')
|
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} m);')
|
||||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} m) { return indent_${str_fn_name}(m, 0);}')
|
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${styp} m) { return indent_${str_fn_name}(m, 0);}')
|
||||||
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} m, int indent_count);')
|
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} m, ${ast.int_type_name} indent_count);')
|
||||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} m, int indent_count) { /* gen_str_for_map */')
|
g.auto_str_funcs.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${styp} m, ${ast.int_type_name} indent_count) { /* gen_str_for_map */')
|
||||||
g.auto_str_funcs.writeln('\tstrings__Builder sb = strings__new_builder(2 + m.key_values.len * 10);')
|
g.auto_str_funcs.writeln('\tstrings__Builder sb = strings__new_builder(2 + m.key_values.len * 10);')
|
||||||
g.auto_str_funcs.writeln('\tstrings__Builder_write_string(&sb, _S("{"));')
|
g.auto_str_funcs.writeln('\tstrings__Builder_write_string(&sb, _S("{"));')
|
||||||
g.auto_str_funcs.writeln('\tbool is_first = true;')
|
g.auto_str_funcs.writeln('\tbool is_first = true;')
|
||||||
g.auto_str_funcs.writeln('\tfor (int i = 0; i < m.key_values.len; ++i) {')
|
g.auto_str_funcs.writeln('\tfor (${ast.int_type_name} i = 0; i < m.key_values.len; ++i) {')
|
||||||
g.auto_str_funcs.writeln('\t\tif (!builtin__DenseArray_has_index(&m.key_values, i)) { continue; }')
|
g.auto_str_funcs.writeln('\t\tif (!builtin__DenseArray_has_index(&m.key_values, i)) { continue; }')
|
||||||
g.auto_str_funcs.writeln('\t\telse if (!is_first) { strings__Builder_write_string(&sb, _S(", ")); }')
|
g.auto_str_funcs.writeln('\t\telse if (!is_first) { strings__Builder_write_string(&sb, _S(", ")); }')
|
||||||
|
|
||||||
|
@ -937,7 +923,11 @@ fn (g &Gen) type_to_fmt(typ ast.Type) StrIntpType {
|
||||||
}
|
}
|
||||||
return .si_g64
|
return .si_g64
|
||||||
} else if sym.kind == .int {
|
} else if sym.kind == .int {
|
||||||
|
$if new_int ? && (arm64 || amd64 || rv64 || s390x || ppc64le || loongarch64) {
|
||||||
|
return .si_i64
|
||||||
|
} $else {
|
||||||
return .si_i32
|
return .si_i32
|
||||||
|
}
|
||||||
} else if sym.kind == .u32 {
|
} else if sym.kind == .u32 {
|
||||||
return .si_u32
|
return .si_u32
|
||||||
} else if sym.kind == .u64 {
|
} else if sym.kind == .u64 {
|
||||||
|
@ -961,12 +951,12 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, lang ast.Language, styp strin
|
||||||
arg_def := if is_c_struct { '${styp}* it' } else { '${styp} it' }
|
arg_def := if is_c_struct { '${styp}* it' } else { '${styp} it' }
|
||||||
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${arg_def});')
|
g.definitions.writeln('${g.static_non_parallel}string ${str_fn_name}(${arg_def});')
|
||||||
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${arg_def}) { return indent_${str_fn_name}(it, 0);}')
|
g.auto_str_funcs.writeln('${g.static_non_parallel}string ${str_fn_name}(${arg_def}) { return indent_${str_fn_name}(it, 0);}')
|
||||||
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${arg_def}, int indent_count);')
|
g.definitions.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${arg_def}, ${ast.int_type_name} indent_count);')
|
||||||
mut fn_builder := strings.new_builder(512)
|
mut fn_builder := strings.new_builder(512)
|
||||||
defer {
|
defer {
|
||||||
g.auto_fn_definitions << fn_builder.str()
|
g.auto_fn_definitions << fn_builder.str()
|
||||||
}
|
}
|
||||||
fn_builder.writeln('string indent_${str_fn_name}(${arg_def}, int indent_count) {')
|
fn_builder.writeln('string indent_${str_fn_name}(${arg_def}, ${ast.int_type_name} indent_count) {')
|
||||||
old := g.reset_tmp_count()
|
old := g.reset_tmp_count()
|
||||||
defer { g.tmp_count = old }
|
defer { g.tmp_count = old }
|
||||||
clean_struct_v_type_name := if info.is_anon { 'struct ' } else { util.strip_main_name(typ_str) }
|
clean_struct_v_type_name := if info.is_anon { 'struct ' } else { util.strip_main_name(typ_str) }
|
||||||
|
@ -1321,7 +1311,7 @@ fn (mut g Gen) gen_enum_static_from_string(fn_name string, mod_enum_name string,
|
||||||
for field_val in enum_field_vals {
|
for field_val in enum_field_vals {
|
||||||
fn_builder.writeln('\tbuiltin__array_push((array*)&field_vals, _MOV((i64[]){ ${field_val} }));')
|
fn_builder.writeln('\tbuiltin__array_push((array*)&field_vals, _MOV((i64[]){ ${field_val} }));')
|
||||||
}
|
}
|
||||||
fn_builder.writeln('\tfor (int i = 0; i < ${enum_field_names.len}; ++i) {')
|
fn_builder.writeln('\tfor (${ast.int_type_name} i = 0; i < ${enum_field_names.len}; ++i) {')
|
||||||
fn_builder.writeln('\t\tif (builtin__fast_string_eq(name, (*(string*)builtin__array_get(field_names, i)))) {')
|
fn_builder.writeln('\t\tif (builtin__fast_string_eq(name, (*(string*)builtin__array_get(field_names, i)))) {')
|
||||||
fn_builder.writeln('\t\t\texists = true;')
|
fn_builder.writeln('\t\t\texists = true;')
|
||||||
fn_builder.writeln('\t\t\tinx = i;')
|
fn_builder.writeln('\t\t\tinx = i;')
|
||||||
|
|
|
@ -197,7 +197,7 @@ mut:
|
||||||
sumtype_casting_fns []SumtypeCastingFn
|
sumtype_casting_fns []SumtypeCastingFn
|
||||||
anon_fn_definitions []string // anon generated functions definition list
|
anon_fn_definitions []string // anon generated functions definition list
|
||||||
anon_fns shared []string // remove duplicate anon generated functions
|
anon_fns shared []string // remove duplicate anon generated functions
|
||||||
sumtype_definitions map[int]bool // `_TypeA_to_sumtype_TypeB()` fns that have been generated
|
sumtype_definitions map[u32]bool // `_TypeA_to_sumtype_TypeB()` fns that have been generated
|
||||||
trace_fn_definitions []string
|
trace_fn_definitions []string
|
||||||
json_types []ast.Type // to avoid json gen duplicates
|
json_types []ast.Type // to avoid json gen duplicates
|
||||||
pcs []ProfileCounterMeta // -prof profile counter fn_names => fn counter name
|
pcs []ProfileCounterMeta // -prof profile counter fn_names => fn counter name
|
||||||
|
@ -532,7 +532,7 @@ pub fn gen(files []&ast.File, mut table ast.Table, pref_ &pref.Preferences) GenO
|
||||||
// Temporary hack to make toml work with -usecache TODO remove
|
// Temporary hack to make toml work with -usecache TODO remove
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
g.definitions.writeln('int _v_type_idx_${sym.cname}(); // 1build module ${g.pref.path}')
|
g.definitions.writeln('u32 _v_type_idx_${sym.cname}(); // 1build module ${g.pref.path}')
|
||||||
}
|
}
|
||||||
} else if g.pref.use_cache {
|
} else if g.pref.use_cache {
|
||||||
is_toml := g.pref.path.contains('/toml')
|
is_toml := g.pref.path.contains('/toml')
|
||||||
|
@ -543,7 +543,7 @@ pub fn gen(files []&ast.File, mut table ast.Table, pref_ &pref.Preferences) GenO
|
||||||
if is_toml && sym.cname.contains('map[string]') {
|
if is_toml && sym.cname.contains('map[string]') {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
g.definitions.writeln('int _v_type_idx_${sym.cname}() { return ${idx}; }; //lol ${g.pref.path}')
|
g.definitions.writeln('u32 _v_type_idx_${sym.cname}() { return ${idx}; }; //lol ${g.pref.path}')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1138,8 +1138,8 @@ pub fn (mut g Gen) write_typeof_functions() {
|
||||||
if sum_info.is_generic {
|
if sum_info.is_generic {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
g.writeln('${static_prefix}char * v_typeof_sumtype_${sym.cname}(int sidx) {')
|
g.writeln('${static_prefix}char * v_typeof_sumtype_${sym.cname}(u32 sidx) {')
|
||||||
g.definitions.writeln('${static_prefix}char * v_typeof_sumtype_${sym.cname}(int);')
|
g.definitions.writeln('${static_prefix}char * v_typeof_sumtype_${sym.cname}(u32);')
|
||||||
if g.pref.build_mode == .build_module {
|
if g.pref.build_mode == .build_module {
|
||||||
g.writeln('\t\tif( sidx == _v_type_idx_${sym.cname}() ) return "${util.strip_main_name(sym.name)}";')
|
g.writeln('\t\tif( sidx == _v_type_idx_${sym.cname}() ) return "${util.strip_main_name(sym.name)}";')
|
||||||
for v in sum_info.variants {
|
for v in sum_info.variants {
|
||||||
|
@ -1152,39 +1152,39 @@ pub fn (mut g Gen) write_typeof_functions() {
|
||||||
tidx := g.table.find_type_idx(sym.name)
|
tidx := g.table.find_type_idx(sym.name)
|
||||||
g.writeln('\tswitch(sidx) {')
|
g.writeln('\tswitch(sidx) {')
|
||||||
g.writeln('\t\tcase ${tidx}: return "${util.strip_main_name(sym.name)}";')
|
g.writeln('\t\tcase ${tidx}: return "${util.strip_main_name(sym.name)}";')
|
||||||
mut idxs := []int{}
|
mut idxs := []ast.Type{}
|
||||||
for v in sum_info.variants {
|
for v in sum_info.variants {
|
||||||
if v in idxs {
|
if v in idxs {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
subtype := g.table.sym(v)
|
subtype := g.table.sym(v)
|
||||||
g.writeln('\t\tcase ${int(v)}: return "${util.strip_main_name(subtype.name)}";')
|
g.writeln('\t\tcase ${u32(v)}: return "${util.strip_main_name(subtype.name)}";')
|
||||||
idxs << v
|
idxs << v
|
||||||
}
|
}
|
||||||
g.writeln('\t\tdefault: return "unknown ${util.strip_main_name(sym.name)}";')
|
g.writeln('\t\tdefault: return "unknown ${util.strip_main_name(sym.name)}";')
|
||||||
g.writeln('\t}')
|
g.writeln('\t}')
|
||||||
}
|
}
|
||||||
g.writeln2('}', '')
|
g.writeln2('}', '')
|
||||||
g.writeln('${static_prefix}int v_typeof_sumtype_idx_${sym.cname}(int sidx) {')
|
g.writeln('${static_prefix}u32 v_typeof_sumtype_idx_${sym.cname}(u32 sidx) {')
|
||||||
if g.pref.build_mode == .build_module {
|
if g.pref.build_mode == .build_module {
|
||||||
g.writeln('\t\tif( sidx == _v_type_idx_${sym.cname}() ) return ${int(ityp)};')
|
g.writeln('\t\tif( sidx == _v_type_idx_${sym.cname}() ) return ${u32(ityp)};')
|
||||||
for v in sum_info.variants {
|
for v in sum_info.variants {
|
||||||
subtype := g.table.sym(v)
|
subtype := g.table.sym(v)
|
||||||
g.writeln('\tif( sidx == _v_type_idx_${subtype.cname}() ) return ${int(v)};')
|
g.writeln('\tif( sidx == _v_type_idx_${subtype.cname}() ) return ${u32(v)};')
|
||||||
}
|
}
|
||||||
g.writeln('\treturn ${int(ityp)};')
|
g.writeln('\treturn ${u32(ityp)};')
|
||||||
} else {
|
} else {
|
||||||
tidx := g.table.find_type_idx(sym.name)
|
tidx := g.table.find_type_idx(sym.name)
|
||||||
g.writeln2('\tswitch(sidx) {', '\t\tcase ${tidx}: return ${int(ityp)};')
|
g.writeln2('\tswitch(sidx) {', '\t\tcase ${tidx}: return ${u32(ityp)};')
|
||||||
mut idxs := []int{}
|
mut idxs := []ast.Type{}
|
||||||
for v in sum_info.variants {
|
for v in sum_info.variants {
|
||||||
if v in idxs {
|
if v in idxs {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
g.writeln('\t\tcase ${int(v)}: return ${int(v)};')
|
g.writeln('\t\tcase ${u32(v)}: return ${u32(v)};')
|
||||||
idxs << v
|
idxs << v
|
||||||
}
|
}
|
||||||
g.writeln2('\t\tdefault: return ${int(ityp)};', '\t}')
|
g.writeln2('\t\tdefault: return ${u32(ityp)};', '\t}')
|
||||||
}
|
}
|
||||||
g.writeln('}')
|
g.writeln('}')
|
||||||
} else if sym.kind == .interface {
|
} else if sym.kind == .interface {
|
||||||
|
@ -1202,11 +1202,11 @@ pub fn (mut g Gen) write_typeof_functions() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
already_generated_ifaces[sym.cname] = true
|
already_generated_ifaces[sym.cname] = true
|
||||||
g.definitions.writeln('${g.static_non_parallel}char * v_typeof_interface_${sym.cname}(int sidx);')
|
g.definitions.writeln('${g.static_non_parallel}char * v_typeof_interface_${sym.cname}(u32 sidx);')
|
||||||
if g.pref.parallel_cc {
|
if g.pref.parallel_cc {
|
||||||
g.extern_out.writeln('extern char * v_typeof_interface_${sym.cname}(int sidx);')
|
g.extern_out.writeln('extern char * v_typeof_interface_${sym.cname}(u32 sidx);')
|
||||||
}
|
}
|
||||||
g.writeln('${g.static_non_parallel}char * v_typeof_interface_${sym.cname}(int sidx) {')
|
g.writeln('${g.static_non_parallel}char * v_typeof_interface_${sym.cname}(u32 sidx) {')
|
||||||
for t in inter_info.types {
|
for t in inter_info.types {
|
||||||
sub_sym := g.table.sym(ast.mktyp(t))
|
sub_sym := g.table.sym(ast.mktyp(t))
|
||||||
if sub_sym.info is ast.Struct && sub_sym.info.is_unresolved_generic() {
|
if sub_sym.info is ast.Struct && sub_sym.info.is_unresolved_generic() {
|
||||||
|
@ -1219,10 +1219,10 @@ pub fn (mut g Gen) write_typeof_functions() {
|
||||||
g.writeln('\tif (sidx == _${sym.cname}_${sub_sym.cname}_index) return "${util.strip_main_name(sub_sym.name)}";')
|
g.writeln('\tif (sidx == _${sym.cname}_${sub_sym.cname}_index) return "${util.strip_main_name(sub_sym.name)}";')
|
||||||
}
|
}
|
||||||
g.writeln2('\treturn "unknown ${util.strip_main_name(sym.name)}";', '}')
|
g.writeln2('\treturn "unknown ${util.strip_main_name(sym.name)}";', '}')
|
||||||
g.definitions.writeln('int v_typeof_interface_idx_${sym.cname}(int sidx);')
|
g.definitions.writeln('u32 v_typeof_interface_idx_${sym.cname}(u32 sidx);')
|
||||||
g.writeln2('', 'int v_typeof_interface_idx_${sym.cname}(int sidx) {')
|
g.writeln2('', 'u32 v_typeof_interface_idx_${sym.cname}(u32 sidx) {')
|
||||||
if g.pref.parallel_cc {
|
if g.pref.parallel_cc {
|
||||||
g.extern_out.writeln('extern int v_typeof_interface_idx_${sym.cname}(int sidx);')
|
g.extern_out.writeln('extern u32 v_typeof_interface_idx_${sym.cname}(u32 sidx);')
|
||||||
}
|
}
|
||||||
for t in inter_info.types {
|
for t in inter_info.types {
|
||||||
sub_sym := g.table.sym(ast.mktyp(t))
|
sub_sym := g.table.sym(ast.mktyp(t))
|
||||||
|
@ -1233,9 +1233,9 @@ pub fn (mut g Gen) write_typeof_functions() {
|
||||||
&& sub_sym.idx !in g.table.used_features.used_syms {
|
&& sub_sym.idx !in g.table.used_features.used_syms {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
g.writeln('\tif (sidx == _${sym.cname}_${sub_sym.cname}_index) return ${int(t.set_nr_muls(0))};')
|
g.writeln('\tif (sidx == _${sym.cname}_${sub_sym.cname}_index) return ${u32(t.set_nr_muls(0))};')
|
||||||
}
|
}
|
||||||
g.writeln2('\treturn ${int(ityp)};', '}')
|
g.writeln2('\treturn ${u32(ityp)};', '}')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g.writeln2('// << typeof() support for sum types', '')
|
g.writeln2('// << typeof() support for sum types', '')
|
||||||
|
@ -1267,14 +1267,6 @@ fn (mut g Gen) base_type(_t ast.Type) string {
|
||||||
return 'u64'
|
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()
|
share := t.share()
|
||||||
mut styp := if share == .atomic_t { t.atomic_typename() } else { g.cc_type(t, true) }
|
mut styp := if share == .atomic_t { t.atomic_typename() } else { g.cc_type(t, true) }
|
||||||
if t.has_flag(.shared_f) {
|
if t.has_flag(.shared_f) {
|
||||||
|
@ -1504,7 +1496,7 @@ fn (mut g Gen) write_shareds() {
|
||||||
g.shared_types.writeln('\t${mtx_typ} mtx;')
|
g.shared_types.writeln('\t${mtx_typ} mtx;')
|
||||||
g.shared_types.writeln('\t${base} val;')
|
g.shared_types.writeln('\t${base} val;')
|
||||||
g.shared_types.writeln('};')
|
g.shared_types.writeln('};')
|
||||||
g.shared_functions.writeln('static inline voidptr __dup${sh_typ}(voidptr src, int sz) {')
|
g.shared_functions.writeln('static inline voidptr __dup${sh_typ}(voidptr src, ${ast.int_type_name} sz) {')
|
||||||
g.shared_functions.writeln('\t${sh_typ}* dest = builtin__memdup(src, sz);')
|
g.shared_functions.writeln('\t${sh_typ}* dest = builtin__memdup(src, sz);')
|
||||||
g.shared_functions.writeln('\tsync__RwMutex_init(&dest->mtx);')
|
g.shared_functions.writeln('\tsync__RwMutex_init(&dest->mtx);')
|
||||||
g.shared_functions.writeln('\treturn dest;')
|
g.shared_functions.writeln('\treturn dest;')
|
||||||
|
@ -1553,7 +1545,7 @@ fn (mut g Gen) register_thread_array_wait_call(eltyp string) string {
|
||||||
g.waiter_fn_definitions.writeln('void ${fn_name}(${thread_arr_typ} a);')
|
g.waiter_fn_definitions.writeln('void ${fn_name}(${thread_arr_typ} a);')
|
||||||
g.gowrappers.writeln('
|
g.gowrappers.writeln('
|
||||||
void ${fn_name}(${thread_arr_typ} a) {
|
void ${fn_name}(${thread_arr_typ} a) {
|
||||||
for (int i = 0; i < a.len; ++i) {
|
for (${ast.int_type_name} i = 0; i < a.len; ++i) {
|
||||||
${thread_typ} t = ((${thread_typ}*)a.data)[i];
|
${thread_typ} t = ((${thread_typ}*)a.data)[i];
|
||||||
if (t == 0) continue;
|
if (t == 0) continue;
|
||||||
__v_thread_wait(t);
|
__v_thread_wait(t);
|
||||||
|
@ -1564,7 +1556,7 @@ void ${fn_name}(${thread_arr_typ} a) {
|
||||||
g.gowrappers.writeln('
|
g.gowrappers.writeln('
|
||||||
${ret_typ} ${fn_name}(${thread_arr_typ} a) {
|
${ret_typ} ${fn_name}(${thread_arr_typ} a) {
|
||||||
${ret_typ} res = builtin____new_array_with_default(a.len, a.len, sizeof(${eltyp}), 0);
|
${ret_typ} res = builtin____new_array_with_default(a.len, a.len, sizeof(${eltyp}), 0);
|
||||||
for (int i = 0; i < a.len; ++i) {
|
for (${ast.int_type_name} i = 0; i < a.len; ++i) {
|
||||||
${thread_typ} t = ((${thread_typ}*)a.data)[i];')
|
${thread_typ} t = ((${thread_typ}*)a.data)[i];')
|
||||||
if g.pref.os == .windows {
|
if g.pref.os == .windows {
|
||||||
g.gowrappers.writeln('\t\tif (t.handle == 0) continue;')
|
g.gowrappers.writeln('\t\tif (t.handle == 0) continue;')
|
||||||
|
@ -1601,7 +1593,7 @@ fn (mut g Gen) register_thread_fixed_array_wait_call(node ast.CallExpr, eltyp st
|
||||||
g.waiter_fn_definitions.writeln('void ${fn_name}(${thread_arr_typ} a);')
|
g.waiter_fn_definitions.writeln('void ${fn_name}(${thread_arr_typ} a);')
|
||||||
g.gowrappers.writeln('
|
g.gowrappers.writeln('
|
||||||
void ${fn_name}(${thread_arr_typ} a) {
|
void ${fn_name}(${thread_arr_typ} a) {
|
||||||
for (int i = 0; i < ${len}; ++i) {
|
for (${ast.int_type_name} i = 0; i < ${len}; ++i) {
|
||||||
${thread_typ} t = ((${thread_typ}*)a)[i];
|
${thread_typ} t = ((${thread_typ}*)a)[i];
|
||||||
if (t == 0) continue;
|
if (t == 0) continue;
|
||||||
__v_thread_wait(t);
|
__v_thread_wait(t);
|
||||||
|
@ -1612,7 +1604,7 @@ void ${fn_name}(${thread_arr_typ} a) {
|
||||||
g.gowrappers.writeln('
|
g.gowrappers.writeln('
|
||||||
${ret_typ} ${fn_name}(${thread_arr_typ} a) {
|
${ret_typ} ${fn_name}(${thread_arr_typ} a) {
|
||||||
${ret_typ} res = builtin____new_array_with_default(${len}, ${len}, sizeof(${eltyp}), 0);
|
${ret_typ} res = builtin____new_array_with_default(${len}, ${len}, sizeof(${eltyp}), 0);
|
||||||
for (int i = 0; i < ${len}; ++i) {
|
for (${ast.int_type_name} i = 0; i < ${len}; ++i) {
|
||||||
${thread_typ} t = ((${thread_typ}*)a)[i];')
|
${thread_typ} t = ((${thread_typ}*)a)[i];')
|
||||||
if g.pref.os == .windows {
|
if g.pref.os == .windows {
|
||||||
g.gowrappers.writeln('\t\tif (t.handle == 0) continue;')
|
g.gowrappers.writeln('\t\tif (t.handle == 0) continue;')
|
||||||
|
@ -1722,7 +1714,7 @@ fn (g &Gen) type_sidx(t ast.Type) string {
|
||||||
sym := g.table.sym(t)
|
sym := g.table.sym(t)
|
||||||
return '_v_type_idx_${sym.cname}()'
|
return '_v_type_idx_${sym.cname}()'
|
||||||
}
|
}
|
||||||
return int(t).str()
|
return u32(t).str()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut g Gen) write_typedef_types() {
|
pub fn (mut g Gen) write_typedef_types() {
|
||||||
|
@ -1926,7 +1918,7 @@ pub fn (mut g Gen) write_interface_typesymbol_declaration(sym ast.TypeSymbol) {
|
||||||
g.type_definitions.writeln('\t\t${vcname}* _${vcname};')
|
g.type_definitions.writeln('\t\t${vcname}* _${vcname};')
|
||||||
}
|
}
|
||||||
g.type_definitions.writeln('\t};')
|
g.type_definitions.writeln('\t};')
|
||||||
g.type_definitions.writeln('\tint _typ;')
|
g.type_definitions.writeln('\tu32 _typ;')
|
||||||
for field in info.fields {
|
for field in info.fields {
|
||||||
styp := g.styp(field.typ)
|
styp := g.styp(field.typ)
|
||||||
cname := c_name(field.name)
|
cname := c_name(field.name)
|
||||||
|
@ -2152,7 +2144,7 @@ fn (mut g Gen) stmts_with_tmp_var(stmts []ast.Stmt, tmp_var string) bool {
|
||||||
mut styp := g.base_type(stmt.typ)
|
mut styp := g.base_type(stmt.typ)
|
||||||
$if tinyc && x32 && windows {
|
$if tinyc && x32 && windows {
|
||||||
if stmt.typ == ast.int_literal_type {
|
if stmt.typ == ast.int_literal_type {
|
||||||
styp = 'int'
|
styp = ast.int_type_name
|
||||||
} else if stmt.typ == ast.float_literal_type {
|
} else if stmt.typ == ast.float_literal_type {
|
||||||
styp = 'f64'
|
styp = 'f64'
|
||||||
}
|
}
|
||||||
|
@ -2210,7 +2202,7 @@ fn (mut g Gen) stmts_with_tmp_var(stmts []ast.Stmt, tmp_var string) bool {
|
||||||
mut styp := g.base_type(stmt.typ)
|
mut styp := g.base_type(stmt.typ)
|
||||||
$if tinyc && x32 && windows {
|
$if tinyc && x32 && windows {
|
||||||
if stmt.typ == ast.int_literal_type {
|
if stmt.typ == ast.int_literal_type {
|
||||||
styp = 'int'
|
styp = ast.int_type_name
|
||||||
} else if stmt.typ == ast.float_literal_type {
|
} else if stmt.typ == ast.float_literal_type {
|
||||||
styp = 'f64'
|
styp = 'f64'
|
||||||
}
|
}
|
||||||
|
@ -2767,7 +2759,7 @@ struct SumtypeCastingFn {
|
||||||
|
|
||||||
fn (mut g Gen) get_sumtype_casting_fn(got_ ast.Type, exp_ ast.Type) string {
|
fn (mut g Gen) get_sumtype_casting_fn(got_ ast.Type, exp_ ast.Type) string {
|
||||||
mut got, exp := got_.idx_type(), exp_.idx_type()
|
mut got, exp := got_.idx_type(), exp_.idx_type()
|
||||||
i := int(got) | int(u32(exp) << 18) | int(u32(exp_.has_flag(.option)) << 17) | int(u32(got_.has_flag(.option)) << 16)
|
i := u32(got) | u32(u32(exp) << 18) | u32(u32(exp_.has_flag(.option)) << 17) | u32(u32(got_.has_flag(.option)) << 16)
|
||||||
exp_sym := g.table.sym(exp)
|
exp_sym := g.table.sym(exp)
|
||||||
mut got_sym := g.table.sym(got)
|
mut got_sym := g.table.sym(got)
|
||||||
cname := if exp == ast.int_type_idx {
|
cname := if exp == ast.int_type_idx {
|
||||||
|
@ -2826,7 +2818,7 @@ fn (mut g Gen) write_sumtype_casting_fn(fun SumtypeCastingFn) {
|
||||||
if g.table.fn_type_source_signature(variant_sym.info.func) == g.table.fn_type_source_signature(got_sym.info.func) {
|
if g.table.fn_type_source_signature(variant_sym.info.func) == g.table.fn_type_source_signature(got_sym.info.func) {
|
||||||
variant_name = g.get_sumtype_variant_name(variant, variant_sym)
|
variant_name = g.get_sumtype_variant_name(variant, variant_sym)
|
||||||
got_cname = g.get_sumtype_variant_type_name(variant, variant_sym)
|
got_cname = g.get_sumtype_variant_type_name(variant, variant_sym)
|
||||||
type_idx = int(variant).str()
|
type_idx = u32(variant).str()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3571,11 +3563,31 @@ fn (mut g Gen) map_fn_ptrs(key_sym ast.TypeSymbol) (string, string, string, stri
|
||||||
if g.pref.ccompiler_type == .tinyc
|
if g.pref.ccompiler_type == .tinyc
|
||||||
&& einfo.typ in [ast.u8_type, ast.u16_type, ast.i8_type, ast.i16_type] {
|
&& einfo.typ in [ast.u8_type, ast.u16_type, ast.i8_type, ast.i16_type] {
|
||||||
// workaround for tcc, since we can not generate a packed Enum with size < 4 bytes
|
// workaround for tcc, since we can not generate a packed Enum with size < 4 bytes
|
||||||
return g.map_fn_ptrs(g.table.sym(ast.int_type))
|
return g.map_fn_ptrs(g.table.sym(ast.i32_type))
|
||||||
}
|
}
|
||||||
|
$if new_int ? && (arm64 || amd64 || rv64 || s390x || ppc64le || loongarch64) {
|
||||||
|
// enum type alway use 32bit `int`
|
||||||
|
if einfo.typ == ast.int_type {
|
||||||
|
return g.map_fn_ptrs(g.table.sym(ast.i32_type))
|
||||||
|
} else {
|
||||||
return g.map_fn_ptrs(g.table.sym(einfo.typ))
|
return g.map_fn_ptrs(g.table.sym(einfo.typ))
|
||||||
}
|
}
|
||||||
.int, .i32, .u32, .rune, .f32 {
|
} $else {
|
||||||
|
return g.map_fn_ptrs(g.table.sym(einfo.typ))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.int {
|
||||||
|
$if new_int ? && (arm64 || amd64 || rv64 || s390x || ppc64le || loongarch64) {
|
||||||
|
hash_fn = '&builtin__map_hash_int_8'
|
||||||
|
key_eq_fn = '&builtin__map_eq_int_8'
|
||||||
|
clone_fn = '&builtin__map_clone_int_8'
|
||||||
|
} $else {
|
||||||
|
hash_fn = '&builtin__map_hash_int_4'
|
||||||
|
key_eq_fn = '&builtin__map_eq_int_4'
|
||||||
|
clone_fn = '&builtin__map_clone_int_4'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.i32, .u32, .rune, .f32 {
|
||||||
hash_fn = '&builtin__map_hash_int_4'
|
hash_fn = '&builtin__map_hash_int_4'
|
||||||
key_eq_fn = '&builtin__map_eq_int_4'
|
key_eq_fn = '&builtin__map_eq_int_4'
|
||||||
clone_fn = '&builtin__map_clone_int_4'
|
clone_fn = '&builtin__map_clone_int_4'
|
||||||
|
@ -4149,11 +4161,11 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
.typ {
|
.typ {
|
||||||
g.write(int(g.unwrap_generic(node.name_type)).str())
|
g.write(u32(g.unwrap_generic(node.name_type)).str())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
.unaliased_typ {
|
.unaliased_typ {
|
||||||
g.write(int(g.table.unaliased_type(g.unwrap_generic(node.name_type))).str())
|
g.write(u32(g.table.unaliased_type(g.unwrap_generic(node.name_type))).str())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
.indirections {
|
.indirections {
|
||||||
|
@ -4592,7 +4604,7 @@ fn (mut g Gen) gen_closure_fn(expr_styp string, m ast.Fn, name string) {
|
||||||
if resolved_sym.is_builtin() {
|
if resolved_sym.is_builtin() {
|
||||||
full_method_name = 'builtin__${full_method_name}'
|
full_method_name = 'builtin__${full_method_name}'
|
||||||
}
|
}
|
||||||
} else if expr_styp in ['int_literal', 'float_literal'] {
|
} else if expr_styp in ['int_literal', 'float_literal', 'vint_t'] {
|
||||||
full_method_name = 'builtin__${full_method_name}'
|
full_method_name = 'builtin__${full_method_name}'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4963,7 +4975,8 @@ fn (mut g Gen) lock_expr(node ast.LockExpr) {
|
||||||
} else {
|
} else {
|
||||||
g.writeln('__sort_ptr(_arr_${mtxs}, _isrlck_${mtxs}, ${node.lockeds.len});')
|
g.writeln('__sort_ptr(_arr_${mtxs}, _isrlck_${mtxs}, ${node.lockeds.len});')
|
||||||
}
|
}
|
||||||
g.writeln2('for (int ${mtxs}=0; ${mtxs}<${node.lockeds.len}; ${mtxs}++) {', '\tif (${mtxs} && _arr_${mtxs}[${mtxs}] == _arr_${mtxs}[${mtxs}-1]) continue;')
|
g.writeln2('for (${ast.int_type_name} ${mtxs}=0; ${mtxs}<${node.lockeds.len}; ${mtxs}++) {',
|
||||||
|
'\tif (${mtxs} && _arr_${mtxs}[${mtxs}] == _arr_${mtxs}[${mtxs}-1]) continue;')
|
||||||
g.writeln2('\tif (_isrlck_${mtxs}[${mtxs}])', '\t\tsync__RwMutex_rlock((sync__RwMutex*)_arr_${mtxs}[${mtxs}]);')
|
g.writeln2('\tif (_isrlck_${mtxs}[${mtxs}])', '\t\tsync__RwMutex_rlock((sync__RwMutex*)_arr_${mtxs}[${mtxs}]);')
|
||||||
g.writeln2('\telse', '\t\tsync__RwMutex_lock((sync__RwMutex*)_arr_${mtxs}[${mtxs}]);')
|
g.writeln2('\telse', '\t\tsync__RwMutex_lock((sync__RwMutex*)_arr_${mtxs}[${mtxs}]);')
|
||||||
g.writeln('}')
|
g.writeln('}')
|
||||||
|
@ -4993,7 +5006,7 @@ fn (mut g Gen) unlock_locks() {
|
||||||
g.expr(g.cur_lock.lockeds[0])
|
g.expr(g.cur_lock.lockeds[0])
|
||||||
g.write('->mtx);')
|
g.write('->mtx);')
|
||||||
} else {
|
} else {
|
||||||
g.writeln('for (int ${g.mtxs}=${g.cur_lock.lockeds.len - 1}; ${g.mtxs}>=0; ${g.mtxs}--) {')
|
g.writeln('for (${ast.int_type_name} ${g.mtxs}=${g.cur_lock.lockeds.len - 1}; ${g.mtxs}>=0; ${g.mtxs}--) {')
|
||||||
g.writeln('\tif (${g.mtxs} && _arr_${g.mtxs}[${g.mtxs}] == _arr_${g.mtxs}[${g.mtxs}-1]) continue;')
|
g.writeln('\tif (${g.mtxs} && _arr_${g.mtxs}[${g.mtxs}] == _arr_${g.mtxs}[${g.mtxs}-1]) continue;')
|
||||||
g.writeln('\tif (_isrlck_${g.mtxs}[${g.mtxs}])')
|
g.writeln('\tif (_isrlck_${g.mtxs}[${g.mtxs}])')
|
||||||
g.writeln('\t\tsync__RwMutex_runlock((sync__RwMutex*)_arr_${g.mtxs}[${g.mtxs}]);')
|
g.writeln('\t\tsync__RwMutex_runlock((sync__RwMutex*)_arr_${g.mtxs}[${g.mtxs}]);')
|
||||||
|
@ -5673,7 +5686,7 @@ fn (mut g Gen) cast_expr(node ast.CastExpr) {
|
||||||
expr_styp := g.styp(expr_typ)
|
expr_styp := g.styp(expr_typ)
|
||||||
g.write('{._${g.table.sym(expr_typ).cname}=builtin__memdup(ADDR(${expr_styp}, ')
|
g.write('{._${g.table.sym(expr_typ).cname}=builtin__memdup(ADDR(${expr_styp}, ')
|
||||||
g.expr(node.expr)
|
g.expr(node.expr)
|
||||||
g.write('), sizeof(${expr_styp})),._typ=${int(expr_typ)}})')
|
g.write('), sizeof(${expr_styp})),._typ=${u32(expr_typ)}})')
|
||||||
} else {
|
} else {
|
||||||
g.write('(')
|
g.write('(')
|
||||||
if node.expr is ast.Ident {
|
if node.expr is ast.Ident {
|
||||||
|
@ -6925,7 +6938,7 @@ fn (mut g Gen) write_types(symbols []&ast.TypeSymbol) {
|
||||||
}
|
}
|
||||||
struct_names[name] = true
|
struct_names[name] = true
|
||||||
g.typedefs.writeln('typedef struct ${name} ${name};')
|
g.typedefs.writeln('typedef struct ${name} ${name};')
|
||||||
mut idxs := []int{}
|
mut idxs := []ast.Type{}
|
||||||
if !g.pref.is_prod {
|
if !g.pref.is_prod {
|
||||||
// Do not print union sum type coment in prod mode
|
// Do not print union sum type coment in prod mode
|
||||||
g.type_definitions.writeln('')
|
g.type_definitions.writeln('')
|
||||||
|
@ -6962,7 +6975,7 @@ fn (mut g Gen) write_types(symbols []&ast.TypeSymbol) {
|
||||||
g.type_definitions.writeln('\t\t${var_type} _${variant_name};')
|
g.type_definitions.writeln('\t\t${var_type} _${variant_name};')
|
||||||
}
|
}
|
||||||
g.type_definitions.writeln('\t};')
|
g.type_definitions.writeln('\t};')
|
||||||
g.type_definitions.writeln('\tint _typ;')
|
g.type_definitions.writeln('\tu32 _typ;')
|
||||||
if sym.info.fields.len > 0 {
|
if sym.info.fields.len > 0 {
|
||||||
g.writeln('\t// pointers to common sumtype fields')
|
g.writeln('\t// pointers to common sumtype fields')
|
||||||
for field in sym.info.fields {
|
for field in sym.info.fields {
|
||||||
|
@ -7465,9 +7478,9 @@ fn (mut g Gen) type_default_sumtype(typ_ ast.Type, sym ast.TypeSymbol) string {
|
||||||
g.type_default_no_sumtype(first_typ)
|
g.type_default_no_sumtype(first_typ)
|
||||||
}
|
}
|
||||||
if default_str[0] == `{` {
|
if default_str[0] == `{` {
|
||||||
return '(${g.styp(typ_)}){._${first_field}=HEAP(${first_styp}, ((${first_styp})${default_str})),._typ=${int(first_typ)}}'
|
return '(${g.styp(typ_)}){._${first_field}=HEAP(${first_styp}, ((${first_styp})${default_str})),._typ=${u32(first_typ)}}'
|
||||||
} else {
|
} else {
|
||||||
return '(${g.styp(typ_)}){._${first_field}=HEAP(${first_styp}, (${default_str})),._typ=${int(first_typ)}}'
|
return '(${g.styp(typ_)}){._${first_field}=HEAP(${first_styp}, (${default_str})),._typ=${u32(first_typ)}}'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8304,9 +8317,9 @@ return ${cast_shared_struct_str};
|
||||||
}
|
}
|
||||||
iin_idx := already_generated_mwrappers[interface_index_name] - iinidx_minimum_base
|
iin_idx := already_generated_mwrappers[interface_index_name] - iinidx_minimum_base
|
||||||
if g.pref.build_mode != .build_module {
|
if g.pref.build_mode != .build_module {
|
||||||
sb.writeln('${g.static_modifier}const int ${interface_index_name} = ${iin_idx};')
|
sb.writeln('${g.static_modifier}const u32 ${interface_index_name} = ${iin_idx};')
|
||||||
} else {
|
} else {
|
||||||
sb.writeln('extern const int ${interface_index_name};')
|
sb.writeln('extern const u32 ${interface_index_name};')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for vtyp, variants in inter_info.conversions {
|
for vtyp, variants in inter_info.conversions {
|
||||||
|
@ -8486,7 +8499,7 @@ pub fn (mut g Gen) contains_ptr(el_typ ast.Type) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
match sym.kind {
|
match sym.kind {
|
||||||
.i8, .i16, .int, .i64, .u8, .u16, .u32, .u64, .f32, .f64, .char, .rune, .bool, .enum {
|
.i8, .i16, .i32, .int, .i64, .u8, .u16, .u32, .u64, .f32, .f64, .char, .rune, .bool, .enum {
|
||||||
g.contains_ptr_cache[typ] = false
|
g.contains_ptr_cache[typ] = false
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -8542,6 +8555,16 @@ fn (mut g Gen) check_noscan(elem_typ ast.Type) string {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// vint2int rename `_vint_t` to `int`
|
||||||
|
fn vint2int(name string) string {
|
||||||
|
$if new_int ? && (arm64 || amd64 || rv64 || s390x || ppc64le || loongarch64) {
|
||||||
|
if name == ast.int_type_name {
|
||||||
|
return 'int'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
const hi_32_mask = u64(0xFFFFFFFF00000000)
|
const hi_32_mask = u64(0xFFFFFFFF00000000)
|
||||||
const lo_32_mask = u64(0x00000000FFFFFFFF)
|
const lo_32_mask = u64(0x00000000FFFFFFFF)
|
||||||
const sign_bit_32 = u32(0x80000000)
|
const sign_bit_32 = u32(0x80000000)
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
module c
|
module c
|
||||||
|
|
||||||
|
import v.ast
|
||||||
|
|
||||||
// Note: @@@ here serve as placeholders.
|
// Note: @@@ here serve as placeholders.
|
||||||
// They will be replaced with correct strings
|
// They will be replaced with correct strings
|
||||||
// for each constant, during C code generation.
|
// for each constant, during C code generation.
|
||||||
|
@ -17,7 +19,7 @@ struct __shared_map {
|
||||||
sync__RwMutex mtx;
|
sync__RwMutex mtx;
|
||||||
map val;
|
map val;
|
||||||
};
|
};
|
||||||
static inline voidptr __dup_shared_map(voidptr src, int sz) {
|
static inline voidptr __dup_shared_map(voidptr src, ${ast.int_type_name} sz) {
|
||||||
__shared_map* dest = builtin__memdup(src, sz);
|
__shared_map* dest = builtin__memdup(src, sz);
|
||||||
sync__RwMutex_init(&dest->mtx);
|
sync__RwMutex_init(&dest->mtx);
|
||||||
return dest;
|
return dest;
|
||||||
|
@ -27,16 +29,16 @@ struct __shared_array {
|
||||||
sync__RwMutex mtx;
|
sync__RwMutex mtx;
|
||||||
array val;
|
array val;
|
||||||
};
|
};
|
||||||
static inline voidptr __dup_shared_array(voidptr src, int sz) {
|
static inline voidptr __dup_shared_array(voidptr src, ${ast.int_type_name} sz) {
|
||||||
__shared_array* dest = builtin__memdup(src, sz);
|
__shared_array* dest = builtin__memdup(src, sz);
|
||||||
sync__RwMutex_init(&dest->mtx);
|
sync__RwMutex_init(&dest->mtx);
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
static inline void __sort_ptr(uintptr_t a[], bool b[], int l) {
|
static inline void __sort_ptr(uintptr_t a[], bool b[], ${ast.int_type_name} l) {
|
||||||
for (int i=1; i<l; i++) {
|
for (${ast.int_type_name} i=1; i<l; i++) {
|
||||||
uintptr_t ins = a[i];
|
uintptr_t ins = a[i];
|
||||||
bool insb = b[i];
|
bool insb = b[i];
|
||||||
int j = i;
|
${ast.int_type_name} j = i;
|
||||||
while(j>0 && a[j-1] > ins) {
|
while(j>0 && a[j-1] > ins) {
|
||||||
a[j] = a[j-1];
|
a[j] = a[j-1];
|
||||||
b[j] = b[j-1];
|
b[j] = b[j-1];
|
||||||
|
|
|
@ -292,7 +292,7 @@ fn (mut g Gen) const_decl_simple_define(mod string, name string, val string) {
|
||||||
if g.pref.translated {
|
if g.pref.translated {
|
||||||
g.global_const_defs[util.no_dots(name)] = GlobalConstDef{
|
g.global_const_defs[util.no_dots(name)] = GlobalConstDef{
|
||||||
mod: mod
|
mod: mod
|
||||||
def: 'const int ${x} = ${val};'
|
def: 'const ${ast.int_type_name} ${x} = ${val};'
|
||||||
order: -1
|
order: -1
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -86,10 +86,10 @@ fn (mut g Gen) write_coverage_stats() {
|
||||||
fmeta.writeln('}') or { continue }
|
fmeta.writeln('}') or { continue }
|
||||||
fmeta.close()
|
fmeta.close()
|
||||||
}
|
}
|
||||||
g.cov_declarations.writeln('\tlong int secs = 0;')
|
g.cov_declarations.writeln('\tint secs = 0;')
|
||||||
g.cov_declarations.writeln('\tlong int nsecs = 0;')
|
g.cov_declarations.writeln('\tint nsecs = 0;')
|
||||||
g.cov_declarations.writeln('\t#if defined(_WIN32)')
|
g.cov_declarations.writeln('\t#if defined(_WIN32)')
|
||||||
g.cov_declarations.writeln('\tlong int ticks_passed = GetTickCount();')
|
g.cov_declarations.writeln('\tint ticks_passed = GetTickCount();')
|
||||||
g.cov_declarations.writeln('\nsecs = ticks_passed / 1000;')
|
g.cov_declarations.writeln('\nsecs = ticks_passed / 1000;')
|
||||||
g.cov_declarations.writeln('\nnsecs = (ticks_passed % 1000) * 1000000;')
|
g.cov_declarations.writeln('\nnsecs = (ticks_passed % 1000) * 1000000;')
|
||||||
g.cov_declarations.writeln('\t#endif')
|
g.cov_declarations.writeln('\t#endif')
|
||||||
|
@ -109,7 +109,7 @@ fn (mut g Gen) write_coverage_stats() {
|
||||||
for k, cov in g.coverage_files {
|
for k, cov in g.coverage_files {
|
||||||
nr_points := cov.points.len
|
nr_points := cov.points.len
|
||||||
g.cov_declarations.writeln('\t{')
|
g.cov_declarations.writeln('\t{')
|
||||||
g.cov_declarations.writeln('\t\tfor (int i = 0; i < ${nr_points}; ++i) {')
|
g.cov_declarations.writeln('\t\tfor (${ast.int_type_name} i = 0; i < ${nr_points}; ++i) {')
|
||||||
g.cov_declarations.writeln('\t\t\tif (_v_cov[_v_cov_file_offset_${k}+i]) {')
|
g.cov_declarations.writeln('\t\t\tif (_v_cov[_v_cov_file_offset_${k}+i]) {')
|
||||||
g.cov_declarations.writeln("\t\t\t\tfprintf(fp, \"%s,%d,%ld\\n\", \"${cov.fhash}\", i, _v_cov[_v_cov_file_offset_${k}+i]);")
|
g.cov_declarations.writeln("\t\t\t\tfprintf(fp, \"%s,%d,%ld\\n\", \"${cov.fhash}\", i, _v_cov[_v_cov_file_offset_${k}+i]);")
|
||||||
g.cov_declarations.writeln('\t\t\t}')
|
g.cov_declarations.writeln('\t\t\t}')
|
||||||
|
|
|
@ -177,14 +177,15 @@ fn (mut g Gen) dump_expr_definitions() {
|
||||||
}
|
}
|
||||||
dump_already_generated_fns[dump_fn_name] = true
|
dump_already_generated_fns[dump_fn_name] = true
|
||||||
|
|
||||||
dump_fn_defs.writeln('${str_dumparg_ret_type} ${dump_fn_name}(string fpath, int line, string sexpr, ${str_dumparg_type} dump_arg);')
|
dump_fn_defs.writeln('${str_dumparg_ret_type} ${dump_fn_name}(string fpath, ${ast.int_type_name} line, string sexpr, ${str_dumparg_type} dump_arg);')
|
||||||
if g.writeln_fn_header('${str_dumparg_ret_type} ${dump_fn_name}(string fpath, int line, string sexpr, ${str_dumparg_type} dump_arg)', mut
|
if g.writeln_fn_header('${str_dumparg_ret_type} ${dump_fn_name}(string fpath, ${ast.int_type_name} line, string sexpr, ${str_dumparg_type} dump_arg)', mut
|
||||||
dump_fns)
|
dump_fns)
|
||||||
{
|
{
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
mut surrounder := util.new_surrounder(3)
|
mut surrounder := util.new_surrounder(3)
|
||||||
surrounder.add('\tstring sline = builtin__int_str(line);', '\tbuiltin__string_free(&sline);')
|
int_str := g.get_str_fn(ast.int_type)
|
||||||
|
surrounder.add('\tstring sline = ${int_str}(line);', '\tbuiltin__string_free(&sline);')
|
||||||
if dump_sym.kind == .function && !is_option {
|
if dump_sym.kind == .function && !is_option {
|
||||||
surrounder.add('\tstring value = ${to_string_fn_name}();', '\tbuiltin__string_free(&value);')
|
surrounder.add('\tstring value = ${to_string_fn_name}();', '\tbuiltin__string_free(&value);')
|
||||||
} else if dump_sym.kind == .none {
|
} else if dump_sym.kind == .none {
|
||||||
|
|
|
@ -1686,7 +1686,7 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
|
||||||
if resolved_sym.is_builtin() && !receiver_type_name.starts_with('_') {
|
if resolved_sym.is_builtin() && !receiver_type_name.starts_with('_') {
|
||||||
name = 'builtin__${name}'
|
name = 'builtin__${name}'
|
||||||
}
|
}
|
||||||
} else if receiver_type_name in ['int_literal', 'float_literal'] {
|
} else if receiver_type_name in ['int_literal', 'float_literal', 'vint_t'] {
|
||||||
name = 'builtin__${name}'
|
name = 'builtin__${name}'
|
||||||
}
|
}
|
||||||
if left_sym.kind == .chan && node.name in ['close', 'try_pop', 'try_push'] {
|
if left_sym.kind == .chan && node.name in ['close', 'try_pop', 'try_push'] {
|
||||||
|
|
|
@ -246,7 +246,7 @@ fn (mut g Gen) for_in_stmt(node_ ast.ForInStmt) {
|
||||||
} else {
|
} else {
|
||||||
'${cond_var}${op_field}len'
|
'${cond_var}${op_field}len'
|
||||||
}
|
}
|
||||||
g.writeln('for (int ${i} = 0; ${i} < ${cond_expr}; ++${i}) {')
|
g.writeln('for (${ast.int_type_name} ${i} = 0; ${i} < ${cond_expr}; ++${i}) {')
|
||||||
if node.val_var != '_' {
|
if node.val_var != '_' {
|
||||||
if mut val_sym.info is ast.FnType {
|
if mut val_sym.info is ast.FnType {
|
||||||
g.write('\t')
|
g.write('\t')
|
||||||
|
@ -308,7 +308,7 @@ fn (mut g Gen) for_in_stmt(node_ ast.ForInStmt) {
|
||||||
idx := if node.key_var in ['', '_'] { g.new_tmp_var() } else { node.key_var }
|
idx := if node.key_var in ['', '_'] { g.new_tmp_var() } else { node.key_var }
|
||||||
cond_sym := g.table.final_sym(node.cond_type)
|
cond_sym := g.table.final_sym(node.cond_type)
|
||||||
info := cond_sym.info as ast.ArrayFixed
|
info := cond_sym.info as ast.ArrayFixed
|
||||||
g.writeln('for (int ${idx} = 0; ${idx} != ${info.size}; ++${idx}) {')
|
g.writeln('for (${ast.int_type_name} ${idx} = 0; ${idx} != ${info.size}; ++${idx}) {')
|
||||||
if node.val_var != '_' {
|
if node.val_var != '_' {
|
||||||
val_sym := g.table.sym(node.val_type)
|
val_sym := g.table.sym(node.val_type)
|
||||||
is_fixed_array := val_sym.kind == .array_fixed && !node.val_is_mut
|
is_fixed_array := val_sym.kind == .array_fixed && !node.val_is_mut
|
||||||
|
@ -357,12 +357,12 @@ fn (mut g Gen) for_in_stmt(node_ ast.ForInStmt) {
|
||||||
idx := g.new_tmp_var()
|
idx := g.new_tmp_var()
|
||||||
map_len := g.new_tmp_var()
|
map_len := g.new_tmp_var()
|
||||||
g.empty_line = true
|
g.empty_line = true
|
||||||
g.writeln('int ${map_len} = ${cond_var}${dot_or_ptr}key_values.len;')
|
g.writeln('${ast.int_type_name} ${map_len} = ${cond_var}${dot_or_ptr}key_values.len;')
|
||||||
g.writeln('for (int ${idx} = 0; ${idx} < ${map_len}; ++${idx} ) {')
|
g.writeln('for (${ast.int_type_name} ${idx} = 0; ${idx} < ${map_len}; ++${idx} ) {')
|
||||||
// TODO: don't have this check when the map has no deleted elements
|
// TODO: don't have this check when the map has no deleted elements
|
||||||
g.indent++
|
g.indent++
|
||||||
diff := g.new_tmp_var()
|
diff := g.new_tmp_var()
|
||||||
g.writeln('int ${diff} = ${cond_var}${dot_or_ptr}key_values.len - ${map_len};')
|
g.writeln('${ast.int_type_name} ${diff} = ${cond_var}${dot_or_ptr}key_values.len - ${map_len};')
|
||||||
g.writeln('${map_len} = ${cond_var}${dot_or_ptr}key_values.len;')
|
g.writeln('${map_len} = ${cond_var}${dot_or_ptr}key_values.len;')
|
||||||
// TODO: optimize this
|
// TODO: optimize this
|
||||||
g.writeln('if (${diff} < 0) {')
|
g.writeln('if (${diff} < 0) {')
|
||||||
|
@ -413,7 +413,7 @@ fn (mut g Gen) for_in_stmt(node_ ast.ForInStmt) {
|
||||||
}
|
}
|
||||||
field_accessor := if node.cond_type.is_ptr() { '->' } else { '.' }
|
field_accessor := if node.cond_type.is_ptr() { '->' } else { '.' }
|
||||||
i := if node.key_var in ['', '_'] { g.new_tmp_var() } else { node.key_var }
|
i := if node.key_var in ['', '_'] { g.new_tmp_var() } else { node.key_var }
|
||||||
g.write('for (int ${i} = 0; ${i} < ')
|
g.write('for (${ast.int_type_name} ${i} = 0; ${i} < ')
|
||||||
g.expr(cond)
|
g.expr(cond)
|
||||||
g.writeln('${field_accessor}len; ++${i}) {')
|
g.writeln('${field_accessor}len; ++${i}) {')
|
||||||
if node.val_var != '_' {
|
if node.val_var != '_' {
|
||||||
|
@ -522,7 +522,7 @@ fn (mut g Gen) for_in_stmt(node_ ast.ForInStmt) {
|
||||||
|
|
||||||
if node.kind == .map {
|
if node.kind == .map {
|
||||||
// diff := g.new_tmp_var()
|
// diff := g.new_tmp_var()
|
||||||
// g.writeln('int $diff = $cond_var${arw_or_pt}key_values.len - $map_len;')
|
// g.writeln('${ast.int_type_name} $diff = $cond_var${arw_or_pt}key_values.len - $map_len;')
|
||||||
// g.writeln('if ($diff < 0) {')
|
// g.writeln('if ($diff < 0) {')
|
||||||
// g.writeln('\t$idx = -1;')
|
// g.writeln('\t$idx = -1;')
|
||||||
// g.writeln('\t$map_len = $cond_var${arw_or_pt}key_values.len;')
|
// g.writeln('\t$map_len = $cond_var${arw_or_pt}key_values.len;')
|
||||||
|
|
|
@ -152,7 +152,7 @@ fn (mut g Gen) index_range_expr(node ast.IndexExpr, range ast.RangeExpr) {
|
||||||
} else if sym.info is ast.ArrayFixed {
|
} else if sym.info is ast.ArrayFixed {
|
||||||
g.write('${sym.info.size}')
|
g.write('${sym.info.size}')
|
||||||
} else {
|
} else {
|
||||||
g.write('2147483647') // max_int
|
g.write('${max_int}')
|
||||||
}
|
}
|
||||||
g.write(')')
|
g.write(')')
|
||||||
|
|
||||||
|
|
|
@ -87,12 +87,12 @@ ${dec_fn_dec} {
|
||||||
if (!root) {
|
if (!root) {
|
||||||
const char *error_ptr = cJSON_GetErrorPtr();
|
const char *error_ptr = cJSON_GetErrorPtr();
|
||||||
if (error_ptr != NULL) {
|
if (error_ptr != NULL) {
|
||||||
const int error_pos = (int)cJSON_GetErrorPos();
|
const ${ast.int_type_name} error_pos = (${ast.int_type_name})cJSON_GetErrorPos();
|
||||||
int maxcontext_chars = 30;
|
${ast.int_type_name} maxcontext_chars = 30;
|
||||||
byte *buf = builtin__vcalloc_noscan(maxcontext_chars + 10);
|
byte *buf = builtin__vcalloc_noscan(maxcontext_chars + 10);
|
||||||
if (error_pos > 0) {
|
if (error_pos > 0) {
|
||||||
int backlines = 1;
|
${ast.int_type_name} backlines = 1;
|
||||||
int backchars = error_pos < maxcontext_chars-7 ? (int)error_pos : maxcontext_chars-7 ;
|
${ast.int_type_name} backchars = error_pos < maxcontext_chars-7 ? (${ast.int_type_name})error_pos : maxcontext_chars-7 ;
|
||||||
char *prevline_ptr = (char*)error_ptr;
|
char *prevline_ptr = (char*)error_ptr;
|
||||||
while(backchars--){
|
while(backchars--){
|
||||||
char prevc = *(prevline_ptr - 1);
|
char prevc = *(prevline_ptr - 1);
|
||||||
|
@ -107,7 +107,7 @@ ${dec_fn_dec} {
|
||||||
break; // stop at `{` too
|
break; // stop at `{` too
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int maxchars = builtin__vstrlen_char(prevline_ptr);
|
${ast.int_type_name} maxchars = builtin__vstrlen_char(prevline_ptr);
|
||||||
builtin__vmemcpy(buf, prevline_ptr, (maxchars < maxcontext_chars ? maxchars : maxcontext_chars));
|
builtin__vmemcpy(buf, prevline_ptr, (maxchars < maxcontext_chars ? maxchars : maxcontext_chars));
|
||||||
}
|
}
|
||||||
string msg;
|
string msg;
|
||||||
|
@ -612,8 +612,8 @@ fn (mut g Gen) gen_sumtype_enc_dec(utyp ast.Type, sym ast.TypeSymbol, mut enc st
|
||||||
dec.writeln('\t\t}')
|
dec.writeln('\t\t}')
|
||||||
}
|
}
|
||||||
|
|
||||||
if var_t in ['i64', 'int', 'i8', 'u64', 'u32', 'u16', 'byte', 'u8', 'rune', 'f64',
|
if var_t in ['i8', 'i16', 'i32', 'i64', ast.int_type_name, 'int', 'u8', 'u16',
|
||||||
'f32'] {
|
'u32', 'u64', 'byte', 'rune', 'f64', 'f32'] {
|
||||||
if number_is_met {
|
if number_is_met {
|
||||||
var_num := var_t.replace('__', '.')
|
var_num := var_t.replace('__', '.')
|
||||||
last_num := last_number_type.replace('__', '.')
|
last_num := last_number_type.replace('__', '.')
|
||||||
|
@ -703,7 +703,7 @@ fn (mut g Gen) gen_struct_enc_dec(utyp ast.Type, type_info ast.TypeInfo, styp st
|
||||||
if is_skip {
|
if is_skip {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
field_type := g.styp(field.typ)
|
field_type := vint2int(g.styp(field.typ))
|
||||||
field_sym := g.table.sym(field.typ)
|
field_sym := g.table.sym(field.typ)
|
||||||
op := if utyp.is_ptr() { '->' } else { '.' }
|
op := if utyp.is_ptr() { '->' } else { '.' }
|
||||||
embed_member := if embed_prefix.len > 0 { '.${embed_prefix}' } else { '' }
|
embed_member := if embed_prefix.len > 0 { '.${embed_prefix}' } else { '' }
|
||||||
|
@ -1031,6 +1031,7 @@ fn js_enc_name(typ string) string {
|
||||||
if typ == 'i32' {
|
if typ == 'i32' {
|
||||||
suffix = typ.replace('i32', 'int')
|
suffix = typ.replace('i32', 'int')
|
||||||
}
|
}
|
||||||
|
suffix = vint2int(suffix)
|
||||||
name := 'json__encode_${suffix}'
|
name := 'json__encode_${suffix}'
|
||||||
return util.no_dots(name)
|
return util.no_dots(name)
|
||||||
}
|
}
|
||||||
|
@ -1040,13 +1041,14 @@ fn js_dec_name(typ string) string {
|
||||||
if typ == 'i32' {
|
if typ == 'i32' {
|
||||||
suffix = typ.replace('i32', 'int')
|
suffix = typ.replace('i32', 'int')
|
||||||
}
|
}
|
||||||
|
suffix = vint2int(suffix)
|
||||||
name := 'json__decode_${suffix}'
|
name := 'json__decode_${suffix}'
|
||||||
return util.no_dots(name)
|
return util.no_dots(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_js_prim(typ string) bool {
|
fn is_js_prim(typ string) bool {
|
||||||
return typ in ['int', 'rune', 'string', 'bool', 'f32', 'f64', 'i8', 'i16', 'i32', 'i64', 'u8',
|
return typ in [ast.int_type_name, 'int', 'rune', 'string', 'bool', 'f32', 'f64', 'i8', 'i16',
|
||||||
'u16', 'u32', 'u64', 'byte']
|
'i32', 'i64', 'u8', 'u16', 'u32', 'u64', 'byte']
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut g Gen) decode_array(utyp ast.Type, value_type ast.Type, fixed_array_size int, ret_styp string) string {
|
fn (mut g Gen) decode_array(utyp ast.Type, value_type ast.Type, fixed_array_size int, ret_styp string) string {
|
||||||
|
@ -1062,7 +1064,7 @@ fn (mut g Gen) decode_array(utyp ast.Type, value_type ast.Type, fixed_array_size
|
||||||
is_array_fixed_val := g.table.final_sym(value_type).kind == .array_fixed
|
is_array_fixed_val := g.table.final_sym(value_type).kind == .array_fixed
|
||||||
if utyp.has_flag(.option) {
|
if utyp.has_flag(.option) {
|
||||||
if fixed_array_size > -1 {
|
if fixed_array_size > -1 {
|
||||||
fixed_array_idx += 'int fixed_array_idx = 0;'
|
fixed_array_idx += '${ast.int_type_name} fixed_array_idx = 0;'
|
||||||
array_element_assign += '((${styp}*)res.data)[fixed_array_idx] = val;'
|
array_element_assign += '((${styp}*)res.data)[fixed_array_idx] = val;'
|
||||||
fixed_array_idx_increment += 'fixed_array_idx++; res.state = 0;'
|
fixed_array_idx_increment += 'fixed_array_idx++; res.state = 0;'
|
||||||
} else {
|
} else {
|
||||||
|
@ -1072,11 +1074,11 @@ fn (mut g Gen) decode_array(utyp ast.Type, value_type ast.Type, fixed_array_size
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if is_array_fixed_val {
|
if is_array_fixed_val {
|
||||||
fixed_array_idx += 'int fixed_array_idx = 0;'
|
fixed_array_idx += '${ast.int_type_name} fixed_array_idx = 0;'
|
||||||
array_element_assign += 'memcpy(res[fixed_array_idx], val, sizeof(${styp}));'
|
array_element_assign += 'memcpy(res[fixed_array_idx], val, sizeof(${styp}));'
|
||||||
fixed_array_idx_increment += 'fixed_array_idx++;'
|
fixed_array_idx_increment += 'fixed_array_idx++;'
|
||||||
} else if fixed_array_size > -1 {
|
} else if fixed_array_size > -1 {
|
||||||
fixed_array_idx += 'int fixed_array_idx = 0;'
|
fixed_array_idx += '${ast.int_type_name} fixed_array_idx = 0;'
|
||||||
array_element_assign += 'res[fixed_array_idx] = val;'
|
array_element_assign += 'res[fixed_array_idx] = val;'
|
||||||
fixed_array_idx_increment += 'fixed_array_idx++;'
|
fixed_array_idx_increment += 'fixed_array_idx++;'
|
||||||
} else {
|
} else {
|
||||||
|
@ -1150,7 +1152,7 @@ fn (mut g Gen) encode_array(utyp ast.Type, value_type ast.Type, fixed_array_size
|
||||||
|
|
||||||
return '
|
return '
|
||||||
o = cJSON_CreateArray();
|
o = cJSON_CreateArray();
|
||||||
for (int i = 0; i < ${size_str}; i++){
|
for (${ast.int_type_name} i = 0; i < ${size_str}; i++){
|
||||||
cJSON_AddItemToArray(o, ${fn_name}( (${data_str})[i] ));
|
cJSON_AddItemToArray(o, ${fn_name}( (${data_str})[i] ));
|
||||||
}
|
}
|
||||||
'
|
'
|
||||||
|
@ -1225,7 +1227,7 @@ fn (mut g Gen) encode_map(utyp ast.Type, key_type ast.Type, value_type ast.Type)
|
||||||
return '
|
return '
|
||||||
o = cJSON_CreateObject();
|
o = cJSON_CreateObject();
|
||||||
Array_${styp} ${keys_tmp} = builtin__map_keys((map*)val.data);
|
Array_${styp} ${keys_tmp} = builtin__map_keys((map*)val.data);
|
||||||
for (int i = 0; i < ${keys_tmp}.len; ++i) {
|
for (${ast.int_type_name} i = 0; i < ${keys_tmp}.len; ++i) {
|
||||||
${key}
|
${key}
|
||||||
cJSON_AddItemToObject(o, (char*) key.str, ${fn_name_v} ( *(${styp_v}*) builtin__map_get((map*)val.data, &key, &(${styp_v}[]) { ${zero} } ) ) );
|
cJSON_AddItemToObject(o, (char*) key.str, ${fn_name_v} ( *(${styp_v}*) builtin__map_get((map*)val.data, &key, &(${styp_v}[]) { ${zero} } ) ) );
|
||||||
}
|
}
|
||||||
|
@ -1235,7 +1237,7 @@ fn (mut g Gen) encode_map(utyp ast.Type, key_type ast.Type, value_type ast.Type)
|
||||||
return '
|
return '
|
||||||
o = cJSON_CreateObject();
|
o = cJSON_CreateObject();
|
||||||
Array_${styp} ${keys_tmp} = builtin__map_keys(&val);
|
Array_${styp} ${keys_tmp} = builtin__map_keys(&val);
|
||||||
for (int i = 0; i < ${keys_tmp}.len; ++i) {
|
for (${ast.int_type_name} i = 0; i < ${keys_tmp}.len; ++i) {
|
||||||
${key}
|
${key}
|
||||||
cJSON_AddItemToObject(o, (char*) key.str, ${fn_name_v} ( *(${styp_v}*) builtin__map_get(&val, &key, &(${styp_v}[]) { ${zero} } ) ) );
|
cJSON_AddItemToObject(o, (char*) key.str, ${fn_name_v} ( *(${styp_v}*) builtin__map_get(&val, &key, &(${styp_v}[]) { ${zero} } ) ) );
|
||||||
}
|
}
|
||||||
|
|
|
@ -292,7 +292,7 @@ fn (mut g Gen) write_orm_update(node &ast.SqlStmtLine, table_name string, connec
|
||||||
g.writeln('.kinds = builtin____new_array_with_default_noscan(0, 0, sizeof(orm__OperationKind), 0),')
|
g.writeln('.kinds = builtin____new_array_with_default_noscan(0, 0, sizeof(orm__OperationKind), 0),')
|
||||||
g.writeln('.is_and = builtin____new_array_with_default_noscan(0, 0, sizeof(bool), 0),')
|
g.writeln('.is_and = builtin____new_array_with_default_noscan(0, 0, sizeof(bool), 0),')
|
||||||
g.writeln('.types = builtin____new_array_with_default_noscan(0, 0, sizeof(${ast.int_type_name}), 0),')
|
g.writeln('.types = builtin____new_array_with_default_noscan(0, 0, sizeof(${ast.int_type_name}), 0),')
|
||||||
g.writeln('.parentheses = builtin____new_array_with_default_noscan(0, 0, sizeof(Array_int), 0),')
|
g.writeln('.parentheses = builtin____new_array_with_default_noscan(0, 0, sizeof(Array_${ast.int_type_name}), 0),')
|
||||||
|
|
||||||
if node.updated_columns.len > 0 {
|
if node.updated_columns.len > 0 {
|
||||||
g.writeln('.fields = builtin__new_array_from_c_array(${node.updated_columns.len}, ${node.updated_columns.len}, sizeof(string),')
|
g.writeln('.fields = builtin__new_array_from_c_array(${node.updated_columns.len}, ${node.updated_columns.len}, sizeof(string),')
|
||||||
|
@ -481,6 +481,7 @@ fn (mut g Gen) write_orm_insert_with_last_ids(node ast.SqlStmtLine, connection_v
|
||||||
} else if sym.kind == .enum {
|
} else if sym.kind == .enum {
|
||||||
typ = g.table.sym(final_field_typ).cname
|
typ = g.table.sym(final_field_typ).cname
|
||||||
}
|
}
|
||||||
|
typ = vint2int(typ)
|
||||||
var := '${node.object_var}${member_access_type}${c_name(field.name)}'
|
var := '${node.object_var}${member_access_type}${c_name(field.name)}'
|
||||||
if final_field_typ.has_flag(.option) {
|
if final_field_typ.has_flag(.option) {
|
||||||
g.writeln('${var}.state == 2? _const_orm__null_primitive : orm__${typ}_to_primitive(*(${ctyp}*)(${var}.data)),')
|
g.writeln('${var}.state == 2? _const_orm__null_primitive : orm__${typ}_to_primitive(*(${ctyp}*)(${var}.data)),')
|
||||||
|
@ -503,7 +504,7 @@ fn (mut g Gen) write_orm_insert_with_last_ids(node ast.SqlStmtLine, connection_v
|
||||||
if auto_fields.len > 0 {
|
if auto_fields.len > 0 {
|
||||||
g.writeln('.auto_fields = builtin__new_array_from_c_array(${auto_fields.len}, ${auto_fields.len}, sizeof(${ast.int_type_name}),')
|
g.writeln('.auto_fields = builtin__new_array_from_c_array(${auto_fields.len}, ${auto_fields.len}, sizeof(${ast.int_type_name}),')
|
||||||
g.indent++
|
g.indent++
|
||||||
g.write('_MOV((int[${auto_fields.len}]){')
|
g.write('_MOV((${ast.int_type_name}[${auto_fields.len}]){')
|
||||||
for i in auto_fields {
|
for i in auto_fields {
|
||||||
g.write(' ${i},')
|
g.write(' ${i},')
|
||||||
}
|
}
|
||||||
|
@ -533,6 +534,7 @@ fn (mut g Gen) write_orm_insert_with_last_ids(node ast.SqlStmtLine, connection_v
|
||||||
if typ == 'time__Time' {
|
if typ == 'time__Time' {
|
||||||
typ = 'time'
|
typ = 'time'
|
||||||
}
|
}
|
||||||
|
typ = vint2int(typ)
|
||||||
g.writeln('orm__Primitive ${id_name} = orm__${typ}_to_primitive(${node.object_var}${member_access_type}${c_name(primary_field.name)});')
|
g.writeln('orm__Primitive ${id_name} = orm__${typ}_to_primitive(${node.object_var}${member_access_type}${c_name(primary_field.name)});')
|
||||||
}
|
}
|
||||||
for i, mut arr in arrs {
|
for i, mut arr in arrs {
|
||||||
|
@ -540,9 +542,9 @@ fn (mut g Gen) write_orm_insert_with_last_ids(node ast.SqlStmtLine, connection_v
|
||||||
ctyp := g.styp(arr.table_expr.typ)
|
ctyp := g.styp(arr.table_expr.typ)
|
||||||
is_option := opt_fields.contains(i)
|
is_option := opt_fields.contains(i)
|
||||||
if is_option {
|
if is_option {
|
||||||
g.writeln('for (int ${idx} = 0; ${node.object_var}${member_access_type}${arr.object_var}.state != 2 && ${idx} < (*(Array_${ctyp}*)${node.object_var}${member_access_type}${arr.object_var}.data).len; ${idx}++) {')
|
g.writeln('for (${ast.int_type_name} ${idx} = 0; ${node.object_var}${member_access_type}${arr.object_var}.state != 2 && ${idx} < (*(Array_${ctyp}*)${node.object_var}${member_access_type}${arr.object_var}.data).len; ${idx}++) {')
|
||||||
} else {
|
} else {
|
||||||
g.writeln('for (int ${idx} = 0; ${idx} < ${node.object_var}${member_access_type}${arr.object_var}.len; ${idx}++) {')
|
g.writeln('for (${ast.int_type_name} ${idx} = 0; ${idx} < ${node.object_var}${member_access_type}${arr.object_var}.len; ${idx}++) {')
|
||||||
}
|
}
|
||||||
g.indent++
|
g.indent++
|
||||||
last_ids := g.new_tmp_var()
|
last_ids := g.new_tmp_var()
|
||||||
|
@ -680,6 +682,7 @@ fn (mut g Gen) write_orm_primitive(t ast.Type, expr ast.Expr) {
|
||||||
} else if g.table.final_sym(t).kind == .array {
|
} else if g.table.final_sym(t).kind == .array {
|
||||||
typ = g.table.sym(g.table.final_type(t)).cname.to_lower()
|
typ = g.table.sym(g.table.final_type(t)).cname.to_lower()
|
||||||
}
|
}
|
||||||
|
typ = vint2int(typ)
|
||||||
g.write('orm__${typ}_to_primitive(')
|
g.write('orm__${typ}_to_primitive(')
|
||||||
if expr is ast.CallExpr {
|
if expr is ast.CallExpr {
|
||||||
g.call_expr(expr)
|
g.call_expr(expr)
|
||||||
|
@ -741,10 +744,10 @@ fn (mut g Gen) write_orm_where(where_expr ast.Expr) {
|
||||||
|
|
||||||
g.write('.parentheses = ')
|
g.write('.parentheses = ')
|
||||||
if parentheses.len > 0 {
|
if parentheses.len > 0 {
|
||||||
g.write('builtin__new_array_from_c_array(${parentheses.len}, ${parentheses.len}, sizeof(Array_int), _MOV((Array_int[${parentheses.len}]){')
|
g.write('builtin__new_array_from_c_array(${parentheses.len}, ${parentheses.len}, sizeof(Array_${ast.int_type_name}), _MOV((Array_${ast.int_type_name}[${parentheses.len}]){')
|
||||||
for par in parentheses {
|
for par in parentheses {
|
||||||
if par.len > 0 {
|
if par.len > 0 {
|
||||||
g.write('builtin__new_array_from_c_array(${par.len}, ${par.len}, sizeof(${ast.int_type_name}), _MOV((int[${par.len}]){')
|
g.write('builtin__new_array_from_c_array(${par.len}, ${par.len}, sizeof(${ast.int_type_name}), _MOV((${ast.int_type_name}[${par.len}]){')
|
||||||
for val in par {
|
for val in par {
|
||||||
g.write('${val},')
|
g.write('${val},')
|
||||||
}
|
}
|
||||||
|
@ -755,7 +758,7 @@ fn (mut g Gen) write_orm_where(where_expr ast.Expr) {
|
||||||
}
|
}
|
||||||
g.write('}))')
|
g.write('}))')
|
||||||
} else {
|
} else {
|
||||||
g.write('builtin____new_array_with_default_noscan(0, 0, sizeof(Array_int), 0)')
|
g.write('builtin____new_array_with_default_noscan(0, 0, sizeof(Array_${ast.int_type_name}), 0)')
|
||||||
}
|
}
|
||||||
g.writeln(',')
|
g.writeln(',')
|
||||||
|
|
||||||
|
@ -1006,7 +1009,7 @@ fn (mut g Gen) write_orm_select(node ast.SqlExpr, connection_var_name string, re
|
||||||
g.indent++
|
g.indent++
|
||||||
|
|
||||||
if types.len > 0 {
|
if types.len > 0 {
|
||||||
g.write('_MOV((int[${types.len}]){')
|
g.write('_MOV((${ast.int_type_name}[${types.len}]){')
|
||||||
for typ in types {
|
for typ in types {
|
||||||
g.write(' ${typ},')
|
g.write(' ${typ},')
|
||||||
}
|
}
|
||||||
|
@ -1032,7 +1035,7 @@ fn (mut g Gen) write_orm_select(node ast.SqlExpr, connection_var_name string, re
|
||||||
g.writeln('.types = builtin____new_array_with_default_noscan(0, 0, sizeof(${ast.int_type_name}), 0),')
|
g.writeln('.types = builtin____new_array_with_default_noscan(0, 0, sizeof(${ast.int_type_name}), 0),')
|
||||||
g.writeln('.kinds = builtin____new_array_with_default_noscan(0, 0, sizeof(orm__OperationKind), 0),')
|
g.writeln('.kinds = builtin____new_array_with_default_noscan(0, 0, sizeof(orm__OperationKind), 0),')
|
||||||
g.writeln('.is_and = builtin____new_array_with_default_noscan(0, 0, sizeof(bool), 0),')
|
g.writeln('.is_and = builtin____new_array_with_default_noscan(0, 0, sizeof(bool), 0),')
|
||||||
g.writeln('.parentheses = builtin____new_array_with_default_noscan(0, 0, sizeof(Array_int), 0),')
|
g.writeln('.parentheses = builtin____new_array_with_default_noscan(0, 0, sizeof(Array_${ast.int_type_name}), 0),')
|
||||||
if exprs.len > 0 {
|
if exprs.len > 0 {
|
||||||
g.write('.data = builtin__new_array_from_c_array(${exprs.len}, ${exprs.len}, sizeof(orm__Primitive),')
|
g.write('.data = builtin__new_array_from_c_array(${exprs.len}, ${exprs.len}, sizeof(orm__Primitive),')
|
||||||
g.write(' _MOV((orm__Primitive[${exprs.len}]){')
|
g.write(' _MOV((orm__Primitive[${exprs.len}]){')
|
||||||
|
@ -1054,7 +1057,7 @@ fn (mut g Gen) write_orm_select(node ast.SqlExpr, connection_var_name string, re
|
||||||
g.writeln('.types = builtin____new_array_with_default_noscan(0, 0, sizeof(${ast.int_type_name}), 0),')
|
g.writeln('.types = builtin____new_array_with_default_noscan(0, 0, sizeof(${ast.int_type_name}), 0),')
|
||||||
g.writeln('.kinds = builtin____new_array_with_default_noscan(0, 0, sizeof(orm__OperationKind), 0),')
|
g.writeln('.kinds = builtin____new_array_with_default_noscan(0, 0, sizeof(orm__OperationKind), 0),')
|
||||||
g.writeln('.is_and = builtin____new_array_with_default_noscan(0, 0, sizeof(bool), 0),')
|
g.writeln('.is_and = builtin____new_array_with_default_noscan(0, 0, sizeof(bool), 0),')
|
||||||
g.writeln('.parentheses = builtin____new_array_with_default_noscan(0, 0, sizeof(Array_int), 0),')
|
g.writeln('.parentheses = builtin____new_array_with_default_noscan(0, 0, sizeof(Array_${ast.int_type_name}), 0),')
|
||||||
g.writeln('.data = builtin____new_array_with_default_noscan(0, 0, sizeof(orm__Primitive), 0)')
|
g.writeln('.data = builtin____new_array_with_default_noscan(0, 0, sizeof(orm__Primitive), 0)')
|
||||||
g.indent--
|
g.indent--
|
||||||
g.writeln('}')
|
g.writeln('}')
|
||||||
|
@ -1077,11 +1080,11 @@ fn (mut g Gen) write_orm_select(node ast.SqlExpr, connection_var_name string, re
|
||||||
g.writeln('Array_Array_orm__Primitive ${select_unwrapped_result_var_name} = (*(Array_Array_orm__Primitive*)${select_result_var_name}.data);')
|
g.writeln('Array_Array_orm__Primitive ${select_unwrapped_result_var_name} = (*(Array_Array_orm__Primitive*)${select_result_var_name}.data);')
|
||||||
|
|
||||||
if node.is_count {
|
if node.is_count {
|
||||||
g.writeln('*(${unwrapped_c_typ}*) ${result_var}.data = *((*(orm__Primitive*) builtin__array_get((*(Array_orm__Primitive*) builtin__array_get(${select_unwrapped_result_var_name}, 0)), 0))._int);')
|
g.writeln('*(${unwrapped_c_typ}*) ${result_var}.data = *((*(orm__Primitive*) builtin__array_get((*(Array_orm__Primitive*) builtin__array_get(${select_unwrapped_result_var_name}, 0)), 0))._${ast.int_type_name});')
|
||||||
} else {
|
} else {
|
||||||
tmp := g.new_tmp_var()
|
tmp := g.new_tmp_var()
|
||||||
idx := g.new_tmp_var()
|
idx := g.new_tmp_var()
|
||||||
g.writeln('int ${idx} = 0;')
|
g.writeln('${ast.int_type_name} ${idx} = 0;')
|
||||||
mut typ_str := ''
|
mut typ_str := ''
|
||||||
if node.is_array {
|
if node.is_array {
|
||||||
info := g.table.sym(node.typ).array_info()
|
info := g.table.sym(node.typ).array_info()
|
||||||
|
@ -1337,8 +1340,8 @@ fn (g &Gen) get_orm_column_name_from_struct_field(field ast.StructField) string
|
||||||
mut name := field.name
|
mut name := field.name
|
||||||
|
|
||||||
if attr := field.attrs.find_first('sql') {
|
if attr := field.attrs.find_first('sql') {
|
||||||
if attr.arg !in ['serial', 'i8', 'i16', 'int', 'i64', 'u8', 'u16', 'u32', 'u64', 'f32',
|
if attr.arg !in ['serial', 'i8', 'i16', 'i32', 'int', 'i64', 'u8', 'u16', 'u32', 'u64',
|
||||||
'f64', 'bool', 'string'] {
|
'f32', 'f64', 'bool', 'string'] {
|
||||||
name = attr.arg
|
name = attr.arg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,7 +123,7 @@ fn (g &Gen) gen_type_array(types []ast.Type) string {
|
||||||
if types.len == 0 {
|
if types.len == 0 {
|
||||||
return g.gen_empty_array(ast.int_type_name)
|
return g.gen_empty_array(ast.int_type_name)
|
||||||
}
|
}
|
||||||
return 'builtin__new_array_from_c_array(${types.len},${types.len},sizeof(${ast.int_type_name}),_MOV((int[${types.len}]){${types.map(int(it).str()).join(',')}}))'
|
return 'builtin__new_array_from_c_array(${types.len},${types.len},sizeof(int),_MOV((int[${types.len}]){${types.map(int(it).str()).join(',')}}))'
|
||||||
}
|
}
|
||||||
|
|
||||||
// gen_string_array generates C code for []string
|
// gen_string_array generates C code for []string
|
||||||
|
|
|
@ -119,16 +119,46 @@ fn (mut g Gen) str_format(node ast.StringInterLiteral, i int, fmts []u8) (u64, s
|
||||||
fmt_type = .si_c
|
fmt_type = .si_c
|
||||||
} else {
|
} else {
|
||||||
match typ {
|
match typ {
|
||||||
ast.i8_type { fmt_type = .si_i8 }
|
ast.i8_type {
|
||||||
ast.u8_type { fmt_type = .si_u8 }
|
fmt_type = .si_i8
|
||||||
ast.i16_type { fmt_type = .si_i16 }
|
}
|
||||||
ast.u16_type { fmt_type = .si_u16 }
|
ast.u8_type {
|
||||||
ast.i64_type { fmt_type = .si_i64 }
|
fmt_type = .si_u8
|
||||||
ast.u64_type { fmt_type = .si_u64 }
|
}
|
||||||
ast.u32_type { fmt_type = .si_u32 }
|
ast.i16_type {
|
||||||
ast.usize_type { fmt_type = .si_u64 }
|
fmt_type = .si_i16
|
||||||
ast.isize_type { fmt_type = .si_i64 }
|
}
|
||||||
else { fmt_type = .si_i32 }
|
ast.u16_type {
|
||||||
|
fmt_type = .si_u16
|
||||||
|
}
|
||||||
|
ast.i64_type {
|
||||||
|
fmt_type = .si_i64
|
||||||
|
}
|
||||||
|
ast.u64_type {
|
||||||
|
fmt_type = .si_u64
|
||||||
|
}
|
||||||
|
ast.i32_type {
|
||||||
|
fmt_type = .si_i32
|
||||||
|
}
|
||||||
|
ast.u32_type {
|
||||||
|
fmt_type = .si_u32
|
||||||
|
}
|
||||||
|
ast.int_type {
|
||||||
|
$if new_int ? && (arm64 || amd64 || rv64 || s390x || ppc64le || loongarch64) {
|
||||||
|
fmt_type = .si_i64
|
||||||
|
} $else {
|
||||||
|
fmt_type = .si_i32
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ast.usize_type {
|
||||||
|
fmt_type = .si_u64
|
||||||
|
}
|
||||||
|
ast.isize_type {
|
||||||
|
fmt_type = .si_i64
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fmt_type = .si_i32
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -206,8 +236,14 @@ fn (mut g Gen) str_val(node ast.StringInterLiteral, i int, fmts []u8) {
|
||||||
g.write('(byte)(')
|
g.write('(byte)(')
|
||||||
} else if typ == ast.i16_type {
|
} else if typ == ast.i16_type {
|
||||||
g.write('(u16)(')
|
g.write('(u16)(')
|
||||||
} else if typ == ast.int_type {
|
} else if typ == ast.i32_type {
|
||||||
g.write('(u32)(')
|
g.write('(u32)(')
|
||||||
|
} else if typ == ast.int_type {
|
||||||
|
$if new_int ? && (arm64 || amd64 || rv64 || s390x || ppc64le || loongarch64) {
|
||||||
|
g.write('(u64)(')
|
||||||
|
} $else {
|
||||||
|
g.write('(u32)(')
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
g.write('(u64)(')
|
g.write('(u64)(')
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,8 @@ fn (mut g JsGen) to_js_typ_val(t ast.Type) string {
|
||||||
return g.to_js_typ_val(sym.info.variants[0])
|
return g.to_js_typ_val(sym.info.variants[0])
|
||||||
}
|
}
|
||||||
match sym.kind {
|
match sym.kind {
|
||||||
.i8, .i16, .int, .i64, .u8, .u16, .u32, .u64, .f32, .f64, .int_literal, .float_literal {
|
.i8, .i16, .i32, .int, .i64, .u8, .u16, .u32, .u64, .f32, .f64, .int_literal,
|
||||||
|
.float_literal {
|
||||||
styp = '${prefix}${g.sym_to_js_typ(sym)}(0)'
|
styp = '${prefix}${g.sym_to_js_typ(sym)}(0)'
|
||||||
}
|
}
|
||||||
.bool {
|
.bool {
|
||||||
|
@ -67,9 +68,16 @@ fn (mut g JsGen) sym_to_js_typ(sym ast.TypeSymbol) string {
|
||||||
.i16 {
|
.i16 {
|
||||||
styp = 'i16'
|
styp = 'i16'
|
||||||
}
|
}
|
||||||
.int {
|
.i32 {
|
||||||
styp = 'int'
|
styp = 'int'
|
||||||
}
|
}
|
||||||
|
.int {
|
||||||
|
$if new_int ? && (arm64 || amd64 || rv64 || s390x || ppc64le || loongarch64) {
|
||||||
|
styp = 'i64'
|
||||||
|
} $else {
|
||||||
|
styp = 'int'
|
||||||
|
}
|
||||||
|
}
|
||||||
.i64 {
|
.i64 {
|
||||||
styp = 'i64'
|
styp = 'i64'
|
||||||
}
|
}
|
||||||
|
@ -352,7 +360,7 @@ fn (mut g JsGen) gen_builtin_type_defs() {
|
||||||
for typ_name in v_types {
|
for typ_name in v_types {
|
||||||
// TODO: JsDoc
|
// TODO: JsDoc
|
||||||
match typ_name {
|
match typ_name {
|
||||||
'i8', 'i16', 'int', 'int_literal' {
|
'i8', 'i16', 'i32', 'int', 'int_literal' {
|
||||||
// TODO: Bounds checking
|
// TODO: Bounds checking
|
||||||
g.gen_builtin_prototype(
|
g.gen_builtin_prototype(
|
||||||
typ_name: typ_name
|
typ_name: typ_name
|
||||||
|
|
|
@ -199,7 +199,7 @@ fn (mut g JsGen) final_gen_copy(typ StrType) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
match styp {
|
match styp {
|
||||||
'byte', 'u8', 'u16', 'u32', 'u64', 'i16', 'int', 'i64', 'isize', 'usize', 'bool',
|
'byte', 'u8', 'u16', 'u32', 'u64', 'i16', 'i32', 'int', 'i64', 'isize', 'usize', 'bool',
|
||||||
'int_literal', 'float_literal', 'f32', 'f64', 'voidptr' {
|
'int_literal', 'float_literal', 'f32', 'f64', 'voidptr' {
|
||||||
g.definitions.writeln('function ${sym.cname}_\$copy(it) { return new ${sym.cname}(it.val); }')
|
g.definitions.writeln('function ${sym.cname}_\$copy(it) { return new ${sym.cname}(it.val); }')
|
||||||
return
|
return
|
||||||
|
|
|
@ -17,9 +17,9 @@ const js_reserved = ['await', 'break', 'case', 'catch', 'class', 'const', 'conti
|
||||||
'var', 'void', 'while', 'with', 'yield', 'Number', 'String', 'Boolean', 'Array', 'Map',
|
'var', 'void', 'while', 'with', 'yield', 'Number', 'String', 'Boolean', 'Array', 'Map',
|
||||||
'document', 'Promise']
|
'document', 'Promise']
|
||||||
// used to generate type structs
|
// used to generate type structs
|
||||||
const v_types = ['i8', 'i16', 'int', 'i64', 'u8', 'u16', 'u32', 'u64', 'f32', 'f64', 'int_literal',
|
const v_types = ['i8', 'i16', 'i32', 'int', 'i64', 'u8', 'u16', 'u32', 'u64', 'f32', 'f64',
|
||||||
'float_literal', 'bool', 'string', 'map', 'array', 'rune', 'any', 'voidptr']
|
'int_literal', 'float_literal', 'bool', 'string', 'map', 'array', 'rune', 'any', 'voidptr']
|
||||||
const shallow_equatables = [ast.Kind.i8, .i16, .int, .i64, .u8, .u16, .u32, .u64, .f32, .f64,
|
const shallow_equatables = [ast.Kind.i8, .i16, .i32, .int, .i64, .u8, .u16, .u32, .u64, .f32, .f64,
|
||||||
.int_literal, .float_literal, .bool, .string]
|
.int_literal, .float_literal, .bool, .string]
|
||||||
const option_name = '_option'
|
const option_name = '_option'
|
||||||
|
|
||||||
|
@ -3186,8 +3186,15 @@ fn (mut g JsGen) greater_typ(left ast.Type, right ast.Type) ast.Type {
|
||||||
if ast.u32_type_idx in lr {
|
if ast.u32_type_idx in lr {
|
||||||
return ast.Type(ast.u32_type_idx)
|
return ast.Type(ast.u32_type_idx)
|
||||||
}
|
}
|
||||||
|
if ast.i32_type_idx in lr {
|
||||||
|
return ast.Type(ast.i32_type_idx)
|
||||||
|
}
|
||||||
if ast.int_type_idx in lr {
|
if ast.int_type_idx in lr {
|
||||||
return ast.Type(ast.int_type_idx)
|
$if new_int ? && (arm64 || amd64 || rv64 || s390x || ppc64le || loongarch64) {
|
||||||
|
return ast.Type(ast.i64_type_idx)
|
||||||
|
} $else {
|
||||||
|
return ast.Type(ast.i32_type_idx)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ast.u16_type_idx in lr {
|
if ast.u16_type_idx in lr {
|
||||||
return ast.Type(ast.u16_type_idx)
|
return ast.Type(ast.u16_type_idx)
|
||||||
|
|
|
@ -501,10 +501,19 @@ fn (mut c Amd64) inc_var(var Var, config VarConfig) {
|
||||||
c.g.write16(0xFF48)
|
c.g.write16(0xFF48)
|
||||||
size_str = 'QWORD'
|
size_str = 'QWORD'
|
||||||
}
|
}
|
||||||
ast.i32_type_idx, ast.int_type_idx, ast.u32_type_idx, ast.rune_type_idx {
|
ast.i32_type_idx, ast.u32_type_idx, ast.rune_type_idx {
|
||||||
c.g.write8(0xFF)
|
c.g.write8(0xFF)
|
||||||
size_str = 'DWORD'
|
size_str = 'DWORD'
|
||||||
}
|
}
|
||||||
|
ast.int_type_idx {
|
||||||
|
$if new_int ? && (arm64 || amd64 || rv64 || s390x || ppc64le || loongarch64) {
|
||||||
|
c.g.write16(0xFF48)
|
||||||
|
size_str = 'QWORD'
|
||||||
|
} $else {
|
||||||
|
c.g.write8(0xFF)
|
||||||
|
size_str = 'DWORD'
|
||||||
|
}
|
||||||
|
}
|
||||||
ast.i16_type_idx, ast.u16_type_idx {
|
ast.i16_type_idx, ast.u16_type_idx {
|
||||||
c.g.write8(0xFF)
|
c.g.write8(0xFF)
|
||||||
size_str = 'WORD'
|
size_str = 'WORD'
|
||||||
|
@ -764,13 +773,25 @@ fn (mut c Amd64) mov_reg_to_var(var Var, r Register, config VarConfig) {
|
||||||
c.g.write16(0x8948 + if is_extended_register { i32(4) } else { i32(0) })
|
c.g.write16(0x8948 + if is_extended_register { i32(4) } else { i32(0) })
|
||||||
size_str = 'QWORD'
|
size_str = 'QWORD'
|
||||||
}
|
}
|
||||||
ast.i32_type_idx, ast.int_type_idx, ast.u32_type_idx, ast.rune_type_idx {
|
ast.i32_type_idx, ast.u32_type_idx, ast.rune_type_idx {
|
||||||
if is_extended_register {
|
if is_extended_register {
|
||||||
c.g.write8(0x44)
|
c.g.write8(0x44)
|
||||||
}
|
}
|
||||||
c.g.write8(0x89)
|
c.g.write8(0x89)
|
||||||
size_str = 'DWORD'
|
size_str = 'DWORD'
|
||||||
}
|
}
|
||||||
|
ast.int_type_idx {
|
||||||
|
$if new_int ? && (arm64 || amd64 || rv64 || s390x || ppc64le || loongarch64) {
|
||||||
|
c.g.write16(0x8948 + if is_extended_register { i32(4) } else { i32(0) })
|
||||||
|
size_str = 'QWORD'
|
||||||
|
} $else {
|
||||||
|
if is_extended_register {
|
||||||
|
c.g.write8(0x44)
|
||||||
|
}
|
||||||
|
c.g.write8(0x89)
|
||||||
|
size_str = 'DWORD'
|
||||||
|
}
|
||||||
|
}
|
||||||
ast.i16_type_idx, ast.u16_type_idx {
|
ast.i16_type_idx, ast.u16_type_idx {
|
||||||
c.g.write8(0x66)
|
c.g.write8(0x66)
|
||||||
if is_extended_register {
|
if is_extended_register {
|
||||||
|
@ -904,7 +925,7 @@ fn (mut c Amd64) mov_int_to_var(var Var, integer i32, config VarConfig) {
|
||||||
c.g.write16(u16(integer))
|
c.g.write16(u16(integer))
|
||||||
c.g.println('mov WORD PTR[rbp-${int(offset).hex2()}], ${integer}')
|
c.g.println('mov WORD PTR[rbp-${int(offset).hex2()}], ${integer}')
|
||||||
}
|
}
|
||||||
ast.i32_type_idx, ast.int_type_idx, ast.u32_type_idx, ast.rune_type_idx {
|
ast.i32_type_idx, ast.u32_type_idx, ast.rune_type_idx {
|
||||||
c.g.write8(0xc7)
|
c.g.write8(0xc7)
|
||||||
c.g.write8(if is_far_var { i32(0x85) } else { i32(0x45) })
|
c.g.write8(if is_far_var { i32(0x85) } else { i32(0x45) })
|
||||||
if is_far_var {
|
if is_far_var {
|
||||||
|
@ -915,6 +936,30 @@ fn (mut c Amd64) mov_int_to_var(var Var, integer i32, config VarConfig) {
|
||||||
c.g.write32(integer)
|
c.g.write32(integer)
|
||||||
c.g.println('mov DWORD PTR[rbp-${int(offset).hex2()}], ${integer}')
|
c.g.println('mov DWORD PTR[rbp-${int(offset).hex2()}], ${integer}')
|
||||||
}
|
}
|
||||||
|
ast.int_type_idx {
|
||||||
|
$if new_int ? && (arm64 || amd64 || rv64 || s390x || ppc64le || loongarch64) {
|
||||||
|
c.g.write8(0x48)
|
||||||
|
c.g.write8(0xc7)
|
||||||
|
c.g.write8(if is_far_var { i32(0x85) } else { i32(0x45) })
|
||||||
|
if is_far_var {
|
||||||
|
c.g.write32(i32((0xffffffff - i64(offset) + 1) % 0x100000000))
|
||||||
|
} else {
|
||||||
|
c.g.write8((0xff - offset + 1) % 0x100)
|
||||||
|
}
|
||||||
|
c.g.write32(integer)
|
||||||
|
c.g.println('mov QWORD PTR[rbp-${int(offset).hex2()}], ${integer}')
|
||||||
|
} $else {
|
||||||
|
c.g.write8(0xc7)
|
||||||
|
c.g.write8(if is_far_var { i32(0x85) } else { i32(0x45) })
|
||||||
|
if is_far_var {
|
||||||
|
c.g.write32(i32((0xffffffff - i64(offset) + 1) % 0x100000000))
|
||||||
|
} else {
|
||||||
|
c.g.write8((0xff - offset + 1) % 0x100)
|
||||||
|
}
|
||||||
|
c.g.write32(integer)
|
||||||
|
c.g.println('mov DWORD PTR[rbp-${int(offset).hex2()}], ${integer}')
|
||||||
|
}
|
||||||
|
}
|
||||||
ast.i64_type_idx, ast.u64_type_idx, ast.isize_type_idx, ast.usize_type_idx,
|
ast.i64_type_idx, ast.u64_type_idx, ast.isize_type_idx, ast.usize_type_idx,
|
||||||
ast.int_literal_type_idx {
|
ast.int_literal_type_idx {
|
||||||
c.g.write8(0x48)
|
c.g.write8(0x48)
|
||||||
|
@ -3950,7 +3995,7 @@ fn (mut c Amd64) zero_fill(size i32, var LocalVar) {
|
||||||
left -= 8
|
left -= 8
|
||||||
}
|
}
|
||||||
if left >= 4 {
|
if left >= 4 {
|
||||||
c.mov_int_to_var(var, 0, offset: size - left, typ: ast.int_type_idx)
|
c.mov_int_to_var(var, 0, offset: size - left, typ: ast.i32_type_idx)
|
||||||
left -= 4
|
left -= 4
|
||||||
}
|
}
|
||||||
if left >= 2 {
|
if left >= 2 {
|
||||||
|
|
|
@ -827,24 +827,64 @@ fn (mut g Gen) get_type_size(raw_type ast.Type) i32 {
|
||||||
}
|
}
|
||||||
if typ in ast.number_type_idxs {
|
if typ in ast.number_type_idxs {
|
||||||
return match typ {
|
return match typ {
|
||||||
ast.i8_type_idx { 1 }
|
ast.i8_type_idx {
|
||||||
ast.u8_type_idx { 1 }
|
1
|
||||||
ast.i16_type_idx { 2 }
|
}
|
||||||
ast.u16_type_idx { 2 }
|
ast.u8_type_idx {
|
||||||
ast.int_type_idx { 4 } // TODO: change when V will have changed
|
1
|
||||||
ast.i32_type_idx { 4 }
|
}
|
||||||
ast.u32_type_idx { 4 }
|
ast.i16_type_idx {
|
||||||
ast.i64_type_idx { 8 }
|
2
|
||||||
ast.u64_type_idx { 8 }
|
}
|
||||||
ast.isize_type_idx { 8 }
|
ast.u16_type_idx {
|
||||||
ast.usize_type_idx { 8 }
|
2
|
||||||
ast.int_literal_type_idx { 8 }
|
}
|
||||||
ast.f32_type_idx { 4 }
|
ast.int_type_idx {
|
||||||
ast.f64_type_idx { 8 }
|
$if new_int ? && (arm64 || amd64 || rv64 || s390x || ppc64le || loongarch64) {
|
||||||
ast.float_literal_type_idx { 8 }
|
8
|
||||||
ast.char_type_idx { 1 }
|
} $else {
|
||||||
ast.rune_type_idx { 4 }
|
4
|
||||||
else { g.n_error('${@LOCATION} unknown type size ${typ}') }
|
}
|
||||||
|
}
|
||||||
|
ast.i32_type_idx {
|
||||||
|
4
|
||||||
|
}
|
||||||
|
ast.u32_type_idx {
|
||||||
|
4
|
||||||
|
}
|
||||||
|
ast.i64_type_idx {
|
||||||
|
8
|
||||||
|
}
|
||||||
|
ast.u64_type_idx {
|
||||||
|
8
|
||||||
|
}
|
||||||
|
ast.isize_type_idx {
|
||||||
|
8
|
||||||
|
}
|
||||||
|
ast.usize_type_idx {
|
||||||
|
8
|
||||||
|
}
|
||||||
|
ast.int_literal_type_idx {
|
||||||
|
8
|
||||||
|
}
|
||||||
|
ast.f32_type_idx {
|
||||||
|
4
|
||||||
|
}
|
||||||
|
ast.f64_type_idx {
|
||||||
|
8
|
||||||
|
}
|
||||||
|
ast.float_literal_type_idx {
|
||||||
|
8
|
||||||
|
}
|
||||||
|
ast.char_type_idx {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
ast.rune_type_idx {
|
||||||
|
4
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
g.n_error('${@LOCATION} unknown type size ${typ}')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if typ.is_bool() {
|
if typ.is_bool() {
|
||||||
|
|
|
@ -37,9 +37,16 @@ pub fn (mut g Gen) get_wasm_type(typ_ ast.Type) wasm.ValType {
|
||||||
return match typ {
|
return match typ {
|
||||||
ast.isize_type_idx, ast.usize_type_idx, ast.i8_type_idx, ast.u8_type_idx,
|
ast.isize_type_idx, ast.usize_type_idx, ast.i8_type_idx, ast.u8_type_idx,
|
||||||
ast.char_type_idx, ast.rune_type_idx, ast.i16_type_idx, ast.u16_type_idx,
|
ast.char_type_idx, ast.rune_type_idx, ast.i16_type_idx, ast.u16_type_idx,
|
||||||
ast.int_type_idx, ast.u32_type_idx {
|
ast.i32_type_idx, ast.u32_type_idx {
|
||||||
wasm.ValType.i32_t
|
wasm.ValType.i32_t
|
||||||
}
|
}
|
||||||
|
ast.int_type_idx {
|
||||||
|
$if new_int ? && (arm64 || amd64 || rv64 || s390x || ppc64le || loongarch64) {
|
||||||
|
wasm.ValType.i64_t
|
||||||
|
} $else {
|
||||||
|
wasm.ValType.i32_t
|
||||||
|
}
|
||||||
|
}
|
||||||
ast.i64_type_idx, ast.u64_type_idx {
|
ast.i64_type_idx, ast.u64_type_idx {
|
||||||
wasm.ValType.i64_t
|
wasm.ValType.i64_t
|
||||||
}
|
}
|
||||||
|
|
|
@ -702,6 +702,9 @@ fn (mut p Parser) parse_any_type(language ast.Language, is_ptr bool, check_dot b
|
||||||
'i16' {
|
'i16' {
|
||||||
ret = ast.i16_type
|
ret = ast.i16_type
|
||||||
}
|
}
|
||||||
|
'i32' {
|
||||||
|
ret = ast.i32_type
|
||||||
|
}
|
||||||
'int' {
|
'int' {
|
||||||
ret = ast.int_type
|
ret = ast.int_type
|
||||||
}
|
}
|
||||||
|
@ -856,7 +859,7 @@ fn (mut p Parser) find_type_or_add_placeholder(name string, language ast.Languag
|
||||||
return typ
|
return typ
|
||||||
}
|
}
|
||||||
// not found - add placeholder
|
// not found - add placeholder
|
||||||
idx = p.table.add_placeholder_type(name, language)
|
idx = p.table.add_placeholder_type(name, name, language)
|
||||||
return ast.new_type(idx)
|
return ast.new_type(idx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -936,10 +939,10 @@ fn (mut p Parser) parse_generic_inst_type(name string) ast.Type {
|
||||||
if gt_idx > 0 {
|
if gt_idx > 0 {
|
||||||
return ast.new_type(gt_idx)
|
return ast.new_type(gt_idx)
|
||||||
}
|
}
|
||||||
gt_idx = p.table.add_placeholder_type(bs_name, .v)
|
gt_idx = p.table.add_placeholder_type(bs_name, bs_cname, .v)
|
||||||
mut parent_idx := p.table.type_idxs[name]
|
mut parent_idx := p.table.type_idxs[name]
|
||||||
if parent_idx == 0 {
|
if parent_idx == 0 {
|
||||||
parent_idx = p.table.add_placeholder_type(name, .v)
|
parent_idx = p.table.add_placeholder_type(name, name, .v)
|
||||||
}
|
}
|
||||||
parent_sym := p.table.sym(ast.new_type(parent_idx))
|
parent_sym := p.table.sym(ast.new_type(parent_idx))
|
||||||
match parent_sym.info {
|
match parent_sym.info {
|
||||||
|
|
|
@ -252,8 +252,6 @@ pub mut:
|
||||||
warn_about_allocs bool // -warn-about-allocs warngs about every single allocation, e.g. 'hi $name'. Mostly for low level development where manual memory management is used.
|
warn_about_allocs bool // -warn-about-allocs warngs about every single allocation, e.g. 'hi $name'. Mostly for low level development where manual memory management is used.
|
||||||
// game prototyping flags:
|
// game prototyping flags:
|
||||||
div_by_zero_is_zero bool // -div-by-zero-is-zero makes so `x / 0 == 0`, i.e. eliminates the division by zero panics/segfaults
|
div_by_zero_is_zero bool // -div-by-zero-is-zero makes so `x / 0 == 0`, i.e. eliminates the division by zero panics/segfaults
|
||||||
// temp
|
|
||||||
// use_64_int bool
|
|
||||||
// forwards compatibility settings:
|
// forwards compatibility settings:
|
||||||
relaxed_gcc14 bool = true // turn on the generated pragmas, that make gcc versions > 14 a lot less pedantic. The default is to have those pragmas in the generated C output, so that gcc-14 can be used on Arch etc.
|
relaxed_gcc14 bool = true // turn on the generated pragmas, that make gcc versions > 14 a lot less pedantic. The default is to have those pragmas in the generated C output, so that gcc-14 can be used on Arch etc.
|
||||||
//
|
//
|
||||||
|
@ -424,9 +422,6 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
|
||||||
'-progress' {
|
'-progress' {
|
||||||
// processed by testing tools in cmd/tools/modules/testing/common.v
|
// processed by testing tools in cmd/tools/modules/testing/common.v
|
||||||
}
|
}
|
||||||
//'-i64' {
|
|
||||||
// res.use_64_int = true
|
|
||||||
//}
|
|
||||||
'-Wimpure-v' {
|
'-Wimpure-v' {
|
||||||
res.warn_impure_v = true
|
res.warn_impure_v = true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue