Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lparser.c File Reference
#include "lprefix.h"
#include <limits.h>
#include <string.h>
#include "lua.h"
#include "lcode.h"
#include "ldebug.h"
#include "ldo.h"
#include "lfunc.h"
#include "llex.h"
#include "lmem.h"
#include "lobject.h"
#include "lopcodes.h"
#include "lparser.h"
#include "lstate.h"
#include "lstring.h"
#include "ltable.h"

Go to the source code of this file.

Data Structures

struct  BlockCnt
 
struct  ConsControl
 
struct  LHS_assign
 

Macros

#define lparser_c
 
#define LUA_CORE
 
#define MAXVARS   200
 
#define hasmultret(k)   ((k) == VCALL || (k) == VVARARG)
 
#define eqstr(a, b)   ((a) == (b))
 
#define check_condition(ls, c, msg)   { if (!(c)) luaX_syntaxerror(ls, msg); }
 
#define new_localvarliteral(ls, v)
 
#define enterlevel(ls)   luaE_incCstack(ls->L)
 
#define leavelevel(ls)   ((ls)->L->nCcalls--)
 
#define UNARY_PRIORITY   12 /* priority for unary operators */
 

Typedefs

typedef struct BlockCnt BlockCnt
 
typedef struct ConsControl ConsControl
 

Functions

static void statement (LexState *ls)
 
static void expr (LexState *ls, expdesc *v)
 
static l_noret error_expected (LexState *ls, int token)
 
static l_noret errorlimit (FuncState *fs, int limit, const char *what)
 
static void checklimit (FuncState *fs, int v, int l, const char *what)
 
static int testnext (LexState *ls, int c)
 
static void check (LexState *ls, int c)
 
static void checknext (LexState *ls, int c)
 
static void check_match (LexState *ls, int what, int who, int where)
 
static TStringstr_checkname (LexState *ls)
 
static void init_exp (expdesc *e, expkind k, int i)
 
static void codestring (expdesc *e, TString *s)
 
static void codename (LexState *ls, expdesc *e)
 
static int registerlocalvar (LexState *ls, FuncState *fs, TString *varname)
 
static int new_localvar (LexState *ls, TString *name)
 
static Vardescgetlocalvardesc (FuncState *fs, int vidx)
 
static int reglevel (FuncState *fs, int nvar)
 
int luaY_nvarstack (FuncState *fs)
 
static LocVarlocaldebuginfo (FuncState *fs, int vidx)
 
static void init_var (FuncState *fs, expdesc *e, int vidx)
 
static void check_readonly (LexState *ls, expdesc *e)
 
static void adjustlocalvars (LexState *ls, int nvars)
 
static void removevars (FuncState *fs, int tolevel)
 
static int searchupvalue (FuncState *fs, TString *name)
 
static Upvaldescallocupvalue (FuncState *fs)
 
static int newupvalue (FuncState *fs, TString *name, expdesc *v)
 
static int searchvar (FuncState *fs, TString *n, expdesc *var)
 
static void markupval (FuncState *fs, int level)
 
static void singlevaraux (FuncState *fs, TString *n, expdesc *var, int base)
 
static void singlevar (LexState *ls, expdesc *var)
 
static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e)
 
static l_noret jumpscopeerror (LexState *ls, Labeldesc *gt)
 
static void solvegoto (LexState *ls, int g, Labeldesc *label)
 
static Labeldescfindlabel (LexState *ls, TString *name)
 
static int newlabelentry (LexState *ls, Labellist *l, TString *name, int line, int pc)
 
static int newgotoentry (LexState *ls, TString *name, int line, int pc)
 
static int solvegotos (LexState *ls, Labeldesc *lb)
 
static int createlabel (LexState *ls, TString *name, int line, int last)
 
static void movegotosout (FuncState *fs, BlockCnt *bl)
 
static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isloop)
 
static l_noret undefgoto (LexState *ls, Labeldesc *gt)
 
static void leaveblock (FuncState *fs)
 
static Protoaddprototype (LexState *ls)
 
static void codeclosure (LexState *ls, expdesc *v)
 
static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl)
 
static void close_func (LexState *ls)
 
static int block_follow (LexState *ls, int withuntil)
 
static void statlist (LexState *ls)
 
static void fieldsel (LexState *ls, expdesc *v)
 
static void yindex (LexState *ls, expdesc *v)
 
static void recfield (LexState *ls, ConsControl *cc)
 
static void closelistfield (FuncState *fs, ConsControl *cc)
 
static void lastlistfield (FuncState *fs, ConsControl *cc)
 
static void listfield (LexState *ls, ConsControl *cc)
 
static void field (LexState *ls, ConsControl *cc)
 
static void constructor (LexState *ls, expdesc *t)
 
static void setvararg (FuncState *fs, int nparams)
 
static void parlist (LexState *ls)
 
static void body (LexState *ls, expdesc *e, int ismethod, int line)
 
static int explist (LexState *ls, expdesc *v)
 
static void funcargs (LexState *ls, expdesc *f, int line)
 
static void primaryexp (LexState *ls, expdesc *v)
 
static void suffixedexp (LexState *ls, expdesc *v)
 
static void simpleexp (LexState *ls, expdesc *v)
 
static UnOpr getunopr (int op)
 
static BinOpr getbinopr (int op)
 
static BinOpr subexpr (LexState *ls, expdesc *v, int limit)
 
static void block (LexState *ls)
 
static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v)
 
static void restassign (LexState *ls, struct LHS_assign *lh, int nvars)
 
static int cond (LexState *ls)
 
static void gotostat (LexState *ls)
 
static void breakstat (LexState *ls)
 
static void checkrepeated (LexState *ls, TString *name)
 
static void labelstat (LexState *ls, TString *name, int line)
 
static void whilestat (LexState *ls, int line)
 
static void repeatstat (LexState *ls, int line)
 
static void exp1 (LexState *ls)
 
static void fixforjump (FuncState *fs, int pc, int dest, int back)
 
static void forbody (LexState *ls, int base, int line, int nvars, int isgen)
 
static void fornum (LexState *ls, TString *varname, int line)
 
static void forlist (LexState *ls, TString *indexname)
 
static void forstat (LexState *ls, int line)
 
static void test_then_block (LexState *ls, int *escapelist)
 
static void ifstat (LexState *ls, int line)
 
static void localfunc (LexState *ls)
 
static int getlocalattribute (LexState *ls)
 
static void checktoclose (LexState *ls, int level)
 
static void localstat (LexState *ls)
 
static int funcname (LexState *ls, expdesc *v)
 
static void funcstat (LexState *ls, int line)
 
static void exprstat (LexState *ls)
 
static void retstat (LexState *ls)
 
static void mainfunc (LexState *ls, FuncState *fs)
 
LClosureluaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, Dyndata *dyd, const char *name, int firstchar)
 

Variables

struct { 
 
   lu_byte   left 
 
   lu_byte   right 
 
priority [] 
 

Macro Definition Documentation

◆ check_condition

#define check_condition ( ls,
c,
msg )   { if (!(c)) luaX_syntaxerror(ls, msg); }

Definition at line 122 of file lua-5.4.3/src/lparser.c.

Referenced by exprstat(), restassign(), and simpleexp().

◆ enterlevel

#define enterlevel ( ls)    luaE_incCstack(ls->L)

◆ eqstr

#define eqstr ( a,
b )   ((a) == (b))

◆ hasmultret

#define hasmultret ( k)    ((k) == VCALL || (k) == VVARARG)

Definition at line 38 of file lua-5.4.3/src/lparser.c.

Referenced by adjust_assign(), funcargs(), lastlistfield(), and retstat().

◆ leavelevel

#define leavelevel ( ls)    ((ls)->L->nCcalls--)

Definition at line 495 of file lua-5.4.3/src/lparser.c.

Referenced by restassign(), statement(), and subexpr().

◆ lparser_c

#define lparser_c

Definition at line 7 of file lua-5.4.3/src/lparser.c.

◆ LUA_CORE

#define LUA_CORE

Definition at line 8 of file lua-5.4.3/src/lparser.c.

◆ MAXVARS

#define MAXVARS   200

Definition at line 35 of file lua-5.4.3/src/lparser.c.

Referenced by new_localvar().

◆ new_localvarliteral

#define new_localvarliteral ( ls,
v )
Value:
luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char)) - 1));
TString * luaX_newstring(LexState *ls, const char *str, size_t l)
static int new_localvar(LexState *ls, TString *name)

