static void codenot (FuncState *fs, expdesc *e) { luaK_dischargevars(fs, e); switch (e->k) { case VNIL: case VFALSE: { e->k = VTRUE; break; } case VK: case VKFLT: case VKINT: case VTRUE: { e->k = VFALSE; break; } case VJMP: { invertjump(fs, e); break; } case VRELOCABLE: case VNONRELOC: { discharge2anyreg(fs, e); freeexp(fs, e); e->u.info = luaK_codeABC(fs, OP_NOT, 0, e->u.info, 0); e->k = VRELOCABLE; break; } default: { lua_assert(0); /* cannot happen */ break; } } /* interchange true and false lists */ { int temp = e->f; e->f = e->t; e->t = temp; } }
static void luaK_testgo (FuncState *fs, expdesc *v, int invert, OpCode jump) { int prevpos; /* position of last instruction */ Instruction *previous; int *golist, *exitlist; if (!invert) { golist = &v->u.l.f; /* go if false */ exitlist = &v->u.l.t; /* exit if true */ } else { golist = &v->u.l.t; /* go if true */ exitlist = &v->u.l.f; /* exit if false */ } discharge1(fs, v); prevpos = fs->pc-1; previous = &fs->f->code[prevpos]; LUA_ASSERT(*previous==previous_instruction(fs), "no jump allowed here"); if (!ISJUMP(GET_OPCODE(*previous))) prevpos = luaK_code1(fs, jump, NO_JUMP); else { /* last instruction is already a jump */ if (invert) SET_OPCODE(*previous, invertjump(GET_OPCODE(*previous))); } luaK_concat(fs, exitlist, prevpos); /* insert last jump in `exitlist' */ luaK_patchlist(fs, *golist, luaK_getlabel(fs)); *golist = NO_JUMP; }
void luaK_goiftrue (FuncState *fs, expdesc *e) { int pc; /* pc of last jump */ luaK_dischargevars(fs, e); switch (e->k) { case VJMP: { invertjump(fs, e); pc = e->u.info; break; } case VTRUE: { pc = NO_JUMP; /* always true; do nothing */ break; } default: { pc = jumponcond(fs, e, 0); break; } } luaK_concat(fs, &e->f, pc); /* insert last jump in `f' list */ luaK_patchtohere(fs, e->t); e->t = NO_JUMP; }