Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lparser.c File Reference
#include "lprefix.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)    new_localvarliteral_(ls, "" v, (sizeof(v)/sizeof(char))-1)
 
#define leavelevel(ls)   ((ls)->L->nCcalls--)
 
#define UNARY_PRIORITY   12 /* priority for unary operators */
 

Typedefs

typedef struct BlockCnt BlockCnt
 

Functions

static void statement (LexState *ls)
 
static void expr (LexState *ls, expdesc *v)
 
static l_noret semerror (LexState *ls, const char *msg)
 
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 (LexState *ls, expdesc *e, TString *s)
 
static void checkname (LexState *ls, expdesc *e)
 
static int registerlocalvar (LexState *ls, TString *varname)
 
static void new_localvar (LexState *ls, TString *name)
 
static void new_localvarliteral_ (LexState *ls, const char *name, size_t sz)
 
static LocVargetlocvar (FuncState *fs, int i)
 
static void adjustlocalvars (LexState *ls, int nvars)
 
static void removevars (FuncState *fs, int tolevel)
 
static int searchupvalue (FuncState *fs, TString *name)
 
static int newupvalue (FuncState *fs, TString *name, expdesc *v)
 
static int searchvar (FuncState *fs, TString *n)
 
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 void enterlevel (LexState *ls)
 
static void closegoto (LexState *ls, int g, Labeldesc *label)
 
static int findlabel (LexState *ls, int g)
 
static int newlabelentry (LexState *ls, Labellist *l, TString *name, int line, int pc)
 
static void findgotos (LexState *ls, Labeldesc *lb)
 
static void movegotosout (FuncState *fs, BlockCnt *bl)
 
static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isloop)
 
static void breaklabel (LexState *ls)
 
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, struct ConsControl *cc)
 
static void closelistfield (FuncState *fs, struct ConsControl *cc)
 
static void lastlistfield (FuncState *fs, struct ConsControl *cc)
 
static void listfield (LexState *ls, struct ConsControl *cc)
 
static void field (LexState *ls, struct ConsControl *cc)
 
static void constructor (LexState *ls, expdesc *t)
 
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 assignment (LexState *ls, struct LHS_assign *lh, int nvars)
 
static int cond (LexState *ls)
 
static void gotostat (LexState *ls, int pc)
 
static void checkrepeated (FuncState *fs, Labellist *ll, TString *label)
 
static void skipnoopstat (LexState *ls)
 
static void labelstat (LexState *ls, TString *label, int line)
 
static void whilestat (LexState *ls, int line)
 
static void repeatstat (LexState *ls, int line)
 
static int exp1 (LexState *ls)
 
static void forbody (LexState *ls, int base, int line, int nvars, int isnum)
 
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 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 118 of file lua-5.3.6/src/lparser.c.

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

◆ eqstr

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

◆ hasmultret

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

Definition at line 37 of file lua-5.3.6/src/lparser.c.

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

◆ leavelevel

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

Definition at line 338 of file lua-5.3.6/src/lparser.c.

Referenced by statement(), and subexpr().

◆ lparser_c

#define lparser_c

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

◆ LUA_CORE

#define LUA_CORE

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

◆ MAXVARS

#define MAXVARS   200

Definition at line 34 of file lua-5.3.6/src/lparser.c.

Referenced by new_localvar().

◆ new_localvarliteral

#define new_localvarliteral ( ls,
v )    new_localvarliteral_(ls, "" v, (sizeof(v)/sizeof(char))-1)

Definition at line 191 of file lua-5.3.6/src/lparser.c.

191#define new_localvarliteral(ls,v) \
192 new_localvarliteral_(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 1042 of file lua-5.3.6/src/lparser.c.

Referenced by subexpr().

Typedef Documentation

◆ BlockCnt

typedef struct BlockCnt BlockCnt

Function Documentation

◆ addprototype()

static Proto * addprototype ( LexState * ls)
static

Definition at line 499 of file lua-5.3.6/src/lparser.c.

499 {
500 Proto *clp;
501 lua_State *L = ls->L;
502 FuncState *fs = ls->fs;
503 Proto *f = fs->f; /* prototype of current function */
504 if (fs->np >= f->sizep) {
505 int oldsize = f->sizep;
506 luaM_growvector(L, f->p, fs->np, f->sizep, Proto *, MAXARG_Bx, "functions");
507 while (oldsize < f->sizep)
508 f->p[oldsize++] = NULL;
509 }
510 f->p[fs->np++] = clp = luaF_newproto(L);
511 luaC_objbarrier(L, f, clp);
512 return clp;
513}
#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 309 of file lua-5.3.6/src/lparser.c.

309 {
310 FuncState *fs = ls->fs;
311 int extra = nvars - nexps;
312 if (hasmultret(e->k)) {
313 extra++; /* includes call itself */
314 if (extra < 0) extra = 0;
315 luaK_setreturns(fs, e, extra); /* last exp. provides the difference */
316 if (extra > 1) luaK_reserveregs(fs, extra-1);
317 }
318 else {
319 if (e->k != VVOID) luaK_exp2nextreg(fs, e); /* close last expression */
320 if (extra > 0) {
321 int reg = fs->freereg;
322 luaK_reserveregs(fs, extra);
323 luaK_nil(fs, reg, extra);
324 }
325 }
326 if (nexps > nvars)
327 ls->fs->freereg -= nexps - nvars; /* remove extra values */
328}
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 assignment(), forlist(), and localstat().

◆ adjustlocalvars()

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

Definition at line 202 of file lua-5.3.6/src/lparser.c.

202 {
203 FuncState *fs = ls->fs;
204 fs->nactvar = cast_byte(fs->nactvar + nvars);
205 for (; nvars; nvars--) {
206 getlocvar(fs, fs->nactvar - nvars)->startpc = fs->pc;
207 }
208}
#define cast_byte(i)
#define getlocvar(fs, i)

References cast_byte, LexState::fs, getlocvar, FuncState::nactvar, and FuncState::pc.

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

◆ assignment()

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

Definition at line 1148 of file lua-5.3.6/src/lparser.c.

1148 {
1149 expdesc e;
1150 check_condition(ls, vkisvar(lh->v.k), "syntax error");
1151 if (testnext(ls, ',')) { /* assignment -> ',' suffixedexp assignment */
1152 struct LHS_assign nv;
1153 nv.prev = lh;
1154 suffixedexp(ls, &nv.v);
1155 if (nv.v.k != VINDEXED)
1156 check_conflict(ls, lh, &nv.v);
1157 checklimit(ls->fs, nvars + ls->L->nCcalls, LUAI_MAXCCALLS,
1158 "C levels");
1159 assignment(ls, &nv, nvars+1);
1160 }
1161 else { /* assignment -> '=' explist */
1162 int nexps;
1163 checknext(ls, '=');
1164 nexps = explist(ls, &e);
1165 if (nexps != nvars)
1166 adjust_assign(ls, nvars, nexps, &e);
1167 else {
1168 luaK_setoneret(ls->fs, &e); /* close last expression */
1169 luaK_storevar(ls->fs, &lh->v, &e);
1170 return; /* avoid default */
1171 }
1172 }
1173 init_exp(&e, VNONRELOC, ls->fs->freereg-1); /* default assignment */
1174 luaK_storevar(ls->fs, &lh->v, &e);
1175}
void luaK_storevar(FuncState *fs, expdesc *var, expdesc *ex)
void luaK_setoneret(FuncState *fs, expdesc *e)
#define LUAI_MAXCCALLS
#define vkisvar(k)
static void checknext(LexState *ls, int c)
static int explist(LexState *ls, expdesc *v)
static void assignment(LexState *ls, struct LHS_assign *lh, int nvars)
static int testnext(LexState *ls, int c)
static void check_conflict(LexState *ls, struct LHS_assign *lh, expdesc *v)
static void adjust_assign(LexState *ls, int nvars, int nexps, expdesc *e)
static void init_exp(expdesc *e, expkind k, int i)
static void checklimit(FuncState *fs, int v, int l, const char *what)
static void suffixedexp(LexState *ls, expdesc *v)
#define check_condition(ls, c, msg)
struct LHS_assign * prev
unsigned short nCcalls

References adjust_assign(), assignment(), check_condition, check_conflict(), checklimit(), checknext(), explist(), FuncState::freereg, LexState::fs, init_exp(), expdesc::k, LexState::L, LUAI_MAXCCALLS, luaK_setoneret(), luaK_storevar(), lua_State::nCcalls, LHS_assign::prev, suffixedexp(), testnext(), LHS_assign::v, VINDEXED, vkisvar, and VNONRELOC.

Referenced by assignment(), and exprstat().

◆ block()

static void block ( LexState * ls)
static

Definition at line 1094 of file lua-5.3.6/src/lparser.c.

1094 {
1095 /* block -> statlist */
1096 FuncState *fs = ls->fs;
1097 BlockCnt bl;
1098 enterblock(fs, &bl, 0);
1099 statlist(ls);
1100 leaveblock(fs);
1101}
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 588 of file lua-5.3.6/src/lparser.c.

588 {
589 switch (ls->t.token) {
590 case TK_ELSE: case TK_ELSEIF:
591 case TK_END: case TK_EOS:
592 return 1;
593 case TK_UNTIL: return withuntil;
594 default: return 0;
595 }
596}
@ 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 783 of file lua-5.3.6/src/lparser.c.

783 {
784 /* body -> '(' parlist ')' block END */
785 FuncState new_fs;
786 BlockCnt bl;
787 new_fs.f = addprototype(ls);
788 new_fs.f->linedefined = line;
789 open_func(ls, &new_fs, &bl);
790 checknext(ls, '(');
791 if (ismethod) {
792 new_localvarliteral(ls, "self"); /* create 'self' parameter */
793 adjustlocalvars(ls, 1);
794 }
795 parlist(ls);
796 checknext(ls, ')');
797 statlist(ls);
798 new_fs.f->lastlinedefined = ls->linenumber;
799 check_match(ls, TK_END, TK_FUNCTION, line);
800 codeclosure(ls, e);
801 close_func(ls);
802}
#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().

◆ breaklabel()

static void breaklabel ( LexState * ls)
static

Definition at line 454 of file lua-5.3.6/src/lparser.c.

454 {
455 TString *n = luaS_new(ls->L, "break");
456 int l = newlabelentry(ls, &ls->dyd->label, n, 0, ls->fs->pc);
457 findgotos(ls, &ls->dyd->label.arr[l]);
458}
#define luaS_new(L, s)
static void findgotos(LexState *ls, Labeldesc *lb)
static int newlabelentry(LexState *ls, Labellist *l, TString *name, int line, int pc)
struct Dyndata * dyd

References Labellist::arr, LexState::dyd, findgotos(), LexState::fs, LexState::L, Dyndata::label, luaS_new, newlabelentry(), and FuncState::pc.

Referenced by leaveblock().

◆ check()

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

Definition at line 106 of file lua-5.3.6/src/lparser.c.

106 {
107 if (ls->t.token != c)
108 error_expected(ls, c);
109}
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 1120 of file lua-5.3.6/src/lparser.c.

1120 {
1121 FuncState *fs = ls->fs;
1122 int extra = fs->freereg; /* eventual position to save local variable */
1123 int conflict = 0;
1124 for (; lh; lh = lh->prev) { /* check all previous assignments */
1125 if (lh->v.k == VINDEXED) { /* assigning to a table? */
1126 /* table is the upvalue/local being assigned now? */
1127 if (lh->v.u.ind.vt == v->k && lh->v.u.ind.t == v->u.info) {
1128 conflict = 1;
1129 lh->v.u.ind.vt = VLOCAL;
1130 lh->v.u.ind.t = extra; /* previous assignment will use safe copy */
1131 }
1132 /* index is the local being assigned? (index cannot be upvalue) */
1133 if (v->k == VLOCAL && lh->v.u.ind.idx == v->u.info) {
1134 conflict = 1;
1135 lh->v.u.ind.idx = extra; /* previous assignment will use safe copy */
1136 }
1137 }
1138 }
1139 if (conflict) {
1140 /* copy upvalue/local value to a temporary (in position 'extra') */
1141 OpCode op = (v->k == VLOCAL) ? OP_MOVE : OP_GETUPVAL;
1142 luaK_codeABC(fs, op, extra, v->u.info, 0);
1143 luaK_reserveregs(fs, 1);
1144 }
1145}
#define luaK_codeABC(fs, o, a, b, c)
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::t, expdesc::u, LHS_assign::v, VINDEXED, VLOCAL, and expdesc::vt.

Referenced by assignment().

◆ check_match()

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

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

122 {
123 if (!testnext(ls, what)) {
124 if (where == ls->linenumber)
125 error_expected(ls, what);
126 else {
128 "%s expected (to close %s at line %d)",
129 luaX_token2str(ls, what), luaX_token2str(ls, who), where));
130 }
131 }
132}
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,...)

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().

