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 of 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.ridx = register index;
39  var.vidx = relative index in 'actvar.arr' */
40  VUPVAL, /* upvalue variable; info = index of upvalue in 'upvalues' */
41  VCONST, /* compile-time <const> variable;
42  info = absolute index in 'actvar.arr' */
43  VINDEXED, /* indexed variable;
44  ind.t = table register;
45  ind.idx = key's R index */
46  VINDEXUP, /* indexed upvalue;
47  ind.t = table upvalue;
48  ind.idx = key's K index */
49  VINDEXI, /* indexed variable with constant integer;
50  ind.t = table register;
51  ind.idx = key's value */
52  VINDEXSTR, /* indexed variable with literal string;
53  ind.t = table register;
54  ind.idx = key's K index */
55  VJMP, /* expression is a test/comparison;
56  info = pc of corresponding jump instruction */
57  VRELOC, /* expression can put result in any register;
58  info = instruction pc */
59  VCALL, /* expression is a function call; info = instruction pc */
60  VVARARG /* vararg expression; info = instruction pc */
61 } expkind;
62 
63 
64 #define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXSTR)
65 #define vkisindexed(k) (VINDEXED <= (k) && (k) <= VINDEXSTR)
66 
67 
68 typedef struct expdesc {
70  union {
71  lua_Integer ival; /* for VKINT */
72  lua_Number nval; /* for VKFLT */
73  TString *strval; /* for VKSTR */
74  int info; /* for generic use */
75  struct { /* for indexed variables */
76  short idx; /* index (R or "long" K) */
77  lu_byte t; /* table (register or upvalue) */
78  } ind;
79  struct { /* for local variables */
80  lu_byte ridx; /* register holding the variable */
81  unsigned short vidx; /* compiler index (in 'actvar.arr') */
82  } var;
83  } u;
84  int t; /* patch list of 'exit when true' */
85  int f; /* patch list of 'exit when false' */
86 } expdesc;
87 
88 
89 /* kinds of variables */
90 #define VDKREG 0 /* regular */
91 #define RDKCONST 1 /* constant */
92 #define RDKTOCLOSE 2 /* to-be-closed */
93 #define RDKCTC 3 /* compile-time constant */
94 
95 /* description of an active local variable */
96 typedef union Vardesc {
97  struct {
98  TValuefields; /* constant value (if it is a compile-time constant) */
100  lu_byte ridx; /* register holding the variable */
101  short pidx; /* index of the variable in the Proto's 'locvars' array */
102  TString *name; /* variable name */
103  } vd;
104  TValue k; /* constant value (if any) */
105 } Vardesc;
106 
107 
108 
109 /* description of pending goto statements and label statements */
110 typedef struct Labeldesc {
111  TString *name; /* label identifier */
112  int pc; /* position in code */
113  int line; /* line where it appeared */
114  lu_byte nactvar; /* number of active variables in that position */
115  lu_byte close; /* goto that escapes upvalues */
116 } Labeldesc;
117 
118 
119 /* list of labels or gotos */
120 typedef struct Labellist {
121  Labeldesc *arr; /* array */
122  int n; /* number of entries in use */
123  int size; /* array size */
124 } Labellist;
125 
126 
127 /* dynamic structures used by the parser */
128 typedef struct Dyndata {
129  struct { /* list of all active local variables */
131  int n;
132  int size;
133  } actvar;
134  Labellist gt; /* list of pending gotos */
135  Labellist label; /* list of active labels */
136 } Dyndata;
137 
138 
139 /* control of blocks */
140 struct BlockCnt; /* defined in lparser.c */
141 
142 
143 /* state needed to generate code for a given function */
144 typedef struct FuncState {
145  Proto *f; /* current function header */
146  struct FuncState *prev; /* enclosing function */
147  struct LexState *ls; /* lexical state */
148  struct BlockCnt *bl; /* chain of current blocks */
149  int pc; /* next position to code (equivalent to 'ncode') */
150  int lasttarget; /* 'label' of last 'jump label' */
151  int previousline; /* last line that was saved in 'lineinfo' */
152  int nk; /* number of elements in 'k' */
153  int np; /* number of elements in 'p' */
154  int nabslineinfo; /* number of elements in 'abslineinfo' */
155  int firstlocal; /* index of first local var (in Dyndata array) */
156  int firstlabel; /* index of first label (in 'dyd->label->arr') */
157  short ndebugvars; /* number of elements in 'f->locvars' */
158  lu_byte nactvar; /* number of active local variables */
159  lu_byte nups; /* number of upvalues */
160  lu_byte freereg; /* first free register */
161  lu_byte iwthabs; /* instructions issued since last absolute line info */
162  lu_byte needclose; /* function needs to close upvalues when returning */
163 } FuncState;
164 
165 
168  Dyndata *dyd, const char *name, int firstchar);
169 
170 
171 #endif
VLOCAL
@ VLOCAL
Definition: lparser.h:38
VJMP
@ VJMP
Definition: lparser.h:55
expdesc::info
int info
Definition: lparser.h:74
LClosure
Definition: lobject.h:641
VCONST
@ VCONST
Definition: lparser.h:41
LUAI_FUNC
#define LUAI_FUNC
Definition: luaconf.h:312
FuncState::ndebugvars
short ndebugvars
Definition: lparser.h:157
Labellist::arr
Labeldesc * arr
Definition: lparser.h:121
TString
Definition: lobject.h:373
VUPVAL
@ VUPVAL
Definition: lparser.h:40
Labeldesc::close
lu_byte close
Definition: lparser.h:115
expdesc::idx
short idx
Definition: lparser.h:76
FuncState::needclose
lu_byte needclose
Definition: lparser.h:162
Labellist::size
int size
Definition: lparser.h:123
FuncState::freereg
lu_byte freereg
Definition: lparser.h:160
VNONRELOC
@ VNONRELOC
Definition: lparser.h:36
FuncState::nabslineinfo
int nabslineinfo
Definition: lparser.h:154
Dyndata::size
int size
Definition: lparser.h:132
Vardesc
Definition: lparser.h:96
FuncState::nactvar
lu_byte nactvar
Definition: lparser.h:158
expdesc::var
struct expdesc::@7::@9 var
FuncState::np
int np
Definition: lparser.h:153
expdesc::ridx
lu_byte ridx
Definition: lparser.h:80
FuncState::f
Proto * f
Definition: lparser.h:145
expdesc::strval
TString * strval
Definition: lparser.h:73
Labeldesc
Definition: lparser.h:110
lua_Number
LUA_NUMBER lua_Number
Definition: lua.h:90
llimits.h
Dyndata
struct Dyndata Dyndata
Vardesc::vd
struct Vardesc::@10 vd
VKFLT
@ VKFLT
Definition: lparser.h:32
VINDEXED
@ VINDEXED
Definition: lparser.h:43
luaY_nvarstack
LUAI_FUNC int luaY_nvarstack(FuncState *fs)
Definition: lparser.c:243
Labeldesc::nactvar
lu_byte nactvar
Definition: lparser.h:114
FuncState
Definition: lparser.h:144
mqtt_test_proto.z
z
Definition: mqtt_test_proto.py:36
Dyndata::label
Labellist label
Definition: lparser.h:135
Dyndata::gt
Labellist gt
Definition: lparser.h:134
VNIL
@ VNIL
Definition: lparser.h:28
Dyndata::n
int n
Definition: lparser.h:131
Mbuffer
Definition: lzio.h:23
expdesc::ind
struct expdesc::@7::@8 ind
expdesc::f
int f
Definition: lparser.h:85
expkind
expkind
Definition: lparser.h:25
FuncState::bl
struct BlockCnt * bl
Definition: lparser.h:148
FuncState::ls
struct LexState * ls
Definition: lparser.h:147
FuncState::prev
struct FuncState * prev
Definition: lparser.h:146
VTRUE
@ VTRUE
Definition: lparser.h:29
expdesc::vidx
unsigned short vidx
Definition: lparser.h:81
Vardesc::ridx
lu_byte ridx
Definition: lparser.h:100
Vardesc::pidx
short pidx
Definition: lparser.h:101
VINDEXUP
@ VINDEXUP
Definition: lparser.h:46
lu_byte
unsigned char lu_byte
Definition: llimits.h:36
VK
@ VK
Definition: lparser.h:31
luaY_parser
LUAI_FUNC LClosure * luaY_parser(lua_State *L, ZIO *z, Mbuffer *buff, Dyndata *dyd, const char *name, int firstchar)
Definition: lparser.c:1931
lua_State
Definition: lstate.h:304
FuncState::previousline
int previousline
Definition: lparser.h:151
VFALSE
@ VFALSE
Definition: lparser.h:30
expdesc::k
expkind k
Definition: lparser.h:69
FuncState::iwthabs
lu_byte iwthabs
Definition: lparser.h:161
VINDEXSTR
@ VINDEXSTR
Definition: lparser.h:52
FuncState::nk
int nk
Definition: lparser.h:152
Proto
Definition: lobject.h:539
VRELOC
@ VRELOC
Definition: lparser.h:57
expdesc::ival
lua_Integer ival
Definition: lparser.h:71
VKSTR
@ VKSTR
Definition: lparser.h:34
lobject.h
FuncState::lasttarget
int lasttarget
Definition: lparser.h:150
FuncState::firstlabel
int firstlabel
Definition: lparser.h:156
lua_Integer
LUA_INTEGER lua_Integer
Definition: lua.h:94
Labellist
struct Labellist Labellist
Vardesc::k
TValue k
Definition: lparser.h:104
Vardesc::name
TString * name
Definition: lparser.h:102
Labeldesc::line
int line
Definition: lparser.h:113
VVOID
@ VVOID
Definition: lparser.h:26
expdesc
Definition: lparser.h:68
Labeldesc::pc
int pc
Definition: lparser.h:112
Dyndata::arr
Vardesc * arr
Definition: lparser.h:130
FuncState::pc
int pc
Definition: lparser.h:149
Labeldesc
struct Labeldesc Labeldesc
FuncState
struct FuncState FuncState
LexState
Definition: llex.h:64
VKINT
@ VKINT
Definition: lparser.h:33
expdesc
struct expdesc expdesc
VCALL
@ VCALL
Definition: lparser.h:59
Vardesc::kind
lu_byte kind
Definition: lparser.h:99
VVARARG
@ VVARARG
Definition: lparser.h:60
Labellist::n
int n
Definition: lparser.h:122
FuncState::firstlocal
int firstlocal
Definition: lparser.h:155
VINDEXI
@ VINDEXI
Definition: lparser.h:49
FuncState::nups
lu_byte nups
Definition: lparser.h:159
expdesc::nval
lua_Number nval
Definition: lparser.h:72
expdesc::u
union expdesc::@7 u
Zio
Definition: lzio.h:55
lzio.h
Dyndata
Definition: lparser.h:128
Vardesc
union Vardesc Vardesc
expdesc::t
lu_byte t
Definition: lparser.h:77
expdesc::t
int t
Definition: lparser.h:84
Labellist
Definition: lparser.h:120
BlockCnt
Definition: lparser.c:49
Vardesc::TValuefields
TValuefields
Definition: lparser.h:98
TValue
Definition: lobject.h:65
Labeldesc::name
TString * name
Definition: lparser.h:111
Dyndata::actvar
struct Dyndata::@11 actvar


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:45