diff --git a/cogo/cogo.go b/cogo/cogo.go index 8d1b6cf..60e5a3f 100755 --- a/cogo/cogo.go +++ b/cogo/cogo.go @@ -23,6 +23,3 @@ func (c *Coroutine[InT, OutT]) Tick() (out OutT, done bool) { func (c *Coroutine[InT, OutT]) Yield(out OutT) { } - -func (c *Coroutine[InT, OutT]) End() { -} diff --git a/inliner/main.go b/inliner/main.go index f33beb2..22cd9e7 100755 --- a/inliner/main.go +++ b/inliner/main.go @@ -165,40 +165,32 @@ func (p *processor) processDeclNode(c *astutil.Cursor) bool { lastCaseEndBodyListIndex = i - } else if cogoFuncSelExpr.Sel.Name == "End" { - - // Add everything from the last begin/yield until this yield into a case - stmtsSinceLastCogo := funcDecl.Body.List[lastCaseEndBodyListIndex+1 : i] - stmtsAfterEnd := funcDecl.Body.List[i+1:] - - caseStmts := make([]ast.Stmt, 0, len(stmtsSinceLastCogo)+len(stmtsAfterEnd)+1) - caseStmts = append(caseStmts, stmtsSinceLastCogo...) - caseStmts = append(caseStmts, - &ast.AssignStmt{ - Lhs: []ast.Expr{ast.NewIdent(coroutineParamName + ".State")}, - Tok: token.ASSIGN, - Rhs: []ast.Expr{ast.NewIdent("-1")}, - }, - ) - caseStmts = append(caseStmts, stmtsAfterEnd...) - - switchStmt.Body.List = append(switchStmt.Body.List, - getCaseWithStmts( - []ast.Expr{ast.NewIdent(fmt.Sprint(len(switchStmt.Body.List)))}, - caseStmts, - ), - ) - - lastCaseEndBodyListIndex = i } } + // Add everything after the last yield in a separate case + stmtsToEndOfFunc := funcDecl.Body.List[lastCaseEndBodyListIndex+1:] + + caseStmts := make([]ast.Stmt, 0, len(stmtsToEndOfFunc)+1) + caseStmts = append(caseStmts, + &ast.AssignStmt{ + Lhs: []ast.Expr{ast.NewIdent(coroutineParamName + ".State")}, + Tok: token.ASSIGN, + Rhs: []ast.Expr{ast.NewIdent("-1")}, + }, + ) + caseStmts = append(caseStmts, stmtsToEndOfFunc...) + + switchStmt.Body.List = append(switchStmt.Body.List, + getCaseWithStmts( + []ast.Expr{ast.NewIdent(fmt.Sprint(len(switchStmt.Body.List)))}, + caseStmts, + ), + ) + + // Apply changes funcDecl.Body.List = funcDecl.Body.List[:beginBodyListIndex] funcDecl.Body.List = append(funcDecl.Body.List, - // &ast.LabeledStmt{ - // Label: ast.NewIdent(cogoSwitchLbl), - // Stmt: switchStmt, - // }, switchStmt, ) return true diff --git a/main.go b/main.go index 61bfcf4..76c3f86 100755 --- a/main.go +++ b/main.go @@ -30,28 +30,6 @@ func test(c *cogo.Coroutine[int, int]) (out int) { c.Yield(4) println("Tick before end") - c.End() - - // switch c.State { - // case 0: - // println("Tick 0") - // c.State++ - // return 1, false - // case 1: - // println("Tick 1") - // c.State++ - // return 2, false - // case 2: - // println("Tick 2") - // c.State++ - // return 3, false - // case 3: - // println("Tick 3") - // c.State++ - // return 4, false - // default: - // return out, true - // } return out }