◆ checklimit()

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

Definition at line 92 of file lua-5.3.6/src/lparser.c.

92 {
93 if (v > l) errorlimit(fs, l, what);
94}
static l_noret errorlimit(FuncState *fs, int limit, const char *what)

References errorlimit().

Referenced by assignment(), enterlevel(), listfield(), new_localvar(), newupvalue(), and recfield().

◆ checkname()

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

Definition at line 156 of file lua-5.3.6/src/lparser.c.

156 {
157 codestring(ls, e, str_checkname(ls));
158}
static TString * str_checkname(LexState *ls)
static void codestring(LexState *ls, expdesc *e, TString *s)

References codestring(), and str_checkname().

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

◆ checknext()

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

Definition at line 112 of file lua-5.3.6/src/lparser.c.

112 {
113 check(ls, c);
114 luaX_next(ls);
115}
#define check(x)
void luaX_next(LexState *ls)

References check, and luaX_next().

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

◆ checkrepeated()

static void checkrepeated ( FuncState * fs,
Labellist * ll,
TString * label )
static

Definition at line 1204 of file lua-5.3.6/src/lparser.c.

1204 {
1205 int i;
1206 for (i = fs->bl->firstlabel; i < ll->n; i++) {
1207 if (eqstr(label, ll->arr[i].name)) {
1208 const char *msg = luaO_pushfstring(fs->ls->L,
1209 "label '%s' already defined on line %d",
1210 getstr(label), ll->arr[i].line);
1211 semerror(fs->ls, msg);
1212 }
1213 }
1214}
#define getstr(ts)
#define eqstr(a, b)
static l_noret semerror(LexState *ls, const char *msg)
struct BlockCnt * bl
struct LexState * ls

References Labellist::arr, FuncState::bl, eqstr, BlockCnt::firstlabel, getstr, LexState::L, Labeldesc::line, FuncState::ls, luaO_pushfstring(), Labellist::n, Labeldesc::name, and semerror().

Referenced by labelstat().

◆ close_func()

static void close_func ( LexState * ls)
static

Definition at line 553 of file lua-5.3.6/src/lparser.c.

553 {
554 lua_State *L = ls->L;
555 FuncState *fs = ls->fs;
556 Proto *f = fs->f;
557 luaK_ret(fs, 0, 0); /* final return */
558 leaveblock(fs);
560 f->sizecode = fs->pc;
561 luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);
562 f->sizelineinfo = fs->pc;
563 luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue);
564 f->sizek = fs->nk;
565 luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *);
566 f->sizep = fs->np;
568 f->sizelocvars = fs->nlocvars;
570 f->sizeupvalues = fs->nups;
571 lua_assert(fs->bl == NULL);
572 ls->fs = fs->prev;
573 luaC_checkGC(L);
574}
void luaK_ret(FuncState *fs, int first, int nret)
#define luaC_checkGC(L)
lu_int32 Instruction
#define lua_assert(c)
#define luaM_reallocvector(L, v, oldn, n, t)
struct FuncState * prev
Instruction * code
struct LocVar * locvars
TString ** upvalues

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

Referenced by body(), and mainfunc().

◆ closegoto()

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

Definition at line 341 of file lua-5.3.6/src/lparser.c.

341 {
342 int i;
343 FuncState *fs = ls->fs;
344 Labellist *gl = &ls->dyd->gt;
345 Labeldesc *gt = &gl->arr[g];
346 lua_assert(eqstr(gt->name, label->name));
347 if (gt->nactvar < label->nactvar) {
348 TString *vname = getlocvar(fs, gt->nactvar)->varname;
349 const char *msg = luaO_pushfstring(ls->L,
350 "<goto %s> at line %d jumps into the scope of local '%s'",
351 getstr(gt->name), gt->line, getstr(vname));
352 semerror(ls, msg);
353 }
354 luaK_patchlist(fs, gt->pc, label->pc);
355 /* remove goto from pending list */
356 for (i = g; i < gl->n - 1; i++)
357 gl->arr[i] = gl->arr[i + 1];
358 gl->n--;
359}
void luaK_patchlist(FuncState *fs, int list, int target)
#define gt(L)

References Labellist::arr, LexState::dyd, eqstr, LexState::fs, getlocvar, getstr, gt, Dyndata::gt, LexState::L, lua_assert, luaK_patchlist(), luaO_pushfstring(), Labellist::n, FuncState::nactvar, Labeldesc::nactvar, Labeldesc::name, FuncState::pc, Labeldesc::pc, and semerror().

Referenced by findgotos(), and findlabel().

◆ closelistfield()

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

Definition at line 668 of file lua-5.3.6/src/lparser.c.

668 {
669 if (cc->v.k == VVOID) return; /* there is no list item */
670 luaK_exp2nextreg(fs, &cc->v);
671 cc->v.k = VVOID;
672 if (cc->tostore == LFIELDS_PER_FLUSH) {
673 luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore); /* flush */
674 cc->tostore = 0; /* no more items pending */
675 }
676}
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 522 of file lua-5.3.6/src/lparser.c.

522 {
523 FuncState *fs = ls->fs->prev;
524 init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np - 1));
525 luaK_exp2nextreg(fs, v); /* fix it at the last register */
526}
int luaK_codeABx(FuncState *fs, OpCode o, int a, unsigned int bc)

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

Referenced by body().

◆ codestring()

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

Definition at line 151 of file lua-5.3.6/src/lparser.c.

151 {
152 init_exp(e, VK, luaK_stringK(ls->fs, s));
153}
int luaK_stringK(FuncState *fs, TString *s)
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318

References LexState::fs, init_exp(), luaK_stringK(), s, and VK.

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

◆ cond()

static int cond ( LexState * ls)
static

Definition at line 1178 of file lua-5.3.6/src/lparser.c.

1178 {
1179 /* cond -> exp */
1180 expdesc v;
1181 expr(ls, &v); /* read condition */
1182 if (v.k == VNIL) v.k = VFALSE; /* 'falses' are all equal here */
1183 luaK_goiftrue(ls->fs, &v);
1184 return v.f;
1185}
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 725 of file lua-5.3.6/src/lparser.c.

