aboutsummaryrefslogtreecommitdiff
path: root/lparser.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-07-10 14:00:22 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-07-10 14:00:22 -0300
commit3d296304ef14ac9a6d1fa9357541ddd9bb54722f (patch)
treee7c8ac1ff0a0750b5db63da68adc0bfa676d1cc3 /lparser.h
parent54f7b46c1e8a0188e1649046a3a72522f2d769f4 (diff)
downloadlua-3d296304ef14ac9a6d1fa9357541ddd9bb54722f.tar.gz
lua-3d296304ef14ac9a6d1fa9357541ddd9bb54722f.tar.bz2
lua-3d296304ef14ac9a6d1fa9357541ddd9bb54722f.zip
Towards constant propagation
This commit detaches the number of active variables from the number of variables in the stack, during compilation. Soon, compile-time constants will be propagated and therefore will not exist during run time (in the stack).
Diffstat (limited to 'lparser.h')
-rw-r--r--lparser.h12
1 files changed, 9 insertions, 3 deletions
diff --git a/lparser.h b/lparser.h
index cc2ec14d..7d43a813 100644
--- a/lparser.h
+++ b/lparser.h
@@ -83,19 +83,24 @@ typedef struct expdesc {
83 83
84/* description of an active local variable */ 84/* description of an active local variable */
85typedef struct Vardesc { 85typedef struct Vardesc {
86 TValuefields; /* constant value (if variable is 'const') */ 86 TValuefields; /* constant value (if it is a compile-time constant) */
87 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 */ 88 lu_byte sidx; /* index of the variable in the stack */
89 short pidx; /* index of the variable in the Proto's 'locvars' array */ 89 short pidx; /* index of the variable in the Proto's 'locvars' array */
90 TString *name; /* variable name */
90} Vardesc; 91} Vardesc;
91 92
92 93
94/* check whether Vardesc is in the stack (not a compile-time constant) */
95#define vdinstack(vd) (ttisnil(vd))
96
97
93/* description of pending goto statements and label statements */ 98/* description of pending goto statements and label statements */
94typedef struct Labeldesc { 99typedef struct Labeldesc {
95 TString *name; /* label identifier */ 100 TString *name; /* label identifier */
96 int pc; /* position in code */ 101 int pc; /* position in code */
97 int line; /* line where it appeared */ 102 int line; /* line where it appeared */
98 lu_byte nactvar; /* local level where it appears in current block */ 103 lu_byte nactvar; /* number of active variables in that position */
99 lu_byte close; /* goto that escapes upvalues */ 104 lu_byte close; /* goto that escapes upvalues */
100} Labeldesc; 105} Labeldesc;
101 106
@@ -138,7 +143,7 @@ typedef struct FuncState {
138 int nabslineinfo; /* number of elements in 'abslineinfo' */ 143 int nabslineinfo; /* number of elements in 'abslineinfo' */
139 int firstlocal; /* index of first local var (in Dyndata array) */ 144 int firstlocal; /* index of first local var (in Dyndata array) */
140 int firstlabel; /* index of first label (in 'dyd->label->arr') */ 145 int firstlabel; /* index of first label (in 'dyd->label->arr') */
141 short nlocvars; /* number of elements in 'f->locvars' */ 146 short ndebugvars; /* number of elements in 'f->locvars' */
142 lu_byte nactvar; /* number of active local variables */ 147 lu_byte nactvar; /* number of active local variables */
143 lu_byte nups; /* number of upvalues */ 148 lu_byte nups; /* number of upvalues */
144 lu_byte freereg; /* first free register */ 149 lu_byte freereg; /* first free register */
@@ -147,6 +152,7 @@ typedef struct FuncState {
147} FuncState; 152} FuncState;
148 153
149 154
155LUAI_FUNC int luaY_nvarstack (FuncState *fs);
150LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, 156LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
151 Dyndata *dyd, const char *name, int firstchar); 157 Dyndata *dyd, const char *name, int firstchar);
152 158