MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / luaV_finishOp

Function luaV_finishOp

3rd/lua-5.4.3/src/lvm.c:808–862  ·  view source on GitHub ↗

** finish execution of an opcode interrupted by a yield */

Source from the content-addressed store, hash-verified

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

Callers 1

unrollFunction · 0.85

Calls 1

luaV_concatFunction · 0.85

Tested by

no test coverage detected