diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-04-05 13:35:37 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-04-05 13:35:37 -0300 |
commit | 6abde1b05a3e7eeb45fc9c0bb77dc660a01497a5 (patch) | |
tree | d15e0540d52db8ae5de71a8be98b643ebbfdee98 | |
parent | d394d5536aeccb937fb6fd8e7476b08d672bc892 (diff) | |
download | lua-6abde1b05a3e7eeb45fc9c0bb77dc660a01497a5.tar.gz lua-6abde1b05a3e7eeb45fc9c0bb77dc660a01497a5.tar.bz2 lua-6abde1b05a3e7eeb45fc9c0bb77dc660a01497a5.zip |
no need to keep "_ENV" name in global state (can be kept in lex state)
-rw-r--r-- | llex.c | 4 | ||||
-rw-r--r-- | llex.h | 3 | ||||
-rw-r--r-- | lparser.c | 10 | ||||
-rw-r--r-- | lstate.c | 4 | ||||
-rw-r--r-- | lstate.h | 3 |
5 files changed, 12 insertions, 12 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llex.c,v 2.34 2009/11/17 16:33:38 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 2.35 2010/02/27 21:16:24 roberto Exp roberto $ |
3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -152,6 +152,8 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { | |||
152 | ls->linenumber = 1; | 152 | ls->linenumber = 1; |
153 | ls->lastline = 1; | 153 | ls->lastline = 1; |
154 | ls->source = source; | 154 | ls->source = source; |
155 | ls->envn = luaS_new(L, "_ENV"); | ||
156 | luaS_fix(ls->envn); /* never collect this name */ | ||
155 | luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ | 157 | luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ |
156 | next(ls); /* read first char */ | 158 | next(ls); /* read first char */ |
157 | } | 159 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llex.h,v 1.63 2010/03/08 16:55:52 roberto Exp roberto $ | 2 | ** $Id: llex.h,v 1.64 2010/03/13 15:55:42 roberto Exp roberto $ |
3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -60,6 +60,7 @@ typedef struct LexState { | |||
60 | Mbuffer *buff; /* buffer for tokens */ | 60 | Mbuffer *buff; /* buffer for tokens */ |
61 | struct Varlist *varl; /* list of all active local variables */ | 61 | struct Varlist *varl; /* list of all active local variables */ |
62 | TString *source; /* current source name */ | 62 | TString *source; /* current source name */ |
63 | TString *envn; /* environment variable name */ | ||
63 | char decpoint; /* locale decimal point */ | 64 | char decpoint; /* locale decimal point */ |
64 | } LexState; | 65 | } LexState; |
65 | 66 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 2.80 2010/03/13 15:55:42 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 2.81 2010/04/05 16:26:37 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 | */ |
@@ -288,7 +288,7 @@ static void singlevar (LexState *ls, expdesc *var) { | |||
288 | FuncState *fs = ls->fs; | 288 | FuncState *fs = ls->fs; |
289 | if (singlevaraux(fs, varname, var, 1) == VVOID) { /* global name? */ | 289 | if (singlevaraux(fs, varname, var, 1) == VVOID) { /* global name? */ |
290 | expdesc key; | 290 | expdesc key; |
291 | singlevaraux(fs, G(ls->L)->envn, var, 1); /* get _ENV variable */ | 291 | singlevaraux(fs, ls->envn, var, 1); /* get _ENV variable */ |
292 | lua_assert(var->k == VLOCAL || var->k == VUPVAL); | 292 | lua_assert(var->k == VLOCAL || var->k == VUPVAL); |
293 | codestring(ls, &key, varname); /* key is variable name */ | 293 | codestring(ls, &key, varname); /* key is variable name */ |
294 | luaK_indexed(fs, var, &key); /* env[varname] */ | 294 | luaK_indexed(fs, var, &key); /* env[varname] */ |
@@ -429,12 +429,12 @@ static void close_func (LexState *ls) { | |||
429 | ** opens the main function, which is a regular vararg function with an | 429 | ** opens the main function, which is a regular vararg function with an |
430 | ** upvalue named '_ENV' | 430 | ** upvalue named '_ENV' |
431 | */ | 431 | */ |
432 | static void open_mainfunc (lua_State *L, LexState *ls, FuncState *fs) { | 432 | static void open_mainfunc (LexState *ls, FuncState *fs) { |
433 | expdesc v; | 433 | expdesc v; |
434 | open_func(ls, fs); | 434 | open_func(ls, fs); |
435 | fs->f->is_vararg = 1; /* main function is always vararg */ | 435 | fs->f->is_vararg = 1; /* main function is always vararg */ |
436 | init_exp(&v, VLOCAL, 0); | 436 | init_exp(&v, VLOCAL, 0); |
437 | newupvalue(fs, G(L)->envn, &v); /* create '_ENV' upvalue */ | 437 | newupvalue(fs, ls->envn, &v); /* create '_ENV' upvalue */ |
438 | } | 438 | } |
439 | 439 | ||
440 | 440 | ||
@@ -448,7 +448,7 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, Varlist *varl, | |||
448 | lexstate.buff = buff; | 448 | lexstate.buff = buff; |
449 | lexstate.varl = varl; | 449 | lexstate.varl = varl; |
450 | luaX_setinput(L, &lexstate, z, tname); | 450 | luaX_setinput(L, &lexstate, z, tname); |
451 | open_mainfunc(L, &lexstate, &funcstate); | 451 | open_mainfunc(&lexstate, &funcstate); |
452 | luaX_next(&lexstate); /* read first token */ | 452 | luaX_next(&lexstate); /* read first token */ |
453 | chunk(&lexstate); /* read main chunk */ | 453 | chunk(&lexstate); /* read main chunk */ |
454 | check(&lexstate, TK_EOS); | 454 | check(&lexstate, TK_EOS); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.c,v 2.75 2010/03/26 20:58:11 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 2.76 2010/03/29 17:43:14 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -157,8 +157,6 @@ static void f_luaopen (lua_State *L, void *ud) { | |||
157 | luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ | 157 | luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ |
158 | luaT_init(L); | 158 | luaT_init(L); |
159 | luaX_init(L); | 159 | luaX_init(L); |
160 | g->envn = luaS_new(L, "_ENV"); | ||
161 | luaS_fix(g->envn); /* never collect this name */ | ||
162 | luaS_fix(luaS_newliteral(L, MEMERRMSG)); | 160 | luaS_fix(luaS_newliteral(L, MEMERRMSG)); |
163 | g->GCthreshold = 4*g->totalbytes; | 161 | g->GCthreshold = 4*g->totalbytes; |
164 | } | 162 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.h,v 2.58 2010/03/26 20:58:11 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 2.59 2010/03/29 17:43:14 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -142,7 +142,6 @@ typedef struct global_State { | |||
142 | lua_CFunction panic; /* to be called in unprotected errors */ | 142 | lua_CFunction panic; /* to be called in unprotected errors */ |
143 | struct lua_State *mainthread; | 143 | struct lua_State *mainthread; |
144 | const lua_Number *version; /* pointer to version number */ | 144 | const lua_Number *version; /* pointer to version number */ |
145 | TString *envn; /* environment variable name */ | ||
146 | TString *tmname[TM_N]; /* array with tag-method names */ | 145 | TString *tmname[TM_N]; /* array with tag-method names */ |
147 | struct Table *mt[NUM_TAGS]; /* metatables for basic types */ | 146 | struct Table *mt[NUM_TAGS]; /* metatables for basic types */ |
148 | } global_State; | 147 | } global_State; |