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 hasmultret(k)   ((k) == VCALL || (k) == VVARARG)
 
#define getlocvar(fs, i)   ((fs)->f->locvars[(fs)->actvar[i]])
 
#define luaY_checklimit(fs, v, l, m)   if ((v)>(l)) errorlimit(fs,l,m)
 
#define check_condition(ls, c, msg)   { if (!(c)) luaX_syntaxerror(ls, msg); }
 
#define new_localvarliteral(ls, v, n)    new_localvar(ls, luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char))-1), n)
 
#define leavelevel(ls)   ((ls)->L->nCcalls--)
 
#define UNARY_PRIORITY   8 /* priority for unary operators */
 

Typedefs

typedef struct BlockCnt BlockCnt
 

Functions

static void chunk (LexState *ls)
 
static void expr (LexState *ls, expdesc *v)
 
static void anchor_token (LexState *ls)
 
static void error_expected (LexState *ls, int token)
 
static void errorlimit (FuncState *fs, int limit, 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, int n)
 
static void adjustlocalvars (LexState *ls, int nvars)
 
static void removevars (LexState *ls, int tolevel)
 
static int indexupvalue (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 enterblock (FuncState *fs, BlockCnt *bl, lu_byte isbreakable)
 
static void leaveblock (FuncState *fs)
 
static void pushclosure (LexState *ls, FuncState *func, expdesc *v)
 
static void open_func (LexState *ls, FuncState *fs)
 
static void close_func (LexState *ls)
 
ProtoluaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name)
 
static void field (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 constructor (LexState *ls, expdesc *t)
 
static void parlist (LexState *ls)
 
static void body (LexState *ls, expdesc *e, int needself, int line)
 
static int explist1 (LexState *ls, expdesc *v)
 
static void funcargs (LexState *ls, expdesc *f)
 
static void prefixexp (LexState *ls, expdesc *v)
 
static void primaryexp (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, unsigned int limit)
 
static int block_follow (int token)
 
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 breakstat (LexState *ls)
 
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 int test_then_block (LexState *ls)
 
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 int statement (LexState *ls)
 

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

Referenced by assignment(), and simpleexp().

◆ getlocvar

#define getlocvar ( fs,
i )   ((fs)->f->locvars[(fs)->actvar[i]])

◆ hasmultret

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

Definition at line 30 of file lua-5.1.5/src/lparser.c.

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

◆ leavelevel

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

Definition at line 282 of file lua-5.1.5/src/lparser.c.

Referenced by chunk(), and subexpr().

◆ lparser_c

#define lparser_c

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

◆ LUA_CORE

#define LUA_CORE

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

◆ luaY_checklimit

#define luaY_checklimit ( fs,
v,
l,
m )   if ((v)>(l)) errorlimit(fs,l,m)

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

Referenced by assignment(), indexupvalue(), listfield(), new_localvar(), and recfield().

◆ new_localvarliteral

#define new_localvarliteral ( ls,
v,
n )    new_localvar(ls, luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char))-1), n)

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

156#define new_localvarliteral(ls,v,n) \
157 new_localvar(ls, luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char))-1), n)

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

◆ UNARY_PRIORITY

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

Definition at line 821 of file lua-5.1.5/src/lparser.c.

Referenced by subexpr().

Typedef Documentation

◆ BlockCnt

typedef struct BlockCnt BlockCnt

Function Documentation

◆ adjust_assign()

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

Definition at line 256 of file lua-5.1.5/src/lparser.c.

256 {
257 FuncState *fs = ls->fs;
258 int extra = nvars - nexps;
259 if (hasmultret(e->k)) {
260 extra++; /* includes call itself */
261 if (extra < 0) extra = 0;
262 luaK_setreturns(fs, e, extra); /* last exp. provides the difference */
263 if (extra > 1) luaK_reserveregs(fs, extra-1);
264 }
265 else {
266 if (e->k != VVOID) luaK_exp2nextreg(fs, e); /* close last expression */
267 if (extra > 0) {
268 int reg = fs->freereg;
269 luaK_reserveregs(fs, extra);
270 luaK_nil(fs, reg, extra);
271 }
272 }
273}
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)
struct FuncState * fs

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

167 {
168 FuncState *fs = ls->fs;
169 fs->nactvar = cast_byte(fs->nactvar + nvars);
170 for (; nvars; nvars--) {
171 getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc;
172 }
173}
#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 57 of file lua-5.1.5/src/lparser.c.

57 {
58 if (ls->t.token == TK_NAME || ls->t.token == TK_STRING) {
59 TString *ts = ls->t.seminfo.ts;
60 luaX_newstring(ls, getstr(ts), ts->tsv.len);
61 }
62}
TString * luaX_newstring(LexState *ls, const char *str, size_t l)
@ TK_NAME
#define getstr(ts)
#define TK_STRING
Definition sqlite3.c:14057
SemInfo seminfo
TString * ts
struct TString::@46 tsv

References getstr, TString::len, luaX_newstring(), Token::seminfo, LexState::t, 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 931 of file lua-5.1.5/src/lparser.c.

931 {
932 expdesc e;
933 check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED,
934 "syntax error");
935 if (testnext(ls, ',')) { /* assignment -> `,' primaryexp assignment */
936 struct LHS_assign nv;
937 nv.prev = lh;
938 primaryexp(ls, &nv.v);
939 if (nv.v.k == VLOCAL)
940 check_conflict(ls, lh, &nv.v);
941 luaY_checklimit(ls->fs, nvars, LUAI_MAXCCALLS - ls->L->nCcalls,
942 "variables in assignment");
943 assignment(ls, &nv, nvars+1);
944 }
945 else { /* assignment -> `=' explist1 */
946 int nexps;
947 checknext(ls, '=');
948 nexps = explist1(ls, &e);
949 if (nexps != nvars) {
950 adjust_assign(ls, nvars, nexps, &e);
951 if (nexps > nvars)
952 ls->fs->freereg -= nexps - nvars; /* remove extra values */
953 }
954 else {
955 luaK_setoneret(ls->fs, &e); /* close last expression */
956 luaK_storevar(ls->fs, &lh->v, &e);
957 return; /* avoid default */
958 }
959 }
960 init_exp(&e, VNONRELOC, ls->fs->freereg-1); /* default assignment */
961 luaK_storevar(ls->fs, &lh->v, &e);
962}
void luaK_storevar(FuncState *fs, expdesc *var, expdesc *ex)
void luaK_setoneret(FuncState *fs, expdesc *e)
static void checknext(LexState *ls, int c)
static void assignment(LexState *ls, struct LHS_assign *lh, int nvars)
#define luaY_checklimit(fs, v, l, m)
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 primaryexp(LexState *ls, expdesc *v)
#define check_condition(ls, c, msg)
static int explist1(LexState *ls, expdesc *v)
#define LUAI_MAXCCALLS
struct LHS_assign * prev
struct lua_State * L
unsigned short nCcalls

References adjust_assign(), assignment(), check_condition, check_conflict(), checknext(), explist1(), FuncState::freereg, LexState::fs, init_exp(), expdesc::k, LexState::L, LUAI_MAXCCALLS, luaK_setoneret(), luaK_storevar(), luaY_checklimit, lua_State::nCcalls, LHS_assign::prev, primaryexp(), testnext(), LHS_assign::v, VINDEXED, VLOCAL, and VNONRELOC.

Referenced by assignment(), and exprstat().

◆ block()

static void block ( LexState * ls)
static

Definition at line 881 of file lua-5.1.5/src/lparser.c.

881 {
882 /* block -> chunk */
883 FuncState *fs = ls->fs;
884 BlockCnt bl;
885 enterblock(fs, &bl, 0);
886 chunk(ls);
888 leaveblock(fs);
889}
#define NO_JUMP
#define lua_assert(c)
static void enterblock(FuncState *fs, BlockCnt *bl, lu_byte isbreakable)
static void chunk(LexState *ls)
static void leaveblock(FuncState *fs)

References BlockCnt::breaklist, chunk(), enterblock(), LexState::fs, leaveblock(), lua_assert, and NO_JUMP.

Referenced by duk__trans_call_cooperate(), duk__trans_call_cooperate(), forbody(), ifstat(), luaM_free_(), luaM_growaux_(), luaM_growaux_(), luaM_growaux_(), luaM_realloc_(), luaM_saferealloc_(), luaM_shrinkvector_(), mg_get_context_info(), mg_get_system_info(), my_cooperate(), statement(), test_then_block(), tryagain(), and whilestat().

