** Emit code for comparisons. ** 'e1' was already put in R/K form by 'luaK_infix'. */
| 1035 | ** 'e1' was already put in R/K form by 'luaK_infix'. |
| 1036 | */ |
| 1037 | static void codecomp (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) { |
| 1038 | int rk1 = (e1->k == VK) ? RKASK(e1->u.info) |
| 1039 | : check_exp(e1->k == VNONRELOC, e1->u.info); |
| 1040 | int rk2 = luaK_exp2RK(fs, e2); |
| 1041 | freeexps(fs, e1, e2); |
| 1042 | switch (opr) { |
| 1043 | case OPR_NE: { /* '(a ~= b)' ==> 'not (a == b)' */ |
| 1044 | e1->u.info = condjump(fs, OP_EQ, 0, rk1, rk2); |
| 1045 | break; |
| 1046 | } |
| 1047 | case OPR_GT: case OPR_GE: { |
| 1048 | /* '(a > b)' ==> '(b < a)'; '(a >= b)' ==> '(b <= a)' */ |
| 1049 | OpCode op = cast(OpCode, (opr - OPR_NE) + OP_EQ); |
| 1050 | e1->u.info = condjump(fs, op, 1, rk2, rk1); /* invert operands */ |
| 1051 | break; |
| 1052 | } |
| 1053 | default: { /* '==', '<', '<=' use their own opcodes */ |
| 1054 | OpCode op = cast(OpCode, (opr - OPR_EQ) + OP_EQ); |
| 1055 | e1->u.info = condjump(fs, op, 1, rk1, rk2); |
| 1056 | break; |
| 1057 | } |
| 1058 | } |
| 1059 | e1->k = VJMP; |
| 1060 | } |
| 1061 | |
| 1062 | |
| 1063 | /* |
no test coverage detected