Lines Matching +full:bl +full:- +full:code +full:- +full:offset

56   lu_byte insidetbc;  /* true if inside the scope of a to-be-closed var. */
62 ** prototypes for recursive non-terminal functions
70 luaO_pushfstring(ls->L, "%s expected", luaX_token2str(ls, token))); in error_expected()
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()
96 if (ls->t.token == c) { in testnext()
108 if (ls->t.token != c) in check()
132 if (where == ls->linenumber) /* all in the same line? */ in check_match()
135 luaX_syntaxerror(ls, luaO_pushfstring(ls->L, in check_match()
146 ts = ls->t.seminfo.ts; in str_checkname()
153 e->f = e->t = NO_JUMP; in init_exp()
154 e->k = k; in init_exp()
155 e->u.info = i; in init_exp()
160 e->f = e->t = NO_JUMP; in codestring()
161 e->k = VKSTR; in codestring()
162 e->u.strval = s; in codestring()
176 Proto *f = fs->f; in registerlocalvar()
177 int oldsize = f->sizelocvars; in registerlocalvar()
178 luaM_growvector(ls->L, f->locvars, fs->ndebugvars, f->sizelocvars, in registerlocalvar()
180 while (oldsize < f->sizelocvars) in registerlocalvar()
181 f->locvars[oldsize++].varname = NULL; in registerlocalvar()
182 f->locvars[fs->ndebugvars].varname = varname; in registerlocalvar()
183 f->locvars[fs->ndebugvars].startpc = fs->pc; in registerlocalvar()
184 luaC_objbarrier(ls->L, f, varname); in registerlocalvar()
185 return fs->ndebugvars++; in registerlocalvar()
194 lua_State *L = ls->L; in new_localvar()
195 FuncState *fs = ls->fs; in new_localvar()
196 Dyndata *dyd = ls->dyd; in new_localvar()
198 checklimit(fs, dyd->actvar.n + 1 - fs->firstlocal, in new_localvar()
200 luaM_growvector(L, dyd->actvar.arr, dyd->actvar.n + 1, in new_localvar()
201 dyd->actvar.size, Vardesc, USHRT_MAX, "local variables"); in new_localvar()
202 var = &dyd->actvar.arr[dyd->actvar.n++]; in new_localvar()
203 var->vd.kind = VDKREG; /* default */ in new_localvar()
204 var->vd.name = name; in new_localvar()
205 return dyd->actvar.n - 1 - fs->firstlocal; in new_localvar()
210 luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char)) - 1));
220 return &fs->ls->dyd->actvar.arr[fs->firstlocal + vidx]; in getlocalvardesc()
230 while (nvar-- > 0) { in reglevel()
232 if (vd->vd.kind != RDKCTC) /* is in a register? */ in reglevel()
233 return vd->vd.ridx + 1; in reglevel()
244 return reglevel(fs, fs->nactvar); in luaY_nvarstack()
249 ** Get the debug-information entry for current variable 'vidx'.
253 if (vd->vd.kind == RDKCTC) in localdebuginfo()
256 int idx = vd->vd.pidx; in localdebuginfo()
257 lua_assert(idx < fs->ndebugvars); in localdebuginfo()
258 return &fs->f->locvars[idx]; in localdebuginfo()
267 e->f = e->t = NO_JUMP; in init_var()
268 e->k = VLOCAL; in init_var()
269 e->u.var.vidx = vidx; in init_var()
270 e->u.var.ridx = getlocalvardesc(fs, vidx)->vd.ridx; in init_var()
278 FuncState *fs = ls->fs; in check_readonly()
280 switch (e->k) { in check_readonly()
282 varname = ls->dyd->actvar.arr[e->u.info].vd.name; in check_readonly()
286 Vardesc *vardesc = getlocalvardesc(fs, e->u.var.vidx); in check_readonly()
287 if (vardesc->vd.kind != VDKREG) /* not a regular variable? */ in check_readonly()
288 varname = vardesc->vd.name; in check_readonly()
292 Upvaldesc *up = &fs->f->upvalues[e->u.info]; in check_readonly()
293 if (up->kind != VDKREG) in check_readonly()
294 varname = up->name; in check_readonly()
298 return; /* other cases cannot be read-only */ in check_readonly()
301 const char *msg = luaO_pushfstring(ls->L, in check_readonly()
312 FuncState *fs = ls->fs; in adjustlocalvars()
316 int vidx = fs->nactvar++; in adjustlocalvars()
318 var->vd.ridx = reglevel++; in adjustlocalvars()
319 var->vd.pidx = registerlocalvar(ls, fs, var->vd.name); in adjustlocalvars()
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()
344 Upvaldesc *up = fs->f->upvalues; in searchupvalue()
345 for (i = 0; i < fs->nups; i++) { in searchupvalue()
348 return -1; /* not found */ in searchupvalue()
353 Proto *f = fs->f; in allocupvalue()
354 int oldsize = f->sizeupvalues; 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()
358 while (oldsize < f->sizeupvalues) in allocupvalue()
359 f->upvalues[oldsize++].name = NULL; in allocupvalue()
360 return &f->upvalues[fs->nups++]; in allocupvalue()
366 FuncState *prev = fs->prev; in newupvalue()
367 if (v->k == VLOCAL) { in newupvalue()
368 up->instack = 1; in newupvalue()
369 up->idx = v->u.var.ridx; in newupvalue()
370 up->kind = getlocalvardesc(prev, v->u.var.vidx)->vd.kind; in newupvalue()
371 lua_assert(eqstr(name, getlocalvardesc(prev, v->u.var.vidx)->vd.name)); in newupvalue()
374 up->instack = 0; in newupvalue()
375 up->idx = cast_byte(v->u.info); in newupvalue()
376 up->kind = prev->f->upvalues[v->u.info].kind; in newupvalue()
377 lua_assert(eqstr(name, prev->f->upvalues[v->u.info].name)); in newupvalue()
379 up->name = name; in newupvalue()
380 luaC_objbarrier(fs->ls->L, fs->f, name); in newupvalue()
381 return fs->nups - 1; in newupvalue()
388 ** its expression kind; otherwise return -1.
392 for (i = cast_int(fs->nactvar) - 1; i >= 0; i--) { in searchvar()
394 if (eqstr(n, vd->vd.name)) { /* found? */ in searchvar()
395 if (vd->vd.kind == RDKCTC) /* compile-time constant? */ in searchvar()
396 init_exp(var, VCONST, fs->firstlocal + i); in searchvar()
399 return var->k; in searchvar()
402 return -1; /* not found */ in searchvar()
411 BlockCnt *bl = fs->bl; in markupval() local
412 while (bl->nactvar > level) in markupval()
413 bl = bl->previous; in markupval()
414 bl->upval = 1; in markupval()
415 fs->needclose = 1; in markupval()
420 ** Mark that current block has a to-be-closed variable.
423 BlockCnt *bl = fs->bl; in marktobeclosed() local
424 bl->upval = 1; in marktobeclosed()
425 bl->insidetbc = 1; in marktobeclosed()
426 fs->needclose = 1; in marktobeclosed()
442 markupval(fs, var->u.var.vidx); /* local will be used as an upval */ in singlevaraux()
447 singlevaraux(fs->prev, n, var, 0); /* try upper levels */ in singlevaraux()
448 if (var->k == VLOCAL || var->k == VUPVAL) /* local or upvalue? */ in singlevaraux()
465 FuncState *fs = ls->fs; in singlevar()
467 if (var->k == VVOID) { /* global name? */ in singlevar()
469 singlevaraux(fs, ls->envn, var, 1); /* get environment variable */ in singlevar()
470 lua_assert(var->k != VVOID); /* this one must exist */ in singlevar()
483 FuncState *fs = ls->fs; in adjust_assign()
484 int needed = nvars - nexps; /* extra values needed */ in adjust_assign()
485 if (hasmultret(e->k)) { /* last expression has multiple returns? */ in adjust_assign()
492 if (e->k != VVOID) /* at least one expression? */ in adjust_assign()
495 luaK_nil(fs, fs->freereg, needed); /* complete with nils */ in adjust_assign()
500 fs->freereg += needed; /* remove extra values */ in adjust_assign()
504 #define enterlevel(ls) luaE_incCstack(ls->L)
507 #define leavelevel(ls) ((ls)->L->nCcalls--)
515 const char *varname = getstr(getlocalvardesc(ls->fs, gt->nactvar)->vd.name); in jumpscopeerror()
517 msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line, varname); in jumpscopeerror()
529 Labellist *gl = &ls->dyd->gt; /* list of gotos */ in solvegoto()
530 Labeldesc *gt = &gl->arr[g]; /* goto to be resolved */ in solvegoto()
531 lua_assert(eqstr(gt->name, label->name)); in solvegoto()
532 if (l_unlikely(gt->nactvar < label->nactvar)) /* enter some scope? */ in solvegoto()
534 luaK_patchlist(ls->fs, gt->pc, label->pc); in solvegoto()
535 for (i = g; i < gl->n - 1; i++) /* remove goto from pending list */ in solvegoto()
536 gl->arr[i] = gl->arr[i + 1]; in solvegoto()
537 gl->n--; in solvegoto()
546 Dyndata *dyd = ls->dyd; in findlabel()
548 for (i = ls->fs->firstlabel; i < dyd->label.n; i++) { in findlabel()
549 Labeldesc *lb = &dyd->label.arr[i]; in findlabel()
550 if (eqstr(lb->name, name)) /* correct label? */ in findlabel()
562 int n = l->n; in newlabelentry()
563 luaM_growvector(ls->L, l->arr, n, l->size, in newlabelentry()
565 l->arr[n].name = name; in newlabelentry()
566 l->arr[n].line = line; in newlabelentry()
567 l->arr[n].nactvar = ls->fs->nactvar; in newlabelentry()
568 l->arr[n].close = 0; in newlabelentry()
569 l->arr[n].pc = pc; in newlabelentry()
570 l->n = n + 1; in newlabelentry()
576 return newlabelentry(ls, &ls->dyd->gt, name, line, pc); in newgotoentry()
586 Labellist *gl = &ls->dyd->gt; in solvegotos()
587 int i = ls->fs->bl->firstgoto; in solvegotos()
589 while (i < gl->n) { in solvegotos()
590 if (eqstr(gl->arr[i].name, lb->name)) { in solvegotos()
591 needsclose |= gl->arr[i].close; in solvegotos()
603 ** 'last' tells whether label is the last non-op statement in its
610 FuncState *fs = ls->fs; in createlabel()
611 Labellist *ll = &ls->dyd->label; in createlabel()
613 if (last) { /* label is last no-op statement in the block? */ in createlabel()
615 ll->arr[l].nactvar = fs->bl->nactvar; in createlabel()
617 if (solvegotos(ls, &ll->arr[l])) { /* need close? */ in createlabel()
628 static void movegotosout (FuncState *fs, BlockCnt *bl) { in movegotosout() argument
630 Labellist *gl = &fs->ls->dyd->gt; in movegotosout()
632 for (i = bl->firstgoto; i < gl->n; i++) { /* for each pending goto */ in movegotosout()
633 Labeldesc *gt = &gl->arr[i]; in movegotosout()
635 if (reglevel(fs, gt->nactvar) > reglevel(fs, bl->nactvar)) in movegotosout()
636 gt->close |= bl->upval; /* jump may need a close */ in movegotosout()
637 gt->nactvar = bl->nactvar; /* update goto level */ in movegotosout()
642 static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isloop) { in enterblock() argument
643 bl->isloop = isloop; in enterblock()
644 bl->nactvar = fs->nactvar; in enterblock()
645 bl->firstlabel = fs->ls->dyd->label.n; in enterblock()
646 bl->firstgoto = fs->ls->dyd->gt.n; in enterblock()
647 bl->upval = 0; in enterblock()
648 bl->insidetbc = (fs->bl != NULL && fs->bl->insidetbc); in enterblock()
649 bl->previous = fs->bl; in enterblock()
650 fs->bl = bl; in enterblock()
651 lua_assert(fs->freereg == luaY_nvarstack(fs)); in enterblock()
660 if (eqstr(gt->name, luaS_newliteral(ls->L, "break"))) { in undefgoto()
662 msg = luaO_pushfstring(ls->L, msg, gt->line); in undefgoto()
666 msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line); in undefgoto()
673 BlockCnt *bl = fs->bl; in leaveblock() local
674 LexState *ls = fs->ls; in leaveblock()
676 int stklevel = reglevel(fs, bl->nactvar); /* level outside the block */ in leaveblock()
677 removevars(fs, bl->nactvar); /* remove block locals */ in leaveblock()
678 lua_assert(bl->nactvar == fs->nactvar); /* back to level on entry */ in leaveblock()
679 if (bl->isloop) /* has to fix pending breaks? */ in leaveblock()
680 hasclose = createlabel(ls, luaS_newliteral(ls->L, "break"), 0, 0); in leaveblock()
681 if (!hasclose && bl->previous && bl->upval) /* still need a 'close'? */ in leaveblock()
683 fs->freereg = stklevel; /* free registers */ in leaveblock()
684 ls->dyd->label.n = bl->firstlabel; /* remove local labels */ in leaveblock()
685 fs->bl = bl->previous; /* current block now is previous one */ in leaveblock()
686 if (bl->previous) /* was it a nested block? */ in leaveblock()
687 movegotosout(fs, bl); /* update pending gotos to enclosing block */ in leaveblock()
689 if (bl->firstgoto < ls->dyd->gt.n) /* still pending gotos? */ in leaveblock()
690 undefgoto(ls, &ls->dyd->gt.arr[bl->firstgoto]); /* error */ in leaveblock()
700 lua_State *L = ls->L; in addprototype()
701 FuncState *fs = ls->fs; in addprototype()
702 Proto *f = fs->f; /* prototype of current function */ in addprototype()
703 if (fs->np >= f->sizep) { in addprototype()
704 int oldsize = f->sizep; in addprototype()
705 luaM_growvector(L, f->p, fs->np, f->sizep, Proto *, MAXARG_Bx, "functions"); in addprototype()
706 while (oldsize < f->sizep) in addprototype()
707 f->p[oldsize++] = NULL; in addprototype()
709 f->p[fs->np++] = clp = luaF_newproto(L); in addprototype()
723 FuncState *fs = ls->fs->prev; in codeclosure()
724 init_exp(v, VRELOC, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np - 1)); in codeclosure()
729 static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) { in open_func() argument
730 Proto *f = fs->f; in open_func()
731 fs->prev = ls->fs; /* linked list of funcstates */ in open_func()
732 fs->ls = ls; in open_func()
733 ls->fs = fs; in open_func()
734 fs->pc = 0; in open_func()
735 fs->previousline = f->linedefined; in open_func()
736 fs->iwthabs = 0; in open_func()
737 fs->lasttarget = 0; in open_func()
738 fs->freereg = 0; in open_func()
739 fs->nk = 0; in open_func()
740 fs->nabslineinfo = 0; in open_func()
741 fs->np = 0; in open_func()
742 fs->nups = 0; in open_func()
743 fs->ndebugvars = 0; in open_func()
744 fs->nactvar = 0; in open_func()
745 fs->needclose = 0; in open_func()
746 fs->firstlocal = ls->dyd->actvar.n; in open_func()
747 fs->firstlabel = ls->dyd->label.n; in open_func()
748 fs->bl = NULL; in open_func()
749 f->source = ls->source; in open_func()
750 luaC_objbarrier(ls->L, f, f->source); in open_func()
751 f->maxstacksize = 2; /* registers 0/1 are always valid */ in open_func()
752 enterblock(fs, bl, 0); in open_func()
757 lua_State *L = ls->L; in close_func()
758 FuncState *fs = ls->fs; in close_func()
759 Proto *f = fs->f; in close_func()
762 lua_assert(fs->bl == NULL); in close_func()
764 luaM_shrinkvector(L, f->code, f->sizecode, fs->pc, Instruction); in close_func()
765 luaM_shrinkvector(L, f->lineinfo, f->sizelineinfo, fs->pc, ls_byte); in close_func()
766 luaM_shrinkvector(L, f->abslineinfo, f->sizeabslineinfo, in close_func()
767 fs->nabslineinfo, AbsLineInfo); in close_func()
768 luaM_shrinkvector(L, f->k, f->sizek, fs->nk, TValue); in close_func()
769 luaM_shrinkvector(L, f->p, f->sizep, fs->np, Proto *); in close_func()
770 luaM_shrinkvector(L, f->locvars, f->sizelocvars, fs->ndebugvars, LocVar); in close_func()
771 luaM_shrinkvector(L, f->upvalues, f->sizeupvalues, fs->nups, Upvaldesc); in close_func()
772 ls->fs = fs->prev; in close_func()
789 switch (ls->t.token) { in block_follow()
800 /* statlist -> { stat [';'] } */ in statlist()
802 if (ls->t.token == TK_RETURN) { in statlist()
812 /* fieldsel -> ['.' | ':'] NAME */ in fieldsel()
813 FuncState *fs = ls->fs; in fieldsel()
823 /* index -> '[' expr ']' */ in yindex()
826 luaK_exp2val(ls->fs, v); in yindex()
848 /* recfield -> (NAME | '['exp']') = exp */ in recfield()
849 FuncState *fs = ls->fs; in recfield()
850 int reg = ls->fs->freereg; in recfield()
852 if (ls->t.token == TK_NAME) { in recfield()
853 checklimit(fs, cc->nh, MAX_INT, "items in a constructor"); in recfield()
856 else /* ls->t.token == '[' */ in recfield()
858 cc->nh++; in recfield()
860 tab = *cc->t; in recfield()
864 fs->freereg = reg; /* free registers */ in recfield()
869 if (cc->v.k == VVOID) return; /* there is no list item */ in closelistfield()
870 luaK_exp2nextreg(fs, &cc->v); in closelistfield()
871 cc->v.k = VVOID; in closelistfield()
872 if (cc->tostore == LFIELDS_PER_FLUSH) { in closelistfield()
873 luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore); /* flush */ in closelistfield()
874 cc->na += cc->tostore; in closelistfield()
875 cc->tostore = 0; /* no more items pending */ in closelistfield()
881 if (cc->tostore == 0) return; in lastlistfield()
882 if (hasmultret(cc->v.k)) { in lastlistfield()
883 luaK_setmultret(fs, &cc->v); in lastlistfield()
884 luaK_setlist(fs, cc->t->u.info, cc->na, LUA_MULTRET); in lastlistfield()
885 cc->na--; /* do not count last expression (unknown number of elements) */ in lastlistfield()
888 if (cc->v.k != VVOID) in lastlistfield()
889 luaK_exp2nextreg(fs, &cc->v); in lastlistfield()
890 luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore); in lastlistfield()
892 cc->na += cc->tostore; in lastlistfield()
897 /* listfield -> exp */ in listfield()
898 expr(ls, &cc->v); in listfield()
899 cc->tostore++; in listfield()
904 /* field -> listfield | recfield */ in field()
905 switch(ls->t.token) { in field()
926 /* constructor -> '{' [ field { sep field } [sep] ] '}' in constructor()
927 sep -> ',' | ';' */ in constructor()
928 FuncState *fs = ls->fs; in constructor()
929 int line = ls->linenumber; in constructor()
935 init_exp(t, VNONRELOC, fs->freereg); /* table will be at stack top */ in constructor()
941 if (ls->t.token == '}') break; in constructor()
947 luaK_settablesize(fs, pc, t->u.info, cc.na, cc.nh); in constructor()
954 fs->f->is_vararg = 1; in setvararg()
960 /* parlist -> [ {NAME ','} (NAME | '...') ] */ in parlist()
961 FuncState *fs = ls->fs; in parlist()
962 Proto *f = fs->f; in parlist()
965 if (ls->t.token != ')') { /* is 'parlist' not empty? */ in parlist()
967 switch (ls->t.token) { in parlist()
983 f->numparams = cast_byte(fs->nactvar); in parlist()
985 setvararg(fs, f->numparams); /* declared vararg */ in parlist()
986 luaK_reserveregs(fs, fs->nactvar); /* reserve registers for parameters */ in parlist()
991 /* body -> '(' parlist ')' block END */ in body()
993 BlockCnt bl; in body() local
995 new_fs.f->linedefined = line; in body()
996 open_func(ls, &new_fs, &bl); in body()
1005 new_fs.f->lastlinedefined = ls->linenumber; in body()
1013 /* explist -> expr { ',' expr } */ in explist()
1017 luaK_exp2nextreg(ls->fs, v); in explist()
1026 FuncState *fs = ls->fs; in funcargs()
1029 switch (ls->t.token) { in funcargs()
1030 case '(': { /* funcargs -> '(' [ explist ] ')' */ in funcargs()
1032 if (ls->t.token == ')') /* arg list is empty? */ in funcargs()
1042 case '{': { /* funcargs -> constructor */ in funcargs()
1046 case TK_STRING: { /* funcargs -> STRING */ in funcargs()
1047 codestring(&args, ls->t.seminfo.ts); in funcargs()
1055 lua_assert(f->k == VNONRELOC); in funcargs()
1056 base = f->u.info; /* base register for call */ in funcargs()
1062 nparams = fs->freereg - (base+1); in funcargs()
1066 fs->freereg = base+1; /* call remove function and arguments and leaves in funcargs()
1081 /* primaryexp -> NAME | '(' expr ')' */ in primaryexp()
1082 switch (ls->t.token) { in primaryexp()
1084 int line = ls->linenumber; in primaryexp()
1088 luaK_dischargevars(ls->fs, v); in primaryexp()
1103 /* suffixedexp -> in suffixedexp()
1105 FuncState *fs = ls->fs; in suffixedexp()
1106 int line = ls->linenumber; in suffixedexp()
1109 switch (ls->t.token) { in suffixedexp()
1141 /* simpleexp -> FLT | INT | STRING | NIL | TRUE | FALSE | ... | in simpleexp()
1143 switch (ls->t.token) { in simpleexp()
1146 v->u.nval = ls->t.seminfo.r; in simpleexp()
1151 v->u.ival = ls->t.seminfo.i; in simpleexp()
1155 codestring(v, ls->t.seminfo.ts); in simpleexp()
1171 FuncState *fs = ls->fs; in simpleexp()
1172 check_condition(ls, fs->f->is_vararg, in simpleexp()
1183 body(ls, v, 0, ls->linenumber); in simpleexp()
1198 case '-': return OPR_MINUS; in getunopr()
1209 case '-': return OPR_SUB; in getbinopr()
1241 {10, 10}, {10, 10}, /* '+' '-' */
1257 ** subexpr -> (simpleexp | unop subexpr) { binop subexpr }
1264 uop = getunopr(ls->t.token); in subexpr()
1266 int line = ls->linenumber; in subexpr()
1269 luaK_prefix(ls->fs, uop, v, line); in subexpr()
1273 op = getbinopr(ls->t.token); in subexpr()
1277 int line = ls->linenumber; in subexpr()
1279 luaK_infix(ls->fs, op, v); in subexpr()
1280 /* read sub-expression with higher priority */ in subexpr()
1282 luaK_posfix(ls->fs, op, v, &v2, line); in subexpr()
1306 /* block -> statlist */ in block()
1307 FuncState *fs = ls->fs; in block()
1308 BlockCnt bl; in block() local
1309 enterblock(fs, &bl, 0); in block()
1316 ** structure to chain all variables in the left-hand side of an
1332 FuncState *fs = ls->fs; in check_conflict()
1333 int extra = fs->freereg; /* eventual position to save local variable */ in check_conflict()
1335 for (; lh; lh = lh->prev) { /* check all previous assignments */ in check_conflict()
1336 if (vkisindexed(lh->v.k)) { /* assignment to table field? */ in check_conflict()
1337 if (lh->v.k == VINDEXUP) { /* is table an upvalue? */ in check_conflict()
1338 if (v->k == VUPVAL && lh->v.u.ind.t == v->u.info) { in check_conflict()
1340 lh->v.k = VINDEXSTR; in check_conflict()
1341 lh->v.u.ind.t = extra; /* assignment will use safe copy */ in check_conflict()
1345 if (v->k == VLOCAL && lh->v.u.ind.t == v->u.var.ridx) { in check_conflict()
1347 lh->v.u.ind.t = extra; /* assignment will use safe copy */ in check_conflict()
1350 if (lh->v.k == VINDEXED && v->k == VLOCAL && in check_conflict()
1351 lh->v.u.ind.idx == v->u.var.ridx) { in check_conflict()
1353 lh->v.u.ind.idx = extra; /* previous assignment will use safe copy */ in check_conflict()
1360 if (v->k == VLOCAL) in check_conflict()
1361 luaK_codeABC(fs, OP_MOVE, extra, v->u.var.ridx, 0); in check_conflict()
1363 luaK_codeABC(fs, OP_GETUPVAL, extra, v->u.info, 0); in check_conflict()
1372 ** assignment -> suffixedexp restassign
1373 ** restassign -> ',' suffixedexp restassign | '=' explist
1377 check_condition(ls, vkisvar(lh->v.k), "syntax error"); in restassign()
1378 check_readonly(ls, &lh->v); in restassign()
1379 if (testnext(ls, ',')) { /* restassign -> ',' suffixedexp restassign */ in restassign()
1389 else { /* restassign -> '=' explist */ in restassign()
1396 luaK_setoneret(ls->fs, &e); /* close last expression */ in restassign()
1397 luaK_storevar(ls->fs, &lh->v, &e); in restassign()
1401 init_exp(&e, VNONRELOC, ls->fs->freereg-1); /* default assignment */ in restassign()
1402 luaK_storevar(ls->fs, &lh->v, &e); in restassign()
1407 /* cond -> exp */ in cond()
1411 luaK_goiftrue(ls->fs, &v); in cond()
1417 FuncState *fs = ls->fs; in gotostat()
1418 int line = ls->linenumber; in gotostat()
1426 int lblevel = reglevel(fs, lb->nactvar); /* label level */ in gotostat()
1430 luaK_patchlist(fs, luaK_jump(fs), lb->pc); in gotostat()
1439 int line = ls->linenumber; in breakstat()
1441 newgotoentry(ls, luaS_newliteral(ls->L, "break"), line, luaK_jump(ls->fs)); in breakstat()
1452 msg = luaO_pushfstring(ls->L, msg, getstr(name), lb->line); in checkrepeated()
1459 /* label -> '::' NAME '::' */ in labelstat()
1461 while (ls->t.token == ';' || ls->t.token == TK_DBCOLON) in labelstat()
1462 statement(ls); /* skip other no-op statements */ in labelstat()
1469 /* whilestat -> WHILE cond DO block END */ in whilestat()
1470 FuncState *fs = ls->fs; in whilestat()
1473 BlockCnt bl; in whilestat() local
1477 enterblock(fs, &bl, 1); in whilestat()
1488 /* repeatstat -> REPEAT block UNTIL cond */ in repeatstat()
1490 FuncState *fs = ls->fs; in repeatstat()
1513 ** Read an expression and generate code to put its results in next
1520 luaK_exp2nextreg(ls->fs, &e); in exp1()
1531 Instruction *jmp = &fs->f->code[pc]; in fixforjump()
1532 int offset = dest - (pc + 1); in fixforjump() local
1534 offset = -offset; in fixforjump()
1535 if (l_unlikely(offset > MAXARG_Bx)) in fixforjump()
1536 luaX_syntaxerror(fs->ls, "control structure too long"); in fixforjump()
1537 SETARG_Bx(*jmp, offset); in fixforjump()
1542 ** Generate code for a 'for' loop.
1545 /* forbody -> DO block */ in forbody()
1548 BlockCnt bl; in forbody() local
1549 FuncState *fs = ls->fs; in forbody()
1553 enterblock(fs, &bl, 0); /* scope for declared variables */ in forbody()
1570 /* fornum -> NAME = exp,exp[,exp] forbody */ in fornum()
1571 FuncState *fs = ls->fs; in fornum()
1572 int base = fs->freereg; in fornum()
1584 luaK_int(fs, fs->freereg, 1); in fornum()
1593 /* forlist -> NAME {,NAME} IN explist forbody */ in forlist()
1594 FuncState *fs = ls->fs; in forlist()
1598 int base = fs->freereg; in forlist()
1611 line = ls->linenumber; in forlist()
1616 forbody(ls, base, line, nvars - 4, 1); in forlist()
1621 /* forstat -> FOR (fornum | forlist) END */ in forstat()
1622 FuncState *fs = ls->fs; in forstat()
1624 BlockCnt bl; in forstat() local
1625 enterblock(fs, &bl, 1); /* scope for loop and control variables */ in forstat()
1628 switch (ls->t.token) { in forstat()
1639 /* test_then_block -> [IF | ELSEIF] cond THEN block */ in test_then_block()
1640 BlockCnt bl; in test_then_block() local
1641 FuncState *fs = ls->fs; in test_then_block()
1643 int jf; /* instruction to skip 'then' code (if condition is false) */ in test_then_block()
1647 if (ls->t.token == TK_BREAK) { /* 'if x then break' ? */ in test_then_block()
1648 int line = ls->linenumber; in test_then_block()
1649 luaK_goiffalse(ls->fs, &v); /* will jump if condition is true */ in test_then_block()
1651 enterblock(fs, &bl, 0); /* must enter block before 'goto' */ in test_then_block()
1652 newgotoentry(ls, luaS_newliteral(ls->L, "break"), line, v.t); in test_then_block()
1662 luaK_goiftrue(ls->fs, &v); /* skip over block if condition is false */ in test_then_block()
1663 enterblock(fs, &bl, 0); in test_then_block()
1668 if (ls->t.token == TK_ELSE || in test_then_block()
1669 ls->t.token == TK_ELSEIF) /* followed by 'else'/'elseif'? */ in test_then_block()
1676 /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */ in ifstat()
1677 FuncState *fs = ls->fs; in ifstat()
1680 while (ls->t.token == TK_ELSEIF) in ifstat()
1691 FuncState *fs = ls->fs; in localfunc()
1692 int fvar = fs->nactvar; /* function's variable index */ in localfunc()
1695 body(ls, &b, 0, ls->linenumber); /* function created in next register */ in localfunc()
1697 localdebuginfo(fs, fvar)->startpc = fs->pc; in localfunc()
1702 /* ATTRIB -> ['<' Name '>'] */ in getlocalattribute()
1707 return RDKCONST; /* read-only variable */ in getlocalattribute()
1709 return RDKTOCLOSE; /* to-be-closed variable */ in getlocalattribute()
1712 luaO_pushfstring(ls->L, "unknown attribute '%s'", attr)); in getlocalattribute()
1719 if (level != -1) { /* is there a to-be-closed variable? */ in checktoclose()
1727 /* stat -> LOCAL NAME ATTRIB { ',' NAME ATTRIB } ['=' explist] */ in localstat()
1728 FuncState *fs = ls->fs; in localstat()
1729 int toclose = -1; /* index of to-be-closed variable (if any) */ in localstat()
1738 getlocalvardesc(fs, vidx)->vd.kind = kind; in localstat()
1739 if (kind == RDKTOCLOSE) { /* to-be-closed? */ in localstat()
1740 if (toclose != -1) /* one already present? */ in localstat()
1741 luaK_semerror(ls, "multiple to-be-closed variables in local list"); in localstat()
1742 toclose = fs->nactvar + nvars; in localstat()
1754 var->vd.kind == RDKCONST && /* last variable is const? */ in localstat()
1755 luaK_exp2const(fs, &e, &var->k)) { /* compile-time constant? */ in localstat()
1756 var->vd.kind = RDKCTC; /* variable is a compile-time constant */ in localstat()
1757 adjustlocalvars(ls, nvars - 1); /* exclude last variable */ in localstat()
1758 fs->nactvar++; /* but count it */ in localstat()
1769 /* funcname -> NAME {fieldsel} [':' NAME] */ in funcname()
1772 while (ls->t.token == '.') in funcname()
1774 if (ls->t.token == ':') { in funcname()
1783 /* funcstat -> FUNCTION funcname body */ in funcstat()
1790 luaK_storevar(ls->fs, &v, &b); in funcstat()
1791 luaK_fixline(ls->fs, line); /* definition "happens" in the first line */ in funcstat()
1796 /* stat -> func | assignment */ in exprstat()
1797 FuncState *fs = ls->fs; in exprstat()
1800 if (ls->t.token == '=' || ls->t.token == ',') { /* stat -> assignment ? */ in exprstat()
1804 else { /* stat -> func */ in exprstat()
1814 /* stat -> RETURN [explist] [';'] */ in retstat()
1815 FuncState *fs = ls->fs; in retstat()
1819 if (block_follow(ls, 1) || ls->t.token == ';') in retstat()
1825 if (e.k == VCALL && nret == 1 && !fs->bl->insidetbc) { /* tail call? */ in retstat()
1836 lua_assert(nret == fs->freereg - first); in retstat()
1846 int line = ls->linenumber; /* may be needed for error messages */ in statement()
1848 switch (ls->t.token) { in statement()
1849 case ';': { /* stat -> ';' (empty statement) */ in statement()
1853 case TK_IF: { /* stat -> ifstat */ in statement()
1857 case TK_WHILE: { /* stat -> whilestat */ in statement()
1861 case TK_DO: { /* stat -> DO block END */ in statement()
1867 case TK_FOR: { /* stat -> forstat */ in statement()
1871 case TK_REPEAT: { /* stat -> repeatstat */ in statement()
1875 case TK_FUNCTION: { /* stat -> funcstat */ in statement()
1879 case TK_LOCAL: { /* stat -> localstat */ in statement()
1887 case TK_DBCOLON: { /* stat -> label */ in statement()
1892 case TK_RETURN: { /* stat -> retstat */ in statement()
1897 case TK_BREAK: { /* stat -> breakstat */ in statement()
1901 case TK_GOTO: { /* stat -> 'goto' NAME */ in statement()
1906 default: { /* stat -> func | assignment */ in statement()
1911 lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg && in statement()
1912 ls->fs->freereg >= luaY_nvarstack(ls->fs)); in statement()
1913 ls->fs->freereg = luaY_nvarstack(ls->fs); /* free registers */ in statement()
1925 BlockCnt bl; in mainfunc() local
1927 open_func(ls, fs, &bl); in mainfunc()
1930 env->instack = 1; in mainfunc()
1931 env->idx = 0; in mainfunc()
1932 env->kind = VDKREG; in mainfunc()
1933 env->name = ls->envn; in mainfunc()
1934 luaC_objbarrier(ls->L, fs->f, env->name); in mainfunc()
1947 setclLvalue2s(L, L->top.p, cl); /* anchor it (to avoid being collected) */ in luaY_parser()
1950 sethvalue2s(L, L->top.p, lexstate.h); /* anchor it */ in luaY_parser()
1952 funcstate.f = cl->p = luaF_newproto(L); in luaY_parser()
1953 luaC_objbarrier(L, cl, cl->p); in luaY_parser()
1954 funcstate.f->source = luaS_new(L, name); /* create and anchor TString */ in luaY_parser()
1955 luaC_objbarrier(L, funcstate.f, funcstate.f->source); in luaY_parser()
1958 dyd->actvar.n = dyd->gt.n = dyd->label.n = 0; in luaY_parser()
1959 luaX_setinput(L, &lexstate, z, funcstate.f->source, firstchar); in luaY_parser()
1963 lua_assert(dyd->actvar.n == 0 && dyd->gt.n == 0 && dyd->label.n == 0); in luaY_parser()
1964 L->top.p--; /* remove scanner's table */ in luaY_parser()