Definition at line 208 of file lua-5.4.3/src/lparser.c.

208#define new_localvarliteral(ls,v) \
209 new_localvar(ls, \
210 luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char)) - 1));

Referenced by body(), forlist(), and fornum().

◆ UNARY_PRIORITY

#define UNARY_PRIORITY   12 /* priority for unary operators */

Definition at line 1241 of file lua-5.4.3/src/lparser.c.

Referenced by subexpr().

Typedef Documentation

◆ BlockCnt

typedef struct BlockCnt BlockCnt

◆ ConsControl

typedef struct ConsControl ConsControl

Function Documentation

◆ addprototype()

static Proto * addprototype ( LexState * ls)
static

Definition at line 686 of file lua-5.4.3/src/lparser.c.

686 {
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}
#define NULL
Definition gmacros.h:924
Proto * luaF_newproto(lua_State *L)
#define luaC_objbarrier(L, p, o)
#define luaM_growvector(L, v, nelems, size, t, limit, e)
#define MAXARG_Bx
struct lua_State * L
struct FuncState * fs
struct Proto ** p

References FuncState::f, LexState::fs, LexState::L, luaC_objbarrier, luaF_newproto(), luaM_growvector, MAXARG_Bx, FuncState::np, NULL, Proto::p, and Proto::sizep.

Referenced by body().

◆ adjust_assign()

static void adjust_assign ( LexState * ls,
int nvars,
int nexps,
expdesc * e )
static

Definition at line 470 of file lua-5.4.3/src/lparser.c.

470 {
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}
void luaK_exp2nextreg(FuncState *fs, expdesc *e)
void luaK_nil(FuncState *fs, int from, int n)
void luaK_setreturns(FuncState *fs, expdesc *e, int nresults)
void luaK_reserveregs(FuncState *fs, int n)
#define hasmultret(k)

References FuncState::freereg, LexState::fs, hasmultret, expdesc::k, luaK_exp2nextreg(), luaK_nil(), luaK_reserveregs(), luaK_setreturns(), and VVOID.

Referenced by forlist(), localstat(), and restassign().

◆ adjustlocalvars()

static void adjustlocalvars ( LexState * ls,
int nvars )
static

Definition at line 311 of file lua-5.4.3/src/lparser.c.

311 {
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}
int luaY_nvarstack(FuncState *fs)
static Vardesc * getlocalvardesc(FuncState *fs, int vidx)
static int reglevel(FuncState *fs, int nvar)
static int registerlocalvar(LexState *ls, FuncState *fs, TString *varname)
struct Vardesc::@92 vd

References LexState::fs, getlocalvardesc(), luaY_nvarstack(), FuncState::nactvar, Vardesc::name, Vardesc::pidx, registerlocalvar(), reglevel(), Vardesc::ridx, and Vardesc::vd.

Referenced by body(), forbody(), forlist(), fornum(), localfunc(), localstat(), and parlist().

◆ allocupvalue()

static Upvaldesc * allocupvalue ( FuncState * fs)
static

Definition at line 352 of file lua-5.4.3/src/lparser.c.

352 {
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}
#define MAXUPVAL
static void checklimit(FuncState *fs, int v, int l, const char *what)
struct LexState * ls
TString ** upvalues

References checklimit(), FuncState::f, LexState::L, FuncState::ls, luaM_growvector, MAXUPVAL, NULL, FuncState::nups, Proto::sizeupvalues, and Proto::upvalues.

Referenced by mainfunc(), and newupvalue().

◆ block()

static void block ( LexState * ls)
static

Definition at line 1293 of file lua-5.4.3/src/lparser.c.

1293 {
1294 /* block -> statlist */
1295 FuncState *fs = ls->fs;
1296 BlockCnt bl;
1297 enterblock(fs, &bl, 0);
1298 statlist(ls);
1299 leaveblock(fs);
1300}
static void leaveblock(FuncState *fs)
static void enterblock(FuncState *fs, BlockCnt *bl, lu_byte isloop)
static void statlist(LexState *ls)

References enterblock(), LexState::fs, leaveblock(), and statlist().

Referenced by forbody(), ifstat(), statement(), and whilestat().

◆ block_follow()

static int block_follow ( LexState * ls,
int withuntil )
static

Definition at line 776 of file lua-5.4.3/src/lparser.c.

776 {
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}
@ TK_UNTIL
@ TK_ELSEIF
#define TK_END
Definition sqlite3.c:13953
#define TK_ELSE
Definition sqlite3.c:14099

References LexState::t, TK_ELSE, TK_ELSEIF, TK_END, TK_EOS, TK_UNTIL, and Token::token.

Referenced by labelstat(), retstat(), statlist(), and test_then_block().

◆ body()

static void body ( LexState * ls,
expdesc * e,
int ismethod,
int line )
static

Definition at line 978 of file lua-5.4.3/src/lparser.c.

978 {
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}
static void checknext(LexState *ls, int c)
#define new_localvarliteral(ls, v)
static void codeclosure(LexState *ls, expdesc *v)
static void close_func(LexState *ls)
static void adjustlocalvars(LexState *ls, int nvars)
static Proto * addprototype(LexState *ls)
static void check_match(LexState *ls, int what, int who, int where)
static void open_func(LexState *ls, FuncState *fs, BlockCnt *bl)
static void parlist(LexState *ls)
#define TK_FUNCTION
Definition sqlite3.c:14111

References addprototype(), adjustlocalvars(), check_match(), checknext(), close_func(), codeclosure(), FuncState::f, Proto::lastlinedefined, Proto::linedefined, LexState::linenumber, new_localvarliteral, open_func(), parlist(), statlist(), TK_END, and TK_FUNCTION.

Referenced by funcstat(), localfunc(), and simpleexp().

◆ breakstat()

static void breakstat ( LexState * ls)
static

Definition at line 1426 of file lua-5.4.3/src/lparser.c.

1426 {
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}
int luaK_jump(FuncState *fs)
void luaX_next(LexState *ls)
#define luaS_newliteral(L, s)
static int newgotoentry(LexState *ls, TString *name, int line, int pc)

References LexState::fs, LexState::L, LexState::linenumber, luaK_jump(), luaS_newliteral, luaX_next(), and newgotoentry().

Referenced by statement().

◆ check()

static void check ( LexState * ls,
int c )
static

Definition at line 107 of file lua-5.4.3/src/lparser.c.

107 {
108 if (ls->t.token != c)
109 error_expected(ls, c);
110}
static l_noret error_expected(LexState *ls, int token)

References error_expected(), LexState::t, and Token::token.

◆ check_conflict()

static void check_conflict ( LexState * ls,
struct LHS_assign * lh,
expdesc * v )
static

Definition at line 1319 of file lua-5.4.3/src/lparser.c.

1319 {
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}
#define luaK_codeABC(fs, o, a, b, c)
#define vkisindexed(k)
struct LHS_assign * prev
struct expdesc::@89::@91 var
union expdesc::@52 u
struct expdesc::@61::@62 ind

References FuncState::freereg, LexState::fs, expdesc::idx, expdesc::ind, expdesc::info, expdesc::k, luaK_codeABC, luaK_reserveregs(), OP_GETUPVAL, OP_MOVE, LHS_assign::prev, expdesc::ridx, expdesc::t, expdesc::u, LHS_assign::v, expdesc::var, VINDEXED, VINDEXSTR, VINDEXUP, vkisindexed, VLOCAL, and VUPVAL.

Referenced by restassign().

◆ check_match()

static void check_match ( LexState * ls,
int what,
int who,
int where )
static

Definition at line 130 of file lua-5.4.3/src/lparser.c.

130 {
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}
void luaX_syntaxerror(LexState *ls, const char *msg)
const char * luaX_token2str(LexState *ls, int token)
const char * luaO_pushfstring(lua_State *L, const char *fmt,...)
static int testnext(LexState *ls, int c)

References error_expected(), LexState::L, LexState::linenumber, luaO_pushfstring(), luaX_syntaxerror(), luaX_token2str(), and testnext().

Referenced by body(), constructor(), forstat(), funcargs(), ifstat(), primaryexp(), repeatstat(), statement(), and whilestat().

◆ check_readonly()

static void check_readonly ( LexState * ls,
expdesc * e )
static

Definition at line 277 of file lua-5.4.3/src/lparser.c.

