diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2016-05-13 16:10:16 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2016-05-13 16:10:16 -0300 |
commit | b65252b39bbda0a75a56135da4765cc540922389 (patch) | |
tree | 1b1880e8fb574edce7481d8e38bc5b7de0eefd8a /lparser.c | |
parent | fbd8614bdb92199520bef10a8e020662bc94222b (diff) | |
download | lua-b65252b39bbda0a75a56135da4765cc540922389.tar.gz lua-b65252b39bbda0a75a56135da4765cc540922389.tar.bz2 lua-b65252b39bbda0a75a56135da4765cc540922389.zip |
'singlevaraux' returns result only in 'var->k'
Diffstat (limited to 'lparser.c')
-rw-r--r-- | lparser.c | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 2.151 2016/01/05 16:22:37 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 2.152 2016/03/07 19:25:39 roberto Exp roberto $ |
3 | ** Lua Parser | 3 | ** Lua Parser |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -267,27 +267,26 @@ static void markupval (FuncState *fs, int level) { | |||
267 | Find variable with given name 'n'. If it is an upvalue, add this | 267 | Find variable with given name 'n'. If it is an upvalue, add this |
268 | upvalue into all intermediate functions. | 268 | upvalue into all intermediate functions. |
269 | */ | 269 | */ |
270 | static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) { | 270 | static void singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) { |
271 | if (fs == NULL) /* no more levels? */ | 271 | if (fs == NULL) /* no more levels? */ |
272 | return VVOID; /* default is global */ | 272 | init_exp(var, VVOID, 0); /* default is global */ |
273 | else { | 273 | else { |
274 | int v = searchvar(fs, n); /* look up locals at current level */ | 274 | int v = searchvar(fs, n); /* look up locals at current level */ |
275 | if (v >= 0) { /* found? */ | 275 | if (v >= 0) { /* found? */ |
276 | init_exp(var, VLOCAL, v); /* variable is local */ | 276 | init_exp(var, VLOCAL, v); /* variable is local */ |
277 | if (!base) | 277 | if (!base) |
278 | markupval(fs, v); /* local will be used as an upval */ | 278 | markupval(fs, v); /* local will be used as an upval */ |
279 | return VLOCAL; | ||
280 | } | 279 | } |
281 | else { /* not found as local at current level; try upvalues */ | 280 | else { /* not found as local at current level; try upvalues */ |
282 | int idx = searchupvalue(fs, n); /* try existing upvalues */ | 281 | int idx = searchupvalue(fs, n); /* try existing upvalues */ |
283 | if (idx < 0) { /* not found? */ | 282 | if (idx < 0) { /* not found? */ |
284 | if (singlevaraux(fs->prev, n, var, 0) == VVOID) /* try upper levels */ | 283 | singlevaraux(fs->prev, n, var, 0); /* try upper levels */ |
285 | return VVOID; /* not found; is a global */ | 284 | if (var->k == VVOID) /* not found? */ |
285 | return; /* it is a global */ | ||
286 | /* else was LOCAL or UPVAL */ | 286 | /* else was LOCAL or UPVAL */ |
287 | idx = newupvalue(fs, n, var); /* will be a new upvalue */ | 287 | idx = newupvalue(fs, n, var); /* will be a new upvalue */ |
288 | } | 288 | } |
289 | init_exp(var, VUPVAL, idx); | 289 | init_exp(var, VUPVAL, idx); /* new or old upvalue */ |
290 | return VUPVAL; | ||
291 | } | 290 | } |
292 | } | 291 | } |
293 | } | 292 | } |
@@ -296,10 +295,11 @@ static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) { | |||
296 | static void singlevar (LexState *ls, expdesc *var) { | 295 | static void singlevar (LexState *ls, expdesc *var) { |
297 | TString *varname = str_checkname(ls); | 296 | TString *varname = str_checkname(ls); |
298 | FuncState *fs = ls->fs; | 297 | FuncState *fs = ls->fs; |
299 | if (singlevaraux(fs, varname, var, 1) == VVOID) { /* global name? */ | 298 | singlevaraux(fs, varname, var, 1); |
299 | if (var->k == VVOID) { /* global name? */ | ||
300 | expdesc key; | 300 | expdesc key; |
301 | singlevaraux(fs, ls->envn, var, 1); /* get environment variable */ | 301 | singlevaraux(fs, ls->envn, var, 1); /* get environment variable */ |
302 | lua_assert(var->k == VLOCAL || var->k == VUPVAL); | 302 | lua_assert(var->k != VVOID); /* this one must exist */ |
303 | codestring(ls, &key, varname); /* key is variable name */ | 303 | codestring(ls, &key, varname); /* key is variable name */ |
304 | luaK_indexed(fs, var, &key); /* env[varname] */ | 304 | luaK_indexed(fs, var, &key); /* env[varname] */ |
305 | } | 305 | } |