diff --git a/array_map.v b/array_map.v index c0c5e7c..0f90a06 100644 --- a/array_map.v +++ b/array_map.v @@ -18,15 +18,14 @@ fn (mut app App) array_init(c CompositeLit) { app.gen(len_val) } app.gen(']') - app.gen(c.typ.elt.name) + app.gen(go2v_type(c.typ.elt.name)) app.gen('{}') } else { // [1,2,3] app.gen('[') elt_name := go2v_type(c.typ.elt.name) for i, elt in c.elts { - if i == 0 && elt_name != '' && elt_name != 'string' && elt_name != 'int' - && !elt_name.starts_with_capital() { + if i == 0 && elt_name != '' && elt_name != 'string' && !elt_name.starts_with_capital() { // specify type in the first element // [u8(1), 2, 3] app.gen('${elt_name}(') @@ -45,7 +44,7 @@ fn (mut app App) array_init(c CompositeLit) { for _ in 0 .. diff { app.gen(',') match elt_name { - 'int' { app.gen('0') } + 'isize', 'usize' { app.gen('0') } 'string' { app.gen("''") } else { app.gen('unknown element type??') } } diff --git a/assign_stmt.v b/assign_stmt.v index b94f7d2..702f619 100644 --- a/assign_stmt.v +++ b/assign_stmt.v @@ -46,13 +46,20 @@ fn (mut app App) gen_append(args []Expr) { } for i := 1; i < args.len; i++ { - if i == 1 && args[i] is BasicLit { + arg_i := args[i] + if i == 1 { app.gen('[') + if arg_i is BasicLit { + app.gen('${go2v_type(arg_i.kind)}(') + } + } + app.expr(arg_i) + if i == 1 && arg_i is BasicLit { + app.gen(')') } - app.expr(args[i]) if i < args.len - 1 { app.gen(',') - } else if i == args.len - 1 && args[i] is BasicLit { + } else if i == args.len - 1 { app.gen(']') } } diff --git a/expr.v b/expr.v index 6f53a20..89d0bf5 100644 --- a/expr.v +++ b/expr.v @@ -134,7 +134,7 @@ fn (mut app App) key_value_expr(expr KeyValueExpr) { fn (mut app App) array_type(node ArrayType) { if node.elt is Ident { - app.gen('[]${node.elt.name}') + app.gen('[]${go2v_type(node.elt.name)}') } else if node.elt is StarExpr { app.gen('[]') app.star_expr(node.elt) diff --git a/tests/append/append.vv b/tests/append/append.vv index de1c440..fb48c08 100644 --- a/tests/append/append.vv +++ b/tests/append/append.vv @@ -1,10 +1,10 @@ module main fn main() { - mut s := []int{} + mut s := []isize{} s << 1 - s << [2, 3, 4] - mut a := [4, 5, 6] - mut b := [1, 2, 3] + s << [isize(2), 3, 4] + mut a := [isize(4), 5, 6] + mut b := [isize(1), 2, 3] b << a } diff --git a/tests/array_fixed_size/array_fixed_size.vv b/tests/array_fixed_size/array_fixed_size.vv index 5008984..1add9ad 100644 --- a/tests/array_fixed_size/array_fixed_size.vv +++ b/tests/array_fixed_size/array_fixed_size.vv @@ -4,10 +4,10 @@ struct Ok { } fn main() { - mut full := [4, 5, 23, 55]! - mut one_missing := [4, 5, 23, 55, 0]! + mut full := [isize(4), 5, 23, 55]! + mut one_missing := [isize(4), 5, 23, 55, 0]! mut missing := ['John', 'Paul', 'George', 'Ringo', '', '']! - mut missing_empty := [2]int{} - mut abc := [1, 2, 3]! + mut missing_empty := [2]isize{} + mut abc := [isize(1), 2, 3]! mut bytes := [u8(1), 2, 3]! } diff --git a/tests/array_type/array_type.vv b/tests/array_type/array_type.vv index e516df6..a61111a 100644 --- a/tests/array_type/array_type.vv +++ b/tests/array_type/array_type.vv @@ -5,7 +5,7 @@ struct Ok { fn main() { mut a := [u8(1), 2, 3] - mut b := [1, 2, 3] + mut b := [isize(1), 2, 3] mut c := ['a', 'b', 'c'] mut d := [Ok{}, Ok{}, Ok{}] mut e := [i32(1), 2, 3] diff --git a/tests/fn/fn.vv b/tests/fn/fn.vv index 10ee821..e5f323f 100644 --- a/tests/fn/fn.vv +++ b/tests/fn/fn.vv @@ -1,4 +1,4 @@ module main -fn abc(a int, b []string, c rune) string { +fn abc(a isize, b []string, c rune) string { } diff --git a/tests/fn_embedded_struct/fn_embedded_struct.vv b/tests/fn_embedded_struct/fn_embedded_struct.vv index 3eac270..06164fb 100644 --- a/tests/fn_embedded_struct/fn_embedded_struct.vv +++ b/tests/fn_embedded_struct/fn_embedded_struct.vv @@ -1,10 +1,10 @@ module main -fn abc(a int, b []string, c Ok) { +fn abc(a isize, b []string, c Ok) { } struct Ok { pub mut: - a int + a isize b []string } diff --git a/tests/fn_pub/fn_pub.vv b/tests/fn_pub/fn_pub.vv index 2c6ee09..93b1de9 100644 --- a/tests/fn_pub/fn_pub.vv +++ b/tests/fn_pub/fn_pub.vv @@ -1,4 +1,4 @@ module main -pub fn abc(a int, b []string, c rune) string { +pub fn abc(a isize, b []string, c rune) string { } diff --git a/tests/fn_return_multiple/fn_return_multiple.vv b/tests/fn_return_multiple/fn_return_multiple.vv index 8c946cd..9da2707 100644 --- a/tests/fn_return_multiple/fn_return_multiple.vv +++ b/tests/fn_return_multiple/fn_return_multiple.vv @@ -1,4 +1,4 @@ module main -fn abc(a int, b []string, c rune) (int, string, []int) { +fn abc(a isize, b []string, c rune) (isize, string, []isize) { } diff --git a/tests/for_in/for_in.vv b/tests/for_in/for_in.vv index c1cb612..fc40581 100644 --- a/tests/for_in/for_in.vv +++ b/tests/for_in/for_in.vv @@ -12,8 +12,8 @@ fn main() { for _ in strings { println('hello') } - for i, _ in [2]int{} { - for j, _ in [2]int{} { + for i, _ in [2]isize{} { + for j, _ in [2]isize{} { println('hello2') } } diff --git a/tests/len_cap/len_cap.vv b/tests/len_cap/len_cap.vv index ac84005..62a8cbe 100644 --- a/tests/len_cap/len_cap.vv +++ b/tests/len_cap/len_cap.vv @@ -1,7 +1,7 @@ module main fn main() { - mut array := [2, 3, 5, 7, 11] + mut array := [isize(2), 3, 5, 7, 11] println(array.len) println(array.cap) } diff --git a/tests/method/method.vv b/tests/method/method.vv index 552eadc..0cb99a2 100644 --- a/tests/method/method.vv +++ b/tests/method/method.vv @@ -2,8 +2,8 @@ module main struct Abc { pub mut: - a int + a isize } -fn (a Abc) ok(d int, b []string, c rune) string { +fn (a Abc) ok(d isize, b []string, c rune) string { } diff --git a/tests/method_embedded/method_embedded.vv b/tests/method_embedded/method_embedded.vv index 647d6fa..61fafeb 100644 --- a/tests/method_embedded/method_embedded.vv +++ b/tests/method_embedded/method_embedded.vv @@ -1,9 +1,9 @@ module main -fn (a Abc) ok(d int, b []string, c rune) string { +fn (a Abc) ok(d isize, b []string, c rune) string { } struct Abc { pub mut: - a int + a isize } diff --git a/tests/struct/struct.vv b/tests/struct/struct.vv index e7d2ff5..f1679ec 100644 --- a/tests/struct/struct.vv +++ b/tests/struct/struct.vv @@ -2,6 +2,6 @@ module main struct Struct1 { pub mut: - a int + a isize b []string } diff --git a/tests/struct_simple/struct_simple.vv b/tests/struct_simple/struct_simple.vv index 2a668e0..90f3a12 100644 --- a/tests/struct_simple/struct_simple.vv +++ b/tests/struct_simple/struct_simple.vv @@ -2,7 +2,7 @@ module main struct Struct1 { pub mut: - a int + a isize b []string } diff --git a/util.v b/util.v index e1aa8c9..1ea4793 100644 --- a/util.v +++ b/util.v @@ -3,10 +3,13 @@ module main fn go2v_type(typ string) string { - match typ { + match typ.to_lower() { 'byte' { return 'u8' } + 'int' { + return 'isize' + } 'int8' { return 'i8' } @@ -20,7 +23,7 @@ fn go2v_type(typ string) string { return 'i64' } 'uint' { - return 'u32' + return 'usize' } 'uint8' { return 'u8'