Lines Matching +full:- +full:fs

60 ** prototypes for recursive non-terminal functions
68 ls->t.token = 0; /* remove "near <token>" from final message */ in semerror()
75 luaO_pushfstring(ls->L, "%s expected", luaX_token2str(ls, token))); in error_expected()
79 static l_noret errorlimit (FuncState *fs, int limit, const char *what) { in errorlimit() argument
80 lua_State *L = fs->ls->L; in errorlimit()
82 int line = fs->f->linedefined; in errorlimit()
88 luaX_syntaxerror(fs->ls, msg); in errorlimit()
92 static void checklimit (FuncState *fs, int v, int l, const char *what) { in checklimit() argument
93 if (v > l) errorlimit(fs, l, what); in checklimit()
98 if (ls->t.token == c) { in testnext()
107 if (ls->t.token != c) in check()
124 if (where == ls->linenumber) in check_match()
127 luaX_syntaxerror(ls, luaO_pushfstring(ls->L, in check_match()
138 ts = ls->t.seminfo.ts; in str_checkname()
145 e->f = e->t = NO_JUMP; in init_exp()
146 e->k = k; in init_exp()
147 e->u.info = i; in init_exp()
152 init_exp(e, VK, luaK_stringK(ls->fs, s)); in codestring()
162 FuncState *fs = ls->fs; in registerlocalvar() local
163 Proto *f = fs->f; in registerlocalvar()
164 int oldsize = f->sizelocvars; in registerlocalvar()
165 luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars, in registerlocalvar()
167 while (oldsize < f->sizelocvars) in registerlocalvar()
168 f->locvars[oldsize++].varname = NULL; in registerlocalvar()
169 f->locvars[fs->nlocvars].varname = varname; in registerlocalvar()
170 luaC_objbarrier(ls->L, f, varname); in registerlocalvar()
171 return fs->nlocvars++; in registerlocalvar()
176 FuncState *fs = ls->fs; in new_localvar() local
177 Dyndata *dyd = ls->dyd; in new_localvar()
179 checklimit(fs, dyd->actvar.n + 1 - fs->firstlocal, in new_localvar()
181 luaM_growvector(ls->L, dyd->actvar.arr, dyd->actvar.n + 1, in new_localvar()
182 dyd->actvar.size, Vardesc, MAX_INT, "local variables"); in new_localvar()
183 dyd->actvar.arr[dyd->actvar.n++].idx = cast(short, reg); in new_localvar()
192 new_localvarliteral_(ls, "" v, (sizeof(v)/sizeof(char))-1)
195 static LocVar *getlocvar (FuncState *fs, int i) { in getlocvar() argument
196 int idx = fs->ls->dyd->actvar.arr[fs->firstlocal + i].idx; in getlocvar()
197 lua_assert(idx < fs->nlocvars); in getlocvar()
198 return &fs->f->locvars[idx]; in getlocvar()
203 FuncState *fs = ls->fs; in adjustlocalvars() local
204 fs->nactvar = cast_byte(fs->nactvar + nvars); in adjustlocalvars()
205 for (; nvars; nvars--) { in adjustlocalvars()
206 getlocvar(fs, fs->nactvar - nvars)->startpc = fs->pc; in adjustlocalvars()
211 static void removevars (FuncState *fs, int tolevel) { in removevars() argument
212 fs->ls->dyd->actvar.n -= (fs->nactvar - tolevel); in removevars()
213 while (fs->nactvar > tolevel) in removevars()
214 getlocvar(fs, --fs->nactvar)->endpc = fs->pc; in removevars()
218 static int searchupvalue (FuncState *fs, TString *name) { in searchupvalue() argument
220 Upvaldesc *up = fs->f->upvalues; in searchupvalue()
221 for (i = 0; i < fs->nups; i++) { in searchupvalue()
224 return -1; /* not found */ in searchupvalue()
228 static int newupvalue (FuncState *fs, TString *name, expdesc *v) { in newupvalue() argument
229 Proto *f = fs->f; in newupvalue()
230 int oldsize = f->sizeupvalues; in newupvalue()
231 checklimit(fs, fs->nups + 1, MAXUPVAL, "upvalues"); in newupvalue()
232 luaM_growvector(fs->ls->L, f->upvalues, fs->nups, f->sizeupvalues, in newupvalue()
234 while (oldsize < f->sizeupvalues) in newupvalue()
235 f->upvalues[oldsize++].name = NULL; in newupvalue()
236 f->upvalues[fs->nups].instack = (v->k == VLOCAL); in newupvalue()
237 f->upvalues[fs->nups].idx = cast_byte(v->u.info); in newupvalue()
238 f->upvalues[fs->nups].name = name; in newupvalue()
239 luaC_objbarrier(fs->ls->L, f, name); in newupvalue()
240 return fs->nups++; in newupvalue()
244 static int searchvar (FuncState *fs, TString *n) { in searchvar() argument
246 for (i = cast_int(fs->nactvar) - 1; i >= 0; i--) { in searchvar()
247 if (eqstr(n, getlocvar(fs, i)->varname)) in searchvar()
250 return -1; /* not found */ in searchvar()
258 static void markupval (FuncState *fs, int level) { in markupval() argument
259 BlockCnt *bl = fs->bl; in markupval()
260 while (bl->nactvar > level) in markupval()
261 bl = bl->previous; in markupval()
262 bl->upval = 1; in markupval()
270 static void singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) { in singlevaraux() argument
271 if (fs == NULL) /* no more levels? */ in singlevaraux()
274 int v = searchvar(fs, n); /* look up locals at current level */ in singlevaraux()
278 markupval(fs, v); /* local will be used as an upval */ in singlevaraux()
281 int idx = searchupvalue(fs, n); /* try existing upvalues */ in singlevaraux()
283 singlevaraux(fs->prev, n, var, 0); /* try upper levels */ in singlevaraux()
284 if (var->k == VVOID) /* not found? */ in singlevaraux()
287 idx = newupvalue(fs, n, var); /* will be a new upvalue */ in singlevaraux()
297 FuncState *fs = ls->fs; in singlevar() local
298 singlevaraux(fs, varname, var, 1); in singlevar()
299 if (var->k == VVOID) { /* global name? */ in singlevar()
301 singlevaraux(fs, ls->envn, var, 1); /* get environment variable */ in singlevar()
302 lua_assert(var->k != VVOID); /* this one must exist */ in singlevar()
304 luaK_indexed(fs, var, &key); /* env[varname] */ in singlevar()
310 FuncState *fs = ls->fs; in adjust_assign() local
311 int extra = nvars - nexps; in adjust_assign()
312 if (hasmultret(e->k)) { in adjust_assign()
315 luaK_setreturns(fs, e, extra); /* last exp. provides the difference */ in adjust_assign()
316 if (extra > 1) luaK_reserveregs(fs, extra-1); in adjust_assign()
319 if (e->k != VVOID) luaK_exp2nextreg(fs, e); /* close last expression */ in adjust_assign()
321 int reg = fs->freereg; in adjust_assign()
322 luaK_reserveregs(fs, extra); in adjust_assign()
323 luaK_nil(fs, reg, extra); in adjust_assign()
327 ls->fs->freereg -= nexps - nvars; /* remove extra values */ in adjust_assign()
332 lua_State *L = ls->L; in enterlevel()
333 ++L->nCcalls; in enterlevel()
334 checklimit(ls->fs, L->nCcalls, LUAI_MAXCCALLS, "C levels"); in enterlevel()
338 #define leavelevel(ls) ((ls)->L->nCcalls--)
343 FuncState *fs = ls->fs; in closegoto() local
344 Labellist *gl = &ls->dyd->gt; in closegoto()
345 Labeldesc *gt = &gl->arr[g]; in closegoto()
346 lua_assert(eqstr(gt->name, label->name)); in closegoto()
347 if (gt->nactvar < label->nactvar) { in closegoto()
348 TString *vname = getlocvar(fs, gt->nactvar)->varname; in closegoto()
349 const char *msg = luaO_pushfstring(ls->L, in closegoto()
351 getstr(gt->name), gt->line, getstr(vname)); in closegoto()
354 luaK_patchlist(fs, gt->pc, label->pc); in closegoto()
356 for (i = g; i < gl->n - 1; i++) in closegoto()
357 gl->arr[i] = gl->arr[i + 1]; in closegoto()
358 gl->n--; in closegoto()
367 BlockCnt *bl = ls->fs->bl; in findlabel()
368 Dyndata *dyd = ls->dyd; in findlabel()
369 Labeldesc *gt = &dyd->gt.arr[g]; in findlabel()
371 for (i = bl->firstlabel; i < dyd->label.n; i++) { in findlabel()
372 Labeldesc *lb = &dyd->label.arr[i]; in findlabel()
373 if (eqstr(lb->name, gt->name)) { /* correct label? */ in findlabel()
374 if (gt->nactvar > lb->nactvar && in findlabel()
375 (bl->upval || dyd->label.n > bl->firstlabel)) in findlabel()
376 luaK_patchclose(ls->fs, gt->pc, lb->nactvar); in findlabel()
387 int n = l->n; in newlabelentry()
388 luaM_growvector(ls->L, l->arr, n, l->size, in newlabelentry()
390 l->arr[n].name = name; in newlabelentry()
391 l->arr[n].line = line; in newlabelentry()
392 l->arr[n].nactvar = ls->fs->nactvar; in newlabelentry()
393 l->arr[n].pc = pc; in newlabelentry()
394 l->n = n + 1; in newlabelentry()
404 Labellist *gl = &ls->dyd->gt; in findgotos()
405 int i = ls->fs->bl->firstgoto; in findgotos()
406 while (i < gl->n) { in findgotos()
407 if (eqstr(gl->arr[i].name, lb->name)) in findgotos()
421 static void movegotosout (FuncState *fs, BlockCnt *bl) { in movegotosout() argument
422 int i = bl->firstgoto; in movegotosout()
423 Labellist *gl = &fs->ls->dyd->gt; in movegotosout()
426 while (i < gl->n) { in movegotosout()
427 Labeldesc *gt = &gl->arr[i]; in movegotosout()
428 if (gt->nactvar > bl->nactvar) { in movegotosout()
429 if (bl->upval) in movegotosout()
430 luaK_patchclose(fs, gt->pc, bl->nactvar); in movegotosout()
431 gt->nactvar = bl->nactvar; in movegotosout()
433 if (!findlabel(fs->ls, i)) in movegotosout()
439 static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isloop) { in enterblock() argument
440 bl->isloop = isloop; in enterblock()
441 bl->nactvar = fs->nactvar; in enterblock()
442 bl->firstlabel = fs->ls->dyd->label.n; in enterblock()
443 bl->firstgoto = fs->ls->dyd->gt.n; in enterblock()
444 bl->upval = 0; in enterblock()
445 bl->previous = fs->bl; in enterblock()
446 fs->bl = bl; in enterblock()
447 lua_assert(fs->freereg == fs->nactvar); in enterblock()
455 TString *n = luaS_new(ls->L, "break"); in breaklabel()
456 int l = newlabelentry(ls, &ls->dyd->label, n, 0, ls->fs->pc); in breaklabel()
457 findgotos(ls, &ls->dyd->label.arr[l]); in breaklabel()
465 const char *msg = isreserved(gt->name) in undefgoto()
468 msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line); in undefgoto()
473 static void leaveblock (FuncState *fs) { in leaveblock() argument
474 BlockCnt *bl = fs->bl; in leaveblock()
475 LexState *ls = fs->ls; in leaveblock()
476 if (bl->previous && bl->upval) { in leaveblock()
478 int j = luaK_jump(fs); in leaveblock()
479 luaK_patchclose(fs, j, bl->nactvar); in leaveblock()
480 luaK_patchtohere(fs, j); in leaveblock()
482 if (bl->isloop) in leaveblock()
484 fs->bl = bl->previous; in leaveblock()
485 removevars(fs, bl->nactvar); in leaveblock()
486 lua_assert(bl->nactvar == fs->nactvar); in leaveblock()
487 fs->freereg = fs->nactvar; /* free registers */ in leaveblock()
488 ls->dyd->label.n = bl->firstlabel; /* remove local labels */ in leaveblock()
489 if (bl->previous) /* inner block? */ in leaveblock()
490 movegotosout(fs, bl); /* update pending gotos to outer block */ in leaveblock()
491 else if (bl->firstgoto < ls->dyd->gt.n) /* pending gotos in outer block? */ in leaveblock()
492 undefgoto(ls, &ls->dyd->gt.arr[bl->firstgoto]); /* error */ in leaveblock()
501 lua_State *L = ls->L; in addprototype()
502 FuncState *fs = ls->fs; in addprototype() local
503 Proto *f = fs->f; /* prototype of current function */ in addprototype()
504 if (fs->np >= f->sizep) { in addprototype()
505 int oldsize = f->sizep; in addprototype()
506 luaM_growvector(L, f->p, fs->np, f->sizep, Proto *, MAXARG_Bx, "functions"); in addprototype()
507 while (oldsize < f->sizep) in addprototype()
508 f->p[oldsize++] = NULL; in addprototype()
510 f->p[fs->np++] = clp = luaF_newproto(L); in addprototype()
523 FuncState *fs = ls->fs->prev; in codeclosure() local
524 init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np - 1)); in codeclosure()
525 luaK_exp2nextreg(fs, v); /* fix it at the last register */ in codeclosure()
529 static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) { in open_func() argument
531 fs->prev = ls->fs; /* linked list of funcstates */ in open_func()
532 fs->ls = ls; in open_func()
533 ls->fs = fs; in open_func()
534 fs->pc = 0; in open_func()
535 fs->lasttarget = 0; in open_func()
536 fs->jpc = NO_JUMP; in open_func()
537 fs->freereg = 0; in open_func()
538 fs->nk = 0; in open_func()
539 fs->np = 0; in open_func()
540 fs->nups = 0; in open_func()
541 fs->nlocvars = 0; in open_func()
542 fs->nactvar = 0; in open_func()
543 fs->firstlocal = ls->dyd->actvar.n; in open_func()
544 fs->bl = NULL; in open_func()
545 f = fs->f; in open_func()
546 f->source = ls->source; in open_func()
547 f->maxstacksize = 2; /* registers 0/1 are always valid */ in open_func()
548 enterblock(fs, bl, 0); in open_func()
553 lua_State *L = ls->L; in close_func()
554 FuncState *fs = ls->fs; in close_func() local
555 Proto *f = fs->f; in close_func()
556 luaK_ret(fs, 0, 0); /* final return */ in close_func()
557 leaveblock(fs); in close_func()
558 luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction); in close_func()
559 f->sizecode = fs->pc; in close_func()
560 luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int); in close_func()
561 f->sizelineinfo = fs->pc; in close_func()
562 luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue); in close_func()
563 f->sizek = fs->nk; in close_func()
564 luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *); in close_func()
565 f->sizep = fs->np; in close_func()
566 luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar); in close_func()
567 f->sizelocvars = fs->nlocvars; in close_func()
568 luaM_reallocvector(L, f->upvalues, f->sizeupvalues, fs->nups, Upvaldesc); in close_func()
569 f->sizeupvalues = fs->nups; in close_func()
570 lua_assert(fs->bl == NULL); in close_func()
571 ls->fs = fs->prev; in close_func()
588 switch (ls->t.token) { in block_follow()
599 /* statlist -> { stat [';'] } */ in statlist()
601 if (ls->t.token == TK_RETURN) { in statlist()
611 /* fieldsel -> ['.' | ':'] NAME */ in fieldsel()
612 FuncState *fs = ls->fs; in fieldsel() local
614 luaK_exp2anyregup(fs, v); in fieldsel()
617 luaK_indexed(fs, v, &key); in fieldsel()
622 /* index -> '[' expr ']' */ in yindex()
625 luaK_exp2val(ls->fs, v); in yindex()
647 /* recfield -> (NAME | '['exp1']') = exp1 */ in recfield()
648 FuncState *fs = ls->fs; in recfield() local
649 int reg = ls->fs->freereg; in recfield()
652 if (ls->t.token == TK_NAME) { in recfield()
653 checklimit(fs, cc->nh, MAX_INT, "items in a constructor"); in recfield()
656 else /* ls->t.token == '[' */ in recfield()
658 cc->nh++; in recfield()
660 rkkey = luaK_exp2RK(fs, &key); in recfield()
662 luaK_codeABC(fs, OP_SETTABLE, cc->t->u.info, rkkey, luaK_exp2RK(fs, &val)); in recfield()
663 fs->freereg = reg; /* free registers */ in recfield()
667 static void closelistfield (FuncState *fs, struct ConsControl *cc) { in closelistfield() argument
668 if (cc->v.k == VVOID) return; /* there is no list item */ in closelistfield()
669 luaK_exp2nextreg(fs, &cc->v); in closelistfield()
670 cc->v.k = VVOID; in closelistfield()
671 if (cc->tostore == LFIELDS_PER_FLUSH) { in closelistfield()
672 luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore); /* flush */ in closelistfield()
673 cc->tostore = 0; /* no more items pending */ in closelistfield()
678 static void lastlistfield (FuncState *fs, struct ConsControl *cc) { in lastlistfield() argument
679 if (cc->tostore == 0) return; in lastlistfield()
680 if (hasmultret(cc->v.k)) { in lastlistfield()
681 luaK_setmultret(fs, &cc->v); in lastlistfield()
682 luaK_setlist(fs, cc->t->u.info, cc->na, LUA_MULTRET); in lastlistfield()
683 cc->na--; /* do not count last expression (unknown number of elements) */ in lastlistfield()
686 if (cc->v.k != VVOID) in lastlistfield()
687 luaK_exp2nextreg(fs, &cc->v); in lastlistfield()
688 luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore); in lastlistfield()
694 /* listfield -> exp */ in listfield()
695 expr(ls, &cc->v); in listfield()
696 checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor"); in listfield()
697 cc->na++; in listfield()
698 cc->tostore++; in listfield()
703 /* field -> listfield | recfield */ in field()
704 switch(ls->t.token) { in field()
725 /* constructor -> '{' [ field { sep field } [sep] ] '}' in constructor()
726 sep -> ',' | ';' */ in constructor()
727 FuncState *fs = ls->fs; in constructor() local
728 int line = ls->linenumber; in constructor()
729 int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0); in constructor()
735 luaK_exp2nextreg(ls->fs, t); /* fix it at stack top */ in constructor()
739 if (ls->t.token == '}') break; in constructor()
740 closelistfield(fs, &cc); in constructor()
744 lastlistfield(fs, &cc); in constructor()
745 SETARG_B(fs->f->code[pc], luaO_int2fb(cc.na)); /* set initial array size */ in constructor()
746 SETARG_C(fs->f->code[pc], luaO_int2fb(cc.nh)); /* set initial table size */ in constructor()
754 /* parlist -> [ param { ',' param } ] */ in parlist()
755 FuncState *fs = ls->fs; in parlist() local
756 Proto *f = fs->f; in parlist()
758 f->is_vararg = 0; in parlist()
759 if (ls->t.token != ')') { /* is 'parlist' not empty? */ in parlist()
761 switch (ls->t.token) { in parlist()
762 case TK_NAME: { /* param -> NAME */ in parlist()
767 case TK_DOTS: { /* param -> '...' */ in parlist()
769 f->is_vararg = 1; /* declared vararg */ in parlist()
774 } while (!f->is_vararg && testnext(ls, ',')); in parlist()
777 f->numparams = cast_byte(fs->nactvar); in parlist()
778 luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */ in parlist()
783 /* body -> '(' parlist ')' block END */ in body()
787 new_fs.f->linedefined = line; in body()
797 new_fs.f->lastlinedefined = ls->linenumber; in body()
805 /* explist -> expr { ',' expr } */ in explist()
809 luaK_exp2nextreg(ls->fs, v); in explist()
818 FuncState *fs = ls->fs; in funcargs() local
821 switch (ls->t.token) { in funcargs()
822 case '(': { /* funcargs -> '(' [ explist ] ')' */ in funcargs()
824 if (ls->t.token == ')') /* arg list is empty? */ in funcargs()
828 luaK_setmultret(fs, &args); in funcargs()
833 case '{': { /* funcargs -> constructor */ in funcargs()
837 case TK_STRING: { /* funcargs -> STRING */ in funcargs()
838 codestring(ls, &args, ls->t.seminfo.ts); in funcargs()
846 lua_assert(f->k == VNONRELOC); in funcargs()
847 base = f->u.info; /* base register for call */ in funcargs()
852 luaK_exp2nextreg(fs, &args); /* close last argument */ in funcargs()
853 nparams = fs->freereg - (base+1); in funcargs()
855 init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2)); in funcargs()
856 luaK_fixline(fs, line); in funcargs()
857 fs->freereg = base+1; /* call remove function and arguments and leaves in funcargs()
872 /* primaryexp -> NAME | '(' expr ')' */ in primaryexp()
873 switch (ls->t.token) { in primaryexp()
875 int line = ls->linenumber; in primaryexp()
879 luaK_dischargevars(ls->fs, v); in primaryexp()
894 /* suffixedexp -> in suffixedexp()
896 FuncState *fs = ls->fs; in suffixedexp() local
897 int line = ls->linenumber; in suffixedexp()
900 switch (ls->t.token) { in suffixedexp()
907 luaK_exp2anyregup(fs, v); in suffixedexp()
909 luaK_indexed(fs, v, &key); in suffixedexp()
916 luaK_self(fs, v, &key); in suffixedexp()
921 luaK_exp2nextreg(fs, v); in suffixedexp()
932 /* simpleexp -> FLT | INT | STRING | NIL | TRUE | FALSE | ... | in simpleexp()
934 switch (ls->t.token) { in simpleexp()
937 v->u.nval = ls->t.seminfo.r; in simpleexp()
942 v->u.ival = ls->t.seminfo.i; in simpleexp()
946 codestring(ls, v, ls->t.seminfo.ts); in simpleexp()
962 FuncState *fs = ls->fs; in simpleexp() local
963 check_condition(ls, fs->f->is_vararg, in simpleexp()
965 init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0)); in simpleexp()
974 body(ls, v, 0, ls->linenumber); in simpleexp()
989 case '-': return OPR_MINUS; in getunopr()
1000 case '-': return OPR_SUB; in getbinopr()
1029 {10, 10}, {10, 10}, /* '+' '-' */
1045 ** subexpr -> (simpleexp | unop subexpr) { binop subexpr }
1052 uop = getunopr(ls->t.token); in subexpr()
1054 int line = ls->linenumber; in subexpr()
1057 luaK_prefix(ls->fs, uop, v, line); in subexpr()
1061 op = getbinopr(ls->t.token); in subexpr()
1065 int line = ls->linenumber; in subexpr()
1067 luaK_infix(ls->fs, op, v); in subexpr()
1068 /* read sub-expression with higher priority */ in subexpr()
1070 luaK_posfix(ls->fs, op, v, &v2, line); in subexpr()
1094 /* block -> statlist */ in block()
1095 FuncState *fs = ls->fs; in block() local
1097 enterblock(fs, &bl, 0); in block()
1099 leaveblock(fs); in block()
1104 ** structure to chain all variables in the left-hand side of an
1120 FuncState *fs = ls->fs; in check_conflict() local
1121 int extra = fs->freereg; /* eventual position to save local variable */ in check_conflict()
1123 for (; lh; lh = lh->prev) { /* check all previous assignments */ in check_conflict()
1124 if (lh->v.k == VINDEXED) { /* assigning to a table? */ in check_conflict()
1126 if (lh->v.u.ind.vt == v->k && lh->v.u.ind.t == v->u.info) { in check_conflict()
1128 lh->v.u.ind.vt = VLOCAL; in check_conflict()
1129 lh->v.u.ind.t = extra; /* previous assignment will use safe copy */ in check_conflict()
1132 if (v->k == VLOCAL && lh->v.u.ind.idx == v->u.info) { in check_conflict()
1134 lh->v.u.ind.idx = extra; /* previous assignment will use safe copy */ in check_conflict()
1140 OpCode op = (v->k == VLOCAL) ? OP_MOVE : OP_GETUPVAL; in check_conflict()
1141 luaK_codeABC(fs, op, extra, v->u.info, 0); in check_conflict()
1142 luaK_reserveregs(fs, 1); in check_conflict()
1149 check_condition(ls, vkisvar(lh->v.k), "syntax error"); in assignment()
1150 if (testnext(ls, ',')) { /* assignment -> ',' suffixedexp assignment */ in assignment()
1156 checklimit(ls->fs, nvars + ls->L->nCcalls, LUAI_MAXCCALLS, in assignment()
1160 else { /* assignment -> '=' explist */ in assignment()
1167 luaK_setoneret(ls->fs, &e); /* close last expression */ in assignment()
1168 luaK_storevar(ls->fs, &lh->v, &e); in assignment()
1172 init_exp(&e, VNONRELOC, ls->fs->freereg-1); /* default assignment */ in assignment()
1173 luaK_storevar(ls->fs, &lh->v, &e); in assignment()
1178 /* cond -> exp */ in cond()
1182 luaK_goiftrue(ls->fs, &v); in cond()
1188 int line = ls->linenumber; in gotostat()
1195 label = luaS_new(ls->L, "break"); in gotostat()
1197 g = newlabelentry(ls, &ls->dyd->gt, label, line, pc); in gotostat()
1203 static void checkrepeated (FuncState *fs, Labellist *ll, TString *label) { in checkrepeated() argument
1205 for (i = fs->bl->firstlabel; i < ll->n; i++) { in checkrepeated()
1206 if (eqstr(label, ll->arr[i].name)) { in checkrepeated()
1207 const char *msg = luaO_pushfstring(fs->ls->L, in checkrepeated()
1209 getstr(label), ll->arr[i].line); in checkrepeated()
1210 semerror(fs->ls, msg); in checkrepeated()
1216 /* skip no-op statements */
1218 while (ls->t.token == ';' || ls->t.token == TK_DBCOLON) in skipnoopstat()
1224 /* label -> '::' NAME '::' */ in labelstat()
1225 FuncState *fs = ls->fs; in labelstat() local
1226 Labellist *ll = &ls->dyd->label; in labelstat()
1228 checkrepeated(fs, ll, label); /* check for repeated labels */ in labelstat()
1231 l = newlabelentry(ls, ll, label, line, luaK_getlabel(fs)); in labelstat()
1232 skipnoopstat(ls); /* skip other no-op statements */ in labelstat()
1233 if (block_follow(ls, 0)) { /* label is last no-op statement in the block? */ in labelstat()
1235 ll->arr[l].nactvar = fs->bl->nactvar; in labelstat()
1237 findgotos(ls, &ll->arr[l]); in labelstat()
1242 /* whilestat -> WHILE cond DO block END */ in whilestat()
1243 FuncState *fs = ls->fs; in whilestat() local
1248 whileinit = luaK_getlabel(fs); in whilestat()
1250 enterblock(fs, &bl, 1); in whilestat()
1253 luaK_jumpto(fs, whileinit); in whilestat()
1255 leaveblock(fs); in whilestat()
1256 luaK_patchtohere(fs, condexit); /* false conditions finish the loop */ in whilestat()
1261 /* repeatstat -> REPEAT block UNTIL cond */ in repeatstat()
1263 FuncState *fs = ls->fs; in repeatstat() local
1264 int repeat_init = luaK_getlabel(fs); in repeatstat()
1266 enterblock(fs, &bl1, 1); /* loop block */ in repeatstat()
1267 enterblock(fs, &bl2, 0); /* scope block */ in repeatstat()
1273 luaK_patchclose(fs, condexit, bl2.nactvar); in repeatstat()
1274 leaveblock(fs); /* finish scope */ in repeatstat()
1275 luaK_patchlist(fs, condexit, repeat_init); /* close the loop */ in repeatstat()
1276 leaveblock(fs); /* finish loop */ in repeatstat()
1284 luaK_exp2nextreg(ls->fs, &e); in exp1()
1292 /* forbody -> DO block */ in forbody()
1294 FuncState *fs = ls->fs; in forbody() local
1298 prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs); in forbody()
1299 enterblock(fs, &bl, 0); /* scope for declared variables */ in forbody()
1301 luaK_reserveregs(fs, nvars); in forbody()
1303 leaveblock(fs); /* end of scope for declared variables */ in forbody()
1304 luaK_patchtohere(fs, prep); in forbody()
1306 endfor = luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP); in forbody()
1308 luaK_codeABC(fs, OP_TFORCALL, base, 0, nvars); in forbody()
1309 luaK_fixline(fs, line); in forbody()
1310 endfor = luaK_codeAsBx(fs, OP_TFORLOOP, base + 2, NO_JUMP); in forbody()
1312 luaK_patchlist(fs, endfor, prep + 1); in forbody()
1313 luaK_fixline(fs, line); in forbody()
1318 /* fornum -> NAME = exp1,exp1[,exp1] forbody */ in fornum()
1319 FuncState *fs = ls->fs; in fornum() local
1320 int base = fs->freereg; in fornum()
1332 luaK_codek(fs, fs->freereg, luaK_intK(fs, 1)); in fornum()
1333 luaK_reserveregs(fs, 1); in fornum()
1340 /* forlist -> NAME {,NAME} IN explist forbody */ in forlist()
1341 FuncState *fs = ls->fs; in forlist() local
1345 int base = fs->freereg; in forlist()
1357 line = ls->linenumber; in forlist()
1359 luaK_checkstack(fs, 3); /* extra space to call generator */ in forlist()
1360 forbody(ls, base, line, nvars - 3, 0); in forlist()
1365 /* forstat -> FOR (fornum | forlist) END */ in forstat()
1366 FuncState *fs = ls->fs; in forstat() local
1369 enterblock(fs, &bl, 1); /* scope for loop and control variables */ in forstat()
1372 switch (ls->t.token) { in forstat()
1378 leaveblock(fs); /* loop scope ('break' jumps to this point) */ in forstat()
1383 /* test_then_block -> [IF | ELSEIF] cond THEN block */ in test_then_block()
1385 FuncState *fs = ls->fs; in test_then_block() local
1391 if (ls->t.token == TK_GOTO || ls->t.token == TK_BREAK) { in test_then_block()
1392 luaK_goiffalse(ls->fs, &v); /* will jump to label if condition is true */ in test_then_block()
1393 enterblock(fs, &bl, 0); /* must enter block before 'goto' */ in test_then_block()
1397 leaveblock(fs); in test_then_block()
1401 jf = luaK_jump(fs); in test_then_block()
1404 luaK_goiftrue(ls->fs, &v); /* skip over block if condition is false */ in test_then_block()
1405 enterblock(fs, &bl, 0); in test_then_block()
1409 leaveblock(fs); in test_then_block()
1410 if (ls->t.token == TK_ELSE || in test_then_block()
1411 ls->t.token == TK_ELSEIF) /* followed by 'else'/'elseif'? */ in test_then_block()
1412 luaK_concat(fs, escapelist, luaK_jump(fs)); /* must jump over it */ in test_then_block()
1413 luaK_patchtohere(fs, jf); in test_then_block()
1418 /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */ in ifstat()
1419 FuncState *fs = ls->fs; in ifstat() local
1422 while (ls->t.token == TK_ELSEIF) in ifstat()
1427 luaK_patchtohere(fs, escapelist); /* patch escape list to 'if' end */ in ifstat()
1433 FuncState *fs = ls->fs; in localfunc() local
1436 body(ls, &b, 0, ls->linenumber); /* function created in next register */ in localfunc()
1438 getlocvar(fs, b.u.info)->startpc = fs->pc; in localfunc()
1443 /* stat -> LOCAL NAME {',' NAME} ['=' explist] */ in localstat()
1463 /* funcname -> NAME {fieldsel} [':' NAME] */ in funcname()
1466 while (ls->t.token == '.') in funcname()
1468 if (ls->t.token == ':') { in funcname()
1477 /* funcstat -> FUNCTION funcname body */ in funcstat()
1483 luaK_storevar(ls->fs, &v, &b); in funcstat()
1484 luaK_fixline(ls->fs, line); /* definition "happens" in the first line */ in funcstat()
1489 /* stat -> func | assignment */ in exprstat()
1490 FuncState *fs = ls->fs; in exprstat() local
1493 if (ls->t.token == '=' || ls->t.token == ',') { /* stat -> assignment ? */ in exprstat()
1497 else { /* stat -> func */ in exprstat()
1499 SETARG_C(getinstruction(fs, &v.v), 1); /* call statement uses no results */ in exprstat()
1505 /* stat -> RETURN [explist] [';'] */ in retstat()
1506 FuncState *fs = ls->fs; in retstat() local
1509 if (block_follow(ls, 1) || ls->t.token == ';') in retstat()
1514 luaK_setmultret(fs, &e); in retstat()
1516 SET_OPCODE(getinstruction(fs,&e), OP_TAILCALL); in retstat()
1517 lua_assert(GETARG_A(getinstruction(fs,&e)) == fs->nactvar); in retstat()
1519 first = fs->nactvar; in retstat()
1524 first = luaK_exp2anyreg(fs, &e); in retstat()
1526 luaK_exp2nextreg(fs, &e); /* values must go to the stack */ in retstat()
1527 first = fs->nactvar; /* return all active values */ in retstat()
1528 lua_assert(nret == fs->freereg - first); in retstat()
1532 luaK_ret(fs, first, nret); in retstat()
1538 int line = ls->linenumber; /* may be needed for error messages */ in statement()
1540 switch (ls->t.token) { in statement()
1541 case ';': { /* stat -> ';' (empty statement) */ in statement()
1545 case TK_IF: { /* stat -> ifstat */ in statement()
1549 case TK_WHILE: { /* stat -> whilestat */ in statement()
1553 case TK_DO: { /* stat -> DO block END */ in statement()
1559 case TK_FOR: { /* stat -> forstat */ in statement()
1563 case TK_REPEAT: { /* stat -> repeatstat */ in statement()
1567 case TK_FUNCTION: { /* stat -> funcstat */ in statement()
1571 case TK_LOCAL: { /* stat -> localstat */ in statement()
1579 case TK_DBCOLON: { /* stat -> label */ in statement()
1584 case TK_RETURN: { /* stat -> retstat */ in statement()
1589 case TK_BREAK: /* stat -> breakstat */ in statement()
1590 case TK_GOTO: { /* stat -> 'goto' NAME */ in statement()
1591 gotostat(ls, luaK_jump(ls->fs)); in statement()
1594 default: { /* stat -> func | assignment */ in statement()
1599 lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg && in statement()
1600 ls->fs->freereg >= ls->fs->nactvar); in statement()
1601 ls->fs->freereg = ls->fs->nactvar; /* free registers */ in statement()
1612 static void mainfunc (LexState *ls, FuncState *fs) { in mainfunc() argument
1615 open_func(ls, fs, &bl); in mainfunc()
1616 fs->f->is_vararg = 1; /* main function is always declared vararg */ in mainfunc()
1618 newupvalue(fs, ls->envn, &v); /* ...set environment upvalue */ in mainfunc()
1631 setclLvalue(L, L->top, cl); /* anchor it (to avoid being collected) */ in luaY_parser()
1634 sethvalue(L, L->top, lexstate.h); /* anchor it */ in luaY_parser()
1636 funcstate.f = cl->p = luaF_newproto(L); in luaY_parser()
1637 funcstate.f->source = luaS_new(L, name); /* create and anchor TString */ in luaY_parser()
1641 dyd->actvar.n = dyd->gt.n = dyd->label.n = 0; in luaY_parser()
1642 luaX_setinput(L, &lexstate, z, funcstate.f->source, firstchar); in luaY_parser()
1644 lua_assert(!funcstate.prev && funcstate.nups == 1 && !lexstate.fs); in luaY_parser()
1646 lua_assert(dyd->actvar.n == 0 && dyd->gt.n == 0 && dyd->label.n == 0); in luaY_parser()
1647 L->top--; /* remove scanner's table */ in luaY_parser()