** Ensures final expression result (including results from its jump ** lists) is in register 'reg'. ** If expression has jumps, need to patch these jumps either to ** its final position or to "load" instructions (for those tests ** that do not produce values). */
| 673 | ** that do not produce values). |
| 674 | */ |
| 675 | static void exp2reg (FuncState *fs, expdesc *e, int reg) { |
| 676 | discharge2reg(fs, e, reg); |
| 677 | if (e->k == VJMP) /* expression itself is a test? */ |
| 678 | luaK_concat(fs, &e->t, e->u.info); /* put this jump in 't' list */ |
| 679 | if (hasjumps(e)) { |
| 680 | int final; /* position after whole expression */ |
| 681 | int p_f = NO_JUMP; /* position of an eventual LOAD false */ |
| 682 | int p_t = NO_JUMP; /* position of an eventual LOAD true */ |
| 683 | if (need_value(fs, e->t) || need_value(fs, e->f)) { |
| 684 | int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs); |
| 685 | p_f = code_loadbool(fs, reg, 0, 1); |
| 686 | p_t = code_loadbool(fs, reg, 1, 0); |
| 687 | luaK_patchtohere(fs, fj); |
| 688 | } |
| 689 | final = luaK_getlabel(fs); |
| 690 | patchlistaux(fs, e->f, final, reg, p_f); |
| 691 | patchlistaux(fs, e->t, final, reg, p_t); |
| 692 | } |
| 693 | e->f = e->t = NO_JUMP; |
| 694 | e->u.info = reg; |
| 695 | e->k = VNONRELOC; |
| 696 | } |
| 697 | |
| 698 | |
| 699 | /* |
no test coverage detected