◆ block_follow()

static int block_follow ( int token)
static

Definition at line 871 of file lua-5.1.5/src/lparser.c.

871 {
872 switch (token) {
873 case TK_ELSE: case TK_ELSEIF: case TK_END:
874 case TK_UNTIL: case TK_EOS:
875 return 1;
876 default: return 0;
877 }
878}
@ TK_UNTIL
@ TK_ELSEIF
#define TK_END
Definition sqlite3.c:13953
#define TK_ELSE
Definition sqlite3.c:14099

References TK_ELSE, TK_ELSEIF, TK_END, TK_EOS, and TK_UNTIL.

Referenced by chunk(), and retstat().

◆ body()

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

Definition at line 576 of file lua-5.1.5/src/lparser.c.

576 {
577 /* body -> `(' parlist `)' chunk END */
578 FuncState new_fs;
579 open_func(ls, &new_fs);
580 new_fs.f->linedefined = line;
581 checknext(ls, '(');
582 if (needself) {
583 new_localvarliteral(ls, "self", 0);
584 adjustlocalvars(ls, 1);
585 }
586 parlist(ls);
587 checknext(ls, ')');
588 chunk(ls);
589 new_fs.f->lastlinedefined = ls->linenumber;
590 check_match(ls, TK_END, TK_FUNCTION, line);
591 close_func(ls);
592 pushclosure(ls, &new_fs, e);
593}
#define new_localvarliteral(ls, v, n)
static void pushclosure(LexState *ls, FuncState *func, expdesc *v)
static void close_func(LexState *ls)
static void adjustlocalvars(LexState *ls, int nvars)
static void open_func(LexState *ls, FuncState *fs)
static void check_match(LexState *ls, int what, int who, int where)
static void parlist(LexState *ls)
#define TK_FUNCTION
Definition sqlite3.c:14111

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

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

◆ breakstat()

static void breakstat ( LexState * ls)
static

Definition at line 975 of file lua-5.1.5/src/lparser.c.

975 {
976 FuncState *fs = ls->fs;
977 BlockCnt *bl = fs->bl;
978 int upval = 0;
979 while (bl && !bl->isbreakable) {
980 upval |= bl->upval;
981 bl = bl->previous;
982 }
983 if (!bl)
984 luaX_syntaxerror(ls, "no loop to break");
985 if (upval)
986 luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0);
987 luaK_concat(fs, &bl->breaklist, luaK_jump(fs));
988}
int luaK_jump(FuncState *fs)
void luaK_concat(FuncState *fs, int *l1, int l2)
void luaX_syntaxerror(LexState *ls, const char *msg)
#define luaK_codeABC(fs, o, a, b, c)
struct BlockCnt * previous
struct BlockCnt * bl

References FuncState::bl, BlockCnt::breaklist, LexState::fs, BlockCnt::isbreakable, luaK_codeABC, luaK_concat(), luaK_jump(), luaX_syntaxerror(), BlockCnt::nactvar, OP_CLOSE, BlockCnt::previous, and BlockCnt::upval.

Referenced by repeatstat(), and statement().

◆ check()

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

Definition at line 89 of file lua-5.1.5/src/lparser.c.

89 {
90 if (ls->t.token != c)
91 error_expected(ls, c);
92}
static void 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 908 of file lua-5.1.5/src/lparser.c.

908 {
909 FuncState *fs = ls->fs;
910 int extra = fs->freereg; /* eventual position to save local variable */
911 int conflict = 0;
912 for (; lh; lh = lh->prev) {
913 if (lh->v.k == VINDEXED) {
914 if (lh->v.u.s.info == v->u.s.info) { /* conflict? */
915 conflict = 1;
916 lh->v.u.s.info = extra; /* previous assignment will use safe copy */
917 }
918 if (lh->v.u.s.aux == v->u.s.info) { /* conflict? */
919 conflict = 1;
920 lh->v.u.s.aux = extra; /* previous assignment will use safe copy */
921 }
922 }
923 }
924 if (conflict) {
925 luaK_codeABC(fs, OP_MOVE, fs->freereg, v->u.s.info, 0); /* make copy */
926 luaK_reserveregs(fs, 1);
927 }
928}
struct expdesc::@52::@53 s
union expdesc::@52 u

References expdesc::aux, FuncState::freereg, LexState::fs, expdesc::info, expdesc::k, luaK_codeABC, luaK_reserveregs(), OP_MOVE, LHS_assign::prev, expdesc::s, expdesc::u, LHS_assign::v, and VINDEXED.

Referenced by assignment().

◆ check_match()

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

Definition at line 104 of file lua-5.1.5/src/lparser.c.

104 {
105 if (!testnext(ls, what)) {
106 if (where == ls->linenumber)
107 error_expected(ls, what);
108 else {
110 LUA_QS " expected (to close " LUA_QS " at line %d)",
111 luaX_token2str(ls, what), luaX_token2str(ls, who), where));
112 }
113 }
114}
const char * luaX_token2str(LexState *ls, int token)
const char * luaO_pushfstring(lua_State *L, const char *fmt,...)
#define LUA_QS

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

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

◆ checkname()

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

Definition at line 138 of file lua-5.1.5/src/lparser.c.

138 {
139 codestring(ls, e, str_checkname(ls));
140}
static TString * str_checkname(LexState *ls)
static void codestring(LexState *ls, expdesc *e, TString *s)

References codestring(), and str_checkname().

Referenced by field(), primaryexp(), and recfield().

◆ checknext()

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

Definition at line 94 of file lua-5.1.5/src/lparser.c.

94 {
95 check(ls, c);
96 luaX_next(ls);
97}
#define check(x)
void luaX_next(LexState *ls)

References check, and luaX_next().

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

◆ chunk()

static void chunk ( LexState * ls)
static

Definition at line 1325 of file lua-5.1.5/src/lparser.c.

1325 {
1326 /* chunk -> { stat [`;'] } */
1327 int islast = 0;
1328 enterlevel(ls);
1329 while (!islast && !block_follow(ls->t.token)) {
1330 islast = statement(ls);
1331 testnext(ls, ';');
1332 lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg &&
1333 ls->fs->freereg >= ls->fs->nactvar);
1334 ls->fs->freereg = ls->fs->nactvar; /* free registers */
1335 }
1336 leavelevel(ls);
1337}
#define leavelevel(ls)
static int statement(LexState *ls)
static int block_follow(int token)
#define enterlevel(ls)
lu_byte maxstacksize

References block_follow(), enterlevel, FuncState::f, FuncState::freereg, LexState::fs, leavelevel, lua_assert, Proto::maxstacksize, FuncState::nactvar, statement(), LexState::t, testnext(), and Token::token.

Referenced by block(), body(), luaY_parser(), mg_send_chunk(), repeatstat(), runargs(), and runargs().

◆ close_func()

static void close_func ( LexState * ls)
static

Definition at line 356 of file lua-5.1.5/src/lparser.c.

356 {
357 lua_State *L = ls->L;
358 FuncState *fs = ls->fs;
359 Proto *f = fs->f;
360 removevars(ls, 0);
361 luaK_ret(fs, 0, 0); /* final return */
363 f->sizecode = fs->pc;
364 luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);
365 f->sizelineinfo = fs->pc;
366 luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue);
367 f->sizek = fs->nk;
368 luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *);
369 f->sizep = fs->np;
371 f->sizelocvars = fs->nlocvars;
373 f->sizeupvalues = f->nups;
375 lua_assert(fs->bl == NULL);
376 ls->fs = fs->prev;
377 /* last token read was anchored in defunct function; must reanchor it */
378 if (fs) anchor_token(ls);
379 L->top -= 2; /* remove table and prototype from the stack */
380}
#define NULL
Definition gmacros.h:924
void luaK_ret(FuncState *fs, int first, int nret)
int luaG_checkcode(const Proto *pt)
lu_int32 Instruction
#define luaM_reallocvector(L, v, oldn, n, t)
static void removevars(LexState *ls, int tolevel)
static void anchor_token(LexState *ls)
struct FuncState * prev
Instruction * code
struct LocVar * locvars
struct Proto ** p
TString ** upvalues

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

