| 1800 | |
| 1801 | |
| 1802 | static void retstat (LexState *ls) { |
| 1803 | /* stat -> RETURN [explist] [';'] */ |
| 1804 | FuncState *fs = ls->fs; |
| 1805 | expdesc e; |
| 1806 | int nret; /* number of values being returned */ |
| 1807 | int first = luaY_nvarstack(fs); /* first slot to be returned */ |
| 1808 | if (block_follow(ls, 1) || ls->t.token == ';') |
| 1809 | nret = 0; /* return no values */ |
| 1810 | else { |
| 1811 | nret = explist(ls, &e); /* optional return values */ |
| 1812 | if (hasmultret(e.k)) { |
| 1813 | luaK_setmultret(fs, &e); |
| 1814 | if (e.k == VCALL && nret == 1 && !fs->bl->insidetbc) { /* tail call? */ |
| 1815 | SET_OPCODE(getinstruction(fs,&e), OP_TAILCALL); |
| 1816 | lua_assert(GETARG_A(getinstruction(fs,&e)) == luaY_nvarstack(fs)); |
| 1817 | } |
| 1818 | nret = LUA_MULTRET; /* return all values */ |
| 1819 | } |
| 1820 | else { |
| 1821 | if (nret == 1) /* only one single value? */ |
| 1822 | first = luaK_exp2anyreg(fs, &e); /* can use original slot */ |
| 1823 | else { /* values must go to the top of the stack */ |
| 1824 | luaK_exp2nextreg(fs, &e); |
| 1825 | lua_assert(nret == fs->freereg - first); |
| 1826 | } |
| 1827 | } |
| 1828 | } |
| 1829 | luaK_ret(fs, first, nret); |
| 1830 | testnext(ls, ';'); /* skip optional semicolon */ |
| 1831 | } |
| 1832 | |
| 1833 | |
| 1834 | static void statement (LexState *ls) { |
no test coverage detected