diff options
Diffstat (limited to 'lparser.c')
-rw-r--r-- | lparser.c | 25 |
1 files changed, 13 insertions, 12 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 | } |