Referenced by body(), luaY_parser(), mg_connect_websocket_client(), mg_connect_websocket_client_extensions(), mg_connect_websocket_client_impl(), mg_connect_websocket_client_secure(), and mg_connect_websocket_client_secure_extensions().

◆ closelistfield()

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

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

464 {
465 if (cc->v.k == VVOID) return; /* there is no list item */
466 luaK_exp2nextreg(fs, &cc->v);
467 cc->v.k = VVOID;
468 if (cc->tostore == LFIELDS_PER_FLUSH) {
469 luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore); /* flush */
470 cc->tostore = 0; /* no more items pending */
471 }
472}
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, expdesc::s, ConsControl::t, ConsControl::tostore, expdesc::u, ConsControl::v, and VVOID.

Referenced by constructor().

◆ codestring()

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

Definition at line 133 of file lua-5.1.5/src/lparser.c.

133 {
134 init_exp(e, VK, luaK_stringK(ls->fs, s));
135}
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(), and simpleexp().

◆ cond()

static int cond ( LexState * ls)
static

Definition at line 965 of file lua-5.1.5/src/lparser.c.

965 {
966 /* cond -> exp */
967 expdesc v;
968 expr(ls, &v); /* read condition */
969 if (v.k == VNIL) v.k = VFALSE; /* `falses' are all equal here */
970 luaK_goiftrue(ls->fs, &v);
971 return v.f;
972}
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 codecomp(), codecomp(), jumponcond(), jumponcond(), jumponcond(), jumponcond(), luaV_execute(), repeatstat(), test_then_block(), and whilestat().

◆ constructor()

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

Definition at line 498 of file lua-5.1.5/src/lparser.c.

498 {
499 /* constructor -> ?? */
500 FuncState *fs = ls->fs;
501 int line = ls->linenumber;
502 int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0);
503 struct ConsControl cc;
504 cc.na = cc.nh = cc.tostore = 0;
505 cc.t = t;
506 init_exp(t, VRELOCABLE, pc);
507 init_exp(&cc.v, VVOID, 0); /* no value (yet) */
508 luaK_exp2nextreg(ls->fs, t); /* fix it at stack top (for gc) */
509 checknext(ls, '{');
510 do {
511 lua_assert(cc.v.k == VVOID || cc.tostore > 0);
512 if (ls->t.token == '}') break;
513 closelistfield(fs, &cc);
514 switch(ls->t.token) {
515 case TK_NAME: { /* may be listfields or recfields */
516 luaX_lookahead(ls);
517 if (ls->lookahead.token != '=') /* expression? */
518 listfield(ls, &cc);
519 else
520 recfield(ls, &cc);
521 break;
522 }
523 case '[': { /* constructor_item -> recfield */
524 recfield(ls, &cc);
525 break;
526 }
527 default: { /* constructor_part -> listfield */
528 listfield(ls, &cc);
529 break;
530 }
531 }
532 } while (testnext(ls, ',') || testnext(ls, ';'));
533 check_match(ls, '}', '{', line);
534 lastlistfield(fs, &cc);
535 SETARG_B(fs->f->code[pc], luaO_int2fb(cc.na)); /* set initial array size */
536 SETARG_C(fs->f->code[pc], luaO_int2fb(cc.nh)); /* set initial table size */
537}
void luaX_lookahead(LexState *ls)
int luaO_int2fb(unsigned int x)
#define SETARG_C(i, b)
#define SETARG_B(i, b)
static void lastlistfield(FuncState *fs, struct ConsControl *cc)
static void closelistfield(FuncState *fs, struct ConsControl *cc)
static void listfield(LexState *ls, struct ConsControl *cc)
static void recfield(LexState *ls, struct ConsControl *cc)

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

Referenced by funcargs(), and simpleexp().

◆ enterblock()

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

Definition at line 285 of file lua-5.1.5/src/lparser.c.

285 {
286 bl->breaklist = NO_JUMP;
287 bl->isbreakable = isbreakable;
288 bl->nactvar = fs->nactvar;
289 bl->upval = 0;
290 bl->previous = fs->bl;
291 fs->bl = bl;
292 lua_assert(fs->freereg == fs->nactvar);
293}

References FuncState::bl, BlockCnt::breaklist, FuncState::freereg, BlockCnt::isbreakable, lua_assert, BlockCnt::nactvar, FuncState::nactvar, NO_JUMP, BlockCnt::previous, and BlockCnt::upval.

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

◆ enterlevel()

static void enterlevel ( LexState * ls)
static

Definition at line 276 of file lua-5.1.5/src/lparser.c.

276 {
277 if (++ls->L->nCcalls > LUAI_MAXCCALLS)
278 luaX_lexerror(ls, "chunk has too many syntax levels", 0);
279}
void luaX_lexerror(LexState *ls, const char *msg, int token)

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

◆ error_expected()

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

Definition at line 65 of file lua-5.1.5/src/lparser.c.

65 {
67 luaO_pushfstring(ls->L, LUA_QS " expected", luaX_token2str(ls, token)));
68}

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

Referenced by check(), and check_match().

◆ errorlimit()

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

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

71 {
72 const char *msg = (fs->f->linedefined == 0) ?
73 luaO_pushfstring(fs->L, "main function has more than %d %s", limit, what) :
74 luaO_pushfstring(fs->L, "function at line %d has more than %d %s",
75 fs->f->linedefined, limit, what);
76 luaX_lexerror(fs->ls, msg, 0);
77}
struct lua_State * L
struct LexState * ls

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

◆ exp1()

static int exp1 ( LexState * ls)
static

Definition at line 1036 of file lua-5.1.5/src/lparser.c.

1036 {
1037 expdesc e;
1038 int k;
1039 expr(ls, &e);
1040 k = e.k;
1041 luaK_exp2nextreg(ls->fs, &e);
1042 return k;
1043}

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

Referenced by fornum(), and lua_strx2number().

◆ explist1()

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

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

596 {
597 /* explist1 -> expr { `,' expr } */
598 int n = 1; /* at least one expression */
599 expr(ls, v);
600 while (testnext(ls, ',')) {
601 luaK_exp2nextreg(ls->fs, v);
602 expr(ls, v);
603 n++;
604 }
605 return n;
606}

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

856 {
857 subexpr(ls, v, 0);
858}
static BinOpr subexpr(LexState *ls, expdesc *v, unsigned int limit)

References subexpr().

Referenced by cond(), exp1(), explist1(), listfield(), prefixexp(), recfield(), and yindex().

◆ exprstat()

static void exprstat ( LexState * ls)
static

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

1224 {
1225 /* stat -> func | assignment */
1226 FuncState *fs = ls->fs;
1227 struct LHS_assign v;
1228 primaryexp(ls, &v.v);
1229 if (v.v.k == VCALL) /* stat -> func */
1230 SETARG_C(getcode(fs, &v.v), 1); /* call statement uses no results */
1231 else { /* stat -> assignment */
1232 v.prev = NULL;
1233 assignment(ls, &v, 1);
1234 }
1235}
#define getcode(fs, e)

References assignment(), LexState::fs, getcode, expdesc::k, NULL, primaryexp(), SETARG_C, LHS_assign::v, and VCALL.

Referenced by statement().

◆ field()

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

Definition at line 407 of file lua-5.1.5/src/lparser.c.

407 {
408 /* field -> ['.' | ':'] NAME */
409 FuncState *fs = ls->fs;
410 expdesc key;
411 luaK_exp2anyreg(fs, v);
412 luaX_next(ls); /* skip the dot or colon */
413 checkname(ls, &key);
414 luaK_indexed(fs, v, &key);
415}
int luaK_exp2anyreg(FuncState *fs, expdesc *e)
void luaK_indexed(FuncState *fs, expdesc *t, expdesc *k)
static void checkname(LexState *ls, expdesc *e)

References checkname(), LexState::fs, FuncState::ls, luaK_exp2anyreg(), luaK_indexed(), and luaX_next().

Referenced by funcname(), and primaryexp().

◆ forbody()

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

Definition at line 1046 of file lua-5.1.5/src/lparser.c.