725 {
726 /* constructor -> '{' [ field { sep field } [sep] ] '}'
727 sep -> ',' | ';' */
728 FuncState *fs = ls->fs;
729 int line = ls->linenumber;
730 int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0);
731 struct ConsControl cc;
732 cc.na = cc.nh = cc.tostore = 0;
733 cc.t = t;
734 init_exp(t, VRELOCABLE, pc);
735 init_exp(&cc.v, VVOID, 0); /* no value (yet) */
736 luaK_exp2nextreg(ls->fs, t); /* fix it at stack top */
737 checknext(ls, '{');
738 do {
739 lua_assert(cc.v.k == VVOID || cc.tostore > 0);
740 if (ls->t.token == '}') break;
741 closelistfield(fs, &cc);
742 field(ls, &cc);
743 } while (testnext(ls, ',') || testnext(ls, ';'));
744 check_match(ls, '}', '{', line);
745 lastlistfield(fs, &cc);
746 SETARG_B(fs->f->code[pc], luaO_int2fb(cc.na)); /* set initial array size */
747 SETARG_C(fs->f->code[pc], luaO_int2fb(cc.nh)); /* set initial table size */
748}
int luaO_int2fb(unsigned int x)
#define SETARG_C(i, b)
#define SETARG_B(i, b)
static void field(LexState *ls, struct ConsControl *cc)
static void lastlistfield(FuncState *fs, struct ConsControl *cc)
static void closelistfield(FuncState *fs, struct ConsControl *cc)

References check_match(), checknext(), closelistfield(), Proto::code, FuncState::f, field(), LexState::fs, init_exp(), expdesc::k, lastlistfield(), LexState::linenumber, lua_assert, luaK_codeABC, luaK_exp2nextreg(), luaO_int2fb(), ConsControl::na, ConsControl::nh, OP_NEWTABLE, SETARG_B, SETARG_C, LexState::t, ConsControl::t, testnext(), Token::token, ConsControl::tostore, ConsControl::v, VRELOCABLE, and VVOID.

Referenced by funcargs(), and simpleexp().

◆ enterblock()

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

◆ enterlevel()

static void enterlevel ( LexState * ls)
static

Definition at line 331 of file lua-5.3.6/src/lparser.c.

331 {
332 lua_State *L = ls->L;
333 ++L->nCcalls;
334 checklimit(ls->fs, L->nCcalls, LUAI_MAXCCALLS, "C levels");
335}

References checklimit(), LexState::fs, LexState::L, LUAI_MAXCCALLS, and lua_State::nCcalls.

◆ error_expected()

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

Definition at line 73 of file lua-5.3.6/src/lparser.c.

73 {
75 luaO_pushfstring(ls->L, "%s expected", luaX_token2str(ls, token)));
76}

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 79 of file lua-5.3.6/src/lparser.c.

79 {
80 lua_State *L = fs->ls->L;
81 const char *msg;
82 int line = fs->f->linedefined;
83 const char *where = (line == 0)
84 ? "main function"
85 : luaO_pushfstring(L, "function at line %d", line);
86 msg = luaO_pushfstring(L, "too many %s (limit is %d) in %s",
87 what, limit, where);
88 luaX_syntaxerror(fs->ls, msg);
89}

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

Referenced by checklimit().

◆ exp1()

static int exp1 ( LexState * ls)
static

Definition at line 1281 of file lua-5.3.6/src/lparser.c.

1281 {
1282 expdesc e;
1283 int reg;
1284 expr(ls, &e);
1285 luaK_exp2nextreg(ls->fs, &e);
1286 lua_assert(e.k == VNONRELOC);
1287 reg = e.u.info;
1288 return reg;
1289}

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

Referenced by fornum().

◆ explist()

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

Definition at line 805 of file lua-5.3.6/src/lparser.c.

805 {
806 /* explist -> expr { ',' expr } */
807 int n = 1; /* at least one expression */
808 expr(ls, v);
809 while (testnext(ls, ',')) {
810 luaK_exp2nextreg(ls->fs, v);
811 expr(ls, v);
812 n++;
813 }
814 return n;
815}

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

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

◆ expr()

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

Definition at line 1079 of file lua-5.3.6/src/lparser.c.

1079 {
1080 subexpr(ls, v, 0);
1081}
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 1489 of file lua-5.3.6/src/lparser.c.

1489 {
1490 /* stat -> func | assignment */
1491 FuncState *fs = ls->fs;
1492 struct LHS_assign v;
1493 suffixedexp(ls, &v.v);
1494 if (ls->t.token == '=' || ls->t.token == ',') { /* stat -> assignment ? */
1495 v.prev = NULL;
1496 assignment(ls, &v, 1);
1497 }
1498 else { /* stat -> func */
1499 check_condition(ls, v.v.k == VCALL, "syntax error");
1500 SETARG_C(getinstruction(fs, &v.v), 1); /* call statement uses no results */
1501 }
1502}
#define getinstruction(fs, e)

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

Referenced by statement().

◆ field()

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

Definition at line 703 of file lua-5.3.6/src/lparser.c.

703 {
704 /* field -> listfield | recfield */
705 switch(ls->t.token) {
706 case TK_NAME: { /* may be 'listfield' or 'recfield' */
707 if (luaX_lookahead(ls) != '=') /* expression? */
708 listfield(ls, cc);
709 else
710 recfield(ls, cc);
711 break;
712 }
713 case '[': {
714 recfield(ls, cc);
715 break;
716 }
717 default: {
718 listfield(ls, cc);
719 break;
720 }
721 }
722}
void luaX_lookahead(LexState *ls)
@ TK_NAME
static void listfield(LexState *ls, struct ConsControl *cc)
static void recfield(LexState *ls, struct 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 611 of file lua-5.3.6/src/lparser.c.

611 {
612 /* fieldsel -> ['.' | ':'] NAME */
613 FuncState *fs = ls->fs;
614 expdesc key;
615 luaK_exp2anyregup(fs, v);
616 luaX_next(ls); /* skip the dot or colon */
617 checkname(ls, &key);
618 luaK_indexed(fs, v, &key);
619}
void luaK_indexed(FuncState *fs, expdesc *t, expdesc *k)
void luaK_exp2anyregup(FuncState *fs, expdesc *e)
static void checkname(LexState *ls, expdesc *e)

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

Referenced by funcname(), and suffixedexp().

◆ findgotos()

static void findgotos ( LexState * ls,
Labeldesc * lb )
static

Definition at line 403 of file lua-5.3.6/src/lparser.c.

403 {
404 Labellist *gl = &ls->dyd->gt;
405 int i = ls->fs->bl->firstgoto;
406 while (i < gl->n) {
407 if (eqstr(gl->arr[i].name, lb->name))
408 closegoto(ls, i, lb);
409 else
410 i++;
411 }
412}
static void closegoto(LexState *ls, int g, Labeldesc *label)

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

Referenced by breaklabel(), and labelstat().

◆ findlabel()

static int findlabel ( LexState * ls,
int g )
static

Definition at line 365 of file lua-5.3.6/src/lparser.c.

365 {
366 int i;
367 BlockCnt *bl = ls->fs->bl;
368 Dyndata *dyd = ls->dyd;
369 Labeldesc *gt = &dyd->gt.arr[g];
370 /* check labels in current block for a match */
371 for (i = bl->firstlabel; i < dyd->label.n; i++) {
372 Labeldesc *lb = &dyd->label.arr[i];
373 if (eqstr(lb->name, gt->name)) { /* correct label? */
374 if (gt->nactvar > lb->nactvar &&
375 (bl->upval || dyd->label.n > bl->firstlabel))
376 luaK_patchclose(ls->fs, gt->pc, lb->nactvar);
377 closegoto(ls, g, lb); /* close it */
378 return 1;
379 }
380 }
381 return 0; /* label not found; cannot close goto */
382}
LUAI_FUNC void luaK_patchclose(FuncState *fs, int list, int level)

References Labellist::arr, FuncState::bl, closegoto(), LexState::dyd, eqstr, BlockCnt::firstlabel, LexState::fs, gt, Dyndata::gt, Dyndata::label, luaK_patchclose(), Labellist::n, Labeldesc::nactvar, Labeldesc::name, FuncState::pc, and BlockCnt::upval.

Referenced by gotostat(), and movegotosout().

◆ forbody()

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

Definition at line 1292 of file lua-5.3.6/src/lparser.c.

1292 {
1293 /* forbody -> DO block */
1294 BlockCnt bl;
1295 FuncState *fs = ls->fs;
1296 int prep, endfor;
1297 adjustlocalvars(ls, 3); /* control variables */
1298 checknext(ls, TK_DO);
1299 prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs);
1300 enterblock(fs, &bl, 0); /* scope for declared variables */
1301 adjustlocalvars(ls, nvars);
1302 luaK_reserveregs(fs, nvars);
1303 block(ls);
1304 leaveblock(fs); /* end of scope for declared variables */
1305 luaK_patchtohere(fs, prep);
1306 if (isnum) /* numeric for? */
1307 endfor = luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP);
1308 else { /* generic for */
1309 luaK_codeABC(fs, OP_TFORCALL, base, 0, nvars);
1310 luaK_fixline(fs, line);
1311 endfor = luaK_codeAsBx(fs, OP_TFORLOOP, base + 2, NO_JUMP);
1312 }
1313 luaK_patchlist(fs, endfor, prep + 1);
1314 luaK_fixline(fs, line);
1315}
int luaK_jump(FuncState *fs)
void luaK_patchtohere(FuncState *fs, int list)
void luaK_fixline(FuncState *fs, int line)
#define luaK_codeAsBx(fs, o, A, sBx)
#define NO_JUMP
static void block(LexState *ls)
#define TK_DO
Definition sqlite3.c:14003

References adjustlocalvars(), block(), checknext(), enterblock(), LexState::fs, leaveblock(), luaK_codeABC, luaK_codeAsBx, luaK_fixline(), luaK_jump(), luaK_patchlist(), luaK_patchtohere(), luaK_reserveregs(), NO_JUMP, OP_FORLOOP, OP_FORPREP, OP_TFORCALL, OP_TFORLOOP, and TK_DO.

