Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

map more go types to v types, and update several tests #122

Merged
merged 1 commit into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions array_map.v
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ fn (mut app App) array_init(c CompositeLit) {
} else {
// [1,2,3]
app.gen('[')
elt_name := go2v_type(c.typ.elt.name)
for i, elt in c.elts {
elt_name := go2v_type(c.typ.elt.name)
if i == 0 && is_fixed && elt_name != '' && elt_name != 'string' && elt_name != 'int' {
if i == 0 && elt_name != '' && elt_name != 'string' && elt_name != 'int'
&& !elt_name.starts_with_capital() {
// specify type in the first element
// [u8(1), 2, 3]
app.gen('${elt_name}(')
Expand All @@ -39,7 +40,6 @@ fn (mut app App) array_init(c CompositeLit) {
}
}
if have_len {
elt_name := go2v_type(c.typ.elt.name)
diff := len_val.int() - c.elts.len
if diff > 0 {
for _ in 0 .. diff {
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion untested/array_type/array_type.vv → test/array_type.vv
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module main

struct Ok {}
struct Ok {
}

fn main() {
mut a := [u8(1), 2, 3]
Expand Down
6 changes: 6 additions & 0 deletions tests/fn_call_chained/fn_call_chained.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module html

fn abc() {
mut actual := a.token()
.string()
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module main

pub fn custom() {}

fn main() {
custom()
}

pub fn custom() {
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module main

fn abc(a int, b []string, c Ok) {
}

struct Ok {
mut:
pub mut:
a int
b []string
}

fn abc(a int, b []string, c Ok) {}
File renamed without changes.
4 changes: 4 additions & 0 deletions tests/fn_empty/fn_empty.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module main

fn main() {
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
module main

fn abc(a int, b []string, c rune) (int, string, []int) {
mut ok := 0
mut err := ''
mut t := []int{}
}
9 changes: 9 additions & 0 deletions tests/method_embedded/method_embedded.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module main

fn (a Abc) ok(d int, b []string, c rune) string {
}

struct Abc {
pub mut:
a int
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 0 additions & 5 deletions untested/fn_call_chained/fn_call_chained.vv

This file was deleted.

28 changes: 14 additions & 14 deletions untested/fn_complex/fn_complex.vv
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
module main

struct Bcd {
mut:
b int
// func (t Test) Ouuu(abc string, ofk []int, c Test) (int, string) {
// fmt.Println("hey")
// }
pub fn (mut a Abc) ok(d int, b []Bcd, c rune) (int, []Efg, rune) {
mut e := 0
mut f := []Efg{}
mut h := `\x00`
}

struct Abc {
mut:
pub mut:
a int
}

struct Efg {
mut:
e int
struct Bcd {
pub mut:
b int
}

// func (t Test) Ouuu(abc string, ofk []int, c Test) (int, string) {
// fmt.Println(\"hey\")
// }
pub fn (mut a Abc) ok(d int, b []Bcd, c rune) (int, []Efg, rune) {
mut e := 0
mut f := []Efg{}
mut h := `\x00`
struct Efg {
pub mut:
e int
}
3 changes: 0 additions & 3 deletions untested/fn_empty/fn_empty.vv

This file was deleted.

3 changes: 1 addition & 2 deletions untested/fn_return_named/fn_return_named.vv
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module main

fn foo() int {
mut im := 0
im = 123
im := 123
return im
}
8 changes: 0 additions & 8 deletions untested/method_embedded/method_embedded.vv

This file was deleted.

30 changes: 30 additions & 0 deletions util.v
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,36 @@ fn go2v_type(typ string) string {
'byte' {
return 'u8'
}
'int8' {
return 'i8'
}
'int16' {
return 'i16'
}
'int32' {
return 'i32'
}
'int64' {
return 'i64'
}
'uint' {
return 'u32'
}
'uint8' {
return 'u8'
}
'uint16' {
return 'u16'
}
'uint32' {
return 'u32'
}
'uint64' {
return 'u64'
}
'float32' {
return 'f32'
}
'float64' {
return 'f64'
}
Expand Down
Loading