}}}
(context *funcContext, stmt *ast.ReturnStmt)
| 870 | } // }}} |
| 871 | |
| 872 | func compileReturnStmt(context *funcContext, stmt *ast.ReturnStmt) { // {{{ |
| 873 | lenexprs := len(stmt.Exprs) |
| 874 | code := context.Code |
| 875 | reg := context.RegTop() |
| 876 | a := reg |
| 877 | lastisvaarg := false |
| 878 | |
| 879 | if lenexprs == 1 { |
| 880 | switch ex := stmt.Exprs[0].(type) { |
| 881 | case *ast.IdentExpr: |
| 882 | if idx := context.FindLocalVar(ex.Value); idx > -1 { |
| 883 | code.AddABC(OP_RETURN, idx, 2, 0, sline(stmt)) |
| 884 | return |
| 885 | } |
| 886 | case *ast.FuncCallExpr: |
| 887 | if ex.AdjustRet { // return (func()) |
| 888 | reg += compileExpr(context, reg, ex, ecnone(0)) |
| 889 | } else { |
| 890 | reg += compileExpr(context, reg, ex, ecnone(-2)) |
| 891 | code.SetOpCode(code.LastPC(), OP_TAILCALL) |
| 892 | } |
| 893 | code.AddABC(OP_RETURN, a, 0, 0, sline(stmt)) |
| 894 | return |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | for i, expr := range stmt.Exprs { |
| 899 | if i == lenexprs-1 && isVarArgReturnExpr(expr) { |
| 900 | compileExpr(context, reg, expr, ecnone(-2)) |
| 901 | lastisvaarg = true |
| 902 | } else { |
| 903 | reg += compileExpr(context, reg, expr, ecnone(0)) |
| 904 | } |
| 905 | } |
| 906 | count := reg - a + 1 |
| 907 | if lastisvaarg { |
| 908 | count = 0 |
| 909 | } |
| 910 | context.Code.AddABC(OP_RETURN, a, count, 0, sline(stmt)) |
| 911 | } // }}} |
| 912 | |
| 913 | func compileIfStmt(context *funcContext, stmt *ast.IfStmt) { // {{{ |
| 914 | thenlabel := context.NewLabel() |
no test coverage detected
searching dependent graphs…