277 {
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}
#define getstr(ts)
l_noret luaK_semerror(LexState *ls, const char *msg)
#define VDKREG
struct Dyndata::@63 actvar
struct Dyndata * dyd
unsigned short vidx

References Dyndata::actvar, Dyndata::arr, LexState::dyd, FuncState::f, LexState::fs, getlocalvardesc(), getstr, expdesc::info, expdesc::k, Upvaldesc::kind, Vardesc::kind, LexState::L, luaK_semerror(), luaO_pushfstring(), Upvaldesc::name, Vardesc::name, NULL, expdesc::u, Proto::upvalues, expdesc::var, VCONST, Vardesc::vd, VDKREG, expdesc::vidx, VLOCAL, and VUPVAL.

Referenced by restassign().

◆ checklimit()

static void checklimit ( FuncState * fs,
int v,
int l,
const char * what )
static

Definition at line 87 of file lua-5.4.3/src/lparser.c.

87 {
88 if (v > l) errorlimit(fs, l, what);
89}
static l_noret errorlimit(FuncState *fs, int limit, const char *what)

References errorlimit().

Referenced by allocupvalue(), new_localvar(), and recfield().

◆ checknext()

static void checknext ( LexState * ls,
int c )
static

Definition at line 116 of file lua-5.4.3/src/lparser.c.

116 {
117 check(ls, c);
118 luaX_next(ls);
119}
#define check(x)

References check, and luaX_next().

Referenced by body(), constructor(), forbody(), forlist(), fornum(), getlocalattribute(), labelstat(), recfield(), restassign(), test_then_block(), whilestat(), and yindex().

◆ checkrepeated()

static void checkrepeated ( LexState * ls,
TString * name )
static

Definition at line 1436 of file lua-5.4.3/src/lparser.c.

1436 {
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}
const char * name
Definition lsqlite3.c:2154
static Labeldesc * findlabel(LexState *ls, TString *name)

References findlabel(), getstr, LexState::L, Labeldesc::line, luaK_semerror(), luaO_pushfstring(), name, and NULL.

Referenced by labelstat().

◆ checktoclose()

static void checktoclose ( LexState * ls,
int level )
static

Definition at line 1706 of file lua-5.4.3/src/lparser.c.

1706 {
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}
static void markupval(FuncState *fs, int level)
struct BlockCnt * bl

References FuncState::bl, LexState::fs, BlockCnt::insidetbc, luaK_codeABC, markupval(), OP_TBC, and reglevel().

Referenced by localstat().

◆ close_func()

static void close_func ( LexState * ls)
static

Definition at line 744 of file lua-5.4.3/src/lparser.c.

744 {
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);
756 luaM_shrinkvector(L, f->k, f->sizek, fs->nk, TValue);
757 luaM_shrinkvector(L, f->p, f->sizep, fs->np, Proto *);
760 ls->fs = fs->prev;
761 luaC_checkGC(L);
762}
void luaK_ret(FuncState *fs, int first, int nret)
#define luaC_checkGC(L)
lu_int32 Instruction
#define lua_assert(c)
void luaK_finish(FuncState *fs)
signed char ls_byte
#define luaM_shrinkvector(L, v, size, fs, t)
struct FuncState * prev
AbsLineInfo * abslineinfo
Instruction * code
struct LocVar * locvars

References Proto::abslineinfo, FuncState::bl, Proto::code, FuncState::f, LexState::fs, Proto::k, LexState::L, leaveblock(), Proto::lineinfo, Proto::locvars, lua_assert, luaC_checkGC, luaK_finish(), luaK_ret(), luaM_shrinkvector, luaY_nvarstack(), FuncState::nabslineinfo, FuncState::ndebugvars, FuncState::nk, FuncState::np, NULL, FuncState::nups, Proto::p, FuncState::pc, FuncState::prev, Proto::sizeabslineinfo, Proto::sizecode, Proto::sizek, Proto::sizelineinfo, Proto::sizelocvars, Proto::sizep, Proto::sizeupvalues, and Proto::upvalues.

Referenced by body(), and mainfunc().

◆ closelistfield()

static void closelistfield ( FuncState * fs,
ConsControl * cc )
static

Definition at line 856 of file lua-5.4.3/src/lparser.c.

856 {
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}
void luaK_setlist(FuncState *fs, int base, int nelems, int tostore)
#define LFIELDS_PER_FLUSH

References expdesc::info, expdesc::k, LFIELDS_PER_FLUSH, luaK_exp2nextreg(), luaK_setlist(), ConsControl::na, ConsControl::t, ConsControl::tostore, expdesc::u, ConsControl::v, and VVOID.

Referenced by constructor().

◆ codeclosure()

static void codeclosure ( LexState * ls,
expdesc * v )
static

Definition at line 710 of file lua-5.4.3/src/lparser.c.

710 {
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}
int luaK_codeABx(FuncState *fs, OpCode o, int a, unsigned int bc)
static void init_exp(expdesc *e, expkind k, int i)

References LexState::fs, init_exp(), luaK_codeABx(), luaK_exp2nextreg(), FuncState::np, OP_CLOSURE, FuncState::prev, and VRELOC.

Referenced by body().

◆ codename()

static void codename ( LexState * ls,
expdesc * e )
static

Definition at line 166 of file lua-5.4.3/src/lparser.c.

166 {
168}
static void codestring(expdesc *e, TString *s)
static TString * str_checkname(LexState *ls)

References codestring(), and str_checkname().

Referenced by fieldsel(), recfield(), and suffixedexp().

◆ codestring()

static void codestring ( expdesc * e,
TString * s )
static

Definition at line 159 of file lua-5.4.3/src/lparser.c.

159 {
160 e->f = e->t = NO_JUMP;
161 e->k = VKSTR;
162 e->u.strval = s;
163}
#define NO_JUMP
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318

References expdesc::f, expdesc::k, NO_JUMP, s, expdesc::strval, expdesc::t, expdesc::u, and VKSTR.

Referenced by codename(), funcargs(), simpleexp(), and singlevar().

◆ cond()

static int cond ( LexState * ls)
static

Definition at line 1394 of file lua-5.4.3/src/lparser.c.

1394 {
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}
void luaK_goiftrue(FuncState *fs, expdesc *e)
static void expr(LexState *ls, expdesc *v)

References expr(), expdesc::f, LexState::fs, expdesc::k, luaK_goiftrue(), LHS_assign::v, VFALSE, and VNIL.

Referenced by repeatstat(), and whilestat().

◆ constructor()

static void constructor ( LexState * ls,
expdesc * t )
static

Definition at line 913 of file lua-5.4.3/src/lparser.c.

913 {
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}
static int luaK_code(FuncState *fs, Instruction i, int line)
void luaK_settablesize(FuncState *fs, int pc, int ra, int asize, int hsize)
static void field(LexState *ls, ConsControl *cc)
static void lastlistfield(FuncState *fs, ConsControl *cc)
static void closelistfield(FuncState *fs, ConsControl *cc)

References check_match(), checknext(), closelistfield(), field(), FuncState::freereg, LexState::fs, expdesc::info, init_exp(), expdesc::k, lastlistfield(), LexState::linenumber, lua_assert, luaK_code(), luaK_codeABC, luaK_reserveregs(), luaK_settablesize(), ConsControl::na, ConsControl::nh, OP_NEWTABLE, LexState::t, ConsControl::t, testnext(), Token::token, ConsControl::tostore, expdesc::u, ConsControl::v, VNONRELOC, and VVOID.

Referenced by funcargs(), and simpleexp().

◆ createlabel()

static int createlabel ( LexState * ls,
TString * name,
int line,
int last )
static

Definition at line 596 of file lua-5.4.3/src/lparser.c.

597 {
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}
int luaK_getlabel(FuncState *fs)
static int solvegotos(LexState *ls, Labeldesc *lb)
static int newlabelentry(LexState *ls, Labellist *l, TString *name, int line, int pc)

References Labellist::arr, FuncState::bl, LexState::dyd, LexState::fs, Dyndata::label, luaK_codeABC, luaK_getlabel(), luaY_nvarstack(), BlockCnt::nactvar, Labeldesc::nactvar, name, newlabelentry(), OP_CLOSE, and solvegotos().

Referenced by labelstat(), and leaveblock().

◆ enterblock()

static void enterblock ( FuncState * fs,
BlockCnt * bl,
lu_byte isloop )
static

◆ error_expected()

static l_noret error_expected ( LexState * ls,
int token )
static

Definition at line 68 of file lua-5.4.3/src/lparser.c.

