static void cond (LexState *ls, expdesc *v) { /* cond -> exp */ expr(ls, v); /* read condition */ if (v->k == VNIL) v->k = VFALSE; /* `falses' are all equal here */ luaK_goiftrue(ls->fs, v); luaK_patchtohere(ls->fs, v->t); }
void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { switch (op) { case OPR_AND: { luaK_goiftrue(fs, v); break; } case OPR_OR: { luaK_goiffalse(fs, v); break; } case OPR_CONCAT: { luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */ break; } case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV: case OPR_IDIV: case OPR_MOD: case OPR_POW: case OPR_BAND: case OPR_BOR: case OPR_BXOR: case OPR_SHL: case OPR_SHR: { if (!tonumeral(v, NULL)) luaK_exp2RK(fs, v); break; } default: { luaK_exp2RK(fs, v); break; } } }
static int cond (LexState *ls) { /* cond -> exp */ expdesc v; expr(ls, &v); /* read condition */ if (v.k == VNIL) v.k = VFALSE; /* `falses' are all equal here */ luaK_goiftrue(ls->fs, &v); return v.f; }
static int cond (LexState *ls) { /* cond -> exp */ expdesc v; expr(ls, &v); /* read condition */ if (v.k == VNIL) { v.k = VFALSE; /* `falses' are all equal here */ } FuncState *fs = GetCurrentFuncState( ls ); luaK_goiftrue(fs, &v); return v.f; }
static void casestat (LexState *ls, expdesc *v) { FuncState *fs = ls->fs; expdesc v2; int nargs, base; /* do not set base to 0 for if case is used in (local) loops, it does not work properly */ base = fs->freereg; luaK_exp2nextreg(fs, v); nargs = explist1(ls, &v2); /* put every value into a register */ luaK_exp2nextreg(fs, &v2); codecompcase(fs, base, nargs+1, v); fs->freereg -= nargs+1; /* free all registers */ if (v->k == VNIL) v->k = VFALSE; luaK_goiftrue(fs, v); luaK_patchtohere(fs, v->t); checknext(ls, TK_THEN); block(ls); }
static void exp2reg (FuncState *fs, expdesc *e, int reg) { discharge2reg(fs, e, reg); if (e->k == VJMP) luaK_concat(fs, &e->t, e->u.info); /* put this jump in `t' list */ if (hasjumps(e)) { if (e->k != VJMP) luaK_goiftrue(fs, e); int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs); int p_f = code_label(fs, reg, 0, 1); luaK_patchtohere(fs, fj); int p_t = code_label(fs, reg, 1, 0); patchlistaux(fs, e->f, p_f); patchlistaux(fs, e->t, p_t); } e->f = e->t = NO_JUMP; e->u.info = reg; e->k = VNONRELOC; }