Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lparser.c File Reference
#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 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   8 /* priority for unary operators */
 

Typedefs

typedef struct BlockCnt BlockCnt
 

Functions

static void statement (LexState *ls)
 
static void expr (LexState *ls, expdesc *v)
 
static void anchor_token (LexState *ls)
 
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 int 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)
 
ClosureluaY_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.2.4/src/lparser.c.

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

◆ hasmultret

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

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

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

◆ leavelevel

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

Definition at line 337 of file lua-5.2.4/src/lparser.c.

Referenced by statement(), and subexpr().

◆ lparser_c

#define lparser_c

Definition at line 10 of file lua-5.2.4/src/lparser.c.

◆ LUA_CORE

#define LUA_CORE

Definition at line 11 of file lua-5.2.4/src/lparser.c.

◆ MAXVARS

#define MAXVARS   200

Definition at line 32 of file lua-5.2.4/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 194 of file lua-5.2.4/src/lparser.c.

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

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

◆ UNARY_PRIORITY

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

Definition at line 1030 of file lua-5.2.4/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 498 of file lua-5.2.4/src/lparser.c.

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

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

205 {
206 FuncState *fs = ls->fs;
207 fs->nactvar = cast_byte(fs->nactvar + nvars);
208 for (; nvars; nvars--) {
209 getlocvar(fs, fs->nactvar - nvars)->startpc = fs->pc;
210 }
211}
#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().

◆ anchor_token()

static void anchor_token ( LexState * ls)
static

Definition at line 60 of file lua-5.2.4/src/lparser.c.

60 {
61 /* last token from outer function must be EOS */
62 lua_assert(ls->fs != NULL || ls->t.token == TK_EOS);
63 if (ls->t.token == TK_NAME || ls->t.token == TK_STRING) {
64 TString *ts = ls->t.seminfo.ts;
65 luaX_newstring(ls, getstr(ts), ts->tsv.len);
66 }
67}
TString * luaX_newstring(LexState *ls, const char *str, size_t l)
@ TK_NAME
#define lua_assert(c)
#define getstr(ts)
#define TK_STRING
Definition sqlite3.c:14057
SemInfo seminfo
TString * ts
struct TString::@46 tsv

References LexState::fs, getstr, TString::len, lua_assert, luaX_newstring(), NULL, Token::seminfo, LexState::t, TK_EOS, TK_NAME, TK_STRING, Token::token, SemInfo::ts, and TString::tsv.

Referenced by close_func().

◆ assignment()

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

Definition at line 1136 of file lua-5.2.4/src/lparser.c.

1136 {
1137 expdesc e;
1138 check_condition(ls, vkisvar(lh->v.k), "syntax error");
1139 if (testnext(ls, ',')) { /* assignment -> ',' suffixedexp assignment */
1140 struct LHS_assign nv;
1141 nv.prev = lh;
1142 suffixedexp(ls, &nv.v);
1143 if (nv.v.k != VINDEXED)
1144 check_conflict(ls, lh, &nv.v);
1145 checklimit(ls->fs, nvars + ls->L->nCcalls, LUAI_MAXCCALLS,
1146 "C levels");
1147 assignment(ls, &nv, nvars+1);
1148 }
1149 else { /* assignment -> `=' explist */
1150 int nexps;
1151 checknext(ls, '=');
1152 nexps = explist(ls, &e);
1153 if (nexps != nvars) {
1154 adjust_assign(ls, nvars, nexps, &e);
1155 if (nexps > nvars)
1156 ls->fs->freereg -= nexps - nvars; /* remove extra values */
1157 }
1158 else {
1159 luaK_setoneret(ls->fs, &e); /* close last expression */
1160 luaK_storevar(ls->fs, &lh->v, &e);
1161 return; /* avoid default */
1162 }
1163 }
1164 init_exp(&e, VNONRELOC, ls->fs->freereg-1); /* default assignment */
1165 luaK_storevar(ls->fs, &lh->v, &e);
1166}
void luaK_storevar(FuncState *fs, expdesc *var, expdesc *ex)
void luaK_setoneret(FuncState *fs, expdesc *e)
#define LUAI_MAXCCALLS
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)
#define vkisvar(k)
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 1082 of file lua-5.2.4/src/lparser.c.

1082 {
1083 /* block -> statlist */
1084 FuncState *fs = ls->fs;
1085 BlockCnt bl;
1086 enterblock(fs, &bl, 0);
1087 statlist(ls);
1088 leaveblock(fs);
1089}
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 593 of file lua-5.2.4/src/lparser.c.

593 {
594 switch (ls->t.token) {
595 case TK_ELSE: case TK_ELSEIF:
596 case TK_END: case TK_EOS:
597 return 1;
598 case TK_UNTIL: return withuntil;
599 default: return 0;
600 }
601}
@ 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 788 of file lua-5.2.4/src/lparser.c.

788 {
789 /* body -> `(' parlist `)' block END */
790 FuncState new_fs;
791 BlockCnt bl;
792 new_fs.f = addprototype(ls);
793 new_fs.f->linedefined = line;
794 open_func(ls, &new_fs, &bl);
795 checknext(ls, '(');
796 if (ismethod) {
797 new_localvarliteral(ls, "self"); /* create 'self' parameter */
798 adjustlocalvars(ls, 1);
799 }
800 parlist(ls);
801 checknext(ls, ')');
802 statlist(ls);
803 new_fs.f->lastlinedefined = ls->linenumber;
804 check_match(ls, TK_END, TK_FUNCTION, line);
805 codeclosure(ls, e);
806 close_func(ls);
807}
#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 453 of file lua-5.2.4/src/lparser.c.

453 {
454 TString *n = luaS_new(ls->L, "break");
455 int l = newlabelentry(ls, &ls->dyd->label, n, 0, ls->fs->pc);
456 findgotos(ls, &ls->dyd->label.arr[l]);
457}
#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 110 of file lua-5.2.4/src/lparser.c.

