• Home
  • Raw
  • Download

Lines Matching refs:fs

62   lua_assert(ls->fs != NULL || ls->t.token == TK_EOS);  in anchor_token()
83 static l_noret errorlimit (FuncState *fs, int limit, const char *what) { in errorlimit() argument
84 lua_State *L = fs->ls->L; in errorlimit()
86 int line = fs->f->linedefined; in errorlimit()
92 luaX_syntaxerror(fs->ls, msg); in errorlimit()
96 static void checklimit (FuncState *fs, int v, int l, const char *what) { in checklimit() argument
97 if (v > l) errorlimit(fs, l, what); in checklimit()
156 init_exp(e, VK, luaK_stringK(ls->fs, s)); in codestring()
166 FuncState *fs = ls->fs; in registerlocalvar() local
167 Proto *f = fs->f; in registerlocalvar()
169 luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars, in registerlocalvar()
172 f->locvars[fs->nlocvars].varname = varname; in registerlocalvar()
174 return fs->nlocvars++; in registerlocalvar()
179 FuncState *fs = ls->fs; in new_localvar() local
182 checklimit(fs, dyd->actvar.n + 1 - fs->firstlocal, in new_localvar()
198 static LocVar *getlocvar (FuncState *fs, int i) { in getlocvar() argument
199 int idx = fs->ls->dyd->actvar.arr[fs->firstlocal + i].idx; in getlocvar()
200 lua_assert(idx < fs->nlocvars); in getlocvar()
201 return &fs->f->locvars[idx]; in getlocvar()
206 FuncState *fs = ls->fs; in adjustlocalvars() local
207 fs->nactvar = cast_byte(fs->nactvar + nvars); in adjustlocalvars()
209 getlocvar(fs, fs->nactvar - nvars)->startpc = fs->pc; in adjustlocalvars()
214 static void removevars (FuncState *fs, int tolevel) { in removevars() argument
215 fs->ls->dyd->actvar.n -= (fs->nactvar - tolevel); in removevars()
216 while (fs->nactvar > tolevel) in removevars()
217 getlocvar(fs, --fs->nactvar)->endpc = fs->pc; in removevars()
221 static int searchupvalue (FuncState *fs, TString *name) { in searchupvalue() argument
223 Upvaldesc *up = fs->f->upvalues; in searchupvalue()
224 for (i = 0; i < fs->nups; i++) { in searchupvalue()
231 static int newupvalue (FuncState *fs, TString *name, expdesc *v) { in newupvalue() argument
232 Proto *f = fs->f; in newupvalue()
234 checklimit(fs, fs->nups + 1, MAXUPVAL, "upvalues"); in newupvalue()
235 luaM_growvector(fs->ls->L, f->upvalues, fs->nups, f->sizeupvalues, in newupvalue()
238 f->upvalues[fs->nups].instack = (v->k == VLOCAL); in newupvalue()
239 f->upvalues[fs->nups].idx = cast_byte(v->u.info); in newupvalue()
240 f->upvalues[fs->nups].name = name; in newupvalue()
241 luaC_objbarrier(fs->ls->L, f, name); in newupvalue()
242 return fs->nups++; in newupvalue()
246 static int searchvar (FuncState *fs, TString *n) { in searchvar() argument
248 for (i = cast_int(fs->nactvar) - 1; i >= 0; i--) { in searchvar()
249 if (luaS_eqstr(n, getlocvar(fs, i)->varname)) in searchvar()
260 static void markupval (FuncState *fs, int level) { in markupval() argument
261 BlockCnt *bl = fs->bl; in markupval()
271 static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) { in singlevaraux() argument
272 if (fs == NULL) /* no more levels? */ in singlevaraux()
275 int v = searchvar(fs, n); /* look up locals at current level */ in singlevaraux()
279 markupval(fs, v); /* local will be used as an upval */ in singlevaraux()
283 int idx = searchupvalue(fs, n); /* try existing upvalues */ in singlevaraux()
285 if (singlevaraux(fs->prev, n, var, 0) == VVOID) /* try upper levels */ in singlevaraux()
288 idx = newupvalue(fs, n, var); /* will be a new upvalue */ in singlevaraux()
299 FuncState *fs = ls->fs; in singlevar() local
300 if (singlevaraux(fs, varname, var, 1) == VVOID) { /* global name? */ in singlevar()
302 singlevaraux(fs, ls->envn, var, 1); /* get environment variable */ in singlevar()
305 luaK_indexed(fs, var, &key); /* env[varname] */ in singlevar()
311 FuncState *fs = ls->fs; in adjust_assign() local
316 luaK_setreturns(fs, e, extra); /* last exp. provides the difference */ in adjust_assign()
317 if (extra > 1) luaK_reserveregs(fs, extra-1); in adjust_assign()
320 if (e->k != VVOID) luaK_exp2nextreg(fs, e); /* close last expression */ in adjust_assign()
322 int reg = fs->freereg; in adjust_assign()
323 luaK_reserveregs(fs, extra); in adjust_assign()
324 luaK_nil(fs, reg, extra); in adjust_assign()
333 checklimit(ls->fs, L->nCcalls, LUAI_MAXCCALLS, "C levels"); in enterlevel()
342 FuncState *fs = ls->fs; in closegoto() local
347 TString *vname = getlocvar(fs, gt->nactvar)->varname; in closegoto()
353 luaK_patchlist(fs, gt->pc, label->pc); in closegoto()
366 BlockCnt *bl = ls->fs->bl; in findlabel()
375 luaK_patchclose(ls->fs, gt->pc, lb->nactvar); in findlabel()
391 l->arr[n].nactvar = ls->fs->nactvar; in newlabelentry()
404 int i = ls->fs->bl->firstgoto; in findgotos()
420 static void movegotosout (FuncState *fs, BlockCnt *bl) { in movegotosout() argument
422 Labellist *gl = &fs->ls->dyd->gt; in movegotosout()
429 luaK_patchclose(fs, gt->pc, bl->nactvar); in movegotosout()
432 if (!findlabel(fs->ls, i)) in movegotosout()
438 static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isloop) { in enterblock() argument
440 bl->nactvar = fs->nactvar; in enterblock()
441 bl->firstlabel = fs->ls->dyd->label.n; in enterblock()
442 bl->firstgoto = fs->ls->dyd->gt.n; in enterblock()
444 bl->previous = fs->bl; in enterblock()
445 fs->bl = bl; in enterblock()
446 lua_assert(fs->freereg == fs->nactvar); in enterblock()
455 int l = newlabelentry(ls, &ls->dyd->label, n, 0, ls->fs->pc); in breaklabel()
472 static void leaveblock (FuncState *fs) { in leaveblock() argument
473 BlockCnt *bl = fs->bl; in leaveblock()
474 LexState *ls = fs->ls; in leaveblock()
477 int j = luaK_jump(fs); in leaveblock()
478 luaK_patchclose(fs, j, bl->nactvar); in leaveblock()
479 luaK_patchtohere(fs, j); in leaveblock()
483 fs->bl = bl->previous; in leaveblock()
484 removevars(fs, bl->nactvar); in leaveblock()
485 lua_assert(bl->nactvar == fs->nactvar); in leaveblock()
486 fs->freereg = fs->nactvar; /* free registers */ in leaveblock()
489 movegotosout(fs, bl); /* update pending gotos to outer block */ in leaveblock()
501 FuncState *fs = ls->fs; in addprototype() local
502 Proto *f = fs->f; /* prototype of current function */ in addprototype()
503 if (fs->np >= f->sizep) { in addprototype()
505 luaM_growvector(L, f->p, fs->np, f->sizep, Proto *, MAXARG_Bx, "functions"); in addprototype()
508 f->p[fs->np++] = clp = luaF_newproto(L); in addprototype()
521 FuncState *fs = ls->fs->prev; in codeclosure() local
522 init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np - 1)); in codeclosure()
523 luaK_exp2nextreg(fs, v); /* fix it at the last register */ in codeclosure()
527 static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) { in open_func() argument
530 fs->prev = ls->fs; /* linked list of funcstates */ in open_func()
531 fs->ls = ls; in open_func()
532 ls->fs = fs; in open_func()
533 fs->pc = 0; in open_func()
534 fs->lasttarget = 0; in open_func()
535 fs->jpc = NO_JUMP; in open_func()
536 fs->freereg = 0; in open_func()
537 fs->nk = 0; in open_func()
538 fs->np = 0; in open_func()
539 fs->nups = 0; in open_func()
540 fs->nlocvars = 0; in open_func()
541 fs->nactvar = 0; in open_func()
542 fs->firstlocal = ls->dyd->actvar.n; in open_func()
543 fs->bl = NULL; in open_func()
544 f = fs->f; in open_func()
547 fs->h = luaH_new(L); in open_func()
549 sethvalue2s(L, L->top, fs->h); in open_func()
551 enterblock(fs, bl, 0); in open_func()
557 FuncState *fs = ls->fs; in close_func() local
558 Proto *f = fs->f; in close_func()
559 luaK_ret(fs, 0, 0); /* final return */ in close_func()
560 leaveblock(fs); in close_func()
561 luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction); in close_func()
562 f->sizecode = fs->pc; in close_func()
563 luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int); in close_func()
564 f->sizelineinfo = fs->pc; in close_func()
565 luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue); in close_func()
566 f->sizek = fs->nk; in close_func()
567 luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *); in close_func()
568 f->sizep = fs->np; in close_func()
569 luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar); in close_func()
570 f->sizelocvars = fs->nlocvars; in close_func()
571 luaM_reallocvector(L, f->upvalues, f->sizeupvalues, fs->nups, Upvaldesc); in close_func()
572 f->sizeupvalues = fs->nups; in close_func()
573 lua_assert(fs->bl == NULL); in close_func()
574 ls->fs = fs->prev; in close_func()
618 FuncState *fs = ls->fs; in fieldsel() local
620 luaK_exp2anyregup(fs, v); in fieldsel()
623 luaK_indexed(fs, v, &key); in fieldsel()
631 luaK_exp2val(ls->fs, v); in yindex()
654 FuncState *fs = ls->fs; in recfield() local
655 int reg = ls->fs->freereg; in recfield()
659 checklimit(fs, cc->nh, MAX_INT, "items in a constructor"); in recfield()
666 rkkey = luaK_exp2RK(fs, &key); in recfield()
668 luaK_codeABC(fs, OP_SETTABLE, cc->t->u.info, rkkey, luaK_exp2RK(fs, &val)); in recfield()
669 fs->freereg = reg; /* free registers */ in recfield()
673 static void closelistfield (FuncState *fs, struct ConsControl *cc) { in closelistfield() argument
675 luaK_exp2nextreg(fs, &cc->v); in closelistfield()
678 luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore); /* flush */ in closelistfield()
684 static void lastlistfield (FuncState *fs, struct ConsControl *cc) { in lastlistfield() argument
687 luaK_setmultret(fs, &cc->v); in lastlistfield()
688 luaK_setlist(fs, cc->t->u.info, cc->na, LUA_MULTRET); in lastlistfield()
693 luaK_exp2nextreg(fs, &cc->v); in lastlistfield()
694 luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore); in lastlistfield()
702 checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor"); in listfield()
733 FuncState *fs = ls->fs; in constructor() local
735 int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0); in constructor()
741 luaK_exp2nextreg(ls->fs, t); /* fix it at stack top */ in constructor()
746 closelistfield(fs, &cc); in constructor()
750 lastlistfield(fs, &cc); in constructor()
751 SETARG_B(fs->f->code[pc], luaO_int2fb(cc.na)); /* set initial array size */ in constructor()
752 SETARG_C(fs->f->code[pc], luaO_int2fb(cc.nh)); /* set initial table size */ in constructor()
761 FuncState *fs = ls->fs; in parlist() local
762 Proto *f = fs->f; in parlist()
783 f->numparams = cast_byte(fs->nactvar); in parlist()
784 luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */ in parlist()
815 luaK_exp2nextreg(ls->fs, v); in explist()
824 FuncState *fs = ls->fs; in funcargs() local
834 luaK_setmultret(fs, &args); in funcargs()
858 luaK_exp2nextreg(fs, &args); /* close last argument */ in funcargs()
859 nparams = fs->freereg - (base+1); in funcargs()
861 init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2)); in funcargs()
862 luaK_fixline(fs, line); in funcargs()
863 fs->freereg = base+1; /* call remove function and arguments and leaves in funcargs()
885 luaK_dischargevars(ls->fs, v); in primaryexp()
902 FuncState *fs = ls->fs; in suffixedexp() local
913 luaK_exp2anyregup(fs, v); in suffixedexp()
915 luaK_indexed(fs, v, &key); in suffixedexp()
922 luaK_self(fs, v, &key); in suffixedexp()
927 luaK_exp2nextreg(fs, v); in suffixedexp()
963 FuncState *fs = ls->fs; in simpleexp() local
964 check_condition(ls, fs->f->is_vararg, in simpleexp()
966 init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0)); in simpleexp()
1046 luaK_prefix(ls->fs, uop, v, line); in subexpr()
1056 luaK_infix(ls->fs, op, v); in subexpr()
1059 luaK_posfix(ls->fs, op, v, &v2, line); in subexpr()
1084 FuncState *fs = ls->fs; in block() local
1086 enterblock(fs, &bl, 0); in block()
1088 leaveblock(fs); in block()
1109 FuncState *fs = ls->fs; in check_conflict() local
1110 int extra = fs->freereg; /* eventual position to save local variable */ in check_conflict()
1130 luaK_codeABC(fs, op, extra, v->u.info, 0); in check_conflict()
1131 luaK_reserveregs(fs, 1); in check_conflict()
1145 checklimit(ls->fs, nvars + ls->L->nCcalls, LUAI_MAXCCALLS, in assignment()
1156 ls->fs->freereg -= nexps - nvars; /* remove extra values */ in assignment()
1159 luaK_setoneret(ls->fs, &e); /* close last expression */ in assignment()
1160 luaK_storevar(ls->fs, &lh->v, &e); in assignment()
1164 init_exp(&e, VNONRELOC, ls->fs->freereg-1); /* default assignment */ in assignment()
1165 luaK_storevar(ls->fs, &lh->v, &e); in assignment()
1174 luaK_goiftrue(ls->fs, &v); in cond()
1195 static void checkrepeated (FuncState *fs, Labellist *ll, TString *label) { in checkrepeated() argument
1197 for (i = fs->bl->firstlabel; i < ll->n; i++) { in checkrepeated()
1199 const char *msg = luaO_pushfstring(fs->ls->L, in checkrepeated()
1202 semerror(fs->ls, msg); in checkrepeated()
1217 FuncState *fs = ls->fs; in labelstat() local
1220 checkrepeated(fs, ll, label); /* check for repeated labels */ in labelstat()
1223 l = newlabelentry(ls, ll, label, line, fs->pc); in labelstat()
1227 ll->arr[l].nactvar = fs->bl->nactvar; in labelstat()
1235 FuncState *fs = ls->fs; in whilestat() local
1240 whileinit = luaK_getlabel(fs); in whilestat()
1242 enterblock(fs, &bl, 1); in whilestat()
1245 luaK_jumpto(fs, whileinit); in whilestat()
1247 leaveblock(fs); in whilestat()
1248 luaK_patchtohere(fs, condexit); /* false conditions finish the loop */ in whilestat()
1255 FuncState *fs = ls->fs; in repeatstat() local
1256 int repeat_init = luaK_getlabel(fs); in repeatstat()
1258 enterblock(fs, &bl1, 1); /* loop block */ in repeatstat()
1259 enterblock(fs, &bl2, 0); /* scope block */ in repeatstat()
1265 luaK_patchclose(fs, condexit, bl2.nactvar); in repeatstat()
1266 leaveblock(fs); /* finish scope */ in repeatstat()
1267 luaK_patchlist(fs, condexit, repeat_init); /* close the loop */ in repeatstat()
1268 leaveblock(fs); /* finish loop */ in repeatstat()
1276 luaK_exp2nextreg(ls->fs, &e); in exp1()
1286 FuncState *fs = ls->fs; in forbody() local
1290 prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs); in forbody()
1291 enterblock(fs, &bl, 0); /* scope for declared variables */ in forbody()
1293 luaK_reserveregs(fs, nvars); in forbody()
1295 leaveblock(fs); /* end of scope for declared variables */ in forbody()
1296 luaK_patchtohere(fs, prep); in forbody()
1298 endfor = luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP); in forbody()
1300 luaK_codeABC(fs, OP_TFORCALL, base, 0, nvars); in forbody()
1301 luaK_fixline(fs, line); in forbody()
1302 endfor = luaK_codeAsBx(fs, OP_TFORLOOP, base + 2, NO_JUMP); in forbody()
1304 luaK_patchlist(fs, endfor, prep + 1); in forbody()
1305 luaK_fixline(fs, line); in forbody()
1311 FuncState *fs = ls->fs; in fornum() local
1312 int base = fs->freereg; in fornum()
1324 luaK_codek(fs, fs->freereg, luaK_numberK(fs, 1)); in fornum()
1325 luaK_reserveregs(fs, 1); in fornum()
1333 FuncState *fs = ls->fs; in forlist() local
1337 int base = fs->freereg; in forlist()
1351 luaK_checkstack(fs, 3); /* extra space to call generator */ in forlist()
1358 FuncState *fs = ls->fs; in forstat() local
1361 enterblock(fs, &bl, 1); /* scope for loop and control variables */ in forstat()
1370 leaveblock(fs); /* loop scope (`break' jumps to this point) */ in forstat()
1377 FuncState *fs = ls->fs; in test_then_block() local
1384 luaK_goiffalse(ls->fs, &v); /* will jump to label if condition is true */ in test_then_block()
1385 enterblock(fs, &bl, 0); /* must enter block before 'goto' */ in test_then_block()
1389 leaveblock(fs); in test_then_block()
1393 jf = luaK_jump(fs); in test_then_block()
1396 luaK_goiftrue(ls->fs, &v); /* skip over block if condition is false */ in test_then_block()
1397 enterblock(fs, &bl, 0); in test_then_block()
1401 leaveblock(fs); in test_then_block()
1404 luaK_concat(fs, escapelist, luaK_jump(fs)); /* must jump over it */ in test_then_block()
1405 luaK_patchtohere(fs, jf); in test_then_block()
1411 FuncState *fs = ls->fs; in ifstat() local
1419 luaK_patchtohere(fs, escapelist); /* patch escape list to 'if' end */ in ifstat()
1425 FuncState *fs = ls->fs; in localfunc() local
1430 getlocvar(fs, b.u.info)->startpc = fs->pc; in localfunc()
1475 luaK_storevar(ls->fs, &v, &b); in funcstat()
1476 luaK_fixline(ls->fs, line); /* definition `happens' in the first line */ in funcstat()
1482 FuncState *fs = ls->fs; in exprstat() local
1491 SETARG_C(getcode(fs, &v.v), 1); /* call statement uses no results */ in exprstat()
1498 FuncState *fs = ls->fs; in retstat() local
1506 luaK_setmultret(fs, &e); in retstat()
1508 SET_OPCODE(getcode(fs,&e), OP_TAILCALL); in retstat()
1509 lua_assert(GETARG_A(getcode(fs,&e)) == fs->nactvar); in retstat()
1511 first = fs->nactvar; in retstat()
1516 first = luaK_exp2anyreg(fs, &e); in retstat()
1518 luaK_exp2nextreg(fs, &e); /* values must go to the `stack' */ in retstat()
1519 first = fs->nactvar; /* return all `active' values */ in retstat()
1520 lua_assert(nret == fs->freereg - first); in retstat()
1524 luaK_ret(fs, first, nret); in retstat()
1583 gotostat(ls, luaK_jump(ls->fs)); in statement()
1591 lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg && in statement()
1592 ls->fs->freereg >= ls->fs->nactvar); in statement()
1593 ls->fs->freereg = ls->fs->nactvar; /* free registers */ in statement()
1604 static void mainfunc (LexState *ls, FuncState *fs) { in mainfunc() argument
1607 open_func(ls, fs, &bl); in mainfunc()
1608 fs->f->is_vararg = 1; /* main function is always vararg */ in mainfunc()
1610 newupvalue(fs, ls->envn, &v); /* ...set environment upvalue */ in mainfunc()
1633 lua_assert(!funcstate.prev && funcstate.nups == 1 && !lexstate.fs); in luaY_parser()