Referenced by forlist(), and fornum().

◆ forlist()

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

Definition at line 1340 of file lua-5.3.6/src/lparser.c.

1340 {
1341 /* forlist -> NAME {,NAME} IN explist forbody */
1342 FuncState *fs = ls->fs;
1343 expdesc e;
1344 int nvars = 4; /* gen, state, control, plus at least one declared var */
1345 int line;
1346 int base = fs->freereg;
1347 /* create control variables */
1348 new_localvarliteral(ls, "(for generator)");
1349 new_localvarliteral(ls, "(for state)");
1350 new_localvarliteral(ls, "(for control)");
1351 /* create declared variables */
1352 new_localvar(ls, indexname);
1353 while (testnext(ls, ',')) {
1354 new_localvar(ls, str_checkname(ls));
1355 nvars++;
1356 }
1357 checknext(ls, TK_IN);
1358 line = ls->linenumber;
1359 adjust_assign(ls, 3, explist(ls, &e), &e);
1360 luaK_checkstack(fs, 3); /* extra space to call generator */
1361 forbody(ls, base, line, nvars - 3, 0);
1362}
void luaK_checkstack(FuncState *fs, int n)
static void new_localvar(LexState *ls, TString *name)
static void forbody(LexState *ls, int base, int line, int nvars, int isnum)
#define TK_IN
Definition sqlite3.c:13991

References adjust_assign(), checknext(), explist(), forbody(), FuncState::freereg, LexState::fs, LexState::linenumber, luaK_checkstack(), 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 1318 of file lua-5.3.6/src/lparser.c.

1318 {
1319 /* fornum -> NAME = exp1,exp1[,exp1] forbody */
1320 FuncState *fs = ls->fs;
1321 int base = fs->freereg;
1322 new_localvarliteral(ls, "(for index)");
1323 new_localvarliteral(ls, "(for limit)");
1324 new_localvarliteral(ls, "(for step)");
1325 new_localvar(ls, varname);
1326 checknext(ls, '=');
1327 exp1(ls); /* initial value */
1328 checknext(ls, ',');
1329 exp1(ls); /* limit */
1330 if (testnext(ls, ','))
1331 exp1(ls); /* optional step */
1332 else { /* default step = 1 */
1333 luaK_codek(fs, fs->freereg, luaK_intK(fs, 1));
1334 luaK_reserveregs(fs, 1);
1335 }
1336 forbody(ls, base, line, 1, 1);
1337}
int luaK_codek(FuncState *fs, int reg, int k)
int luaK_intK(FuncState *fs, lua_Integer n)
static int exp1(LexState *ls)

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

Referenced by forstat().

◆ forstat()

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

Definition at line 1365 of file lua-5.3.6/src/lparser.c.

1365 {
1366 /* forstat -> FOR (fornum | forlist) END */
1367 FuncState *fs = ls->fs;
1368 TString *varname;
1369 BlockCnt bl;
1370 enterblock(fs, &bl, 1); /* scope for loop and control variables */
1371 luaX_next(ls); /* skip 'for' */
1372 varname = str_checkname(ls); /* first variable name */
1373 switch (ls->t.token) {
1374 case '=': fornum(ls, varname, line); break;
1375 case ',': case TK_IN: forlist(ls, varname); break;
1376 default: luaX_syntaxerror(ls, "'=' or 'in' expected");
1377 }
1378 check_match(ls, TK_END, TK_FOR, line);
1379 leaveblock(fs); /* loop scope ('break' jumps to this point) */
1380}
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 818 of file lua-5.3.6/src/lparser.c.

818 {
819 FuncState *fs = ls->fs;
820 expdesc args;
821 int base, nparams;
822 switch (ls->t.token) {
823 case '(': { /* funcargs -> '(' [ explist ] ')' */
824 luaX_next(ls);
825 if (ls->t.token == ')') /* arg list is empty? */
826 args.k = VVOID;
827 else {
828 explist(ls, &args);
829 luaK_setmultret(fs, &args);
830 }
831 check_match(ls, ')', '(', line);
832 break;
833 }
834 case '{': { /* funcargs -> constructor */
835 constructor(ls, &args);
836 break;
837 }
838 case TK_STRING: { /* funcargs -> STRING */
839 codestring(ls, &args, ls->t.seminfo.ts);
840 luaX_next(ls); /* must use 'seminfo' before 'next' */
841 break;
842 }
843 default: {
844 luaX_syntaxerror(ls, "function arguments expected");
845 }
846 }
847 lua_assert(f->k == VNONRELOC);
848 base = f->u.info; /* base register for call */
849 if (hasmultret(args.k))
850 nparams = LUA_MULTRET; /* open call */
851 else {
852 if (args.k != VVOID)
853 luaK_exp2nextreg(fs, &args); /* close last argument */
854 nparams = fs->freereg - (base+1);
855 }
856 init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2));
857 luaK_fixline(fs, line);
858 fs->freereg = base+1; /* call remove function and arguments and leaves
859 (unless changed) one result */
860}
#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 1463 of file lua-5.3.6/src/lparser.c.

1463 {
1464 /* funcname -> NAME {fieldsel} [':' NAME] */
1465 int ismethod = 0;
1466 singlevar(ls, v);
1467 while (ls->t.token == '.')
1468 fieldsel(ls, v);
1469 if (ls->t.token == ':') {
1470 ismethod = 1;
1471 fieldsel(ls, v);
1472 }
1473 return ismethod;
1474}
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 1477 of file lua-5.3.6/src/lparser.c.

1477 {
1478 /* funcstat -> FUNCTION funcname body */
1479 int ismethod;
1480 expdesc v, b;
1481 luaX_next(ls); /* skip FUNCTION */
1482 ismethod = funcname(ls, &v);
1483 body(ls, &b, ismethod, line);
1484 luaK_storevar(ls->fs, &v, &b);
1485 luaK_fixline(ls->fs, line); /* definition "happens" in the first line */
1486}
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 998 of file lua-5.3.6/src/lparser.c.

998 {
999 switch (op) {
1000 case '+': return OPR_ADD;
1001 case '-': return OPR_SUB;
1002 case '*': return OPR_MUL;
1003 case '%': return OPR_MOD;
1004 case '^': return OPR_POW;
1005 case '/': return OPR_DIV;
1006 case TK_IDIV: return OPR_IDIV;
1007 case '&': return OPR_BAND;
1008 case '|': return OPR_BOR;
1009 case '~': return OPR_BXOR;
1010 case TK_SHL: return OPR_SHL;
1011 case TK_SHR: return OPR_SHR;
1012 case TK_CONCAT: return OPR_CONCAT;
1013 case TK_NE: return OPR_NE;
1014 case TK_EQ: return OPR_EQ;
1015 case '<': return OPR_LT;
1016 case TK_LE: return OPR_LE;
1017 case '>': return OPR_GT;
1018 case TK_GE: return OPR_GE;
1019 case TK_AND: return OPR_AND;
1020 case TK_OR: return OPR_OR;
1021 default: return OPR_NOBINOPR;
1022 }
1023}
@ 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().

◆ getlocvar()

static LocVar * getlocvar ( FuncState * fs,
int i )
static

Definition at line 195 of file lua-5.3.6/src/lparser.c.

195 {
196 int idx = fs->ls->dyd->actvar.arr[fs->firstlocal + i].idx;
197 lua_assert(idx < fs->nlocvars);
198 return &fs->f->locvars[idx];
199}
struct Dyndata::@63 actvar

References Dyndata::actvar, Dyndata::arr, LexState::dyd, FuncState::f, FuncState::firstlocal, Vardesc::idx, Proto::locvars, FuncState::ls, and lua_assert.

◆ getunopr()

static UnOpr getunopr ( int op)
static

Definition at line 987 of file lua-5.3.6/src/lparser.c.

987 {
988 switch (op) {
989 case TK_NOT: return OPR_NOT;
990 case '-': return OPR_MINUS;
991 case '~': return OPR_BNOT;
992 case '#': return OPR_LEN;
993 default: return OPR_NOUNOPR;
994 }
995}
@ 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,
int pc )
static

Definition at line 1188 of file lua-5.3.6/src/lparser.c.

1188 {
1189 int line = ls->linenumber;
1190 TString *label;
1191 int g;
1192 if (testnext(ls, TK_GOTO))
1193 label = str_checkname(ls);
1194 else {
1195 luaX_next(ls); /* skip break */
1196 label = luaS_new(ls->L, "break");
1197 }
1198 g = newlabelentry(ls, &ls->dyd->gt, label, line, pc);
1199 findlabel(ls, g); /* close it if label already defined */
1200}
@ TK_GOTO
static int findlabel(LexState *ls, int g)

References LexState::dyd, findlabel(), Dyndata::gt, LexState::L, LexState::linenumber, luaS_new, luaX_next(), newlabelentry(), str_checkname(), testnext(), and TK_GOTO.

Referenced by statement(), and test_then_block().

◆ ifstat()

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

Definition at line 1418 of file lua-5.3.6/src/lparser.c.

1418 {
1419 /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */
1420 FuncState *fs = ls->fs;
1421 int escapelist = NO_JUMP; /* exit list for finished parts */
1422 test_then_block(ls, &escapelist); /* IF cond THEN block */
1423 while (ls->t.token == TK_ELSEIF)
1424 test_then_block(ls, &escapelist); /* ELSEIF cond THEN block */
1425 if (testnext(ls, TK_ELSE))
1426 block(ls); /* 'else' part */
1427 check_match(ls, TK_END, TK_IF, line);
1428 luaK_patchtohere(fs, escapelist); /* patch escape list to 'if' end */
1429}
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 144 of file lua-5.3.6/src/lparser.c.