110 {
111 if (ls->t.token != c)
112 error_expected(ls, c);
113}
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 1108 of file lua-5.2.4/src/lparser.c.

1108 {
1109 FuncState *fs = ls->fs;
1110 int extra = fs->freereg; /* eventual position to save local variable */
1111 int conflict = 0;
1112 for (; lh; lh = lh->prev) { /* check all previous assignments */
1113 if (lh->v.k == VINDEXED) { /* assigning to a table? */
1114 /* table is the upvalue/local being assigned now? */
1115 if (lh->v.u.ind.vt == v->k && lh->v.u.ind.t == v->u.info) {
1116 conflict = 1;
1117 lh->v.u.ind.vt = VLOCAL;
1118 lh->v.u.ind.t = extra; /* previous assignment will use safe copy */
1119 }
1120 /* index is the local being assigned? (index cannot be upvalue) */
1121 if (v->k == VLOCAL && lh->v.u.ind.idx == v->u.info) {
1122 conflict = 1;
1123 lh->v.u.ind.idx = extra; /* previous assignment will use safe copy */
1124 }
1125 }
1126 }
1127 if (conflict) {
1128 /* copy upvalue/local value to a temporary (in position 'extra') */
1129 OpCode op = (v->k == VLOCAL) ? OP_MOVE : OP_GETUPVAL;
1130 luaK_codeABC(fs, op, extra, v->u.info, 0);
1131 luaK_reserveregs(fs, 1);
1132 }
1133}
#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 126 of file lua-5.2.4/src/lparser.c.

126 {
127 if (!testnext(ls, what)) {
128 if (where == ls->linenumber)
129 error_expected(ls, what);
130 else {
132 "%s expected (to close %s at line %d)",
133 luaX_token2str(ls, what), luaX_token2str(ls, who), where));
134 }
135 }
136}
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 96 of file lua-5.2.4/src/lparser.c.

96 {
97 if (v > l) errorlimit(fs, l, what);
98}
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 160 of file lua-5.2.4/src/lparser.c.

160 {
161 codestring(ls, e, str_checkname(ls));
162}
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 116 of file lua-5.2.4/src/lparser.c.

116 {
117 check(ls, c);
118 luaX_next(ls);
119}
#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 1195 of file lua-5.2.4/src/lparser.c.

1195 {
1196 int i;
1197 for (i = fs->bl->firstlabel; i < ll->n; i++) {
1198 if (luaS_eqstr(label, ll->arr[i].name)) {
1199 const char *msg = luaO_pushfstring(fs->ls->L,
1200 "label " LUA_QS " already defined on line %d",
1201 getstr(label), ll->arr[i].line);
1202 semerror(fs->ls, msg);
1203 }
1204 }
1205}
#define LUA_QS
static l_noret semerror(LexState *ls, const char *msg)
int luaS_eqstr(TString *a, TString *b)
struct BlockCnt * bl
struct LexState * ls

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

Referenced by labelstat().

◆ close_func()

static void close_func ( LexState * ls)
static

Definition at line 555 of file lua-5.2.4/src/lparser.c.

555 {
556 lua_State *L = ls->L;
557 FuncState *fs = ls->fs;
558 Proto *f = fs->f;
559 luaK_ret(fs, 0, 0); /* final return */
560 leaveblock(fs);
562 f->sizecode = fs->pc;
563 luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);
564 f->sizelineinfo = fs->pc;
565 luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue);
566 f->sizek = fs->nk;
567 luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *);
568 f->sizep = fs->np;
570 f->sizelocvars = fs->nlocvars;
572 f->sizeupvalues = fs->nups;
573 lua_assert(fs->bl == NULL);
574 ls->fs = fs->prev;
575 /* last token read was anchored in defunct function; must re-anchor it */
576 anchor_token(ls);
577 L->top--; /* pop table of constants */
578 luaC_checkGC(L);
579}
void luaK_ret(FuncState *fs, int first, int nret)
#define luaC_checkGC(L)
lu_int32 Instruction
#define luaM_reallocvector(L, v, oldn, n, t)
static void anchor_token(LexState *ls)
struct FuncState * prev
Instruction * code
struct LocVar * locvars
TString ** upvalues

References anchor_token(), 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, lua_State::top, and Proto::upvalues.

Referenced by body(), and mainfunc().

◆ closegoto()

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

Definition at line 340 of file lua-5.2.4/src/lparser.c.

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

References Labellist::arr, LexState::dyd, LexState::fs, getlocvar, getstr, gt, Dyndata::gt, LexState::L, lua_assert, LUA_QS, luaK_patchlist(), luaO_pushfstring(), luaS_eqstr(), 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 673 of file lua-5.2.4/src/lparser.c.

673 {
674 if (cc->v.k == VVOID) return; /* there is no list item */
675 luaK_exp2nextreg(fs, &cc->v);
676 cc->v.k = VVOID;
677 if (cc->tostore == LFIELDS_PER_FLUSH) {
678 luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore); /* flush */
679 cc->tostore = 0; /* no more items pending */
680 }
681}
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 520 of file lua-5.2.4/src/lparser.c.

520 {
521 FuncState *fs = ls->fs->prev;
522 init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np - 1));
523 luaK_exp2nextreg(fs, v); /* fix it at the last register */
524}
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 155 of file lua-5.2.4/src/lparser.c.

155 {
156 init_exp(e, VK, luaK_stringK(ls->fs, s));
157}
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 1169 of file lua-5.2.4/src/lparser.c.

