Transpile `argc` and `argv` to `AssignStmt`s
@@ -149,12 +149,10 @@ func transpileFunctionDecl(n *ast.FunctionDecl, p *program.Program) error {
prependStmtsInMain = append(
prependStmtsInMain,
- &goast.ExprStmt{
- X: util.NewBinaryExpr(
- fieldList.List[0].Names[0],
- token.DEFINE,
- util.NewCallExpr("len", util.NewIdent("os.Args")),
- ),
+ &goast.AssignStmt{
+ Lhs: []goast.Expr{fieldList.List[0].Names[0]},
+ Tok: token.DEFINE,
+ Rhs: []goast.Expr{util.NewCallExpr("len", util.NewTypeIdent("os.Args"))},
},
)
}
@@ -162,39 +160,30 @@ func transpileFunctionDecl(n *ast.FunctionDecl, p *program.Program) error {
if len(fieldList.List) > 1 {
prependStmtsInMain = append(
prependStmtsInMain,
- &goast.ExprStmt{
- X: util.NewBinaryExpr(
- fieldList.List[1].Names[0],
- token.DEFINE,
-
- // We must use goast.NewIdent here instead of
- // util.NewTypeIdent because of the initialisation
- // with "{}".
- goast.NewIdent("[][]byte{}"),
- ),
+ &goast.AssignStmt{
+ Lhs: []goast.Expr{fieldList.List[1].Names[0]},
+ Tok: token.DEFINE,
+ Rhs: []goast.Expr{&goast.CompositeLit{Type: util.NewTypeIdent("[][]byte")}},
},
&goast.RangeStmt{
Key: util.NewIdent("_"),
Value: util.NewIdent("argvSingle"),
Tok: token.DEFINE,
- X: util.NewIdent("os.Args"),
+ X: util.NewTypeIdent("os.Args"),
Body: &goast.BlockStmt{
List: []goast.Stmt{
- &goast.ExprStmt{
- X: util.NewBinaryExpr(
- fieldList.List[1].Names[0],
- token.ASSIGN,
- util.NewCallExpr(
+ &goast.AssignStmt{
+ Lhs: []goast.Expr{fieldList.List[1].Names[0]},
+ Tok: token.ASSIGN,
+ Rhs: []goast.Expr{util.NewCallExpr(
"append",
fieldList.List[1].Names[0],
util.NewCallExpr("[]byte", util.NewIdent("argvSingle")),
- ),
- ),
- },
+ )},
},
},
},
- )
+ })
}
// Prepend statements for main().
