MCPcopy Create free account
hub / github.com/DFHack/dfhack / luaK_posfix

Function luaK_posfix

depends/lua/src/lcode.c:1124–1171  ·  view source on GitHub ↗

** Finalize code for binary operation, after reading 2nd operand. ** For '(a .. b .. c)' (which is '(a .. (b .. c))', because ** concatenation is right associative), merge second CONCAT into first ** one. */

Source from the content-addressed store, hash-verified

1122** one.
1123*/
1124void luaK_posfix (FuncState *fs, BinOpr op,
1125 expdesc *e1, expdesc *e2, int line) {
1126 switch (op) {
1127 case OPR_AND: {
1128 lua_assert(e1->t == NO_JUMP); /* list closed by 'luK_infix' */
1129 luaK_dischargevars(fs, e2);
1130 luaK_concat(fs, &e2->f, e1->f);
1131 *e1 = *e2;
1132 break;
1133 }
1134 case OPR_OR: {
1135 lua_assert(e1->f == NO_JUMP); /* list closed by 'luK_infix' */
1136 luaK_dischargevars(fs, e2);
1137 luaK_concat(fs, &e2->t, e1->t);
1138 *e1 = *e2;
1139 break;
1140 }
1141 case OPR_CONCAT: {
1142 luaK_exp2val(fs, e2);
1143 if (e2->k == VRELOCABLE &&
1144 GET_OPCODE(getinstruction(fs, e2)) == OP_CONCAT) {
1145 lua_assert(e1->u.info == GETARG_B(getinstruction(fs, e2))-1);
1146 freeexp(fs, e1);
1147 SETARG_B(getinstruction(fs, e2), e1->u.info);
1148 e1->k = VRELOCABLE; e1->u.info = e2->u.info;
1149 }
1150 else {
1151 luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */
1152 codebinexpval(fs, OP_CONCAT, e1, e2, line);
1153 }
1154 break;
1155 }
1156 case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
1157 case OPR_IDIV: case OPR_MOD: case OPR_POW:
1158 case OPR_BAND: case OPR_BOR: case OPR_BXOR:
1159 case OPR_SHL: case OPR_SHR: {
1160 if (!constfolding(fs, op + LUA_OPADD, e1, e2))
1161 codebinexpval(fs, cast(OpCode, op + OP_ADD), e1, e2, line);
1162 break;
1163 }
1164 case OPR_EQ: case OPR_LT: case OPR_LE:
1165 case OPR_NE: case OPR_GT: case OPR_GE: {
1166 codecomp(fs, op, e1, e2);
1167 break;
1168 }
1169 default: lua_assert(0);
1170 }
1171}
1172
1173
1174/*

Callers 1

subexprFunction · 0.85

Calls 9

luaK_dischargevarsFunction · 0.85
luaK_concatFunction · 0.85
luaK_exp2valFunction · 0.85
freeexpFunction · 0.85
luaK_exp2nextregFunction · 0.85
codebinexpvalFunction · 0.85
constfoldingFunction · 0.85
castFunction · 0.85
codecompFunction · 0.85

Tested by

no test coverage detected