1046 {
1047 /* forbody -> DO block */
1048 BlockCnt bl;
1049 FuncState *fs = ls->fs;
1050 int prep, endfor;
1051 adjustlocalvars(ls, 3); /* control variables */
1052 checknext(ls, TK_DO);
1053 prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs);
1054 enterblock(fs, &bl, 0); /* scope for declared variables */
1055 adjustlocalvars(ls, nvars);
1056 luaK_reserveregs(fs, nvars);
1057 block(ls);
1058 leaveblock(fs); /* end of scope for declared variables */
1059 luaK_patchtohere(fs, prep);
1060 endfor = (isnum) ? luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP) :
1061 luaK_codeABC(fs, OP_TFORLOOP, base, 0, nvars);
1062 luaK_fixline(fs, line); /* pretend that `OP_FOR' starts the loop */
1063 luaK_patchlist(fs, (isnum ? endfor : luaK_jump(fs)), prep + 1);
1064}
void luaK_patchlist(FuncState *fs, int list, int target)
void luaK_patchtohere(FuncState *fs, int list)
void luaK_fixline(FuncState *fs, int line)
#define luaK_codeAsBx(fs, o, A, sBx)
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_TFORLOOP, and TK_DO.

Referenced by forlist(), and fornum().

◆ forlist()

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

Definition at line 1089 of file lua-5.1.5/src/lparser.c.

1089 {
1090 /* forlist -> NAME {,NAME} IN explist1 forbody */
1091 FuncState *fs = ls->fs;
1092 expdesc e;
1093 int nvars = 0;
1094 int line;
1095 int base = fs->freereg;
1096 /* create control variables */
1097 new_localvarliteral(ls, "(for generator)", nvars++);
1098 new_localvarliteral(ls, "(for state)", nvars++);
1099 new_localvarliteral(ls, "(for control)", nvars++);
1100 /* create declared variables */
1101 new_localvar(ls, indexname, nvars++);
1102 while (testnext(ls, ','))
1103 new_localvar(ls, str_checkname(ls), nvars++);
1104 checknext(ls, TK_IN);
1105 line = ls->linenumber;
1106 adjust_assign(ls, 3, explist1(ls, &e), &e);
1107 luaK_checkstack(fs, 3); /* extra space to call generator */
1108 forbody(ls, base, line, nvars - 3, 0);
1109}
void luaK_checkstack(FuncState *fs, int n)
static void new_localvar(LexState *ls, TString *name, int n)
static void forbody(LexState *ls, int base, int line, int nvars, int isnum)
#define TK_IN
Definition sqlite3.c:13991

References adjust_assign(), checknext(), explist1(), 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 1067 of file lua-5.1.5/src/lparser.c.

1067 {
1068 /* fornum -> NAME = exp1,exp1[,exp1] forbody */
1069 FuncState *fs = ls->fs;
1070 int base = fs->freereg;
1071 new_localvarliteral(ls, "(for index)", 0);
1072 new_localvarliteral(ls, "(for limit)", 1);
1073 new_localvarliteral(ls, "(for step)", 2);
1074 new_localvar(ls, varname, 3);
1075 checknext(ls, '=');
1076 exp1(ls); /* initial value */
1077 checknext(ls, ',');
1078 exp1(ls); /* limit */
1079 if (testnext(ls, ','))
1080 exp1(ls); /* optional step */
1081 else { /* default step = 1 */
1082 luaK_codeABx(fs, OP_LOADK, fs->freereg, luaK_numberK(fs, 1));
1083 luaK_reserveregs(fs, 1);
1084 }
1085 forbody(ls, base, line, 1, 1);
1086}
int luaK_numberK(FuncState *fs, lua_Number r)
int luaK_codeABx(FuncState *fs, OpCode o, int a, unsigned int bc)
static int exp1(LexState *ls)

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

Referenced by forstat().

◆ forstat()

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

Definition at line 1112 of file lua-5.1.5/src/lparser.c.

1112 {
1113 /* forstat -> FOR (fornum | forlist) END */
1114 FuncState *fs = ls->fs;
1115 TString *varname;
1116 BlockCnt bl;
1117 enterblock(fs, &bl, 1); /* scope for loop and control variables */
1118 luaX_next(ls); /* skip `for' */
1119 varname = str_checkname(ls); /* first variable name */
1120 switch (ls->t.token) {
1121 case '=': fornum(ls, varname, line); break;
1122 case ',': case TK_IN: forlist(ls, varname); break;
1123 default: luaX_syntaxerror(ls, LUA_QL("=") " or " LUA_QL("in") " expected");
1124 }
1125 check_match(ls, TK_END, TK_FOR, line);
1126 leaveblock(fs); /* loop scope (`break' jumps to this point) */
1127}
static void fornum(LexState *ls, TString *varname, int line)
static void forlist(LexState *ls, TString *indexname)
#define LUA_QL(x)
#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 )
static

Definition at line 609 of file lua-5.1.5/src/lparser.c.

609 {
610 FuncState *fs = ls->fs;
611 expdesc args;
612 int base, nparams;
613 int line = ls->linenumber;
614 switch (ls->t.token) {
615 case '(': { /* funcargs -> `(' [ explist1 ] `)' */
616 if (line != ls->lastline)
617 luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)");
618 luaX_next(ls);
619 if (ls->t.token == ')') /* arg list is empty? */
620 args.k = VVOID;
621 else {
622 explist1(ls, &args);
623 luaK_setmultret(fs, &args);
624 }
625 check_match(ls, ')', '(', line);
626 break;
627 }
628 case '{': { /* funcargs -> constructor */
629 constructor(ls, &args);
630 break;
631 }
632 case TK_STRING: { /* funcargs -> STRING */
633 codestring(ls, &args, ls->t.seminfo.ts);
634 luaX_next(ls); /* must use `seminfo' before `next' */
635 break;
636 }
637 default: {
638 luaX_syntaxerror(ls, "function arguments expected");
639 return;
640 }
641 }
642 lua_assert(f->k == VNONRELOC);
643 base = f->u.s.info; /* base register for call */
644 if (hasmultret(args.k))
645 nparams = LUA_MULTRET; /* open call */
646 else {
647 if (args.k != VVOID)
648 luaK_exp2nextreg(fs, &args); /* close last argument */
649 nparams = fs->freereg - (base+1);
650 }
651 init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2));
652 luaK_fixline(fs, line);
653 fs->freereg = base+1; /* call remove function and arguments and leaves
654 (unless changed) one result */
655}
#define luaK_setmultret(fs, e)
static void constructor(LexState *ls, expdesc *t)
#define LUA_MULTRET

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

Referenced by primaryexp().

◆ funcname()

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

Definition at line 1198 of file lua-5.1.5/src/lparser.c.

1198 {
1199 /* funcname -> NAME {field} [`:' NAME] */
1200 int needself = 0;
1201 singlevar(ls, v);
1202 while (ls->t.token == '.')
1203 field(ls, v);
1204 if (ls->t.token == ':') {
1205 needself = 1;
1206 field(ls, v);
1207 }
1208 return needself;
1209}
static void singlevar(LexState *ls, expdesc *var)
static void field(LexState *ls, expdesc *v)

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

Referenced by _file_lock(), check_file(), duk__error_getter_helper(), funcstat(), loader_C(), loader_Croot(), loadfunc(), and mkfuncname().

◆ funcstat()

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

Definition at line 1212 of file lua-5.1.5/src/lparser.c.