1169 {
1170 /* cond -> exp */
1171 expdesc v;
1172 expr(ls, &v); /* read condition */
1173 if (v.k == VNIL) v.k = VFALSE; /* `falses' are all equal here */
1174 luaK_goiftrue(ls->fs, &v);
1175 return v.f;
1176}
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 730 of file lua-5.2.4/src/lparser.c.

730 {
731 /* constructor -> '{' [ field { sep field } [sep] ] '}'
732 sep -> ',' | ';' */
733 FuncState *fs = ls->fs;
734 int line = ls->linenumber;
735 int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0);
736 struct ConsControl cc;
737 cc.na = cc.nh = cc.tostore = 0;
738 cc.t = t;
739 init_exp(t, VRELOCABLE, pc);
740 init_exp(&cc.v, VVOID, 0); /* no value (yet) */
741 luaK_exp2nextreg(ls->fs, t); /* fix it at stack top */
742 checknext(ls, '{');
743 do {
744 lua_assert(cc.v.k == VVOID || cc.tostore > 0);
745 if (ls->t.token == '}') break;
746 closelistfield(fs, &cc);
747 field(ls, &cc);
748 } while (testnext(ls, ',') || testnext(ls, ';'));
749 check_match(ls, '}', '{', line);
750 lastlistfield(fs, &cc);
751 SETARG_B(fs->f->code[pc], luaO_int2fb(cc.na)); /* set initial array size */
752 SETARG_C(fs->f->code[pc], luaO_int2fb(cc.nh)); /* set initial table size */
753}
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 330 of file lua-5.2.4/src/lparser.c.

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

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

77 {
79 luaO_pushfstring(ls->L, "%s expected", luaX_token2str(ls, token)));
80}

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

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

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

1272 {
1273 expdesc e;
1274 int reg;
1275 expr(ls, &e);
1276 luaK_exp2nextreg(ls->fs, &e);
1277 lua_assert(e.k == VNONRELOC);
1278 reg = e.u.info;
1279 return reg;
1280}

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

810 {
811 /* explist -> expr { `,' expr } */
812 int n = 1; /* at least one expression */
813 expr(ls, v);
814 while (testnext(ls, ',')) {
815 luaK_exp2nextreg(ls->fs, v);
816 expr(ls, v);
817 n++;
818 }
819 return n;
820}

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

1067 {
1068 subexpr(ls, v, 0);
1069}
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 1480 of file lua-5.2.4/src/lparser.c.

1480 {
1481 /* stat -> func | assignment */
1482 FuncState *fs = ls->fs;
1483 struct LHS_assign v;
1484 suffixedexp(ls, &v.v);
1485 if (ls->t.token == '=' || ls->t.token == ',') { /* stat -> assignment ? */
1486 v.prev = NULL;
1487 assignment(ls, &v, 1);
1488 }
1489 else { /* stat -> func */
1490 check_condition(ls, v.v.k == VCALL, "syntax error");
1491 SETARG_C(getcode(fs, &v.v), 1); /* call statement uses no results */
1492 }
1493}
#define getcode(fs, e)

References assignment(), check_condition, LexState::fs, getcode, 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 708 of file lua-5.2.4/src/lparser.c.

708 {
709 /* field -> listfield | recfield */
710 switch(ls->t.token) {
711 case TK_NAME: { /* may be 'listfield' or 'recfield' */
712 if (luaX_lookahead(ls) != '=') /* expression? */
713 listfield(ls, cc);
714 else
715 recfield(ls, cc);
716 break;
717 }
718 case '[': {
719 recfield(ls, cc);
720 break;
721 }
722 default: {
723 listfield(ls, cc);
724 break;
725 }
726 }
727}
void luaX_lookahead(LexState *ls)
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 616 of file lua-5.2.4/src/lparser.c.

616 {
617 /* fieldsel -> ['.' | ':'] NAME */
618 FuncState *fs = ls->fs;
619 expdesc key;
620 luaK_exp2anyregup(fs, v);
621 luaX_next(ls); /* skip the dot or colon */
622 checkname(ls, &key);
623 luaK_indexed(fs, v, &key);
624}
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 402 of file lua-5.2.4/src/lparser.c.

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

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

Referenced by breaklabel(), and labelstat().

◆ findlabel()

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

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

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

References Labellist::arr, FuncState::bl, closegoto(), LexState::dyd, BlockCnt::firstlabel, LexState::fs, gt, Dyndata::gt, Dyndata::label, luaK_patchclose(), luaS_eqstr(), 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 1283 of file lua-5.2.4/src/lparser.c.

1283 {
1284 /* forbody -> DO block */
1285 BlockCnt bl;
1286 FuncState *fs = ls->fs;
1287 int prep, endfor;
1288 adjustlocalvars(ls, 3); /* control variables */
1289 checknext(ls, TK_DO);
1290 prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs);
1291 enterblock(fs, &bl, 0); /* scope for declared variables */
1292 adjustlocalvars(ls, nvars);
1293 luaK_reserveregs(fs, nvars);
1294 block(ls);
1295 leaveblock(fs); /* end of scope for declared variables */
1296 luaK_patchtohere(fs, prep);
1297 if (isnum) /* numeric for? */
1298 endfor = luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP);
1299 else { /* generic for */
1300 luaK_codeABC(fs, OP_TFORCALL, base, 0, nvars);
1301 luaK_fixline(fs, line);
1302 endfor = luaK_codeAsBx(fs, OP_TFORLOOP, base + 2, NO_JUMP);
1303 }
1304 luaK_patchlist(fs, endfor, prep + 1);
1305 luaK_fixline(fs, line);
1306}
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 1331 of file lua-5.2.4/src/lparser.c.

