Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
3rdparty
lua-5.4.1
src
lparser.h
Go to the documentation of this file.
1
/*
2
** $Id: lparser.h $
3
** Lua Parser
4
** See Copyright Notice in lua.h
5
*/
6
7
#ifndef lparser_h
8
#define lparser_h
9
10
#include "
llimits.h
"
11
#include "
lobject.h
"
12
#include "
lzio.h
"
13
14
15
/*
16
** Expression and variable descriptor.
17
** Code generation for variables and expressions can be delayed to allow
18
** optimizations; An 'expdesc' structure describes a potentially-delayed
19
** variable/expression. It has a description of its "main" value plus a
20
** list of conditional jumps that can also produce its value (generated
21
** by short-circuit operators 'and'/'or').
22
*/
23
24
/* kinds of variables/expressions */
25
typedef
enum
{
26
VVOID
,
/* when 'expdesc' describes the last expression a list,
27
this kind means an empty list (so, no expression) */
28
VNIL
,
/* constant nil */
29
VTRUE
,
/* constant true */
30
VFALSE
,
/* constant false */
31
VK
,
/* constant in 'k'; info = index of constant in 'k' */
32
VKFLT
,
/* floating constant; nval = numerical float value */
33
VKINT
,
/* integer constant; ival = numerical integer value */
34
VKSTR
,
/* string constant; strval = TString address;
35
(string is fixed by the lexer) */
36
VNONRELOC
,
/* expression has its value in a fixed register;
37
info = result register */
38
VLOCAL
,
/* local variable; var.sidx = stack index (local register);
39
var.vidx = relative index in 'actvar.arr' */
40
VUPVAL
,
/* upvalue variable; info = index of upvalue in 'upvalues' */
41
VCONST
,
/* compile-time constant; info = absolute index in 'actvar.arr' */
42
VINDEXED
,
/* indexed variable;
43
ind.t = table register;
44
ind.idx = key's R index */
45
VINDEXUP
,
/* indexed upvalue;
46
ind.t = table upvalue;
47
ind.idx = key's K index */
48
VINDEXI
,
/* indexed variable with constant integer;
49
ind.t = table register;
50
ind.idx = key's value */
51
VINDEXSTR
,
/* indexed variable with literal string;
52
ind.t = table register;
53
ind.idx = key's K index */
54
VJMP
,
/* expression is a test/comparison;
55
info = pc of corresponding jump instruction */
56
VRELOC
,
/* expression can put result in any register;
57
info = instruction pc */
58
VCALL
,
/* expression is a function call; info = instruction pc */
59
VVARARG
/* vararg expression; info = instruction pc */
60
}
expkind
;
61
62
63
#define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXSTR)
64
#define vkisindexed(k) (VINDEXED <= (k) && (k) <= VINDEXSTR)
65
66
67
typedef
struct
expdesc
{
68
expkind
k
;
69
union
{
70
lua_Integer
ival
;
/* for VKINT */
71
lua_Number
nval
;
/* for VKFLT */
72
TString
*
strval
;
/* for VKSTR */
73
int
info
;
/* for generic use */
74
struct
{
/* for indexed variables */
75
short
idx
;
/* index (R or "long" K) */
76
lu_byte
t
;
/* table (register or upvalue) */
77
}
ind
;
78
struct
{
/* for local variables */
79
lu_byte
sidx
;
/* index in the stack */
80
unsigned
short
vidx
;
/* compiler index (in 'actvar.arr') */
81
}
var
;
82
}
u
;
83
int
t
;
/* patch list of 'exit when true' */
84
int
f
;
/* patch list of 'exit when false' */
85
}
expdesc
;
86
87
88
/* kinds of variables */
89
#define VDKREG 0
/* regular */
90
#define RDKCONST 1
/* constant */
91
#define RDKTOCLOSE 2
/* to-be-closed */
92
#define RDKCTC 3
/* compile-time constant */
93
94
/* description of an active local variable */
95
typedef
union
Vardesc
{
96
struct
{
97
TValuefields
;
/* constant value (if it is a compile-time constant) */
98
lu_byte
kind
;
99
lu_byte
sidx
;
/* index of the variable in the stack */
100
short
pidx
;
/* index of the variable in the Proto's 'locvars' array */
101
TString
*
name
;
/* variable name */
102
} vd;
103
TValue
k
;
/* constant value (if any) */
104
}
Vardesc
;
105
106
107
108
/* description of pending goto statements and label statements */
109
typedef
struct
Labeldesc
{
110
TString
*
name
;
/* label identifier */
111
int
pc
;
/* position in code */
112
int
line
;
/* line where it appeared */
113
lu_byte
nactvar
;
/* number of active variables in that position */
114
lu_byte
close
;
/* goto that escapes upvalues */
115
}
Labeldesc
;
116
117
118
/* list of labels or gotos */
119
typedef
struct
Labellist
{
120
Labeldesc
*
arr
;
/* array */
121
int
n
;
/* number of entries in use */
122
int
size
;
/* array size */
123
}
Labellist
;
124
125
126
/* dynamic structures used by the parser */
127
typedef
struct
Dyndata
{
128
struct
{
/* list of all active local variables */
129
Vardesc
*
arr
;
130
int
n
;
131
int
size
;
132
} actvar;
133
Labellist
gt
;
/* list of pending gotos */
134
Labellist
label
;
/* list of active labels */
135
}
Dyndata
;
136
137
138
/* control of blocks */
139
struct
BlockCnt
;
/* defined in lparser.c */
140
141
142
/* state needed to generate code for a given function */
143
typedef
struct
FuncState
{
144
Proto
*
f
;
/* current function header */
145
struct
FuncState
*
prev
;
/* enclosing function */
146
struct
LexState
*
ls
;
/* lexical state */
147
struct
BlockCnt
*
bl
;
/* chain of current blocks */
148
int
pc
;
/* next position to code (equivalent to 'ncode') */
149
int
lasttarget
;
/* 'label' of last 'jump label' */
150
int
previousline
;
/* last line that was saved in 'lineinfo' */
151
int
nk
;
/* number of elements in 'k' */
152
int
np
;
/* number of elements in 'p' */
153
int
nabslineinfo
;
/* number of elements in 'abslineinfo' */
154
int
firstlocal
;
/* index of first local var (in Dyndata array) */
155
int
firstlabel
;
/* index of first label (in 'dyd->label->arr') */
156
short
ndebugvars
;
/* number of elements in 'f->locvars' */
157
lu_byte
nactvar
;
/* number of active local variables */
158
lu_byte
nups
;
/* number of upvalues */
159
lu_byte
freereg
;
/* first free register */
160
lu_byte
iwthabs
;
/* instructions issued since last absolute line info */
161
lu_byte
needclose
;
/* function needs to close upvalues when returning */
162
}
FuncState
;
163
164
165
LUAI_FUNC
int
luaY_nvarstack
(
FuncState
*fs);
166
LUAI_FUNC
LClosure
*
luaY_parser
(
lua_State
*L,
ZIO
*z,
Mbuffer
*buff,
167
Dyndata
*dyd,
const
char
*
name
,
int
firstchar);
168
169
170
#endif
FuncState::ls
struct LexState * ls
Definition:
lparser.h:146
Vardesc
Definition:
lparser.h:95
LClosure
Definition:
lobject.h:629
Labellist::n
int n
Definition:
lparser.h:121
expdesc::t
lu_byte t
Definition:
lparser.h:76
FuncState::firstlabel
int firstlabel
Definition:
lparser.h:155
VRELOC
Definition:
lparser.h:56
BlockCnt
Definition:
lparser.c:49
VINDEXSTR
Definition:
lparser.h:51
Labeldesc::pc
int pc
Definition:
lparser.h:111
Proto
Definition:
lobject.h:528
LUAI_FUNC
#define LUAI_FUNC
Definition:
luaconf.h:322
VINDEXUP
Definition:
lparser.h:45
VKFLT
Definition:
lparser.h:32
VVOID
Definition:
lparser.h:26
Dyndata
Definition:
lparser.h:127
expdesc::nval
lua_Number nval
Definition:
lparser.h:71
FuncState::pc
int pc
Definition:
lparser.h:148
VVARARG
Definition:
lparser.h:59
FuncState::nk
int nk
Definition:
lparser.h:151
Dyndata::gt
Labellist gt
Definition:
lparser.h:133
Dyndata::n
int n
Definition:
lparser.h:130
FuncState
Definition:
lparser.h:143
expdesc::vidx
unsigned short vidx
Definition:
lparser.h:80
VJMP
Definition:
lparser.h:54
FuncState::lasttarget
int lasttarget
Definition:
lparser.h:149
Labeldesc::line
int line
Definition:
lparser.h:112
Vardesc::TValuefields
TValuefields
Definition:
lparser.h:97
TValue
Definition:
lobject.h:63
Vardesc::k
TValue k
Definition:
lparser.h:103
FuncState::nups
lu_byte nups
Definition:
lparser.h:158
FuncState::firstlocal
int firstlocal
Definition:
lparser.h:154
Labeldesc
Definition:
lparser.h:109
VKINT
Definition:
lparser.h:33
expkind
expkind
Definition:
lparser.h:25
expdesc::sidx
lu_byte sidx
Definition:
lparser.h:79
expdesc::info
int info
Definition:
lparser.h:73
Labeldesc::name
TString * name
Definition:
lparser.h:110
VINDEXI
Definition:
lparser.h:48
luaY_nvarstack
LUAI_FUNC int luaY_nvarstack(FuncState *fs)
Definition:
lparser.c:243
VLOCAL
Definition:
lparser.h:38
lua_Integer
LUA_INTEGER lua_Integer
Definition:
lua.h:94
luaY_parser
LUAI_FUNC LClosure * luaY_parser(lua_State *L, ZIO *z, Mbuffer *buff, Dyndata *dyd, const char *name, int firstchar)
Definition:
lparser.c:1971
lobject.h
lu_byte
unsigned char lu_byte
Definition:
llimits.h:36
VK
Definition:
lparser.h:31
expdesc::u
union expdesc::@25 u
VCALL
Definition:
lparser.h:58
Vardesc::name
TString * name
Definition:
lparser.h:101
VCONST
Definition:
lparser.h:41
VNONRELOC
Definition:
lparser.h:36
Labellist::arr
Labeldesc * arr
Definition:
lparser.h:120
Vardesc::sidx
lu_byte sidx
Definition:
lparser.h:99
Labellist::size
int size
Definition:
lparser.h:122
Vardesc
union Vardesc Vardesc
lua_State
Definition:
lstate.h:306
Labeldesc
struct Labeldesc Labeldesc
Dyndata
struct Dyndata Dyndata
VINDEXED
Definition:
lparser.h:42
expdesc::t
int t
Definition:
lparser.h:83
lzio.h
Dyndata::arr
Vardesc * arr
Definition:
lparser.h:129
expdesc::var
struct expdesc::@25::@27 var
Dyndata::label
Labellist label
Definition:
lparser.h:134
FuncState::needclose
lu_byte needclose
Definition:
lparser.h:161
VTRUE
Definition:
lparser.h:29
Zio
Definition:
lzio.h:55
name
const char * name
Definition:
MQTTProperties.c:329
expdesc::idx
short idx
Definition:
lparser.h:75
FuncState::nactvar
lu_byte nactvar
Definition:
lparser.h:157
FuncState::freereg
lu_byte freereg
Definition:
lparser.h:159
FuncState::ndebugvars
short ndebugvars
Definition:
lparser.h:156
VNIL
Definition:
lparser.h:28
llimits.h
LexState
Definition:
llex.h:64
Labeldesc::nactvar
lu_byte nactvar
Definition:
lparser.h:113
expdesc::ind
struct expdesc::@25::@26 ind
FuncState::nabslineinfo
int nabslineinfo
Definition:
lparser.h:153
Vardesc::kind
lu_byte kind
Definition:
lparser.h:98
Labeldesc::close
lu_byte close
Definition:
lparser.h:114
Labellist
struct Labellist Labellist
FuncState::np
int np
Definition:
lparser.h:152
FuncState::f
Proto * f
Definition:
lparser.h:144
TString
Definition:
lobject.h:362
VKSTR
Definition:
lparser.h:34
expdesc::strval
TString * strval
Definition:
lparser.h:72
expdesc
Definition:
lparser.h:67
expdesc
struct expdesc expdesc
Labellist
Definition:
lparser.h:119
Mbuffer
Definition:
lzio.h:23
expdesc::f
int f
Definition:
lparser.h:84
expdesc::ival
lua_Integer ival
Definition:
lparser.h:70
Vardesc::pidx
short pidx
Definition:
lparser.h:100
FuncState
struct FuncState FuncState
FuncState::previousline
int previousline
Definition:
lparser.h:150
Dyndata::size
int size
Definition:
lparser.h:131
FuncState::bl
struct BlockCnt * bl
Definition:
lparser.h:147
lua_Number
LUA_NUMBER lua_Number
Definition:
lua.h:90
VUPVAL
Definition:
lparser.h:40
VFALSE
Definition:
lparser.h:30
FuncState::prev
struct FuncState * prev
Definition:
lparser.h:145
FuncState::iwthabs
lu_byte iwthabs
Definition:
lparser.h:160
expdesc::k
expkind k
Definition:
lparser.h:68
plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:09