diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-05-11 11:51:58 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-05-11 11:51:58 -0300 |
commit | 5b1ab8efdcb7b48cab8148a407266c467d57114c (patch) | |
tree | 1ec673c0171801c24854220e0fbc7ef6c19c7ed1 /lparser.c | |
parent | 7ade1557627cf3f09c23c892ee227b7386f28414 (diff) | |
download | lua-5b1ab8efdcb7b48cab8148a407266c467d57114c.tar.gz lua-5b1ab8efdcb7b48cab8148a407266c467d57114c.tar.bz2 lua-5b1ab8efdcb7b48cab8148a407266c467d57114c.zip |
'expdesc' doesn't depend on 'actvar' for var. info.
In preparation for 'global *', the structure 'expdesc' does not point
to 'actvar.arr' for information about global variables.
Diffstat (limited to 'lparser.c')
-rw-r--r-- | lparser.c | 15 |
1 files changed, 7 insertions, 8 deletions
@@ -304,11 +304,9 @@ static void check_readonly (LexState *ls, expdesc *e) { | |||
304 | varname = up->name; | 304 | varname = up->name; |
305 | break; | 305 | break; |
306 | } | 306 | } |
307 | case VINDEXUP: case VINDEXSTR: case VINDEXED: { | 307 | case VINDEXUP: case VINDEXSTR: case VINDEXED: { /* global variable */ |
308 | int vidx = e->u.ind.vidx; | 308 | if (e->u.ind.ro) /* read-only? */ |
309 | /* is it a read-only declared global? */ | 309 | varname = tsvalue(&fs->f->k[e->u.ind.keystr]); |
310 | if (vidx != -1 && ls->dyd->actvar.arr[vidx].vd.kind == GDKCONST) | ||
311 | varname = ls->dyd->actvar.arr[vidx].vd.name; | ||
312 | break; | 310 | break; |
313 | } | 311 | } |
314 | default: | 312 | default: |
@@ -483,8 +481,6 @@ static void buildvar (LexState *ls, TString *varname, expdesc *var) { | |||
483 | if (var->k == VGLOBAL) { /* global name? */ | 481 | if (var->k == VGLOBAL) { /* global name? */ |
484 | expdesc key; | 482 | expdesc key; |
485 | int info = var->u.info; | 483 | int info = var->u.info; |
486 | lua_assert(info == -1 || | ||
487 | eqstr(ls->dyd->actvar.arr[info].vd.name, varname)); | ||
488 | /* global by default in the scope of a global declaration? */ | 484 | /* global by default in the scope of a global declaration? */ |
489 | if (info == -1 && fs->bl->globdec) | 485 | if (info == -1 && fs->bl->globdec) |
490 | luaK_semerror(ls, "variable '%s' not declared", getstr(varname)); | 486 | luaK_semerror(ls, "variable '%s' not declared", getstr(varname)); |
@@ -495,7 +491,10 @@ static void buildvar (LexState *ls, TString *varname, expdesc *var) { | |||
495 | luaK_exp2anyregup(fs, var); /* but could be a constant */ | 491 | luaK_exp2anyregup(fs, var); /* but could be a constant */ |
496 | codestring(&key, varname); /* key is variable name */ | 492 | codestring(&key, varname); /* key is variable name */ |
497 | luaK_indexed(fs, var, &key); /* env[varname] */ | 493 | luaK_indexed(fs, var, &key); /* env[varname] */ |
498 | var->u.ind.vidx = cast_short(info); /* mark it as a declared global */ | 494 | if (info != -1 && ls->dyd->actvar.arr[info].vd.kind == GDKCONST) |
495 | var->u.ind.ro = 1; /* mark variable as read-only */ | ||
496 | else /* anyway must be a global */ | ||
497 | lua_assert(info == -1 || ls->dyd->actvar.arr[info].vd.kind == GDKREG); | ||
499 | } | 498 | } |
500 | } | 499 | } |
501 | 500 | ||