1331 {
1332 /* forlist -> NAME {,NAME} IN explist forbody */
1333 FuncState *fs = ls->fs;
1334 expdesc e;
1335 int nvars = 4; /* gen, state, control, plus at least one declared var */
1336 int line;
1337 int base = fs->freereg;
1338 /* create control variables */
1339 new_localvarliteral(ls, "(for generator)");
1340 new_localvarliteral(ls, "(for state)");
1341 new_localvarliteral(ls, "(for control)");
1342 /* create declared variables */
1343 new_localvar(ls, indexname);
1344 while (testnext(ls, ',')) {
1345 new_localvar(ls, str_checkname(ls));
1346 nvars++;
1347 }
1348 checknext(ls, TK_IN);
1349 line = ls->linenumber;
1350 adjust_assign(ls, 3, explist(ls, &e), &e);
1351 luaK_checkstack(fs, 3); /* extra space to call generator */
1352 forbody(ls, base, line, nvars - 3, 0);
1353}
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 1309 of file lua-5.2.4/src/lparser.c.

1309 {
1310 /* fornum -> NAME = exp1,exp1[,exp1] forbody */
1311 FuncState *fs = ls->fs;
1312 int base = fs->freereg;
1313 new_localvarliteral(ls, "(for index)");
1314 new_localvarliteral(ls, "(for limit)");
1315 new_localvarliteral(ls, "(for step)");
1316 new_localvar(ls, varname);
1317 checknext(ls, '=');
1318 exp1(ls); /* initial value */
1319 checknext(ls, ',');
1320 exp1(ls); /* limit */
1321 if (testnext(ls, ','))
1322 exp1(ls); /* optional step */
1323 else { /* default step = 1 */
1324 luaK_codek(fs, fs->freereg, luaK_numberK(fs, 1));
1325 luaK_reserveregs(fs, 1);
1326 }
1327 forbody(ls, base, line, 1, 1);
1328}
int luaK_numberK(FuncState *fs, lua_Number r)
int luaK_codek(FuncState *fs, int reg, int k)
static int exp1(LexState *ls)

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

Referenced by forstat().

◆ forstat()

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

Definition at line 1356 of file lua-5.2.4/src/lparser.c.

1356 {
1357 /* forstat -> FOR (fornum | forlist) END */
1358 FuncState *fs = ls->fs;
1359 TString *varname;
1360 BlockCnt bl;
1361 enterblock(fs, &bl, 1); /* scope for loop and control variables */
1362 luaX_next(ls); /* skip `for' */
1363 varname = str_checkname(ls); /* first variable name */
1364 switch (ls->t.token) {
1365 case '=': fornum(ls, varname, line); break;
1366 case ',': case TK_IN: forlist(ls, varname); break;
1367 default: luaX_syntaxerror(ls, LUA_QL("=") " or " LUA_QL("in") " expected");
1368 }
1369 check_match(ls, TK_END, TK_FOR, line);
1370 leaveblock(fs); /* loop scope (`break' jumps to this point) */
1371}
#define LUA_QL(x)
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(), LUA_QL, 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 823 of file lua-5.2.4/src/lparser.c.

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

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

1454 {
1455 /* funcname -> NAME {fieldsel} [`:' NAME] */
1456 int ismethod = 0;
1457 singlevar(ls, v);
1458 while (ls->t.token == '.')
1459 fieldsel(ls, v);
1460 if (ls->t.token == ':') {
1461 ismethod = 1;
1462 fieldsel(ls, v);
1463 }
1464 return ismethod;
1465}
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 1468 of file lua-5.2.4/src/lparser.c.

1468 {
1469 /* funcstat -> FUNCTION funcname body */
1470 int ismethod;
1471 expdesc v, b;
1472 luaX_next(ls); /* skip FUNCTION */
1473 ismethod = funcname(ls, &v);
1474 body(ls, &b, ismethod, line);
1475 luaK_storevar(ls->fs, &v, &b);
1476 luaK_fixline(ls->fs, line); /* definition `happens' in the first line */
1477}
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 997 of file lua-5.2.4/src/lparser.c.

997 {
998 switch (op) {
999 case '+': return OPR_ADD;
1000 case '-': return OPR_SUB;
1001 case '*': return OPR_MUL;
1002 case '/': return OPR_DIV;
1003 case '%': return OPR_MOD;
1004 case '^': return OPR_POW;
1005 case TK_CONCAT: return OPR_CONCAT;
1006 case TK_NE: return OPR_NE;
1007 case TK_EQ: return OPR_EQ;
1008 case '<': return OPR_LT;
1009 case TK_LE: return OPR_LE;
1010 case '>': return OPR_GT;
1011 case TK_GE: return OPR_GE;
1012 case TK_AND: return OPR_AND;
1013 case TK_OR: return OPR_OR;
1014 default: return OPR_NOBINOPR;
1015 }
1016}
@ OPR_NOBINOPR
@ OPR_CONCAT
#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_CONCAT, OPR_DIV, OPR_EQ, OPR_GE, OPR_GT, OPR_LE, OPR_LT, OPR_MOD, OPR_MUL, OPR_NE, OPR_NOBINOPR, OPR_OR, OPR_POW, OPR_SUB, TK_AND, TK_CONCAT, TK_EQ, TK_GE, TK_LE, TK_NE, and TK_OR.

Referenced by subexpr().

◆ getlocvar()

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

Definition at line 198 of file lua-5.2.4/src/lparser.c.

198 {
199 int idx = fs->ls->dyd->actvar.arr[fs->firstlocal + i].idx;
200 lua_assert(idx < fs->nlocvars);
201 return &fs->f->locvars[idx];
202}
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.2.4/src/lparser.c.

987 {
988 switch (op) {
989 case TK_NOT: return OPR_NOT;
990 case '-': return OPR_MINUS;
991 case '#': return OPR_LEN;
992 default: return OPR_NOUNOPR;
993 }
994}
@ OPR_MINUS
@ OPR_NOUNOPR
#define TK_NOT
Definition sqlite3.c:13961

References 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 1179 of file lua-5.2.4/src/lparser.c.