144 {
145 e->f = e->t = NO_JUMP;
146 e->k = k;
147 e->u.info = i;
148}

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

Referenced by assignment(), codeclosure(), codestring(), constructor(), funcargs(), mainfunc(), simpleexp(), and singlevaraux().

◆ labelstat()

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

Definition at line 1224 of file lua-5.3.6/src/lparser.c.

1224 {
1225 /* label -> '::' NAME '::' */
1226 FuncState *fs = ls->fs;
1227 Labellist *ll = &ls->dyd->label;
1228 int l; /* index of new label being created */
1229 checkrepeated(fs, ll, label); /* check for repeated labels */
1230 checknext(ls, TK_DBCOLON); /* skip double colon */
1231 /* create new entry for this label */
1232 l = newlabelentry(ls, ll, label, line, luaK_getlabel(fs));
1233 skipnoopstat(ls); /* skip other no-op statements */
1234 if (block_follow(ls, 0)) { /* label is last no-op statement in the block? */
1235 /* assume that locals are already out of scope */
1236 ll->arr[l].nactvar = fs->bl->nactvar;
1237 }
1238 findgotos(ls, &ll->arr[l]);
1239}
int luaK_getlabel(FuncState *fs)
@ TK_DBCOLON
static void checkrepeated(FuncState *fs, Labellist *ll, TString *label)
static void skipnoopstat(LexState *ls)
static int block_follow(LexState *ls, int withuntil)

References Labellist::arr, FuncState::bl, block_follow(), checknext(), checkrepeated(), LexState::dyd, findgotos(), LexState::fs, Dyndata::label, luaK_getlabel(), BlockCnt::nactvar, Labeldesc::nactvar, newlabelentry(), skipnoopstat(), and TK_DBCOLON.

Referenced by statement().

◆ lastlistfield()

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

Definition at line 679 of file lua-5.3.6/src/lparser.c.

679 {
680 if (cc->tostore == 0) return;
681 if (hasmultret(cc->v.k)) {
682 luaK_setmultret(fs, &cc->v);
683 luaK_setlist(fs, cc->t->u.info, cc->na, LUA_MULTRET);
684 cc->na--; /* do not count last expression (unknown number of elements) */
685 }
686 else {
687 if (cc->v.k != VVOID)
688 luaK_exp2nextreg(fs, &cc->v);
689 luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore);
690 }
691}

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 473 of file lua-5.3.6/src/lparser.c.

473 {
474 BlockCnt *bl = fs->bl;
475 LexState *ls = fs->ls;
476 if (bl->previous && bl->upval) {
477 /* create a 'jump to here' to close upvalues */
478 int j = luaK_jump(fs);
479 luaK_patchclose(fs, j, bl->nactvar);
480 luaK_patchtohere(fs, j);
481 }
482 if (bl->isloop)
483 breaklabel(ls); /* close pending breaks */
484 fs->bl = bl->previous;
485 removevars(fs, bl->nactvar);
486 lua_assert(bl->nactvar == fs->nactvar);
487 fs->freereg = fs->nactvar; /* free registers */
488 ls->dyd->label.n = bl->firstlabel; /* remove local labels */
489 if (bl->previous) /* inner block? */
490 movegotosout(fs, bl); /* update pending gotos to outer block */
491 else if (bl->firstgoto < ls->dyd->gt.n) /* pending gotos in outer block? */
492 undefgoto(ls, &ls->dyd->gt.arr[bl->firstgoto]); /* error */
493}
static l_noret undefgoto(LexState *ls, Labeldesc *gt)
static void removevars(FuncState *fs, int tolevel)
static void movegotosout(FuncState *fs, BlockCnt *bl)
static void breaklabel(LexState *ls)

References Labellist::arr, FuncState::bl, breaklabel(), LexState::dyd, BlockCnt::firstgoto, BlockCnt::firstlabel, FuncState::freereg, Dyndata::gt, BlockCnt::isloop, Dyndata::label, FuncState::ls, lua_assert, luaK_jump(), luaK_patchclose(), luaK_patchtohere(), movegotosout(), Labellist::n, BlockCnt::nactvar, FuncState::nactvar, BlockCnt::previous, removevars(), undefgoto(), and BlockCnt::upval.

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

◆ listfield()

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

Definition at line 694 of file lua-5.3.6/src/lparser.c.

694 {
695 /* listfield -> exp */
696 expr(ls, &cc->v);
697 checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor");
698 cc->na++;
699 cc->tostore++;
700}
#define MAX_INT

References checklimit(), expr(), LexState::fs, MAX_INT, ConsControl::na, ConsControl::tostore, and ConsControl::v.

Referenced by field().

◆ localfunc()

static void localfunc ( LexState * ls)
static

Definition at line 1432 of file lua-5.3.6/src/lparser.c.

1432 {
1433 expdesc b;
1434 FuncState *fs = ls->fs;
1435 new_localvar(ls, str_checkname(ls)); /* new local variable */
1436 adjustlocalvars(ls, 1); /* enter its scope */
1437 body(ls, &b, 0, ls->linenumber); /* function created in next register */
1438 /* debug information will only see the variable after this point! */
1439 getlocvar(fs, b.u.info)->startpc = fs->pc;
1440}

References adjustlocalvars(), body(), LexState::fs, getlocvar, expdesc::info, LexState::linenumber, new_localvar(), FuncState::pc, str_checkname(), and expdesc::u.

Referenced by statement().

◆ localstat()

static void localstat ( LexState * ls)
static

Definition at line 1443 of file lua-5.3.6/src/lparser.c.

1443 {
1444 /* stat -> LOCAL NAME {',' NAME} ['=' explist] */
1445 int nvars = 0;
1446 int nexps;
1447 expdesc e;
1448 do {
1449 new_localvar(ls, str_checkname(ls));
1450 nvars++;
1451 } while (testnext(ls, ','));
1452 if (testnext(ls, '='))
1453 nexps = explist(ls, &e);
1454 else {
1455 e.k = VVOID;
1456 nexps = 0;
1457 }
1458 adjust_assign(ls, nvars, nexps, &e);
1459 adjustlocalvars(ls, nvars);
1460}

References adjust_assign(), adjustlocalvars(), explist(), expdesc::k, new_localvar(), str_checkname(), testnext(), and VVOID.

Referenced by statement().

◆ luaY_parser()

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

Definition at line 1628 of file lua-5.3.6/src/lparser.c.

1629 {
1630 LexState lexstate;
1631 FuncState funcstate;
1632 LClosure *cl = luaF_newLclosure(L, 1); /* create main closure */
1633 setclLvalue(L, L->top, cl); /* anchor it (to avoid being collected) */
1634 luaD_inctop(L);
1635 lexstate.h = luaH_new(L); /* create table for scanner */
1636 sethvalue(L, L->top, lexstate.h); /* anchor it */
1637 luaD_inctop(L);
1638 funcstate.f = cl->p = luaF_newproto(L);
1639 luaC_objbarrier(L, cl, cl->p);
1640 funcstate.f->source = luaS_new(L, name); /* create and anchor TString */
1641 lua_assert(iswhite(funcstate.f)); /* do not need barrier here */
1642 lexstate.buff = buff;
1643 lexstate.dyd = dyd;
1644 dyd->actvar.n = dyd->gt.n = dyd->label.n = 0;
1645 luaX_setinput(L, &lexstate, z, funcstate.f->source, firstchar);
1646 mainfunc(&lexstate, &funcstate);
1647 lua_assert(!funcstate.prev && funcstate.nups == 1 && !lexstate.fs);
1648 /* all scopes should be correctly finished */
1649 lua_assert(dyd->actvar.n == 0 && dyd->gt.n == 0 && dyd->label.n == 0);
1650 L->top--; /* remove scanner's table */
1651 return cl; /* closure is on the stack, too */
1652}
const char * name
Definition lsqlite3.c:2154
Closure * luaF_newLclosure(lua_State *L, int nelems, Table *e)
#define iswhite(x)
void luaX_setinput(lua_State *L, LexState *ls, ZIO *z, TString *source)
#define sethvalue(L, obj, x)
Table * luaH_new(lua_State *L, int narray, int nhash)
#define setclLvalue(L, obj, x)
void luaD_inctop(lua_State *L)
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, iswhite, 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, setclLvalue, sethvalue, Proto::source, and lua_State::top.

◆ mainfunc()

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

Definition at line 1613 of file lua-5.3.6/src/lparser.c.

1613 {
1614 BlockCnt bl;
1615 expdesc v;
1616 open_func(ls, fs, &bl);
1617 fs->f->is_vararg = 1; /* main function is always declared vararg */
1618 init_exp(&v, VLOCAL, 0); /* create and... */
1619 newupvalue(fs, ls->envn, &v); /* ...set environment upvalue */
1620 luaC_objbarrier(ls->L, fs->f, ls->envn);
1621 luaX_next(ls); /* read first token */
1622 statlist(ls); /* parse main body */
1623 check(ls, TK_EOS);
1624 close_func(ls);
1625}
static int newupvalue(FuncState *fs, TString *name, expdesc *v)
TString * envn

References check, close_func(), LexState::envn, FuncState::f, init_exp(), Proto::is_vararg, LexState::L, luaC_objbarrier, luaX_next(), newupvalue(), open_func(), statlist(), TK_EOS, LHS_assign::v, and VLOCAL.

Referenced by luaY_parser().

◆ markupval()

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

Definition at line 258 of file lua-5.3.6/src/lparser.c.

258 {
259 BlockCnt *bl = fs->bl;
260 while (bl->nactvar > level)
261 bl = bl->previous;
262 bl->upval = 1;
263}

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

Referenced by singlevaraux().

