static void adjustlocalvars (LexState *ls, int nvars) { FuncState *fs = ls->fs; fs->nactvar = cast_byte(fs->nactvar + nvars); for (; nvars; nvars--) { getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc; } }
static void removevars(ktap_funcstate *fs, int tolevel) { fs->ls->dyd->actvar.n -= (fs->nactvar - tolevel); while (fs->nactvar > tolevel) getlocvar(fs, --fs->nactvar)->endpc = fs->pc; }
static void closegoto(LexState *ls, int g, Labeldesc *label) { int i; FuncState *fs = ls->fs; Labellist *gl = &ls->dyd->gt; Labeldesc *gt = &gl->arr[g]; lua_assert(luaS_eqstr(gt->name, label->name)); if (gt->nactvar < label->nactvar) { TString *vname = getlocvar(fs, gt->nactvar)->varname; const char *msg = luaO_pushfstring(ls->L, "<goto %s> at line %d jumps into the scope of local " LUA_QS, getstr(gt->name), gt->line, getstr(vname)); semerror(ls, msg); } luaK_patchlist(fs, gt->pc, label->pc); /* remove goto from pending list */ for (i = g; i < gl->n - 1; i++) gl->arr[i] = gl->arr[i + 1]; gl->n--; }
static int searchvar (FuncState *fs, TString *n) { int i; for (i=fs->nactvar-1; i >= 0; i--) { if (luaS_eqstr(n, getlocvar(fs, i)->varname)) return i; } return -1; /* not found */ }
static int searchvar (FuncState *fs, TString *n) { int i; for (i = cast_int(fs->nlocvars) - 1; i >= 0; i--) { if (eqstr(n, getlocvar(fs, i)->varname)) return i; } return -1; /* not found */ }
/*static*/ int FuncState::searchvar (/*FuncState *fs,*/ TString *n) { int i; for (i = cast_int(nactvar) - 1; i >= 0; i--) { if (eqstr(n, getlocvar(i)->varname)) return i; } return -1; /* not found */ }
static int searchvar (FuncState *fs, TString *n) { int i; for (i=fs->nactvar-1; i >= 0; i--) { if (n == getlocvar(fs, i).varname) return i; } return -1; /* not found */ }
static void adjustlocalvars(ktap_lexstate *ls, int nvars) { ktap_funcstate *fs = ls->fs; fs->nactvar = (u8)(fs->nactvar + nvars); for (; nvars; nvars--) { getlocvar(fs, fs->nactvar - nvars)->startpc = fs->pc; } }
static void removevars (LexState *ls, int tolevel) { FuncState *fs = GetCurrentFuncState( ls ); while (fs->nactvar > tolevel) { getlocvar(fs, --fs->nactvar).endpc = fs->pc; } }
static int searchvar(ktap_funcstate *fs, ktap_string *n) { int i; for (i = fs->nactvar-1; i >= 0; i--) { if (ktapc_ts_eqstr(n, getlocvar(fs, i)->varname)) return i; } return -1; /* not found */ }
static void localfunc (LexState *ls) { expdesc v, b; FuncState *fs = ls->fs; new_localvar(ls, str_checkname(ls), 0); init_exp(&v, VLOCAL, fs->freereg); luaK_reserveregs(fs, 1); adjustlocalvars(ls, 1); body(ls, &b, 0, ls->linenumber); luaK_storevar(fs, &v, &b); /* debug information will only see the variable after this point! */ getlocvar(fs, fs->nactvar - 1).startpc = fs->pc; }
static int searchvar (FuncState *fs, TString *n) { int i; for (i=fs->nactvar-1; i >= 0; i--) { #if LUA_EXT_CONTINUE if (n == getlocvar(fs, i).varname) { if (i >= fs->prohibitedloc) { BlockCnt *bl = fs->bl; int line; while (bl->continuelist == NO_JUMP) bl = bl->previous; line = fs->f->lineinfo[bl->continuelist]; fs->ls->linenumber = fs->ls->lastline; /* Go back to the name token for the error message line number */ luaX_lexerror(fs->ls, luaO_pushfstring(fs->L, "use of variable " LUA_QS " is not permitted in this context as its initialisation could have been skipped by the " LUA_QL("continue") " statement on line %d", n + 1, line), 0); } return i; } #else if (n == getlocvar(fs, i).varname) return i; #endif /* LUA_EXT_CONTINUE */ } return -1; /* not found */ }
static void localstat (LexState *ls) { /* stat -> LOCAL NAME {`,' NAME} [ IN primaryexp | `=' explist1] */ int nvars = 0; int nexps; expdesc e; do { new_localvar(ls, str_checkname(ls), nvars++); } while (testnext(ls, ',')); if (testnext(ls, TK_IN)) { lu_byte from_var; int regs = ls->fs->freereg; int vars = ls->fs->nactvar; luaK_reserveregs(ls->fs, nvars); adjustlocalvars(ls, nvars); new_localvarliteral(ls, "(from)", 0); primaryexp(ls, &e); luaK_exp2nextreg(ls->fs, &e); from_var = ls->fs->nactvar; adjustlocalvars(ls, 1); luaK_setoneret(ls->fs, &e); /* close last expression */ for (nexps=0; nexps<nvars; nexps++) { expdesc v, key; init_exp(&e, VNONRELOC, ls->fs->freereg-1); codestring(ls, &key, getlocvar(ls->fs, vars+nexps).varname); luaK_indexed(ls->fs, &e, &key); init_exp(&v, VLOCAL, regs+nexps); luaK_storevar(ls->fs, &v, &e); } removevars(ls, from_var); return; } if (testnext(ls, '=')) nexps = explist1(ls, &e); else { e.k = VVOID; nexps = 0; } adjust_assign(ls, nvars, nexps, &e); adjustlocalvars(ls, nvars); }
static void getfrom (LexState *ls, expdesc *e, expdesc *v) { expdesc key; int k = v->k; if (k == VLOCAL) { codestring(ls, &key, getlocvar(ls->fs, v->u.s.info).varname); } else if (k == VUPVAL) { codestring(ls, &key, ls->fs->f->upvalues[v->u.s.info]); } else if (k== VGLOBAL) { init_exp(&key, VK, v->u.s.info); } else { check_condition(ls, VLOCAL <= k && k <= VGLOBAL, "syntax error in from vars"); } luaK_indexed(ls->fs, e, &key); }
static void closegoto(ktap_lexstate *ls, int g, ktap_labeldesc *label) { int i; ktap_funcstate *fs = ls->fs; ktap_labellist *gl = &ls->dyd->gt; ktap_labeldesc *gt = &gl->arr[g]; ktap_assert(ktapc_ts_eqstr(gt->name, label->name)); if (gt->nactvar < label->nactvar) { ktap_string *vname = getlocvar(fs, gt->nactvar)->varname; const char *msg = ktapc_sprintf( "<goto %s> at line %d jumps into the scope of local " KTAP_QS, getstr(gt->name), gt->line, getstr(vname)); semerror(ls, msg); } codegen_patchlist(fs, gt->pc, label->pc); /* remove goto from pending list */ for (i = g; i < gl->n - 1; i++) gl->arr[i] = gl->arr[i + 1]; gl->n--; }
static void removevars (LexState *ls, int tolevel) { FuncState *fs = ls->fs; while (fs->nactvar > tolevel) getlocvar(fs, --fs->nactvar).endpc = fs->pc; }
/*static*/ void FuncState::removevars (/*FuncState *fs,*/ int tolevel) { ls->dyd->actvar.n -= (nactvar - tolevel); while (nactvar > tolevel) getlocvar(--nactvar)->endpc = pc; }