1212 {
1213 /* funcstat -> FUNCTION funcname body */
1214 int needself;
1215 expdesc v, b;
1216 luaX_next(ls); /* skip FUNCTION */
1217 needself = funcname(ls, &v);
1218 body(ls, &b, needself, line);
1219 luaK_storevar(ls->fs, &v, &b);
1220 luaK_fixline(ls->fs, line); /* definition `happens' in the first line */
1221}
static int funcname(LexState *ls, expdesc *v)
static void body(LexState *ls, expdesc *e, int needself, 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 788 of file lua-5.1.5/src/lparser.c.

788 {
789 switch (op) {
790 case '+': return OPR_ADD;
791 case '-': return OPR_SUB;
792 case '*': return OPR_MUL;
793 case '/': return OPR_DIV;
794 case '%': return OPR_MOD;
795 case '^': return OPR_POW;
796 case TK_CONCAT: return OPR_CONCAT;
797 case TK_NE: return OPR_NE;
798 case TK_EQ: return OPR_EQ;
799 case '<': return OPR_LT;
800 case TK_LE: return OPR_LE;
801 case '>': return OPR_GT;
802 case TK_GE: return OPR_GE;
803 case TK_AND: return OPR_AND;
804 case TK_OR: return OPR_OR;
805 default: return OPR_NOBINOPR;
806 }
807}
@ 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().

◆ getunopr()

static UnOpr getunopr ( int op)
static

Definition at line 778 of file lua-5.1.5/src/lparser.c.

778 {
779 switch (op) {
780 case TK_NOT: return OPR_NOT;
781 case '-': return OPR_MINUS;
782 case '#': return OPR_LEN;
783 default: return OPR_NOUNOPR;
784 }
785}
@ 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().

◆ ifstat()

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

Definition at line 1141 of file lua-5.1.5/src/lparser.c.

1141 {
1142 /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */
1143 FuncState *fs = ls->fs;
1144 int flist;
1145 int escapelist = NO_JUMP;
1146 flist = test_then_block(ls); /* IF cond THEN block */
1147 while (ls->t.token == TK_ELSEIF) {
1148 luaK_concat(fs, &escapelist, luaK_jump(fs));
1149 luaK_patchtohere(fs, flist);
1150 flist = test_then_block(ls); /* ELSEIF cond THEN block */
1151 }
1152 if (ls->t.token == TK_ELSE) {
1153 luaK_concat(fs, &escapelist, luaK_jump(fs));
1154 luaK_patchtohere(fs, flist);
1155 luaX_next(ls); /* skip ELSE (after patch, for correct line info) */
1156 block(ls); /* `else' part */
1157 }
1158 else
1159 luaK_concat(fs, &escapelist, flist);
1160 luaK_patchtohere(fs, escapelist);
1161 check_match(ls, TK_END, TK_IF, line);
1162}
static int test_then_block(LexState *ls)
#define TK_IF
Definition sqlite3.c:13960

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

Referenced by statement().

◆ indexupvalue()

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

Definition at line 183 of file lua-5.1.5/src/lparser.c.

183 {
184 int i;
185 Proto *f = fs->f;
186 int oldsize = f->sizeupvalues;
187 for (i=0; i<f->nups; i++) {
188 if (fs->upvalues[i].k == v->k && fs->upvalues[i].info == v->u.s.info) {
189 lua_assert(f->upvalues[i] == name);
190 return i;
191 }
192 }
193 /* new one */
194 luaY_checklimit(fs, f->nups + 1, LUAI_MAXUPVALUES, "upvalues");
196 TString *, MAX_INT, "");
197 while (oldsize < f->sizeupvalues) f->upvalues[oldsize++] = NULL;
198 f->upvalues[f->nups] = name;
199 luaC_objbarrier(fs->L, f, name);
200 lua_assert(v->k == VLOCAL || v->k == VUPVAL);
201 fs->upvalues[f->nups].k = cast_byte(v->k);
202 fs->upvalues[f->nups].info = cast_byte(v->u.s.info);
203 return f->nups++;
204}
const char * name
Definition lsqlite3.c:2154
#define luaC_objbarrier(L, p, o)
#define MAX_INT
#define luaM_growvector(L, v, nelems, size, t, limit, e)
#define LUAI_MAXUPVALUES
upvaldesc upvalues[LUAI_MAXUPVALUES]

References cast_byte, FuncState::f, expdesc::info, upvaldesc::info, expdesc::k, upvaldesc::k, FuncState::L, lua_assert, luaC_objbarrier, LUAI_MAXUPVALUES, luaM_growvector, luaY_checklimit, MAX_INT, name, NULL, Proto::nups, expdesc::s, Proto::sizeupvalues, expdesc::u, Proto::upvalues, FuncState::upvalues, VLOCAL, and VUPVAL.

Referenced by singlevaraux().

◆ init_exp()

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

Definition at line 126 of file lua-5.1.5/src/lparser.c.

126 {
127 e->f = e->t = NO_JUMP;
128 e->k = k;
129 e->u.s.info = i;
130}

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

Referenced by assignment(), codestring(), constructor(), funcargs(), localfunc(), pushclosure(), simpleexp(), and singlevaraux().

◆ lastlistfield()

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

Definition at line 475 of file lua-5.1.5/src/lparser.c.

475 {
476 if (cc->tostore == 0) return;
477 if (hasmultret(cc->v.k)) {
478 luaK_setmultret(fs, &cc->v);
479 luaK_setlist(fs, cc->t->u.s.info, cc->na, LUA_MULTRET);
480 cc->na--; /* do not count last expression (unknown number of elements) */
481 }
482 else {
483 if (cc->v.k != VVOID)
484 luaK_exp2nextreg(fs, &cc->v);
485 luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore);
486 }
487}

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

Referenced by constructor().

◆ leaveblock()

static void leaveblock ( FuncState * fs)
static

Definition at line 296 of file lua-5.1.5/src/lparser.c.

296 {
297 BlockCnt *bl = fs->bl;
298 fs->bl = bl->previous;
299 removevars(fs->ls, bl->nactvar);
300 if (bl->upval)
301 luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0);
302 /* a block either controls scope or breaks (never both) */
303 lua_assert(!bl->isbreakable || !bl->upval);
304 lua_assert(bl->nactvar == fs->nactvar);
305 fs->freereg = fs->nactvar; /* free registers */
307}

References FuncState::bl, BlockCnt::breaklist, FuncState::freereg, BlockCnt::isbreakable, FuncState::ls, lua_assert, luaK_codeABC, luaK_patchtohere(), BlockCnt::nactvar, FuncState::nactvar, OP_CLOSE, BlockCnt::previous, removevars(), and BlockCnt::upval.

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

◆ listfield()

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

Definition at line 490 of file lua-5.1.5/src/lparser.c.

490 {
491 expr(ls, &cc->v);
492 luaY_checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor");
493 cc->na++;
494 cc->tostore++;
495}

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

Referenced by constructor().

◆ localfunc()

static void localfunc ( LexState * ls)
static

Definition at line 1165 of file lua-5.1.5/src/lparser.c.

1165 {
1166 expdesc v, b;
1167 FuncState *fs = ls->fs;
1168 new_localvar(ls, str_checkname(ls), 0);
1169 init_exp(&v, VLOCAL, fs->freereg);
1170 luaK_reserveregs(fs, 1);
1171 adjustlocalvars(ls, 1);
1172 body(ls, &b, 0, ls->linenumber);
1173 luaK_storevar(fs, &v, &b);
1174 /* debug information will only see the variable after this point! */
1175 getlocvar(fs, fs->nactvar - 1).startpc = fs->pc;
1176}

References adjustlocalvars(), body(), FuncState::freereg, LexState::fs, getlocvar, init_exp(), LexState::linenumber, luaK_reserveregs(), luaK_storevar(), FuncState::nactvar, new_localvar(), FuncState::pc, str_checkname(), LHS_assign::v, and VLOCAL.

Referenced by statement().

◆ localstat()

static void localstat ( LexState * ls)
static

Definition at line 1179 of file lua-5.1.5/src/lparser.c.

1179 {
1180 /* stat -> LOCAL NAME {`,' NAME} [`=' explist1] */
1181 int nvars = 0;
1182 int nexps;
1183 expdesc e;
1184 do {
1185 new_localvar(ls, str_checkname(ls), nvars++);
1186 } while (testnext(ls, ','));
1187 if (testnext(ls, '='))
1188 nexps = explist1(ls, &e);
1189 else {
1190 e.k = VVOID;
1191 nexps = 0;
1192 }
1193 adjust_assign(ls, nvars, nexps, &e);
1194 adjustlocalvars(ls, nvars);
1195}

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

Referenced by statement().

◆ luaY_parser()

Proto * luaY_parser ( lua_State * L,
ZIO * z,
Mbuffer * buff,
const char * name )

Definition at line 383 of file lua-5.1.5/src/lparser.c.

383 {
384 struct LexState lexstate;
385 struct FuncState funcstate;
386 lexstate.buff = buff;
387 luaX_setinput(L, &lexstate, z, luaS_new(L, name));
388 open_func(&lexstate, &funcstate);
389 funcstate.f->is_vararg = VARARG_ISVARARG; /* main func. is always vararg */
390 luaX_next(&lexstate); /* read first token */
391 chunk(&lexstate);
392 check(&lexstate, TK_EOS);
393 close_func(&lexstate);
394 lua_assert(funcstate.prev == NULL);
395 lua_assert(funcstate.f->nups == 0);
396 lua_assert(lexstate.fs == NULL);
397 return funcstate.f;
398}
void luaX_setinput(lua_State *L, LexState *ls, ZIO *z, TString *source)
#define VARARG_ISVARARG
#define luaS_new(L, s)