1179 {
1180 int line = ls->linenumber;
1181 TString *label;
1182 int g;
1183 if (testnext(ls, TK_GOTO))
1184 label = str_checkname(ls);
1185 else {
1186 luaX_next(ls); /* skip break */
1187 label = luaS_new(ls->L, "break");
1188 }
1189 g = newlabelentry(ls, &ls->dyd->gt, label, line, pc);
1190 findlabel(ls, g); /* close it if label already defined */
1191}
@ 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 1409 of file lua-5.2.4/src/lparser.c.

1409 {
1410 /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */
1411 FuncState *fs = ls->fs;
1412 int escapelist = NO_JUMP; /* exit list for finished parts */
1413 test_then_block(ls, &escapelist); /* IF cond THEN block */
1414 while (ls->t.token == TK_ELSEIF)
1415 test_then_block(ls, &escapelist); /* ELSEIF cond THEN block */
1416 if (testnext(ls, TK_ELSE))
1417 block(ls); /* `else' part */
1418 check_match(ls, TK_END, TK_IF, line);
1419 luaK_patchtohere(fs, escapelist); /* patch escape list to 'if' end */
1420}
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 148 of file lua-5.2.4/src/lparser.c.

148 {
149 e->f = e->t = NO_JUMP;
150 e->k = k;
151 e->u.info = i;
152}

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

1215 {
1216 /* label -> '::' NAME '::' */
1217 FuncState *fs = ls->fs;
1218 Labellist *ll = &ls->dyd->label;
1219 int l; /* index of new label being created */
1220 checkrepeated(fs, ll, label); /* check for repeated labels */
1221 checknext(ls, TK_DBCOLON); /* skip double colon */
1222 /* create new entry for this label */
1223 l = newlabelentry(ls, ll, label, line, fs->pc);
1224 skipnoopstat(ls); /* skip other no-op statements */
1225 if (block_follow(ls, 0)) { /* label is last no-op statement in the block? */
1226 /* assume that locals are already out of scope */
1227 ll->arr[l].nactvar = fs->bl->nactvar;
1228 }
1229 findgotos(ls, &ll->arr[l]);
1230}
@ 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, BlockCnt::nactvar, Labeldesc::nactvar, newlabelentry(), FuncState::pc, skipnoopstat(), and TK_DBCOLON.

Referenced by statement().

◆ lastlistfield()

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

Definition at line 684 of file lua-5.2.4/src/lparser.c.

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

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

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

699 {
700 /* listfield -> exp */
701 expr(ls, &cc->v);
702 checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor");
703 cc->na++;
704 cc->tostore++;
705}
#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 1423 of file lua-5.2.4/src/lparser.c.

1423 {
1424 expdesc b;
1425 FuncState *fs = ls->fs;
1426 new_localvar(ls, str_checkname(ls)); /* new local variable */
1427 adjustlocalvars(ls, 1); /* enter its scope */
1428 body(ls, &b, 0, ls->linenumber); /* function created in next register */
1429 /* debug information will only see the variable after this point! */
1430 getlocvar(fs, b.u.info)->startpc = fs->pc;
1431}

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

1434 {
1435 /* stat -> LOCAL NAME {`,' NAME} [`=' explist] */
1436 int nvars = 0;
1437 int nexps;
1438 expdesc e;
1439 do {
1440 new_localvar(ls, str_checkname(ls));
1441 nvars++;
1442 } while (testnext(ls, ','));
1443 if (testnext(ls, '='))
1444 nexps = explist(ls, &e);
1445 else {
1446 e.k = VVOID;
1447 nexps = 0;
1448 }
1449 adjust_assign(ls, nvars, nexps, &e);
1450 adjustlocalvars(ls, nvars);
1451}

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

Referenced by statement().

◆ luaY_parser()

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

Definition at line 1618 of file lua-5.2.4/src/lparser.c.

1619 {
1620 LexState lexstate;
1621 FuncState funcstate;
1622 Closure *cl = luaF_newLclosure(L, 1); /* create main closure */
1623 /* anchor closure (to avoid being collected) */
1624 setclLvalue(L, L->top, cl);
1625 incr_top(L);
1626 funcstate.f = cl->l.p = luaF_newproto(L);
1627 funcstate.f->source = luaS_new(L, name); /* create and anchor TString */
1628 lexstate.buff = buff;
1629 lexstate.dyd = dyd;
1630 dyd->actvar.n = dyd->gt.n = dyd->label.n = 0;
1631 luaX_setinput(L, &lexstate, z, funcstate.f->source, firstchar);
1632 mainfunc(&lexstate, &funcstate);
1633 lua_assert(!funcstate.prev && funcstate.nups == 1 && !lexstate.fs);
1634 /* all scopes should be correctly finished */
1635 lua_assert(dyd->actvar.n == 0 && dyd->gt.n == 0 && dyd->label.n == 0);
1636 return cl; /* it's on the stack too */
1637}
const char * name
Definition lsqlite3.c:2154
#define incr_top(L)
Closure * luaF_newLclosure(lua_State *L, int nelems, Table *e)
void luaX_setinput(lua_State *L, LexState *ls, ZIO *z, TString *source)
#define setclLvalue(L, obj, x)
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, incr_top, Closure::l, Dyndata::label, lua_assert, luaF_newLclosure(), luaF_newproto(), luaS_new, luaX_setinput(), mainfunc(), Labellist::n, Dyndata::n, name, FuncState::nups, LClosure::p, FuncState::prev, setclLvalue, Proto::source, and lua_State::top.

◆ mainfunc()

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

Definition at line 1604 of file lua-5.2.4/src/lparser.c.

