Skip to content

Commit

Permalink
fix map types -> v types (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
JalonSolov authored Aug 26, 2024
1 parent eeed915 commit 23dc2ac
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
43 changes: 30 additions & 13 deletions assign_stmt.v
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,37 @@ fn (mut app App) gen_append(args []Expr) {

for i := 1; i < args.len; i++ {
arg_i := args[i]
if i == 1 {
app.gen('[')
if arg_i is BasicLit {
app.gen('${go2v_type(arg_i.kind)}(')
match arg_i {
BasicLit {
v_kind := go2v_type(arg_i.kind.to_lower())
needs_cast := v_kind != 'int'
if i == 1 {
app.gen('[')
if needs_cast {
app.gen('${go2v_type(v_kind)}(')
}
}
app.expr(arg_i)
if i == 1 && needs_cast {
app.gen(')')
}
if i < args.len - 1 {
app.gen(',')
} else if i == args.len - 1 {
app.gen(']')
}
}
else {
if i == 1 {
app.gen('[')
}
app.expr(arg_i)
if i < args.len - 1 {
app.gen(',')
} else if i == args.len - 1 {
app.gen(']')
}
}
}
app.expr(arg_i)
if i == 1 && arg_i is BasicLit {
app.gen(')')
}
if i < args.len - 1 {
app.gen(',')
} else if i == args.len - 1 {
app.gen(']')
}
}
app.genln('')
Expand Down
3 changes: 1 addition & 2 deletions expr.v
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ fn (mut app App) key_value_expr(expr KeyValueExpr) {
app.gen(': ')
}
app.expr(expr.value)
app.genln('')
}

fn (mut app App) array_type(node ArrayType) {
Expand All @@ -156,5 +155,5 @@ fn (mut app App) star_expr(node StarExpr) {

fn (mut app App) ident(node Ident) {
// app.gen('f=${app.force_upper}')
app.gen(app.go2v_ident(node.name))
app.gen(go2v_type(app.go2v_ident(node.name)))
}
3 changes: 1 addition & 2 deletions tests/var_struct_fields/var_struct_fields.vv
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ struct Ok {
pub mut:
a isize
b string
m map[string]int
m map[string]isize
}

fn main() {
mut long := Ok{
a: 1

b: 'hello'
}
mut short := Ok{3, 'hello'}
Expand Down
2 changes: 1 addition & 1 deletion util.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module main

fn go2v_type(typ string) string {
match typ.to_lower() {
match typ {
'byte' {
return 'u8'
}
Expand Down

0 comments on commit 23dc2ac

Please sign in to comment.