diff --git a/array_map.v b/array_map.v index 0f90a06..1915dc4 100644 --- a/array_map.v +++ b/array_map.v @@ -1,60 +1,83 @@ -module main +// Copyright (c) 2024 Alexander Medvednikov. All rights reserved. +// Use of this source code is governed by a GPL license that can be found in the LICENSE file. fn (mut app App) array_init(c CompositeLit) { - mut have_len := false - mut len_val := '' - mut is_fixed := false - if c.typ.len is BasicLit { - is_fixed = c.typ.len.value != '' - have_len = c.typ.len.value != '' - len_val = c.typ.len.value - } else if c.typ.len is Ellipsis { - is_fixed = true - } - // No elements, just `[]bool{}` (specify type) - if c.elts.len == 0 { - app.gen('[') - if have_len { - app.gen(len_val) - } - app.gen(']') - 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.starts_with_capital() { - // specify type in the first element - // [u8(1), 2, 3] - app.gen('${elt_name}(') - app.expr(elt) - app.gen(')') - } else { - app.expr(elt) + typ := c.typ + match typ { + ArrayType { + mut have_len := false + mut len_val := '' + mut is_fixed := false + if typ.len is BasicLit { + is_fixed = typ.len.value != '' + have_len = typ.len.value != '' + len_val = typ.len.value + } else if typ.len is Ellipsis { + is_fixed = true } - if i < c.elts.len - 1 { - app.gen(',') + mut elt_name := '' + match typ.elt { + Ident { + elt_name = go2v_type(typ.elt.name) + } + StarExpr { + x := typ.elt.x + match x { + Ident { + elt_name = go2v_type(x.name) + } + else {} + } + } + else {} } - } - if have_len { - diff := len_val.int() - c.elts.len - if diff > 0 { - for _ in 0 .. diff { - app.gen(',') - match elt_name { - 'isize', 'usize' { app.gen('0') } - 'string' { app.gen("''") } - else { app.gen('unknown element type??') } + // No elements, just `[]bool{}` (specify type) + if c.elts.len == 0 { + app.gen('[') + if have_len { + app.gen(len_val) + } + app.gen(']') + app.gen(elt_name) + app.gen('{}') + } else { + // [1,2,3] + app.gen('[') + for i, elt in c.elts { + 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}(') + app.expr(elt) + app.gen(')') + } else { + app.expr(elt) + } + if i < c.elts.len - 1 { + app.gen(',') } } + if have_len { + diff := len_val.int() - c.elts.len + if diff > 0 { + for _ in 0 .. diff { + app.gen(',') + match elt_name { + 'isize', 'usize' { app.gen('0') } + 'string' { app.gen("''") } + else { app.gen('unknown element type??') } + } + } + } + } + app.gen(']') + if is_fixed { + app.gen('!') + } } } - app.gen(']') - if is_fixed { - app.gen('!') - } + else {} } } diff --git a/assign_stmt.v b/assign_stmt.v index a256435..370b841 100644 --- a/assign_stmt.v +++ b/assign_stmt.v @@ -1,5 +1,7 @@ +// Copyright (c) 2024 Alexander Medvednikov. All rights reserved. +// Use of this source code is governed by a GPL license that can be found in the LICENSE file. + fn (mut app App) assign_stmt(assign AssignStmt, no_mut bool) { - // app.genln('//assign_stmt') for l_idx, lhs_expr in assign.lhs { if l_idx == 0 { match lhs_expr { @@ -26,10 +28,29 @@ fn (mut app App) assign_stmt(assign AssignStmt, no_mut bool) { // app.gen(assign.tok) for r_idx, rhs_expr in assign.rhs { + mut needs_close_paren := false + if r_idx == 0 { + rhs := rhs_expr + match rhs { + BasicLit { + if rhs.kind.is_upper() { + v_kind := go2v_type(rhs.kind.to_lower()) + if v_kind != 'int' && v_kind != 'string' { + app.gen('${v_kind}(') + needs_close_paren = true + } + } + } + else {} + } + } if r_idx > 0 { app.gen(', ') } app.expr(rhs_expr) + if needs_close_paren { + app.gen(')') + } } app.genln('') } diff --git a/ast.v b/ast.v index d3817a7..b4969c3 100644 --- a/ast.v +++ b/ast.v @@ -3,6 +3,8 @@ import json import os +type Decls = FuncDecl | GenDecl + type Expr = InvalidExpr | ArrayType | BasicLit @@ -14,10 +16,10 @@ type Expr = InvalidExpr | Ident | IndexExpr | KeyValueExpr + | MapType | ParenExpr | SelectorExpr | StarExpr - | TypeOrIdent | UnaryExpr type Stmt = AssignStmt @@ -36,6 +38,8 @@ type Stmt = AssignStmt struct InvalidExpr {} +type Specs = ImportSpec | TypeSpec | ValueSpec + type Type = StructType | ArrayType | MapType @@ -46,8 +50,8 @@ type Type = StructType | SelectorExpr struct GoFile { - name Ident @[json: 'Name'] - decls []Decl @[json: 'Decls'] + package_name Ident @[json: 'Name'] + decls []Decls @[json: 'Decls'] } struct Doc { @@ -56,33 +60,39 @@ struct Doc { } @[json: 'List'] } -struct Decl { +struct FuncDecl { node_type string @[json: '_type'] - specs []Spec @[json: 'Specs'] - decls []Decl @[json: 'Decls'] + doc Doc @[json: 'Doc'] + recv FieldList @[json: 'Recv'] name Ident @[json: 'Name'] typ FuncType @[json: 'Type'] - recv FieldList @[json: 'Recv'] body BlockStmt @[json: 'Body'] - tok string @[json: 'Tok'] - doc Doc @[json: 'Doc'] } -struct Spec { +struct GenDecl { node_type string @[json: '_type'] - name Ident @[json: 'Name'] - names []Ident @[json: 'Names'] - values []Expr @[json: 'Values'] - // typ Type @[json: 'Type'] - typ Type @[json: 'Type'] - args []Expr @[json: 'Args'] - path BasicLit @[json: 'Path'] + doc Doc @[json: 'Doc'] + tok string @[json: 'Tok'] + specs []Specs @[json: 'Specs'] +} + +struct ImportSpec { + node_type string @[json: '_type'] + name Ident @[json: 'Name'] + path BasicLit @[json: 'Path'] +} + +struct TypeSpec { + node_type string @[json: '_type'] + name Ident @[json: 'Name'] + params FieldList @[json: 'TypeParams'] + typ Type @[json: 'Type'] } struct ArrayType { node_type string @[json: '_type'] - // elt Ident @[json: 'Elt'] - elt Expr @[json: 'Elt'] + len Expr @[json: 'Len'] + elt Expr @[json: 'Elt'] } struct MapType { @@ -103,19 +113,15 @@ struct FuncType { } struct ValueSpec { - node_type string @[json: '_type'] - - names []Ident @[json: 'Names'] - typ TypeOrIdent @[json: 'Type'] - values []Expr @[json: 'Values'] + node_type string @[json: '_type'] + names []Ident @[json: 'Names'] + typ Type @[json: 'Type'] + values []Expr @[json: 'Values'] } struct DeclStmt { - node_type string @[json: '_type'] - decl struct { - tok string @[json: 'Tok'] - specs []ValueSpec @[json: 'Specs'] - } @[json: 'Decl'] + node_type string @[json: '_type'] + decl Decls @[json: 'Decl'] } struct BlockStmt { @@ -149,8 +155,7 @@ struct ForStmt { init AssignStmt @[json: 'Init'] cond Expr @[json: 'Cond'] post Stmt @[json: 'Post'] - - body BlockStmt @[json: 'Body'] + body BlockStmt @[json: 'Body'] } struct ExprStmt { @@ -161,14 +166,14 @@ struct ExprStmt { struct AssignStmt { node_type string @[json: '_type'] lhs []Expr @[json: 'Lhs'] - - rhs []Expr @[json: 'Rhs'] - tok string @[json: 'Tok'] + rhs []Expr @[json: 'Rhs'] + tok string @[json: 'Tok'] } struct StructType { - node_type string @[json: '_type'] - fields FieldList @[json: 'Fields'] + node_type string @[json: '_type'] + fields FieldList @[json: 'Fields'] + incomplete bool @[json: 'Incomplete'] } struct InterfaceType { @@ -183,9 +188,8 @@ struct FieldList { struct Field { node_type string @[json: '_type'] names []Ident @[json: 'Names'] - // typ TypeOrIdent @[json: 'Type'] - typ Type @[json: 'Type'] - doc Doc @[json: 'Doc'] + typ Type @[json: 'Type'] + doc Doc @[json: 'Doc'] } struct Ident { @@ -193,13 +197,6 @@ struct Ident { name string @[json: 'Name'] } -struct TypeOrIdent { - node_type string @[json: '_type'] - name string @[json: 'Name'] - len Expr @[json: 'Len'] - elt Ident @[json: 'Elt'] -} - struct BasicLit { node_type string @[json: '_type'] kind string @[json: 'Kind'] @@ -218,23 +215,11 @@ struct SelectorExpr { x Expr @[json: 'X'] } -// Foo{bar:baz} -// []bool{} struct CompositeLit { - node_type string @[json: '_type'] - typ TypeOrIdent @[json: 'Type'] - elts []Expr @[json: 'Elts'] -} - -/* -struct Elt { - key struct { - name string @[json: 'Name'] - } @[json: 'Key'] - - value Expr @[json: 'Value'] + node_type string @[json: '_type'] + typ Expr @[json: 'Type'] + elts []Expr @[json: 'Elts'] } -*/ struct BinaryExpr { node_type string @[json: '_type'] @@ -250,7 +235,6 @@ struct UnaryExpr { } struct KeyValueExpr { - // key Ident @[json: 'Key'] key Expr @[json: 'Key'] value Expr @[json: 'Value'] node_type string @[json: '_type'] @@ -263,10 +247,9 @@ struct IncDecStmt { } struct IndexExpr { - x Expr @[json: 'X'] - index Expr @[json: 'Index'] - node_type string @[json: '_type'] + x Expr @[json: 'X'] + index Expr @[json: 'Index'] } // `for ... := range` loop @@ -328,10 +311,10 @@ fn (e Expr) node_type() string { Ident { return e.node_type } IndexExpr { return e.node_type } KeyValueExpr { return e.node_type } + MapType { return e.node_type } ParenExpr { return e.node_type } SelectorExpr { return e.node_type } StarExpr { return e.node_type } - TypeOrIdent { return e.node_type } UnaryExpr { return e.node_type } } return 'unknown node type' diff --git a/asty.v b/asty.v index 58bfca3..3ff659e 100644 --- a/asty.v +++ b/asty.v @@ -1,3 +1,5 @@ +// Copyright (c) 2024 Alexander Medvednikov. All rights reserved. +// Use of this source code is governed by a GPL license that can be found in the LICENSE file. import os const gopath_res = os.execute('go env GOPATH') @@ -9,7 +11,7 @@ fn ensure_asty_is_installed() ! { if _ := os.find_abs_path_of_executable(asty_executable_name) { return } - // Ensure that $GOPATH/bin is in PATH, and that asty is present, so invokin `asty` works: + // Ensure that $GOPATH/bin is in PATH, and that asty is present, so invokin `asty` works: if gopath_res.exit_code != 0 { return error('Failed to find Go. Visit https://go.dev/dl/ to see instructions, on how to install it.') } diff --git a/expr.v b/expr.v index 63aa89c..d220215 100644 --- a/expr.v +++ b/expr.v @@ -1,6 +1,5 @@ // Copyright (c) 2024 Alexander Medvednikov. All rights reserved. // Use of this source code is governed by a GPL license that can be found in the LICENSE file. -module main fn (mut app App) expr(expr Expr) { match expr { @@ -22,9 +21,6 @@ fn (mut app App) expr(expr Expr) { SelectorExpr { app.selector_expr(expr) } - TypeOrIdent { - type_or_ident(expr) - } CompositeLit { app.composite_lit(expr) } @@ -34,6 +30,9 @@ fn (mut app App) expr(expr Expr) { IndexExpr { app.index_expr(expr) } + MapType { + app.map_type(expr) + } ParenExpr { app.paren_expr(expr) } @@ -50,21 +49,14 @@ fn (mut app App) expr(expr Expr) { app.func_lit(expr) } Ellipsis {} - // else { - // app.gen('/* UNHANDLED EXPR ${expr.node_type} */') - //} } } fn (mut app App) basic_lit(l BasicLit) { if l.kind == 'CHAR' { - // app.gen(l.value.replace("'", '`')) - // app.gen(quoted_lit(l.value), "'", '`') app.gen(quoted_lit(l.value, '`')) } else if l.kind == 'STRING' { - // app.gen(quoted_lit(l.value), '`', "'") app.gen(quoted_lit(l.value, "'")) - // app.gen(l.value.replace('`', "'")) } else { app.gen(l.value) } diff --git a/fn_decl.v b/fn_decl.v index d7806f5..929d907 100644 --- a/fn_decl.v +++ b/fn_decl.v @@ -1,6 +1,7 @@ // Copyright (c) 2024 Alexander Medvednikov. All rights reserved. // Use of this source code is governed by a GPL license that can be found in the LICENSE file. -fn (mut app App) func_decl(decl Decl) { + +fn (mut app App) func_decl(decl FuncDecl) { app.comments(decl.doc) method_name := decl.name.name.to_lower() // Capital? Then it's public in Go diff --git a/main.v b/main.v index 25eb585..195f858 100644 --- a/main.v +++ b/main.v @@ -26,23 +26,15 @@ fn (mut app App) gen(s string) { } fn (mut app App) generate_v_code(go_file GoFile) string { - app.genln('module ${go_file.name.name}\n') + app.genln('module ${go_file.package_name.name}\n') for decl in go_file.decls { - match decl.node_type { - // match decl { - //.gen_decl { - // GenDecl { - 'GenDecl' { - app.gen_decl(decl) - } - // FuncDecl { - 'FuncDecl' { - //.func_decl { + match decl { + FuncDecl { app.func_decl(decl) } - else { - app.genln('// UNHANDLED decl ${decl}') + GenDecl { + app.gen_decl(decl) } } } @@ -88,10 +80,6 @@ fn (mut app App) typ(t Type) { app.force_upper = false } -fn type_or_ident(typ TypeOrIdent) string { - return if typ.elt.name != '' { '[]${typ.elt.name}' } else { typ.name } -} - fn generate_ast_for_go_file(go_file_path string) string { output_file := go_file_path + '.json' diff --git a/stmt.v b/stmt.v index 0d746a5..d8796fa 100644 --- a/stmt.v +++ b/stmt.v @@ -55,10 +55,6 @@ fn (mut app App) stmt(stmt Stmt) { app.genln('\t// unhandled in stmt: ${stmt}') } // Add additional handlers as needed } - if stmt.node_type == 'GenDecl' { //.gen_decl { - app.gen_decl_stmt(stmt) - return - } } fn (mut app App) expr_stmt(stmt ExprStmt) { @@ -149,19 +145,40 @@ fn (mut app App) inc_dec_stmt(i IncDecStmt) { } fn (mut app App) decl_stmt(d DeclStmt) { - // app.gen(d.str()) - if d.decl.tok == 'var' { - app.gen('mut ') - app.gen(d.decl.specs[0].names[0].name) - app.gen(' := ') - typ_name := go2v_type(d.decl.specs[0].typ.name) - if typ_name != '' { - app.gen(typ_name) - app.gen('(') - } - app.expr(d.decl.specs[0].values[0]) - if typ_name != '' { - app.gen(')') + match d.decl { + GenDecl { + if d.decl.tok == 'var' { + for spec in d.decl.specs { + match spec { + ValueSpec { + app.gen('mut ') + app.gen(spec.names[0].name) + app.gen(' := ') + mut kind := 'int' + value := spec.values[0] + match value { + BasicLit { + kind = go2v_type(value.kind.to_lower()) + if kind != 'int' { + app.gen('${kind}(') + } + } + else {} + } + app.expr(spec.values[0]) + if kind != 'int' { + app.gen(')') + } + } + else { + app.gen('// UNHANDLED DeclStmt-GenDecl spec') + } + } + } + } + } + else { + app.gen('// UNHANDLED DeclStmt') } } app.genln('') diff --git a/struct.v b/struct.v index 8e7c32f..51be20f 100644 --- a/struct.v +++ b/struct.v @@ -1,64 +1,53 @@ // Copyright (c) 2024 Alexander Medvednikov. All rights reserved. // Use of this source code is governed by a GPL license that can be found in the LICENSE file. -fn (mut app App) gen_decl_stmt(stmt Stmt) { - // for decl in stmt.decls { - // app.gen_decl(decl) - //} -} - -fn (mut app App) gen_decl(decl Decl) { +fn (mut app App) gen_decl(decl GenDecl) { + mut needs_closer := false app.comments(decl.doc) - if decl.tok == 'const' { - // app.genln('//constb') - app.const_block(decl) - return - } - // is_enum_decl := decl.specs[0].node_type == 'TypeSpec' && decl. for spec in decl.specs { - if spec.node_type == 'TypeSpec' { - // println('TYPE NAME=${spec.name.name}') - // println(spec.typ) - // println(spec.typ.node_type) - match spec.typ { - InterfaceType { - app.interface_decl(spec) + match spec { + ImportSpec { + app.import_spec(spec) + } + TypeSpec { + match spec.typ { + InterfaceType { + app.interface_decl(spec.name.name, spec.typ) + } + StructType { + app.struct_decl(spec.name.name, spec.typ) + } + else { + app.type_decl(spec) + } } - StructType { - app.struct_decl(spec) + } + ValueSpec { + if spec.typ is Ident { + needs_closer = true } - else { - app.type_decl(spec) + match decl.tok { + 'var' { + app.global_decl(spec) + } + else { + app.const_decl(spec) + } } } - } else if spec.node_type == 'ImportSpec' && spec.path.value != '' { - app.import_spec(spec) - } else if spec.node_type == 'ValueSpec' { - if decl.tok == 'var' { - app.global_decl(spec) - } else { - app.const_decl(spec) - } } } + if needs_closer { + app.genln('}') + } } -fn (mut app App) type_decl(spec Spec) { +fn (mut app App) type_decl(spec TypeSpec) { // Remember the type name for the upcoming const (enum) handler app.type_decl_name = spec.name.name } -fn (mut app App) const_block(decl Decl) { - for spec in decl.specs { - app.const_decl(spec) - } - if decl.specs.len > 1 && app.is_enum_decl { - app.genln('}') - app.is_enum_decl = false - } -} - -fn (mut app App) global_decl(spec Spec) { +fn (mut app App) global_decl(spec ValueSpec) { for name in spec.names { app.gen('__global ${name.name} ') app.typ(spec.typ) @@ -66,25 +55,17 @@ fn (mut app App) global_decl(spec Spec) { } } -fn (mut app App) const_decl(spec Spec) { +fn (mut app App) const_decl(spec ValueSpec) { // Handle iota (V enuma) if spec.values.len > 0 { first_val := spec.values[0] if first_val is Ident { if first_val.name == 'iota' { - //} - // if spec.values[0].name == 'iota' { app.is_enum_decl = true app.genln('enum ${app.type_decl_name} {') - // for i, name in spec.names { - // app.genln(app.go2v_ident(name.name)) - //} - // app.genln('}') - // return } } } - // app.genln('// const') for i, name in spec.names { if !app.is_enum_decl && name.name.starts_with_capital() { app.gen('pub ') @@ -105,7 +86,7 @@ fn (mut app App) const_decl(spec Spec) { } } -fn (mut app App) import_spec(spec Spec) { +fn (mut app App) import_spec(spec ImportSpec) { name := spec.path.value.replace('"', '').replace('/', '.') // Skip modules that don't exist in V (fmt, strings etc) if name in unexisting_modules { @@ -114,19 +95,14 @@ fn (mut app App) import_spec(spec Spec) { app.genln('import ${name}') } -fn (mut app App) struct_decl(spec Spec) { - struct_name := spec.name.name +fn (mut app App) struct_decl(struct_name string, spec StructType) { app.genln('struct ${struct_name} {') - struct_type := spec.typ as StructType - if struct_type.fields.list.len > 0 { + if spec.fields.list.len > 0 { app.genln('pub mut:') } - for field in struct_type.fields.list { - // type_name := type_or_ident(field.typ) + for field in spec.fields.list { for n in field.names { - // app.genln('\t${go2v_ident(n.name)} ${go2v_type(type_name)}') app.gen('\t') - // app.force_upper = true app.gen(app.go2v_ident(n.name)) app.gen(' ') app.force_upper = true @@ -140,18 +116,12 @@ fn (mut app App) struct_decl(spec Spec) { app.genln('}\n') } -fn (mut app App) interface_decl(spec Spec) { - name := spec.name.name - app.genln('interface ${name} {') - i_type := spec.typ as InterfaceType - // println('TTT ${i_type}') - for field in i_type.methods.list { - // type_name := type_or_ident(field.typ) +fn (mut app App) interface_decl(interface_name string, spec InterfaceType) { + app.genln('interface ${interface_name} {') + for field in spec.methods.list { app.comments(field.doc) for n in field.names { - // app.genln('\t${go2v_ident(n.name)} ${go2v_type(type_name)}') app.gen('\t') - // app.force_upper = true app.gen(app.go2v_ident(n.name)) app.force_upper = true app.typ(field.typ) @@ -162,15 +132,18 @@ fn (mut app App) interface_decl(spec Spec) { } fn (mut app App) composite_lit(c CompositeLit) { - if c.typ.name != '' { - app.struct_init(c) - return - } - match c.typ.node_type { - 'ArrayType' { + // if c.typ.name != '' { + // app.struct_init(c) + // return + // } + match c.typ { + ArrayType { app.array_init(c) } - 'MapType' { + Ident { + app.struct_init(c) + } + MapType { app.map_init(c) } else { @@ -180,10 +153,16 @@ fn (mut app App) composite_lit(c CompositeLit) { } fn (mut app App) struct_init(c CompositeLit) { - app.genln('${c.typ.name}{') - for elt in c.elts { - app.expr(elt) - app.genln('') + typ := c.typ + match typ { + Ident { + app.genln('${typ.name}{') + for elt in c.elts { + app.expr(elt) + app.genln('') + } + app.gen('}') + } + else {} } - app.gen('}') } diff --git a/tests/block/block.vv b/tests/block/block.vv index 1773c17..392b03f 100644 --- a/tests/block/block.vv +++ b/tests/block/block.vv @@ -1,8 +1,8 @@ module main fn main() { - mut i := 0 + mut i := isize(0) { - mut j := 1 + mut j := isize(1) } } diff --git a/tests/case/case.vv b/tests/case/case.vv index e91259e..c665eb1 100644 --- a/tests/case/case.vv +++ b/tests/case/case.vv @@ -9,7 +9,7 @@ const lowercase = 0 fn ok() { mut er_fd_fs324 := ['a', 'b', 'c', 'd'] - mut id_weird := 0 + mut id_weird := isize(0) println(er_fd_fs324[id_weird]) println(er_fd_fs324) } diff --git a/tests/for_c_style_inc/for_c_style_inc.vv b/tests/for_c_style_inc/for_c_style_inc.vv index 13a9b3f..1abc147 100644 --- a/tests/for_c_style_inc/for_c_style_inc.vv +++ b/tests/for_c_style_inc/for_c_style_inc.vv @@ -1,7 +1,7 @@ module main fn main() { - for i := 1; i < 5; i++ { + for i := isize(1); i < 5; i++ { println('Hi buddy') } } diff --git a/tests/for_while/for_while.vv b/tests/for_while/for_while.vv index ba1c827..45ef35e 100644 --- a/tests/for_while/for_while.vv +++ b/tests/for_while/for_while.vv @@ -1,8 +1,8 @@ module main fn main() { - mut n := 1 + mut n := isize(1) for n < 5 { - n *= 2 + n *= isize(2) } } diff --git a/tests/if_init/if_init.vv b/tests/if_init/if_init.vv index 7e6d0dc..255b379 100644 --- a/tests/if_init/if_init.vv +++ b/tests/if_init/if_init.vv @@ -1,8 +1,8 @@ module main fn main() { - mut abc := 123 - mut a := 1 + mut abc := isize(123) + mut a := isize(1) if abc != a { println('abc') } diff --git a/tests/if_nested/if_nested.vv b/tests/if_nested/if_nested.vv index bbb234c..a6380e5 100644 --- a/tests/if_nested/if_nested.vv +++ b/tests/if_nested/if_nested.vv @@ -1,11 +1,11 @@ module main fn main() { - mut z := 123 + mut z := isize(123) if z == 0 { println('ok') } else { - mut x := 456 + mut x := isize(456) if x == 0 { println(x) } diff --git a/tests/match/match.vv b/tests/match/match.vv index 73f79cc..aeea3cb 100644 --- a/tests/match/match.vv +++ b/tests/match/match.vv @@ -2,7 +2,7 @@ module main fn main() { print("You're") - mut age := 27 + mut age := isize(27) match age { 18 { println(' of age') diff --git a/tests/struct_simple/struct_simple.vv b/tests/struct_simple/struct_simple.vv index 90f3a12..04e5521 100644 --- a/tests/struct_simple/struct_simple.vv +++ b/tests/struct_simple/struct_simple.vv @@ -10,5 +10,5 @@ fn main() { mut foo := Struct1{ a: 5 } - foo.a = 7 + foo.a = isize(7) } diff --git a/tests/var/var.vv b/tests/var/var.vv index d5b16e4..729a341 100644 --- a/tests/var/var.vv +++ b/tests/var/var.vv @@ -1,8 +1,8 @@ module main fn main() { - mut i := 42 - i = 24 - mut j := 24 - j = 42 + mut i := isize(42) + i = isize(24) + mut j := isize(24) + j = isize(42) } diff --git a/tests/var_increment/var_increment.vv b/tests/var_increment/var_increment.vv index bbc17d1..a569eda 100644 --- a/tests/var_increment/var_increment.vv +++ b/tests/var_increment/var_increment.vv @@ -7,7 +7,7 @@ pub mut: fn main() { mut ok := Ok{} - mut sum := 0 + mut sum := isize(0) sum++ ok.a++ sum-- diff --git a/tests/var_operators/var_operators.vv b/tests/var_operators/var_operators.vv index ed67e1b..b89543c 100644 --- a/tests/var_operators/var_operators.vv +++ b/tests/var_operators/var_operators.vv @@ -7,7 +7,7 @@ pub mut: fn main() { mut ok := Ok{} - mut sum := 0 - sum += 1 - ok.a /= 2 + mut sum := isize(0) + sum += isize(1) + ok.a /= isize(2) } diff --git a/tests/var_two_vals/var_two_vals.vv b/tests/var_two_vals/var_two_vals.vv index cbc7f73..87a7f08 100644 --- a/tests/var_two_vals/var_two_vals.vv +++ b/tests/var_two_vals/var_two_vals.vv @@ -5,6 +5,6 @@ fn two_fn() (isize, isize) { } fn main() { - mut a, b := 1, 2 + mut a, b := isize(1), 2 mut c, d := two_fn() } diff --git a/tests/var_underscore/var_underscore.vv b/tests/var_underscore/var_underscore.vv index c90c528..7479d69 100644 --- a/tests/var_underscore/var_underscore.vv +++ b/tests/var_underscore/var_underscore.vv @@ -1,6 +1,6 @@ module main fn main() { - _ := `a` - _ := `b` + _ := u8(`a`) + _ := u8(`b`) } diff --git a/util.v b/util.v index f5dfdcb..14813ea 100644 --- a/util.v +++ b/util.v @@ -1,12 +1,20 @@ // Copyright (c) 2024 Alexander Medvednikov. All rights reserved. // Use of this source code is governed by a GPL license that can be found in the LICENSE file. -module main fn go2v_type(typ string) string { match typ { 'byte' { return 'u8' } + 'char' { + return 'u8' + } + 'float32' { + return 'f32' + } + 'float64' { + return 'f64' + } 'int' { return 'isize' } @@ -37,12 +45,6 @@ fn go2v_type(typ string) string { 'uint64' { return 'u64' } - 'float32' { - return 'f32' - } - 'float64' { - return 'f64' - } else {} } return typ