** Ensures expression value is in register 'reg' (and therefore ** 'e' will become a non-relocatable expression). */
| 593 | ** 'e' will become a non-relocatable expression). |
| 594 | */ |
| 595 | static void discharge2reg (FuncState *fs, expdesc *e, int reg) { |
| 596 | luaK_dischargevars(fs, e); |
| 597 | switch (e->k) { |
| 598 | case VNIL: { |
| 599 | luaK_nil(fs, reg, 1); |
| 600 | break; |
| 601 | } |
| 602 | case VFALSE: case VTRUE: { |
| 603 | luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0); |
| 604 | break; |
| 605 | } |
| 606 | case VK: { |
| 607 | luaK_codek(fs, reg, e->u.info); |
| 608 | break; |
| 609 | } |
| 610 | case VKFLT: { |
| 611 | luaK_codek(fs, reg, luaK_numberK(fs, e->u.nval)); |
| 612 | break; |
| 613 | } |
| 614 | case VKINT: { |
| 615 | luaK_codek(fs, reg, luaK_intK(fs, e->u.ival)); |
| 616 | break; |
| 617 | } |
| 618 | case VRELOCABLE: { |
| 619 | Instruction *pc = &getinstruction(fs, e); |
| 620 | SETARG_A(*pc, reg); /* instruction will put result in 'reg' */ |
| 621 | break; |
| 622 | } |
| 623 | case VNONRELOC: { |
| 624 | if (reg != e->u.info) |
| 625 | luaK_codeABC(fs, OP_MOVE, reg, e->u.info, 0); |
| 626 | break; |
| 627 | } |
| 628 | default: { |
| 629 | lua_assert(e->k == VJMP); |
| 630 | return; /* nothing to do... */ |
| 631 | } |
| 632 | } |
| 633 | e->u.info = reg; |
| 634 | e->k = VNONRELOC; |
| 635 | } |
| 636 | |
| 637 | |
| 638 | /* |
no test coverage detected