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