68 {
70 luaO_pushfstring(ls->L, "%s expected", luaX_token2str(ls, token)));
71}

References LexState::L, luaO_pushfstring(), luaX_syntaxerror(), and luaX_token2str().

Referenced by check(), and check_match().

◆ errorlimit()

static l_noret errorlimit ( FuncState * fs,
int limit,
const char * what )
static

Definition at line 74 of file lua-5.4.3/src/lparser.c.

74 {
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}

References FuncState::f, LexState::L, Proto::linedefined, FuncState::ls, luaO_pushfstring(), and luaX_syntaxerror().

Referenced by checklimit().

◆ exp1()

static void exp1 ( LexState * ls)
static

Definition at line 1505 of file lua-5.4.3/src/lparser.c.

1505 {
1506 expdesc e;
1507 expr(ls, &e);
1508 luaK_exp2nextreg(ls->fs, &e);
1509 lua_assert(e.k == VNONRELOC);
1510}

References expr(), LexState::fs, expdesc::k, lua_assert, luaK_exp2nextreg(), and VNONRELOC.

Referenced by fornum().

◆ explist()

static int explist ( LexState * ls,
expdesc * v )
static

Definition at line 1000 of file lua-5.4.3/src/lparser.c.

1000 {
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}

References expr(), LexState::fs, luaK_exp2nextreg(), and testnext().

Referenced by forlist(), funcargs(), localstat(), restassign(), and retstat().

◆ expr()

static void expr ( LexState * ls,
expdesc * v )
static

Definition at line 1278 of file lua-5.4.3/src/lparser.c.

1278 {
1279 subexpr(ls, v, 0);
1280}
static BinOpr subexpr(LexState *ls, expdesc *v, int limit)

References subexpr().

Referenced by cond(), exp1(), explist(), listfield(), primaryexp(), recfield(), test_then_block(), and yindex().

◆ exprstat()

static void exprstat ( LexState * ls)
static

Definition at line 1784 of file lua-5.4.3/src/lparser.c.

1784 {
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}
#define SETARG_C(i, b)
#define getinstruction(fs, e)
static void restassign(LexState *ls, struct LHS_assign *lh, int nvars)
static void suffixedexp(LexState *ls, expdesc *v)
#define check_condition(ls, c, msg)

References check_condition, LexState::fs, getinstruction, expdesc::k, NULL, restassign(), SETARG_C, suffixedexp(), LexState::t, Token::token, LHS_assign::v, and VCALL.

Referenced by statement().

◆ field()

static void field ( LexState * ls,
ConsControl * cc )
static

Definition at line 891 of file lua-5.4.3/src/lparser.c.

891 {
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}
void luaX_lookahead(LexState *ls)
@ TK_NAME
static void listfield(LexState *ls, ConsControl *cc)
static void recfield(LexState *ls, ConsControl *cc)

References listfield(), luaX_lookahead(), recfield(), LexState::t, TK_NAME, and Token::token.

Referenced by constructor().

◆ fieldsel()

static void fieldsel ( LexState * ls,
expdesc * v )
static

Definition at line 799 of file lua-5.4.3/src/lparser.c.

799 {
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}
void luaK_indexed(FuncState *fs, expdesc *t, expdesc *k)
void luaK_exp2anyregup(FuncState *fs, expdesc *e)
static void codename(LexState *ls, expdesc *e)

References codename(), LexState::fs, luaK_exp2anyregup(), luaK_indexed(), and luaX_next().

Referenced by funcname(), and suffixedexp().

◆ findlabel()

static Labeldesc * findlabel ( LexState * ls,
TString * name )
static

Definition at line 532 of file lua-5.4.3/src/lparser.c.

532 {
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}
#define eqstr(a, b)

References Labellist::arr, LexState::dyd, eqstr, FuncState::firstlabel, LexState::fs, Dyndata::label, Labellist::n, name, Labeldesc::name, and NULL.

Referenced by checkrepeated(), and gotostat().

◆ fixforjump()

static void fixforjump ( FuncState * fs,
int pc,
int dest,
int back )
static

Definition at line 1518 of file lua-5.4.3/src/lparser.c.

1518 {
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}
#define SETARG_Bx(i, b)

References Proto::code, FuncState::f, FuncState::ls, luaX_syntaxerror(), MAXARG_Bx, and SETARG_Bx.

Referenced by forbody().

◆ forbody()

static void forbody ( LexState * ls,
int base,
int line,
int nvars,
int isgen )
static

Definition at line 1532 of file lua-5.4.3/src/lparser.c.

1532 {
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}
void luaK_fixline(FuncState *fs, int line)
static void block(LexState *ls)
static void fixforjump(FuncState *fs, int pc, int dest, int back)
static int forprep(lua_State *L, StkId ra)
#define TK_DO
Definition sqlite3.c:14003

References adjustlocalvars(), block(), checknext(), enterblock(), fixforjump(), forprep(), LexState::fs, leaveblock(), luaK_codeABC, luaK_codeABx(), luaK_fixline(), luaK_getlabel(), luaK_reserveregs(), OP_FORLOOP, OP_FORPREP, OP_TFORCALL, OP_TFORLOOP, OP_TFORPREP, and TK_DO.

Referenced by forlist(), and fornum().

◆ forlist()

static void forlist ( LexState * ls,
TString * indexname )
static

Definition at line 1580 of file lua-5.4.3/src/lparser.c.

1580 {
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}
void luaK_checkstack(FuncState *fs, int n)
static void forbody(LexState *ls, int base, int line, int nvars, int isgen)
static int explist(LexState *ls, expdesc *v)
static void adjust_assign(LexState *ls, int nvars, int nexps, expdesc *e)
#define TK_IN
Definition sqlite3.c:13991

References adjust_assign(), adjustlocalvars(), checknext(), explist(), forbody(), FuncState::freereg, LexState::fs, LexState::linenumber, luaK_checkstack(), markupval(), FuncState::nactvar, new_localvar(), new_localvarliteral, str_checkname(), testnext(), and TK_IN.

Referenced by forstat().

◆ fornum()

static void fornum ( LexState * ls,
TString * varname,
int line )
static

Definition at line 1557 of file lua-5.4.3/src/lparser.c.

1557 {
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}
void luaK_int(FuncState *fs, int reg, lua_Integer i)
static void exp1(LexState *ls)

References adjustlocalvars(), checknext(), exp1(), forbody(), FuncState::freereg, LexState::fs, luaK_int(), luaK_reserveregs(), new_localvar(), new_localvarliteral, and testnext().

Referenced by forstat().

◆ forstat()

static void forstat ( LexState * ls,
int line )
static

Definition at line 1608 of file lua-5.4.3/src/lparser.c.

1608 {
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}
static void fornum(LexState *ls, TString *varname, int line)
static void forlist(LexState *ls, TString *indexname)
#define TK_FOR
Definition sqlite3.c:14004

References check_match(), enterblock(), forlist(), fornum(), LexState::fs, leaveblock(), luaX_next(), luaX_syntaxerror(), str_checkname(), LexState::t, TK_END, TK_FOR, TK_IN, and Token::token.

Referenced by statement().

◆ funcargs()

static void funcargs ( LexState * ls,
expdesc * f,
int line )
static

Definition at line 1013 of file lua-5.4.3/src/lparser.c.

1013 {
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}
#define luaK_setmultret(fs, e)
#define LUA_MULTRET
static void constructor(LexState *ls, expdesc *t)
#define TK_STRING
Definition sqlite3.c:14057
SemInfo seminfo
TString * ts

References check_match(), codestring(), constructor(), explist(), FuncState::freereg, LexState::fs, hasmultret, expdesc::info, init_exp(), expdesc::k, lua_assert, LUA_MULTRET, luaK_codeABC, luaK_exp2nextreg(), luaK_fixline(), luaK_setmultret, luaX_next(), luaX_syntaxerror(), OP_CALL, Token::seminfo, LexState::t, TK_STRING, Token::token, SemInfo::ts, expdesc::u, VCALL, VNONRELOC, and VVOID.

Referenced by suffixedexp().

◆ funcname()

static int funcname ( LexState * ls,
expdesc * v )
static

Definition at line 1758 of file lua-5.4.3/src/lparser.c.

1758 {
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}
static void singlevar(LexState *ls, expdesc *var)
static void fieldsel(LexState *ls, expdesc *v)

References fieldsel(), singlevar(), LexState::t, Token::token, and LHS_assign::v.