References LexState::buff, check, chunk(), close_func(), FuncState::f, LexState::fs, Proto::is_vararg, FuncState::L, lua_assert, luaS_new, luaX_next(), luaX_setinput(), name, NULL, Proto::nups, open_func(), FuncState::prev, TK_EOS, and VARARG_ISVARARG.

◆ markupval()

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

Definition at line 217 of file lua-5.1.5/src/lparser.c.

217 {
218 BlockCnt *bl = fs->bl;
219 while (bl && bl->nactvar > level) bl = bl->previous;
220 if (bl) bl->upval = 1;
221}

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

Referenced by singlevaraux().

◆ new_localvar()

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

Definition at line 160 of file lua-5.1.5/src/lparser.c.

160 {
161 FuncState *fs = ls->fs;
162 luaY_checklimit(fs, fs->nactvar+n+1, LUAI_MAXVARS, "local variables");
163 fs->actvar[fs->nactvar+n] = cast(unsigned short, registerlocalvar(ls, name));
164}
#define cast(t, exp)
static int registerlocalvar(LexState *ls, TString *varname)
#define LUAI_MAXVARS
unsigned short actvar[LUAI_MAXVARS]

References FuncState::actvar, cast, LexState::fs, LUAI_MAXVARS, luaY_checklimit, FuncState::nactvar, name, and registerlocalvar().

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

◆ open_func()

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

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

328 {
329 lua_State *L = ls->L;
330 Proto *f = luaF_newproto(L);
331 fs->f = f;
332 fs->prev = ls->fs; /* linked list of funcstates */
333 fs->ls = ls;
334 fs->L = L;
335 ls->fs = fs;
336 fs->pc = 0;
337 fs->lasttarget = -1;
338 fs->jpc = NO_JUMP;
339 fs->freereg = 0;
340 fs->nk = 0;
341 fs->np = 0;
342 fs->nlocvars = 0;
343 fs->nactvar = 0;
344 fs->bl = NULL;
345 f->source = ls->source;
346 f->maxstacksize = 2; /* registers 0/1 are always valid */
347 fs->h = luaH_new(L, 0, 0);
348 /* anchor table of constants and prototype (to avoid being collected) */
349 sethvalue2s(L, L->top, fs->h);
350 incr_top(L);
351 setptvalue2s(L, L->top, f);
352 incr_top(L);
353}
#define incr_top(L)
Proto * luaF_newproto(lua_State *L)
#define sethvalue2s
#define setptvalue2s
Table * luaH_new(lua_State *L, int narray, int nhash)
TString * source
TString * source

References FuncState::bl, FuncState::f, FuncState::freereg, LexState::fs, FuncState::h, incr_top, FuncState::jpc, LexState::L, FuncState::L, FuncState::lasttarget, FuncState::ls, luaF_newproto(), luaH_new(), Proto::maxstacksize, FuncState::nactvar, FuncState::nk, FuncState::nlocvars, NO_JUMP, FuncState::np, NULL, FuncState::pc, FuncState::prev, sethvalue2s, setptvalue2s, LexState::source, Proto::source, and lua_State::top.

Referenced by body(), and luaY_parser().

◆ parlist()

static void parlist ( LexState * ls)
static

Definition at line 543 of file lua-5.1.5/src/lparser.c.

543 {
544 /* parlist -> [ param { `,' param } ] */
545 FuncState *fs = ls->fs;
546 Proto *f = fs->f;
547 int nparams = 0;
548 f->is_vararg = 0;
549 if (ls->t.token != ')') { /* is `parlist' not empty? */
550 do {
551 switch (ls->t.token) {
552 case TK_NAME: { /* param -> NAME */
553 new_localvar(ls, str_checkname(ls), nparams++);
554 break;
555 }
556 case TK_DOTS: { /* param -> `...' */
557 luaX_next(ls);
558#if defined(LUA_COMPAT_VARARG)
559 /* use `arg' as default name */
560 new_localvarliteral(ls, "arg", nparams++);
562#endif
564 break;
565 }
566 default: luaX_syntaxerror(ls, "<name> or " LUA_QL("...") " expected");
567 }
568 } while (!f->is_vararg && testnext(ls, ','));
569 }
570 adjustlocalvars(ls, nparams);
572 luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */
573}
@ TK_DOTS
#define VARARG_HASARG
#define VARARG_NEEDSARG

References adjustlocalvars(), cast_byte, FuncState::f, LexState::fs, Proto::is_vararg, LUA_QL, luaK_reserveregs(), luaX_next(), luaX_syntaxerror(), FuncState::nactvar, new_localvar(), new_localvarliteral, Proto::numparams, str_checkname(), LexState::t, testnext(), TK_DOTS, TK_NAME, Token::token, VARARG_HASARG, VARARG_ISVARARG, and VARARG_NEEDSARG.

Referenced by body().

◆ prefixexp()

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

Definition at line 667 of file lua-5.1.5/src/lparser.c.

667 {
668 /* prefixexp -> NAME | '(' expr ')' */
669 switch (ls->t.token) {
670 case '(': {
671 int line = ls->linenumber;
672 luaX_next(ls);
673 expr(ls, v);
674 check_match(ls, ')', '(', line);
675 luaK_dischargevars(ls->fs, v);
676 return;
677 }
678 case TK_NAME: {
679 singlevar(ls, v);
680 return;
681 }
682 default: {
683 luaX_syntaxerror(ls, "unexpected symbol");
684 return;
685 }
686 }
687}
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 primaryexp().

◆ primaryexp()

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

Definition at line 690 of file lua-5.1.5/src/lparser.c.

690 {
691 /* primaryexp ->
692 prefixexp { `.' NAME | `[' exp `]' | `:' NAME funcargs | funcargs } */
693 FuncState *fs = ls->fs;
694 prefixexp(ls, v);
695 for (;;) {
696 switch (ls->t.token) {
697 case '.': { /* field */
698 field(ls, v);
699 break;
700 }
701 case '[': { /* `[' exp1 `]' */
702 expdesc key;
703 luaK_exp2anyreg(fs, v);
704 yindex(ls, &key);
705 luaK_indexed(fs, v, &key);
706 break;
707 }
708 case ':': { /* `:' NAME funcargs */
709 expdesc key;
710 luaX_next(ls);
711 checkname(ls, &key);
712 luaK_self(fs, v, &key);
713 funcargs(ls, v);
714 break;
715 }
716 case '(': case TK_STRING: case '{': { /* funcargs */
717 luaK_exp2nextreg(fs, v);
718 funcargs(ls, v);
719 break;
720 }
721 default: return;
722 }
723 }
724}
void luaK_self(FuncState *fs, expdesc *e, expdesc *key)
static void prefixexp(LexState *ls, expdesc *v)
static void funcargs(LexState *ls, expdesc *f)
static void yindex(LexState *ls, expdesc *v)

References checkname(), field(), LexState::fs, funcargs(), luaK_exp2anyreg(), luaK_exp2nextreg(), luaK_indexed(), luaK_self(), luaX_next(), prefixexp(), LexState::t, TK_STRING, Token::token, ConsControl::v, and yindex().

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

◆ pushclosure()

static void pushclosure ( LexState * ls,
FuncState * func,
expdesc * v )
static

Definition at line 310 of file lua-5.1.5/src/lparser.c.

310 {
311 FuncState *fs = ls->fs;
312 Proto *f = fs->f;
313 int oldsize = f->sizep;
314 int i;
315 luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *,
316 MAXARG_Bx, "constant table overflow");
317 while (oldsize < f->sizep) f->p[oldsize++] = NULL;
318 f->p[fs->np++] = func->f;
319 luaC_objbarrier(ls->L, f, func->f);
320 init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np-1));
321 for (i=0; i<func->f->nups; i++) {
322 OpCode o = (func->upvalues[i].k == VLOCAL) ? OP_MOVE : OP_GETUPVAL;
323 luaK_codeABC(fs, o, 0, func->upvalues[i].info, 0);
324 }
325}
#define MAXARG_Bx

