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

Function discharge2reg

3rd/lua-5.4.3/src/lcode.c:807–854  ·  view source on GitHub ↗

** Ensure expression value is in register 'reg', making 'e' a ** non-relocatable expression. ** (Expression still may have jump lists.) */

Source from the content-addressed store, hash-verified

805** (Expression still may have jump lists.)
806*/
807static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
808 luaK_dischargevars(fs, e);
809 switch (e->k) {
810 case VNIL: {
811 luaK_nil(fs, reg, 1);
812 break;
813 }
814 case VFALSE: {
815 luaK_codeABC(fs, OP_LOADFALSE, reg, 0, 0);
816 break;
817 }
818 case VTRUE: {
819 luaK_codeABC(fs, OP_LOADTRUE, reg, 0, 0);
820 break;
821 }
822 case VKSTR: {
823 str2K(fs, e);
824 } /* FALLTHROUGH */
825 case VK: {
826 luaK_codek(fs, reg, e->u.info);
827 break;
828 }
829 case VKFLT: {
830 luaK_float(fs, reg, e->u.nval);
831 break;
832 }
833 case VKINT: {
834 luaK_int(fs, reg, e->u.ival);
835 break;
836 }
837 case VRELOC: {
838 Instruction *pc = &getinstruction(fs, e);
839 SETARG_A(*pc, reg); /* instruction will put result in 'reg' */
840 break;
841 }
842 case VNONRELOC: {
843 if (reg != e->u.info)
844 luaK_codeABC(fs, OP_MOVE, reg, e->u.info, 0);
845 break;
846 }
847 default: {
848 lua_assert(e->k == VJMP);
849 return; /* nothing to do... */
850 }
851 }
852 e->u.info = reg;
853 e->k = VNONRELOC;
854}
855
856
857/*

Callers 2

discharge2anyregFunction · 0.85
exp2regFunction · 0.85

Calls 6

luaK_dischargevarsFunction · 0.85
luaK_nilFunction · 0.85
str2KFunction · 0.85
luaK_codekFunction · 0.85
luaK_floatFunction · 0.85
luaK_intFunction · 0.85

Tested by

no test coverage detected