Referenced by funcstat().

◆ funcstat()

static void funcstat ( LexState * ls,
int line )
static

Definition at line 1772 of file lua-5.4.3/src/lparser.c.

1772 {
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}
void luaK_storevar(FuncState *fs, expdesc *var, expdesc *ex)
static int funcname(LexState *ls, expdesc *v)
static void body(LexState *ls, expdesc *e, int ismethod, int line)

References body(), LexState::fs, funcname(), luaK_fixline(), luaK_storevar(), luaX_next(), and LHS_assign::v.

Referenced by statement().

◆ getbinopr()

static BinOpr getbinopr ( int op)
static

Definition at line 1194 of file lua-5.4.3/src/lparser.c.

1194 {
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}
@ OPR_NOBINOPR
@ OPR_CONCAT
@ TK_IDIV
#define TK_EQ
Definition sqlite3.c:13995
#define TK_GE
Definition sqlite3.c:13999
#define TK_LE
Definition sqlite3.c:13997
#define TK_CONCAT
Definition sqlite3.c:14052
#define TK_NE
Definition sqlite3.c:13994
#define TK_AND
Definition sqlite3.c:13986
#define TK_OR
Definition sqlite3.c:13985

References OPR_ADD, OPR_AND, OPR_BAND, OPR_BOR, OPR_BXOR, OPR_CONCAT, OPR_DIV, OPR_EQ, OPR_GE, OPR_GT, OPR_IDIV, OPR_LE, OPR_LT, OPR_MOD, OPR_MUL, OPR_NE, OPR_NOBINOPR, OPR_OR, OPR_POW, OPR_SHL, OPR_SHR, OPR_SUB, TK_AND, TK_CONCAT, TK_EQ, TK_GE, TK_IDIV, TK_LE, TK_NE, TK_OR, TK_SHL, and TK_SHR.

Referenced by subexpr().

◆ getlocalattribute()

static int getlocalattribute ( LexState * ls)
static

Definition at line 1689 of file lua-5.4.3/src/lparser.c.

1689 {
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}
#define RDKCONST
#define RDKTOCLOSE

References checknext(), getstr, LexState::L, luaK_semerror(), luaO_pushfstring(), RDKCONST, RDKTOCLOSE, str_checkname(), testnext(), and VDKREG.

Referenced by localstat().

◆ getlocalvardesc()

static Vardesc * getlocalvardesc ( FuncState * fs,
int vidx )
static

◆ getunopr()

static UnOpr getunopr ( int op)
static

Definition at line 1183 of file lua-5.4.3/src/lparser.c.

1183 {
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}
@ OPR_MINUS
@ OPR_NOUNOPR
#define TK_NOT
Definition sqlite3.c:13961

References OPR_BNOT, OPR_LEN, OPR_MINUS, OPR_NOT, OPR_NOUNOPR, and TK_NOT.

Referenced by subexpr().

◆ gotostat()

static void gotostat ( LexState * ls)
static

Definition at line 1404 of file lua-5.4.3/src/lparser.c.

1404 {
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}
void luaK_patchlist(FuncState *fs, int list, int target)

References findlabel(), LexState::fs, LexState::linenumber, luaK_codeABC, luaK_jump(), luaK_patchlist(), luaY_nvarstack(), Labeldesc::nactvar, name, newgotoentry(), NULL, OP_CLOSE, Labeldesc::pc, reglevel(), and str_checkname().

Referenced by statement().

◆ ifstat()

static void ifstat ( LexState * ls,
int line )
static

Definition at line 1663 of file lua-5.4.3/src/lparser.c.

1663 {
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}
void luaK_patchtohere(FuncState *fs, int list)
static void test_then_block(LexState *ls, int *escapelist)
#define TK_IF
Definition sqlite3.c:13960

References block(), check_match(), LexState::fs, luaK_patchtohere(), NO_JUMP, LexState::t, test_then_block(), testnext(), TK_ELSE, TK_ELSEIF, TK_END, TK_IF, and Token::token.

Referenced by statement().

◆ init_exp()

static void init_exp ( expdesc * e,
expkind k,
int i )
static

Definition at line 152 of file lua-5.4.3/src/lparser.c.

152 {
153 e->f = e->t = NO_JUMP;
154 e->k = k;
155 e->u.info = i;
156}

References expdesc::f, expdesc::info, expdesc::k, NO_JUMP, expdesc::t, and expdesc::u.

Referenced by codeclosure(), constructor(), funcargs(), restassign(), searchvar(), simpleexp(), and singlevaraux().

◆ init_var()

static void init_var ( FuncState * fs,
expdesc * e,
int vidx )
static

Definition at line 266 of file lua-5.4.3/src/lparser.c.

266 {
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}

References expdesc::f, getlocalvardesc(), expdesc::k, NO_JUMP, expdesc::ridx, Vardesc::ridx, expdesc::t, expdesc::u, expdesc::var, Vardesc::vd, expdesc::vidx, and VLOCAL.

Referenced by searchvar().

◆ jumpscopeerror()

static l_noret jumpscopeerror ( LexState * ls,
Labeldesc * gt )
static

Definition at line 502 of file lua-5.4.3/src/lparser.c.

502 {
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}
#define gt(L)

References LexState::fs, getlocalvardesc(), getstr, gt, LexState::L, luaK_semerror(), luaO_pushfstring(), FuncState::nactvar, Vardesc::name, and Vardesc::vd.

Referenced by solvegoto().

◆ labelstat()

static void labelstat ( LexState * ls,
TString * name,
int line )
static

Definition at line 1446 of file lua-5.4.3/src/lparser.c.

1446 {
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}
@ TK_DBCOLON
static int block_follow(LexState *ls, int withuntil)
static void checkrepeated(LexState *ls, TString *name)
static int createlabel(LexState *ls, TString *name, int line, int last)
static void statement(LexState *ls)

References block_follow(), checknext(), checkrepeated(), createlabel(), name, statement(), LexState::t, TK_DBCOLON, and Token::token.

Referenced by statement().

◆ lastlistfield()

static void lastlistfield ( FuncState * fs,
ConsControl * cc )
static

Definition at line 868 of file lua-5.4.3/src/lparser.c.

868 {
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}

References hasmultret, expdesc::info, expdesc::k, LUA_MULTRET, luaK_exp2nextreg(), luaK_setlist(), luaK_setmultret, ConsControl::na, ConsControl::t, ConsControl::tostore, expdesc::u, ConsControl::v, and VVOID.

Referenced by constructor().

◆ leaveblock()

static void leaveblock ( FuncState * fs)
static

Definition at line 660 of file lua-5.4.3/src/lparser.c.

660 {
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}
static l_noret undefgoto(LexState *ls, Labeldesc *gt)
static void removevars(FuncState *fs, int tolevel)
static void movegotosout(FuncState *fs, BlockCnt *bl)

References Labellist::arr, FuncState::bl, createlabel(), LexState::dyd, BlockCnt::firstgoto, BlockCnt::firstlabel, FuncState::freereg, Dyndata::gt, BlockCnt::isloop, LexState::L, Dyndata::label, FuncState::ls, lua_assert, luaK_codeABC, luaS_newliteral, movegotosout(), Labellist::n, BlockCnt::nactvar, FuncState::nactvar, OP_CLOSE, BlockCnt::previous, reglevel(), removevars(), undefgoto(), and BlockCnt::upval.

Referenced by block(), close_func(), forbody(), forstat(), repeatstat(), test_then_block(), and whilestat().

◆ listfield()

static void listfield ( LexState * ls,
ConsControl * cc )
static

Definition at line 884 of file lua-5.4.3/src/lparser.c.

884 {
885 /* listfield -> exp */
886 expr(ls, &cc->v);
887 cc->tostore++;
888}

References expr(), ConsControl::tostore, and ConsControl::v.

Referenced by field().

◆ localdebuginfo()

static LocVar * localdebuginfo ( FuncState * fs,
int vidx )
static

Definition at line 251 of file lua-5.4.3/src/lparser.c.

251 {
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}
#define RDKCTC

References FuncState::f, getlocalvardesc(), Vardesc::kind, Proto::locvars, lua_assert, NULL, Vardesc::pidx, RDKCTC, and Vardesc::vd.

Referenced by localfunc(), and removevars().

◆ localfunc()

static void localfunc ( LexState * ls)
static

Definition at line 1677 of file lua-5.4.3/src/lparser.c.