References FuncState::f, LexState::fs, upvaldesc::info, init_exp(), upvaldesc::k, LexState::L, luaC_objbarrier, luaK_codeABC, luaK_codeABx(), luaM_growvector, MAXARG_Bx, FuncState::np, NULL, Proto::nups, OP_CLOSURE, OP_GETUPVAL, OP_MOVE, Proto::p, Proto::sizep, FuncState::upvalues, VLOCAL, and VRELOCABLE.

Referenced by body().

◆ recfield()

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

Definition at line 443 of file lua-5.1.5/src/lparser.c.

443 {
444 /* recfield -> (NAME | `['exp1`]') = exp1 */
445 FuncState *fs = ls->fs;
446 int reg = ls->fs->freereg;
447 expdesc key, val;
448 int rkkey;
449 if (ls->t.token == TK_NAME) {
450 luaY_checklimit(fs, cc->nh, MAX_INT, "items in a constructor");
451 checkname(ls, &key);
452 }
453 else /* ls->t.token == '[' */
454 yindex(ls, &key);
455 cc->nh++;
456 checknext(ls, '=');
457 rkkey = luaK_exp2RK(fs, &key);
458 expr(ls, &val);
459 luaK_codeABC(fs, OP_SETTABLE, cc->t->u.s.info, rkkey, luaK_exp2RK(fs, &val));
460 fs->freereg = reg; /* free registers */
461}
int luaK_exp2RK(FuncState *fs, expdesc *e)

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

Referenced by constructor().

◆ registerlocalvar()

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

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

143 {
144 FuncState *fs = ls->fs;
145 Proto *f = fs->f;
146 int oldsize = f->sizelocvars;
148 LocVar, SHRT_MAX, "too many local variables");
149 while (oldsize < f->sizelocvars) f->locvars[oldsize++].varname = NULL;
150 f->locvars[fs->nlocvars].varname = varname;
151 luaC_objbarrier(ls->L, f, varname);
152 return fs->nlocvars++;
153}
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 ( LexState * ls,
int tolevel )
static

Definition at line 176 of file lua-5.1.5/src/lparser.c.

176 {
177 FuncState *fs = ls->fs;
178 while (fs->nactvar > tolevel)
179 getlocvar(fs, --fs->nactvar).endpc = fs->pc;
180}

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

Referenced by close_func(), and leaveblock().

◆ repeatstat()

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

Definition at line 1010 of file lua-5.1.5/src/lparser.c.

1010 {
1011 /* repeatstat -> REPEAT block UNTIL cond */
1012 int condexit;
1013 FuncState *fs = ls->fs;
1014 int repeat_init = luaK_getlabel(fs);
1015 BlockCnt bl1, bl2;
1016 enterblock(fs, &bl1, 1); /* loop block */
1017 enterblock(fs, &bl2, 0); /* scope block */
1018 luaX_next(ls); /* skip REPEAT */
1019 chunk(ls);
1020 check_match(ls, TK_UNTIL, TK_REPEAT, line);
1021 condexit = cond(ls); /* read condition (inside scope block) */
1022 if (!bl2.upval) { /* no upvalues? */
1023 leaveblock(fs); /* finish scope */
1024 luaK_patchlist(ls->fs, condexit, repeat_init); /* close the loop */
1025 }
1026 else { /* complete semantics when there are upvalues */
1027 breakstat(ls); /* if condition then break */
1028 luaK_patchtohere(ls->fs, condexit); /* else... */
1029 leaveblock(fs); /* finish scope... */
1030 luaK_patchlist(ls->fs, luaK_jump(fs), repeat_init); /* and repeat */
1031 }
1032 leaveblock(fs); /* finish loop */
1033}
int luaK_getlabel(FuncState *fs)
@ TK_REPEAT
static int cond(LexState *ls)
static void breakstat(LexState *ls)

References breakstat(), check_match(), chunk(), cond(), enterblock(), LexState::fs, leaveblock(), luaK_getlabel(), luaK_jump(), luaK_patchlist(), luaK_patchtohere(), luaX_next(), TK_REPEAT, TK_UNTIL, and BlockCnt::upval.

Referenced by statement().

◆ retstat()

static void retstat ( LexState * ls)
static

Definition at line 1238 of file lua-5.1.5/src/lparser.c.

1238 {
1239 /* stat -> RETURN explist */
1240 FuncState *fs = ls->fs;
1241 expdesc e;
1242 int first, nret; /* registers with returned values */
1243 luaX_next(ls); /* skip RETURN */
1244 if (block_follow(ls->t.token) || ls->t.token == ';')
1245 first = nret = 0; /* return no values */
1246 else {
1247 nret = explist1(ls, &e); /* optional return values */
1248 if (hasmultret(e.k)) {
1249 luaK_setmultret(fs, &e);
1250 if (e.k == VCALL && nret == 1) { /* tail call? */
1252 lua_assert(GETARG_A(getcode(fs,&e)) == fs->nactvar);
1253 }
1254 first = fs->nactvar;
1255 nret = LUA_MULTRET; /* return all values */
1256 }
1257 else {
1258 if (nret == 1) /* only one single value? */
1259 first = luaK_exp2anyreg(fs, &e);
1260 else {
1261 luaK_exp2nextreg(fs, &e); /* values must go to the `stack' */
1262 first = fs->nactvar; /* return all `active' values */
1263 lua_assert(nret == fs->freereg - first);
1264 }
1265 }
1266 }
1267 luaK_ret(fs, first, nret);
1268}
#define GETARG_A(i)
#define SET_OPCODE(i, o)

References block_follow(), explist1(), FuncState::freereg, LexState::fs, GETARG_A, getcode, hasmultret, expdesc::k, lua_assert, LUA_MULTRET, luaK_exp2anyreg(), luaK_exp2nextreg(), luaK_ret(), luaK_setmultret, luaX_next(), FuncState::nactvar, OP_TAILCALL, SET_OPCODE, LexState::t, Token::token, and VCALL.

Referenced by statement().

◆ searchvar()

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

Definition at line 207 of file lua-5.1.5/src/lparser.c.

207 {
208 int i;
209 for (i=fs->nactvar-1; i >= 0; i--) {
210 if (n == getlocvar(fs, i).varname)
211 return i;
212 }
213 return -1; /* not found */
214}

References getlocvar, and FuncState::nactvar.

Referenced by singlevaraux().

◆ simpleexp()

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

Definition at line 727 of file lua-5.1.5/src/lparser.c.

727 {
728 /* simpleexp -> NUMBER | STRING | NIL | true | false | ... |
729 constructor | FUNCTION body | primaryexp */
730 switch (ls->t.token) {
731 case TK_NUMBER: {
732 init_exp(v, VKNUM, 0);
733 v->u.nval = ls->t.seminfo.r;
734 break;
735 }
736 case TK_STRING: {
737 codestring(ls, v, ls->t.seminfo.ts);
738 break;
739 }
740 case TK_NIL: {
741 init_exp(v, VNIL, 0);
742 break;
743 }
744 case TK_TRUE: {
745 init_exp(v, VTRUE, 0);
746 break;
747 }
748 case TK_FALSE: {
749 init_exp(v, VFALSE, 0);
750 break;
751 }
752 case TK_DOTS: { /* vararg */
753 FuncState *fs = ls->fs;
754 check_condition(ls, fs->f->is_vararg,
755 "cannot use " LUA_QL("...") " outside a vararg function");
756 fs->f->is_vararg &= ~VARARG_NEEDSARG; /* don't need 'arg' */
757 init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0));
758 break;
759 }
760 case '{': { /* constructor */
761 constructor(ls, v);
762 return;
763 }
764 case TK_FUNCTION: {
765 luaX_next(ls);
766 body(ls, v, 0, ls->linenumber);
767 return;
768 }
769 default: {
770 primaryexp(ls, v);
771 return;
772 }
773 }
774 luaX_next(ls);
775}
@ 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, primaryexp(), SemInfo::r, Token::seminfo, 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 248 of file lua-5.1.5/src/lparser.c.

248 {
249 TString *varname = str_checkname(ls);
250 FuncState *fs = ls->fs;
251 if (singlevaraux(fs, varname, var, 1) == VGLOBAL)
252 var->u.s.info = luaK_stringK(fs, varname); /* info points to global name */
253}
static int singlevaraux(FuncState *fs, TString *n, expdesc *var, int base)

References LexState::fs, expdesc::info, luaK_stringK(), expdesc::s, singlevaraux(), str_checkname(), expdesc::u, and VGLOBAL.

