| 2015 | |
| 2016 | |
| 2017 | static void retstat (LexState *ls) { |
| 2018 | /* stat -> RETURN [explist] [';'] */ |
| 2019 | FuncState *fs = ls->fs; |
| 2020 | expdesc e; |
| 2021 | int nret; /* number of values being returned */ |
| 2022 | int first = luaY_nvarstack(fs); /* first slot to be returned */ |
| 2023 | if (block_follow(ls, 1) || ls->t.token == ';') |
| 2024 | nret = 0; /* return no values */ |
| 2025 | else { |
| 2026 | nret = explist(ls, &e); /* optional return values */ |
| 2027 | if (hasmultret(e.k)) { |
| 2028 | luaK_setmultret(fs, &e); |
| 2029 | if (e.k == VCALL && nret == 1 && !fs->bl->insidetbc) { /* tail call? */ |
| 2030 | SET_OPCODE(getinstruction(fs,&e), OP_TAILCALL); |
| 2031 | lua_assert(GETARG_A(getinstruction(fs,&e)) == luaY_nvarstack(fs)); |
| 2032 | } |
| 2033 | nret = LUA_MULTRET; /* return all values */ |
| 2034 | } |
| 2035 | else { |
| 2036 | if (nret == 1) /* only one single value? */ |
| 2037 | first = luaK_exp2anyreg(fs, &e); /* can use original slot */ |
| 2038 | else { /* values must go to the top of the stack */ |
| 2039 | luaK_exp2nextreg(fs, &e); |
| 2040 | lua_assert(nret == fs->freereg - first); |
| 2041 | } |
| 2042 | } |
| 2043 | } |
| 2044 | luaK_ret(fs, first, nret); |
| 2045 | testnext(ls, ';'); /* skip optional semicolon */ |
| 2046 | } |
| 2047 | |
| 2048 | |
| 2049 | static void statement (LexState *ls) { |
no test coverage detected