MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / luaV_finishOp

Function luaV_finishOp

lib/lua/src/lvm.c:824–887  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

Callers 1

unrollFunction · 0.85

Calls 1

luaV_concatFunction · 0.85

Tested by

no test coverage detected