1604 {
1605 BlockCnt bl;
1606 expdesc v;
1607 open_func(ls, fs, &bl);
1608 fs->f->is_vararg = 1; /* main function is always vararg */
1609 init_exp(&v, VLOCAL, 0); /* create and... */
1610 newupvalue(fs, ls->envn, &v); /* ...set environment upvalue */
1611 luaX_next(ls); /* read first token */
1612 statlist(ls); /* parse main body */
1613 check(ls, TK_EOS);
1614 close_func(ls);
1615}
static int newupvalue(FuncState *fs, TString *name, expdesc *v)
TString * envn

References check, close_func(), LexState::envn, FuncState::f, init_exp(), Proto::is_vararg, 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 260 of file lua-5.2.4/src/lparser.c.

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

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

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

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

178 {
179 FuncState *fs = ls->fs;
180 Dyndata *dyd = ls->dyd;
181 int reg = registerlocalvar(ls, name);
182 checklimit(fs, dyd->actvar.n + 1 - fs->firstlocal,
183 MAXVARS, "local variables");
184 luaM_growvector(ls->L, dyd->actvar.arr, dyd->actvar.n + 1,
185 dyd->actvar.size, Vardesc, MAX_INT, "local variables");
186 dyd->actvar.arr[dyd->actvar.n++].idx = cast(short, reg);
187}
#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 190 of file lua-5.2.4/src/lparser.c.

190 {
191 new_localvar(ls, luaX_newstring(ls, name, sz));
192}

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

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

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

231 {
232 Proto *f = fs->f;
233 int oldsize = f->sizeupvalues;
234 checklimit(fs, fs->nups + 1, MAXUPVAL, "upvalues");
235 luaM_growvector(fs->ls->L, f->upvalues, fs->nups, f->sizeupvalues,
236 Upvaldesc, MAXUPVAL, "upvalues");
237 while (oldsize < f->sizeupvalues) f->upvalues[oldsize++].name = NULL;
238 f->upvalues[fs->nups].instack = (v->k == VLOCAL);
239 f->upvalues[fs->nups].idx = cast_byte(v->u.info);
240 f->upvalues[fs->nups].name = name;
241 luaC_objbarrier(fs->ls->L, f, name);
242 return fs->nups++;
243}
#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 527 of file lua-5.2.4/src/lparser.c.

527 {
528 lua_State *L = ls->L;
529 Proto *f;
530 fs->prev = ls->fs; /* linked list of funcstates */
531 fs->ls = ls;
532 ls->fs = fs;
533 fs->pc = 0;
534 fs->lasttarget = 0;
535 fs->jpc = NO_JUMP;
536 fs->freereg = 0;
537 fs->nk = 0;
538 fs->np = 0;
539 fs->nups = 0;
540 fs->nlocvars = 0;
541 fs->nactvar = 0;
542 fs->firstlocal = ls->dyd->actvar.n;
543 fs->bl = NULL;
544 f = fs->f;
545 f->source = ls->source;
546 f->maxstacksize = 2; /* registers 0/1 are always valid */
547 fs->h = luaH_new(L);
548 /* anchor table of constants (to avoid being collected) */
549 sethvalue2s(L, L->top, fs->h);
550 incr_top(L);
551 enterblock(fs, bl, 0);
552}
#define sethvalue2s
Table * luaH_new(lua_State *L, int narray, int nhash)
TString * source
lu_byte maxstacksize

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

Referenced by body(), and mainfunc().

◆ parlist()

static void parlist ( LexState * ls)
static

Definition at line 759 of file lua-5.2.4/src/lparser.c.

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

References adjustlocalvars(), cast_byte, FuncState::f, LexState::fs, Proto::is_vararg, LUA_QL, 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 877 of file lua-5.2.4/src/lparser.c.

877 {
878 /* primaryexp -> NAME | '(' expr ')' */
879 switch (ls->t.token) {
880 case '(': {
881 int line = ls->linenumber;
882 luaX_next(ls);
883 expr(ls, v);
884 check_match(ls, ')', '(', line);
885 luaK_dischargevars(ls->fs, v);
886 return;
887 }
888 case TK_NAME: {
889 singlevar(ls, v);
890 return;
891 }
892 default: {
893 luaX_syntaxerror(ls, "unexpected symbol");
894 }
895 }
896}
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 652 of file lua-5.2.4/src/lparser.c.

652 {
653 /* recfield -> (NAME | `['exp1`]') = exp1 */
654 FuncState *fs = ls->fs;
655 int reg = ls->fs->freereg;
656 expdesc key, val;
657 int rkkey;
658 if (ls->t.token == TK_NAME) {
659 checklimit(fs, cc->nh, MAX_INT, "items in a constructor");
660 checkname(ls, &key);
661 }
662 else /* ls->t.token == '[' */
663 yindex(ls, &key);
664 cc->nh++;
665 checknext(ls, '=');
666 rkkey = luaK_exp2RK(fs, &key);
667 expr(ls, &val);
668 luaK_codeABC(fs, OP_SETTABLE, cc->t->u.info, rkkey, luaK_exp2RK(fs, &val));
669 fs->freereg = reg; /* free registers */
670}
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 165 of file lua-5.2.4/src/lparser.c.

165 {
166 FuncState *fs = ls->fs;
167 Proto *f = fs->f;
168 int oldsize = f->sizelocvars;
170 LocVar, SHRT_MAX, "local variables");
171 while (oldsize < f->sizelocvars) f->locvars[oldsize++].varname = NULL;
172 f->locvars[fs->nlocvars].varname = varname;
173 luaC_objbarrier(ls->L, f, varname);
174 return fs->nlocvars++;
175}
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 214 of file lua-5.2.4/src/lparser.c.

214 {
215 fs->ls->dyd->actvar.n -= (fs->nactvar - tolevel);
216 while (fs->nactvar > tolevel)
217 getlocvar(fs, --fs->nactvar)->endpc = fs->pc;
218}

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

