** Ensures final expression result (which includes 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). */
| 898 | ** that do not produce values). |
| 899 | */ |
| 900 | static void exp2reg (FuncState *fs, expdesc *e, int reg) { |
| 901 | discharge2reg(fs, e, reg); |
| 902 | if (e->k == VJMP) /* expression itself is a test? */ |
| 903 | luaK_concat(fs, &e->t, e->u.info); /* put this jump in 't' list */ |
| 904 | if (hasjumps(e)) { |
| 905 | int final; /* position after whole expression */ |
| 906 | int p_f = NO_JUMP; /* position of an eventual LOAD false */ |
| 907 | int p_t = NO_JUMP; /* position of an eventual LOAD true */ |
| 908 | if (need_value(fs, e->t) || need_value(fs, e->f)) { |
| 909 | int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs); |
| 910 | p_f = code_loadbool(fs, reg, OP_LFALSESKIP); /* skip next inst. */ |
| 911 | p_t = code_loadbool(fs, reg, OP_LOADTRUE); |
| 912 | /* jump around these booleans if 'e' is not a test */ |
| 913 | luaK_patchtohere(fs, fj); |
| 914 | } |
| 915 | final = luaK_getlabel(fs); |
| 916 | patchlistaux(fs, e->f, final, reg, p_f); |
| 917 | patchlistaux(fs, e->t, final, reg, p_t); |
| 918 | } |
| 919 | e->f = e->t = NO_JUMP; |
| 920 | e->u.info = reg; |
| 921 | e->k = VNONRELOC; |
| 922 | } |
| 923 | |
| 924 | |
| 925 | /* |
no test coverage detected