Lines Matching refs:ls
64 static void statement (LexState *ls);
65 static void expr (LexState *ls, expdesc *v);
68 static l_noret error_expected (LexState *ls, int token) { in error_expected() argument
69 luaX_syntaxerror(ls, in error_expected()
70 luaO_pushfstring(ls->L, "%s expected", luaX_token2str(ls, token))); in error_expected()
75 lua_State *L = fs->ls->L; in errorlimit()
83 luaX_syntaxerror(fs->ls, msg); in errorlimit()
95 static int testnext (LexState *ls, int c) { in testnext() argument
96 if (ls->t.token == c) { in testnext()
97 luaX_next(ls); in testnext()
107 static void check (LexState *ls, int c) { in check() argument
108 if (ls->t.token != c) in check()
109 error_expected(ls, c); in check()
116 static void checknext (LexState *ls, int c) { in checknext() argument
117 check(ls, c); in checknext()
118 luaX_next(ls); in checknext()
122 #define check_condition(ls,c,msg) { if (!(c)) luaX_syntaxerror(ls, msg); } argument
130 static void check_match (LexState *ls, int what, int who, int where) { in check_match() argument
131 if (unlikely(!testnext(ls, what))) { in check_match()
132 if (where == ls->linenumber) /* all in the same line? */ in check_match()
133 error_expected(ls, what); /* do not need a complex message */ in check_match()
135 luaX_syntaxerror(ls, luaO_pushfstring(ls->L, in check_match()
137 luaX_token2str(ls, what), luaX_token2str(ls, who), where)); in check_match()
143 static TString *str_checkname (LexState *ls) { in str_checkname() argument
145 check(ls, TK_NAME); in str_checkname()
146 ts = ls->t.seminfo.ts; in str_checkname()
147 luaX_next(ls); in str_checkname()
166 static void codename (LexState *ls, expdesc *e) { in codename() argument
167 codestring(e, str_checkname(ls)); in codename()
175 static int registerlocalvar (LexState *ls, FuncState *fs, TString *varname) { in registerlocalvar() argument
178 luaM_growvector(ls->L, f->locvars, fs->ndebugvars, f->sizelocvars, in registerlocalvar()
184 luaC_objbarrier(ls->L, f, varname); in registerlocalvar()
193 static int new_localvar (LexState *ls, TString *name) { in new_localvar() argument
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()
208 #define new_localvarliteral(ls,v) \ argument
209 new_localvar(ls, \
210 luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char)) - 1));
220 return &fs->ls->dyd->actvar.arr[fs->firstlocal + vidx]; in getlocalvardesc()
277 static void check_readonly (LexState *ls, expdesc *e) { in check_readonly() argument
278 FuncState *fs = ls->fs; in check_readonly()
282 varname = ls->dyd->actvar.arr[e->u.info].vd.name; in check_readonly()
301 const char *msg = luaO_pushfstring(ls->L, in check_readonly()
303 luaK_semerror(ls, msg); /* error */ in check_readonly()
311 static void adjustlocalvars (LexState *ls, int nvars) { in adjustlocalvars() argument
312 FuncState *fs = ls->fs; 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()
356 luaM_growvector(fs->ls->L, f->upvalues, fs->nups, f->sizeupvalues, in allocupvalue()
380 luaC_objbarrier(fs->ls->L, fs->f, name); in newupvalue()
452 static void singlevar (LexState *ls, expdesc *var) { in singlevar() argument
453 TString *varname = str_checkname(ls); in singlevar()
454 FuncState *fs = ls->fs; in singlevar()
458 singlevaraux(fs, ls->envn, var, 1); /* get environment variable */ in singlevar()
470 static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) { in adjust_assign() argument
471 FuncState *fs = ls->fs; in adjust_assign()
495 #define enterlevel(ls) luaE_enterCcall((ls)->L) argument
497 #define leavelevel(ls) luaE_exitCcall((ls)->L) argument
504 static l_noret jumpscopeerror (LexState *ls, Labeldesc *gt) { in jumpscopeerror() argument
505 const char *varname = getstr(getlocalvardesc(ls->fs, gt->nactvar)->vd.name); in jumpscopeerror()
507 msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line, varname); in jumpscopeerror()
508 luaK_semerror(ls, msg); /* raise the error */ in jumpscopeerror()
517 static void solvegoto (LexState *ls, int g, Labeldesc *label) { in solvegoto() argument
519 Labellist *gl = &ls->dyd->gt; /* list of goto's */ in solvegoto()
523 jumpscopeerror(ls, gt); in solvegoto()
524 luaK_patchlist(ls->fs, gt->pc, label->pc); in solvegoto()
534 static Labeldesc *findlabel (LexState *ls, TString *name) { in findlabel() argument
536 Dyndata *dyd = ls->dyd; in findlabel()
538 for (i = ls->fs->firstlabel; i < dyd->label.n; i++) { in findlabel()
550 static int newlabelentry (LexState *ls, Labellist *l, TString *name, in newlabelentry() argument
553 luaM_growvector(ls->L, l->arr, n, l->size, in newlabelentry()
557 l->arr[n].nactvar = ls->fs->nactvar; in newlabelentry()
565 static int newgotoentry (LexState *ls, TString *name, int line, int pc) { in newgotoentry() argument
566 return newlabelentry(ls, &ls->dyd->gt, name, line, pc); in newgotoentry()
575 static int solvegotos (LexState *ls, Labeldesc *lb) { in solvegotos() argument
576 Labellist *gl = &ls->dyd->gt; in solvegotos()
577 int i = ls->fs->bl->firstgoto; in solvegotos()
582 solvegoto(ls, i, lb); /* will remove 'i' from the list */ in solvegotos()
598 static int createlabel (LexState *ls, TString *name, int line, in createlabel() argument
600 FuncState *fs = ls->fs; in createlabel()
601 Labellist *ll = &ls->dyd->label; in createlabel()
602 int l = newlabelentry(ls, ll, name, line, luaK_getlabel(fs)); in createlabel()
607 if (solvegotos(ls, &ll->arr[l])) { /* need close? */ in createlabel()
620 Labellist *gl = &fs->ls->dyd->gt; in movegotosout()
635 bl->firstlabel = fs->ls->dyd->label.n; in enterblock()
636 bl->firstgoto = fs->ls->dyd->gt.n; in enterblock()
648 static l_noret undefgoto (LexState *ls, Labeldesc *gt) { in undefgoto() argument
650 if (eqstr(gt->name, luaS_newliteral(ls->L, "break"))) { in undefgoto()
652 msg = luaO_pushfstring(ls->L, msg, gt->line); in undefgoto()
656 msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line); in undefgoto()
658 luaK_semerror(ls, msg); in undefgoto()
664 LexState *ls = fs->ls; in leaveblock() local
668 hasclose = createlabel(ls, luaS_newliteral(ls->L, "break"), 0, 0); in leaveblock()
675 ls->dyd->label.n = bl->firstlabel; /* remove local labels */ in leaveblock()
679 if (bl->firstgoto < ls->dyd->gt.n) /* pending gotos in outer block? */ in leaveblock()
680 undefgoto(ls, &ls->dyd->gt.arr[bl->firstgoto]); /* error */ in leaveblock()
688 static Proto *addprototype (LexState *ls) { in addprototype() argument
690 lua_State *L = ls->L; in addprototype()
691 FuncState *fs = ls->fs; in addprototype()
712 static void codeclosure (LexState *ls, expdesc *v) { in codeclosure() argument
713 FuncState *fs = ls->fs->prev; in codeclosure()
719 static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) { in open_func() argument
721 fs->prev = ls->fs; /* linked list of funcstates */ in open_func()
722 fs->ls = ls; in open_func()
723 ls->fs = fs; in open_func()
736 fs->firstlocal = ls->dyd->actvar.n; in open_func()
737 fs->firstlabel = ls->dyd->label.n; in open_func()
739 f->source = ls->source; in open_func()
740 luaC_objbarrier(ls->L, f, f->source); in open_func()
746 static void close_func (LexState *ls) { in close_func() argument
747 lua_State *L = ls->L; in close_func()
748 FuncState *fs = ls->fs; in close_func()
762 ls->fs = fs->prev; in close_func()
778 static int block_follow (LexState *ls, int withuntil) { in block_follow() argument
779 switch (ls->t.token) { in block_follow()
789 static void statlist (LexState *ls) { in statlist() argument
791 while (!block_follow(ls, 1)) { in statlist()
792 if (ls->t.token == TK_RETURN) { in statlist()
793 statement(ls); in statlist()
796 statement(ls); in statlist()
801 static void fieldsel (LexState *ls, expdesc *v) { in fieldsel() argument
803 FuncState *fs = ls->fs; in fieldsel()
806 luaX_next(ls); /* skip the dot or colon */ in fieldsel()
807 codename(ls, &key); in fieldsel()
812 static void yindex (LexState *ls, expdesc *v) { in yindex() argument
814 luaX_next(ls); /* skip the '[' */ in yindex()
815 expr(ls, v); in yindex()
816 luaK_exp2val(ls->fs, v); in yindex()
817 checknext(ls, ']'); in yindex()
837 static void recfield (LexState *ls, ConsControl *cc) { in recfield() argument
839 FuncState *fs = ls->fs; in recfield()
840 int reg = ls->fs->freereg; in recfield()
842 if (ls->t.token == TK_NAME) { in recfield()
844 codename(ls, &key); in recfield()
847 yindex(ls, &key); in recfield()
849 checknext(ls, '='); in recfield()
852 expr(ls, &val); in recfield()
886 static void listfield (LexState *ls, ConsControl *cc) { in listfield() argument
888 expr(ls, &cc->v); in listfield()
893 static void field (LexState *ls, ConsControl *cc) { in field() argument
895 switch(ls->t.token) { in field()
897 if (luaX_lookahead(ls) != '=') /* expression? */ in field()
898 listfield(ls, cc); in field()
900 recfield(ls, cc); in field()
904 recfield(ls, cc); in field()
908 listfield(ls, cc); in field()
915 static void constructor (LexState *ls, expdesc *t) { in constructor() argument
918 FuncState *fs = ls->fs; in constructor()
919 int line = ls->linenumber; in constructor()
928 checknext(ls, '{'); in constructor()
931 if (ls->t.token == '}') break; in constructor()
933 field(ls, &cc); in constructor()
934 } while (testnext(ls, ',') || testnext(ls, ';')); in constructor()
935 check_match(ls, '}', '{', line); in constructor()
949 static void parlist (LexState *ls) { in parlist() argument
951 FuncState *fs = ls->fs; in parlist()
955 if (ls->t.token != ')') { /* is 'parlist' not empty? */ in parlist()
957 switch (ls->t.token) { in parlist()
959 new_localvar(ls, str_checkname(ls)); in parlist()
964 luaX_next(ls); in parlist()
968 default: luaX_syntaxerror(ls, "<name> or '...' expected"); in parlist()
970 } while (!isvararg && testnext(ls, ',')); in parlist()
972 adjustlocalvars(ls, nparams); in parlist()
980 static void body (LexState *ls, expdesc *e, int ismethod, int line) { in body() argument
984 new_fs.f = addprototype(ls); in body()
986 open_func(ls, &new_fs, &bl); in body()
987 checknext(ls, '('); in body()
989 new_localvarliteral(ls, "self"); /* create 'self' parameter */ in body()
990 adjustlocalvars(ls, 1); in body()
992 parlist(ls); in body()
993 checknext(ls, ')'); in body()
994 statlist(ls); in body()
995 new_fs.f->lastlinedefined = ls->linenumber; in body()
996 check_match(ls, TK_END, TK_FUNCTION, line); in body()
997 codeclosure(ls, e); in body()
998 close_func(ls); in body()
1002 static int explist (LexState *ls, expdesc *v) { in explist() argument
1005 expr(ls, v); in explist()
1006 while (testnext(ls, ',')) { in explist()
1007 luaK_exp2nextreg(ls->fs, v); in explist()
1008 expr(ls, v); in explist()
1015 static void funcargs (LexState *ls, expdesc *f, int line) { in funcargs() argument
1016 FuncState *fs = ls->fs; in funcargs()
1019 switch (ls->t.token) { in funcargs()
1021 luaX_next(ls); in funcargs()
1022 if (ls->t.token == ')') /* arg list is empty? */ in funcargs()
1025 explist(ls, &args); in funcargs()
1029 check_match(ls, ')', '(', line); in funcargs()
1033 constructor(ls, &args); in funcargs()
1037 codestring(&args, ls->t.seminfo.ts); in funcargs()
1038 luaX_next(ls); /* must use 'seminfo' before 'next' */ in funcargs()
1042 luaX_syntaxerror(ls, "function arguments expected"); in funcargs()
1070 static void primaryexp (LexState *ls, expdesc *v) { in primaryexp() argument
1072 switch (ls->t.token) { in primaryexp()
1074 int line = ls->linenumber; in primaryexp()
1075 luaX_next(ls); in primaryexp()
1076 expr(ls, v); in primaryexp()
1077 check_match(ls, ')', '(', line); in primaryexp()
1078 luaK_dischargevars(ls->fs, v); in primaryexp()
1082 singlevar(ls, v); in primaryexp()
1086 luaX_syntaxerror(ls, "unexpected symbol"); in primaryexp()
1092 static void suffixedexp (LexState *ls, expdesc *v) { in suffixedexp() argument
1095 FuncState *fs = ls->fs; in suffixedexp()
1096 int line = ls->linenumber; in suffixedexp()
1097 primaryexp(ls, v); in suffixedexp()
1099 switch (ls->t.token) { in suffixedexp()
1101 fieldsel(ls, v); in suffixedexp()
1107 yindex(ls, &key); in suffixedexp()
1113 luaX_next(ls); in suffixedexp()
1114 codename(ls, &key); in suffixedexp()
1116 funcargs(ls, v, line); in suffixedexp()
1121 funcargs(ls, v, line); in suffixedexp()
1130 static void simpleexp (LexState *ls, expdesc *v) { in simpleexp() argument
1133 switch (ls->t.token) { in simpleexp()
1136 v->u.nval = ls->t.seminfo.r; in simpleexp()
1141 v->u.ival = ls->t.seminfo.i; in simpleexp()
1145 codestring(v, ls->t.seminfo.ts); in simpleexp()
1161 FuncState *fs = ls->fs; in simpleexp()
1162 check_condition(ls, fs->f->is_vararg, in simpleexp()
1168 constructor(ls, v); in simpleexp()
1172 luaX_next(ls); in simpleexp()
1173 body(ls, v, 0, ls->linenumber); in simpleexp()
1177 suffixedexp(ls, v); in simpleexp()
1181 luaX_next(ls); in simpleexp()
1250 static BinOpr subexpr (LexState *ls, expdesc *v, int limit) { in subexpr() argument
1253 enterlevel(ls); in subexpr()
1254 uop = getunopr(ls->t.token); in subexpr()
1256 int line = ls->linenumber; in subexpr()
1257 luaX_next(ls); /* skip operator */ in subexpr()
1258 subexpr(ls, v, UNARY_PRIORITY); in subexpr()
1259 luaK_prefix(ls->fs, uop, v, line); in subexpr()
1261 else simpleexp(ls, v); in subexpr()
1263 op = getbinopr(ls->t.token); in subexpr()
1267 int line = ls->linenumber; in subexpr()
1268 luaX_next(ls); /* skip operator */ in subexpr()
1269 luaK_infix(ls->fs, op, v); in subexpr()
1271 nextop = subexpr(ls, &v2, priority[op].right); in subexpr()
1272 luaK_posfix(ls->fs, op, v, &v2, line); in subexpr()
1275 leavelevel(ls); in subexpr()
1280 static void expr (LexState *ls, expdesc *v) { in expr() argument
1281 subexpr(ls, v, 0); in expr()
1295 static void block (LexState *ls) { in block() argument
1297 FuncState *fs = ls->fs; in block()
1300 statlist(ls); in block()
1321 static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) { in check_conflict() argument
1322 FuncState *fs = ls->fs; in check_conflict()
1365 static void restassign (LexState *ls, struct LHS_assign *lh, int nvars) { in restassign() argument
1367 check_condition(ls, vkisvar(lh->v.k), "syntax error"); in restassign()
1368 check_readonly(ls, &lh->v); in restassign()
1369 if (testnext(ls, ',')) { /* restassign -> ',' suffixedexp restassign */ in restassign()
1372 suffixedexp(ls, &nv.v); in restassign()
1374 check_conflict(ls, lh, &nv.v); in restassign()
1375 enterlevel(ls); /* control recursion depth */ in restassign()
1376 restassign(ls, &nv, nvars+1); in restassign()
1377 leavelevel(ls); in restassign()
1381 checknext(ls, '='); in restassign()
1382 nexps = explist(ls, &e); in restassign()
1384 adjust_assign(ls, nvars, nexps, &e); in restassign()
1386 luaK_setoneret(ls->fs, &e); /* close last expression */ in restassign()
1387 luaK_storevar(ls->fs, &lh->v, &e); in restassign()
1391 init_exp(&e, VNONRELOC, ls->fs->freereg-1); /* default assignment */ in restassign()
1392 luaK_storevar(ls->fs, &lh->v, &e); in restassign()
1396 static int cond (LexState *ls) { in cond() argument
1399 expr(ls, &v); /* read condition */ in cond()
1401 luaK_goiftrue(ls->fs, &v); in cond()
1406 static void gotostat (LexState *ls) { in gotostat() argument
1407 FuncState *fs = ls->fs; in gotostat()
1408 int line = ls->linenumber; in gotostat()
1409 TString *name = str_checkname(ls); /* label's name */ in gotostat()
1410 Labeldesc *lb = findlabel(ls, name); in gotostat()
1413 newgotoentry(ls, name, line, luaK_jump(fs)); in gotostat()
1428 static void breakstat (LexState *ls) { in breakstat() argument
1429 int line = ls->linenumber; in breakstat()
1430 luaX_next(ls); /* skip break */ in breakstat()
1431 newgotoentry(ls, luaS_newliteral(ls->L, "break"), line, luaK_jump(ls->fs)); in breakstat()
1438 static void checkrepeated (LexState *ls, TString *name) { in checkrepeated() argument
1439 Labeldesc *lb = findlabel(ls, name); in checkrepeated()
1442 msg = luaO_pushfstring(ls->L, msg, getstr(name), lb->line); in checkrepeated()
1443 luaK_semerror(ls, msg); /* error */ in checkrepeated()
1448 static void labelstat (LexState *ls, TString *name, int line) { in labelstat() argument
1450 checknext(ls, TK_DBCOLON); /* skip double colon */ in labelstat()
1451 while (ls->t.token == ';' || ls->t.token == TK_DBCOLON) in labelstat()
1452 statement(ls); /* skip other no-op statements */ in labelstat()
1453 checkrepeated(ls, name); /* check for repeated labels */ in labelstat()
1454 createlabel(ls, name, line, block_follow(ls, 0)); in labelstat()
1458 static void whilestat (LexState *ls, int line) { in whilestat() argument
1460 FuncState *fs = ls->fs; in whilestat()
1464 luaX_next(ls); /* skip WHILE */ in whilestat()
1466 condexit = cond(ls); in whilestat()
1468 checknext(ls, TK_DO); in whilestat()
1469 block(ls); in whilestat()
1471 check_match(ls, TK_END, TK_WHILE, line); in whilestat()
1477 static void repeatstat (LexState *ls, int line) { in repeatstat() argument
1480 FuncState *fs = ls->fs; in repeatstat()
1485 luaX_next(ls); /* skip REPEAT */ in repeatstat()
1486 statlist(ls); in repeatstat()
1487 check_match(ls, TK_UNTIL, TK_REPEAT, line); in repeatstat()
1488 condexit = cond(ls); /* read condition (inside scope block) */ in repeatstat()
1507 static void exp1 (LexState *ls) { in exp1() argument
1509 expr(ls, &e); in exp1()
1510 luaK_exp2nextreg(ls->fs, &e); in exp1()
1526 luaX_syntaxerror(fs->ls, "control structure too long"); in fixforjump()
1534 static void forbody (LexState *ls, int base, int line, int nvars, int isgen) { in forbody() argument
1539 FuncState *fs = ls->fs; in forbody()
1541 checknext(ls, TK_DO); in forbody()
1544 adjustlocalvars(ls, nvars); in forbody()
1546 block(ls); in forbody()
1559 static void fornum (LexState *ls, TString *varname, int line) { in fornum() argument
1561 FuncState *fs = ls->fs; in fornum()
1563 new_localvarliteral(ls, "(for state)"); in fornum()
1564 new_localvarliteral(ls, "(for state)"); in fornum()
1565 new_localvarliteral(ls, "(for state)"); in fornum()
1566 new_localvar(ls, varname); in fornum()
1567 checknext(ls, '='); in fornum()
1568 exp1(ls); /* initial value */ in fornum()
1569 checknext(ls, ','); in fornum()
1570 exp1(ls); /* limit */ in fornum()
1571 if (testnext(ls, ',')) in fornum()
1572 exp1(ls); /* optional step */ in fornum()
1577 adjustlocalvars(ls, 3); /* control variables */ in fornum()
1578 forbody(ls, base, line, 1, 0); in fornum()
1582 static void forlist (LexState *ls, TString *indexname) { in forlist() argument
1584 FuncState *fs = ls->fs; in forlist()
1590 new_localvarliteral(ls, "(for state)"); in forlist()
1591 new_localvarliteral(ls, "(for state)"); in forlist()
1592 new_localvarliteral(ls, "(for state)"); in forlist()
1593 new_localvarliteral(ls, "(for state)"); in forlist()
1595 new_localvar(ls, indexname); in forlist()
1596 while (testnext(ls, ',')) { in forlist()
1597 new_localvar(ls, str_checkname(ls)); in forlist()
1600 checknext(ls, TK_IN); in forlist()
1601 line = ls->linenumber; in forlist()
1602 adjust_assign(ls, 4, explist(ls, &e), &e); in forlist()
1603 adjustlocalvars(ls, 4); /* control variables */ in forlist()
1606 forbody(ls, base, line, nvars - 4, 1); in forlist()
1610 static void forstat (LexState *ls, int line) { in forstat() argument
1612 FuncState *fs = ls->fs; in forstat()
1616 luaX_next(ls); /* skip 'for' */ in forstat()
1617 varname = str_checkname(ls); /* first variable name */ in forstat()
1618 switch (ls->t.token) { in forstat()
1619 case '=': fornum(ls, varname, line); break; in forstat()
1620 case ',': case TK_IN: forlist(ls, varname); break; in forstat()
1621 default: luaX_syntaxerror(ls, "'=' or 'in' expected"); in forstat()
1623 check_match(ls, TK_END, TK_FOR, line); in forstat()
1636 static int issinglejump (LexState *ls, TString **label, int *target) { in issinglejump() argument
1637 if (testnext(ls, TK_BREAK)) { /* a break? */ in issinglejump()
1638 *label = luaS_newliteral(ls->L, "break"); in issinglejump()
1641 else if (ls->t.token != TK_GOTO || luaX_lookahead(ls) != TK_NAME) in issinglejump()
1644 TString *lname = ls->lookahead.seminfo.ts; /* label's id */ in issinglejump()
1645 Labeldesc *lb = findlabel(ls, lname); in issinglejump()
1648 if (luaY_nvarstack(ls->fs) > stacklevel(ls->fs, lb->nactvar)) in issinglejump()
1654 luaX_next(ls); /* skip goto */ in issinglejump()
1655 luaX_next(ls); /* skip name */ in issinglejump()
1661 static void test_then_block (LexState *ls, int *escapelist) { in test_then_block() argument
1665 FuncState *fs = ls->fs; in test_then_block()
1670 luaX_next(ls); /* skip IF or ELSEIF */ in test_then_block()
1671 expr(ls, &v); /* read condition */ in test_then_block()
1672 checknext(ls, TK_THEN); in test_then_block()
1673 line = ls->linenumber; in test_then_block()
1674 if (issinglejump(ls, &jlb, &target)) { /* 'if x then goto' ? */ in test_then_block()
1675 luaK_goiffalse(ls->fs, &v); /* will jump to label if condition is true */ in test_then_block()
1678 newgotoentry(ls, jlb, line, v.t); /* will be resolved later */ in test_then_block()
1681 while (testnext(ls, ';')) {} /* skip semicolons */ in test_then_block()
1682 if (block_follow(ls, 0)) { /* jump is the entire block? */ in test_then_block()
1690 luaK_goiftrue(ls->fs, &v); /* skip over block if condition is false */ in test_then_block()
1694 statlist(ls); /* 'then' part */ in test_then_block()
1696 if (ls->t.token == TK_ELSE || in test_then_block()
1697 ls->t.token == TK_ELSEIF) /* followed by 'else'/'elseif'? */ in test_then_block()
1703 static void ifstat (LexState *ls, int line) { in ifstat() argument
1705 FuncState *fs = ls->fs; in ifstat()
1707 test_then_block(ls, &escapelist); /* IF cond THEN block */ in ifstat()
1708 while (ls->t.token == TK_ELSEIF) in ifstat()
1709 test_then_block(ls, &escapelist); /* ELSEIF cond THEN block */ in ifstat()
1710 if (testnext(ls, TK_ELSE)) in ifstat()
1711 block(ls); /* 'else' part */ in ifstat()
1712 check_match(ls, TK_END, TK_IF, line); in ifstat()
1717 static void localfunc (LexState *ls) { in localfunc() argument
1719 FuncState *fs = ls->fs; in localfunc()
1721 new_localvar(ls, str_checkname(ls)); /* new local variable */ in localfunc()
1722 adjustlocalvars(ls, 1); /* enter its scope */ in localfunc()
1723 body(ls, &b, 0, ls->linenumber); /* function created in next register */ in localfunc()
1729 static int getlocalattribute (LexState *ls) { in getlocalattribute() argument
1731 if (testnext(ls, '<')) { in getlocalattribute()
1732 const char *attr = getstr(str_checkname(ls)); in getlocalattribute()
1733 checknext(ls, '>'); in getlocalattribute()
1739 luaK_semerror(ls, in getlocalattribute()
1740 luaO_pushfstring(ls->L, "unknown attribute '%s'", attr)); in getlocalattribute()
1746 static void checktoclose (LexState *ls, int level) { in checktoclose() argument
1748 FuncState *fs = ls->fs; in checktoclose()
1756 static void localstat (LexState *ls) { in localstat() argument
1758 FuncState *fs = ls->fs; in localstat()
1766 vidx = new_localvar(ls, str_checkname(ls)); in localstat()
1767 kind = getlocalattribute(ls); in localstat()
1771 luaK_semerror(ls, "multiple to-be-closed variables in local list"); in localstat()
1775 } while (testnext(ls, ',')); in localstat()
1776 if (testnext(ls, '=')) in localstat()
1777 nexps = explist(ls, &e); in localstat()
1787 adjustlocalvars(ls, nvars - 1); /* exclude last variable */ in localstat()
1791 adjust_assign(ls, nvars, nexps, &e); in localstat()
1792 adjustlocalvars(ls, nvars); in localstat()
1794 checktoclose(ls, toclose); in localstat()
1798 static int funcname (LexState *ls, expdesc *v) { in funcname() argument
1801 singlevar(ls, v); in funcname()
1802 while (ls->t.token == '.') in funcname()
1803 fieldsel(ls, v); in funcname()
1804 if (ls->t.token == ':') { in funcname()
1806 fieldsel(ls, v); in funcname()
1812 static void funcstat (LexState *ls, int line) { in funcstat() argument
1816 luaX_next(ls); /* skip FUNCTION */ in funcstat()
1817 ismethod = funcname(ls, &v); in funcstat()
1818 body(ls, &b, ismethod, line); in funcstat()
1819 luaK_storevar(ls->fs, &v, &b); in funcstat()
1820 luaK_fixline(ls->fs, line); /* definition "happens" in the first line */ in funcstat()
1824 static void exprstat (LexState *ls) { in exprstat() argument
1826 FuncState *fs = ls->fs; in exprstat()
1828 suffixedexp(ls, &v.v); in exprstat()
1829 if (ls->t.token == '=' || ls->t.token == ',') { /* stat -> assignment ? */ in exprstat()
1831 restassign(ls, &v, 1); in exprstat()
1835 check_condition(ls, v.v.k == VCALL, "syntax error"); in exprstat()
1842 static void retstat (LexState *ls) { in retstat() argument
1844 FuncState *fs = ls->fs; in retstat()
1848 if (block_follow(ls, 1) || ls->t.token == ';') in retstat()
1851 nret = explist(ls, &e); /* optional return values */ in retstat()
1870 testnext(ls, ';'); /* skip optional semicolon */ in retstat()
1874 static void statement (LexState *ls) { in statement() argument
1875 int line = ls->linenumber; /* may be needed for error messages */ in statement()
1876 enterlevel(ls); in statement()
1877 switch (ls->t.token) { in statement()
1879 luaX_next(ls); /* skip ';' */ in statement()
1883 ifstat(ls, line); in statement()
1887 whilestat(ls, line); in statement()
1891 luaX_next(ls); /* skip DO */ in statement()
1892 block(ls); in statement()
1893 check_match(ls, TK_END, TK_DO, line); in statement()
1897 forstat(ls, line); in statement()
1901 repeatstat(ls, line); in statement()
1905 funcstat(ls, line); in statement()
1909 luaX_next(ls); /* skip LOCAL */ in statement()
1910 if (testnext(ls, TK_FUNCTION)) /* local function? */ in statement()
1911 localfunc(ls); in statement()
1913 localstat(ls); in statement()
1917 luaX_next(ls); /* skip double colon */ in statement()
1918 labelstat(ls, str_checkname(ls), line); in statement()
1922 luaX_next(ls); /* skip RETURN */ in statement()
1923 retstat(ls); in statement()
1927 breakstat(ls); in statement()
1931 luaX_next(ls); /* skip 'goto' */ in statement()
1932 gotostat(ls); in statement()
1936 exprstat(ls); in statement()
1940 lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg && in statement()
1941 ls->fs->freereg >= luaY_nvarstack(ls->fs)); in statement()
1942 ls->fs->freereg = luaY_nvarstack(ls->fs); /* free registers */ in statement()
1943 leavelevel(ls); in statement()
1953 static void mainfunc (LexState *ls, FuncState *fs) { in mainfunc() argument
1956 open_func(ls, fs, &bl); in mainfunc()
1962 env->name = ls->envn; in mainfunc()
1963 luaC_objbarrier(ls->L, fs->f, env->name); in mainfunc()
1964 luaX_next(ls); /* read first token */ in mainfunc()
1965 statlist(ls); /* parse main body */ in mainfunc()
1966 check(ls, TK_EOS); in mainfunc()
1967 close_func(ls); in mainfunc()