diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-06-21 10:16:57 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-06-21 10:16:57 -0300 |
| commit | e4b02ca8e48b499c57dd3e5882d18145db60fd4c (patch) | |
| tree | e04e28b662e455a74d87b05f78b2d73eb0627873 | |
| parent | 20a9853e0279903d255846108ffe320826dddcca (diff) | |
| download | lua-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'.
| -rw-r--r-- | lparser.c | 25 | ||||
| -rw-r--r-- | lparser.h | 1 |
2 files changed, 13 insertions, 13 deletions
| @@ -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 | */ |
| 240 | static Vardesc *getvardesc (FuncState *fs, expdesc *e) { | 241 | static 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 | ||
| 263 | static void check_readonly (LexState *ls, expdesc *e) { | 262 | static 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 | } |
| @@ -81,7 +81,6 @@ typedef struct expdesc { | |||
| 81 | 81 | ||
| 82 | /* description of an active local variable */ | 82 | /* description of an active local variable */ |
| 83 | typedef struct Vardesc { | 83 | typedef struct Vardesc { |
| 84 | TString *name; | ||
| 85 | short idx; /* index of the variable in the Proto's 'locvars' array */ | 84 | short idx; /* index of the variable in the Proto's 'locvars' array */ |
| 86 | lu_byte ro; /* true if variable is 'const' */ | 85 | lu_byte ro; /* true if variable is 'const' */ |
| 87 | } Vardesc; | 86 | } Vardesc; |
