MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / codeexpval

Function codeexpval

src/Chain/libraries/glua/lcode.cpp:794–822  ·  view source on GitHub ↗

** Code for binary and unary expressions that "produce values" ** (arithmetic operations, bitwise operations, concat, length). First ** try to do constant folding (only for numeric [arithmetic and ** bitwise] operations, which is what 'lua_arith' accepts). ** Expression to produce final result will be encoded in 'e1'. */

Source from the content-addressed store, hash-verified

792** Expression to produce final result will be encoded in 'e1'.
793*/
794static void codeexpval(FuncState *fs, OpCode op,
795 expdesc *e1, expdesc *e2, int line) {
796 lua_assert(op >= OP_ADD);
797 if (op <= OP_BNOT && constfolding(fs, (op - OP_ADD) + LUA_OPADD, e1, e2))
798 return; /* result has been folded */
799 else {
800 int o1, o2;
801 /* move operands to registers (if needed) */
802 if (op == OP_UNM || op == OP_BNOT || op == OP_LEN) { /* unary op? */
803 o2 = 0; /* no second expression */
804 o1 = luaK_exp2anyreg(fs, e1); /* cannot operate on constants */
805 }
806 else { /* regular case (binary operators) */
807 o2 = luaK_exp2RK(fs, e2); /* both operands are "RK" */
808 o1 = luaK_exp2RK(fs, e1);
809 }
810 if (o1 > o2) { /* free registers in proper order */
811 freeexp(fs, e1);
812 freeexp(fs, e2);
813 }
814 else {
815 freeexp(fs, e2);
816 freeexp(fs, e1);
817 }
818 e1->u.info = luaK_codeABC(fs, op, 0, o1, o2); /* generate opcode */
819 e1->k = VRELOCABLE; /* all those operations are relocatable */
820 luaK_fixline(fs, line);
821 }
822}
823
824
825static void codecomp(FuncState *fs, OpCode op, int cond, expdesc *e1,

Callers 2

luaK_prefixFunction · 0.85
luaK_posfixFunction · 0.85

Calls 6

constfoldingFunction · 0.85
luaK_exp2anyregFunction · 0.85
luaK_exp2RKFunction · 0.85
freeexpFunction · 0.85
luaK_codeABCFunction · 0.85
luaK_fixlineFunction · 0.85

Tested by

no test coverage detected