** finish execution of an opcode interrupted by a yield */
| 812 | ** finish execution of an opcode interrupted by a yield |
| 813 | */ |
| 814 | void luaV_finishOp (lua_State *L) { |
| 815 | CallInfo *ci = L->ci; |
| 816 | StkId base = ci->func.p + 1; |
| 817 | Instruction inst = *(ci->u.l.savedpc - 1); /* interrupted instruction */ |
| 818 | OpCode op = GET_OPCODE(inst); |
| 819 | switch (op) { /* finish its execution */ |
| 820 | case OP_MMBIN: case OP_MMBINI: case OP_MMBINK: { |
| 821 | setobjs2s(L, base + GETARG_A(*(ci->u.l.savedpc - 2)), --L->top.p); |
| 822 | break; |
| 823 | } |
| 824 | case OP_UNM: case OP_BNOT: case OP_LEN: |
| 825 | case OP_GETTABUP: case OP_GETTABLE: case OP_GETI: |
| 826 | case OP_GETFIELD: case OP_SELF: { |
| 827 | setobjs2s(L, base + GETARG_A(inst), --L->top.p); |
| 828 | break; |
| 829 | } |
| 830 | case OP_LT: case OP_LE: |
| 831 | case OP_LTI: case OP_LEI: |
| 832 | case OP_GTI: case OP_GEI: |
| 833 | case OP_EQ: { /* note that 'OP_EQI'/'OP_EQK' cannot yield */ |
| 834 | int res = !l_isfalse(s2v(L->top.p - 1)); |
| 835 | L->top.p--; |
| 836 | #if defined(LUA_COMPAT_LT_LE) |
| 837 | if (ci->callstatus & CIST_LEQ) { /* "<=" using "<" instead? */ |
| 838 | ci->callstatus ^= CIST_LEQ; /* clear mark */ |
| 839 | res = !res; /* negate result */ |
| 840 | } |
| 841 | #endif |
| 842 | lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP); |
| 843 | if (res != GETARG_k(inst)) /* condition failed? */ |
| 844 | ci->u.l.savedpc++; /* skip jump instruction */ |
| 845 | break; |
| 846 | } |
| 847 | case OP_CONCAT: { |
| 848 | StkId top = L->top.p - 1; /* top when 'luaT_tryconcatTM' was called */ |
| 849 | int a = GETARG_A(inst); /* first element to concatenate */ |
| 850 | int total = cast_int(top - 1 - (base + a)); /* yet to concatenate */ |
| 851 | setobjs2s(L, top - 2, top); /* put TM result in proper position */ |
| 852 | L->top.p = top - 1; /* top is one after last element (at top-2) */ |
| 853 | luaV_concat(L, total); /* concat them (may yield again) */ |
| 854 | break; |
| 855 | } |
| 856 | case OP_CLOSE: { /* yielded closing variables */ |
| 857 | ci->u.l.savedpc--; /* repeat instruction to close other vars. */ |
| 858 | break; |
| 859 | } |
| 860 | case OP_RETURN: { /* yielded closing variables */ |
| 861 | StkId ra = base + GETARG_A(inst); |
| 862 | /* adjust top to signal correct number of returns, in case the |
| 863 | return is "up to top" ('isIT') */ |
| 864 | L->top.p = ra + ci->u2.nres; |
| 865 | /* repeat instruction to close other vars. and complete the return */ |
| 866 | ci->u.l.savedpc--; |
| 867 | break; |
| 868 | } |
| 869 | default: { |
| 870 | /* only these other opcodes can yield */ |
| 871 | lua_assert(op == OP_TFORCALL || op == OP_CALL || |