aboutsummaryrefslogtreecommitdiff
path: root/lparser.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-07-09 10:43:17 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-07-09 10:43:17 -0300
commit54f7b46c1e8a0188e1649046a3a72522f2d769f4 (patch)
tree28e973e10e2bc82de4d7d1e7a9f6673b028f7ad2 /lparser.h
parente888976bc6ba5592fb8ab8ecc04a8f63e217aa74 (diff)
downloadlua-54f7b46c1e8a0188e1649046a3a72522f2d769f4.tar.gz
lua-54f7b46c1e8a0188e1649046a3a72522f2d769f4.tar.bz2
lua-54f7b46c1e8a0188e1649046a3a72522f2d769f4.zip
New implementation for constants
VLOCAL expressions keep a reference to their corresponding 'Vardesc', and 'Upvaldesc' (for upvalues) has a field 'ro' (read-only). So, it is easier to check whether a variable is read-only. The decoupling in VLOCAL between 'vidx' ('Vardesc' index) and 'sidx' (stack index) should also help the forthcoming implementation of compile-time constant propagation.
Diffstat (limited to 'lparser.h')
-rw-r--r--lparser.h16
1 files changed, 9 insertions, 7 deletions
diff --git a/lparser.h b/lparser.h
index b708de25..cc2ec14d 100644
--- a/lparser.h
+++ b/lparser.h
@@ -33,8 +33,9 @@ typedef enum {
33 VKINT, /* integer constant; nval = numerical integer value */ 33 VKINT, /* integer constant; nval = numerical integer value */
34 VNONRELOC, /* expression has its value in a fixed register; 34 VNONRELOC, /* expression has its value in a fixed register;
35 info = result register */ 35 info = result register */
36 VLOCAL, /* local variable; var.idx = local register */ 36 VLOCAL, /* local variable; var.ridx = local register;
37 VUPVAL, /* upvalue variable; var.idx = index of upvalue in 'upvalues' */ 37 var.vidx = index in 'actvar.arr' */
38 VUPVAL, /* upvalue variable; info = index of upvalue in 'upvalues' */
38 VINDEXED, /* indexed variable; 39 VINDEXED, /* indexed variable;
39 ind.t = table register; 40 ind.t = table register;
40 ind.idx = key's R index */ 41 ind.idx = key's R index */
@@ -70,8 +71,9 @@ typedef struct expdesc {
70 short idx; /* index (R or "long" K) */ 71 short idx; /* index (R or "long" K) */
71 lu_byte t; /* table (register or upvalue) */ 72 lu_byte t; /* table (register or upvalue) */
72 } ind; 73 } ind;
73 struct { /* for local variables and upvalues */ 74 struct { /* for local variables */
74 lu_byte idx; /* index of the variable */ 75 lu_byte sidx; /* index in the stack */
76 unsigned short vidx; /* index in 'actvar.arr' */
75 } var; 77 } var;
76 } u; 78 } u;
77 int t; /* patch list of 'exit when true' */ 79 int t; /* patch list of 'exit when true' */
@@ -81,9 +83,10 @@ typedef struct expdesc {
81 83
82/* description of an active local variable */ 84/* description of an active local variable */
83typedef struct Vardesc { 85typedef struct Vardesc {
84 TValue val; /* constant value (if variable is 'const') */ 86 TValuefields; /* constant value (if variable is 'const') */
85 short idx; /* index of the variable in the Proto's 'locvars' array */
86 lu_byte ro; /* true if variable is 'const' */ 87 lu_byte ro; /* true if variable is 'const' */
88 lu_byte sidx; /* index of the variable in the stack */
89 short pidx; /* index of the variable in the Proto's 'locvars' array */
87} Vardesc; 90} Vardesc;
88 91
89 92
@@ -144,7 +147,6 @@ typedef struct FuncState {
144} FuncState; 147} FuncState;
145 148
146 149
147LUAI_FUNC Vardesc *luaY_getvardesc (FuncState **fs, const expdesc *e);
148LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, 150LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
149 Dyndata *dyd, const char *name, int firstchar); 151 Dyndata *dyd, const char *name, int firstchar);
150 152