◆ movegotosout()

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

Definition at line 421 of file lua-5.3.6/src/lparser.c.

421 {
422 int i = bl->firstgoto;
423 Labellist *gl = &fs->ls->dyd->gt;
424 /* correct pending gotos to current block and try to close it
425 with visible labels */
426 while (i < gl->n) {
427 Labeldesc *gt = &gl->arr[i];
428 if (gt->nactvar > bl->nactvar) {
429 if (bl->upval)
430 luaK_patchclose(fs, gt->pc, bl->nactvar);
431 gt->nactvar = bl->nactvar;
432 }
433 if (!findlabel(fs->ls, i))
434 i++; /* move to next one */
435 }
436}

References Labellist::arr, LexState::dyd, findlabel(), BlockCnt::firstgoto, gt, Dyndata::gt, FuncState::ls, luaK_patchclose(), BlockCnt::nactvar, FuncState::pc, and BlockCnt::upval.

Referenced by leaveblock().

◆ new_localvar()

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

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

175 {
176 FuncState *fs = ls->fs;
177 Dyndata *dyd = ls->dyd;
178 int reg = registerlocalvar(ls, name);
179 checklimit(fs, dyd->actvar.n + 1 - fs->firstlocal,
180 MAXVARS, "local variables");
181 luaM_growvector(ls->L, dyd->actvar.arr, dyd->actvar.n + 1,
182 dyd->actvar.size, Vardesc, MAX_INT, "local variables");
183 dyd->actvar.arr[dyd->actvar.n++].idx = cast(short, reg);
184}
#define cast(t, exp)
#define MAXVARS
static int registerlocalvar(LexState *ls, TString *varname)

References Dyndata::actvar, Dyndata::arr, cast, checklimit(), LexState::dyd, FuncState::firstlocal, LexState::fs, Vardesc::idx, LexState::L, luaM_growvector, MAX_INT, MAXVARS, Dyndata::n, name, registerlocalvar(), and Dyndata::size.

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

◆ new_localvarliteral_()

static void new_localvarliteral_ ( LexState * ls,
const char * name,
size_t sz )
static

Definition at line 187 of file lua-5.3.6/src/lparser.c.

187 {
188 new_localvar(ls, luaX_newstring(ls, name, sz));
189}
TString * luaX_newstring(LexState *ls, const char *str, size_t l)

References luaX_newstring(), name, and new_localvar().

◆ newlabelentry()

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

Definition at line 385 of file lua-5.3.6/src/lparser.c.

386 {
387 int n = l->n;
388 luaM_growvector(ls->L, l->arr, n, l->size,
389 Labeldesc, SHRT_MAX, "labels/gotos");
390 l->arr[n].name = name;
391 l->arr[n].line = line;
392 l->arr[n].nactvar = ls->fs->nactvar;
393 l->arr[n].pc = pc;
394 l->n = n + 1;
395 return n;
396}

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

Referenced by breaklabel(), gotostat(), and labelstat().

◆ newupvalue()

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

Definition at line 228 of file lua-5.3.6/src/lparser.c.

228 {
229 Proto *f = fs->f;
230 int oldsize = f->sizeupvalues;
231 checklimit(fs, fs->nups + 1, MAXUPVAL, "upvalues");
232 luaM_growvector(fs->ls->L, f->upvalues, fs->nups, f->sizeupvalues,
233 Upvaldesc, MAXUPVAL, "upvalues");
234 while (oldsize < f->sizeupvalues)
235 f->upvalues[oldsize++].name = NULL;
236 f->upvalues[fs->nups].instack = (v->k == VLOCAL);
237 f->upvalues[fs->nups].idx = cast_byte(v->u.info);
238 f->upvalues[fs->nups].name = name;
239 luaC_objbarrier(fs->ls->L, f, name);
240 return fs->nups++;
241}
#define MAXUPVAL

References cast_byte, checklimit(), FuncState::f, expdesc::info, expdesc::k, LexState::L, FuncState::ls, luaC_objbarrier, luaM_growvector, MAXUPVAL, name, NULL, FuncState::nups, Proto::sizeupvalues, expdesc::u, Proto::upvalues, and VLOCAL.

Referenced by mainfunc(), and singlevaraux().

◆ open_func()

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

Definition at line 529 of file lua-5.3.6/src/lparser.c.

529 {
530 Proto *f;
531 fs->prev = ls->fs; /* linked list of funcstates */
532 fs->ls = ls;
533 ls->fs = fs;
534 fs->pc = 0;
535 fs->lasttarget = 0;
536 fs->jpc = NO_JUMP;
537 fs->freereg = 0;
538 fs->nk = 0;
539 fs->np = 0;
540 fs->nups = 0;
541 fs->nlocvars = 0;
542 fs->nactvar = 0;
543 fs->firstlocal = ls->dyd->actvar.n;
544 fs->bl = NULL;
545 f = fs->f;
546 f->source = ls->source;
547 luaC_objbarrier(ls->L, f, f->source);
548 f->maxstacksize = 2; /* registers 0/1 are always valid */
549 enterblock(fs, bl, 0);
550}
TString * source
lu_byte maxstacksize

References Dyndata::actvar, FuncState::bl, LexState::dyd, enterblock(), FuncState::f, FuncState::firstlocal, FuncState::freereg, LexState::fs, FuncState::jpc, LexState::L, FuncState::lasttarget, FuncState::ls, luaC_objbarrier, Proto::maxstacksize, Dyndata::n, FuncState::nactvar, FuncState::nk, FuncState::nlocvars, NO_JUMP, FuncState::np, NULL, FuncState::nups, FuncState::pc, FuncState::prev, LexState::source, and Proto::source.

Referenced by body(), and mainfunc().

◆ parlist()

static void parlist ( LexState * ls)
static

Definition at line 754 of file lua-5.3.6/src/lparser.c.

754 {
755 /* parlist -> [ param { ',' param } ] */
756 FuncState *fs = ls->fs;
757 Proto *f = fs->f;
758 int nparams = 0;
759 f->is_vararg = 0;
760 if (ls->t.token != ')') { /* is 'parlist' not empty? */
761 do {
762 switch (ls->t.token) {
763 case TK_NAME: { /* param -> NAME */
765 nparams++;
766 break;
767 }
768 case TK_DOTS: { /* param -> '...' */
769 luaX_next(ls);
770 f->is_vararg = 1; /* declared vararg */
771 break;
772 }
773 default: luaX_syntaxerror(ls, "<name> or '...' expected");
774 }
775 } while (!f->is_vararg && testnext(ls, ','));
776 }
777 adjustlocalvars(ls, nparams);
778 f->numparams = cast_byte(fs->nactvar);
779 luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */
780}
@ TK_DOTS

References adjustlocalvars(), cast_byte, FuncState::f, LexState::fs, Proto::is_vararg, luaK_reserveregs(), luaX_next(), luaX_syntaxerror(), FuncState::nactvar, new_localvar(), Proto::numparams, 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 872 of file lua-5.3.6/src/lparser.c.

872 {
873 /* primaryexp -> NAME | '(' expr ')' */
874 switch (ls->t.token) {
875 case '(': {
876 int line = ls->linenumber;
877 luaX_next(ls);
878 expr(ls, v);
879 check_match(ls, ')', '(', line);
880 luaK_dischargevars(ls->fs, v);
881 return;
882 }
883 case TK_NAME: {
884 singlevar(ls, v);
885 return;
886 }
887 default: {
888 luaX_syntaxerror(ls, "unexpected symbol");
889 }
890 }
891}
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, Token::token, and ConsControl::v.

Referenced by suffixedexp().

◆ recfield()

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

Definition at line 647 of file lua-5.3.6/src/lparser.c.

647 {
648 /* recfield -> (NAME | '['exp1']') = exp1 */
649 FuncState *fs = ls->fs;
650 int reg = ls->fs->freereg;
651 expdesc key, val;
652 int rkkey;
653 if (ls->t.token == TK_NAME) {
654 checklimit(fs, cc->nh, MAX_INT, "items in a constructor");
655 checkname(ls, &key);
656 }
657 else /* ls->t.token == '[' */
658 yindex(ls, &key);
659 cc->nh++;
660 checknext(ls, '=');
661 rkkey = luaK_exp2RK(fs, &key);
662 expr(ls, &val);
663 luaK_codeABC(fs, OP_SETTABLE, cc->t->u.info, rkkey, luaK_exp2RK(fs, &val));
664 fs->freereg = reg; /* free registers */
665}
int luaK_exp2RK(FuncState *fs, expdesc *e)
static void yindex(LexState *ls, expdesc *v)

References checklimit(), checkname(), checknext(), expr(), FuncState::freereg, LexState::fs, expdesc::info, luaK_codeABC, luaK_exp2RK(), MAX_INT, ConsControl::nh, OP_SETTABLE, LexState::t, ConsControl::t, TK_NAME, Token::token, expdesc::u, and yindex().

Referenced by field().

◆ registerlocalvar()

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

Definition at line 161 of file lua-5.3.6/src/lparser.c.

161 {
162 FuncState *fs = ls->fs;
163 Proto *f = fs->f;
164 int oldsize = f->sizelocvars;
166 LocVar, SHRT_MAX, "local variables");
167 while (oldsize < f->sizelocvars)
168 f->locvars[oldsize++].varname = NULL;
169 f->locvars[fs->nlocvars].varname = varname;
170 luaC_objbarrier(ls->L, f, varname);
171 return fs->nlocvars++;
172}
TString * varname

References FuncState::f, LexState::fs, LexState::L, Proto::locvars, luaC_objbarrier, luaM_growvector, FuncState::nlocvars, NULL, Proto::sizelocvars, and LocVar::varname.

Referenced by new_localvar().