Referenced by funcname(), and prefixexp().

◆ singlevaraux()

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

Definition at line 224 of file lua-5.1.5/src/lparser.c.

224 {
225 if (fs == NULL) { /* no more levels? */
226 init_exp(var, VGLOBAL, NO_REG); /* default is global variable */
227 return VGLOBAL;
228 }
229 else {
230 int v = searchvar(fs, n); /* look up at current level */
231 if (v >= 0) {
232 init_exp(var, VLOCAL, v);
233 if (!base)
234 markupval(fs, v); /* local will be used as an upval */
235 return VLOCAL;
236 }
237 else { /* not found at current level; try upper one */
238 if (singlevaraux(fs->prev, n, var, 0) == VGLOBAL)
239 return VGLOBAL;
240 var->u.s.info = indexupvalue(fs, n, var); /* else was LOCAL or UPVAL */
241 var->k = VUPVAL; /* upvalue in this level */
242 return VUPVAL;
243 }
244 }
245}
#define NO_REG
static int indexupvalue(FuncState *fs, TString *name, expdesc *v)
static void markupval(FuncState *fs, int level)
static int searchvar(FuncState *fs, TString *n)

References indexupvalue(), expdesc::info, init_exp(), expdesc::k, markupval(), NO_REG, NULL, FuncState::prev, expdesc::s, searchvar(), singlevaraux(), expdesc::u, VGLOBAL, VLOCAL, and VUPVAL.

Referenced by singlevar(), and singlevaraux().

◆ statement()

static int statement ( LexState * ls)
static

Definition at line 1271 of file lua-5.1.5/src/lparser.c.

1271 {
1272 int line = ls->linenumber; /* may be needed for error messages */
1273 switch (ls->t.token) {
1274 case TK_IF: { /* stat -> ifstat */
1275 ifstat(ls, line);
1276 return 0;
1277 }
1278 case TK_WHILE: { /* stat -> whilestat */
1279 whilestat(ls, line);
1280 return 0;
1281 }
1282 case TK_DO: { /* stat -> DO block END */
1283 luaX_next(ls); /* skip DO */
1284 block(ls);
1285 check_match(ls, TK_END, TK_DO, line);
1286 return 0;
1287 }
1288 case TK_FOR: { /* stat -> forstat */
1289 forstat(ls, line);
1290 return 0;
1291 }
1292 case TK_REPEAT: { /* stat -> repeatstat */
1293 repeatstat(ls, line);
1294 return 0;
1295 }
1296 case TK_FUNCTION: {
1297 funcstat(ls, line); /* stat -> funcstat */
1298 return 0;
1299 }
1300 case TK_LOCAL: { /* stat -> localstat */
1301 luaX_next(ls); /* skip LOCAL */
1302 if (testnext(ls, TK_FUNCTION)) /* local function? */
1303 localfunc(ls);
1304 else
1305 localstat(ls);
1306 return 0;
1307 }
1308 case TK_RETURN: { /* stat -> retstat */
1309 retstat(ls);
1310 return 1; /* must be last statement */
1311 }
1312 case TK_BREAK: { /* stat -> breakstat */
1313 luaX_next(ls); /* skip BREAK */
1314 breakstat(ls);
1315 return 1; /* must be last statement */
1316 }
1317 default: {
1318 exprstat(ls);
1319 return 0; /* to avoid warnings */
1320 }
1321 }
1322}
@ TK_BREAK
@ TK_WHILE
@ TK_LOCAL
@ TK_RETURN
static void exprstat(LexState *ls)
static void retstat(LexState *ls)
static void funcstat(LexState *ls, int line)
static void repeatstat(LexState *ls, int line)
static void localfunc(LexState *ls)
static void ifstat(LexState *ls, int line)
static void localstat(LexState *ls)
static void whilestat(LexState *ls, int line)
static void forstat(LexState *ls, int line)

References block(), breakstat(), check_match(), exprstat(), forstat(), funcstat(), ifstat(), LexState::linenumber, localfunc(), localstat(), luaX_next(), repeatstat(), retstat(), LexState::t, testnext(), TK_BREAK, TK_DO, TK_END, TK_FOR, TK_FUNCTION, TK_IF, TK_LOCAL, TK_REPEAT, TK_RETURN, TK_WHILE, Token::token, and whilestat().

Referenced by chunk().

◆ str_checkname()

static TString * str_checkname ( LexState * ls)
static

Definition at line 117 of file lua-5.1.5/src/lparser.c.

117 {
118 TString *ts;
119 check(ls, TK_NAME);
120 ts = ls->t.seminfo.ts;
121 luaX_next(ls);
122 return ts;
123}

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

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

◆ subexpr()

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

Definition at line 828 of file lua-5.1.5/src/lparser.c.

828 {
829 BinOpr op;
830 UnOpr uop;
831 enterlevel(ls);
832 uop = getunopr(ls->t.token);
833 if (uop != OPR_NOUNOPR) {
834 luaX_next(ls);
835 subexpr(ls, v, UNARY_PRIORITY);
836 luaK_prefix(ls->fs, uop, v);
837 }
838 else simpleexp(ls, v);
839 /* expand while operators have priorities higher than `limit' */
840 op = getbinopr(ls->t.token);
841 while (op != OPR_NOBINOPR && priority[op].left > limit) {
842 expdesc v2;
843 BinOpr nextop;
844 luaX_next(ls);
845 luaK_infix(ls->fs, op, v);
846 /* read sub-expression with higher priority */
847 nextop = subexpr(ls, &v2, priority[op].right);
848 luaK_posfix(ls->fs, op, v, &v2);
849 op = nextop;
850 }
851 leavelevel(ls);
852 return op; /* return first untreated operator */
853}
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 const struct @51 priority[]
static BinOpr getbinopr(int op)
static UnOpr getunopr(int op)

References enterlevel, LexState::fs, getbinopr(), getunopr(), leavelevel, left, 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().

◆ test_then_block()

static int test_then_block ( LexState * ls)
static

Definition at line 1130 of file lua-5.1.5/src/lparser.c.

1130 {
1131 /* test_then_block -> [IF | ELSEIF] cond THEN block */
1132 int condexit;
1133 luaX_next(ls); /* skip IF or ELSEIF */
1134 condexit = cond(ls);
1135 checknext(ls, TK_THEN);
1136 block(ls); /* `then' part */
1137 return condexit;
1138}
#define TK_THEN
Definition sqlite3.c:14098

References block(), checknext(), cond(), luaX_next(), and TK_THEN.

Referenced by ifstat().

◆ testnext()

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

Definition at line 80 of file lua-5.1.5/src/lparser.c.

80 {
81 if (ls->t.token == c) {
82 luaX_next(ls);
83 return 1;
84 }
85 else return 0;
86}

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

Referenced by assignment(), check_match(), chunk(), constructor(), explist1(), forlist(), fornum(), localstat(), parlist(), and statement().

◆ whilestat()

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

Definition at line 991 of file lua-5.1.5/src/lparser.c.

991 {
992 /* whilestat -> WHILE cond DO block END */
993 FuncState *fs = ls->fs;
994 int whileinit;
995 int condexit;
996 BlockCnt bl;
997 luaX_next(ls); /* skip WHILE */
998 whileinit = luaK_getlabel(fs);
999 condexit = cond(ls);
1000 enterblock(fs, &bl, 1);
1001 checknext(ls, TK_DO);
1002 block(ls);
1003 luaK_patchlist(fs, luaK_jump(fs), whileinit);
1004 check_match(ls, TK_END, TK_WHILE, line);
1005 leaveblock(fs);
1006 luaK_patchtohere(fs, condexit); /* false conditions finish the loop */
1007}

References block(), check_match(), checknext(), cond(), enterblock(), LexState::fs, leaveblock(), luaK_getlabel(), luaK_jump(), luaK_patchlist(), 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 418 of file lua-5.1.5/src/lparser.c.

418 {
419 /* index -> '[' expr ']' */
420 luaX_next(ls); /* skip the '[' */
421 expr(ls, v);
422 luaK_exp2val(ls->fs, v);
423 checknext(ls, ']');
424}
void luaK_exp2val(FuncState *fs, expdesc *e)

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

Referenced by primaryexp(), and recfield().

Variable Documentation

◆ left

◆ [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 doctest::registerReporter(), and subexpr().

◆ right