Lines Matching refs:fs
74 static l_noret errorlimit (FuncState *fs, int limit, const char *what) { in errorlimit() argument
75 lua_State *L = fs->ls->L; in errorlimit()
77 int line = fs->f->linedefined; in errorlimit()
83 luaX_syntaxerror(fs->ls, msg); in errorlimit()
87 static void checklimit (FuncState *fs, int v, int l, const char *what) { in checklimit() argument
88 if (v > l) errorlimit(fs, l, what); in checklimit()
175 static int registerlocalvar (LexState *ls, FuncState *fs, TString *varname) { in registerlocalvar() argument
176 Proto *f = fs->f; in registerlocalvar()
178 luaM_growvector(ls->L, f->locvars, fs->ndebugvars, f->sizelocvars, in registerlocalvar()
182 f->locvars[fs->ndebugvars].varname = varname; in registerlocalvar()
183 f->locvars[fs->ndebugvars].startpc = fs->pc; in registerlocalvar()
185 return fs->ndebugvars++; in registerlocalvar()
195 FuncState *fs = ls->fs; in new_localvar() local
198 checklimit(fs, dyd->actvar.n + 1 - fs->firstlocal, in new_localvar()
205 return dyd->actvar.n - 1 - fs->firstlocal; in new_localvar()
219 static Vardesc *getlocalvardesc (FuncState *fs, int vidx) { in getlocalvardesc() argument
220 return &fs->ls->dyd->actvar.arr[fs->firstlocal + vidx]; in getlocalvardesc()
229 static int reglevel (FuncState *fs, int nvar) { in reglevel() argument
231 Vardesc *vd = getlocalvardesc(fs, nvar); /* get previous variable */ in reglevel()
243 int luaY_nvarstack (FuncState *fs) { in luaY_nvarstack() argument
244 return reglevel(fs, fs->nactvar); in luaY_nvarstack()
251 static LocVar *localdebuginfo (FuncState *fs, int vidx) { in localdebuginfo() argument
252 Vardesc *vd = getlocalvardesc(fs, vidx); in localdebuginfo()
257 lua_assert(idx < fs->ndebugvars); in localdebuginfo()
258 return &fs->f->locvars[idx]; in localdebuginfo()
266 static void init_var (FuncState *fs, expdesc *e, int vidx) { in init_var() argument
270 e->u.var.ridx = getlocalvardesc(fs, vidx)->vd.ridx; in init_var()
278 FuncState *fs = ls->fs; in check_readonly() local
286 Vardesc *vardesc = getlocalvardesc(fs, e->u.var.vidx); in check_readonly()
292 Upvaldesc *up = &fs->f->upvalues[e->u.info]; in check_readonly()
312 FuncState *fs = ls->fs; in adjustlocalvars() local
313 int reglevel = luaY_nvarstack(fs); in adjustlocalvars()
316 int vidx = fs->nactvar++; in adjustlocalvars()
317 Vardesc *var = getlocalvardesc(fs, vidx); in adjustlocalvars()
319 var->vd.pidx = registerlocalvar(ls, fs, var->vd.name); in adjustlocalvars()
328 static void removevars (FuncState *fs, int tolevel) { in removevars() argument
329 fs->ls->dyd->actvar.n -= (fs->nactvar - tolevel); in removevars()
330 while (fs->nactvar > tolevel) { in removevars()
331 LocVar *var = localdebuginfo(fs, --fs->nactvar); in removevars()
333 var->endpc = fs->pc; in removevars()
342 static int searchupvalue (FuncState *fs, TString *name) { in searchupvalue() argument
344 Upvaldesc *up = fs->f->upvalues; in searchupvalue()
345 for (i = 0; i < fs->nups; i++) { in searchupvalue()
352 static Upvaldesc *allocupvalue (FuncState *fs) { in allocupvalue() argument
353 Proto *f = fs->f; in allocupvalue()
355 checklimit(fs, fs->nups + 1, MAXUPVAL, "upvalues"); in allocupvalue()
356 luaM_growvector(fs->ls->L, f->upvalues, fs->nups, f->sizeupvalues, in allocupvalue()
360 return &f->upvalues[fs->nups++]; in allocupvalue()
364 static int newupvalue (FuncState *fs, TString *name, expdesc *v) { in newupvalue() argument
365 Upvaldesc *up = allocupvalue(fs); in newupvalue()
366 FuncState *prev = fs->prev; in newupvalue()
380 luaC_objbarrier(fs->ls->L, fs->f, name); in newupvalue()
381 return fs->nups - 1; in newupvalue()
390 static int searchvar (FuncState *fs, TString *n, expdesc *var) { in searchvar() argument
392 for (i = cast_int(fs->nactvar) - 1; i >= 0; i--) { in searchvar()
393 Vardesc *vd = getlocalvardesc(fs, i); in searchvar()
396 init_exp(var, VCONST, fs->firstlocal + i); in searchvar()
398 init_var(fs, var, i); in searchvar()
410 static void markupval (FuncState *fs, int level) { in markupval() argument
411 BlockCnt *bl = fs->bl; in markupval()
415 fs->needclose = 1; in markupval()
424 static void singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) { in singlevaraux() argument
425 if (fs == NULL) /* no more levels? */ in singlevaraux()
428 int v = searchvar(fs, n, var); /* look up locals at current level */ in singlevaraux()
431 markupval(fs, var->u.var.vidx); /* local will be used as an upval */ in singlevaraux()
434 int idx = searchupvalue(fs, n); /* try existing upvalues */ in singlevaraux()
436 singlevaraux(fs->prev, n, var, 0); /* try upper levels */ in singlevaraux()
438 idx = newupvalue(fs, n, var); /* will be a new upvalue */ in singlevaraux()
454 FuncState *fs = ls->fs; in singlevar() local
455 singlevaraux(fs, varname, var, 1); in singlevar()
458 singlevaraux(fs, ls->envn, var, 1); /* get environment variable */ in singlevar()
461 luaK_indexed(fs, var, &key); /* env[varname] */ in singlevar()
471 FuncState *fs = ls->fs; in adjust_assign() local
477 luaK_setreturns(fs, e, extra); /* last exp. provides the difference */ in adjust_assign()
481 luaK_exp2nextreg(fs, e); /* close last expression */ in adjust_assign()
483 luaK_nil(fs, fs->freereg, needed); /* complete with nils */ in adjust_assign()
486 luaK_reserveregs(fs, needed); /* registers for extra values */ in adjust_assign()
488 fs->freereg += needed; /* remove extra values */ in adjust_assign()
503 const char *varname = getstr(getlocalvardesc(ls->fs, gt->nactvar)->vd.name); in jumpscopeerror()
522 luaK_patchlist(ls->fs, gt->pc, label->pc); in solvegoto()
536 for (i = ls->fs->firstlabel; i < dyd->label.n; i++) { in findlabel()
555 l->arr[n].nactvar = ls->fs->nactvar; in newlabelentry()
575 int i = ls->fs->bl->firstgoto; in solvegotos()
598 FuncState *fs = ls->fs; in createlabel() local
600 int l = newlabelentry(ls, ll, name, line, luaK_getlabel(fs)); in createlabel()
603 ll->arr[l].nactvar = fs->bl->nactvar; in createlabel()
606 luaK_codeABC(fs, OP_CLOSE, luaY_nvarstack(fs), 0, 0); in createlabel()
616 static void movegotosout (FuncState *fs, BlockCnt *bl) { in movegotosout() argument
618 Labellist *gl = &fs->ls->dyd->gt; in movegotosout()
623 if (reglevel(fs, gt->nactvar) > reglevel(fs, bl->nactvar)) in movegotosout()
630 static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isloop) { in enterblock() argument
632 bl->nactvar = fs->nactvar; in enterblock()
633 bl->firstlabel = fs->ls->dyd->label.n; in enterblock()
634 bl->firstgoto = fs->ls->dyd->gt.n; in enterblock()
636 bl->insidetbc = (fs->bl != NULL && fs->bl->insidetbc); in enterblock()
637 bl->previous = fs->bl; in enterblock()
638 fs->bl = bl; in enterblock()
639 lua_assert(fs->freereg == luaY_nvarstack(fs)); in enterblock()
660 static void leaveblock (FuncState *fs) { in leaveblock() argument
661 BlockCnt *bl = fs->bl; in leaveblock()
662 LexState *ls = fs->ls; in leaveblock()
664 int stklevel = reglevel(fs, bl->nactvar); /* level outside the block */ in leaveblock()
668 luaK_codeABC(fs, OP_CLOSE, stklevel, 0, 0); in leaveblock()
669 fs->bl = bl->previous; in leaveblock()
670 removevars(fs, bl->nactvar); in leaveblock()
671 lua_assert(bl->nactvar == fs->nactvar); in leaveblock()
672 fs->freereg = stklevel; /* free registers */ in leaveblock()
675 movegotosout(fs, bl); /* update pending gotos to outer block */ in leaveblock()
689 FuncState *fs = ls->fs; in addprototype() local
690 Proto *f = fs->f; /* prototype of current function */ in addprototype()
691 if (fs->np >= f->sizep) { in addprototype()
693 luaM_growvector(L, f->p, fs->np, f->sizep, Proto *, MAXARG_Bx, "functions"); in addprototype()
697 f->p[fs->np++] = clp = luaF_newproto(L); in addprototype()
711 FuncState *fs = ls->fs->prev; in codeclosure() local
712 init_exp(v, VRELOC, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np - 1)); in codeclosure()
713 luaK_exp2nextreg(fs, v); /* fix it at the last register */ in codeclosure()
717 static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) { in open_func() argument
718 Proto *f = fs->f; in open_func()
719 fs->prev = ls->fs; /* linked list of funcstates */ in open_func()
720 fs->ls = ls; in open_func()
721 ls->fs = fs; in open_func()
722 fs->pc = 0; in open_func()
723 fs->previousline = f->linedefined; in open_func()
724 fs->iwthabs = 0; in open_func()
725 fs->lasttarget = 0; in open_func()
726 fs->freereg = 0; in open_func()
727 fs->nk = 0; in open_func()
728 fs->nabslineinfo = 0; in open_func()
729 fs->np = 0; in open_func()
730 fs->nups = 0; in open_func()
731 fs->ndebugvars = 0; in open_func()
732 fs->nactvar = 0; in open_func()
733 fs->needclose = 0; in open_func()
734 fs->firstlocal = ls->dyd->actvar.n; in open_func()
735 fs->firstlabel = ls->dyd->label.n; in open_func()
736 fs->bl = NULL; in open_func()
740 enterblock(fs, bl, 0); in open_func()
746 FuncState *fs = ls->fs; in close_func() local
747 Proto *f = fs->f; in close_func()
748 luaK_ret(fs, luaY_nvarstack(fs), 0); /* final return */ in close_func()
749 leaveblock(fs); in close_func()
750 lua_assert(fs->bl == NULL); in close_func()
751 luaK_finish(fs); in close_func()
752 luaM_shrinkvector(L, f->code, f->sizecode, fs->pc, Instruction); in close_func()
753 luaM_shrinkvector(L, f->lineinfo, f->sizelineinfo, fs->pc, ls_byte); in close_func()
755 fs->nabslineinfo, AbsLineInfo); in close_func()
756 luaM_shrinkvector(L, f->k, f->sizek, fs->nk, TValue); in close_func()
757 luaM_shrinkvector(L, f->p, f->sizep, fs->np, Proto *); in close_func()
758 luaM_shrinkvector(L, f->locvars, f->sizelocvars, fs->ndebugvars, LocVar); in close_func()
759 luaM_shrinkvector(L, f->upvalues, f->sizeupvalues, fs->nups, Upvaldesc); in close_func()
760 ls->fs = fs->prev; in close_func()
801 FuncState *fs = ls->fs; in fieldsel() local
803 luaK_exp2anyregup(fs, v); in fieldsel()
806 luaK_indexed(fs, v, &key); in fieldsel()
814 luaK_exp2val(ls->fs, v); in yindex()
837 FuncState *fs = ls->fs; in recfield() local
838 int reg = ls->fs->freereg; in recfield()
841 checklimit(fs, cc->nh, MAX_INT, "items in a constructor"); in recfield()
849 luaK_indexed(fs, &tab, &key); in recfield()
851 luaK_storevar(fs, &tab, &val); in recfield()
852 fs->freereg = reg; /* free registers */ in recfield()
856 static void closelistfield (FuncState *fs, ConsControl *cc) { in closelistfield() argument
858 luaK_exp2nextreg(fs, &cc->v); in closelistfield()
861 luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore); /* flush */ in closelistfield()
868 static void lastlistfield (FuncState *fs, ConsControl *cc) { in lastlistfield() argument
871 luaK_setmultret(fs, &cc->v); in lastlistfield()
872 luaK_setlist(fs, cc->t->u.info, cc->na, LUA_MULTRET); in lastlistfield()
877 luaK_exp2nextreg(fs, &cc->v); in lastlistfield()
878 luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore); in lastlistfield()
916 FuncState *fs = ls->fs; in constructor() local
918 int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0); in constructor()
920 luaK_code(fs, 0); /* space for extra arg. */ in constructor()
923 init_exp(t, VNONRELOC, fs->freereg); /* table will be at stack top */ in constructor()
924 luaK_reserveregs(fs, 1); in constructor()
930 closelistfield(fs, &cc); in constructor()
934 lastlistfield(fs, &cc); in constructor()
935 luaK_settablesize(fs, pc, t->u.info, cc.na, cc.nh); in constructor()
941 static void setvararg (FuncState *fs, int nparams) { in setvararg() argument
942 fs->f->is_vararg = 1; in setvararg()
943 luaK_codeABC(fs, OP_VARARGPREP, nparams, 0, 0); in setvararg()
949 FuncState *fs = ls->fs; in parlist() local
950 Proto *f = fs->f; in parlist()
971 f->numparams = cast_byte(fs->nactvar); in parlist()
973 setvararg(fs, f->numparams); /* declared vararg */ in parlist()
974 luaK_reserveregs(fs, fs->nactvar); /* reserve registers for parameters */ in parlist()
1005 luaK_exp2nextreg(ls->fs, v); in explist()
1014 FuncState *fs = ls->fs; in funcargs() local
1025 luaK_setmultret(fs, &args); in funcargs()
1049 luaK_exp2nextreg(fs, &args); /* close last argument */ in funcargs()
1050 nparams = fs->freereg - (base+1); in funcargs()
1052 init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2)); in funcargs()
1053 luaK_fixline(fs, line); in funcargs()
1054 fs->freereg = base+1; /* call remove function and arguments and leaves in funcargs()
1076 luaK_dischargevars(ls->fs, v); in primaryexp()
1093 FuncState *fs = ls->fs; in suffixedexp() local
1104 luaK_exp2anyregup(fs, v); in suffixedexp()
1106 luaK_indexed(fs, v, &key); in suffixedexp()
1113 luaK_self(fs, v, &key); in suffixedexp()
1118 luaK_exp2nextreg(fs, v); in suffixedexp()
1159 FuncState *fs = ls->fs; in simpleexp() local
1160 check_condition(ls, fs->f->is_vararg, in simpleexp()
1162 init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 0, 1)); in simpleexp()
1257 luaK_prefix(ls->fs, uop, v, line); in subexpr()
1267 luaK_infix(ls->fs, op, v); in subexpr()
1270 luaK_posfix(ls->fs, op, v, &v2, line); in subexpr()
1295 FuncState *fs = ls->fs; in block() local
1297 enterblock(fs, &bl, 0); in block()
1299 leaveblock(fs); in block()
1320 FuncState *fs = ls->fs; in check_conflict() local
1321 int extra = fs->freereg; /* eventual position to save local variable */ in check_conflict()
1349 luaK_codeABC(fs, OP_MOVE, extra, v->u.var.ridx, 0); in check_conflict()
1351 luaK_codeABC(fs, OP_GETUPVAL, extra, v->u.info, 0); in check_conflict()
1352 luaK_reserveregs(fs, 1); in check_conflict()
1384 luaK_setoneret(ls->fs, &e); /* close last expression */ in restassign()
1385 luaK_storevar(ls->fs, &lh->v, &e); in restassign()
1389 init_exp(&e, VNONRELOC, ls->fs->freereg-1); /* default assignment */ in restassign()
1390 luaK_storevar(ls->fs, &lh->v, &e); in restassign()
1399 luaK_goiftrue(ls->fs, &v); in cond()
1405 FuncState *fs = ls->fs; in gotostat() local
1411 newgotoentry(ls, name, line, luaK_jump(fs)); in gotostat()
1414 int lblevel = reglevel(fs, lb->nactvar); /* label level */ in gotostat()
1415 if (luaY_nvarstack(fs) > lblevel) /* leaving the scope of a variable? */ in gotostat()
1416 luaK_codeABC(fs, OP_CLOSE, lblevel, 0, 0); in gotostat()
1418 luaK_patchlist(fs, luaK_jump(fs), lb->pc); in gotostat()
1429 newgotoentry(ls, luaS_newliteral(ls->L, "break"), line, luaK_jump(ls->fs)); in breakstat()
1458 FuncState *fs = ls->fs; in whilestat() local
1463 whileinit = luaK_getlabel(fs); in whilestat()
1465 enterblock(fs, &bl, 1); in whilestat()
1468 luaK_jumpto(fs, whileinit); in whilestat()
1470 leaveblock(fs); in whilestat()
1471 luaK_patchtohere(fs, condexit); /* false conditions finish the loop */ in whilestat()
1478 FuncState *fs = ls->fs; in repeatstat() local
1479 int repeat_init = luaK_getlabel(fs); in repeatstat()
1481 enterblock(fs, &bl1, 1); /* loop block */ in repeatstat()
1482 enterblock(fs, &bl2, 0); /* scope block */ in repeatstat()
1487 leaveblock(fs); /* finish scope */ in repeatstat()
1489 int exit = luaK_jump(fs); /* normal exit must jump over fix */ in repeatstat()
1490 luaK_patchtohere(fs, condexit); /* repetition must close upvalues */ in repeatstat()
1491 luaK_codeABC(fs, OP_CLOSE, reglevel(fs, bl2.nactvar), 0, 0); in repeatstat()
1492 condexit = luaK_jump(fs); /* repeat after closing upvalues */ in repeatstat()
1493 luaK_patchtohere(fs, exit); /* normal exit comes to here */ in repeatstat()
1495 luaK_patchlist(fs, condexit, repeat_init); /* close the loop */ in repeatstat()
1496 leaveblock(fs); /* finish loop */ in repeatstat()
1508 luaK_exp2nextreg(ls->fs, &e); in exp1()
1518 static void fixforjump (FuncState *fs, int pc, int dest, int back) { in fixforjump() argument
1519 Instruction *jmp = &fs->f->code[pc]; in fixforjump()
1524 luaX_syntaxerror(fs->ls, "control structure too long"); in fixforjump()
1537 FuncState *fs = ls->fs; in forbody() local
1540 prep = luaK_codeABx(fs, forprep[isgen], base, 0); in forbody()
1541 enterblock(fs, &bl, 0); /* scope for declared variables */ in forbody()
1543 luaK_reserveregs(fs, nvars); in forbody()
1545 leaveblock(fs); /* end of scope for declared variables */ in forbody()
1546 fixforjump(fs, prep, luaK_getlabel(fs), 0); in forbody()
1548 luaK_codeABC(fs, OP_TFORCALL, base, 0, nvars); in forbody()
1549 luaK_fixline(fs, line); in forbody()
1551 endfor = luaK_codeABx(fs, forloop[isgen], base, 0); in forbody()
1552 fixforjump(fs, endfor, prep + 1, 1); in forbody()
1553 luaK_fixline(fs, line); in forbody()
1559 FuncState *fs = ls->fs; in fornum() local
1560 int base = fs->freereg; in fornum()
1572 luaK_int(fs, fs->freereg, 1); in fornum()
1573 luaK_reserveregs(fs, 1); in fornum()
1582 FuncState *fs = ls->fs; in forlist() local
1586 int base = fs->freereg; in forlist()
1602 markupval(fs, fs->nactvar); /* last control var. must be closed */ in forlist()
1603 luaK_checkstack(fs, 3); /* extra space to call generator */ in forlist()
1610 FuncState *fs = ls->fs; in forstat() local
1613 enterblock(fs, &bl, 1); /* scope for loop and control variables */ in forstat()
1622 leaveblock(fs); /* loop scope ('break' jumps to this point) */ in forstat()
1629 FuncState *fs = ls->fs; in test_then_block() local
1637 luaK_goiffalse(ls->fs, &v); /* will jump if condition is true */ in test_then_block()
1639 enterblock(fs, &bl, 0); /* must enter block before 'goto' */ in test_then_block()
1643 leaveblock(fs); in test_then_block()
1647 jf = luaK_jump(fs); in test_then_block()
1650 luaK_goiftrue(ls->fs, &v); /* skip over block if condition is false */ in test_then_block()
1651 enterblock(fs, &bl, 0); in test_then_block()
1655 leaveblock(fs); in test_then_block()
1658 luaK_concat(fs, escapelist, luaK_jump(fs)); /* must jump over it */ in test_then_block()
1659 luaK_patchtohere(fs, jf); in test_then_block()
1665 FuncState *fs = ls->fs; in ifstat() local
1673 luaK_patchtohere(fs, escapelist); /* patch escape list to 'if' end */ in ifstat()
1679 FuncState *fs = ls->fs; in localfunc() local
1680 int fvar = fs->nactvar; /* function's variable index */ in localfunc()
1685 localdebuginfo(fs, fvar)->startpc = fs->pc; in localfunc()
1708 FuncState *fs = ls->fs; in checktoclose() local
1709 markupval(fs, level + 1); in checktoclose()
1710 fs->bl->insidetbc = 1; /* in the scope of a to-be-closed variable */ in checktoclose()
1711 luaK_codeABC(fs, OP_TBC, reglevel(fs, level), 0, 0); in checktoclose()
1718 FuncState *fs = ls->fs; in localstat() local
1728 getlocalvardesc(fs, vidx)->vd.kind = kind; in localstat()
1732 toclose = fs->nactvar + nvars; in localstat()
1742 var = getlocalvardesc(fs, vidx); /* get last variable */ in localstat()
1745 luaK_exp2const(fs, &e, &var->k)) { /* compile-time constant? */ in localstat()
1748 fs->nactvar++; /* but count it */ in localstat()
1779 luaK_storevar(ls->fs, &v, &b); in funcstat()
1780 luaK_fixline(ls->fs, line); /* definition "happens" in the first line */ in funcstat()
1786 FuncState *fs = ls->fs; in exprstat() local
1796 inst = &getinstruction(fs, &v.v); in exprstat()
1804 FuncState *fs = ls->fs; in retstat() local
1807 int first = luaY_nvarstack(fs); /* first slot to be returned */ in retstat()
1813 luaK_setmultret(fs, &e); in retstat()
1814 if (e.k == VCALL && nret == 1 && !fs->bl->insidetbc) { /* tail call? */ in retstat()
1815 SET_OPCODE(getinstruction(fs,&e), OP_TAILCALL); in retstat()
1816 lua_assert(GETARG_A(getinstruction(fs,&e)) == luaY_nvarstack(fs)); in retstat()
1822 first = luaK_exp2anyreg(fs, &e); /* can use original slot */ in retstat()
1824 luaK_exp2nextreg(fs, &e); in retstat()
1825 lua_assert(nret == fs->freereg - first); in retstat()
1829 luaK_ret(fs, first, nret); in retstat()
1900 lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg && in statement()
1901 ls->fs->freereg >= luaY_nvarstack(ls->fs)); in statement()
1902 ls->fs->freereg = luaY_nvarstack(ls->fs); /* free registers */ in statement()
1913 static void mainfunc (LexState *ls, FuncState *fs) { in mainfunc() argument
1916 open_func(ls, fs, &bl); in mainfunc()
1917 setvararg(fs, 0); /* main function is always declared vararg */ in mainfunc()
1918 env = allocupvalue(fs); /* ...set environment upvalue */ in mainfunc()
1923 luaC_objbarrier(ls->L, fs->f, env->name); in mainfunc()
1950 lua_assert(!funcstate.prev && funcstate.nups == 1 && !lexstate.fs); in luaY_parser()