MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / luaV_finishOp

Function luaV_finishOp

xrepo/packages/l/lua/port/lua/src/lvm.c:809–872  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

Callers 1

unrollFunction · 0.85

Calls 1

luaV_concatFunction · 0.70

Tested by

no test coverage detected