diff --git a/transpile/service.go b/transpile/service.go index ccfee17..42cedae 100644 --- a/transpile/service.go +++ b/transpile/service.go @@ -176,6 +176,12 @@ func handleAssignStmt(as *ast.AssignStmt) string { return code } +func handleIncDecStmt(as *ast.IncDecStmt) string { + code := handleExpr(as.X) + code += as.Tok.String() + return code +} + func handleAssignStmtExpr(e []ast.Expr) string { ops := make([]string, 0) code := "" @@ -505,6 +511,11 @@ func handleStmt(stmt ast.Stmt, standaloneAssignment bool) string { if !standaloneAssignment { code += ";" } + case *ast.IncDecStmt: + code += handleIncDecStmt(s) + if !standaloneAssignment { + code += ";" + } case *ast.BranchStmt: code += handleBranchStmt(s) case *ast.CaseClause: diff --git a/transpile/service_test.go b/transpile/service_test.go index 601ceea..a4b2fea 100644 --- a/transpile/service_test.go +++ b/transpile/service_test.go @@ -835,6 +835,49 @@ var _ = Describe("Go Translator", func() { ` Compare(source, expected) }) + It("for i=0; i<10; i++", func() { + source := `package test + func Setup() {} + func Loop() { + var i int + for i=0; i<10; i++ { + i = i + } + } + ` + expected := ` + void setup(); + void loop(); + + void setup() {} + void loop() { + int i; + for (i=0; i<10; i++) { + i = i; + } + } + ` + Compare(source, expected) + }) + }) + Describe("Математика", func() { + It("i++", func() { + source := `package test + func Loop() { + var i int + i++ + } + ` + expected := ` + void loop(); + + void loop() { + int i; + i++; + } + ` + Compare(source, expected) + }) }) })