◆ removevars()

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

Definition at line 211 of file lua-5.3.6/src/lparser.c.

211 {
212 fs->ls->dyd->actvar.n -= (fs->nactvar - tolevel);
213 while (fs->nactvar > tolevel)
214 getlocvar(fs, --fs->nactvar)->endpc = fs->pc;
215}

References Dyndata::actvar, LexState::dyd, getlocvar, FuncState::ls, Dyndata::n, FuncState::nactvar, and FuncState::pc.

Referenced by leaveblock().

◆ repeatstat()

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

Definition at line 1261 of file lua-5.3.6/src/lparser.c.

1261 {
1262 /* repeatstat -> REPEAT block UNTIL cond */
1263 int condexit;
1264 FuncState *fs = ls->fs;
1265 int repeat_init = luaK_getlabel(fs);
1266 BlockCnt bl1, bl2;
1267 enterblock(fs, &bl1, 1); /* loop block */
1268 enterblock(fs, &bl2, 0); /* scope block */
1269 luaX_next(ls); /* skip REPEAT */
1270 statlist(ls);
1271 check_match(ls, TK_UNTIL, TK_REPEAT, line);
1272 condexit = cond(ls); /* read condition (inside scope block) */
1273 if (bl2.upval) /* upvalues? */
1274 luaK_patchclose(fs, condexit, bl2.nactvar);
1275 leaveblock(fs); /* finish scope */
1276 luaK_patchlist(fs, condexit, repeat_init); /* close the loop */
1277 leaveblock(fs); /* finish loop */
1278}
@ TK_REPEAT
static int cond(LexState *ls)

References check_match(), cond(), enterblock(), LexState::fs, leaveblock(), luaK_getlabel(), luaK_patchclose(), luaK_patchlist(), luaX_next(), BlockCnt::nactvar, statlist(), TK_REPEAT, TK_UNTIL, and BlockCnt::upval.

Referenced by statement().

◆ retstat()

static void retstat ( LexState * ls)
static

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

1505 {
1506 /* stat -> RETURN [explist] [';'] */
1507 FuncState *fs = ls->fs;
1508 expdesc e;
1509 int first, nret; /* registers with returned values */
1510 if (block_follow(ls, 1) || ls->t.token == ';')
1511 first = nret = 0; /* return no values */
1512 else {
1513 nret = explist(ls, &e); /* optional return values */
1514 if (hasmultret(e.k)) {
1515 luaK_setmultret(fs, &e);
1516 if (e.k == VCALL && nret == 1) { /* tail call? */
1518 lua_assert(GETARG_A(getinstruction(fs,&e)) == fs->nactvar);
1519 }
1520 first = fs->nactvar;
1521 nret = LUA_MULTRET; /* return all values */
1522 }
1523 else {
1524 if (nret == 1) /* only one single value? */
1525 first = luaK_exp2anyreg(fs, &e);
1526 else {
1527 luaK_exp2nextreg(fs, &e); /* values must go to the stack */
1528 first = fs->nactvar; /* return all active values */
1529 lua_assert(nret == fs->freereg - first);
1530 }
1531 }
1532 }
1533 luaK_ret(fs, first, nret);
1534 testnext(ls, ';'); /* skip optional semicolon */
1535}
int luaK_exp2anyreg(FuncState *fs, expdesc *e)
#define GETARG_A(i)
#define SET_OPCODE(i, o)

References block_follow(), explist(), FuncState::freereg, LexState::fs, GETARG_A, getinstruction, hasmultret, expdesc::k, lua_assert, LUA_MULTRET, luaK_exp2anyreg(), luaK_exp2nextreg(), luaK_ret(), luaK_setmultret, FuncState::nactvar, 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 218 of file lua-5.3.6/src/lparser.c.

218 {
219 int i;
220 Upvaldesc *up = fs->f->upvalues;
221 for (i = 0; i < fs->nups; i++) {
222 if (eqstr(up[i].name, name)) return i;
223 }
224 return -1; /* not found */
225}

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

Referenced by singlevaraux().

◆ searchvar()

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

Definition at line 244 of file lua-5.3.6/src/lparser.c.

244 {
245 int i;
246 for (i = cast_int(fs->nactvar) - 1; i >= 0; i--) {
247 if (eqstr(n, getlocvar(fs, i)->varname))
248 return i;
249 }
250 return -1; /* not found */
251}
#define cast_int(i)

References cast_int, eqstr, getlocvar, and FuncState::nactvar.

Referenced by singlevaraux().

◆ semerror()

static l_noret semerror ( LexState * ls,
const char * msg )
static

Definition at line 67 of file lua-5.3.6/src/lparser.c.

67 {
68 ls->t.token = 0; /* remove "near <token>" from final message */
69 luaX_syntaxerror(ls, msg);
70}

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

Referenced by checkrepeated(), closegoto(), and undefgoto().

◆ simpleexp()

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

Definition at line 932 of file lua-5.3.6/src/lparser.c.

932 {
933 /* simpleexp -> FLT | INT | STRING | NIL | TRUE | FALSE | ... |
934 constructor | FUNCTION body | suffixedexp */
935 switch (ls->t.token) {
936 case TK_FLT: {
937 init_exp(v, VKFLT, 0);
938 v->u.nval = ls->t.seminfo.r;
939 break;
940 }
941 case TK_INT: {
942 init_exp(v, VKINT, 0);
943 v->u.ival = ls->t.seminfo.i;
944 break;
945 }
946 case TK_STRING: {
947 codestring(ls, v, ls->t.seminfo.ts);
948 break;
949 }
950 case TK_NIL: {
951 init_exp(v, VNIL, 0);
952 break;
953 }
954 case TK_TRUE: {
955 init_exp(v, VTRUE, 0);
956 break;
957 }
958 case TK_FALSE: {
959 init_exp(v, VFALSE, 0);
960 break;
961 }
962 case TK_DOTS: { /* vararg */
963 FuncState *fs = ls->fs;
964 check_condition(ls, fs->f->is_vararg,
965 "cannot use '...' outside a vararg function");
966 init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0));
967 break;
968 }
969 case '{': { /* constructor */
970 constructor(ls, v);
971 return;
972 }
973 case TK_FUNCTION: {
974 luaX_next(ls);
975 body(ls, v, 0, ls->linenumber);
976 return;
977 }
978 default: {
979 suffixedexp(ls, v);
980 return;
981 }
982 }
983 luaX_next(ls);
984}
@ 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, ConsControl::v, VFALSE, VKFLT, VKINT, VNIL, VTRUE, and VVARARG.

Referenced by subexpr().

◆ singlevar()

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

Definition at line 295 of file lua-5.3.6/src/lparser.c.

295 {
296 TString *varname = str_checkname(ls);
297 FuncState *fs = ls->fs;
298 singlevaraux(fs, varname, var, 1);
299 if (var->k == VVOID) { /* global name? */
300 expdesc key;
301 singlevaraux(fs, ls->envn, var, 1); /* get environment variable */
302 lua_assert(var->k != VVOID); /* this one must exist */
303 codestring(ls, &key, varname); /* key is variable name */
304 luaK_indexed(fs, var, &key); /* env[varname] */
305 }
306}
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 270 of file lua-5.3.6/src/lparser.c.

270 {
271 if (fs == NULL) /* no more levels? */
272 init_exp(var, VVOID, 0); /* default is global */
273 else {
274 int v = searchvar(fs, n); /* look up locals at current level */
275 if (v >= 0) { /* found? */
276 init_exp(var, VLOCAL, v); /* variable is local */
277 if (!base)
278 markupval(fs, v); /* local will be used as an upval */
279 }
280 else { /* not found as local at current level; try upvalues */
281 int idx = searchupvalue(fs, n); /* try existing upvalues */
282 if (idx < 0) { /* not found? */
283 singlevaraux(fs->prev, n, var, 0); /* try upper levels */
284 if (var->k == VVOID) /* not found? */
285 return; /* it is a global */
286 /* else was LOCAL or UPVAL */
287 idx = newupvalue(fs, n, var); /* will be a new upvalue */
288 }
289 init_exp(var, VUPVAL, idx); /* new or old upvalue */
290 }
291 }
292}
static int searchupvalue(FuncState *fs, TString *name)
static void markupval(FuncState *fs, int level)
static int searchvar(FuncState *fs, TString *n)

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

Referenced by singlevar(), and singlevaraux().

◆ skipnoopstat()

static void skipnoopstat ( LexState * ls)
static

Definition at line 1218 of file lua-5.3.6/src/lparser.c.

1218 {
1219 while (ls->t.token == ';' || ls->t.token == TK_DBCOLON)
1220 statement(ls);
1221}
static void statement(LexState *ls)

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

Referenced by labelstat().

◆ statement()

static void statement ( LexState * ls)
static

Definition at line 1538 of file lua-5.3.6/src/lparser.c.