1677 {
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}
static LocVar * localdebuginfo(FuncState *fs, int vidx)

References adjustlocalvars(), body(), LexState::fs, LexState::linenumber, localdebuginfo(), FuncState::nactvar, new_localvar(), FuncState::pc, LocVar::startpc, and str_checkname().

Referenced by statement().

◆ localstat()

static void localstat ( LexState * ls)
static

Definition at line 1716 of file lua-5.4.3/src/lparser.c.

1716 {
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}
int luaK_exp2const(FuncState *fs, const expdesc *e, TValue *v)
static void checktoclose(LexState *ls, int level)
static int getlocalattribute(LexState *ls)

References adjust_assign(), adjustlocalvars(), checktoclose(), explist(), LexState::fs, getlocalattribute(), getlocalvardesc(), expdesc::k, Vardesc::k, Vardesc::kind, luaK_exp2const(), luaK_semerror(), FuncState::nactvar, new_localvar(), RDKCONST, RDKCTC, RDKTOCLOSE, str_checkname(), testnext(), Vardesc::vd, and VVOID.

Referenced by statement().

◆ luaY_nvarstack()

int luaY_nvarstack ( FuncState * fs)

Definition at line 243 of file lua-5.4.3/src/lparser.c.

243 {
244 return reglevel(fs, fs->nactvar);
245}

References FuncState::nactvar, and reglevel().

Referenced by adjustlocalvars(), close_func(), createlabel(), enterblock(), freereg(), gotostat(), luaK_exp2anyreg(), retstat(), and statement().

◆ luaY_parser()

LClosure * luaY_parser ( lua_State * L,
ZIO * z,
Mbuffer * buff,
Dyndata * dyd,
const char * name,
int firstchar )

Definition at line 1931 of file lua-5.4.3/src/lparser.c.

1932 {
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}
Closure * luaF_newLclosure(lua_State *L, int nelems, Table *e)
void luaX_setinput(lua_State *L, LexState *ls, ZIO *z, TString *source)
#define sethvalue2s
#define luaS_new(L, s)
Table * luaH_new(lua_State *L, int narray, int nhash)
void luaD_inctop(lua_State *L)
#define setclLvalue2s(L, o, cl)
static void mainfunc(LexState *ls, FuncState *fs)
struct Proto * p
Mbuffer * buff
TString * source

References Dyndata::actvar, LexState::buff, LexState::dyd, FuncState::f, LexState::fs, Dyndata::gt, LexState::h, Dyndata::label, lua_assert, luaC_objbarrier, luaD_inctop(), luaF_newLclosure(), luaF_newproto(), luaH_new(), luaS_new, luaX_setinput(), mainfunc(), Labellist::n, Dyndata::n, name, FuncState::nups, LClosure::p, FuncState::prev, setclLvalue2s, sethvalue2s, Proto::source, and lua_State::top.

◆ mainfunc()

static void mainfunc ( LexState * ls,
FuncState * fs )
static

Definition at line 1913 of file lua-5.4.3/src/lparser.c.

1913 {
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}
static Upvaldesc * allocupvalue(FuncState *fs)
static void setvararg(FuncState *fs, int nparams)
TString * envn

References allocupvalue(), check, close_func(), LexState::envn, FuncState::f, Upvaldesc::idx, Upvaldesc::instack, Upvaldesc::kind, LexState::L, luaC_objbarrier, luaX_next(), Upvaldesc::name, open_func(), setvararg(), statlist(), TK_EOS, and VDKREG.

Referenced by luaY_parser().

◆ markupval()

static void markupval ( FuncState * fs,
int level )
static

Definition at line 410 of file lua-5.4.3/src/lparser.c.

410 {
411 BlockCnt *bl = fs->bl;
412 while (bl->nactvar > level)
413 bl = bl->previous;
414 bl->upval = 1;
415 fs->needclose = 1;
416}

References FuncState::bl, BlockCnt::nactvar, FuncState::needclose, BlockCnt::previous, and BlockCnt::upval.

Referenced by checktoclose(), forlist(), and singlevaraux().

◆ movegotosout()

static void movegotosout ( FuncState * fs,
BlockCnt * bl )
static

Definition at line 616 of file lua-5.4.3/src/lparser.c.

616 {
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}

References Labellist::arr, Labeldesc::close, LexState::dyd, BlockCnt::firstgoto, gt, Dyndata::gt, FuncState::ls, Labellist::n, BlockCnt::nactvar, FuncState::nactvar, reglevel(), and BlockCnt::upval.

Referenced by leaveblock().

◆ new_localvar()

static int new_localvar ( LexState * ls,
TString * name )
static

Definition at line 193 of file lua-5.4.3/src/lparser.c.

193 {
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}
#define MAXVARS

References Dyndata::actvar, Dyndata::arr, checklimit(), LexState::dyd, FuncState::firstlocal, LexState::fs, Vardesc::kind, LexState::L, luaM_growvector, MAXVARS, Dyndata::n, name, Vardesc::name, Dyndata::size, Vardesc::vd, and VDKREG.

Referenced by forlist(), fornum(), localfunc(), localstat(), and parlist().

◆ newgotoentry()

static int newgotoentry ( LexState * ls,
TString * name,
int line,
int pc )
static

Definition at line 563 of file lua-5.4.3/src/lparser.c.

563 {
564 return newlabelentry(ls, &ls->dyd->gt, name, line, pc);
565}

References LexState::dyd, Dyndata::gt, name, and newlabelentry().

Referenced by breakstat(), gotostat(), and test_then_block().

◆ newlabelentry()

static int newlabelentry ( LexState * ls,
Labellist * l,
TString * name,
int line,
int pc )
static

Definition at line 548 of file lua-5.4.3/src/lparser.c.

549 {
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}

References Labellist::arr, Labeldesc::close, LexState::fs, LexState::L, Labeldesc::line, luaM_growvector, Labellist::n, FuncState::nactvar, Labeldesc::nactvar, name, Labeldesc::name, Labeldesc::pc, and Labellist::size.

Referenced by createlabel(), and newgotoentry().

◆ newupvalue()

static int newupvalue ( FuncState * fs,
TString * name,
expdesc * v )
static

Definition at line 364 of file lua-5.4.3/src/lparser.c.

364 {
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;
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}
#define cast_byte(i)

References allocupvalue(), cast_byte, eqstr, FuncState::f, getlocalvardesc(), Upvaldesc::idx, expdesc::info, Upvaldesc::instack, expdesc::k, Upvaldesc::kind, Vardesc::kind, LexState::L, FuncState::ls, lua_assert, luaC_objbarrier, name, Upvaldesc::name, Vardesc::name, FuncState::nups, FuncState::prev, expdesc::ridx, expdesc::u, Proto::upvalues, expdesc::var, Vardesc::vd, expdesc::vidx, and VLOCAL.

Referenced by singlevaraux().

◆ open_func()

static void open_func ( LexState * ls,
FuncState * fs,
BlockCnt * bl )
static

Definition at line 717 of file lua-5.4.3/src/lparser.c.

717 {
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}
TString * source
lu_byte maxstacksize

References Dyndata::actvar, FuncState::bl, LexState::dyd, enterblock(), FuncState::f, FuncState::firstlabel, FuncState::firstlocal, FuncState::freereg, LexState::fs, FuncState::iwthabs, LexState::L, Dyndata::label, FuncState::lasttarget, Proto::linedefined, FuncState::ls, luaC_objbarrier, Proto::maxstacksize, Labellist::n, Dyndata::n, FuncState::nabslineinfo, FuncState::nactvar, FuncState::ndebugvars, FuncState::needclose, FuncState::nk, FuncState::np, NULL, FuncState::nups, FuncState::pc, FuncState::prev, FuncState::previousline, LexState::source, and Proto::source.

Referenced by body(), and mainfunc().

◆ parlist()

static void parlist ( LexState * ls)
static

Definition at line 947 of file lua-5.4.3/src/lparser.c.

