MCPcopy
hub / github.com/yuin/gopher-lua / compileReturnStmt

Function compileReturnStmt

compile.go:872–911  ·  view source on GitHub ↗

}}}

(context *funcContext, stmt *ast.ReturnStmt)

Source from the content-addressed store, hash-verified

870} // }}}
871
872func 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
913func compileIfStmt(context *funcContext, stmt *ast.IfStmt) { // {{{
914 thenlabel := context.NewLabel()

Callers 1

compileStmtFunction · 0.85

Calls 9

slineFunction · 0.85
compileExprFunction · 0.85
ecnoneFunction · 0.85
isVarArgReturnExprFunction · 0.85
RegTopMethod · 0.80
FindLocalVarMethod · 0.80
AddABCMethod · 0.80
SetOpCodeMethod · 0.80
LastPCMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…