1252 {
1253 /* repeatstat -> REPEAT block UNTIL cond */
1254 int condexit;
1255 FuncState *fs = ls->fs;
1256 int repeat_init = luaK_getlabel(fs);
1257 BlockCnt bl1, bl2;
1258 enterblock(fs, &bl1, 1); /* loop block */
1259 enterblock(fs, &bl2, 0); /* scope block */
1260 luaX_next(ls); /* skip REPEAT */
1261 statlist(ls);
1262 check_match(ls, TK_UNTIL, TK_REPEAT, line);
1263 condexit = cond(ls); /* read condition (inside scope block) */
1264 if (bl2.upval) /* upvalues? */
1265 luaK_patchclose(fs, condexit, bl2.nactvar);
1266 leaveblock(fs); /* finish scope */
1267 luaK_patchlist(fs, condexit, repeat_init); /* close the loop */
1268 leaveblock(fs); /* finish loop */
1269}
int luaK_getlabel(FuncState *fs)
@ 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 1496 of file lua-5.2.4/src/lparser.c.

1496 {
1497 /* stat -> RETURN [explist] [';'] */
1498 FuncState *fs = ls->fs;
1499 expdesc e;
1500 int first, nret; /* registers with returned values */
1501 if (block_follow(ls, 1) || ls->t.token == ';')
1502 first = nret = 0; /* return no values */
1503 else {
1504 nret = explist(ls, &e); /* optional return values */
1505 if (hasmultret(e.k)) {
1506 luaK_setmultret(fs, &e);
1507 if (e.k == VCALL && nret == 1) { /* tail call? */
1509 lua_assert(GETARG_A(getcode(fs,&e)) == fs->nactvar);
1510 }
1511 first = fs->nactvar;
1512 nret = LUA_MULTRET; /* return all values */
1513 }
1514 else {
1515 if (nret == 1) /* only one single value? */
1516 first = luaK_exp2anyreg(fs, &e);
1517 else {
1518 luaK_exp2nextreg(fs, &e); /* values must go to the `stack' */
1519 first = fs->nactvar; /* return all `active' values */
1520 lua_assert(nret == fs->freereg - first);
1521 }
1522 }
1523 }
1524 luaK_ret(fs, first, nret);
1525 testnext(ls, ';'); /* skip optional semicolon */
1526}
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, getcode, 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 221 of file lua-5.2.4/src/lparser.c.

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

References FuncState::f, luaS_eqstr(), name, FuncState::nups, and Proto::upvalues.

Referenced by singlevaraux().

◆ searchvar()

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

Definition at line 246 of file lua-5.2.4/src/lparser.c.

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

References cast_int, getlocvar, luaS_eqstr(), and FuncState::nactvar.

Referenced by singlevaraux().

◆ semerror()

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

Definition at line 71 of file lua-5.2.4/src/lparser.c.

71 {
72 ls->t.token = 0; /* remove 'near to' from final message */
73 luaX_syntaxerror(ls, msg);
74}

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