947 {
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: {
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}
@ TK_DOTS

References adjustlocalvars(), cast_byte, FuncState::f, LexState::fs, luaK_reserveregs(), luaX_next(), luaX_syntaxerror(), FuncState::nactvar, new_localvar(), Proto::numparams, setvararg(), str_checkname(), LexState::t, testnext(), TK_DOTS, TK_NAME, and Token::token.

Referenced by body().

◆ primaryexp()

static void primaryexp ( LexState * ls,
expdesc * v )
static

Definition at line 1068 of file lua-5.4.3/src/lparser.c.

1068 {
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}
void luaK_dischargevars(FuncState *fs, expdesc *e)

References check_match(), expr(), LexState::fs, LexState::linenumber, luaK_dischargevars(), luaX_next(), luaX_syntaxerror(), singlevar(), LexState::t, TK_NAME, and Token::token.

Referenced by suffixedexp().

◆ recfield()

static void recfield ( LexState * ls,
ConsControl * cc )
static

Definition at line 835 of file lua-5.4.3/src/lparser.c.

835 {
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}
#define MAX_INT
static void yindex(LexState *ls, expdesc *v)

References checklimit(), checknext(), codename(), expr(), FuncState::freereg, LexState::fs, luaK_indexed(), luaK_storevar(), MAX_INT, ConsControl::nh, LexState::t, ConsControl::t, TK_NAME, Token::token, and yindex().

Referenced by field().

◆ registerlocalvar()

static int registerlocalvar ( LexState * ls,
FuncState * fs,
TString * varname )
static

Definition at line 175 of file lua-5.4.3/src/lparser.c.

175 {
176 Proto *f = fs->f;
177 int oldsize = 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}
TString * varname

References FuncState::f, LexState::L, Proto::locvars, luaC_objbarrier, luaM_growvector, FuncState::ndebugvars, NULL, FuncState::pc, Proto::sizelocvars, LocVar::startpc, and LocVar::varname.

Referenced by adjustlocalvars().

◆ reglevel()

static int reglevel ( FuncState * fs,
int nvar )
static

Definition at line 229 of file lua-5.4.3/src/lparser.c.

229 {
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}

References getlocalvardesc(), Vardesc::kind, RDKCTC, Vardesc::ridx, and Vardesc::vd.

Referenced by adjustlocalvars(), checktoclose(), gotostat(), leaveblock(), luaY_nvarstack(), movegotosout(), and repeatstat().

◆ removevars()

static void removevars ( FuncState * fs,
int tolevel )
static

Definition at line 328 of file lua-5.4.3/src/lparser.c.

328 {
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}

References Dyndata::actvar, LexState::dyd, LocVar::endpc, localdebuginfo(), FuncState::ls, Dyndata::n, FuncState::nactvar, and FuncState::pc.

Referenced by leaveblock().

◆ repeatstat()

static void repeatstat ( LexState * ls,
int line )
static

Definition at line 1475 of file lua-5.4.3/src/lparser.c.

1475 {
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}
@ TK_REPEAT
static int cond(LexState *ls)

References check_match(), cond(), enterblock(), LexState::fs, leaveblock(), luaK_codeABC, luaK_getlabel(), luaK_jump(), luaK_patchlist(), luaK_patchtohere(), luaX_next(), BlockCnt::nactvar, OP_CLOSE, reglevel(), statlist(), TK_REPEAT, TK_UNTIL, and BlockCnt::upval.

Referenced by statement().

◆ restassign()

static void restassign ( LexState * ls,
struct LHS_assign * lh,
int nvars )
static

Definition at line 1363 of file lua-5.4.3/src/lparser.c.

1363 {
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}
void luaK_setoneret(FuncState *fs, expdesc *e)
#define vkisvar(k)
#define leavelevel(ls)
static void check_readonly(LexState *ls, expdesc *e)
static void check_conflict(LexState *ls, struct LHS_assign *lh, expdesc *v)
#define enterlevel(ls)

References adjust_assign(), check_condition, check_conflict(), check_readonly(), checknext(), enterlevel, explist(), FuncState::freereg, LexState::fs, init_exp(), expdesc::k, leavelevel, luaK_setoneret(), luaK_storevar(), LHS_assign::prev, restassign(), suffixedexp(), testnext(), LHS_assign::v, vkisindexed, vkisvar, and VNONRELOC.

Referenced by exprstat(), and restassign().

◆ retstat()

static void retstat ( LexState * ls)
static

Definition at line 1802 of file lua-5.4.3/src/lparser.c.

1802 {
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}
int luaK_exp2anyreg(FuncState *fs, expdesc *e)
#define GETARG_A(i)
#define SET_OPCODE(i, o)

References FuncState::bl, block_follow(), explist(), FuncState::freereg, LexState::fs, GETARG_A, getinstruction, hasmultret, BlockCnt::insidetbc, expdesc::k, lua_assert, LUA_MULTRET, luaK_exp2anyreg(), luaK_exp2nextreg(), luaK_ret(), luaK_setmultret, luaY_nvarstack(), OP_TAILCALL, SET_OPCODE, LexState::t, testnext(), Token::token, and VCALL.

Referenced by statement().

◆ searchupvalue()

static int searchupvalue ( FuncState * fs,
TString * name )
static

Definition at line 342 of file lua-5.4.3/src/lparser.c.

342 {
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}

References eqstr, FuncState::f, name, FuncState::nups, and Proto::upvalues.

Referenced by singlevaraux().

◆ searchvar()

static int searchvar ( FuncState * fs,
TString * n,
expdesc * var )
static

Definition at line 390 of file lua-5.4.3/src/lparser.c.

390 {
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}
#define cast_int(i)
static void init_var(FuncState *fs, expdesc *e, int vidx)

References cast_int, eqstr, FuncState::firstlocal, getlocalvardesc(), init_exp(), init_var(), expdesc::k, Vardesc::kind, FuncState::nactvar, Vardesc::name, RDKCTC, VCONST, and Vardesc::vd.

Referenced by singlevaraux().

◆ setvararg()

static void setvararg ( FuncState * fs,
int nparams )
static

Definition at line 941 of file lua-5.4.3/src/lparser.c.

941 {
942 fs->f->is_vararg = 1;
943 luaK_codeABC(fs, OP_VARARGPREP, nparams, 0, 0);
944}

References FuncState::f, Proto::is_vararg, luaK_codeABC, and OP_VARARGPREP.

Referenced by mainfunc(), and parlist().

◆ simpleexp()

static void simpleexp ( LexState * ls,
expdesc * v )
static

Definition at line 1128 of file lua-5.4.3/src/lparser.c.

1128 {
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}
@ TK_FALSE
@ TK_TRUE
lua_Integer ival
lua_Number nval
lua_Number r
lua_Integer i

References body(), check_condition, codestring(), constructor(), FuncState::f, LexState::fs, SemInfo::i, init_exp(), Proto::is_vararg, expdesc::ival, LexState::linenumber, luaK_codeABC, luaX_next(), expdesc::nval, OP_VARARG, SemInfo::r, Token::seminfo, suffixedexp(), LexState::t, TK_DOTS, TK_FALSE, TK_FLT, TK_FUNCTION, TK_INT, TK_NIL, TK_STRING, TK_TRUE, Token::token, SemInfo::ts, expdesc::u, VFALSE, VKFLT, VKINT, VNIL, VTRUE, and VVARARG.

Referenced by subexpr().

◆ singlevar()

static void singlevar ( LexState * ls,
expdesc * var )
static

Definition at line 452 of file lua-5.4.3/src/lparser.c.

452 {
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}
static void singlevaraux(FuncState *fs, TString *n, expdesc *var, int base)

References codestring(), LexState::envn, LexState::fs, expdesc::k, lua_assert, luaK_indexed(), singlevaraux(), str_checkname(), and VVOID.

Referenced by funcname(), and primaryexp().

◆ singlevaraux()

static void singlevaraux ( FuncState * fs,
TString * n,
expdesc * var,
int base )
static

Definition at line 424 of file lua-5.4.3/src/lparser.c.

424 {
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}
static int searchupvalue(FuncState *fs, TString *name)
static int newupvalue(FuncState *fs, TString *name, expdesc *v)
static int searchvar(FuncState *fs, TString *n, expdesc *var)

References init_exp(), expdesc::k, markupval(), newupvalue(), NULL, FuncState::prev, searchupvalue(), searchvar(), singlevaraux(), expdesc::u, expdesc::var, expdesc::vidx, VLOCAL, VUPVAL, and VVOID.

Referenced by singlevar(), and singlevaraux().

◆ solvegoto()

static void solvegoto ( LexState * ls,
int g,
Labeldesc * label )
static

Definition at line 515 of file lua-5.4.3/src/lparser.c.

515 {
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}
static l_noret jumpscopeerror(LexState *ls, Labeldesc *gt)

References Labellist::arr, LexState::dyd, eqstr, LexState::fs, gt, Dyndata::gt, jumpscopeerror(), lua_assert, luaK_patchlist(), Labellist::n, Labeldesc::nactvar, Labeldesc::name, FuncState::pc, and Labeldesc::pc.

Referenced by solvegotos().

◆ solvegotos()

static int solvegotos ( LexState * ls,
Labeldesc * lb )
static

Definition at line 573 of file lua-5.4.3/src/lparser.c.

573 {
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}
static void solvegoto(LexState *ls, int g, Labeldesc *label)

References Labellist::arr, FuncState::bl, Labeldesc::close, LexState::dyd, eqstr, BlockCnt::firstgoto, LexState::fs, Dyndata::gt, Labeldesc::name, and solvegoto().

Referenced by createlabel().

◆ statement()

static void statement ( LexState * ls)
static

Definition at line 1834 of file lua-5.4.3/src/lparser.c.

1834 {
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}
@ TK_BREAK
@ TK_WHILE
@ TK_LOCAL
@ TK_RETURN
@ TK_GOTO
static void labelstat(LexState *ls, TString *name, int line)
static void exprstat(LexState *ls)
static void gotostat(LexState *ls)
static void retstat(LexState *ls)
static void funcstat(LexState *ls, int line)
static void repeatstat(LexState *ls, int line)
static void localfunc(LexState *ls)
static void breakstat(LexState *ls)
static void ifstat(LexState *ls, int line)
static void localstat(LexState *ls)
static void whilestat(LexState *ls, int line)
static void forstat(LexState *ls, int line)

References block(), breakstat(), check_match(), enterlevel, exprstat(), FuncState::f, forstat(), FuncState::freereg, LexState::fs, funcstat(), gotostat(), ifstat(), labelstat(), leavelevel, LexState::linenumber, localfunc(), localstat(), lua_assert, luaX_next(), luaY_nvarstack(), Proto::maxstacksize, repeatstat(), retstat(), str_checkname(), LexState::t, testnext(), TK_BREAK, TK_DBCOLON, TK_DO, TK_END, TK_FOR, TK_FUNCTION, TK_GOTO, TK_IF, TK_LOCAL, TK_REPEAT, TK_RETURN, TK_WHILE, Token::token, and whilestat().

Referenced by labelstat(), and statlist().

◆ statlist()

static void statlist ( LexState * ls)
static

Definition at line 787 of file lua-5.4.3/src/lparser.c.

787 {
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}

References block_follow(), statement(), LexState::t, TK_RETURN, and Token::token.

Referenced by block(), body(), mainfunc(), repeatstat(), and test_then_block().

◆ str_checkname()

static TString * str_checkname ( LexState * ls)
static

Definition at line 143 of file lua-5.4.3/src/lparser.c.

143 {
144 TString *ts;
145 check(ls, TK_NAME);
146 ts = ls->t.seminfo.ts;
147 luaX_next(ls);
148 return ts;
149}

References check, luaX_next(), Token::seminfo, LexState::t, TK_NAME, and SemInfo::ts.

Referenced by codename(), forlist(), forstat(), getlocalattribute(), gotostat(), localfunc(), localstat(), parlist(), singlevar(), and statement().

◆ subexpr()

static BinOpr subexpr ( LexState * ls,
expdesc * v,
int limit )
static

Definition at line 1248 of file lua-5.4.3/src/lparser.c.

1248 {
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}
void luaK_prefix(FuncState *fs, UnOpr op, expdesc *e)
void luaK_infix(FuncState *fs, BinOpr op, expdesc *v)
void luaK_posfix(FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2)
static const struct @88 priority[]
lu_byte right
lu_byte left
static void simpleexp(LexState *ls, expdesc *v)
#define UNARY_PRIORITY
static BinOpr getbinopr(int op)
static UnOpr getunopr(int op)

References enterlevel, LexState::fs, getbinopr(), getunopr(), leavelevel, left, LexState::linenumber, luaK_infix(), luaK_posfix(), luaK_prefix(), luaX_next(), OPR_NOBINOPR, OPR_NOUNOPR, priority, right, simpleexp(), subexpr(), LexState::t, Token::token, and UNARY_PRIORITY.

Referenced by expr(), and subexpr().

◆ suffixedexp()

static void suffixedexp ( LexState * ls,
expdesc * v )
static

Definition at line 1090 of file lua-5.4.3/src/lparser.c.

1090 {
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}
void luaK_self(FuncState *fs, expdesc *e, expdesc *key)
static void funcargs(LexState *ls, expdesc *f, int line)
static void primaryexp(LexState *ls, expdesc *v)

References codename(), fieldsel(), LexState::fs, funcargs(), LexState::linenumber, luaK_exp2anyregup(), luaK_exp2nextreg(), luaK_indexed(), luaK_self(), luaX_next(), primaryexp(), LexState::t, TK_STRING, Token::token, and yindex().

Referenced by exprstat(), restassign(), and simpleexp().

◆ test_then_block()

static void test_then_block ( LexState * ls,
int * escapelist )
static

Definition at line 1626 of file lua-5.4.3/src/lparser.c.

1626 {
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}
static void luaK_goiffalse(FuncState *fs, expdesc *e)
void luaK_concat(FuncState *fs, int *l1, int l2)
#define TK_THEN
Definition sqlite3.c:14098

References block_follow(), checknext(), enterblock(), expr(), expdesc::f, LexState::fs, LexState::L, leaveblock(), LexState::linenumber, luaK_concat(), luaK_goiffalse(), luaK_goiftrue(), luaK_jump(), luaK_patchtohere(), luaS_newliteral, luaX_next(), newgotoentry(), statlist(), LexState::t, expdesc::t, testnext(), TK_BREAK, TK_ELSE, TK_ELSEIF, TK_THEN, Token::token, and LHS_assign::v.

Referenced by ifstat().

◆ testnext()

static int testnext ( LexState * ls,
int c )
static

Definition at line 95 of file lua-5.4.3/src/lparser.c.

95 {
96 if (ls->t.token == c) {
97 luaX_next(ls);
98 return 1;
99 }
100 else return 0;
101}

References luaX_next(), LexState::t, and Token::token.

Referenced by check_match(), constructor(), explist(), forlist(), fornum(), getlocalattribute(), ifstat(), localstat(), parlist(), restassign(), retstat(), statement(), and test_then_block().

◆ undefgoto()

static l_noret undefgoto ( LexState * ls,
Labeldesc * gt )
static

Definition at line 646 of file lua-5.4.3/src/lparser.c.

646 {
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}

References eqstr, getstr, gt, LexState::L, luaK_semerror(), luaO_pushfstring(), and luaS_newliteral.

Referenced by leaveblock().

◆ whilestat()

static void whilestat ( LexState * ls,
int line )
static

Definition at line 1456 of file lua-5.4.3/src/lparser.c.

1456 {
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}
#define luaK_jumpto(fs, t)

References block(), check_match(), checknext(), cond(), enterblock(), LexState::fs, leaveblock(), luaK_getlabel(), luaK_jumpto, luaK_patchtohere(), luaX_next(), TK_DO, TK_END, and TK_WHILE.

Referenced by statement().

◆ yindex()

static void yindex ( LexState * ls,
expdesc * v )
static

Definition at line 810 of file lua-5.4.3/src/lparser.c.

810 {
811 /* index -> '[' expr ']' */
812 luaX_next(ls); /* skip the '[' */
813 expr(ls, v);
814 luaK_exp2val(ls->fs, v);
815 checknext(ls, ']');
816}
void luaK_exp2val(FuncState *fs, expdesc *e)

References checknext(), expr(), LexState::fs, luaK_exp2val(), and luaX_next().

Referenced by recfield(), and suffixedexp().

Variable Documentation

◆ left

lu_byte left

Definition at line 1226 of file lua-5.4.3/src/lparser.c.

Referenced by subexpr().

◆ [struct]

const struct { ... } priority[]
Initial value:
= {
{10, 10}, {10, 10},
{11, 11}, {11, 11},
{14, 13},
{11, 11}, {11, 11},
{6, 6}, {4, 4}, {5, 5},
{7, 7}, {7, 7},
{9, 8},
{3, 3}, {3, 3}, {3, 3},
{3, 3}, {3, 3}, {3, 3},
{2, 2}, {1, 1}
}

Referenced by subexpr().

◆ right

lu_byte right

Definition at line 1227 of file lua-5.4.3/src/lparser.c.

Referenced by subexpr().