aboutsummaryrefslogtreecommitdiff
path: root/lparser.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-06-21 10:16:57 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-06-21 10:16:57 -0300
commite4b02ca8e48b499c57dd3e5882d18145db60fd4c (patch)
treee04e28b662e455a74d87b05f78b2d73eb0627873 /lparser.c
parent20a9853e0279903d255846108ffe320826dddcca (diff)
downloadlua-e4b02ca8e48b499c57dd3e5882d18145db60fd4c.tar.gz
lua-e4b02ca8e48b499c57dd3e5882d18145db60fd4c.tar.bz2
lua-e4b02ca8e48b499c57dd3e5882d18145db60fd4c.zip
Structure 'Vardesc' does not need a 'name' field
Removed the field 'name' from the structure 'Vardesc', as the name of the local variable is already available in the prototype of the function, through the index 'idx'.
Diffstat (limited to 'lparser.c')
-rw-r--r--lparser.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/lparser.c b/lparser.c
index 045efd93..3c68f2d7 100644
--- a/lparser.c
+++ b/lparser.c
@@ -205,7 +205,6 @@ static Vardesc *new_localvar (LexState *ls, TString *name) {
205 dyd->actvar.size, Vardesc, MAX_INT, "local variables"); 205 dyd->actvar.size, Vardesc, MAX_INT, "local variables");
206 var = &dyd->actvar.arr[dyd->actvar.n++]; 206 var = &dyd->actvar.arr[dyd->actvar.n++];
207 var->idx = cast(short, reg); 207 var->idx = cast(short, reg);
208 var->name = name;
209 var->ro = 0; 208 var->ro = 0;
210 return var; 209 return var;
211} 210}
@@ -235,25 +234,25 @@ static LocVar *getlocvar (FuncState *fs, int i) {
235 234
236/* 235/*
237** Return the "variable description" (Vardesc) of a given 236** Return the "variable description" (Vardesc) of a given
238** variable or upvalue 237** local variable and update 'fs' to point to the function
238** where that variable was defined. Return NULL if expression
239** is neither a local variable nor an upvalue.
239*/ 240*/
240static Vardesc *getvardesc (FuncState *fs, expdesc *e) { 241static Vardesc *getvardesc (FuncState **fs, expdesc *e) {
241 if (e->k == VLOCAL) 242 if (e->k == VLOCAL)
242 return getlocalvardesc(fs, e->u.var.idx); 243 return getlocalvardesc(*fs, e->u.var.idx);
243 else if (e->k != VUPVAL) 244 else if (e->k != VUPVAL)
244 return NULL; /* not a local variable */ 245 return NULL; /* not a local variable */
245 else { /* upvalue: must go up all levels up to the original local */ 246 else { /* upvalue: must go up all levels up to the original local */
246 int idx = e->u.var.idx; 247 int idx = e->u.var.idx;
247 for (;;) { 248 for (;;) {
248 Upvaldesc *up = &fs->f->upvalues[idx]; 249 Upvaldesc *up = &(*fs)->f->upvalues[idx];
249 fs = fs->prev; /* must look at the previous level */ 250 *fs = (*fs)->prev; /* must look at the previous level */
250 idx = up->idx; /* at this index */ 251 idx = up->idx; /* at this index */
251 if (fs == NULL) { /* no more levels? (can happen only with _ENV) */ 252 if (*fs == NULL) /* no more levels? (can happen only with _ENV) */
252 lua_assert(strcmp(getstr(up->name), LUA_ENV) == 0);
253 return NULL; 253 return NULL;
254 }
255 else if (up->instack) /* got to the original level? */ 254 else if (up->instack) /* got to the original level? */
256 return getlocalvardesc(fs, idx); 255 return getlocalvardesc(*fs, idx);
257 /* else repeat for previous level */ 256 /* else repeat for previous level */
258 } 257 }
259 } 258 }
@@ -261,10 +260,12 @@ static Vardesc *getvardesc (FuncState *fs, expdesc *e) {
261 260
262 261
263static void check_readonly (LexState *ls, expdesc *e) { 262static void check_readonly (LexState *ls, expdesc *e) {
264 Vardesc *vardesc = getvardesc(ls->fs, e); 263 FuncState *fs = ls->fs;
264 Vardesc *vardesc = getvardesc(&fs, e);
265 if (vardesc && vardesc->ro) { /* is variable local and const? */ 265 if (vardesc && vardesc->ro) { /* is variable local and const? */
266 const char *msg = luaO_pushfstring(ls->L, 266 const char *msg = luaO_pushfstring(ls->L,
267 "attempt to assign to const variable '%s'", getstr(vardesc->name)); 267 "attempt to assign to const variable '%s'",
268 getstr(fs->f->locvars[vardesc->idx].varname));
268 luaK_semerror(ls, msg); /* error */ 269 luaK_semerror(ls, msg); /* error */
269 } 270 }
270} 271}