lparser.c
Go to the documentation of this file.
1 /*
2 ** $Id: lparser.c $
3 ** Lua Parser
4 ** See Copyright Notice in lua.h
5 */
6 
7 #define lparser_c
8 #define LUA_CORE
9 
10 #include "lprefix.h"
11 
12 
13 #include <limits.h>
14 #include <string.h>
15 
16 #include "lua.h"
17 
18 #include "lcode.h"
19 #include "ldebug.h"
20 #include "ldo.h"
21 #include "lfunc.h"
22 #include "llex.h"
23 #include "lmem.h"
24 #include "lobject.h"
25 #include "lopcodes.h"
26 #include "lparser.h"
27 #include "lstate.h"
28 #include "lstring.h"
29 #include "ltable.h"
30 
31 
32 
33 /* maximum number of local variables per function (must be smaller
34  than 250, due to the bytecode format) */
35 #define MAXVARS 200
36 
37 
38 #define hasmultret(k) ((k) == VCALL || (k) == VVARARG)
39 
40 
41 /* because all strings are unified by the scanner, the parser
42  can use pointer equality for string equality */
43 #define eqstr(a,b) ((a) == (b))
44 
45 
46 /*
47 ** nodes for block list (list of active blocks)
48 */
49 typedef struct BlockCnt {
50  struct BlockCnt *previous; /* chain */
51  int firstlabel; /* index of first label in this block */
52  int firstgoto; /* index of first pending goto in this block */
53  lu_byte nactvar; /* # active locals outside the block */
54  lu_byte upval; /* true if some variable in the block is an upvalue */
55  lu_byte isloop; /* true if 'block' is a loop */
56  lu_byte insidetbc; /* true if inside the scope of a to-be-closed var. */
57 } BlockCnt;
58 
59 
60 
61 /*
62 ** prototypes for recursive non-terminal functions
63 */
64 static void statement (LexState *ls);
65 static void expr (LexState *ls, expdesc *v);
66 
67 
68 static l_noret error_expected (LexState *ls, int token) {
70  luaO_pushfstring(ls->L, "%s expected", luaX_token2str(ls, token)));
71 }
72 
73 
74 static l_noret errorlimit (FuncState *fs, int limit, const char *what) {
75  lua_State *L = fs->ls->L;
76  const char *msg;
77  int line = fs->f->linedefined;
78  const char *where = (line == 0)
79  ? "main function"
80  : luaO_pushfstring(L, "function at line %d", line);
81  msg = luaO_pushfstring(L, "too many %s (limit is %d) in %s",
82  what, limit, where);
83  luaX_syntaxerror(fs->ls, msg);
84 }
85 
86 
87 static void checklimit (FuncState *fs, int v, int l, const char *what) {
88  if (v > l) errorlimit(fs, l, what);
89 }
90 
91 
92 /*
93 ** Test whether next token is 'c'; if so, skip it.
94 */
95 static int testnext (LexState *ls, int c) {
96  if (ls->t.token == c) {
97  luaX_next(ls);
98  return 1;
99  }
100  else return 0;
101 }
102 
103 
104 /*
105 ** Check that next token is 'c'.
106 */
107 static void check (LexState *ls, int c) {
108  if (ls->t.token != c)
109  error_expected(ls, c);
110 }
111 
112 
113 /*
114 ** Check that next token is 'c' and skip it.
115 */
116 static void checknext (LexState *ls, int c) {
117  check(ls, c);
118  luaX_next(ls);
119 }
120 
121 
122 #define check_condition(ls,c,msg) { if (!(c)) luaX_syntaxerror(ls, msg); }
123 
124 
125 /*
126 ** Check that next token is 'what' and skip it. In case of error,
127 ** raise an error that the expected 'what' should match a 'who'
128 ** in line 'where' (if that is not the current line).
129 */
130 static void check_match (LexState *ls, int what, int who, int where) {
131  if (l_unlikely(!testnext(ls, what))) {
132  if (where == ls->linenumber) /* all in the same line? */
133  error_expected(ls, what); /* do not need a complex message */
134  else {
136  "%s expected (to close %s at line %d)",
137  luaX_token2str(ls, what), luaX_token2str(ls, who), where));
138  }
139  }
140 }
141 
142 
144  TString *ts;
145  check(ls, TK_NAME);
146  ts = ls->t.seminfo.ts;
147  luaX_next(ls);
148  return ts;
149 }
150 
151 
152 static void init_exp (expdesc *e, expkind k, int i) {
153  e->f = e->t = NO_JUMP;
154  e->k = k;
155  e->u.info = i;
156 }
157 
158 
159 static void codestring (expdesc *e, TString *s) {
160  e->f = e->t = NO_JUMP;
161  e->k = VKSTR;
162  e->u.strval = s;
163 }
164 
165 
166 static void codename (LexState *ls, expdesc *e) {
167  codestring(e, str_checkname(ls));
168 }
169 
170 
171 /*
172 ** Register a new local variable in the active 'Proto' (for debug
173 ** information).
174 */
175 static int registerlocalvar (LexState *ls, FuncState *fs, TString *varname) {
176  Proto *f = fs->f;
177  int oldsize = f->sizelocvars;
178  luaM_growvector(ls->L, f->locvars, fs->ndebugvars, f->sizelocvars,
179  LocVar, SHRT_MAX, "local variables");
180  while (oldsize < f->sizelocvars)
181  f->locvars[oldsize++].varname = NULL;
182  f->locvars[fs->ndebugvars].varname = varname;
183  f->locvars[fs->ndebugvars].startpc = fs->pc;
184  luaC_objbarrier(ls->L, f, varname);
185  return fs->ndebugvars++;
186 }
187 
188 
189 /*
190 ** Create a new local variable with the given 'name'. Return its index
191 ** in the function.
192 */
193 static int new_localvar (LexState *ls, TString *name) {
194  lua_State *L = ls->L;
195  FuncState *fs = ls->fs;
196  Dyndata *dyd = ls->dyd;
197  Vardesc *var;
198  checklimit(fs, dyd->actvar.n + 1 - fs->firstlocal,
199  MAXVARS, "local variables");
200  luaM_growvector(L, dyd->actvar.arr, dyd->actvar.n + 1,
201  dyd->actvar.size, Vardesc, USHRT_MAX, "local variables");
202  var = &dyd->actvar.arr[dyd->actvar.n++];
203  var->vd.kind = VDKREG; /* default */
204  var->vd.name = name;
205  return dyd->actvar.n - 1 - fs->firstlocal;
206 }
207 
208 #define new_localvarliteral(ls,v) \
209  new_localvar(ls, \
210  luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char)) - 1));
211 
212 
213 
214 /*
215 ** Return the "variable description" (Vardesc) of a given variable.
216 ** (Unless noted otherwise, all variables are referred to by their
217 ** compiler indices.)
218 */
219 static Vardesc *getlocalvardesc (FuncState *fs, int vidx) {
220  return &fs->ls->dyd->actvar.arr[fs->firstlocal + vidx];
221 }
222 
223 
224 /*
225 ** Convert 'nvar', a compiler index level, to its corresponding
226 ** register. For that, search for the highest variable below that level
227 ** that is in a register and uses its register index ('ridx') plus one.
228 */
229 static int reglevel (FuncState *fs, int nvar) {
230  while (nvar-- > 0) {
231  Vardesc *vd = getlocalvardesc(fs, nvar); /* get previous variable */
232  if (vd->vd.kind != RDKCTC) /* is in a register? */
233  return vd->vd.ridx + 1;
234  }
235  return 0; /* no variables in registers */
236 }
237 
238 
239 /*
240 ** Return the number of variables in the register stack for the given
241 ** function.
242 */
244  return reglevel(fs, fs->nactvar);
245 }
246 
247 
248 /*
249 ** Get the debug-information entry for current variable 'vidx'.
250 */
251 static LocVar *localdebuginfo (FuncState *fs, int vidx) {
252  Vardesc *vd = getlocalvardesc(fs, vidx);
253  if (vd->vd.kind == RDKCTC)
254  return NULL; /* no debug info. for constants */
255  else {
256  int idx = vd->vd.pidx;
257  lua_assert(idx < fs->ndebugvars);
258  return &fs->f->locvars[idx];
259  }
260 }
261 
262 
263 /*
264 ** Create an expression representing variable 'vidx'
265 */
266 static void init_var (FuncState *fs, expdesc *e, int vidx) {
267  e->f = e->t = NO_JUMP;
268  e->k = VLOCAL;
269  e->u.var.vidx = vidx;
270  e->u.var.ridx = getlocalvardesc(fs, vidx)->vd.ridx;
271 }
272 
273 
274 /*
275 ** Raises an error if variable described by 'e' is read only
276 */
277 static void check_readonly (LexState *ls, expdesc *e) {
278  FuncState *fs = ls->fs;
279  TString *varname = NULL; /* to be set if variable is const */
280  switch (e->k) {
281  case VCONST: {
282  varname = ls->dyd->actvar.arr[e->u.info].vd.name;
283  break;
284  }
285  case VLOCAL: {
286  Vardesc *vardesc = getlocalvardesc(fs, e->u.var.vidx);
287  if (vardesc->vd.kind != VDKREG) /* not a regular variable? */
288  varname = vardesc->vd.name;
289  break;
290  }
291  case VUPVAL: {
292  Upvaldesc *up = &fs->f->upvalues[e->u.info];
293  if (up->kind != VDKREG)
294  varname = up->name;
295  break;
296  }
297  default:
298  return; /* other cases cannot be read-only */
299  }
300  if (varname) {
301  const char *msg = luaO_pushfstring(ls->L,
302  "attempt to assign to const variable '%s'", getstr(varname));
303  luaK_semerror(ls, msg); /* error */
304  }
305 }
306 
307 
308 /*
309 ** Start the scope for the last 'nvars' created variables.
310 */
311 static void adjustlocalvars (LexState *ls, int nvars) {
312  FuncState *fs = ls->fs;
313  int reglevel = luaY_nvarstack(fs);
314  int i;
315  for (i = 0; i < nvars; i++) {
316  int vidx = fs->nactvar++;
317  Vardesc *var = getlocalvardesc(fs, vidx);
318  var->vd.ridx = reglevel++;
319  var->vd.pidx = registerlocalvar(ls, fs, var->vd.name);
320  }
321 }
322 
323 
324 /*
325 ** Close the scope for all variables up to level 'tolevel'.
326 ** (debug info.)
327 */
328 static void removevars (FuncState *fs, int tolevel) {
329  fs->ls->dyd->actvar.n -= (fs->nactvar - tolevel);
330  while (fs->nactvar > tolevel) {
331  LocVar *var = localdebuginfo(fs, --fs->nactvar);
332  if (var) /* does it have debug information? */
333  var->endpc = fs->pc;
334  }
335 }
336 
337 
338 /*
339 ** Search the upvalues of the function 'fs' for one
340 ** with the given 'name'.
341 */
342 static int searchupvalue (FuncState *fs, TString *name) {
343  int i;
344  Upvaldesc *up = fs->f->upvalues;
345  for (i = 0; i < fs->nups; i++) {
346  if (eqstr(up[i].name, name)) return i;
347  }
348  return -1; /* not found */
349 }
350 
351 
353  Proto *f = fs->f;
354  int oldsize = f->sizeupvalues;
355  checklimit(fs, fs->nups + 1, MAXUPVAL, "upvalues");
356  luaM_growvector(fs->ls->L, f->upvalues, fs->nups, f->sizeupvalues,
357  Upvaldesc, MAXUPVAL, "upvalues");
358  while (oldsize < f->sizeupvalues)
359  f->upvalues[oldsize++].name = NULL;
360  return &f->upvalues[fs->nups++];
361 }
362 
363 
364 static int newupvalue (FuncState *fs, TString *name, expdesc *v) {
365  Upvaldesc *up = allocupvalue(fs);
366  FuncState *prev = fs->prev;
367  if (v->k == VLOCAL) {
368  up->instack = 1;
369  up->idx = v->u.var.ridx;
370  up->kind = getlocalvardesc(prev, v->u.var.vidx)->vd.kind;
371  lua_assert(eqstr(name, getlocalvardesc(prev, v->u.var.vidx)->vd.name));
372  }
373  else {
374  up->instack = 0;
375  up->idx = cast_byte(v->u.info);
376  up->kind = prev->f->upvalues[v->u.info].kind;
377  lua_assert(eqstr(name, prev->f->upvalues[v->u.info].name));
378  }
379  up->name = name;
380  luaC_objbarrier(fs->ls->L, fs->f, name);
381  return fs->nups - 1;
382 }
383 
384 
385 /*
386 ** Look for an active local variable with the name 'n' in the
387 ** function 'fs'. If found, initialize 'var' with it and return
388 ** its expression kind; otherwise return -1.
389 */
390 static int searchvar (FuncState *fs, TString *n, expdesc *var) {
391  int i;
392  for (i = cast_int(fs->nactvar) - 1; i >= 0; i--) {
393  Vardesc *vd = getlocalvardesc(fs, i);
394  if (eqstr(n, vd->vd.name)) { /* found? */
395  if (vd->vd.kind == RDKCTC) /* compile-time constant? */
396  init_exp(var, VCONST, fs->firstlocal + i);
397  else /* real variable */
398  init_var(fs, var, i);
399  return var->k;
400  }
401  }
402  return -1; /* not found */
403 }
404 
405 
406 /*
407 ** Mark block where variable at given level was defined
408 ** (to emit close instructions later).
409 */
410 static void markupval (FuncState *fs, int level) {
411  BlockCnt *bl = fs->bl;
412  while (bl->nactvar > level)
413  bl = bl->previous;
414  bl->upval = 1;
415  fs->needclose = 1;
416 }
417 
418 
419 /*
420 ** Find a variable with the given name 'n'. If it is an upvalue, add
421 ** this upvalue into all intermediate functions. If it is a global, set
422 ** 'var' as 'void' as a flag.
423 */
424 static void singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) {
425  if (fs == NULL) /* no more levels? */
426  init_exp(var, VVOID, 0); /* default is global */
427  else {
428  int v = searchvar(fs, n, var); /* look up locals at current level */
429  if (v >= 0) { /* found? */
430  if (v == VLOCAL && !base)
431  markupval(fs, var->u.var.vidx); /* local will be used as an upval */
432  }
433  else { /* not found as local at current level; try upvalues */
434  int idx = searchupvalue(fs, n); /* try existing upvalues */
435  if (idx < 0) { /* not found? */
436  singlevaraux(fs->prev, n, var, 0); /* try upper levels */
437  if (var->k == VLOCAL || var->k == VUPVAL) /* local or upvalue? */
438  idx = newupvalue(fs, n, var); /* will be a new upvalue */
439  else /* it is a global or a constant */
440  return; /* don't need to do anything at this level */
441  }
442  init_exp(var, VUPVAL, idx); /* new or old upvalue */
443  }
444  }
445 }
446 
447 
448 /*
449 ** Find a variable with the given name 'n', handling global variables
450 ** too.
451 */
452 static void singlevar (LexState *ls, expdesc *var) {
453  TString *varname = str_checkname(ls);
454  FuncState *fs = ls->fs;
455  singlevaraux(fs, varname, var, 1);
456  if (var->k == VVOID) { /* global name? */
457  expdesc key;
458  singlevaraux(fs, ls->envn, var, 1); /* get environment variable */
459  lua_assert(var->k != VVOID); /* this one must exist */
460  codestring(&key, varname); /* key is variable name */
461  luaK_indexed(fs, var, &key); /* env[varname] */
462  }
463 }
464 
465 
466 /*
467 ** Adjust the number of results from an expression list 'e' with 'nexps'
468 ** expressions to 'nvars' values.
469 */
470 static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {
471  FuncState *fs = ls->fs;
472  int needed = nvars - nexps; /* extra values needed */
473  if (hasmultret(e->k)) { /* last expression has multiple returns? */
474  int extra = needed + 1; /* discount last expression itself */
475  if (extra < 0)
476  extra = 0;
477  luaK_setreturns(fs, e, extra); /* last exp. provides the difference */
478  }
479  else {
480  if (e->k != VVOID) /* at least one expression? */
481  luaK_exp2nextreg(fs, e); /* close last expression */
482  if (needed > 0) /* missing values? */
483  luaK_nil(fs, fs->freereg, needed); /* complete with nils */
484  }
485  if (needed > 0)
486  luaK_reserveregs(fs, needed); /* registers for extra values */
487  else /* adding 'needed' is actually a subtraction */
488  fs->freereg += needed; /* remove extra values */
489 }
490 
491 
492 #define enterlevel(ls) luaE_incCstack(ls->L)
493 
494 
495 #define leavelevel(ls) ((ls)->L->nCcalls--)
496 
497 
498 /*
499 ** Generates an error that a goto jumps into the scope of some
500 ** local variable.
501 */
503  const char *varname = getstr(getlocalvardesc(ls->fs, gt->nactvar)->vd.name);
504  const char *msg = "<goto %s> at line %d jumps into the scope of local '%s'";
505  msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line, varname);
506  luaK_semerror(ls, msg); /* raise the error */
507 }
508 
509 
510 /*
511 ** Solves the goto at index 'g' to given 'label' and removes it
512 ** from the list of pending goto's.
513 ** If it jumps into the scope of some variable, raises an error.
514 */
515 static void solvegoto (LexState *ls, int g, Labeldesc *label) {
516  int i;
517  Labellist *gl = &ls->dyd->gt; /* list of goto's */
518  Labeldesc *gt = &gl->arr[g]; /* goto to be resolved */
519  lua_assert(eqstr(gt->name, label->name));
520  if (l_unlikely(gt->nactvar < label->nactvar)) /* enter some scope? */
521  jumpscopeerror(ls, gt);
522  luaK_patchlist(ls->fs, gt->pc, label->pc);
523  for (i = g; i < gl->n - 1; i++) /* remove goto from pending list */
524  gl->arr[i] = gl->arr[i + 1];
525  gl->n--;
526 }
527 
528 
529 /*
530 ** Search for an active label with the given name.
531 */
532 static Labeldesc *findlabel (LexState *ls, TString *name) {
533  int i;
534  Dyndata *dyd = ls->dyd;
535  /* check labels in current function for a match */
536  for (i = ls->fs->firstlabel; i < dyd->label.n; i++) {
537  Labeldesc *lb = &dyd->label.arr[i];
538  if (eqstr(lb->name, name)) /* correct label? */
539  return lb;
540  }
541  return NULL; /* label not found */
542 }
543 
544 
545 /*
546 ** Adds a new label/goto in the corresponding list.
547 */
548 static int newlabelentry (LexState *ls, Labellist *l, TString *name,
549  int line, int pc) {
550  int n = l->n;
551  luaM_growvector(ls->L, l->arr, n, l->size,
552  Labeldesc, SHRT_MAX, "labels/gotos");
553  l->arr[n].name = name;
554  l->arr[n].line = line;
555  l->arr[n].nactvar = ls->fs->nactvar;
556  l->arr[n].close = 0;
557  l->arr[n].pc = pc;
558  l->n = n + 1;
559  return n;
560 }
561 
562 
563 static int newgotoentry (LexState *ls, TString *name, int line, int pc) {
564  return newlabelentry(ls, &ls->dyd->gt, name, line, pc);
565 }
566 
567 
568 /*
569 ** Solves forward jumps. Check whether new label 'lb' matches any
570 ** pending gotos in current block and solves them. Return true
571 ** if any of the goto's need to close upvalues.
572 */
573 static int solvegotos (LexState *ls, Labeldesc *lb) {
574  Labellist *gl = &ls->dyd->gt;
575  int i = ls->fs->bl->firstgoto;
576  int needsclose = 0;
577  while (i < gl->n) {
578  if (eqstr(gl->arr[i].name, lb->name)) {
579  needsclose |= gl->arr[i].close;
580  solvegoto(ls, i, lb); /* will remove 'i' from the list */
581  }
582  else
583  i++;
584  }
585  return needsclose;
586 }
587 
588 
589 /*
590 ** Create a new label with the given 'name' at the given 'line'.
591 ** 'last' tells whether label is the last non-op statement in its
592 ** block. Solves all pending goto's to this new label and adds
593 ** a close instruction if necessary.
594 ** Returns true iff it added a close instruction.
595 */
596 static int createlabel (LexState *ls, TString *name, int line,
597  int last) {
598  FuncState *fs = ls->fs;
599  Labellist *ll = &ls->dyd->label;
600  int l = newlabelentry(ls, ll, name, line, luaK_getlabel(fs));
601  if (last) { /* label is last no-op statement in the block? */
602  /* assume that locals are already out of scope */
603  ll->arr[l].nactvar = fs->bl->nactvar;
604  }
605  if (solvegotos(ls, &ll->arr[l])) { /* need close? */
606  luaK_codeABC(fs, OP_CLOSE, luaY_nvarstack(fs), 0, 0);
607  return 1;
608  }
609  return 0;
610 }
611 
612 
613 /*
614 ** Adjust pending gotos to outer level of a block.
615 */
616 static void movegotosout (FuncState *fs, BlockCnt *bl) {
617  int i;
618  Labellist *gl = &fs->ls->dyd->gt;
619  /* correct pending gotos to current block */
620  for (i = bl->firstgoto; i < gl->n; i++) { /* for each pending goto */
621  Labeldesc *gt = &gl->arr[i];
622  /* leaving a variable scope? */
623  if (reglevel(fs, gt->nactvar) > reglevel(fs, bl->nactvar))
624  gt->close |= bl->upval; /* jump may need a close */
625  gt->nactvar = bl->nactvar; /* update goto level */
626  }
627 }
628 
629 
630 static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isloop) {
631  bl->isloop = isloop;
632  bl->nactvar = fs->nactvar;
633  bl->firstlabel = fs->ls->dyd->label.n;
634  bl->firstgoto = fs->ls->dyd->gt.n;
635  bl->upval = 0;
636  bl->insidetbc = (fs->bl != NULL && fs->bl->insidetbc);
637  bl->previous = fs->bl;
638  fs->bl = bl;
639  lua_assert(fs->freereg == luaY_nvarstack(fs));
640 }
641 
642 
643 /*
644 ** generates an error for an undefined 'goto'.
645 */
646 static l_noret undefgoto (LexState *ls, Labeldesc *gt) {
647  const char *msg;
648  if (eqstr(gt->name, luaS_newliteral(ls->L, "break"))) {
649  msg = "break outside loop at line %d";
650  msg = luaO_pushfstring(ls->L, msg, gt->line);
651  }
652  else {
653  msg = "no visible label '%s' for <goto> at line %d";
654  msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line);
655  }
656  luaK_semerror(ls, msg);
657 }
658 
659 
660 static void leaveblock (FuncState *fs) {
661  BlockCnt *bl = fs->bl;
662  LexState *ls = fs->ls;
663  int hasclose = 0;
664  int stklevel = reglevel(fs, bl->nactvar); /* level outside the block */
665  if (bl->isloop) /* fix pending breaks? */
666  hasclose = createlabel(ls, luaS_newliteral(ls->L, "break"), 0, 0);
667  if (!hasclose && bl->previous && bl->upval)
668  luaK_codeABC(fs, OP_CLOSE, stklevel, 0, 0);
669  fs->bl = bl->previous;
670  removevars(fs, bl->nactvar);
671  lua_assert(bl->nactvar == fs->nactvar);
672  fs->freereg = stklevel; /* free registers */
673  ls->dyd->label.n = bl->firstlabel; /* remove local labels */
674  if (bl->previous) /* inner block? */
675  movegotosout(fs, bl); /* update pending gotos to outer block */
676  else {
677  if (bl->firstgoto < ls->dyd->gt.n) /* pending gotos in outer block? */
678  undefgoto(ls, &ls->dyd->gt.arr[bl->firstgoto]); /* error */
679  }
680 }
681 
682 
683 /*
684 ** adds a new prototype into list of prototypes
685 */
686 static Proto *addprototype (LexState *ls) {
687  Proto *clp;
688  lua_State *L = ls->L;
689  FuncState *fs = ls->fs;
690  Proto *f = fs->f; /* prototype of current function */
691  if (fs->np >= f->sizep) {
692  int oldsize = f->sizep;
693  luaM_growvector(L, f->p, fs->np, f->sizep, Proto *, MAXARG_Bx, "functions");
694  while (oldsize < f->sizep)
695  f->p[oldsize++] = NULL;
696  }
697  f->p[fs->np++] = clp = luaF_newproto(L);
698  luaC_objbarrier(L, f, clp);
699  return clp;
700 }
701 
702 
703 /*
704 ** codes instruction to create new closure in parent function.
705 ** The OP_CLOSURE instruction uses the last available register,
706 ** so that, if it invokes the GC, the GC knows which registers
707 ** are in use at that time.
708 
709 */
710 static void codeclosure (LexState *ls, expdesc *v) {
711  FuncState *fs = ls->fs->prev;
712  init_exp(v, VRELOC, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np - 1));
713  luaK_exp2nextreg(fs, v); /* fix it at the last register */
714 }
715 
716 
717 static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) {
718  Proto *f = fs->f;
719  fs->prev = ls->fs; /* linked list of funcstates */
720  fs->ls = ls;
721  ls->fs = fs;
722  fs->pc = 0;
723  fs->previousline = f->linedefined;
724  fs->iwthabs = 0;
725  fs->lasttarget = 0;
726  fs->freereg = 0;
727  fs->nk = 0;
728  fs->nabslineinfo = 0;
729  fs->np = 0;
730  fs->nups = 0;
731  fs->ndebugvars = 0;
732  fs->nactvar = 0;
733  fs->needclose = 0;
734  fs->firstlocal = ls->dyd->actvar.n;
735  fs->firstlabel = ls->dyd->label.n;
736  fs->bl = NULL;
737  f->source = ls->source;
738  luaC_objbarrier(ls->L, f, f->source);
739  f->maxstacksize = 2; /* registers 0/1 are always valid */
740  enterblock(fs, bl, 0);
741 }
742 
743 
744 static void close_func (LexState *ls) {
745  lua_State *L = ls->L;
746  FuncState *fs = ls->fs;
747  Proto *f = fs->f;
748  luaK_ret(fs, luaY_nvarstack(fs), 0); /* final return */
749  leaveblock(fs);
750  lua_assert(fs->bl == NULL);
751  luaK_finish(fs);
752  luaM_shrinkvector(L, f->code, f->sizecode, fs->pc, Instruction);
753  luaM_shrinkvector(L, f->lineinfo, f->sizelineinfo, fs->pc, ls_byte);
754  luaM_shrinkvector(L, f->abslineinfo, f->sizeabslineinfo,
756  luaM_shrinkvector(L, f->k, f->sizek, fs->nk, TValue);
757  luaM_shrinkvector(L, f->p, f->sizep, fs->np, Proto *);
758  luaM_shrinkvector(L, f->locvars, f->sizelocvars, fs->ndebugvars, LocVar);
759  luaM_shrinkvector(L, f->upvalues, f->sizeupvalues, fs->nups, Upvaldesc);
760  ls->fs = fs->prev;
761  luaC_checkGC(L);
762 }
763 
764 
765 
766 /*============================================================*/
767 /* GRAMMAR RULES */
768 /*============================================================*/
769 
770 
771 /*
772 ** check whether current token is in the follow set of a block.
773 ** 'until' closes syntactical blocks, but do not close scope,
774 ** so it is handled in separate.
775 */
776 static int block_follow (LexState *ls, int withuntil) {
777  switch (ls->t.token) {
778  case TK_ELSE: case TK_ELSEIF:
779  case TK_END: case TK_EOS:
780  return 1;
781  case TK_UNTIL: return withuntil;
782  default: return 0;
783  }
784 }
785 
786 
787 static void statlist (LexState *ls) {
788  /* statlist -> { stat [';'] } */
789  while (!block_follow(ls, 1)) {
790  if (ls->t.token == TK_RETURN) {
791  statement(ls);
792  return; /* 'return' must be last statement */
793  }
794  statement(ls);
795  }
796 }
797 
798 
799 static void fieldsel (LexState *ls, expdesc *v) {
800  /* fieldsel -> ['.' | ':'] NAME */
801  FuncState *fs = ls->fs;
802  expdesc key;
803  luaK_exp2anyregup(fs, v);
804  luaX_next(ls); /* skip the dot or colon */
805  codename(ls, &key);
806  luaK_indexed(fs, v, &key);
807 }
808 
809 
810 static void yindex (LexState *ls, expdesc *v) {
811  /* index -> '[' expr ']' */
812  luaX_next(ls); /* skip the '[' */
813  expr(ls, v);
814  luaK_exp2val(ls->fs, v);
815  checknext(ls, ']');
816 }
817 
818 
819 /*
820 ** {======================================================================
821 ** Rules for Constructors
822 ** =======================================================================
823 */
824 
825 
826 typedef struct ConsControl {
827  expdesc v; /* last list item read */
828  expdesc *t; /* table descriptor */
829  int nh; /* total number of 'record' elements */
830  int na; /* number of array elements already stored */
831  int tostore; /* number of array elements pending to be stored */
832 } ConsControl;
833 
834 
835 static void recfield (LexState *ls, ConsControl *cc) {
836  /* recfield -> (NAME | '['exp']') = exp */
837  FuncState *fs = ls->fs;
838  int reg = ls->fs->freereg;
839  expdesc tab, key, val;
840  if (ls->t.token == TK_NAME) {
841  checklimit(fs, cc->nh, MAX_INT, "items in a constructor");
842  codename(ls, &key);
843  }
844  else /* ls->t.token == '[' */
845  yindex(ls, &key);
846  cc->nh++;
847  checknext(ls, '=');
848  tab = *cc->t;
849  luaK_indexed(fs, &tab, &key);
850  expr(ls, &val);
851  luaK_storevar(fs, &tab, &val);
852  fs->freereg = reg; /* free registers */
853 }
854 
855 
856 static void closelistfield (FuncState *fs, ConsControl *cc) {
857  if (cc->v.k == VVOID) return; /* there is no list item */
858  luaK_exp2nextreg(fs, &cc->v);
859  cc->v.k = VVOID;
860  if (cc->tostore == LFIELDS_PER_FLUSH) {
861  luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore); /* flush */
862  cc->na += cc->tostore;
863  cc->tostore = 0; /* no more items pending */
864  }
865 }
866 
867 
868 static void lastlistfield (FuncState *fs, ConsControl *cc) {
869  if (cc->tostore == 0) return;
870  if (hasmultret(cc->v.k)) {
871  luaK_setmultret(fs, &cc->v);
872  luaK_setlist(fs, cc->t->u.info, cc->na, LUA_MULTRET);
873  cc->na--; /* do not count last expression (unknown number of elements) */
874  }
875  else {
876  if (cc->v.k != VVOID)
877  luaK_exp2nextreg(fs, &cc->v);
878  luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore);
879  }
880  cc->na += cc->tostore;
881 }
882 
883 
884 static void listfield (LexState *ls, ConsControl *cc) {
885  /* listfield -> exp */
886  expr(ls, &cc->v);
887  cc->tostore++;
888 }
889 
890 
891 static void field (LexState *ls, ConsControl *cc) {
892  /* field -> listfield | recfield */
893  switch(ls->t.token) {
894  case TK_NAME: { /* may be 'listfield' or 'recfield' */
895  if (luaX_lookahead(ls) != '=') /* expression? */
896  listfield(ls, cc);
897  else
898  recfield(ls, cc);
899  break;
900  }
901  case '[': {
902  recfield(ls, cc);
903  break;
904  }
905  default: {
906  listfield(ls, cc);
907  break;
908  }
909  }
910 }
911 
912 
913 static void constructor (LexState *ls, expdesc *t) {
914  /* constructor -> '{' [ field { sep field } [sep] ] '}'
915  sep -> ',' | ';' */
916  FuncState *fs = ls->fs;
917  int line = ls->linenumber;
918  int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0);
919  ConsControl cc;
920  luaK_code(fs, 0); /* space for extra arg. */
921  cc.na = cc.nh = cc.tostore = 0;
922  cc.t = t;
923  init_exp(t, VNONRELOC, fs->freereg); /* table will be at stack top */
924  luaK_reserveregs(fs, 1);
925  init_exp(&cc.v, VVOID, 0); /* no value (yet) */
926  checknext(ls, '{');
927  do {
928  lua_assert(cc.v.k == VVOID || cc.tostore > 0);
929  if (ls->t.token == '}') break;
930  closelistfield(fs, &cc);
931  field(ls, &cc);
932  } while (testnext(ls, ',') || testnext(ls, ';'));
933  check_match(ls, '}', '{', line);
934  lastlistfield(fs, &cc);
935  luaK_settablesize(fs, pc, t->u.info, cc.na, cc.nh);
936 }
937 
938 /* }====================================================================== */
939 
940 
941 static void setvararg (FuncState *fs, int nparams) {
942  fs->f->is_vararg = 1;
943  luaK_codeABC(fs, OP_VARARGPREP, nparams, 0, 0);
944 }
945 
946 
947 static void parlist (LexState *ls) {
948  /* parlist -> [ {NAME ','} (NAME | '...') ] */
949  FuncState *fs = ls->fs;
950  Proto *f = fs->f;
951  int nparams = 0;
952  int isvararg = 0;
953  if (ls->t.token != ')') { /* is 'parlist' not empty? */
954  do {
955  switch (ls->t.token) {
956  case TK_NAME: {
957  new_localvar(ls, str_checkname(ls));
958  nparams++;
959  break;
960  }
961  case TK_DOTS: {
962  luaX_next(ls);
963  isvararg = 1;
964  break;
965  }
966  default: luaX_syntaxerror(ls, "<name> or '...' expected");
967  }
968  } while (!isvararg && testnext(ls, ','));
969  }
970  adjustlocalvars(ls, nparams);
971  f->numparams = cast_byte(fs->nactvar);
972  if (isvararg)
973  setvararg(fs, f->numparams); /* declared vararg */
974  luaK_reserveregs(fs, fs->nactvar); /* reserve registers for parameters */
975 }
976 
977 
978 static void body (LexState *ls, expdesc *e, int ismethod, int line) {
979  /* body -> '(' parlist ')' block END */
980  FuncState new_fs;
981  BlockCnt bl;
982  new_fs.f = addprototype(ls);
983  new_fs.f->linedefined = line;
984  open_func(ls, &new_fs, &bl);
985  checknext(ls, '(');
986  if (ismethod) {
987  new_localvarliteral(ls, "self"); /* create 'self' parameter */
988  adjustlocalvars(ls, 1);
989  }
990  parlist(ls);
991  checknext(ls, ')');
992  statlist(ls);
993  new_fs.f->lastlinedefined = ls->linenumber;
994  check_match(ls, TK_END, TK_FUNCTION, line);
995  codeclosure(ls, e);
996  close_func(ls);
997 }
998 
999 
1000 static int explist (LexState *ls, expdesc *v) {
1001  /* explist -> expr { ',' expr } */
1002  int n = 1; /* at least one expression */
1003  expr(ls, v);
1004  while (testnext(ls, ',')) {
1005  luaK_exp2nextreg(ls->fs, v);
1006  expr(ls, v);
1007  n++;
1008  }
1009  return n;
1010 }
1011 
1012 
1013 static void funcargs (LexState *ls, expdesc *f, int line) {
1014  FuncState *fs = ls->fs;
1015  expdesc args;
1016  int base, nparams;
1017  switch (ls->t.token) {
1018  case '(': { /* funcargs -> '(' [ explist ] ')' */
1019  luaX_next(ls);
1020  if (ls->t.token == ')') /* arg list is empty? */
1021  args.k = VVOID;
1022  else {
1023  explist(ls, &args);
1024  if (hasmultret(args.k))
1025  luaK_setmultret(fs, &args);
1026  }
1027  check_match(ls, ')', '(', line);
1028  break;
1029  }
1030  case '{': { /* funcargs -> constructor */
1031  constructor(ls, &args);
1032  break;
1033  }
1034  case TK_STRING: { /* funcargs -> STRING */
1035  codestring(&args, ls->t.seminfo.ts);
1036  luaX_next(ls); /* must use 'seminfo' before 'next' */
1037  break;
1038  }
1039  default: {
1040  luaX_syntaxerror(ls, "function arguments expected");
1041  }
1042  }
1043  lua_assert(f->k == VNONRELOC);
1044  base = f->u.info; /* base register for call */
1045  if (hasmultret(args.k))
1046  nparams = LUA_MULTRET; /* open call */
1047  else {
1048  if (args.k != VVOID)
1049  luaK_exp2nextreg(fs, &args); /* close last argument */
1050  nparams = fs->freereg - (base+1);
1051  }
1052  init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2));
1053  luaK_fixline(fs, line);
1054  fs->freereg = base+1; /* call remove function and arguments and leaves
1055  (unless changed) one result */
1056 }
1057 
1058 
1059 
1060 
1061 /*
1062 ** {======================================================================
1063 ** Expression parsing
1064 ** =======================================================================
1065 */
1066 
1067 
1068 static void primaryexp (LexState *ls, expdesc *v) {
1069  /* primaryexp -> NAME | '(' expr ')' */
1070  switch (ls->t.token) {
1071  case '(': {
1072  int line = ls->linenumber;
1073  luaX_next(ls);
1074  expr(ls, v);
1075  check_match(ls, ')', '(', line);
1076  luaK_dischargevars(ls->fs, v);
1077  return;
1078  }
1079  case TK_NAME: {
1080  singlevar(ls, v);
1081  return;
1082  }
1083  default: {
1084  luaX_syntaxerror(ls, "unexpected symbol");
1085  }
1086  }
1087 }
1088 
1089 
1090 static void suffixedexp (LexState *ls, expdesc *v) {
1091  /* suffixedexp ->
1092  primaryexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs } */
1093  FuncState *fs = ls->fs;
1094  int line = ls->linenumber;
1095  primaryexp(ls, v);
1096  for (;;) {
1097  switch (ls->t.token) {
1098  case '.': { /* fieldsel */
1099  fieldsel(ls, v);
1100  break;
1101  }
1102  case '[': { /* '[' exp ']' */
1103  expdesc key;
1104  luaK_exp2anyregup(fs, v);
1105  yindex(ls, &key);
1106  luaK_indexed(fs, v, &key);
1107  break;
1108  }
1109  case ':': { /* ':' NAME funcargs */
1110  expdesc key;
1111  luaX_next(ls);
1112  codename(ls, &key);
1113  luaK_self(fs, v, &key);
1114  funcargs(ls, v, line);
1115  break;
1116  }
1117  case '(': case TK_STRING: case '{': { /* funcargs */
1118  luaK_exp2nextreg(fs, v);
1119  funcargs(ls, v, line);
1120  break;
1121  }
1122  default: return;
1123  }
1124  }
1125 }
1126 
1127 
1128 static void simpleexp (LexState *ls, expdesc *v) {
1129  /* simpleexp -> FLT | INT | STRING | NIL | TRUE | FALSE | ... |
1130  constructor | FUNCTION body | suffixedexp */
1131  switch (ls->t.token) {
1132  case TK_FLT: {
1133  init_exp(v, VKFLT, 0);
1134  v->u.nval = ls->t.seminfo.r;
1135  break;
1136  }
1137  case TK_INT: {
1138  init_exp(v, VKINT, 0);
1139  v->u.ival = ls->t.seminfo.i;
1140  break;
1141  }
1142  case TK_STRING: {
1143  codestring(v, ls->t.seminfo.ts);
1144  break;
1145  }
1146  case TK_NIL: {
1147  init_exp(v, VNIL, 0);
1148  break;
1149  }
1150  case TK_TRUE: {
1151  init_exp(v, VTRUE, 0);
1152  break;
1153  }
1154  case TK_FALSE: {
1155  init_exp(v, VFALSE, 0);
1156  break;
1157  }
1158  case TK_DOTS: { /* vararg */
1159  FuncState *fs = ls->fs;
1160  check_condition(ls, fs->f->is_vararg,
1161  "cannot use '...' outside a vararg function");
1162  init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 0, 1));
1163  break;
1164  }
1165  case '{': { /* constructor */
1166  constructor(ls, v);
1167  return;
1168  }
1169  case TK_FUNCTION: {
1170  luaX_next(ls);
1171  body(ls, v, 0, ls->linenumber);
1172  return;
1173  }
1174  default: {
1175  suffixedexp(ls, v);
1176  return;
1177  }
1178  }
1179  luaX_next(ls);
1180 }
1181 
1182 
1183 static UnOpr getunopr (int op) {
1184  switch (op) {
1185  case TK_NOT: return OPR_NOT;
1186  case '-': return OPR_MINUS;
1187  case '~': return OPR_BNOT;
1188  case '#': return OPR_LEN;
1189  default: return OPR_NOUNOPR;
1190  }
1191 }
1192 
1193 
1194 static BinOpr getbinopr (int op) {
1195  switch (op) {
1196  case '+': return OPR_ADD;
1197  case '-': return OPR_SUB;
1198  case '*': return OPR_MUL;
1199  case '%': return OPR_MOD;
1200  case '^': return OPR_POW;
1201  case '/': return OPR_DIV;
1202  case TK_IDIV: return OPR_IDIV;
1203  case '&': return OPR_BAND;
1204  case '|': return OPR_BOR;
1205  case '~': return OPR_BXOR;
1206  case TK_SHL: return OPR_SHL;
1207  case TK_SHR: return OPR_SHR;
1208  case TK_CONCAT: return OPR_CONCAT;
1209  case TK_NE: return OPR_NE;
1210  case TK_EQ: return OPR_EQ;
1211  case '<': return OPR_LT;
1212  case TK_LE: return OPR_LE;
1213  case '>': return OPR_GT;
1214  case TK_GE: return OPR_GE;
1215  case TK_AND: return OPR_AND;
1216  case TK_OR: return OPR_OR;
1217  default: return OPR_NOBINOPR;
1218  }
1219 }
1220 
1221 
1222 /*
1223 ** Priority table for binary operators.
1224 */
1225 static const struct {
1226  lu_byte left; /* left priority for each binary operator */
1227  lu_byte right; /* right priority */
1228 } priority[] = { /* ORDER OPR */
1229  {10, 10}, {10, 10}, /* '+' '-' */
1230  {11, 11}, {11, 11}, /* '*' '%' */
1231  {14, 13}, /* '^' (right associative) */
1232  {11, 11}, {11, 11}, /* '/' '//' */
1233  {6, 6}, {4, 4}, {5, 5}, /* '&' '|' '~' */
1234  {7, 7}, {7, 7}, /* '<<' '>>' */
1235  {9, 8}, /* '..' (right associative) */
1236  {3, 3}, {3, 3}, {3, 3}, /* ==, <, <= */
1237  {3, 3}, {3, 3}, {3, 3}, /* ~=, >, >= */
1238  {2, 2}, {1, 1} /* and, or */
1239 };
1240 
1241 #define UNARY_PRIORITY 12 /* priority for unary operators */
1242 
1243 
1244 /*
1245 ** subexpr -> (simpleexp | unop subexpr) { binop subexpr }
1246 ** where 'binop' is any binary operator with a priority higher than 'limit'
1247 */
1248 static BinOpr subexpr (LexState *ls, expdesc *v, int limit) {
1249  BinOpr op;
1250  UnOpr uop;
1251  enterlevel(ls);
1252  uop = getunopr(ls->t.token);
1253  if (uop != OPR_NOUNOPR) { /* prefix (unary) operator? */
1254  int line = ls->linenumber;
1255  luaX_next(ls); /* skip operator */
1256  subexpr(ls, v, UNARY_PRIORITY);
1257  luaK_prefix(ls->fs, uop, v, line);
1258  }
1259  else simpleexp(ls, v);
1260  /* expand while operators have priorities higher than 'limit' */
1261  op = getbinopr(ls->t.token);
1262  while (op != OPR_NOBINOPR && priority[op].left > limit) {
1263  expdesc v2;
1264  BinOpr nextop;
1265  int line = ls->linenumber;
1266  luaX_next(ls); /* skip operator */
1267  luaK_infix(ls->fs, op, v);
1268  /* read sub-expression with higher priority */
1269  nextop = subexpr(ls, &v2, priority[op].right);
1270  luaK_posfix(ls->fs, op, v, &v2, line);
1271  op = nextop;
1272  }
1273  leavelevel(ls);
1274  return op; /* return first untreated operator */
1275 }
1276 
1277 
1278 static void expr (LexState *ls, expdesc *v) {
1279  subexpr(ls, v, 0);
1280 }
1281 
1282 /* }==================================================================== */
1283 
1284 
1285 
1286 /*
1287 ** {======================================================================
1288 ** Rules for Statements
1289 ** =======================================================================
1290 */
1291 
1292 
1293 static void block (LexState *ls) {
1294  /* block -> statlist */
1295  FuncState *fs = ls->fs;
1296  BlockCnt bl;
1297  enterblock(fs, &bl, 0);
1298  statlist(ls);
1299  leaveblock(fs);
1300 }
1301 
1302 
1303 /*
1304 ** structure to chain all variables in the left-hand side of an
1305 ** assignment
1306 */
1307 struct LHS_assign {
1308  struct LHS_assign *prev;
1309  expdesc v; /* variable (global, local, upvalue, or indexed) */
1310 };
1311 
1312 
1313 /*
1314 ** check whether, in an assignment to an upvalue/local variable, the
1315 ** upvalue/local variable is begin used in a previous assignment to a
1316 ** table. If so, save original upvalue/local value in a safe place and
1317 ** use this safe copy in the previous assignment.
1318 */
1319 static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {
1320  FuncState *fs = ls->fs;
1321  int extra = fs->freereg; /* eventual position to save local variable */
1322  int conflict = 0;
1323  for (; lh; lh = lh->prev) { /* check all previous assignments */
1324  if (vkisindexed(lh->v.k)) { /* assignment to table field? */
1325  if (lh->v.k == VINDEXUP) { /* is table an upvalue? */
1326  if (v->k == VUPVAL && lh->v.u.ind.t == v->u.info) {
1327  conflict = 1; /* table is the upvalue being assigned now */
1328  lh->v.k = VINDEXSTR;
1329  lh->v.u.ind.t = extra; /* assignment will use safe copy */
1330  }
1331  }
1332  else { /* table is a register */
1333  if (v->k == VLOCAL && lh->v.u.ind.t == v->u.var.ridx) {
1334  conflict = 1; /* table is the local being assigned now */
1335  lh->v.u.ind.t = extra; /* assignment will use safe copy */
1336  }
1337  /* is index the local being assigned? */
1338  if (lh->v.k == VINDEXED && v->k == VLOCAL &&
1339  lh->v.u.ind.idx == v->u.var.ridx) {
1340  conflict = 1;
1341  lh->v.u.ind.idx = extra; /* previous assignment will use safe copy */
1342  }
1343  }
1344  }
1345  }
1346  if (conflict) {
1347  /* copy upvalue/local value to a temporary (in position 'extra') */
1348  if (v->k == VLOCAL)
1349  luaK_codeABC(fs, OP_MOVE, extra, v->u.var.ridx, 0);
1350  else
1351  luaK_codeABC(fs, OP_GETUPVAL, extra, v->u.info, 0);
1352  luaK_reserveregs(fs, 1);
1353  }
1354 }
1355 
1356 /*
1357 ** Parse and compile a multiple assignment. The first "variable"
1358 ** (a 'suffixedexp') was already read by the caller.
1359 **
1360 ** assignment -> suffixedexp restassign
1361 ** restassign -> ',' suffixedexp restassign | '=' explist
1362 */
1363 static void restassign (LexState *ls, struct LHS_assign *lh, int nvars) {
1364  expdesc e;
1365  check_condition(ls, vkisvar(lh->v.k), "syntax error");
1366  check_readonly(ls, &lh->v);
1367  if (testnext(ls, ',')) { /* restassign -> ',' suffixedexp restassign */
1368  struct LHS_assign nv;
1369  nv.prev = lh;
1370  suffixedexp(ls, &nv.v);
1371  if (!vkisindexed(nv.v.k))
1372  check_conflict(ls, lh, &nv.v);
1373  enterlevel(ls); /* control recursion depth */
1374  restassign(ls, &nv, nvars+1);
1375  leavelevel(ls);
1376  }
1377  else { /* restassign -> '=' explist */
1378  int nexps;
1379  checknext(ls, '=');
1380  nexps = explist(ls, &e);
1381  if (nexps != nvars)
1382  adjust_assign(ls, nvars, nexps, &e);
1383  else {
1384  luaK_setoneret(ls->fs, &e); /* close last expression */
1385  luaK_storevar(ls->fs, &lh->v, &e);
1386  return; /* avoid default */
1387  }
1388  }
1389  init_exp(&e, VNONRELOC, ls->fs->freereg-1); /* default assignment */
1390  luaK_storevar(ls->fs, &lh->v, &e);
1391 }
1392 
1393 
1394 static int cond (LexState *ls) {
1395  /* cond -> exp */
1396  expdesc v;
1397  expr(ls, &v); /* read condition */
1398  if (v.k == VNIL) v.k = VFALSE; /* 'falses' are all equal here */
1399  luaK_goiftrue(ls->fs, &v);
1400  return v.f;
1401 }
1402 
1403 
1404 static void gotostat (LexState *ls) {
1405  FuncState *fs = ls->fs;
1406  int line = ls->linenumber;
1407  TString *name = str_checkname(ls); /* label's name */
1408  Labeldesc *lb = findlabel(ls, name);
1409  if (lb == NULL) /* no label? */
1410  /* forward jump; will be resolved when the label is declared */
1411  newgotoentry(ls, name, line, luaK_jump(fs));
1412  else { /* found a label */
1413  /* backward jump; will be resolved here */
1414  int lblevel = reglevel(fs, lb->nactvar); /* label level */
1415  if (luaY_nvarstack(fs) > lblevel) /* leaving the scope of a variable? */
1416  luaK_codeABC(fs, OP_CLOSE, lblevel, 0, 0);
1417  /* create jump and link it to the label */
1418  luaK_patchlist(fs, luaK_jump(fs), lb->pc);
1419  }
1420 }
1421 
1422 
1423 /*
1424 ** Break statement. Semantically equivalent to "goto break".
1425 */
1426 static void breakstat (LexState *ls) {
1427  int line = ls->linenumber;
1428  luaX_next(ls); /* skip break */
1429  newgotoentry(ls, luaS_newliteral(ls->L, "break"), line, luaK_jump(ls->fs));
1430 }
1431 
1432 
1433 /*
1434 ** Check whether there is already a label with the given 'name'.
1435 */
1436 static void checkrepeated (LexState *ls, TString *name) {
1437  Labeldesc *lb = findlabel(ls, name);
1438  if (l_unlikely(lb != NULL)) { /* already defined? */
1439  const char *msg = "label '%s' already defined on line %d";
1440  msg = luaO_pushfstring(ls->L, msg, getstr(name), lb->line);
1441  luaK_semerror(ls, msg); /* error */
1442  }
1443 }
1444 
1445 
1446 static void labelstat (LexState *ls, TString *name, int line) {
1447  /* label -> '::' NAME '::' */
1448  checknext(ls, TK_DBCOLON); /* skip double colon */
1449  while (ls->t.token == ';' || ls->t.token == TK_DBCOLON)
1450  statement(ls); /* skip other no-op statements */
1451  checkrepeated(ls, name); /* check for repeated labels */
1452  createlabel(ls, name, line, block_follow(ls, 0));
1453 }
1454 
1455 
1456 static void whilestat (LexState *ls, int line) {
1457  /* whilestat -> WHILE cond DO block END */
1458  FuncState *fs = ls->fs;
1459  int whileinit;
1460  int condexit;
1461  BlockCnt bl;
1462  luaX_next(ls); /* skip WHILE */
1463  whileinit = luaK_getlabel(fs);
1464  condexit = cond(ls);
1465  enterblock(fs, &bl, 1);
1466  checknext(ls, TK_DO);
1467  block(ls);
1468  luaK_jumpto(fs, whileinit);
1469  check_match(ls, TK_END, TK_WHILE, line);
1470  leaveblock(fs);
1471  luaK_patchtohere(fs, condexit); /* false conditions finish the loop */
1472 }
1473 
1474 
1475 static void repeatstat (LexState *ls, int line) {
1476  /* repeatstat -> REPEAT block UNTIL cond */
1477  int condexit;
1478  FuncState *fs = ls->fs;
1479  int repeat_init = luaK_getlabel(fs);
1480  BlockCnt bl1, bl2;
1481  enterblock(fs, &bl1, 1); /* loop block */
1482  enterblock(fs, &bl2, 0); /* scope block */
1483  luaX_next(ls); /* skip REPEAT */
1484  statlist(ls);
1485  check_match(ls, TK_UNTIL, TK_REPEAT, line);
1486  condexit = cond(ls); /* read condition (inside scope block) */
1487  leaveblock(fs); /* finish scope */
1488  if (bl2.upval) { /* upvalues? */
1489  int exit = luaK_jump(fs); /* normal exit must jump over fix */
1490  luaK_patchtohere(fs, condexit); /* repetition must close upvalues */
1491  luaK_codeABC(fs, OP_CLOSE, reglevel(fs, bl2.nactvar), 0, 0);
1492  condexit = luaK_jump(fs); /* repeat after closing upvalues */
1493  luaK_patchtohere(fs, exit); /* normal exit comes to here */
1494  }
1495  luaK_patchlist(fs, condexit, repeat_init); /* close the loop */
1496  leaveblock(fs); /* finish loop */
1497 }
1498 
1499 
1500 /*
1501 ** Read an expression and generate code to put its results in next
1502 ** stack slot.
1503 **
1504 */
1505 static void exp1 (LexState *ls) {
1506  expdesc e;
1507  expr(ls, &e);
1508  luaK_exp2nextreg(ls->fs, &e);
1509  lua_assert(e.k == VNONRELOC);
1510 }
1511 
1512 
1513 /*
1514 ** Fix for instruction at position 'pc' to jump to 'dest'.
1515 ** (Jump addresses are relative in Lua). 'back' true means
1516 ** a back jump.
1517 */
1518 static void fixforjump (FuncState *fs, int pc, int dest, int back) {
1519  Instruction *jmp = &fs->f->code[pc];
1520  int offset = dest - (pc + 1);
1521  if (back)
1522  offset = -offset;
1523  if (l_unlikely(offset > MAXARG_Bx))
1524  luaX_syntaxerror(fs->ls, "control structure too long");
1525  SETARG_Bx(*jmp, offset);
1526 }
1527 
1528 
1529 /*
1530 ** Generate code for a 'for' loop.
1531 */
1532 static void forbody (LexState *ls, int base, int line, int nvars, int isgen) {
1533  /* forbody -> DO block */
1534  static const OpCode forprep[2] = {OP_FORPREP, OP_TFORPREP};
1535  static const OpCode forloop[2] = {OP_FORLOOP, OP_TFORLOOP};
1536  BlockCnt bl;
1537  FuncState *fs = ls->fs;
1538  int prep, endfor;
1539  checknext(ls, TK_DO);
1540  prep = luaK_codeABx(fs, forprep[isgen], base, 0);
1541  enterblock(fs, &bl, 0); /* scope for declared variables */
1542  adjustlocalvars(ls, nvars);
1543  luaK_reserveregs(fs, nvars);
1544  block(ls);
1545  leaveblock(fs); /* end of scope for declared variables */
1546  fixforjump(fs, prep, luaK_getlabel(fs), 0);
1547  if (isgen) { /* generic for? */
1548  luaK_codeABC(fs, OP_TFORCALL, base, 0, nvars);
1549  luaK_fixline(fs, line);
1550  }
1551  endfor = luaK_codeABx(fs, forloop[isgen], base, 0);
1552  fixforjump(fs, endfor, prep + 1, 1);
1553  luaK_fixline(fs, line);
1554 }
1555 
1556 
1557 static void fornum (LexState *ls, TString *varname, int line) {
1558  /* fornum -> NAME = exp,exp[,exp] forbody */
1559  FuncState *fs = ls->fs;
1560  int base = fs->freereg;
1561  new_localvarliteral(ls, "(for state)");
1562  new_localvarliteral(ls, "(for state)");
1563  new_localvarliteral(ls, "(for state)");
1564  new_localvar(ls, varname);
1565  checknext(ls, '=');
1566  exp1(ls); /* initial value */
1567  checknext(ls, ',');
1568  exp1(ls); /* limit */
1569  if (testnext(ls, ','))
1570  exp1(ls); /* optional step */
1571  else { /* default step = 1 */
1572  luaK_int(fs, fs->freereg, 1);
1573  luaK_reserveregs(fs, 1);
1574  }
1575  adjustlocalvars(ls, 3); /* control variables */
1576  forbody(ls, base, line, 1, 0);
1577 }
1578 
1579 
1580 static void forlist (LexState *ls, TString *indexname) {
1581  /* forlist -> NAME {,NAME} IN explist forbody */
1582  FuncState *fs = ls->fs;
1583  expdesc e;
1584  int nvars = 5; /* gen, state, control, toclose, 'indexname' */
1585  int line;
1586  int base = fs->freereg;
1587  /* create control variables */
1588  new_localvarliteral(ls, "(for state)");
1589  new_localvarliteral(ls, "(for state)");
1590  new_localvarliteral(ls, "(for state)");
1591  new_localvarliteral(ls, "(for state)");
1592  /* create declared variables */
1593  new_localvar(ls, indexname);
1594  while (testnext(ls, ',')) {
1595  new_localvar(ls, str_checkname(ls));
1596  nvars++;
1597  }
1598  checknext(ls, TK_IN);
1599  line = ls->linenumber;
1600  adjust_assign(ls, 4, explist(ls, &e), &e);
1601  adjustlocalvars(ls, 4); /* control variables */
1602  markupval(fs, fs->nactvar); /* last control var. must be closed */
1603  luaK_checkstack(fs, 3); /* extra space to call generator */
1604  forbody(ls, base, line, nvars - 4, 1);
1605 }
1606 
1607 
1608 static void forstat (LexState *ls, int line) {
1609  /* forstat -> FOR (fornum | forlist) END */
1610  FuncState *fs = ls->fs;
1611  TString *varname;
1612  BlockCnt bl;
1613  enterblock(fs, &bl, 1); /* scope for loop and control variables */
1614  luaX_next(ls); /* skip 'for' */
1615  varname = str_checkname(ls); /* first variable name */
1616  switch (ls->t.token) {
1617  case '=': fornum(ls, varname, line); break;
1618  case ',': case TK_IN: forlist(ls, varname); break;
1619  default: luaX_syntaxerror(ls, "'=' or 'in' expected");
1620  }
1621  check_match(ls, TK_END, TK_FOR, line);
1622  leaveblock(fs); /* loop scope ('break' jumps to this point) */
1623 }
1624 
1625 
1626 static void test_then_block (LexState *ls, int *escapelist) {
1627  /* test_then_block -> [IF | ELSEIF] cond THEN block */
1628  BlockCnt bl;
1629  FuncState *fs = ls->fs;
1630  expdesc v;
1631  int jf; /* instruction to skip 'then' code (if condition is false) */
1632  luaX_next(ls); /* skip IF or ELSEIF */
1633  expr(ls, &v); /* read condition */
1634  checknext(ls, TK_THEN);
1635  if (ls->t.token == TK_BREAK) { /* 'if x then break' ? */
1636  int line = ls->linenumber;
1637  luaK_goiffalse(ls->fs, &v); /* will jump if condition is true */
1638  luaX_next(ls); /* skip 'break' */
1639  enterblock(fs, &bl, 0); /* must enter block before 'goto' */
1640  newgotoentry(ls, luaS_newliteral(ls->L, "break"), line, v.t);
1641  while (testnext(ls, ';')) {} /* skip semicolons */
1642  if (block_follow(ls, 0)) { /* jump is the entire block? */
1643  leaveblock(fs);
1644  return; /* and that is it */
1645  }
1646  else /* must skip over 'then' part if condition is false */
1647  jf = luaK_jump(fs);
1648  }
1649  else { /* regular case (not a break) */
1650  luaK_goiftrue(ls->fs, &v); /* skip over block if condition is false */
1651  enterblock(fs, &bl, 0);
1652  jf = v.f;
1653  }
1654  statlist(ls); /* 'then' part */
1655  leaveblock(fs);
1656  if (ls->t.token == TK_ELSE ||
1657  ls->t.token == TK_ELSEIF) /* followed by 'else'/'elseif'? */
1658  luaK_concat(fs, escapelist, luaK_jump(fs)); /* must jump over it */
1659  luaK_patchtohere(fs, jf);
1660 }
1661 
1662 
1663 static void ifstat (LexState *ls, int line) {
1664  /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */
1665  FuncState *fs = ls->fs;
1666  int escapelist = NO_JUMP; /* exit list for finished parts */
1667  test_then_block(ls, &escapelist); /* IF cond THEN block */
1668  while (ls->t.token == TK_ELSEIF)
1669  test_then_block(ls, &escapelist); /* ELSEIF cond THEN block */
1670  if (testnext(ls, TK_ELSE))
1671  block(ls); /* 'else' part */
1672  check_match(ls, TK_END, TK_IF, line);
1673  luaK_patchtohere(fs, escapelist); /* patch escape list to 'if' end */
1674 }
1675 
1676 
1677 static void localfunc (LexState *ls) {
1678  expdesc b;
1679  FuncState *fs = ls->fs;
1680  int fvar = fs->nactvar; /* function's variable index */
1681  new_localvar(ls, str_checkname(ls)); /* new local variable */
1682  adjustlocalvars(ls, 1); /* enter its scope */
1683  body(ls, &b, 0, ls->linenumber); /* function created in next register */
1684  /* debug information will only see the variable after this point! */
1685  localdebuginfo(fs, fvar)->startpc = fs->pc;
1686 }
1687 
1688 
1689 static int getlocalattribute (LexState *ls) {
1690  /* ATTRIB -> ['<' Name '>'] */
1691  if (testnext(ls, '<')) {
1692  const char *attr = getstr(str_checkname(ls));
1693  checknext(ls, '>');
1694  if (strcmp(attr, "const") == 0)
1695  return RDKCONST; /* read-only variable */
1696  else if (strcmp(attr, "close") == 0)
1697  return RDKTOCLOSE; /* to-be-closed variable */
1698  else
1699  luaK_semerror(ls,
1700  luaO_pushfstring(ls->L, "unknown attribute '%s'", attr));
1701  }
1702  return VDKREG; /* regular variable */
1703 }
1704 
1705 
1706 static void checktoclose (LexState *ls, int level) {
1707  if (level != -1) { /* is there a to-be-closed variable? */
1708  FuncState *fs = ls->fs;
1709  markupval(fs, level + 1);
1710  fs->bl->insidetbc = 1; /* in the scope of a to-be-closed variable */
1711  luaK_codeABC(fs, OP_TBC, reglevel(fs, level), 0, 0);
1712  }
1713 }
1714 
1715 
1716 static void localstat (LexState *ls) {
1717  /* stat -> LOCAL NAME ATTRIB { ',' NAME ATTRIB } ['=' explist] */
1718  FuncState *fs = ls->fs;
1719  int toclose = -1; /* index of to-be-closed variable (if any) */
1720  Vardesc *var; /* last variable */
1721  int vidx, kind; /* index and kind of last variable */
1722  int nvars = 0;
1723  int nexps;
1724  expdesc e;
1725  do {
1726  vidx = new_localvar(ls, str_checkname(ls));
1727  kind = getlocalattribute(ls);
1728  getlocalvardesc(fs, vidx)->vd.kind = kind;
1729  if (kind == RDKTOCLOSE) { /* to-be-closed? */
1730  if (toclose != -1) /* one already present? */
1731  luaK_semerror(ls, "multiple to-be-closed variables in local list");
1732  toclose = fs->nactvar + nvars;
1733  }
1734  nvars++;
1735  } while (testnext(ls, ','));
1736  if (testnext(ls, '='))
1737  nexps = explist(ls, &e);
1738  else {
1739  e.k = VVOID;
1740  nexps = 0;
1741  }
1742  var = getlocalvardesc(fs, vidx); /* get last variable */
1743  if (nvars == nexps && /* no adjustments? */
1744  var->vd.kind == RDKCONST && /* last variable is const? */
1745  luaK_exp2const(fs, &e, &var->k)) { /* compile-time constant? */
1746  var->vd.kind = RDKCTC; /* variable is a compile-time constant */
1747  adjustlocalvars(ls, nvars - 1); /* exclude last variable */
1748  fs->nactvar++; /* but count it */
1749  }
1750  else {
1751  adjust_assign(ls, nvars, nexps, &e);
1752  adjustlocalvars(ls, nvars);
1753  }
1754  checktoclose(ls, toclose);
1755 }
1756 
1757 
1758 static int funcname (LexState *ls, expdesc *v) {
1759  /* funcname -> NAME {fieldsel} [':' NAME] */
1760  int ismethod = 0;
1761  singlevar(ls, v);
1762  while (ls->t.token == '.')
1763  fieldsel(ls, v);
1764  if (ls->t.token == ':') {
1765  ismethod = 1;
1766  fieldsel(ls, v);
1767  }
1768  return ismethod;
1769 }
1770 
1771 
1772 static void funcstat (LexState *ls, int line) {
1773  /* funcstat -> FUNCTION funcname body */
1774  int ismethod;
1775  expdesc v, b;
1776  luaX_next(ls); /* skip FUNCTION */
1777  ismethod = funcname(ls, &v);
1778  body(ls, &b, ismethod, line);
1779  luaK_storevar(ls->fs, &v, &b);
1780  luaK_fixline(ls->fs, line); /* definition "happens" in the first line */
1781 }
1782 
1783 
1784 static void exprstat (LexState *ls) {
1785  /* stat -> func | assignment */
1786  FuncState *fs = ls->fs;
1787  struct LHS_assign v;
1788  suffixedexp(ls, &v.v);
1789  if (ls->t.token == '=' || ls->t.token == ',') { /* stat -> assignment ? */
1790  v.prev = NULL;
1791  restassign(ls, &v, 1);
1792  }
1793  else { /* stat -> func */
1794  Instruction *inst;
1795  check_condition(ls, v.v.k == VCALL, "syntax error");
1796  inst = &getinstruction(fs, &v.v);
1797  SETARG_C(*inst, 1); /* call statement uses no results */
1798  }
1799 }
1800 
1801 
1802 static void retstat (LexState *ls) {
1803  /* stat -> RETURN [explist] [';'] */
1804  FuncState *fs = ls->fs;
1805  expdesc e;
1806  int nret; /* number of values being returned */
1807  int first = luaY_nvarstack(fs); /* first slot to be returned */
1808  if (block_follow(ls, 1) || ls->t.token == ';')
1809  nret = 0; /* return no values */
1810  else {
1811  nret = explist(ls, &e); /* optional return values */
1812  if (hasmultret(e.k)) {
1813  luaK_setmultret(fs, &e);
1814  if (e.k == VCALL && nret == 1 && !fs->bl->insidetbc) { /* tail call? */
1817  }
1818  nret = LUA_MULTRET; /* return all values */
1819  }
1820  else {
1821  if (nret == 1) /* only one single value? */
1822  first = luaK_exp2anyreg(fs, &e); /* can use original slot */
1823  else { /* values must go to the top of the stack */
1824  luaK_exp2nextreg(fs, &e);
1825  lua_assert(nret == fs->freereg - first);
1826  }
1827  }
1828  }
1829  luaK_ret(fs, first, nret);
1830  testnext(ls, ';'); /* skip optional semicolon */
1831 }
1832 
1833 
1834 static void statement (LexState *ls) {
1835  int line = ls->linenumber; /* may be needed for error messages */
1836  enterlevel(ls);
1837  switch (ls->t.token) {
1838  case ';': { /* stat -> ';' (empty statement) */
1839  luaX_next(ls); /* skip ';' */
1840  break;
1841  }
1842  case TK_IF: { /* stat -> ifstat */
1843  ifstat(ls, line);
1844  break;
1845  }
1846  case TK_WHILE: { /* stat -> whilestat */
1847  whilestat(ls, line);
1848  break;
1849  }
1850  case TK_DO: { /* stat -> DO block END */
1851  luaX_next(ls); /* skip DO */
1852  block(ls);
1853  check_match(ls, TK_END, TK_DO, line);
1854  break;
1855  }
1856  case TK_FOR: { /* stat -> forstat */
1857  forstat(ls, line);
1858  break;
1859  }
1860  case TK_REPEAT: { /* stat -> repeatstat */
1861  repeatstat(ls, line);
1862  break;
1863  }
1864  case TK_FUNCTION: { /* stat -> funcstat */
1865  funcstat(ls, line);
1866  break;
1867  }
1868  case TK_LOCAL: { /* stat -> localstat */
1869  luaX_next(ls); /* skip LOCAL */
1870  if (testnext(ls, TK_FUNCTION)) /* local function? */
1871  localfunc(ls);
1872  else
1873  localstat(ls);
1874  break;
1875  }
1876  case TK_DBCOLON: { /* stat -> label */
1877  luaX_next(ls); /* skip double colon */
1878  labelstat(ls, str_checkname(ls), line);
1879  break;
1880  }
1881  case TK_RETURN: { /* stat -> retstat */
1882  luaX_next(ls); /* skip RETURN */
1883  retstat(ls);
1884  break;
1885  }
1886  case TK_BREAK: { /* stat -> breakstat */
1887  breakstat(ls);
1888  break;
1889  }
1890  case TK_GOTO: { /* stat -> 'goto' NAME */
1891  luaX_next(ls); /* skip 'goto' */
1892  gotostat(ls);
1893  break;
1894  }
1895  default: { /* stat -> func | assignment */
1896  exprstat(ls);
1897  break;
1898  }
1899  }
1900  lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg &&
1901  ls->fs->freereg >= luaY_nvarstack(ls->fs));
1902  ls->fs->freereg = luaY_nvarstack(ls->fs); /* free registers */
1903  leavelevel(ls);
1904 }
1905 
1906 /* }====================================================================== */
1907 
1908 
1909 /*
1910 ** compiles the main function, which is a regular vararg function with an
1911 ** upvalue named LUA_ENV
1912 */
1913 static void mainfunc (LexState *ls, FuncState *fs) {
1914  BlockCnt bl;
1915  Upvaldesc *env;
1916  open_func(ls, fs, &bl);
1917  setvararg(fs, 0); /* main function is always declared vararg */
1918  env = allocupvalue(fs); /* ...set environment upvalue */
1919  env->instack = 1;
1920  env->idx = 0;
1921  env->kind = VDKREG;
1922  env->name = ls->envn;
1923  luaC_objbarrier(ls->L, fs->f, env->name);
1924  luaX_next(ls); /* read first token */
1925  statlist(ls); /* parse main body */
1926  check(ls, TK_EOS);
1927  close_func(ls);
1928 }
1929 
1930 
1932  Dyndata *dyd, const char *name, int firstchar) {
1933  LexState lexstate;
1934  FuncState funcstate;
1935  LClosure *cl = luaF_newLclosure(L, 1); /* create main closure */
1936  setclLvalue2s(L, L->top, cl); /* anchor it (to avoid being collected) */
1937  luaD_inctop(L);
1938  lexstate.h = luaH_new(L); /* create table for scanner */
1939  sethvalue2s(L, L->top, lexstate.h); /* anchor it */
1940  luaD_inctop(L);
1941  funcstate.f = cl->p = luaF_newproto(L);
1942  luaC_objbarrier(L, cl, cl->p);
1943  funcstate.f->source = luaS_new(L, name); /* create and anchor TString */
1944  luaC_objbarrier(L, funcstate.f, funcstate.f->source);
1945  lexstate.buff = buff;
1946  lexstate.dyd = dyd;
1947  dyd->actvar.n = dyd->gt.n = dyd->label.n = 0;
1948  luaX_setinput(L, &lexstate, z, funcstate.f->source, firstchar);
1949  mainfunc(&lexstate, &funcstate);
1950  lua_assert(!funcstate.prev && funcstate.nups == 1 && !lexstate.fs);
1951  /* all scopes should be correctly finished */
1952  lua_assert(dyd->actvar.n == 0 && dyd->gt.n == 0 && dyd->label.n == 0);
1953  L->top--; /* remove scanner's table */
1954  return cl; /* closure is on the stack, too */
1955 }
1956 
luaX_next
void luaX_next(LexState *ls)
Definition: llex.c:565
TK_IF
@ TK_IF
Definition: llex.h:36
setvararg
static void setvararg(FuncState *fs, int nparams)
Definition: lparser.c:941
hasmultret
#define hasmultret(k)
Definition: lparser.c:38
ConsControl::tostore
int tostore
Definition: lparser.c:831
luaK_exp2anyreg
int luaK_exp2anyreg(FuncState *fs, expdesc *e)
Definition: lcode.c:936
OPR_GE
@ OPR_GE
Definition: lcode.h:37
VLOCAL
@ VLOCAL
Definition: lparser.h:38
left
lu_byte left
Definition: lparser.c:1226
luaK_goiffalse
void luaK_goiffalse(FuncState *fs, expdesc *e)
Definition: lcode.c:1142
luaY_parser
LClosure * luaY_parser(lua_State *L, ZIO *z, Mbuffer *buff, Dyndata *dyd, const char *name, int firstchar)
Definition: lparser.c:1931
LexState::fs
struct FuncState * fs
Definition: llex.h:70
TK_SHR
@ TK_SHR
Definition: llex.h:40
LClosure::p
struct Proto * p
Definition: lobject.h:643
op
#define op
expdesc::info
int info
Definition: lparser.h:74
lua_assert
#define lua_assert(c)
Definition: lauxlib.h:170
detail::first
auto first(const T &value, const Tail &...) -> const T &
Definition: compile.h:60
Proto::linedefined
int linedefined
Definition: lobject.h:551
restassign
static void restassign(LexState *ls, struct LHS_assign *lh, int nvars)
Definition: lparser.c:1363
luaK_fixline
void luaK_fixline(FuncState *fs, int line)
Definition: lcode.c:1726
ls_byte
signed char ls_byte
Definition: llimits.h:37
LClosure
Definition: lobject.h:641
OPR_AND
@ OPR_AND
Definition: lcode.h:39
OP_VARARG
@ OP_VARARG
Definition: lopcodes.h:304
VCONST
@ VCONST
Definition: lparser.h:41
cast_byte
#define cast_byte(i)
Definition: llimits.h:130
l_noret
#define l_noret
Definition: llimits.h:162
ConsControl::t
expdesc * t
Definition: lparser.c:828
FuncState::ndebugvars
short ndebugvars
Definition: lparser.h:157
OP_TFORPREP
@ OP_TFORPREP
Definition: lopcodes.h:296
Labellist::arr
Labeldesc * arr
Definition: lparser.h:121
LexState::h
Table * h
Definition: llex.h:74
allocupvalue
static Upvaldesc * allocupvalue(FuncState *fs)
Definition: lparser.c:352
TString
Definition: lobject.h:373
jumpscopeerror
static l_noret jumpscopeerror(LexState *ls, Labeldesc *gt)
Definition: lparser.c:502
check_readonly
static void check_readonly(LexState *ls, expdesc *e)
Definition: lparser.c:277
localstat
static void localstat(LexState *ls)
Definition: lparser.c:1716
codename
static void codename(LexState *ls, expdesc *e)
Definition: lparser.c:166
TK_THEN
@ TK_THEN
Definition: llex.h:37
luaX_token2str
const char * luaX_token2str(LexState *ls, int token)
Definition: llex.c:82
simpleexp
static void simpleexp(LexState *ls, expdesc *v)
Definition: lparser.c:1128
LUA_MULTRET
#define LUA_MULTRET
Definition: lua.h:36
VUPVAL
@ VUPVAL
Definition: lparser.h:40
luaX_setinput
void luaX_setinput(lua_State *L, LexState *ls, ZIO *z, TString *source, int firstchar)
Definition: llex.c:167
lstate.h
vkisvar
#define vkisvar(k)
Definition: lparser.h:64
TK_REPEAT
@ TK_REPEAT
Definition: llex.h:36
new_localvarliteral
#define new_localvarliteral(ls, v)
Definition: lparser.c:208
Labeldesc::close
lu_byte close
Definition: lparser.h:115
FuncState::needclose
lu_byte needclose
Definition: lparser.h:162
Labellist::size
int size
Definition: lparser.h:123
RDKCONST
#define RDKCONST
Definition: lparser.h:91
OP_TAILCALL
@ OP_TAILCALL
Definition: lopcodes.h:286
close_func
static void close_func(LexState *ls)
Definition: lparser.c:744
TK_NE
@ TK_NE
Definition: llex.h:39
BlockCnt::firstlabel
int firstlabel
Definition: lparser.c:51
luaK_patchlist
void luaK_patchlist(FuncState *fs, int list, int target)
Definition: lcode.c:305
luaK_jumpto
#define luaK_jumpto(fs, t)
Definition: lcode.h:60
FuncState::freereg
lu_byte freereg
Definition: lparser.h:160
lcode.h
searchupvalue
static int searchupvalue(FuncState *fs, TString *name)
Definition: lparser.c:342
RDKCTC
#define RDKCTC
Definition: lparser.h:93
Proto::locvars
LocVar * locvars
Definition: lobject.h:559
LHS_assign::prev
struct LHS_assign * prev
Definition: lparser.c:1308
OP_CALL
@ OP_CALL
Definition: lopcodes.h:285
enterblock
static void enterblock(FuncState *fs, BlockCnt *bl, lu_byte isloop)
Definition: lparser.c:630
OPR_NOUNOPR
@ OPR_NOUNOPR
Definition: lcode.h:51
Proto::code
Instruction * code
Definition: lobject.h:554
TK_FLT
@ TK_FLT
Definition: llex.h:42
OPR_NOT
@ OPR_NOT
Definition: lcode.h:51
luaC_objbarrier
#define luaC_objbarrier(L, p, o)
Definition: lgc.h:173
ConsControl::nh
int nh
Definition: lparser.c:829
VNONRELOC
@ VNONRELOC
Definition: lparser.h:36
exp1
static void exp1(LexState *ls)
Definition: lparser.c:1505
luaK_setlist
void luaK_setlist(FuncState *fs, int base, int nelems, int tostore)
Definition: lcode.c:1750
check_condition
#define check_condition(ls, c, msg)
Definition: lparser.c:122
Token::token
int token
Definition: llex.h:57
OP_GETUPVAL
@ OP_GETUPVAL
Definition: lopcodes.h:209
FuncState::nabslineinfo
int nabslineinfo
Definition: lparser.h:154
luaS_new
TString * luaS_new(lua_State *L, const char *str)
Definition: lstring.c:241
cond
static int cond(LexState *ls)
Definition: lparser.c:1394
s
XmlRpcServer s
checkrepeated
static void checkrepeated(LexState *ls, TString *name)
Definition: lparser.c:1436
GETARG_A
#define GETARG_A(i)
Definition: lopcodes.h:125
closelistfield
static void closelistfield(FuncState *fs, ConsControl *cc)
Definition: lparser.c:856
TK_IDIV
@ TK_IDIV
Definition: llex.h:39
solvegotos
static int solvegotos(LexState *ls, Labeldesc *lb)
Definition: lparser.c:573
ltable.h
luaC_checkGC
#define luaC_checkGC(L)
Definition: lgc.h:162
Dyndata::size
int size
Definition: lparser.h:132
primaryexp
static void primaryexp(LexState *ls, expdesc *v)
Definition: lparser.c:1068
LexState::source
TString * source
Definition: llex.h:76
localfunc
static void localfunc(LexState *ls)
Definition: lparser.c:1677
Vardesc
Definition: lparser.h:96
FuncState::nactvar
lu_byte nactvar
Definition: lparser.h:158
Proto::is_vararg
lu_byte is_vararg
Definition: lobject.h:542
Proto::source
TString * source
Definition: lobject.h:560
lua_State::top
StkId top
Definition: lstate.h:309
luaK_setmultret
#define luaK_setmultret(fs, e)
Definition: lcode.h:58
right
lu_byte right
Definition: lparser.c:1227
expdesc::var
struct expdesc::@7::@9 var
OP_FORLOOP
@ OP_FORLOOP
Definition: lopcodes.h:292
TK_WHILE
@ TK_WHILE
Definition: llex.h:37
LHS_assign
Definition: lparser.c:1307
FuncState::np
int np
Definition: lparser.h:153
removevars
static void removevars(FuncState *fs, int tolevel)
Definition: lparser.c:328
SemInfo::i
lua_Integer i
Definition: llex.h:51
init_exp
static void init_exp(expdesc *e, expkind k, int i)
Definition: lparser.c:152
undefgoto
static l_noret undefgoto(LexState *ls, Labeldesc *gt)
Definition: lparser.c:646
checklimit
static void checklimit(FuncState *fs, int v, int l, const char *what)
Definition: lparser.c:87
TK_BREAK
@ TK_BREAK
Definition: llex.h:34
Upvaldesc::kind
lu_byte kind
Definition: lobject.h:506
OPR_MOD
@ OPR_MOD
Definition: lcode.h:28
forprep
static int forprep(lua_State *L, StkId ra)
Definition: lvm.c:206
FuncState::f
Proto * f
Definition: lparser.h:145
TK_LOCAL
@ TK_LOCAL
Definition: llex.h:36
BlockCnt::nactvar
lu_byte nactvar
Definition: lparser.c:53
expdesc::strval
TString * strval
Definition: lparser.h:73
SemInfo::ts
TString * ts
Definition: llex.h:52
Labeldesc
Definition: lparser.h:110
fixforjump
static void fixforjump(FuncState *fs, int pc, int dest, int back)
Definition: lparser.c:1518
OPR_GT
@ OPR_GT
Definition: lcode.h:37
OPR_MUL
@ OPR_MUL
Definition: lcode.h:28
OPR_SHL
@ OPR_SHL
Definition: lcode.h:32
llex.h
adjustlocalvars
static void adjustlocalvars(LexState *ls, int nvars)
Definition: lparser.c:311
adjust_assign
static void adjust_assign(LexState *ls, int nvars, int nexps, expdesc *e)
Definition: lparser.c:470
AbsLineInfo
Definition: lobject.h:531
Vardesc::vd
struct Vardesc::@10 vd
SETARG_Bx
#define SETARG_Bx(i, v)
Definition: lopcodes.h:141
Proto::lastlinedefined
int lastlinedefined
Definition: lobject.h:552
VKFLT
@ VKFLT
Definition: lparser.h:32
OPR_BOR
@ OPR_BOR
Definition: lcode.h:31
VINDEXED
@ VINDEXED
Definition: lparser.h:43
OPR_LEN
@ OPR_LEN
Definition: lcode.h:51
leaveblock
static void leaveblock(FuncState *fs)
Definition: lparser.c:660
luaK_infix
void luaK_infix(FuncState *fs, BinOpr op, expdesc *v)
Definition: lcode.c:1574
registerlocalvar
static int registerlocalvar(LexState *ls, FuncState *fs, TString *varname)
Definition: lparser.c:175
fornum
static void fornum(LexState *ls, TString *varname, int line)
Definition: lparser.c:1557
OPR_DIV
@ OPR_DIV
Definition: lcode.h:29
mqtt_test_proto.msg
msg
Definition: mqtt_test_proto.py:43
LexState::envn
TString * envn
Definition: llex.h:77
OPR_NOBINOPR
@ OPR_NOBINOPR
Definition: lcode.h:40
luaK_posfix
void luaK_posfix(FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2, int line)
Definition: lcode.c:1642
LexState::L
struct lua_State * L
Definition: llex.h:71
body
static void body(LexState *ls, expdesc *e, int ismethod, int line)
Definition: lparser.c:978
TK_ELSE
@ TK_ELSE
Definition: llex.h:35
solvegoto
static void solvegoto(LexState *ls, int g, Labeldesc *label)
Definition: lparser.c:515
new_localvar
static int new_localvar(LexState *ls, TString *name)
Definition: lparser.c:193
LFIELDS_PER_FLUSH
#define LFIELDS_PER_FLUSH
Definition: lopcodes.h:390
fieldsel
static void fieldsel(LexState *ls, expdesc *v)
Definition: lparser.c:799
Labeldesc::nactvar
lu_byte nactvar
Definition: lparser.h:114
FuncState
Definition: lparser.h:144
TK_DBCOLON
@ TK_DBCOLON
Definition: llex.h:41
Upvaldesc::instack
lu_byte instack
Definition: lobject.h:504
TK_RETURN
@ TK_RETURN
Definition: llex.h:37
check_conflict
static void check_conflict(LexState *ls, struct LHS_assign *lh, expdesc *v)
Definition: lparser.c:1319
statlist
static void statlist(LexState *ls)
Definition: lparser.c:787
OP_MOVE
@ OP_MOVE
Definition: lopcodes.h:200
TK_AND
@ TK_AND
Definition: llex.h:34
testnext
static int testnext(LexState *ls, int c)
Definition: lparser.c:95
OPR_EQ
@ OPR_EQ
Definition: lcode.h:36
f
f
yindex
static void yindex(LexState *ls, expdesc *v)
Definition: lparser.c:810
mqtt_test_proto.z
z
Definition: mqtt_test_proto.py:36
singlevaraux
static void singlevaraux(FuncState *fs, TString *n, expdesc *var, int base)
Definition: lparser.c:424
errorlimit
static l_noret errorlimit(FuncState *fs, int limit, const char *what)
Definition: lparser.c:74
Dyndata::label
Labellist label
Definition: lparser.h:135
TK_END
@ TK_END
Definition: llex.h:35
str_checkname
static TString * str_checkname(LexState *ls)
Definition: lparser.c:143
TK_SHL
@ TK_SHL
Definition: llex.h:40
TK_UNTIL
@ TK_UNTIL
Definition: llex.h:37
Dyndata::gt
Labellist gt
Definition: lparser.h:134
lua.h
breakstat
static void breakstat(LexState *ls)
Definition: lparser.c:1426
OP_CLOSE
@ OP_CLOSE
Definition: lopcodes.h:268
TK_FALSE
@ TK_FALSE
Definition: llex.h:35
VNIL
@ VNIL
Definition: lparser.h:28
leavelevel
#define leavelevel(ls)
Definition: lparser.c:495
OPR_ADD
@ OPR_ADD
Definition: lcode.h:28
MAXARG_Bx
#define MAXARG_Bx
Definition: lopcodes.h:74
getlocalattribute
static int getlocalattribute(LexState *ls)
Definition: lparser.c:1689
MAXUPVAL
#define MAXUPVAL
Definition: lfunc.h:29
luaK_code
int luaK_code(FuncState *fs, Instruction i)
Definition: lcode.c:381
Dyndata::n
int n
Definition: lparser.h:131
SETARG_C
#define SETARG_C(i, v)
Definition: lopcodes.h:134
OPR_SUB
@ OPR_SUB
Definition: lcode.h:28
SET_OPCODE
#define SET_OPCODE(i, o)
Definition: lopcodes.h:115
Mbuffer
Definition: lzio.h:23
luaK_jump
int luaK_jump(FuncState *fs)
Definition: lcode.c:198
OP_TFORLOOP
@ OP_TFORLOOP
Definition: lopcodes.h:298
luaK_exp2anyregup
void luaK_exp2anyregup(FuncState *fs, expdesc *e)
Definition: lcode.c:958
expdesc::ind
struct expdesc::@7::@8 ind
luaK_patchtohere
void luaK_patchtohere(FuncState *fs, int list)
Definition: lcode.c:311
getbinopr
static BinOpr getbinopr(int op)
Definition: lparser.c:1194
sol::var
auto var(V &&v)
Definition: sol.hpp:18020
expdesc::f
int f
Definition: lparser.h:85
luaX_syntaxerror
l_noret luaX_syntaxerror(LexState *ls, const char *msg)
Definition: llex.c:119
luaK_int
void luaK_int(FuncState *fs, int reg, lua_Integer i)
Definition: lcode.c:654
luaK_storevar
void luaK_storevar(FuncState *fs, expdesc *var, expdesc *ex)
Definition: lcode.c:1030
OP_CLOSURE
@ OP_CLOSURE
Definition: lopcodes.h:302
codestring
static void codestring(expdesc *e, TString *s)
Definition: lparser.c:159
expkind
expkind
Definition: lparser.h:25
TK_ELSEIF
@ TK_ELSEIF
Definition: llex.h:35
FuncState::bl
struct BlockCnt * bl
Definition: lparser.h:148
OPR_IDIV
@ OPR_IDIV
Definition: lcode.h:29
FuncState::ls
struct LexState * ls
Definition: lparser.h:147
LocVar::startpc
int startpc
Definition: lobject.h:516
forstat
static void forstat(LexState *ls, int line)
Definition: lparser.c:1608
MAXVARS
#define MAXVARS
Definition: lparser.c:35
VDKREG
#define VDKREG
Definition: lparser.h:90
FuncState::prev
struct FuncState * prev
Definition: lparser.h:146
VTRUE
@ VTRUE
Definition: lparser.h:29
error_expected
static l_noret error_expected(LexState *ls, int token)
Definition: lparser.c:68
getlocalvardesc
static Vardesc * getlocalvardesc(FuncState *fs, int vidx)
Definition: lparser.c:219
lprefix.h
TK_NOT
@ TK_NOT
Definition: llex.h:36
funcname
static int funcname(LexState *ls, expdesc *v)
Definition: lparser.c:1758
Vardesc::ridx
lu_byte ridx
Definition: lparser.h:100
setclLvalue2s
#define setclLvalue2s(L, o, cl)
Definition: lobject.h:602
check
static void check(LexState *ls, int c)
Definition: lparser.c:107
ldebug.h
LexState::linenumber
int linenumber
Definition: llex.h:66
Vardesc::pidx
short pidx
Definition: lparser.h:101
TK_OR
@ TK_OR
Definition: llex.h:36
vkisindexed
#define vkisindexed(k)
Definition: lparser.h:65
ConsControl
struct ConsControl ConsControl
VINDEXUP
@ VINDEXUP
Definition: lparser.h:46
TK_IN
@ TK_IN
Definition: llex.h:36
lu_byte
unsigned char lu_byte
Definition: llimits.h:36
luaM_shrinkvector
#define luaM_shrinkvector(L, v, size, fs, t)
Definition: lmem.h:74
OP_TBC
@ OP_TBC
Definition: lopcodes.h:269
getstr
#define getstr(ts)
Definition: lobject.h:390
constructor
static void constructor(LexState *ls, expdesc *t)
Definition: lparser.c:913
BlockCnt::firstgoto
int firstgoto
Definition: lparser.c:52
lua_State
Definition: lstate.h:304
FuncState::previousline
int previousline
Definition: lparser.h:151
luaD_inctop
void luaD_inctop(lua_State *L)
Definition: ldo.c:293
ConsControl
Definition: lparser.c:826
newupvalue
static int newupvalue(FuncState *fs, TString *name, expdesc *v)
Definition: lparser.c:364
OP_VARARGPREP
@ OP_VARARGPREP
Definition: lopcodes.h:306
explist
static int explist(LexState *ls, expdesc *v)
Definition: lparser.c:1000
VFALSE
@ VFALSE
Definition: lparser.h:30
mainfunc
static void mainfunc(LexState *ls, FuncState *fs)
Definition: lparser.c:1913
OPR_CONCAT
@ OPR_CONCAT
Definition: lcode.h:34
checktoclose
static void checktoclose(LexState *ls, int level)
Definition: lparser.c:1706
expdesc::k
expkind k
Definition: lparser.h:69
LHS_assign::v
expdesc v
Definition: lparser.c:1309
BlockCnt
struct BlockCnt BlockCnt
FuncState::iwthabs
lu_byte iwthabs
Definition: lparser.h:161
ConsControl::na
int na
Definition: lparser.c:830
VINDEXSTR
@ VINDEXSTR
Definition: lparser.h:52
recfield
static void recfield(LexState *ls, ConsControl *cc)
Definition: lparser.c:835
FuncState::nk
int nk
Definition: lparser.h:152
Proto
Definition: lobject.h:539
UNARY_PRIORITY
#define UNARY_PRIORITY
Definition: lparser.c:1241
VRELOC
@ VRELOC
Definition: lparser.h:57
expdesc::ival
lua_Integer ival
Definition: lparser.h:71
luaK_ret
void luaK_ret(FuncState *fs, int first, int nret)
Definition: lcode.c:206
TK_EOS
@ TK_EOS
Definition: llex.h:41
getunopr
static UnOpr getunopr(int op)
Definition: lparser.c:1183
VKSTR
@ VKSTR
Definition: lparser.h:34
luaK_settablesize
void luaK_settablesize(FuncState *fs, int pc, int ra, int asize, int hsize)
Definition: lcode.c:1732
labelstat
static void labelstat(LexState *ls, TString *name, int line)
Definition: lparser.c:1446
lobject.h
Upvaldesc
Definition: lobject.h:502
luaH_new
Table * luaH_new(lua_State *L)
Definition: ltable.c:615
FuncState::lasttarget
int lasttarget
Definition: lparser.h:150
FuncState::firstlabel
int firstlabel
Definition: lparser.h:156
gotostat
static void gotostat(LexState *ls)
Definition: lparser.c:1404
OPR_MINUS
@ OPR_MINUS
Definition: lcode.h:51
retstat
static void retstat(LexState *ls)
Definition: lparser.c:1802
forlist
static void forlist(LexState *ls, TString *indexname)
Definition: lparser.c:1580
TK_GE
@ TK_GE
Definition: llex.h:39
BlockCnt::upval
lu_byte upval
Definition: lparser.c:54
BlockCnt::previous
struct BlockCnt * previous
Definition: lparser.c:50
lparser.h
subexpr
static BinOpr subexpr(LexState *ls, expdesc *v, int limit)
Definition: lparser.c:1248
parlist
static void parlist(LexState *ls)
Definition: lparser.c:947
luaK_exp2val
void luaK_exp2val(FuncState *fs, expdesc *e)
Definition: lcode.c:968
whilestat
static void whilestat(LexState *ls, int line)
Definition: lparser.c:1456
OPR_BXOR
@ OPR_BXOR
Definition: lcode.h:31
OPR_BNOT
@ OPR_BNOT
Definition: lcode.h:51
Vardesc::name
TString * name
Definition: lparser.h:102
luaK_nil
void luaK_nil(FuncState *fs, int from, int n)
Definition: lcode.c:130
luaF_newproto
Proto * luaF_newproto(lua_State *L)
Definition: lfunc.c:240
Labeldesc::line
int line
Definition: lparser.h:113
VVOID
@ VVOID
Definition: lparser.h:26
expdesc
Definition: lparser.h:68
luaK_getlabel
int luaK_getlabel(FuncState *fs)
Definition: lcode.c:231
TK_CONCAT
@ TK_CONCAT
Definition: llex.h:39
Upvaldesc::idx
lu_byte idx
Definition: lobject.h:505
ifstat
static void ifstat(LexState *ls, int line)
Definition: lparser.c:1663
Labeldesc::pc
int pc
Definition: lparser.h:112
luaO_pushfstring
const char * luaO_pushfstring(lua_State *L, const char *fmt,...)
Definition: lobject.c:539
luaM_growvector
#define luaM_growvector(L, v, nelems, size, t, limit, e)
Definition: lmem.h:66
Dyndata::arr
Vardesc * arr
Definition: lparser.h:130
dest
char * dest
Definition: lz4.h:765
OPR_LE
@ OPR_LE
Definition: lcode.h:36
BinOpr
BinOpr
Definition: lcode.h:26
open_func
static void open_func(LexState *ls, FuncState *fs, BlockCnt *bl)
Definition: lparser.c:717
FuncState::pc
int pc
Definition: lparser.h:149
TK_INT
@ TK_INT
Definition: llex.h:42
Instruction
l_uint32 Instruction
Definition: llimits.h:178
block
static void block(LexState *ls)
Definition: lparser.c:1293
luaK_checkstack
void luaK_checkstack(FuncState *fs, int n)
Definition: lcode.c:465
movegotosout
static void movegotosout(FuncState *fs, BlockCnt *bl)
Definition: lparser.c:616
LexState::t
Token t
Definition: llex.h:68
OpCode
OpCode
Definition: lopcodes.h:196
addprototype
static Proto * addprototype(LexState *ls)
Definition: lparser.c:686
LexState
Definition: llex.h:64
TK_FOR
@ TK_FOR
Definition: llex.h:35
TK_GOTO
@ TK_GOTO
Definition: llex.h:36
SemInfo::r
lua_Number r
Definition: llex.h:50
repeatstat
static void repeatstat(LexState *ls, int line)
Definition: lparser.c:1475
luaK_prefix
void luaK_prefix(FuncState *fs, UnOpr op, expdesc *e, int line)
Definition: lcode.c:1553
VKINT
@ VKINT
Definition: lparser.h:33
findlabel
static Labeldesc * findlabel(LexState *ls, TString *name)
Definition: lparser.c:532
forbody
static void forbody(LexState *ls, int base, int line, int nvars, int isgen)
Definition: lparser.c:1532
OPR_POW
@ OPR_POW
Definition: lcode.h:28
sethvalue2s
#define sethvalue2s(L, o, h)
Definition: lobject.h:676
luaK_setoneret
void luaK_setoneret(FuncState *fs, expdesc *e)
Definition: lcode.c:736
LexState::buff
Mbuffer * buff
Definition: llex.h:73
luaK_exp2const
int luaK_exp2const(FuncState *fs, const expdesc *e, TValue *v)
Definition: lcode.c:83
funcstat
static void funcstat(LexState *ls, int line)
Definition: lparser.c:1772
VCALL
@ VCALL
Definition: lparser.h:59
OPR_SHR
@ OPR_SHR
Definition: lcode.h:32
suffixedexp
static void suffixedexp(LexState *ls, expdesc *v)
Definition: lparser.c:1090
Vardesc::kind
lu_byte kind
Definition: lparser.h:99
block_follow
static int block_follow(LexState *ls, int withuntil)
Definition: lparser.c:776
luaY_nvarstack
int luaY_nvarstack(FuncState *fs)
Definition: lparser.c:243
field
static void field(LexState *ls, ConsControl *cc)
Definition: lparser.c:891
markupval
static void markupval(FuncState *fs, int level)
Definition: lparser.c:410
MAX_INT
#define MAX_INT
Definition: llimits.h:53
VVARARG
@ VVARARG
Definition: lparser.h:60
TK_TRUE
@ TK_TRUE
Definition: llex.h:37
init_var
static void init_var(FuncState *fs, expdesc *e, int vidx)
Definition: lparser.c:266
codeclosure
static void codeclosure(LexState *ls, expdesc *v)
Definition: lparser.c:710
TK_NIL
@ TK_NIL
Definition: llex.h:36
TK_DOTS
@ TK_DOTS
Definition: llex.h:39
luaK_indexed
void luaK_indexed(FuncState *fs, expdesc *t, expdesc *k)
Definition: lcode.c:1260
Labellist::n
int n
Definition: lparser.h:122
lstring.h
BlockCnt::isloop
lu_byte isloop
Definition: lparser.c:55
FuncState::firstlocal
int firstlocal
Definition: lparser.h:155
luaF_newLclosure
LClosure * luaF_newLclosure(lua_State *L, int nupvals)
Definition: lfunc.c:35
check_match
static void check_match(LexState *ls, int what, int who, int where)
Definition: lparser.c:130
listfield
static void listfield(LexState *ls, ConsControl *cc)
Definition: lparser.c:884
luaK_setreturns
void luaK_setreturns(FuncState *fs, expdesc *e, int nresults)
Definition: lcode.c:703
TK_DO
@ TK_DO
Definition: llex.h:35
OPR_LT
@ OPR_LT
Definition: lcode.h:36
expr
static void expr(LexState *ls, expdesc *v)
Definition: lparser.c:1278
TK_STRING
@ TK_STRING
Definition: llex.h:42
luaK_finish
void luaK_finish(FuncState *fs)
Definition: lcode.c:1786
TK_NAME
@ TK_NAME
Definition: llex.h:42
luaK_dischargevars
void luaK_dischargevars(FuncState *fs, expdesc *e)
Definition: lcode.c:754
luaK_concat
void luaK_concat(FuncState *fs, int *l1, int l2)
Definition: lcode.c:180
newlabelentry
static int newlabelentry(LexState *ls, Labellist *l, TString *name, int line, int pc)
Definition: lparser.c:548
FuncState::nups
lu_byte nups
Definition: lparser.h:159
reglevel
static int reglevel(FuncState *fs, int nvar)
Definition: lparser.c:229
lmem.h
checknext
static void checknext(LexState *ls, int c)
Definition: lparser.c:116
eqstr
#define eqstr(a, b)
Definition: lparser.c:43
expdesc::nval
lua_Number nval
Definition: lparser.h:72
enterlevel
#define enterlevel(ls)
Definition: lparser.c:492
OP_TFORCALL
@ OP_TFORCALL
Definition: lopcodes.h:297
luaK_goiftrue
void luaK_goiftrue(FuncState *fs, expdesc *e)
Definition: lcode.c:1115
lastlistfield
static void lastlistfield(FuncState *fs, ConsControl *cc)
Definition: lparser.c:868
Token::seminfo
SemInfo seminfo
Definition: llex.h:58
statement
static void statement(LexState *ls)
Definition: lparser.c:1834
expdesc::u
union expdesc::@7 u
luaK_semerror
l_noret luaK_semerror(LexState *ls, const char *msg)
Definition: lcode.c:45
UnOpr
UnOpr
Definition: lcode.h:51
Upvaldesc::name
TString * name
Definition: lobject.h:503
localdebuginfo
static LocVar * localdebuginfo(FuncState *fs, int vidx)
Definition: lparser.c:251
OPR_OR
@ OPR_OR
Definition: lcode.h:39
OPR_BAND
@ OPR_BAND
Definition: lcode.h:31
priority
static const struct @6 priority[]
Zio
Definition: lzio.h:55
OPR_NE
@ OPR_NE
Definition: lcode.h:37
Dyndata
Definition: lparser.h:128
luaK_codeABC
#define luaK_codeABC(fs, o, a, b, c)
Definition: lcode.h:48
createlabel
static int createlabel(LexState *ls, TString *name, int line, int last)
Definition: lparser.c:596
searchvar
static int searchvar(FuncState *fs, TString *n, expdesc *var)
Definition: lparser.c:390
luaK_reserveregs
void luaK_reserveregs(FuncState *fs, int n)
Definition: lcode.c:479
luaK_codeABx
int luaK_codeABx(FuncState *fs, OpCode o, int a, unsigned int bc)
Definition: lcode.c:407
expdesc::t
lu_byte t
Definition: lparser.h:77
luaK_self
void luaK_self(FuncState *fs, expdesc *e, expdesc *key)
Definition: lcode.c:1067
RDKTOCLOSE
#define RDKTOCLOSE
Definition: lparser.h:92
OP_FORPREP
@ OP_FORPREP
Definition: lopcodes.h:293
funcargs
static void funcargs(LexState *ls, expdesc *f, int line)
Definition: lparser.c:1013
OP_NEWTABLE
@ OP_NEWTABLE
Definition: lopcodes.h:222
BlockCnt::insidetbc
lu_byte insidetbc
Definition: lparser.c:56
ConsControl::v
expdesc v
Definition: lparser.c:827
luaS_newliteral
#define luaS_newliteral(L, s)
Definition: lstring.h:28
Labellist
Definition: lparser.h:120
TK_EQ
@ TK_EQ
Definition: llex.h:39
LexState::dyd
struct Dyndata * dyd
Definition: llex.h:75
TK_FUNCTION
@ TK_FUNCTION
Definition: llex.h:35
getinstruction
#define getinstruction(fs, e)
Definition: lcode.h:55
BlockCnt
Definition: lparser.c:49
singlevar
static void singlevar(LexState *ls, expdesc *var)
Definition: lparser.c:452
test_then_block
static void test_then_block(LexState *ls, int *escapelist)
Definition: lparser.c:1626
lopcodes.h
lfunc.h
Proto::upvalues
Upvaldesc * upvalues
Definition: lobject.h:556
NO_JUMP
#define NO_JUMP
Definition: lcode.h:20
luaX_lookahead
int luaX_lookahead(LexState *ls)
Definition: llex.c:576
Proto::maxstacksize
lu_byte maxstacksize
Definition: lobject.h:543
ldo.h
luaK_exp2nextreg
void luaK_exp2nextreg(FuncState *fs, expdesc *e)
Definition: lcode.c:924
TValue
Definition: lobject.h:65
cast_int
#define cast_int(i)
Definition: llimits.h:128
TK_LE
@ TK_LE
Definition: llex.h:39
Labeldesc::name
TString * name
Definition: lparser.h:111
udp_client.args
args
Definition: udp_client.py:12
LocVar
Definition: lobject.h:514
newgotoentry
static int newgotoentry(LexState *ls, TString *name, int line, int pc)
Definition: lparser.c:563
Dyndata::actvar
struct Dyndata::@11 actvar
exprstat
static void exprstat(LexState *ls)
Definition: lparser.c:1784


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:45