937 {
938 /* simpleexp -> NUMBER | STRING | NIL | TRUE | FALSE | ... |
939 constructor | FUNCTION body | suffixedexp */
940 switch (ls->t.token) {
941 case TK_NUMBER: {
942 init_exp(v, VKNUM, 0);
943 v->u.nval = ls->t.seminfo.r;
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 " LUA_QL("...") " 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_NUMBER
@ TK_TRUE
lua_Number nval
lua_Number r

References body(), check_condition, codestring(), constructor(), FuncState::f, LexState::fs, init_exp(), Proto::is_vararg, LexState::linenumber, LUA_QL, luaK_codeABC, luaX_next(), expdesc::nval, OP_VARARG, SemInfo::r, Token::seminfo, suffixedexp(), LexState::t, TK_DOTS, TK_FALSE, TK_FUNCTION, TK_NIL, TK_NUMBER, TK_STRING, TK_TRUE, Token::token, SemInfo::ts, expdesc::u, ConsControl::v, VFALSE, VKNUM, VNIL, VTRUE, and VVARARG.

Referenced by subexpr().

◆ singlevar()

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

Definition at line 297 of file lua-5.2.4/src/lparser.c.

297 {
298 TString *varname = str_checkname(ls);
299 FuncState *fs = ls->fs;
300 if (singlevaraux(fs, varname, var, 1) == VVOID) { /* global name? */
301 expdesc key;
302 singlevaraux(fs, ls->envn, var, 1); /* get environment variable */
303 lua_assert(var->k == VLOCAL || var->k == VUPVAL);
304 codestring(ls, &key, varname); /* key is variable name */
305 luaK_indexed(fs, var, &key); /* env[varname] */
306 }
307}
static int singlevaraux(FuncState *fs, TString *n, expdesc *var, int base)

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

Referenced by funcname(), and primaryexp().

◆ singlevaraux()

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

Definition at line 271 of file lua-5.2.4/src/lparser.c.

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

References init_exp(), 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 1209 of file lua-5.2.4/src/lparser.c.

1209 {
1210 while (ls->t.token == ';' || ls->t.token == TK_DBCOLON)
1211 statement(ls);
1212}
static void statement(LexState *ls)

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

Referenced by labelstat(), and test_then_block().

◆ statement()

static void statement ( LexState * ls)
static

Definition at line 1529 of file lua-5.2.4/src/lparser.c.

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

604 {
605 /* statlist -> { stat [`;'] } */
606 while (!block_follow(ls, 1)) {
607 if (ls->t.token == TK_RETURN) {
608 statement(ls);
609 return; /* 'return' must be last statement */
610 }
611 statement(ls);
612 }
613}

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

139 {
140 TString *ts;
141 check(ls, TK_NAME);
142 ts = ls->t.seminfo.ts;
143 luaX_next(ls);
144 return ts;
145}

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

1037 {
1038 BinOpr op;
1039 UnOpr uop;
1040 enterlevel(ls);
1041 uop = getunopr(ls->t.token);
1042 if (uop != OPR_NOUNOPR) {
1043 int line = ls->linenumber;
1044 luaX_next(ls);
1045 subexpr(ls, v, UNARY_PRIORITY);
1046 luaK_prefix(ls->fs, uop, v, line);
1047 }
1048 else simpleexp(ls, v);
1049 /* expand while operators have priorities higher than `limit' */
1050 op = getbinopr(ls->t.token);
1051 while (op != OPR_NOBINOPR && priority[op].left > limit) {
1052 expdesc v2;
1053 BinOpr nextop;
1054 int line = ls->linenumber;
1055 luaX_next(ls);
1056 luaK_infix(ls->fs, op, v);
1057 /* read sub-expression with higher priority */
1058 nextop = subexpr(ls, &v2, priority[op].right);
1059 luaK_posfix(ls->fs, op, v, &v2, line);
1060 op = nextop;
1061 }
1062 leavelevel(ls);
1063 return op; /* return first untreated operator */
1064}
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 @60 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 899 of file lua-5.2.4/src/lparser.c.

899 {
900 /* suffixedexp ->
901 primaryexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs } */
902 FuncState *fs = ls->fs;
903 int line = ls->linenumber;
904 primaryexp(ls, v);
905 for (;;) {
906 switch (ls->t.token) {
907 case '.': { /* fieldsel */
908 fieldsel(ls, v);
909 break;
910 }
911 case '[': { /* `[' exp1 `]' */
912 expdesc key;
913 luaK_exp2anyregup(fs, v);
914 yindex(ls, &key);
915 luaK_indexed(fs, v, &key);
916 break;
917 }
918 case ':': { /* `:' NAME funcargs */
919 expdesc key;
920 luaX_next(ls);
921 checkname(ls, &key);
922 luaK_self(fs, v, &key);
923 funcargs(ls, v, line);
924 break;
925 }
926 case '(': case TK_STRING: case '{': { /* funcargs */
927 luaK_exp2nextreg(fs, v);
928 funcargs(ls, v, line);
929 break;
930 }
931 default: return;
932 }
933 }
934}
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 1374 of file lua-5.2.4/src/lparser.c.

1374 {
1375 /* test_then_block -> [IF | ELSEIF] cond THEN block */
1376 BlockCnt bl;
1377 FuncState *fs = ls->fs;
1378 expdesc v;
1379 int jf; /* instruction to skip 'then' code (if condition is false) */
1380 luaX_next(ls); /* skip IF or ELSEIF */
1381 expr(ls, &v); /* read condition */
1382 checknext(ls, TK_THEN);
1383 if (ls->t.token == TK_GOTO || ls->t.token == TK_BREAK) {
1384 luaK_goiffalse(ls->fs, &v); /* will jump to label if condition is true */
1385 enterblock(fs, &bl, 0); /* must enter block before 'goto' */
1386 gotostat(ls, v.t); /* handle goto/break */
1387 skipnoopstat(ls); /* skip other no-op statements */
1388 if (block_follow(ls, 0)) { /* 'goto' is the entire block? */
1389 leaveblock(fs);
1390 return; /* and that is it */
1391 }
1392 else /* must skip over 'then' part if condition is false */
1393 jf = luaK_jump(fs);
1394 }
1395 else { /* regular case (not goto/break) */
1396 luaK_goiftrue(ls->fs, &v); /* skip over block if condition is false */
1397 enterblock(fs, &bl, 0);
1398 jf = v.f;
1399 }
1400 statlist(ls); /* `then' part */
1401 leaveblock(fs);
1402 if (ls->t.token == TK_ELSE ||
1403 ls->t.token == TK_ELSEIF) /* followed by 'else'/'elseif'? */
1404 luaK_concat(fs, escapelist, luaK_jump(fs)); /* must jump over it */
1405 luaK_patchtohere(fs, jf);
1406}
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(), skipnoopstat(), statlist(), LexState::t, expdesc::t, 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 101 of file lua-5.2.4/src/lparser.c.

101 {
102 if (ls->t.token == c) {
103 luaX_next(ls);
104 return 1;
105 }
106 else return 0;
107}

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

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

◆ undefgoto()

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

Definition at line 463 of file lua-5.2.4/src/lparser.c.

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

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

Referenced by leaveblock().

◆ whilestat()

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

Definition at line 1233 of file lua-5.2.4/src/lparser.c.

1233 {
1234 /* whilestat -> WHILE cond DO block END */
1235 FuncState *fs = ls->fs;
1236 int whileinit;
1237 int condexit;
1238 BlockCnt bl;
1239 luaX_next(ls); /* skip WHILE */
1240 whileinit = luaK_getlabel(fs);
1241 condexit = cond(ls);
1242 enterblock(fs, &bl, 1);
1243 checknext(ls, TK_DO);
1244 block(ls);
1245 luaK_jumpto(fs, whileinit);
1246 check_match(ls, TK_END, TK_WHILE, line);
1247 leaveblock(fs);
1248 luaK_patchtohere(fs, condexit); /* false conditions finish the loop */
1249}
#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 627 of file lua-5.2.4/src/lparser.c.

627 {
628 /* index -> '[' expr ']' */
629 luaX_next(ls); /* skip the '[' */
630 expr(ls, v);
631 luaK_exp2val(ls->fs, v);
632 checknext(ls, ']');
633}
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 1020 of file lua-5.2.4/src/lparser.c.

Referenced by subexpr().

◆ [struct]

const struct { ... } priority[]
Initial value:
= {
{6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7},
{10, 9}, {5, 4},
{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 1021 of file lua-5.2.4/src/lparser.c.

Referenced by subexpr().