1538 {
1539 int line = ls->linenumber; /* may be needed for error messages */
1540 enterlevel(ls);
1541 switch (ls->t.token) {
1542 case ';': { /* stat -> ';' (empty statement) */
1543 luaX_next(ls); /* skip ';' */
1544 break;
1545 }
1546 case TK_IF: { /* stat -> ifstat */
1547 ifstat(ls, line);
1548 break;
1549 }
1550 case TK_WHILE: { /* stat -> whilestat */
1551 whilestat(ls, line);
1552 break;
1553 }
1554 case TK_DO: { /* stat -> DO block END */
1555 luaX_next(ls); /* skip DO */
1556 block(ls);
1557 check_match(ls, TK_END, TK_DO, line);
1558 break;
1559 }
1560 case TK_FOR: { /* stat -> forstat */
1561 forstat(ls, line);
1562 break;
1563 }
1564 case TK_REPEAT: { /* stat -> repeatstat */
1565 repeatstat(ls, line);
1566 break;
1567 }
1568 case TK_FUNCTION: { /* stat -> funcstat */
1569 funcstat(ls, line);
1570 break;
1571 }
1572 case TK_LOCAL: { /* stat -> localstat */
1573 luaX_next(ls); /* skip LOCAL */
1574 if (testnext(ls, TK_FUNCTION)) /* local function? */
1575 localfunc(ls);
1576 else
1577 localstat(ls);
1578 break;
1579 }
1580 case TK_DBCOLON: { /* stat -> label */
1581 luaX_next(ls); /* skip double colon */
1582 labelstat(ls, str_checkname(ls), line);
1583 break;
1584 }
1585 case TK_RETURN: { /* stat -> retstat */
1586 luaX_next(ls); /* skip RETURN */
1587 retstat(ls);
1588 break;
1589 }
1590 case TK_BREAK: /* stat -> breakstat */
1591 case TK_GOTO: { /* stat -> 'goto' NAME */
1592 gotostat(ls, luaK_jump(ls->fs));
1593 break;
1594 }
1595 default: { /* stat -> func | assignment */
1596 exprstat(ls);
1597 break;
1598 }
1599 }
1600 lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg &&
1601 ls->fs->freereg >= ls->fs->nactvar);
1602 ls->fs->freereg = ls->fs->nactvar; /* free registers */
1603 leavelevel(ls);
1604}
@ TK_BREAK
@ TK_WHILE
@ TK_LOCAL
@ TK_RETURN
#define leavelevel(ls)
static void gotostat(LexState *ls, int pc)
static void exprstat(LexState *ls)
static void labelstat(LexState *ls, TString *label, int line)
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 ifstat(LexState *ls, int line)
static void localstat(LexState *ls)
static void whilestat(LexState *ls, int line)
static void forstat(LexState *ls, int line)
#define enterlevel(ls)

References block(), check_match(), enterlevel, exprstat(), FuncState::f, forstat(), FuncState::freereg, LexState::fs, funcstat(), gotostat(), ifstat(), labelstat(), leavelevel, LexState::linenumber, localfunc(), localstat(), lua_assert, luaK_jump(), luaX_next(), Proto::maxstacksize, FuncState::nactvar, 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 skipnoopstat(), and statlist().

◆ statlist()

static void statlist ( LexState * ls)
static

Definition at line 599 of file lua-5.3.6/src/lparser.c.

599 {
600 /* statlist -> { stat [';'] } */
601 while (!block_follow(ls, 1)) {
602 if (ls->t.token == TK_RETURN) {
603 statement(ls);
604 return; /* 'return' must be last statement */
605 }
606 statement(ls);
607 }
608}

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 135 of file lua-5.3.6/src/lparser.c.

135 {
136 TString *ts;
137 check(ls, TK_NAME);
138 ts = ls->t.seminfo.ts;
139 luaX_next(ls);
140 return ts;
141}

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

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

◆ subexpr()

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

Definition at line 1049 of file lua-5.3.6/src/lparser.c.

1049 {
1050 BinOpr op;
1051 UnOpr uop;
1052 enterlevel(ls);
1053 uop = getunopr(ls->t.token);
1054 if (uop != OPR_NOUNOPR) {
1055 int line = ls->linenumber;
1056 luaX_next(ls);
1057 subexpr(ls, v, UNARY_PRIORITY);
1058 luaK_prefix(ls->fs, uop, v, line);
1059 }
1060 else simpleexp(ls, v);
1061 /* expand while operators have priorities higher than 'limit' */
1062 op = getbinopr(ls->t.token);
1063 while (op != OPR_NOBINOPR && priority[op].left > limit) {
1064 expdesc v2;
1065 BinOpr nextop;
1066 int line = ls->linenumber;
1067 luaX_next(ls);
1068 luaK_infix(ls->fs, op, v);
1069 /* read sub-expression with higher priority */
1070 nextop = subexpr(ls, &v2, priority[op].right);
1071 luaK_posfix(ls->fs, op, v, &v2, line);
1072 op = nextop;
1073 }
1074 leavelevel(ls);
1075 return op; /* return first untreated operator */
1076}
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)
lu_byte right
lu_byte left
static void simpleexp(LexState *ls, expdesc *v)
#define UNARY_PRIORITY
static BinOpr getbinopr(int op)
static const struct @72 priority[]
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 894 of file lua-5.3.6/src/lparser.c.

894 {
895 /* suffixedexp ->
896 primaryexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs } */
897 FuncState *fs = ls->fs;
898 int line = ls->linenumber;
899 primaryexp(ls, v);
900 for (;;) {
901 switch (ls->t.token) {
902 case '.': { /* fieldsel */
903 fieldsel(ls, v);
904 break;
905 }
906 case '[': { /* '[' exp1 ']' */
907 expdesc key;
908 luaK_exp2anyregup(fs, v);
909 yindex(ls, &key);
910 luaK_indexed(fs, v, &key);
911 break;
912 }
913 case ':': { /* ':' NAME funcargs */
914 expdesc key;
915 luaX_next(ls);
916 checkname(ls, &key);
917 luaK_self(fs, v, &key);
918 funcargs(ls, v, line);
919 break;
920 }
921 case '(': case TK_STRING: case '{': { /* funcargs */
922 luaK_exp2nextreg(fs, v);
923 funcargs(ls, v, line);
924 break;
925 }
926 default: return;
927 }
928 }
929}
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 checkname(), fieldsel(), LexState::fs, funcargs(), LexState::linenumber, luaK_exp2anyregup(), luaK_exp2nextreg(), luaK_indexed(), luaK_self(), luaX_next(), primaryexp(), LexState::t, TK_STRING, Token::token, ConsControl::v, and yindex().

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

◆ test_then_block()

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

Definition at line 1383 of file lua-5.3.6/src/lparser.c.

1383 {
1384 /* test_then_block -> [IF | ELSEIF] cond THEN block */
1385 BlockCnt bl;
1386 FuncState *fs = ls->fs;
1387 expdesc v;
1388 int jf; /* instruction to skip 'then' code (if condition is false) */
1389 luaX_next(ls); /* skip IF or ELSEIF */
1390 expr(ls, &v); /* read condition */
1391 checknext(ls, TK_THEN);
1392 if (ls->t.token == TK_GOTO || ls->t.token == TK_BREAK) {
1393 luaK_goiffalse(ls->fs, &v); /* will jump to label if condition is true */
1394 enterblock(fs, &bl, 0); /* must enter block before 'goto' */
1395 gotostat(ls, v.t); /* handle goto/break */
1396 while (testnext(ls, ';')) {} /* skip colons */
1397 if (block_follow(ls, 0)) { /* 'goto' is the entire block? */
1398 leaveblock(fs);
1399 return; /* and that is it */
1400 }
1401 else /* must skip over 'then' part if condition is false */
1402 jf = luaK_jump(fs);
1403 }
1404 else { /* regular case (not goto/break) */
1405 luaK_goiftrue(ls->fs, &v); /* skip over block if condition is false */
1406 enterblock(fs, &bl, 0);
1407 jf = v.f;
1408 }
1409 statlist(ls); /* 'then' part */
1410 leaveblock(fs);
1411 if (ls->t.token == TK_ELSE ||
1412 ls->t.token == TK_ELSEIF) /* followed by 'else'/'elseif'? */
1413 luaK_concat(fs, escapelist, luaK_jump(fs)); /* must jump over it */
1414 luaK_patchtohere(fs, jf);
1415}
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, gotostat(), leaveblock(), luaK_concat(), luaK_goiffalse(), luaK_goiftrue(), luaK_jump(), luaK_patchtohere(), luaX_next(), statlist(), LexState::t, expdesc::t, testnext(), TK_BREAK, TK_ELSE, TK_ELSEIF, TK_GOTO, TK_THEN, Token::token, and LHS_assign::v.

Referenced by ifstat().

◆ testnext()

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

Definition at line 97 of file lua-5.3.6/src/lparser.c.

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

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

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

◆ undefgoto()

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

Definition at line 464 of file lua-5.3.6/src/lparser.c.

464 {
465 const char *msg = isreserved(gt->name)
466 ? "<%s> at line %d not inside a loop"
467 : "no visible label '%s' for <goto> at line %d";
468 msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line);
469 semerror(ls, msg);
470}
#define isreserved(s)

References getstr, gt, isreserved, LexState::L, luaO_pushfstring(), and semerror().

Referenced by leaveblock().

◆ whilestat()

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

Definition at line 1242 of file lua-5.3.6/src/lparser.c.

1242 {
1243 /* whilestat -> WHILE cond DO block END */
1244 FuncState *fs = ls->fs;
1245 int whileinit;
1246 int condexit;
1247 BlockCnt bl;
1248 luaX_next(ls); /* skip WHILE */
1249 whileinit = luaK_getlabel(fs);
1250 condexit = cond(ls);
1251 enterblock(fs, &bl, 1);
1252 checknext(ls, TK_DO);
1253 block(ls);
1254 luaK_jumpto(fs, whileinit);
1255 check_match(ls, TK_END, TK_WHILE, line);
1256 leaveblock(fs);
1257 luaK_patchtohere(fs, condexit); /* false conditions finish the loop */
1258}
#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 622 of file lua-5.3.6/src/lparser.c.

622 {
623 /* index -> '[' expr ']' */
624 luaX_next(ls); /* skip the '[' */
625 expr(ls, v);
626 luaK_exp2val(ls->fs, v);
627 checknext(ls, ']');
628}
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 1027 of file lua-5.3.6/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 1028 of file lua-5.3.6/src/lparser.c.

Referenced by subexpr().